NCE Controller interface

As the NCE Controller interfaces via a serial device the RXTX library was used to create the connection.  This requires the binary runtimes to be installed this is quite a simple process on debian based operating systems like that of raspbian on the raspberry pi.  This is simply installed via the apt command as follows:

sudo apt-get install librxtx-java

The NCE interface is then created by creating an NCE message processor this processes the internal message types into NCE implementation runner versions of them, the NCE implementation when run converts the internal data to a packet of data to be sent across the serial interface to the NCE controller.  Once the NCE controller has processed the data packet sent it returns data back across the serial interface.  The NCE implementation then converts the NCE data back to an internal format and returns this back to the core services.

Further interfaces to controllers can be created in a similar fashion simply by adding a message processor implementation for the controller and then creating the controller specific message types to convert the internal types to send the data to the controller.

Interfacing with controllers

The interface to the controllers is based on sending a message to be processed by a message processor of the controller type.

The messages passed to the message processor contain only the information in order to complete an action.  This information is in an internal data format.  Each message processor then processes the information into packets of data to be sent to the controller over the interface device of the controller.

If there is any data to be sent back from the controller the data is read by the processor, processed and returned in an internal format.

Using this process the implementation is contained only withing the controller implementation of the message processor.

For example the steps to read a CV from a decoder using program track mode would be completed using the following steps:

  1. Send the message processor a “Enter Program Mode” message.
  2. Send the message processor a “Read CV” message requesting the CV number.
  3. The “Read CV” message returns the value contain in the decoders CV.
  4. Repeating the steps for each CV to be read.
  5. Send the message processor a “Exit Program Mode” message.

In a similar manner messages are sent to the message processor to set the speed and direction of locos, set decoder functions on or off or setting accessories etc.

Initial Design

The aim of the DCC web application was to create a web base application that could run on a raspberry pi and interface with a DCC controller and allow the controller of locos and accessories.

OK This does sound a lot like JMRI but I found that JMRI did not have some features that I wanted to include, I did try looking at the java code to see if I could implement the features that I wanted within JMRI but found the architecture that JMRI to be a little bit…  Lets just say I decided to start from scratch.

So first things first I decided on the frameworks that should be used to create the application.

Spring boot was an obvious choice for dependency injection and the Restful services.

For the web interface I choose AnguarJS and bootstrap for the css framework.  Not long after starting Angular 2 was released and so I quickly decided that interface should be moved to using the newer Angular 2 and write the interface code using typescript rather than javascript.

So for the database I decided on using a basic derby database with a spring JPA implementation.  The reason behind the basic derby database was to keep the installation to a bare minimum without the need to setup mysql or similar on the raspberry pi before installing the web application.

To build the application and run the unit tests I decided on the tried and trusted Maven.  As for the the unit tests these are written using JUnit4 and also utilise Mockito to mock objects that are not being tested in individual tests.

Finally Jenkins to automate builds and run the static analysis which I decided to use SonarQube to keep an eye on the code quality and the unit test coverage.

And that pretty much covers the initial design decisions.