Almost...Unfortunately all my information is based on reverse engineering Tinyos 1.x and I think there may have been some changes in 2.x, so YMMV. I think there is a TEP document on the docs.tinyos.net site that might be clearer than me...
I have a package of Java code for host side reading and writing of messages, but it is targeted at a platform that I added (USBPIC) so {may,is} be a bit more confusing than necessary. Here: http://www.etantdonnes.com/DOC/USBPIC/JavaCommCode.zip Also there is an old document that _almost_ describes the format, but I notice that it is not quite correct either (...it's missing the seqno field...) here: http://web.archive.org/web/20060627154751/http://www.octavetech.com/pubs/TB5-01+Deciphering+TinyOS+Serial+Packets.pdf Specifics that I notice right away... First you are using the "old" mica2 AM.h format which will not fly with the telosb. Look in the telos platform directories for an AM.h file that specs the correct header format, mostly just adding some number of useless fields that can be set to 0. (This may be hidden in T2, I'm not sure if the basestation code translates telosb headers or not). Second there are hidden message type and sequence number fields immediately following the first 0x7E frame byte: Each message sent or received has this raw format: -------------------------- added by Packetizer.java framer protocol byte frame=0x7E; // framing byte...gets escaped in body byte mtype=0x42; // TOS message type -- used for status byte seqno; // incremented sequence number -------------------------- user message with appropriate tinyos Header byte data[MAX_LEN]; // header and user payload -------------------------- added by Packetizer.java framer protocol byte frame=0x7E; Then the tinyos header Length field is the _payload_ length not including hidden stuff and the other header fields. In your case it would be 2. And finally you need to deal with the "escaping" of 0x7E and 0x7D values in the message body and calculating the CRC value correctly. It does _not_ include the frame or escaping bytes...See the two links above for info... MS On 10/1/2012 8:08 AM, Sean Dekker wrote: > Hi, > > I just want to make packets in C# and send to a TelosB mote. As simple > as that but I couldn' make this packet yet. Can you please check what I > am doing wrong? > > Here is the struct that I have defined and programmed into TelosB mote: > > > typedef nx_struct pc_serial_msg > { > nx_uint8_t sequenceNumber; > nx_uint16_t controlCommand; > } pc_serial_msg; > > > And here is the code that responsible to make the packet: > > private Byte[] MakePacket(byte command) > { > //Increment the sequence > _sequenceNumber++; > > var pkt = new byte[10]; > > //START FLAG > pkt[0] = 0x7E; > > //HEADER > pkt[1] = 0xf; //Destination > pkt[2] = 0xf; //Source > pkt[3] = 0xf; //Length ??? > pkt[4] = 0x1; //Group > pkt[5] = 0x1; //Type > > //PAYLOAD > pkt[6] = _sequenceNumber; > pkt[7] = command; > > //Generating CRC > pkt[8] = 0x1; > > //END > pkt[9] = 0x7E; //END > > return pkt; > } > > > Can you tell me what I have to put in Destination, Source, Group and > Type bytes? What is Length? is it the length of the packet that is going > to be transmitet and equals number of bytes in the packet? Am I atleast > in the right track or this is totaly wrong? > > Thanks, > Sean. > > > _______________________________________________ > Tinyos-help mailing list > Tinyos-help@millennium.berkeley.edu > https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help > _______________________________________________ Tinyos-help mailing list Tinyos-help@millennium.berkeley.edu https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help