Open a second window and go to the Bombilla
application directory. Using your favorite editor,
create a file named "reboot.txt" with this code in it:
led(1);
This tells the VM to turn on the red LED. Exit
your editor and type this at the command line:
java net.tinyos.script.Scripter -comm tossim-serial reboot reboot.txt
This runs the TinyScript
compiler/scripter. -comm tossim-serial
tells it to connect to TOSSIM through a virtual
serial port to mote 0. reboot reboot.txt
tells it to inject code that should run when the VM
reboots (Reboot), and the code is in the
file reboot.txt. The VM reboots every time
it installs new code.
All of the tools for interacting with a running
VM, such as Scripter and
VMBufferReader (which you'll use later, in
Lesson 2), must be executed from the VM's
application directory. This is because each VM can
have customized message formats and values, and the
tools must use the VM-specific versions of those
Java classes, which reside in the directory named
vm_specific.
In the TOSSIM window, you should see this output:
0: LEDS: Red on.
0: LEDS: Green off.
0: LEDS: Yellow off.
If you don't see the output, trying running the
Scripter again.
That program was very simple: it wasn't even
Blink. Let's try CntToLeds. This requires writing
two scripts: one for what to do when a timer fires
(increment a counter and display it), and one to
start the timer. Open a file named "timer0.txt" and
type:
private counter;
counter = counter + 1;
led(counter % 8);
Every time this program runs, it will increment
counter and display its bottom three bits on the
mote LEDs (% is the modulo operator). Type
java net.tinyos.script.Scripter -comm tossim-serial timer0 timer0.txt
to install the timer script on the VM. However,
the timer isn't firing yet; you need to install a
script that will start it. Re-open "reboot.txt" and
edit it to be
settimer0(10);
The function settimer0 controls the rate
at which timer0 fires. The parameter is in terms of
tenths of a second, so 10 will fire the timer at
once a second. Calling it with 0 will stop the
timer. When the VM installs the script, it will
reboot and run it, starting timer0:
java net.tinyos.script.Scripter -comm tossim-serial reboot reboot.txt
You should see the LED increment in the TOSSIM
window. You can also start TinyViz with
java net.tinyos.sim.SimDriver -gui
to see the mote blink visually.
|