![](/media/cache/profiles/7c39a5f991bef4a1e34187677a65871d.jpg.50x50_q85.jpg)
Manchester receiver demo.
Dependencies: Manchester mbed CRC16 ManchesterMsg
Diff: main.cpp
- Revision:
- 1:2ce05484e526
- Parent:
- 0:91017f5f5cb3
- Child:
- 2:1cb83aa7b99a
--- a/main.cpp Wed May 17 07:59:46 2017 +0000 +++ b/main.cpp Wed May 17 21:27:02 2017 +0000 @@ -2,27 +2,34 @@ #include "Manchester.h" DigitalOut led(LED1); -Manchester man(p11, p12, 9600); // Tx pin, Rx pin, speed [bps] -ManchesterMsg msg(255); // Message container (max bytes) -char str[255]; // Array of char -uint32_t val; int main(void) { + Manchester man(p11, p12, 9600); // Tx pin, Rx pin, speed [bps] + ManchesterMsg msg(100); // Message container (max bytes) + char str[50]; // Array of char + uint32_t val; + + //pc.baud(9600); while(1) { if(man.receive(msg)) { // Receive message - // Print data length and raw data + // Print data length and raw data bytes printf("\r\n----------------------\r\n"); - printf("len = %d\r\n", msg.len); - printf("raw data :\r\n"); - for(int i = 0; i < msg.len; i++) - printf("\t0x%.2x\r\n", msg.data[i]); - + printf("Length = %d\r\n", msg.len); + printf("Raw data :\r\n"); + 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"); + // Extract data from message and print msg >> str >> val; - printf("data :\r\n"); - printf("\tstr = %s\r\n", str); - printf("\tval = 0x%x\r\n", val); + printf("Extracted data :\r\n"); + printf(" str = %s\r\n", str); + printf(" val = 0x%x\r\n", val); } else printf("Error\r\n");