As you build a modular system you will implement a lot of variables in each module that you might want to change as part of configuration or see as they are sensor values. To do this I create a separate module called a “Dictionary” that is illustrated below.
The dictionary itself is a large Index table over variables and data you want to interface with a set of standard functionality. The primary interface is CLI over USB or Ehernet – CLI (Command Line Interface) is a text based interface allowing a serial console or TCP client to be your actual interface. Through CLI you can list, set or read all variables in the Dictionary.
Most variables are real-time and can be read/write at you discression.
A protocol like Modbus or CANopen can have their own map on top of the dictionary.
Some dictionary values can be tagged as “persistant” meaning they will be stored on SPI Flash then changed and read back as the system start. This includes Bitrate setting, baudrate settings, switching tables, IP/MAC settings etc – config we want the system to remember.
Data Integrity is also supported in the dictionary. Some protocols like CANopen and Modbus have the capbability to write single variables leaving an Entity (a collection of variables) with broken integrity – so we can protect those and ensure that the module only receive a complete entity.
Sensor arrays/filters are another feature. Some sensors sample faster than we are interested in so we offer techniques to store windows and filter values here rather than forcing every sensor to implement it separately.
And last, but not least – user modules use Dictionary as it’s interface according to a scheme you decide.
The nice thing about the dictionary is that the modules don’t know about it – it is the dictionary who need to know about modules – and to avoid lengthly index searching we can allow IO messages to be mapped, meanuing you do not search the index at all. At module start you can request direct access and store addresses – you can then write/read directly or through safe Dictionary functions.
CLI however will need to search the index always.
RTOS, CLI, Switch and Dictionary is a powerfully start for any embedded application. They do howether come at the price of a minimum of Flash and SRAM.