:D I knew someone was going to catch that the moment I read my sent mails list. I ought to spend more time rooting out bugs in my emails, or stop worrying about sending out errata for emails.

Step 2 ought to have been:
2. Run the CRC algorithm on the raw data packet

Sankar.

----- Original Message ----- From: "Ben Buckner" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Tuesday, April 10, 2007 10:55 AM
Subject: Re: [Tinyos-help] CRC checking



Yes. My mistake.

We would want to make sure the CRC bytes don't have the 7E or 7D bytes. >
The
corrected procedure would be as here:

1. create the message packet including everything but the Sync bytes (7E)
2. run the CRC algorithm on the escaped data packet
3. attach the CRC in little endian format (lower byte first)
4. escape the bytes corresponding to 7D, or 7E
5. attach the sync bytes
6. Send.

Sankar.

Hmm... you still CRCed the escaped data in #2 - every byte has to be CRCed
before escaping. I was looking at my code yesterday when I posted, and it
definitely CRCs unescaped data. I think the idea is that the TOS_Msg is
supposed to be a higher layer than the "raw packet" frame, and the CRC is
nominally part of that layer so it shouldn't care what is in the raw packet (except for that pesky packet type & ACK prefix, it seems). The relevant TOS
code (in TOS 1.11, which I'm using) appears to be in tos\system\FramerM in
ByteComm.rxByteReady()

   case RXSTATE_ESC:
     if (data == HDLC_FLAG_BYTE) {
// Error case, fail and resync
gRxByteCnt = gRxRunningCRC = 0;
gMsgRcvTbl[gRxHeadIndex].Length = 0;
gMsgRcvTbl[gRxHeadIndex].Token = 0;
gRxState = RXSTATE_NOSYNC;
     }
     else {
data = data ^ 0x20;
       gpRxBuf[gRxByteCnt] = data; // unescape - BB
if (gRxByteCnt >= 2) { // CRC if we're in the TOS_MSG pkt - BB

  gRxRunningCRC = crcByte(gRxRunningCRC,gpRxBuf[(gRxByteCnt-2)]);
}
gRxByteCnt++;
gRxState = RXSTATE_INFO;
     }
     break;

Note that the receiver unescapes before doing the CRC.
And the transmission:

   case TXSTATE_INFO:
     nextByte = gpTxBuf[gTxByteCnt];

     gTxRunningCRC = crcByte(gTxRunningCRC,nextByte); // CRC- BB
     gTxByteCnt++;
     if (gTxByteCnt >= gTxLength) {
gTxState = TXSTATE_FCS1;
     }

     TxResult = TxArbitraryByte(nextByte); // now escape and Xmit - BB
     break;

Where the TxArbitraryByte function does the escaping:

 result_t TxArbitraryByte(uint8_t inByte) {
   if ((inByte == HDLC_FLAG_BYTE) || (inByte == HDLC_CTLESC_BYTE)) {
     atomic {
       gPrevTxState = gTxState;
       gTxState = TXSTATE_ESC;
       gTxEscByte = inByte;
     }
     inByte = HDLC_CTLESC_BYTE;
   }

Ben

------------------------------







_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to