multihop protocol
Dependencies: mbed
Diff: remote.cpp
- Revision:
- 4:024e613151a5
- Parent:
- 3:1b37d57a4e41
- Child:
- 5:387b2ebf6b91
--- a/remote.cpp Tue Nov 10 23:00:05 2015 +0000 +++ b/remote.cpp Tue Nov 10 23:09:18 2015 +0000 @@ -26,6 +26,8 @@ char rxBuffer[128]; int rxLen; +packet buffer; + //***************** Do not change these methods (please) *****************// /** @@ -34,26 +36,25 @@ * @param data A pointer to a char array to hold the data * @param maxLength The max amount of data to read. */ -int rf_receive(char *data, uint8_t maxLength) +int rf_receive(packet *data, uint8_t maxLength) { uint8_t len = mrf.Receive((uint8_t *)data, maxLength); - uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00}; + - if(len > 10) { - //Remove the header and footer of the message - for(uint8_t i = 0; i < len-2; i++) { - if(i<8) { - //Make sure our header is valid first - if(data[i] != header[i]) - return 0; - } else { - data[i-8] = data[i]; - } + if(len > 4) { + //valid data with full header + if(data.to != NODE) + { + //throw out the data + return 0; } - + pc.printf("Received data for us from node: %d\r\n",data.from); + //pc.printf("Received: %s length:%d\r\n", data, ((int)len)-10); } - return ((int)len)-10; + + + return ((int)len); } /** @@ -63,10 +64,8 @@ * @param maxLength The length of the data to send. * If you are sending a null-terminated string you can pass strlen(data)+1 */ -void rf_send(char *data, uint8_t len) +void rf_send(packet *data, uint8_t len) { - //We need to prepend the message with a valid ZigBee header - uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00}; uint8_t *send_buf = (uint8_t *) malloc( sizeof(uint8_t) * (len+8) ); for(uint8_t i = 0; i < len+8; i++) {