Search code examples
linuxnetwork-programmingudpxbee

Carriage return (0X0D) between data sent over Xbee S1 modules


I'm trying to send the following hexadecimal block of data:

45,  0,  0, 63,  0,  0, 40,  0, 40, 11, 6E, DC,  A,  0,  0,  1, C0, A8,  1,  5, 9D, B3, 22, B8,  0, 4F, 2E, 47, 61, 62, 63, 64, 65, 66, 67, 68, 69, 6A, 6B, 6C, 6D, 6E, 6F, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 7A, 61, 62, 63, 64, 65, 66, 67, 68, 69, 6A, 6B, 6C, 6D, 6E, 6F, 70, 71, 72, 73, 74, 61, 62, 63, 64, 65, 66, 67, 68, 69, 6A, 6B, 6C, 6D, 6E, 6F, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79

Which is originally a UDP packet over Xbee S1 module to another Xbee S1 module

When I read the received block of data using X-CTU the received data is:

45 00 00 63 00 00 40 00 40 11 6E DC 0D

0A 00 00 01 C0 A8 01 05 9D B3 22 B8 00 4F 2E 47 61 62 63 64 65 66 67 68 6A 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79 7A 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 71 72 73 74 61 62 63 64 65 66 67 68 69 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79  

Note the Bold byte (0D) which is not related to the sent data?

Any one can guess the reason? is it the configurations?

Xbees working in the transparent mode.


Solution

  • the problem was in the "ONLCR and OCRNL" flags of the termios.c_oflag structure, which translate any newline character "0A hex" to carriage return character "0D hex", so, if one send "0A hex" over the serial port, the port will send 0D 0A instead, if the above mentioned flags value was 1.

    The solution was by set these flags value to zero.

    struct termios options;
    options.c_oflag &= ~(ONLCR | OCRNL);
    

    for more information refer to the termios manpage: [http://man7.org/linux/man-pages/man3/termios.3.html][1]