Wednesday, 16 January 2013

Setup for Tossim in ubuntu

-->

Troubleshooting TOSSIM compilation

TOSSIM is a C/C++ shared library with an optional Python translation layer. Almost all of the problems encountered in compiling TOSSIM are due to C linking issues. If you don't know what a linker is (or have never linked a C program), then chances are the rest of this appendix is going to be cryptic and incomprehensible. You're best off starting with learning about linkers, why they are needed, and how you use the gcc/g++ compilers to link code.
Generally, when compiling TOSSIM using make micaz sim, one of four things can go wrong:
  1. You are using Cygwin but the sim compilation option can't figure this out.
  2. You do not have the needed Python support installed.
  3. You have Python support installed, but the make system can't find it.
  4. You have Python support installed, but it turns out to be incompatible with TOSSIM.
  5. You have a variant of gcc/g++ installed that expects slightly different compilation options than the normal installation.
We'll visit each in turn.

1) You are using Cygwin but the sim compilation option can't figure this out

It turns out that the Cygwin and Linux versions of gcc/g++ have different command-line flags and require different options to compile TOSSIM properly. For example, telling the Linux compiler to build a library requires -fPIC while the Cygwin is -fpic. If you're using Cygwin and you see the output look like this:
ncc -c -shared -fPIC -o build/micaz/sim.o ...
rather than
ncc -c -DUSE_DL_IMPORT -fpic -o build/micaz/sim.o ...
then you have encountered this problem. The problem occurs because Cygwin installations do not have a consistent naming scheme, and so it's difficult for the compilation toolchain to always figure out whether it's under Linux or Cygwin.
Symptom: You're running cygwin but you see the -fPIC rather than -fpic option being passed to the compiler.
Solution: Explicitly set the OSTYPE environment variable to be cygwin either in your .bashrc or when you compile. For example, in bash:
$ OSTYPE=cygwin make micaz sim
or in tcsh
$ setenv OSTYPE cygwin
$ make micaz sim
Note that often this problem occurs in addition to other ones, due to using a nonstandard Cygwin installation. So you might have more problems to track down.





2) You do not have the needed Python support installed

If when you compile you see lots of errors such as "undefined reference to" or "Python.h: No such file or directory" then this might be your problem. It is a subcase of the more general problem of TOSSIM not being able to find needed libraries and files.
Compiling Python scripting support requires that you have certain Python development libraries installed. First, check that you have Python installed:
$ python -V
Python 2.4.2
In the above example, the system has Python 2.4.2. If you see "command not found" then you do not have Python installed. You'll need to track down an RPM and install it. TOSSIM has been tested with Python versions 2.3 and 2.4. You can install other versions, but there's no assurance things will work.
In addition to the Python interpreter itself, you need the libraries and files for Python development. This is essentially a set of header files and shared libraries. If you have the locate command, you can type locate libpython, or if you don't, you can look in /lib, /usr/lib and /usr/local/lib. You're looking for a file with a name such as libpython2.4.so and a file named Python.h. If you can't find these files, then you need to install a python-devel package.
Symptom: Compilation can't find critical files such as the Python interpreter, Python.h or a Python shared library, and searching your filesystem shows that you don't have them.
Solution: Installed the needed files from Python and/or Python development RPMS.
If you have all of the needed files, but are still getting errors such as "undefined reference" or "Python.h: No such file or directory", then you have the next problem: they're on your filesystem, but TOSSIM can't find them.



3) You have Python support installed, but the make system can't find it

You've found libpython and Python.h, but when TOSSIM compiles it says that it can't find one or both of them. If it can't find Python.h then compilation will fail pretty early, as g++ won't be able to compile the Python glue code. If it can't find the python library, then compilation will fail at linking, and you'll see errors along the lines of "undefined reference to __Py...". You need to point the make system at the right place.
Open up support/make/sim.extra. If the make system can't find Python.h, then chances are it isn't in one of the standard places (e.g., /usr/include). You need to tell the make system to look in the directory where Python.h is with a -I option. At the top of sim.extra, under the PFLAGS entry, add
CFLAGS += -I/path
where /path is the path of the directory where Python.h lives. For example, if it is in /opt/python/include, then add CFLAGS += -I/opt/python/include.
If the make system can't find the python library for linking (causing "undefined reference") error messages, then you need to make sure the make system can find it. The sim.extra file uses two variables to find the library: PYDIR and PYTHON_VERSION. It looks for a file named libpython$(PYTHON_VERSION).so. So if you have Python 2.4 installed, make sure that PYTHON_VERSION is 2.4 (be sure to use no spaces!) and if 2.3, make sure it is 2.3.
Usually the Python library is found in /usr/lib. If it isn't there, then you will need to modify the PLATFORM_LIB_FLAGS variable. The -L flag tells gcc in what directories to look for libraries. So if libpython2.4.so is in /opt/python/lib, then add -L/opt/python/lib to the PLATFORM_LIB_FLAGS. Note that there are three different versions of this variable, depending on what OS you're using. Be sure to modify the correct one (or be paranoid and modify all three).
Symptom: You've verified that you have the needed Python files and libraries, but compilation is still saying that it can't link to them ("undefined reference") or can't find them ("cannot find -lpython2.4").
Solution: Change the sim.extra file to point to the correct directories using -L and -I flags.



4) You have Python support installed, but it turns out to be incompatible with TOSSIM.

Symptom: You see a "This python version requires to use swig with the -classic option" error message.
Symptom: You see a long string of compilation errors relating to SWIG and Python, e.g.:
 /opt/tinyos-2.1.1/tos/lib/tossim/tossim_wrap.cxx: In function ‘void SWIG_Python_AddErrorMsg(const char*)’:
 /opt/tinyos-2.1.1/tos/lib/tossim/tossim_wrap.cxx:880: warning: format not a string literal and no format arguments



Solution: Install SWIG and regenerate Python support with the sing-generate script in tos/lib/tossim, or install a different version of Python.

5) You have a variant of gcc/g++ installed that expects slightly different compilation options than the normal installation.

Symptom: g++ complains that it cannot find main() when you are compiling the shared library ("undefined reference to `_WinMain@16'").
Solution: There are two possible solutions. The first is to include a dummy main(), as described in this tinyos-help posting. The second is to add the -shared option, as described in this web page.
Hopefully, these solutions worked and you can get back to compiling, If not, then you should email tinyos-help.



ERROR:
make: g++ : command not found
> make: *** [ sim-exe] Error 127

Sollution:need to install the g++ packages. 
  sudo apt-get install g++

Tuesday, 15 January 2013

Install TinyOS in Ubuntu

1) Remove any old tinyos repository from /etc/apt/sources.list and add the following: 
A common pool supports all Ubuntu distributions based on Debian Squeeze. Specifing lucid as the distibrution should work fine. 
       deb http://tinyos.stanford.edu/tinyos/dists/ubuntu lucid main 
 
2) Update your repository cache : 
       sudo apt-get update 
3) Run the following to install the latest release of tinyos and all its supported tools: 
       sudo apt-get install tinyos
 
This will likely give you a message telling you to choose between the two available versions.  An example to then execute is:
       sudo apt-get install tinyos-2.1.1
 
 
4)(Optional)This should install the latest MSPGCC tools. We now have to download the
 latest TinyOS® version from the official repository, in order to be 
able to compile for telosb based products. Open a console and type:
 
cd /opt
sudo svn checkout http://tinyos-main.googlecode.com/svn/trunk/ tinyos-main-read-only
sudo cp -R /opt/tinyos-main-read-only /opt/tinyos-2.x
 
This will add the latest Tinyos® code, which include the new msp430x chip drivers.
 
 5) Then we need to change the environmental variables. For this we open the .bashrc file
$ gedit ~/.bashrc
and paste the following lines to the bashrc file.
export TOSROOT=/opt/tinyos-2.1.1
export TOSDIR=$TOSROOT/tos
export CLASSPATH=$TOSROOT/support/sdk/java:.:$TOSROOT/support/sdk/java/tinyos.jar : . : $CLASSPATH
export MAKERULES=$TOSROOT/support/make/Makerules             
export PATH=/opt/msp430/bin:$PATH    
 
  Add the following line to your ~/.bashrc or ~/.profile file in your home directory to set up the environment for TinyOS development at login 
        #Sourcing the tinyos environment variable setup script
        source /opt/tinyos-2.1.1/tinyos.sh 
 
6)Change the permission
 
sudo chmod 777 $TOSROOT 
 
7) Finally, to check if the installation was done , run the command
$ tos-check-env
 
For further help visit to :
http://docs.tinyos.net/tinywiki/index.php/Installing_TinyOS_2.1.1 

Wednesday, 10 October 2012

Avrora Installation


-->
Steps to install AVRORA


Step 0: Get Java!

Avrora is implemented in Java, and therefore it requires that you have a functional Java Virtual Machine installed. Once the JVM is installed and you are able to run java at the command line, you're ready to continue to the next step.

Freely available Java Virtual Machine implementations are available from both Sun Microsystems and IBM.

See http://java.sun.com to download the Sun Java implementation for your platform.

Avrora is not dependent on the particular Java implementation that you choose.


step1:Download the Avrora JAR Archive

Download the latest JAR archive release from "http://compilers.cs.ucla.edu/avrora/release.html". Simply save the JAR file to your disk.
Copy the avrora jar file(avrora-beta-1.6.0.jar in this case) in a directory say "home/test/avrora/avrora-beta-1.6.0.jar"
copy the following code to ".bashrc" to set path

alias avrora='java -jar /home/test/avrora/avrora-beta-1.6.0.jar'

Close all the shells opened
Open a new shelll and type "avrora" if no error then avrora is successfully install.

Step 2:Compile

1>The Atmel assembler syntax. Files that end with the .asm extension are assumed to be in this format. Files in this format can be loaded directly by Avrora.
2>The GNU assembler (GAS) syntax. Files that end with the .s extension are assumed to be in this format.
3>The output of the avr-objdump utility. Files that end with the .od extension are assumed to be in this format. Avrora cannot directly load ELF or SREC images, therefore binary programs in those formats must be converted to a textual format with avr-objdump


1> To run Blink application goto Blink directory then type the follwing

make micaz

2> convert the executable file main.exe to .od file by typing

avr-objdump -zhD build/mica2/main.exe > blink.od


Step 3: Test Simulation

In order to select a multi-node simulation, we will need to specify the "simulation" option with the value "sensor-network". This tells Avrora to the simulation type is a sensor network, rather than the default, single node simulation.

type
avrora -simulation=sensor-network -seconds=5.0 -nodecount=15 blink.od









Note that only AVR platforms such as Mica2/Micaz is supported by Avrora

For more information visit to "http://compilers.cs.ucla.edu/avrora/"