Example Application: Oscilloscope
| #include "gen/cOscilloscope_TinyOSModule.h" #include "gen/cOscilloscope_Main.h" cOscilloscope_Main *m = new cOscilloscope_Main(this,main,"Main",index()); m->StdControl_init(); m->StdControl_start(); |
NesCT is going to build all the classes in gen directory. Replace
"cp" with "copy" and slash (/) with backslash (\) for windows operating
system at the following instructions.
[root@sinan tictoc]# cd components/
[root@sinan components]# cp Oscilloscope.nc ../Application.nc
[root@sinan components]# cd ..
[root@sinan tictoc]# ./nesct.exe Application.nc
done.
Type 'opp_makemake -c config -f' to create new Makefile for your
environment. If your build environment is windows type 'opp_nmakemake -c
config.win32 -f' to create new Makefile for
your environment. Additionally, you need to run 'nmake -f Makefile.vc
depend' for windows.
Note that, NesCT assumes that your OMNeT++ distribution is in /opt/omnetpp-3.2 for linux and in c:\omnet++ for windows. If it is installed at some other directory, you'll need to edit config or config.win32 file to change the path for nedtool, lib and include directories of OMNeT++.
[root@sinan tictoc]# opp_makemake -c config -f
Makefile created, adding dependencies...
Done.
Type "make" for linux, "nmake -f makefile.vc" for windows to build the binary.
[root@sinan tictoc]# make
g++ -c -g -fpermissive -fPIC -DWITH_NETBUILDER -w -DTOSNODES=1000
-DLINUX -DPLATFORM_OMNETPP -I./include
-I/root/projects/tinyos-1.x/tos/interfaces -I./include_tos
-I/opt/omnetpp-3.2/include simstart.cc
g++ tictoc1_n.o debug.o simstart.o tinyos.o tinyosmain.o tossim.o txc1.o
-g -L/opt/omnetpp-3.2/lib -lenvir -lcmdenv -lsim_std -lnedxml -lxml2
-ldl -lstdc++ -lpthread -o tictoc
echo>.tstamp
Edit omnetpp.ini file and change wait-for-sf to true. After enabling this option, the simulation will wait 10 seconds before starting to allow sf to connect.
Start SerialForwarder by running ./bin/sf_sim . For windows, you may
need to enter the contents of the file yourself in a console windows
(cygwin). The exceptions will be lost once we start the simulator.
[root@sinan tictoc]# ./bin/sf_sim
Listening to tossim-serial
SF enabled, 0 clients, 0 packets read, 0 packets written getenv JNI
library not found. Env.getenv will not work
(please consult installation directions in
tinyos-1.x/tools/java/net/tinyos/util/Env.INSTALL)
Platform avrmote
Opening tossim-serial source
Connecting to Tossim event port at localhost:10585
Listening for client connections on port 9001
SF enabled, 0 clients, 0 packets read, 0 packets written
java.net.ConnectException: Connection refused
Start Oscilloscope GUI from another window.
[root@sinan ~]# java net.tinyos.oscope.oscilloscope
A preferable run directory is bin for windows. Copy tictoc.exe to
your bin directory and execute it to run the simulation. The simulation
screen should like this.
[root@sinan tictoc]# cp tictoc ./bin
[root@sinan tictoc]# cd bin
Let's enable all debug options for demonstration purposes. Use "export"
keyword for linux and "set" keyword for windows to change environment
variable. You should
see an output similar to this in TK window.

[root@sinan bin]# export DBG=all
[root@sinan bin]# ./tictoc
0:0:2.58922650: LEDS: Red on.
0:0:2.58922650: LEDS: Red on.
0:0:2.71128900: HPLADC: request for port 1
0:0:2.71128900: HPLADC: request for port 1
0:0:2.71128900: HPLADC: request for port 1
0:0:2.71128900: adc_tick: port 1 with value 16882
0:0:2.71128900: adc_tick: port 1 with value 7931
0:0:2.71128900: adc_tick: port 1 with value 43491
0:0:2.71128900: data_event
0:0:2.71128900: data_event
0:0:2.71128900: data_event
0:0:2.71128900: LEDS: Red on.
0:0:2.71128900: LEDS: Red on.
0:0:2.71128900: LEDS: Red on.
See the following output in Oscilloscope window.