hw2: q&a oct. 02, 2007. lab machine tinyos is installed in one machine (531ab). but, you have to...
TRANSCRIPT
![Page 1: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/1.jpg)
HW2: Q&A
Oct. 02, 2007
![Page 2: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/2.jpg)
Lab Machine
TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign up to reserve a time slot.
No password needed.
![Page 3: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/3.jpg)
Procedure
PC(java program)
BSMib510+mica2
(apps\TOSBase)
Mica2+sensor(NesC program)
1. Get input (type, id)
2. Broadcast it to radio
3. Check id
4. Sense light/temp/acoustic
5. Send sensed data
6. Forward it to the serial port
7. Display it
![Page 4: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/4.jpg)
hw2.java
package net.tinyos.tools;
import java.io.*;import net.tinyos.packet.*;import net.tinyos.util.*;import net.tinyos.message.*;
public class HW2_skel { public static void main(String args[]) throws IOException {
if (args.length > 0) {/* Print out a message *
* System.err.println(); */
System.exit(2);}
// Create a serial reader and writer
PacketSource srw = BuildSource.makePacketSource();if (srw == null) { System.err.println("Invalid packet source (check your MOTECOM environment variable)"); System.exit(2);}
![Page 5: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/5.jpg)
hw2.java - continue
srw.open(PrintStreamMessenger.err);
try { // Read a packet from a serial port byte[] packet = srw.readPacket();
// Write a packet to a serial port // Please look at the lesson 6 to see the packet format srw.writePacket(packet);
// Display this on a screen Dump.printPacket(System.out, packet); System.out.println(); System.out.flush();}catch (IOException e) { System.err.println("Error on " + srw.getName() + ": " + e);}
}}
![Page 6: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/6.jpg)
SenseMsg.h
struct SenseMsg{ uint16_t sourceMoteID; //Holds the queried mote id uint16_t datatype; // The type of data that is being sensed 1 for
Temperature 2 for Light and 3 for Mic readings uint16_t data; // The sensed data.};
enum { AM_SENSEMSG = 100,};
![Page 7: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/7.jpg)
Packet format
Format
Other java programs
Check out \opt\tinyos-1.x\tools\java\net\tinyos\tools
Dest. address
Active Msg handler
Group ID Msg length
Payload (SenseMsg.h)
SourceID datatype Data
2 bytes 1 byte 1 byte 1 byte 2 bytes 2 bytes 2 bytes
FF FF 64 7D 06
![Page 8: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/8.jpg)
hw2.nc (configuration)
includes SenseMsg;
configuration hw2 { }implementation{ components Main, hw2M, LedsC, Photo, GenericComm as Comm;
Main.StdControl -> hw2M; Main.StdControl -> Comm; hw2M.Leds -> LedsC; hw2M.ADCLight -> Photo; hw2M.LightControl -> Photo;
hw2M.DataMsg -> Comm.SendMsg[AM_SENSEMSG]; hw2M.RecMsg -> Comm.ReceiveMsg[AM_SENSEMSG];}
![Page 9: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/9.jpg)
hw2M.nc (Module)
includes SenseMsg;
module hw2M{ provides interface StdControl; uses { interface Leds; interface ADC as ADCLight;
interface StdControl as LightControl;
interface StdControl as CommControl; interface SendMsg as DataMsg; interface ReceiveMsg as RecMsg; }}
![Page 10: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/10.jpg)
hw2M.nc (Module) - Continue
implementation{ TOS_Msg msg;
command result_t StdControl.init() { // initialization return SUCCESS; }
command result_t StdControl.start() { // starting return SUCCESS; }
command result_t StdControl.stop() { // stopping return SUCCESS; }
![Page 11: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/11.jpg)
hw2M.nc (Module) - Continue
async event result_t ADCLight.dataReady(uint16_t data) { // When sensing is done,
return SUCCESS; }
event result_t DataMsg.sendDone(TOS_MsgPtr sent, result_t success) { return SUCCESS; }
event TOS_MsgPtr RecMsg.receive(TOS_MsgPtr m) { // When a packet is received
return m; }}
![Page 12: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/12.jpg)
Other sensors?
Check out
\opt\tinyos-1.x\tos\sensorboards\micasb
e.g) Photo.nc: for light sensors
![Page 13: HW2: Q&A Oct. 02, 2007. Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign](https://reader035.vdocuments.mx/reader035/viewer/2022072014/56649ea95503460f94badbed/html5/thumbnails/13.jpg)
Makefile
// specify the component to install
COMPONENT=hw2
PFLAGS=-I../hw2
// set the frequency of mica2 as 916.7 MHz
PFLAGS += -DCC1K_DEF_FREQ=916700000
include ../Makerules