1 TinyOS Network Communication Computer Network Programming Wenyuan Xu Fall 2007.

Slides:



Advertisements
Similar presentations
Cyclic Code.
Advertisements

Introduction to Information Technologies
EEC-484/584 Computer Networks
TinyOS Tutorial Communication Networks I Wenyuan Xu Fall 2006.
EEC-484/584 Computer Networks Lecture 6 Wenbing Zhao
CSCI 4550/8556 Computer Networks Comer, Chapter 7: Packets, Frames, And Error Detection.
PART III DATA LINK LAYER. Position of the Data-Link Layer.
Long distance communication Multiplexing  Allow multiple signals to travel through one medium  Types Frequency division multiplexing Synchronous time.
The OSI Reference Model
CMPE 150- Introduction to Computer Networks 1 CMPE 150 Fall 2005 Lecture 11 Introduction to Computer Networks.
Data Communications Chapter 7 Error Detection. Despite the best prevention techniques, errors may still happen. To detect an error, something extra has.
Chapter 2 : Direct Link Networks (Continued). So far... Modulation and Encoding Link layer protocols Error Detection -- Parity Check.
Chapter 3 Review of Protocols And Packet Formats
CS352- Link Layer Dept. of Computer Science Rutgers University.
Data Link Layer IS250 Spring 2010
Chapter 10 Error Detection and Correction
Shashank Srivastava Motilal Nehru National Institute Of Technology, Allahabad Error Detection and Correction : Data Link Layer.
TinyOS Tutorial Based on Wenyuan Xu’s slides ( NetsF06/Comnet_TinyOS_Tutorial_xwy.ppt)
1 TinyOS Computer Network Programming Wenyuan Xu Fall 2007.
Channel Coding and Error Control
CSE331: Introduction to Networks and Security Lecture 3 Fall 2002.
COM342 Networks and Data Communications
HW2: Q&A Oct. 02, Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign.
1 Data Link Layer Lecture 20 Imran Ahmed University of Management & Technology.
PART III DATA LINK LAYER. Position of the Data-Link Layer.
Transmission Control Protocol
Part 2: Packet Transmission Packets, frames Local area networks (LANs) Wide area networks (LANs) Hardware addresses Bridges and switches Routing and protocols.
Dhanshree Nimje Smita Khartad
10.1 Chapter 10 Error Detection and Correction Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 14.
1 Part III Packet Transmission Chapter 7 Packets, Frames, and Error Detection.
Chapter 3 Data Link Layer With special focus on Ethernet.
Lecture 6: Framing and Error Detection-Data Link Layer Functions
Part 2 TinyOS and nesC Programming Selected slides from:
Feb 2007WSN Training: MICA2/z Radio Stack1 MoteWorks Radio Stack Objectives  Background  Radio Stack API  MICA2 radio stack  MICAz radio stack  Configure.
Data and Computer Communications by William Stallings Eighth Edition Digital Data Communications Techniques Digital Data Communications Techniques Click.
Cyclic Redundancy Check (CRC).  An error detection mechanism in which a special number is appended to a block of data in order to detect any changes.
COSC 3213: Computer Networks I Instructor: Dr. Amir Asif Department of Computer Science York University Section M Topics: 1. Error Detection Techniques:
Layer Two Data Link Layer Collects bits from layer 1 and organizes into frames Passes bits that make up frames to layer 1 for transmission Concerned with.
10/27/ Data Link Layer - Lin 1 CPET/ECET Data Link Layer Data Communications and Networking Fall 2004 Professor Paul I-Hai Lin Electrical.
Chapter 9 Hardware Addressing and Frame Type Identification 1.Delivering and sending packets 2.Hardware addressing: specifying a destination 3. Broadcasting.
TinyOS Applications Advanced Computer Networks. TinyOS Applications Outline  AntiTheft Example {done in gradual pieces} –LEDs, timer, booting  Sensing.
Main Issues Three major issues that we are concerned with in sensor networks are – Clustering Routing and Security To be considered against the backdrop.
Computer Networks Lecture 2: Data Link Based on slides from D. Choffnes Northeastern U. and P. Gill from StonyBrook University Revised Autumn 2015 by S.
Error Detection.
10.1 Chapter 10 Error Detection and Correction Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Review.
Lab 3, Part 2 Selected slides from: Wireless Sensor Networks Hardware/Software Tiny OS & NesC Programming borrowed from Turgay Korkmaz.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
Based on slides from Andreas Larsson Table from CY Chong, SP Kumar, BA Hamilton - Proceedings of the IEEE, 2003.
Data Communications is the Real World OSI Layers 1 & 2 a.k.a TCP/IP Network Interface Layer.
Network Layer4-1 Chapter 5: The Data Link Layer Our goals: r understand principles behind data link layer services: m error detection, correction m sharing.
Data Link Layer. Link Layer The data unit to be transmited at the link layer is called a frame. Why link layer? How can it know where a frame begins and.
Cyber-Physical Programming
Local Area Networks: Topologies. 2 Packet Identification & MAC Addresses Each packet specifies an intended recipient with an identifier. – Demultiplexing.
Why does it need? [USN] ( 주 ) 한백전자 Background Wireless Sensor Network (WSN)  Relationship between Sensor and WSN Individual sensors are very limited.
TinyOS Sandeep Gupta. TinyOS basics TinyOS is  Single tasking OS  Interrupt driven Written using a Component based language A set of components put.
Introduction to Information Technologies
Data Link Layer.
Cyclic Redundancy Check (CRC)
Local Area Networks: Topologies
Advanced Computer Networks
CIS 321 Data Communications & Networking
Data Link Layer What does it do?
Reliable transmission
Computer Networks Bhushan Trivedi, Director, MCA Programme, at the GLS Institute of Computer Technology, Ahmadabad.
Introduction to Information Technologies
SenseToRfm SenseToInt.Timer -> TimerC; configuration SenseToRfm {
Data Link Layer. Position of the data-link layer.
Presentation transcript:

1 TinyOS Network Communication Computer Network Programming Wenyuan Xu Fall 2007

2 Inter-Node Communication General idea:  Sender:  Receiver: Fill message buffer with data Specify Recipients Pass buffer to OS Determine when message buffer can be reused OS Buffers incoming message in a free buffer Signal application with new message OS obtains free buffer to store next message

3 TOS Active Messages Message is “active” because it contains the destination address, group ID, and type. ‘group’: group IDs create a virtual network  an 8 bit value specified in /apps/Makelocal The address is a 16-bit value specified by “make”  – make install. mica2 “length” specifies the size of the message. “crc” is the check sum typedef struct TOS_Msg { // the following are transmitted uint16_t addr; uint8_t type; uint8_t group; uint8_t length; int8_t data [TOSH_DATA_LENGTH ]; uint16_t crc; // the following are not transmitted uint16_t strength; uint8_t ack; uint16_t time; uint8_t sendSecurityMode; uint8_t receiveSecurityMode; } TOS_Msg; PreambleHeader (5)Payload (29)CRC (2) Sync

4 TOS Active Messages (continue)

5 Receiving a message Define the message format Define a unique active message number How does TOS know the AM number? configuration Forwarder { } implementation { … ForwarderM.SendMsg -> Comm.SendMsg[AM_INTMSG]; ForwarderM.ReceiveMsg -> Comm.ReceiveMsg[AM_INTMSG]; } struct Int16Msg { uint16_t val; }; enum { AM_INTMSG = 47 }; File: Int16Msg.h includes Int16Msg; module ForwarderM { //interface declaration } implementation { event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr m) { call Leds.yellowToggle(); call SendMsg.send(TOS_BCAST_ADDR, sizeof(IntMsg), m); return m; } event result_t SendMsg.sendDone(TOS_MsgPtr msg, bool success) { call Leds.greenToggle(); return success; } Message received

6 Sending a message Define the message format Define a unique active message number How does TOS know the AM number? configuration Forwarder { } implementation { … ForwarderM.SendMsg -> Comm.SendMsg[AM_INTMSG]; ForwarderM.ReceiveMsg -> Comm.ReceiveMsg[AM_INTMSG]; } struct Int16Msg { uint16_t val; }; enum { AM_INTMSG = 47 }; File: Int16Msg.h includes Int16Msg; module ForwarderM { //interface declaration } implementation { event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr m) { call Leds.yellowToggle(); call SendMsg.send(TOS_BCAST_ADDR, sizeof(IntMsg), m); return m; } event result_t SendMsg.sendDone(TOS_MsgPtr msg, bool success) { call Leds.greenToggle(); return success; } destination length

7 Where exactly is the radio stuff? CC1000RadioC CC1000RadioIntM StdControl ReceiveMsg BareSendMsg StdControl BareSendMsg ReceiveMsg Mica2

8 Spi bus interrupt handler Connection between Chipcon CC1000 radio and the ATmega128 processor: SPI bus. Spibus interrupt handler: SpiByteFifo.dataReady() SpiByteFifo.dataReady() will be called every 8 ticks. file:CC1000RadioIntM.nc async event result_t SpiByteFifo.dataReady(uint8_t data_in) { … switch (RadioState) { case RX_STATE: {...} case DISABLED_STATE: {…} case IDLE_STATE: {...} case PRETX_STATE: {...} case SYNC_STATE: {...} case RX_STATE: {...} return SUCCESS; } PreambleHeader (5)Payload (29)CRC (2) Sync

9 Receiving a message (1) file:CC1000RadioIntM.nc async event result_t SpiByteFifo.dataReady(uint8_t data_in) { … switch (RadioState) { … case IDLE_STATE: { if (((data_in == (0xaa)) || (data_in == (0x55)))) { PreambleCount++; if (PreambleCount > CC1K_ValidPrecursor) { PreambleCount = SOFCount = 0; RxBitOffset = RxByteCnt = 0; usRunningCRC = 0; rxlength = MSG_DATA_SIZE-2; RadioState = SYNC_STATE; } } … } PreambleHeader (5)Payload (29)CRC (2) Sync IDLE_STATE  SYNC_STATE  Listen to the preamble, if the enough bytes of preamble are received, entering SYCN_STATE

10 Receiving a message (2) file:CC1000RadioIntM.nc async event result_t SpiByteFifo.dataReady(uint8_t data_in) { … switch (RadioState) { case SYNC_STATE: … { if ( find SYCN_WORD) { … RadioState = RX_STATE; } else if ( too many preamble) { … RadioState = IDLE_STATE; } } … } PreambleHeader (5)Payload (29)CRC (2) Sync SYNC_STATE  RX_STATE  look for a SYNC_WORD (0x33cc).  Save the last received byte and current received byte  Use a bit shift compare to find the byte boundary for the sync byte  Retain the shift value and use it to collect all of the packet data SYNC_STATE  IDLE_STATE  didn't find the SYNC_WORD after a reasonable number of tries, so set the radio state back to idle: RadioState = IDLE_STATE;

11 Receiving a message (3) file:CC1000RadioIntM.nc async event result_t SpiByteFifo.dataReady(uint8_t data_in) { … switch (RadioState) { … case RX_STATE: { …RxByteCnt++; if (RxByteCnt <= rxlength) { usRunningCRC = crcByte(usRunningCRC,Byte); if (RxByteCnt == HEADER_LENGTH_OFFSET) { rxlength = rxbufptr->length;} } else if (RxByteCnt == rxlength-CRCBYTE_OFFSET) { if (rxbufptr->crc == usRunningCRC) { rxbufptr->crc = 1; } else { rxbufptr->crc = 0; } … RadioState = IDLE_STATE; post PacketRcvd(); } … PreambleHeader (5)Payload (29)CRC (2) Sync RX_STATE  IDLE_STATE/SENDING_ACK  Keep receiving bytes and calculate CRC until the end of the packet.  The end of the packet are specified by the length in the packet header  Pass the message to the application layer, no matter whether the message passed the CRC check

12 Error Detection – CRC CRC – Cyclic Redundancy Check  Polynomial codes or checksums Procedure: 1. Let r be the degree of the code polynomial. Append r zero bits to the end of the transmitted bit string. Call the entire bit string S(x) 2. Divide S(x) by the code polynomial using modulo 2 division. 3. Subtract the remainder from S(x) using modulo 2 subtraction. The result is the checksummed message

13 Generating a CRC – example Message: 1011  1 * x * x * x + 1= x 3 + x + 1 Code Polynomial: x (101) Step 1: Compute S(x) r = 2 S(x) = Step 2: Modulo 2 divide Remainder Step 3: Modulo 2 subtract the remainder from S(x) Checksummed Message

14 Decoding a CRC – example Procedure 1. Let n be the length of the checksummed message in bits 2. Divide the checksummed message by the code polynomial using modulo 2 division. If the remainder is zero, there is no error detected. Case 1: Remainder = 0 (No error detected) Case 2: Remainder = 1 (Error detected) Checksummed message (n=6): Original message

15 CRC in TinyOS Calculate the CRC byte by byte crc=0x0000; while (more bytes) { crc=crc^b<<8; calculate the high byte of crc } Code Polynomial: CRC-CCITT 0x1021 = x 16 + x 12 + x file: system/crc.h uint16_t crcByte(uint16_t crc, uint8_t b) { uint8_t i; crc = crc ^ b << 8; i = 8; do if (crc & 0x8000) crc = crc << 1 ^ 0x1021; else crc = crc << 1; while (--i); return crc; } Example: 10… …