Arianna autonomous DAQ firmware
Dependencies: mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW
Diff: SnConfigFrame.cpp
- Revision:
- 84:80b15993944e
- Parent:
- 83:a0d38ba9d6c2
- Child:
- 85:3ced48ef94c5
--- a/SnConfigFrame.cpp Mon Feb 23 03:04:39 2015 +0000 +++ b/SnConfigFrame.cpp Fri Oct 30 04:49:40 2015 +0000 @@ -13,9 +13,9 @@ bool SnConfigFrame::fgApplySafetyNets = true; #if CHIPBOARD==ATWD4CH -const uint8_t SnConfigFrame::kIOVers = 8; +const uint8_t SnConfigFrame::kIOVers = 11; #else // SST -const uint8_t SnConfigFrame::kIOVers = 10; +const uint8_t SnConfigFrame::kIOVers = 12; #endif #ifdef USE_INTERFACE_CHIP @@ -28,6 +28,7 @@ #endif const char* const SnConfigFrame::kDefIPflag = "DEF"; +const uint32_t SnConfigFrame::kDefIPvalue = 0; const uint32_t SnConfigFrame::kMinCommWinPrdLowPwr = 14400; // exclusive min low power comm win period (s) const uint32_t SnConfigFrame::kMaxCommWinPrdLowPwr = 259200; // exclusive max low power comm win period (s) const uint32_t SnConfigFrame::kMinCommWinDurLowPwr = 300; // exclusive min low power comm win duration (s) @@ -54,7 +55,7 @@ } void SnConfigFrame::SetHardDefaults() { - sprintf(fLabel,"Stn19HardDefR83"); + sprintf(fLabel,"HardDefTestSST"); fConfTime = 1338854400u; // Tue, 05 Jun 2012 00:00:00 GMT fRun = 0; fFirstSeq = 0; @@ -68,7 +69,7 @@ fWvLoseLSB = 0; fWvLoseMSB = 4; fWvBaseline = 0; - fDatPackType = kSDcard | kIrid | kAfar | kUSB; + fDatPackType = kSDcard | kIrid | kAfar | kUSB; // starting with io vers 11+, this is no longer changeable uint16_t* dc = &(fDAC[0][0]); for (uint16_t i=0; i<kTotDacs; i++, dc++) { *dc = 3072u; @@ -84,7 +85,7 @@ fEnableThermTrig = 0; fForceTrigPeriod = 0; fHeartBeatPeriod = 0; - fAmpsOn = 0x0Fu; + //fAmpsOn = 0x0Fu; removed vers 11+ fEvtThrtlPeriodMs = 0; fPowerMode = kIridComWin | kAfarComWin; fBatVoltToLowPwr = 0; @@ -95,11 +96,13 @@ fCommSendData = static_cast<int16_t>(kUseBits); fCommWinPrdLowPwr = 86100u; fCommWinDurLowPwr = 300u; - fCommWinConnectTOMin = 3u; - fCommWinListenTOMin = 3u; + for (uint8_t i=0; i<kNumDatStreams; ++i) { + fCommWinConnTOMins[i] = GetDefaultConnTOMin(i); + fCommWinListTOMins[i] = GetDefaultListTOMin(i); + } fWatchDogPeriod = WDFAILSAFE; #if CHIPBOARD==ATWD4CH - fTempCheckPeriod = 0; +// fTempCheckPeriod = 0; #else // not ATWD4CH fTempCheckPeriod = -8; #endif @@ -286,18 +289,27 @@ SetDefaultGateIP(); } -void SnConfigFrame::ApplyConnectListenSafetyNets() { - if (fCommWinConnectTOMin<kDefTimeoutMin) { - fCommWinConnectTOMin=kDefTimeoutMin; +void SnConfigFrame::ApplyConnectListenSafetyNets(const uint8_t dataStreamIdx) { + const float maxto_f = (fCommWinDuration/(60.*static_cast<float>(kNcomms))); + const uint8_t maxto = (maxto_f < kDefTimeoutMin) ? kDefTimeoutMin : + (maxto_f > 255.0) ? kDefTimeoutSafe : static_cast<uint8_t>(maxto_f); + if (fCommWinConnTOMins[dataStreamIdx] < kDefTimeoutMin) { + fCommWinConnTOMins[dataStreamIdx] = kDefTimeoutMin; + } + if (fCommWinConnTOMins[dataStreamIdx] > maxto) { + fCommWinConnTOMins[dataStreamIdx] = maxto; } - if (fCommWinConnectTOMin>(fCommWinDuration/(60.*static_cast<float>(kNcomms)))) { - fCommWinConnectTOMin=kDefTimeoutMin; + if (fCommWinListTOMins[dataStreamIdx] < kDefTimeoutMin) { + fCommWinListTOMins[dataStreamIdx] = kDefTimeoutMin; + } + if (fCommWinListTOMins[dataStreamIdx] > maxto) { + fCommWinListTOMins[dataStreamIdx] = maxto; } - if (fCommWinListenTOMin<kDefTimeoutMin) { - fCommWinListenTOMin=kDefTimeoutMin; - } - if (fCommWinListenTOMin>(fCommWinDuration/(60.*static_cast<float>(kNcomms)))) { - fCommWinListenTOMin=kDefTimeoutMin; +} + +void SnConfigFrame::ApplyConnectListenSafetyNets() { + for (uint8_t i=0; i<kNumDatStreams; ++i) { + ApplyConnectListenSafetyNets(i); } } @@ -375,7 +387,7 @@ if ( (ct<startTime) || (ct==0) || (lst>kSecsPerDay) ) { // possible clock problems - lst = static_cast<uint32_t>(kDefTimeoutMin)*60u; + lst = static_cast<uint32_t>(kDefTimeoutSafe)*60u; } const uint32_t lio = ((lst+delta) < GetCommWinDuration()) ? @@ -420,6 +432,10 @@ // set mode to low power fIsLowPower = true; + + if (fgApplySafetyNets) { + ApplySafetyNets(); + } } void SnConfigFrame::ChangeToNormPower() { @@ -429,6 +445,10 @@ fPowerMode = fNormPowerMode; // set mode to normal fIsLowPower = false; + + if (fgApplySafetyNets) { + ApplySafetyNets(); + } } void SnConfigFrame::GetPackParsFor(const EDatPackBit d, @@ -583,3 +603,39 @@ // reset the SD card init cache, in case the SD ignore run mode changed SnSDUtils::SetDoNeedToInit(); } + +void SnConfigFrame::GetIpStrFromVal(const uint32_t ip, + char(& str)[SnConfigFrame::kIPLen]) { + if (ip==kDefIPvalue) { + snprintf(str, kIPLen, kDefIPflag); + } else { + // little endian, but same method is used in ipToVal so the + // conversions will be consistent on this machine, but of course, + // the remote machine better send the right integer... + union { + uint8_t c[4]; + uint32_t u; + } x; + x.u = ip; + snprintf(str, kIPLen, "%hhu.%hhu.%hhu.%hhu", + x.c[3], x.c[2], x.c[1], x.c[0]); + } +} + +uint32_t SnConfigFrame::GetIpValFromStr(const char(& str)[SnConfigFrame::kIPLen]) { + if (strncmp(str, kDefIPflag, kIPLen)==0) { + return kDefIPvalue; + } else { + union { + uint8_t c[4]; + uint32_t u; + } x; + // 17 = space for terminating null + // little endian, but same method is used in ipToVal so the + // conversions will be consistent on this machine, but of course, + // the remote machine better send the right integer... + sscanf(str, "%hhu.%hhu.%hhu.%hhu", + x.c+3, x.c+2, x.c+1, x.c); + return x.u; + } +}