probeSettings method

void probeSettings(
  1. int base
)

Get settings from the provided file. This is used to check if the generated data was correct.

Implementation

void probeSettings(int base){
  logger?.verbose('Probing for Settings');
  // Unpack CRC and version
  String fmt = '<I';
  int crc = Struct.unpack(fmt,ihex.getsAsList(base + 0, 4)) & 0xffffffff;
  int ver = Struct.unpack(fmt,ihex.getsAsList(base + 4, 4)) & 0xffffffff;

  BLDFUSettingsStructV1 setts;
  if (ver == 1){
    setts = BLDFUSettingsStructV1(base,true);
  }
  else if (ver == 2){
    setts = BLDFUSettingsStructV2(base);
  }
  else{
    throw("Unknown Bootloader DFU settings version: $ver");
  }

  // calculate the CRC32 over the data
  int crcTemp = calculateCRC32FromHex(ihex,base + 4,setts.initCmd - 1) & 0xffffffff;

  if( crcTemp != crc){
    throw("CRC32 mismtach: flash: $crc calculated: $crcTemp");
  }

  this.crc = crc;
  blSettVersion     = _getValueFromHex(setts.settingsVersion);
  appVersion         = _getValueFromHex(setts.appVersion);
  blVersion          = _getValueFromHex(setts.blVersion);
  bankLayout     = _getValueFromHex(setts.bankLayout);
  bankCurrent    = _getValueFromHex(setts.bankCurrent);
  appSize          = _getValueFromHex(setts.bankImgSize);
  appCrc         = _getValueFromHex(setts.bankImgCrc);
  bankCode = _getValueFromHex(setts.bankCode);

  if (blSettVersion == 2){
    setts as BLDFUSettingsStructV2;
    sdSize                    = _getValueFromHex(setts.sdSize);
    bootValidationCrc      = _getValueFromHex(setts.bootValidationCrc);
    sdValType  = _getValueFromHex(setts.sdValidationType, 1, '<b');
    appValType = _getValueFromHex(setts.appValidationType, 1, '<b');
  }
  else{
    sdSize                    = 0x0 & 0xffffffff;
    bootValidationCrc      = 0x0 & 0xffffffff;
    sdValType  = 0x0 & 0xffffffff;
    appValType = 0x0 & 0xffffffff;
  }
  String temp = {
    'crc': crc.hexilfy(),
    'settingsVersion': blSettVersion.hexilfy(),
    'appVersion': appVersion.hexilfy(),
    'blVersion': blVersion.hexilfy(),
    'bankLayout': bankLayout.hexilfy(),
    'bankCurrent': bankCurrent.hexilfy(),
    'bankImgSize': appSize.hexilfy(),
    'bankImgCrc': appCrc.hexilfy(),
    'bankCode': bankCode.hexilfy(),
    'sdSize': sdSize.hexilfy(),
    'bootValidationCrc': bootValidationCrc.hexilfy(),
    'sdValidationType': sdValType.hexilfy(2),
    'appValidationType': appValType.hexilfy(2),
  }.toString();
  logger?.verbose('BLE Settings Version: $ver');
  logger?.verbose(temp);
}