SLIPstream

Version 22 (Anthony Rowe, 07/18/2007 04:46 pm)

1 2 Anthony Rowe
[[Image(slip-stream-car.png)]]
2 3 Anthony Rowe
3 12 Anthony Rowe
SLIPstream is an emerging standard in sensor networks for IP to sensor node gateway communication. The SLIPstream program allows for terminal style debugging with a transparent bi-directional packet based communication channel.  The SLIPstream server is written in C and should be easily executable on any embedded or desktop Unix based platform.  In its most basic form, the SLIPstream server can act as a terminal program that displays debugging serial messages from a gateway node.  The SLIPstream server also acts as a UDP server that allows PC programs to connect to the socket for datagram communication to a set of SLIP based functions running on the gateway node.  Unlike a simple serial to socket forwarder, the SLIP protocol allows for framing and checksumming of datagram packets going into and out of a sensor node.  Since SLIP packets have special ESC characters, this can co-exist with normal debug messages that transmit ASCII readable text.  UDP packets sent to the SLIPstream server are forwarded on to the node, and any SLIP replies from the node are passed back to the UDP client.  Below is a block diagram showing the components in the architecture:
4 4 Anthony Rowe
5 3 Anthony Rowe
[[Image(block-diagram.png)]]
6 3 Anthony Rowe
7 15 Anthony Rowe
SLIPstream uses a modified version of the SLIP (serial line IP) protocol described [http://tools.ietf.org/html/rfc1055 here].  Since we want the system to interact with normal debugging messages, we have added a <START> escape character as well as a checksum and length field.  The maximum transmission unit (MTU) is 127 bytes to match the MTU for the wireless network.  The checksum and size are 7bit values so that they can never be confused with an ESC control sequence.  To avoid synchronization errors, all control codes that appear in the SLIP data payload section are wrapped in escape sequences.  Below is a diagram of the SLIP data format which is used internally by SLIPstream and the Nano-RK slip functions:
8 5 Anthony Rowe
9 3 Anthony Rowe
[[Image(SLIP-packet.png)]]
10 6 Anthony Rowe
11 7 Anthony Rowe
There are three main components to SLIPstream.  First there is the SLIPstream server which can be found in the nano-RK/tools/SLIPstream/SLIPstream-server directory.  Second, there is the SLIP module that runs in Nano-RK on the sensor node. This provides your sensor node application with a slip_tx() and slip_rx() function. Lastly, there is a sample UDP client application which would likely be customized for your particular application that can be fond in the nano-RK/tools/SLIPstream/SLIPstream-client directory.
12 9 Anthony Rowe
13 13 Anthony Rowe
= Nano-RK APIs =
14 13 Anthony Rowe
15 14 Anthony Rowe
This section describes the Nano-RK related function calls that can be used with SLIPstream.  When adding SLIP to an application, '''it is important to address the following in your nrk_cfg.h''':
16 13 Anthony Rowe
17 16 Anthony Rowe
 * #define the correct SLIP_PCP_CEILING value
18 16 Anthony Rowe
  * This must be set to the priority of the highest priority task that calls printf() or uses the serial port.  This priority is inherited by the task that calls slip_tx() so that no other serial traffic goes into the SLIP packet.  If in doubt, set this to a very high priority.  However, be careful that it is not higher than something important like the network link layer.
19 13 Anthony Rowe
 * #define NRK_UART_BUF   1
20 13 Anthony Rowe
 * #define MAX_RX_UART_BUF 128
21 13 Anthony Rowe
 * Increase NRK_MAX_RESOURCE_CNT by 1
22 13 Anthony Rowe
  * This semaphore is used to block multiple tasks from using slip_tx() at the same time.  Typically it is a good idea to keep slip_tx() and slip_rx() localized in one area.
23 13 Anthony Rowe
 * SLIP does not increase the task count in the system
24 13 Anthony Rowe
25 13 Anthony Rowe
{{{
26 13 Anthony Rowe
#!c
27 13 Anthony Rowe
// This must be greater than or equal to the highest priority task that uses
28 13 Anthony Rowe
// the serial port (i.e. print of nrk_kprintf)
29 13 Anthony Rowe
#define SLIP_PCP_CEILING                18     
30 13 Anthony Rowe
 	
31 13 Anthony Rowe
// Enable buffered and signal controlled serial RX
32 13 Anthony Rowe
#define NRK_UART_BUF                    1
33 13 Anthony Rowe
// Set buffer to MAX slip packet size.
34 13 Anthony Rowe
// This could be smaller than 128 if you are careful.
35 13 Anthony Rowe
#define MAX_RX_UART_BUF                 128
36 13 Anthony Rowe
37 13 Anthony Rowe
// Slip uses a single semaphore to control UART access
38 13 Anthony Rowe
#define NRK_MAX_RESOURCE_CNT            2
39 13 Anthony Rowe
}}}
40 13 Anthony Rowe
41 13 Anthony Rowe
42 13 Anthony Rowe
'''slip_init (stdin, stdout, 0, 0)'''
43 13 Anthony Rowe
44 13 Anthony Rowe
'''int8_t slip_started ()'''
45 13 Anthony Rowe
46 17 Anthony Rowe
'''int8_t slip_tx (uint8_t *buf, uint8_t len)'''
47 13 Anthony Rowe
48 13 Anthony Rowe
'''int8_t slip_rx (uint8_t *buf, uint8_t max_len)'''
49 13 Anthony Rowe
50 13 Anthony Rowe
= UDP Client APIs =
51 10 Anthony Rowe
52 19 Anthony Rowe
The following API can be used after including "slipstream.h" in any standard C program running under Unix.  For more information see the [http://www.nanork.org/nano-RK/browser/nano-RK/tools/SLIPstream/SLIPstream-client SLIPstream-client project].  These functions are wrappers around UDP messages.  For an example of using raw UDP see the [http://www.nanork.org/nano-RK/browser/nano-RK/tools/SLIPstream/SLIPstream-client-UDP SLIPstream-client-UDP project].
53 18 Anthony Rowe
54 18 Anthony Rowe
'''int slipstream_open(char *address,int port,int blocking)'''
55 18 Anthony Rowe
56 18 Anthony Rowe
'''int slipstream_send(char *buf,int length)'''
57 18 Anthony Rowe
58 18 Anthony Rowe
'''int slipstream_receive( char *buf)'''
59 18 Anthony Rowe
60 18 Anthony Rowe
61 10 Anthony Rowe
= Testing SLIPstream =
62 10 Anthony Rowe
63 10 Anthony Rowe
The following section shows how to run the SLIPstream sample program.  This example sends normal printf() statements to the SLIPstream terminal program while periodically sending SLIP messages.  It also echos any received SLIP messages over the normal terminal so that you can verify the reception.  The UDP client program prints out any received SLIP messages and periodically transmits its own SLIP messages that are received and printout out by the sensor node.
64 10 Anthony Rowe
65 10 Anthony Rowe
66 10 Anthony Rowe
'''Sensor Node SLIP sample program'''
67 10 Anthony Rowe
68 10 Anthony Rowe
69 9 Anthony Rowe
'''SLIPstream Server'''
70 9 Anthony Rowe
71 9 Anthony Rowe
To compile SLIPstream server do the following:
72 9 Anthony Rowe
73 9 Anthony Rowe
{{{
74 9 Anthony Rowe
 user:> cd nano-RK/tools/SLIPstream/SLIPstream-server
75 9 Anthony Rowe
 user:~/nano-RK/tools/SLIPstream/SLIPstream-server> make
76 9 Anthony Rowe
 gcc -c -o main.o main.c -I.
77 9 Anthony Rowe
 gcc -o SLIPstream main.o -I.
78 9 Anthony Rowe
 user:~/nano-RK/tools/SLIPstream/SLIPstream-server>
79 9 Anthony Rowe
}}}
80 9 Anthony Rowe
81 9 Anthony Rowe
To test the SLIPstream server type:
82 9 Anthony Rowe
83 9 Anthony Rowe
{{{
84 9 Anthony Rowe
 ./SLIPstream /dev/ttyUSB0 4000
85 9 Anthony Rowe
  opening: /dev/ttyUSB0
86 9 Anthony Rowe
}}}
87 10 Anthony Rowe
88 11 Anthony Rowe
In this case, the serial port is /dev/ttyUSB0 and the server is listening on port 4000.
89 11 Anthony Rowe
90 10 Anthony Rowe
91 10 Anthony Rowe
'''SLIPstream Client Sample'''
92 20 Anthony Rowe
93 20 Anthony Rowe
94 20 Anthony Rowe
95 21 Anthony Rowe
= Important Notes =
96 20 Anthony Rowe
97 22 Anthony Rowe
 * FireFly 2 (not 2_2) boards required reduced baudrates to correctly receive data.  At full speed, the CRC will fail and slip_rx() will never return.
98 20 Anthony Rowe
 * Make sure to manage flow control going into the boards.  Your PC based UDP program can generate data much faster than the node can consume it.  Typically you should use an application level acknowledge and timeout scheme to deal with flow control.