#ifndef CANDIS_STRUCTS_H
#define CANDIS_STRUCTS_H
//----------------------------------------------------------------------------
///
/// \brief   Structures for mainswitch
///
///          -
///
/// \date   20240910
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

#include <campo/hwinfo_v5.h>
#include <biwak/retain.h>        // RETAIN_HEADER_SIZE


//---Declaration--------------------------------------------------------------


// vagus will check for this to verify the correct header
#define VAGUS_STRUCTS

#define CONFIG_LAYOUT_MAJOR               3
#define CONFIG_LAYOUT_MINOR               0

enum class EInterface : uint8_t
{
   Usb=0,
   Can=1,
   EntriesCount,
};

inline EInterface operator++ (EInterface& e) {
    e = static_cast<EInterface>((static_cast<int>(e) + 1) % static_cast<int>(EInterface::EntriesCount) );
    return e;
}

struct SEepromConfigCustom: SEepromConfigBase
{
   // #0
      EInterface  interface;
      struct
      {
          bool        periodicSyncRtc  : 1;
          bool        screensaver      : 1;
          bool        totalOff         : 1;
      } fields;
      //uint8_t     reserved1[2];
      //uint16_t    bootCounter;
      //uint16_t    nodeId;
   // #6
      uint16_t    buddies[3];
   //#12
      uint8_t     buddies_index[3];
      uint8_t     reserved1[1];
   //#16
      uint32_t    operatingTime;
   //#20
      char reserved[ 0x20 - RETAIN_HEADER_SIZE - ( 3 * 2 ) - ( 3 * 3 ) - 1 - ( 1 * 4 ) ];

      void dump() const;
      #if 0
      void dump() const
      {
         lInfo(" Intf   : %s", interface == EInterface::Usb ? "USB" : "CAN");
         lInfo(" Snc-RTC: %d", fields.periodicSyncRtc);
         lInfo(" Scrsvr : %d", fields.screensaver);
         lInfo(" Tot-Off: %d", fields.totalOff);
         lInfo(" Node-ID: %d", nodeId);
         lInfo(" Buddy0 : %d", buddies[0]);
         lInfo(" Buddy1 : %d", buddies[1]);
      }
      #endif

} __attribute ((packed));


/*
struct SEepromBoardConfig: SEepromBoardBase
{
   char reserved[ 0x20 - ( 4 ) ];
} __attribute ((packed));
*/

/*
struct SEepromHwData
{
   SEepromBoardInfo boardInfo;
   SEepromBoardConfig boardConfig;
} __attribute ((packed));
*/

//static_assert( sizeof( SEepromConfig ) == ( 0x20 - 0xC ) );
static_assert( sizeof(SEepromHwData) == ( 0x40 - 0xC ) );


//---fin----------------------------------------------------------------------
#endif // ? ! CANDIS_STRUCTS_H
