[ebus-dev] CSMA/CD test code
Werner Koch
wk at gnupg.org
Mon Aug 22 11:59:58 CEST 2011
Hi!
I tinkered a bit with the Elektor Bus hardware and after some
experiments with a Modbus alike protocol I now implemented a CSMA
protocol. It still uses the 16 byte fixed message size but uses an
explicit framing similar to PPP to ease synchronization and to convey
the messages transparently.
The advantage of CMSA for my domotik installation is that it is more
reliable in case of a failed node, does not require a master and sensor
only nodes may fall asleep until a new sensor value shall be sent
(e.g. every few minutes for room temperatures).
The code is written in C using avr-gcc. As an Emacs adept I don't use a
Makefile for this simple code but put the build instructions at the end
of the file. I am currently using 5 nodes for my test; if you use more
you may want to adjust ebusdump.c.
You may checkout the code from a git repo or download the latest version
using these URLS:
The node code:
<http://git.gnupg.org/cgi-bin/gitweb.cgi?p=wk-misc.git;a=blob_plain;f=ebusnode1.c;hb=HEAD>
A utility to show/log what's going on on the bus:
<http://git.gnupg.org/cgi-bin/gitweb.cgi?p=wk-misc.git;a=blob_plain;f=ebusdump.c;hb=HEAD>
Here is the blurb from the file:
Build instructions are at the end of this file. Please make sure
to set the FUSE bits correctly and assign a different node-id to
each node by storing them in the EEPROM.
The tool ebusdump.c may be used on a Unix hosts to display the
stats. Assuming the RS-485 converter is attached to /dev/ttyUSB1
you would do this:
stty </dev/ttyUSB1 speed 9600 raw
./ebusdump </dev/ttyUSB1 --top
Instead of of showing the stats page, ebusdump may also be used to
dump the activity by usingit without the --top option.
This code sends status information to allow analyzing the bus
behaviour under load. The keys S2 and S3 are used to change the
send interval of those messages in discrete steps. With 9600 baud
you will notice many collisions in particular if the interval has
been set down to 25 by pressing the S3 button 4 times; the interval
is shown in the ebusdump output.
In contrast to the original Elektor Bus protocol, this version uses
implements a CSMA/CD protocol with an explicit framing similar to
PPP (RFC-1662). The original 0xAA byte has been replaced by a
protocol ID to allow the use of several protocols on the same bus.
Future work:
- Detect collisions more reliable by adding a CRC to the framing.
- Use correct timings.
- Add a framework to register actual applications.
- Use a simple send queue to allow receiving urgent data.
Shalom-Salam,
Werner
--
Die Gedanken sind frei. Ausnahmen regelt ein Bundesgesetz.
More information about the Ebus-dev
mailing list