Difference between revisions of "TinyOS 2 Serial Communication Mechanism port on contiki"
Line 13: | Line 13: | ||
In '''core/dev/serial-line.h''', add the following definition: | In '''core/dev/serial-line.h''', add the following definition: | ||
− | + | #ifdef TINYOS_2X_SERIAL_PACKET | |
− | + | #include "CPSL-tinyos-2x-serial.h" | |
− | + | #endif | |
'''Step 2:''' | '''Step 2:''' | ||
Line 25: | Line 25: | ||
In the function, add the following statements: | In the function, add the following statements: | ||
− | + | #ifdef TINYOS_2X_SERIAL_PACKET | |
tinyos2x_serial_dispatcher(c); | tinyos2x_serial_dispatcher(c); | ||
− | + | #endif | |
Some note about the implementation: | Some note about the implementation: |
Latest revision as of 17:50, 14 September 2017
The source files for the TinyOS 2 serial communication mechanism on contiki:
core/dev/CPSL-tinyos-2x-serial.h core/dev/CPSL-tinyos-2x-serial.c core/dev/CPSL-tinyos2x-serial-header.h
My principle when implement this feature is try not to touch the original contiki source code.
To add the TinyOS 2 serial communication mechanism:
Step 1:
In core/dev/serial-line.h, add the following definition:
- ifdef TINYOS_2X_SERIAL_PACKET
- include "CPSL-tinyos-2x-serial.h"
- endif
Step 2:
In core/dev/serial-line.c, modify the function serial_line_input_byte,
this function is invoked every time a character come in through the serial port.
In the function, add the following statements:
- ifdef TINYOS_2X_SERIAL_PACKET
tinyos2x_serial_dispatcher(c);
- endif
Some note about the implementation:
There are 2 processes in this implementation:
tinyos2x_serial_unescape_process, this process is invoked every time a packet has been
taken out from the byte stream. It will unescape the byte array received.
tinyos2x_serial_ack_send_process, this process is invoked every time unescaping of the
byte array has been done, it will send ack packet to the server.
Send data to the server:
Suppose you have a data array called payload, its length is len. Just pass the data array and its
length to function send_data_to_server in CPSL-tinyos-2x-serial.c. Remember that the data
array only need to contain the payload, all other stuff in the packet will be automatically set
by this function.