Skip to content

Applications

balazsracz edited this page Jun 14, 2014 · 2 revisions

Applications

This page describes the example applications in the OpenMRN source tree. The goal of these applications is to give a starting point to various directions that OpenMRN can be used. They are not full-featured production applications.

Applications can be found under $(OPENMRNPATH)/applications/$(APP_NAME). Different applications may have been ported to different target platforms and boards, if you want to add a port to an existing demo application, or contribute a new test application, feel free to do so!

blink_raw

This application demonstrates the basic portability of OpenMRN's OS abstraction layer. It doesn't bring up any protocol stack, just boots the OS and starts blinking a led (at the rate of 1/second). It is useful as a first target in bringing up a new port of OpenMRN. The sucessful run of blink_raw means the MCU has been set up with the approriate clocks, the flash and memory banks are properly configured, threads can be created and run, as well as the LED driver is working.

This application does not need any drivers.

async_blink

This application blinks a LED controlled by OpenLCB / NMRAnet event protocol. It contains a producer that produces two events alternating at 1/sec rate, and a consumer that turns a LED on/off as these events come in.

The code demonstrates how to

  • bring up the hardware interface layer and the cooperative multitasking scheduler
  • configure a virtual CANbus
  • how to bind it to a physical CANbus (when a driver is present)
  • bring up an NMRAnet interface connected to this CANbus
  • simple event consumer
  • a simple asynchronous state machine that produces alternating events at a fixed rate.

The same code compiles and runs under a variety of targets, from linux to all existing MCU ports of OpenMRN; with physical , USB or virtual CANbus adapters.

usb_can

This application runs on MCUs with CAN and USB port and acts as an adapter between them, using GridConnect protocol on a USB virtual serial port, and transmitting all frames to the physical CAN-bus and reverse.

With such an adapter it is possible to connect a computer to an OpenLCB / NMRAnet bus (or any other CANbus, running at the given speed). The computer should be running an application that can talk to a GridConnect-compatible USB adapter and has the appropriate OpenLCB protocol stack. OpenMRN's applications compiled to the host operating systems are an example, but this also allows JMRI to connect to a physical CAN-bus (choose connection mode "CAN via GridConnect adapter").

hub

This application acts as a TCP/IP-based virtual CAN-bus hub. It runs as a server, listening for incoming connections. Incoming connections automatically create new hub ports. A packet received from any connection will be forwarded to all other connections. There is no inherent limit on the number of connections possible --- it is limited by the amount of memory available to the system and the number of open sockets the system can handle. All connections use the GridConnect CANbus protocol.

JMRI can connect to this hub by choosing "CAN via GridConnect network interface". JMRI can also act as a hub like this by choosing OpenLCB->Start OpenLCB hub.

This application requires an operating system that provides Berkeley socket-compatible TCP/IP API (socket, bind, listen, accept, read, write).

Clone this wiki locally