#Node SerialBuster
A protocol for communicating between several nodes on a single serial bus. This protocol is mainly developed for an RS485 network with one master and a number of slave devices.
The library uses https://github.com/voodootikigod/node-serialport for underlying communication.
##Protocol structure
Chunk | Item | Type | Length | Example | Note |
---|---|---|---|---|---|
0 | Start | uint8 | 1 | 0x02 | Signals start of package |
1 | Recipient | uint8 | 1 | 0x01 | Recipient address `0xFF` for broadcast |
2 | Sender | uint8 | 1 | 0x02 | Sender address `0x00` for master |
3 | Length | uint16 | 2 | Length of payload (excluding headers) | |
4 | Payload | uint8[] | N | Hello world! | Any (binary safe) data |
5 | CRC8 | uint8 | 1 | Checksum of header and payload | |
6 | End | uint8 | 1 | 0x03 | Signals end of package |
To send a message to all listening clients use the BROADCAST
address 0xFF
.
The master device has address MASTER
or 0x00
.
A very lightweight 8bit checksum is calculated for the header + payload data in the envelope. Packages that aren't valid gets dropped. CRC8 is calculated before the packet contents have be escaped. Everything but the start and end bytes are escaped.
var serialbuster = require('serialbuster');
var my_node_address = serialbuster.CONSTANTS.MASTER;
var serial = new serialbuster.SerialBuster('/dev/tty.usbserial-A800f7Vn', {
'baudrate' : 9600
, 'parser' : serialbuster.parser(my_node_address)
, 'buffersize' : 1024
});
// Give the serial connection some time to
// get established after it's first created
setTimeout(function() {
var packet = new serialbuster.Packet({
'recipient' : serialbuster.CONSTANTS.BROADCAST // send to all nodes
, 'sender' : my_node_address
});
packet.setPayload("Hello everyone! \n\nlove, master");
serial.sendPacket(packet);
}, 2000);
npm install git+https://github.com/breakfastny/node-serialbuster
make test
Perform DNS lookup before connecting to TCP socket. Also preventing clients from writing data to a closed TCP socket.