Download presentation
Presentation is loading. Please wait.
Published byOpal Evans Modified over 9 years ago
1
HW2: Q&A Oct. 02, 2007
2
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.
3
Procedure PC (java program) BS Mib510+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
4
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); }
5
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); }
6
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 Tem perature 2 for Light and 3 for Mic readings uint16_t data; // The sensed data. }; enum { AM_SENSEMSG = 100, };
7
Packet format Format Other java programs Check out \opt\tinyos-1.x\tools\java\net\tinyos\tools Dest. address Active Msg handler Group IDMsg length Payload (SenseMsg.h) SourceIDdatatypeData 2 bytes1 byte 2 bytes FF 647D06
8
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]; }
9
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; }
10
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; }
11
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; }
12
Other sensors? Check out \opt\tinyos-1.x\tos\sensorboards\micasb e.g) Photo.nc: for light sensors
13
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.