![](/media/cache/profiles/7c39a5f991bef4a1e34187677a65871d.jpg.50x50_q85.jpg)
Manchester receiver demo.
Dependencies: Manchester mbed CRC16 ManchesterMsg
Diff: main.cpp
- Revision:
- 4:649d9a4219c0
- Parent:
- 3:0c6680f77855
- Child:
- 5:3dc7d8e25c89
diff -r 0c6680f77855 -r 649d9a4219c0 main.cpp --- a/main.cpp Thu May 18 11:07:36 2017 +0000 +++ b/main.cpp Sun May 21 19:28:00 2017 +0000 @@ -10,43 +10,43 @@ char str[80]; // Storage for the received array of char uint32_t val; // Storage for the value received CRC16 crc16; // CRC16 object - unsigned short msgCRC16; // CRC16 received in message + unsigned short recvCRC16; // CRC16 received in the message unsigned short calcCRC16; // CRC16 calculated //pc.baud(9600); while(1) { if(man.receive(msg)) { // Receive message + // Print data length and raw data bytes - printf("\r\n----------------------\r\n"); - printf("Length = %d\r\n", msg.len); - printf("Raw data :\r\n"); + printf("\r\n----------------------------------------\r\n"); + printf("Message length = %d, Raw data :\r\n", msg.len); for(size_t i = 0; i < msg.len; i++) { if((i + 1) % 10 == 0) printf(" %.2x\r\n", msg.data[i]); else printf(" %.2x", msg.data[i]); } - printf("\r\n"); + printf("\r\n\r\n"); - // Calculate CRC16 (CRC bytes are excluded from calculation) + // Calculate CRC16 (exclude CRC bytes (last two bytes) from calculation) calcCRC16 = crc16.calc(msg.data, msg.len - 2); // Extract data and CRC16 from the message - msg >> str >> val >> msgCRC16; + msg >> str >> val >> recvCRC16; - printf("msgCRC16 = %d\r\n", msgCRC16); - printf("calcCRC16 = %d\r\n", calcCRC16); + printf("Calculated CRC16 = %d\r\n", calcCRC16); + printf("Received CRC16 = %d\r\n", recvCRC16); + printf("\r\n"); - if( calcCRC16 != msgCRC16) { - printf("CRC error\r\n"); - } - else { - printf("Extracted data :\r\n"); + if( calcCRC16 = recvCRC16) { + printf("Received data :\r\n"); printf(" str = %s\r\n", str); printf(" val = 0x%x\r\n", val); } + else + printf("CRC error\r\n"); } else printf("Error\r\n");