     TIME_LSD = OTV0P2BASE::getSecondsLT();
 }
 
-//========================================
-// MAIN LOOP
-//========================================
+
+/******************************************************************************
+ * MAIN LOOP
+ *****************************************************************************/
+
 void loop()
 {
     stackCheck();

    // and which should also allow some energy-saving sleep.
    if(OTV0P2BASE::CLI::isCLIActive()) {
        const uint8_t stopBy = nearOverrunThreshold - 1;
        char buf[BUFSIZ_pollUI];
        OTV0P2BASE::ScratchSpace s((uint8_t*)buf, sizeof(buf));
        pollCLI(stopBy, 0 == TIME_LSD, s);
    }
}

#undef OTSIM900LINK_SUBCYCLE_SEND_TIMEOUT_TEST
 */

/******************************************************************************
 * INCLUDES
 *****************************************************************************/

////// GLOBAL flags that alter system build and behaviour.

// If defined, do extra checks and serial logging.  Will take more code space and power.
#undef DEBUG

// *** Global flag for REVx configuration here *** //
// e.g.
#define V0p2_REV 10

// --------------------------------------------
// I/O pin allocation and setup: include ahead of I/O module headers.
#include <OTV0p2_Board_IO_Config.h>


////// MAIN LIBRARIES

#include <Arduino.h>
#include <OTV0p2Base.h>
#include <OTRadioLink.h>


////// ADDITIONAL LIBRARIES/PERIPHERALS

#define RFM23B_IRQ_CONTROL  // Enable RFM23B IRQ control code.
#include <OTRFM23BLink.h>
#include <OTSIM900Link.h>
#include <OTAESGCM.h>


////// ADDITIONAL USER HEADERS

#include "secondaryRadioConfig.h"  // IP address in separate header to avoid accidentally committing.

/******************************************************************************
 * GENERAL CONSTANTS AND VARIABLES
 * Core constants and variables required for V0p2 loop.
 *****************************************************************************/
// Controller's view of Least Significant Digits of the current (local) time, in this case whole seconds.
// TIME_LSD ranges from 0 to TIME_CYCLE_S-1, also major cycle length.
static constexpr uint_fast8_t TIME_CYCLE_S = 60;
// Controller's notion/cache of seconds within major cycle.
static uint_fast8_t TIME_LSD;

// Send the underlying stats binary/text 'whitened' message.
// This must be terminated with an 0xff (which is not sent),
// and no longer than STATS_MSG_MAX_LEN bytes long in total (excluding the terminating 0xff).
// This must not contain any 0xff and should not contain long runs of 0x00 bytes.
// The message to be sent must be written at an offset of STATS_MSG_START_OFFSET from the start of the buffer.
// This routine will alter the content of the buffer for transmission,
// and the buffer should not be re-used as is.
//   * doubleTX  double TX to increase chance of successful reception
//   * RFM23BfriendlyPremable  if true then add an extra preamble
//     to allow RFM23B-based receiver to RX this
// This will use whichever transmission medium/carrier/etc is available.
static constexpr uint8_t RFM22_PREAMBLE_BYTES = 5; // Recommended number of preamble bytes for reliable reception.
static constexpr uint8_t RFM22_SYNC_MIN_BYTES = 3; // Minimum number of sync bytes.
static constexpr uint8_t STATS_MSG_START_OFFSET = (RFM22_PREAMBLE_BYTES + RFM22_SYNC_MIN_BYTES);
static constexpr uint8_t STATS_MSG_MAX_LEN = (64 - STATS_MSG_START_OFFSET);

// 'Elapsed minutes' count of minute/major cycles; cheaper than accessing RTC and not tied to real time.
// Starts at or just above zero (within the first 4-minute cycle) to help avoid collisions between units after mass power-up.
