David Lakata / Receiver

Dependents:   QuadTrio

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers receiver.cpp Source File

receiver.cpp

00001 #include "mbed.h"
00002 #include "MRF24J40.h"
00003 
00004 /**
00005 * Receive data from the MRF24J40.
00006 *
00007 * @param mrf, RF tranceiver to link with
00008 * @param data A pointer to a char array to hold the data
00009 * @param maxLength The max amount of data to read.
00010 */
00011 int rf_receive_rssi(MRF24J40 mrf, char *data, uint8_t *rssi, uint8_t maxLength) {
00012     uint8_t len = mrf.Receive_RSSI((uint8_t *)data, rssi, maxLength);
00013     uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00};
00014 
00015     if(len > 10) {
00016         //Remove the header and footer of the message
00017         for(uint8_t i = 0; i < len-2; i++) {
00018             if(i<8) {
00019                 //Make sure our header is valid first
00020                 if(data[i] != header[i])
00021                     return 0;
00022             } else {
00023                 data[i-8] = data[i];
00024             }
00025         }
00026         //pc.printf("Received: %s length:%d\r\n", data, ((int)len)-10);
00027     }
00028     return ((int)len)-10;
00029 }