Software/loconetd/UDP Loconet |
The Loconet protocol was developed by Digitrax, Inc. to interconnect throttles and other devices to their digital command and control (DCC) command station for use on model railroads. This protocol uses standard low-speed asynchronous serial interfaces such as the PC serial port augmented with a multidrop "wired-or" modulation scheme, an access arbitration protocol and a message set. The protocol is proprietary, but Digitrax did publish a subset under the title "LOCONET Personal Use Edition," which can be found here.
Interfacing to Loconet has been somewhat daunting to the hobbyist. The protocol does not cleanly separate the functions of layers 1-3 of the ISO Reference Model, which makes it difficult to modularize and abstract some of its complexities. Additionally, the access arbitration protocol requires millisecond precision timing, which can be hard to achieve in a multitasking operating system. Early on, John Kabat produced a Loconet driver, Locont1, for the IBM PC that presented a software interrupt interface and a somewhat abstracted set of operations from the message formats; it can be found here. This library is tightly tied to the IBM PC. Locont1 and a few other interfaces within the confines of commercial model railroad control software packages were until recently the only alternatives short of from-scratch development for hobbyists to interface to Loconet. Recently, John Jabour has developed a module that tackles the hardest part of Locnet: access arbitration. His Locobuffer allows any computer with a serial port to deliver raw Loconet packets for buffering and transmission on a connected Loconet. Documentation on Locobuffer can be found here.
The Locobuffer opened up the Loconet, IMHO. Particularly, it allowed me to start thinking about how to interface Loconet to other protocols, particularly TCP/IP. I've always been a fan of transaction-based protocols like HTTP, where a single TCP connection was used to accomplish a single action e.g., retrieve a web page. For control applications, this sort of client-server model has a lot of advantages, not the least being that TCP will queue connect requests, eliminating the need for locks and other mechanisms to arbitrate multiple simultaneous accesses. I wrote such a server a few years ago in anticipation of building a Centralized Traffic Control (CTC) system for my model railroad. With it, I could write clients that displayed the railroad and updated block occupancy, turnout status, etc., in real-time, as well a train simulators that would "travel" over the railroad presented by the server. A lot of fun to program, very educational experience regarding client-server apps, but it really amounted to no more than a curiosity.
Where I work, we use the User Datagram Protocol, or UDP, to forward radar and telemetry data to network subscribers. Paricularly, we use UDP multicast to do this, as multiple receivers can get the data without having to code the server to manage individual connections. This application really hit home with Loconet, for there are a number of Loconet applications (fast clock, for one) that could benefit from a simple way to deliver updates to a large number of clients. So I set out to develop a gateway program that took Loconet packets, stuck them in UDP datagrams, and sent them to a multicast group. Conversely, it would receive UDP datagrams, pull out their contents and forward it on Loconet as a valid packet. This program, written for Linux, (will probably work on other Unixes), can be found here.
Gatewaying Loconet to UDP is quite simple; the full Loconet packet, including checksum, is simply wrapped in a UDP datagram. There are no other payload fields. The specifics for doing this currently lie in the selection of ports and addresses; the current loconetd uses multicast group 225.0.0.2 and port 4501. loconetd can also be set up to do simple UDP broadcast on a single subnet using the same port. UDP clients who want to forward Loconet packets simply wrap valid Loconet packets including checksum in a UDP datagram and send them to the machine running the loconetd gateway, which is listening for them on port 4500. These group and port numbers were picked arbitrarily from the numbers >1024 in order to stay away from well-know services.
loconetd is my reference implementation of the Loconet/UDP gateway protocol. It can be configured to gateway Loconet to either UDP mulicast, simple UDP broadcast, or both. It is .conf file configurable, and will also log packet receipt for debugging.
The mulicast group is statically identified in the configuration file; however deployment of multicast networks to date has established conventions where sessions are assigned group numbers when they are scheduled, and the group number is valid until the session expires. To work in this concept, loconetd would have to interact with sdr, the standard UDP multicast session scheduling tool; this modification is not currently planned.
A lot of flexibility will be gained by gatewaying Loconet to the Internet. I happen to believe that a UDP solution is the cleanest way to do this, and I proved it to myself in implementing and using loconetd. However, I do not see any Loconet gateway being commercially fielded until the Loconet protocol is modified to eliminate dependence on direct knowledge of the network state to arbitrate transaction integrity.
Version 1, 3 December, 2002
Contact me at: