#include "regConfig.hpp"
#include "regEntries.hpp"
#include "regDescriptors.hpp"
#include "sampleConfig.hpp"

int main(int argc, const char *argv[])
{
   CRegConfig <uint8_t> conf(0x100);
   //, regEntries);

   SSettingDesctriptor *d=descriptors;

   conf.setSetting( RESequencerOff, ESequencerOff::SequencerOn);
   conf.setSetting( REListenOn, EListenOn::ListenOff);
   conf.setSetting( REMode, EMode::Standby);
   conf.setSetting( REDataMode, EDataMode::PacketMode);
   conf.setSetting( REModulationType, EModulationType::FSK);
   conf.setSetting( REModulationShaping, EModulationShaping::None);
   conf.setSetting( REBitRateMsb, EBitRateMsb::_55555);
   conf.setSetting( REBitRateLsb, EBitRateLsb::_55555);
   conf.setSetting( REFdevMsb, EFdevMsb::_5000Hz );
   conf.setSetting( REFdevLsb, EFdevLsb::_5000Hz );
   conf.setSetting( REFrfMsb, EFrfMsb::_868Mhz );
   conf.setSetting( REFrfMid, EFrfMid::_868Mhz );
   conf.setSetting( REFrfLsb, EFrfLsb::_868Mhz );
   conf.setSetting( REDccFreq, 0b010 );
   conf.setSetting( RERxBwMant, ERxBwMant::M16);
   conf.setSetting( RERxBwExp, 2);
   conf.setSetting( REDio0Mapping, 1);
   conf.setSetting( REClkOut, EClkOut::Off);
   conf.setSetting( REFifoOverrun, 1);       // writing to this bit ensures that the FIFO & status flags are reset
   conf.setSetting( RERssiThreshold, 220);
   conf.setSetting( RESyncOn, ESyncOn::SyncOn);
   conf.setSetting( REFifoFillCondition, EFifoFillCondition::Auto);
   conf.setSetting( RESyncSize, ESyncSize::_2Bytes);
   conf.setSetting( RESyncTol, 0);
   conf.setSetting( RESyncValue1, 0x2D);
   conf.setSetting( RESyncValue2, 0x3C);
   conf.setSetting( REPacketFormat, EPacketFormat::Variable);
   conf.setSetting( REDcFree, EDcFree::None);
   conf.setSetting( RECrcOn, ECrcOn::CrcOn);
   conf.setSetting( RECrcAutoClearOff, ECrcAutoClearOff::AutoClearOn);
   conf.setSetting( REAddressFiltering, EAddressFiltering::None);
   conf.setSetting( REPayloadLength, 66);
   conf.setSetting( RETxStartCondition, ETxStartCondition::FifoNotEmpty);
   conf.setSetting( REFifoThreshold, 0x0F);
   conf.setSetting( REInterPacketRxDelay, EInterPacketRxDelay::Delay2Bits);
   conf.setSetting( REAutoRxRestartOn, EAutoRxRestartOn::RestartOn);
   conf.setSetting( REAesOn, EAesOn::AesOff);
   conf.setSetting( REContinuousDagc, EContinuousDagc::ImprovedMargin_LowBeta0);

   /*
   conf.data()[ RegOpMode ] = conf.plainSetting( RESequencerOff, ESequencerOff::SequencerOn)
                            | conf.plainSetting( REListenOn, EListenOn::ListenOff)
                            | conf.plainSetting( REMode, EMode::Standby);
   */

   //conf.setDescriptors( descriptors );
   conf.dumpConfig( descriptors, descriptorCount );

   int i1=0;
   for(; CONFIG[i1][0]<255; i1++)
   {
      if( CONFIG[i1][1] != conf.data()[ CONFIG[i1][0] ] )
      {
         printf("Missmatch: Reg 0x%X: 0x%X vs 0x%X\n", CONFIG[i1][0],
               CONFIG[i1][1], conf.data()[ CONFIG[i1][0] ] );
      }
   }

   return(0);
}

