ArduinoDECADES v3.0 Embedded software

Code to be uploaded to an Arduino UNO.

The firmware boots up and interrogates the SD card for an arddConf.cfg file, so as to set the following:

tcpServerA IP address/port
tcpServerB IP address/port
NTP server IP address/port
UDP multicast address/port

The firmware then connects to both TCP servers and the NTP server and synchronises the internal clock.
A file is opened on the SD card for backup logging of data (outwith the DECADES system).
The firmware then listens on the predefined UDP multicast address/port for packets from the same subnet so as to extract the flight number from one of the core DECADES instruments. It collects 3 consecutive samples with matching flight numbers before declaring the flight number valid and moving into LOOP mode to collect data. A timeout of 5 minutes is provided, such that if a flight number is not obtained after this time, the firmware moves into LOOP mode irrespective.

In LOOP mode, the firmware continually polls the internal clock to check the if the sample period has elapsed, after which samples are taken from the ADC channels 0 and 1. The difference between these two samples is stored to SD card and transmitted to both TCP servers and over UDP multicast.
  A check is made to how many samples previously the internal clock was synced to NTP and if this has extended past the sync period, an NTP request is made to resync. This request itself has a timeout so as to ensure the system remains responsive to data collection. The processor clock itself was found to be inaccurate with significant drift and therefore a resync period of ~10s is appropriate.

The algorithm used to sync to NTP takes no account for the additional round trip delay. This was considered unneccessarily complex to calculate given:
i) the NTP server for DECADES is on the same subnet and therefore round trip delay is of the order of millisecs; and
ii) the sample period being used is 1s which is two orders of magnitude greater than the round trip delay.

The serial terminal can be used to follow the firmware progress with additional debug data. This data is self explanatory.