25 #define LOG(__msg__, __level__,__location__) m_rMFCController.l_SendLogMessage(__msg__, __level__, ".MFC2x46Device", __location__)
34 const std::string & rDefaultPAConfScriptFilePath,
35 const std::string & rCustomPAConfScriptDir)
37 m_rMFCController(rMFCController),
39 m_DefaultPAConfScriptFilePath(rDefaultPAConfScriptFilePath),
40 m_CustomPAConfScriptDirectory(rCustomPAConfScriptDir)
53 bool CMFC2x46Device::l_UtcToStrDateISO8601(
const std::time_t & rUtcDate, std::string & rStrDate)
56 auto l_TimePointUTC = std::chrono::system_clock::from_time_t(rUtcDate);
57 rStrDate =
date::format(
"%FT%TZ", date::floor<std::chrono::seconds>(l_TimePointUTC));
59 throw sMFCDeviceError(sMFCDeviceError::eLevel::kWarning,
"Fail to format time_t UTC date to string",
MTL__LOCATION__);
70 bool CMFC2x46Device::l_ExecuteConfigurationScript (U16 Model, U32 SN, sMFCDeviceError & rError)
77 std::stringstream lssFileName;
78 lssFileName << std::setfill(
'0') << std::setw(4) << Model <<
"_" << std::setw(8) << SN <<
".scs";
79 std::string lPAScriptFilePath = m_CustomPAConfScriptDirectory +
DIR_SEP + lssFileName.str();
81 std::ifstream lScriptFile;
83 lScriptFile.open(lPAScriptFilePath);
84 if (lScriptFile.is_open())
91 lScriptFile.open(m_DefaultPAConfScriptFilePath);
92 if (!lScriptFile.is_open())
93 throw sMFCDeviceError(sMFCDeviceError::eLevel::kError,
"Could not open Command Script File",
MTL__LOCATION__);
97 std::string lFileLine;
98 while (std::getline(lScriptFile, lFileLine))
101 throw sMFCDeviceError(sMFCDeviceError::eLevel::kError,
"Could not write command from script",
MTL__LOCATION__);
104 catch (sMFCDeviceError & rE)
117 *(
reinterpret_cast<U64*
>(&lastcfg.
FreqMin)) != *(
reinterpret_cast<U64*
>(&newcfg.
FreqMin)) ||
118 *(
reinterpret_cast<U64*
>(&lastcfg.
FreqMax)) != *(
reinterpret_cast<U64*
>(&newcfg.
FreqMax)) ||
133 if (l_ConfigurationChanged(m_LastConfigured, rInstrState))
143 throw sMFCDeviceError(sMFCDeviceError::eLevel::kError,
"Could not set limited list state",
MTL__LOCATION__);
148 throw sMFCDeviceError(sMFCDeviceError::eLevel::kError,
"Could not set limited list state",
MTL__LOCATION__);
159 l_CameraChannelList.push_back(m_PAChannel);
161 throw sMFCDeviceError(sMFCDeviceError::eLevel::kError,
"Could not select camera",
MTL__LOCATION__);
166 m_NbOfMeasurementsToFetch = m_NbOfSearchHeads;
169 m_NbOfMeasurementsToFetch = m_NbOfMeasHeads;
182 l_SingleHeadChannelList.push_back(l_SingleHeadChannel);
185 throw sMFCDeviceError(sMFCDeviceError::eLevel::kError,
"Could not select camera",
MTL__LOCATION__);
187 m_NbOfMeasurementsToFetch = 1;
193 throw sMFCDeviceError(sMFCDeviceError::eLevel::kFatal,
"Unhandled selection mode",
MTL__LOCATION__);
199 throw sMFCDeviceError(sMFCDeviceError::eLevel::kError,
"Could not set search limits",
MTL__LOCATION__);
219 throw sMFCDeviceError(sMFCDeviceError::eLevel::kError,
"Could not set measurement averaging",
MTL__LOCATION__);
221 catch (sMFCDeviceError & rE)
232 m_LastConfigured = rInstrState;
237 void CMFC2x46Device::l_ComputeAveraging (
const std::vector<tFlux> & rFluxList, F64 & rReturnedAveraging, F64 & rReturnedStdDev)
241 rReturnedAveraging = 0.0l;
242 rReturnedStdDev = 0.0l;
247 if (rFluxList.empty())
251 for (std::vector<tFlux>::const_iterator l_it = rFluxList.begin(); l_it != rFluxList.end(); l_it++)
255 if (!std::isnan(*l_it))
258 rReturnedAveraging += *l_it;
264 if (l_ValidCount > 0)
265 rReturnedAveraging = rReturnedAveraging / l_ValidCount;
267 rReturnedAveraging = DPqNaN;
270 if (l_ValidCount > 1)
272 for (std::vector<tFlux>::const_iterator l_it = rFluxList.begin(); l_it != rFluxList.end(); l_it++)
276 if (!std::isnan(*l_it))
278 F64 l_Value = *l_it - rReturnedAveraging;
279 rReturnedStdDev += l_Value * l_Value;
283 rReturnedStdDev = sqrt(rReturnedStdDev / (l_ValidCount - 1)) / rReturnedAveraging * 1e6;
286 rReturnedStdDev = DPqNaN;
291 rReturnedAveraging = DPqNaN;
292 rReturnedStdDev = DPqNaN;
298 bool l_ReturnSucceeded = m_PT2026.
Abort(
true);
301 bool l_RemoteBoxPressed(
false);
303 return l_ReturnSucceeded;
323 if (!m_PT2026.
Abort(
true))
329 std::regex l_reg(
"([^,]+)+");
330 std::sregex_token_iterator l_IdnTokIt(l_IDN.begin(), l_IDN.end(), l_reg);
331 std::vector<std::string> l_IdnTokens(l_IdnTokIt, std::sregex_token_iterator());
332 if (l_IdnTokens.size() < 4)
335 std::string l_ManDateStr, l_CalDateStr;
336 time_t l_ManDate, l_CalDateUTC;
345 if (!l_IDN.empty() && l_IDN[l_IDN.length()-1] ==
'\n') {
346 l_IDN.erase(l_IDN.length()-1);
366 rPaInfoChanged =
false;
370 if (l_NewChanList != m_ChanList)
374 m_ChanList = l_NewChanList;
384 if (m_ChanList.empty())
387 std::vector<sChannelIformation> l_FCAChanInfoVect;
390 for (
auto & l_ChanIt : m_ChanList)
395 m_PAChannel = l_ChanIt.Channel;
401 l_FCAChannelListVect.clear();
402 l_FCAChannelListVect.push_back(l_ChanIt.Channel);
407 if(!l_FCAChannelListVect.empty())
411 l_FCAChanInfoVect.clear();
415 if(!l_FCAChanInfoVect.empty())
417 l_FCAInfo.
Description = l_FCAChanInfoVect.at(0).Designation;
418 l_FCAInfo.
SerialNumber = std::to_string(l_FCAChanInfoVect.at(0).SN);
419 l_FCAInfo.
FCAFwVersion = l_FCAChanInfoVect.at(0).FirmwareVersion;
425 if (m_PAChannel.empty())
430 l_CameraChannelList.push_back(m_PAChannel);
445 std::vector<U8> l_ROMContent;
496 if (!l_ExecuteConfigurationScript(l_Identification.
Model, l_Identification.
SN, l_Error))
500 switch (l_Identification.
Model) {
522 m_NbOfSearchHeads =
static_cast<U8
>(l_SearchHeadList.size());
523 m_NbOfMeasHeads =
static_cast<U8
>(l_MeasHeadList.size());
541 std::match_results<std::string::const_iterator> l_DateMatch;
543 if (std::regex_match(l_PwCamPhysInfo.
NormalizationDate, l_DateMatch, std::regex(
"^([0-9]{4}-[0-9]{2}-[0-9]{2})(T[0-9]{2}:[0-9]{2}:[0-9]{2})(Z?)")))
547 else if (std::regex_match(l_PwCamPhysInfo.
NormalizationDate, l_DateMatch, std::regex(
"^([0-9]{4}-[0-9]{2}-[0-9]{2})(.*)")))
551 else if (std::regex_match(l_PwCamPhysInfo.
NormalizationDate, l_DateMatch, std::regex(
"^([0-9]{2})(-[0-9]{2}-)([0-9]{4})(.*)")))
553 rPAInfo.
NormalizationDate = l_DateMatch[3].str() + l_DateMatch[2].str() + l_DateMatch[1].str() +
"T00:00:00Z";
562 rPaInfoChanged =
true;
565 catch (
bool & rUsableCamera)
571 rPaInfoChanged =
true;
580 m_NbOfSearchHeads = 0;
582 m_NbOfMeasurementsToFetch = 0;
583 rPaInfoChanged =
true;
598 rPaInfoChanged =
true;
607 rPaInfoChanged =
true;
613 std::string l_Identification;
614 if (rE.
Level > sMFCDeviceError::eLevel::kError
633 if (m_PAChannel.empty())
637 if(!l_ConfigureForOperation(rInstrState, l_Error))
642 if (!m_PT2026.
Initiate(l_InitiatedContinuous))
670 m_rMFCController.l_SendSearchProgress(l_SPR);
673 std::this_thread::sleep_for(std::chrono::milliseconds(SEARCH_POLLING_PERIOD_MS));
683 if (!m_rMFCController.l_IsAbortRequested())
688 std::vector<tFlux> l_Flux;
690 if (!m_PT2026.
MeasurementsGet(m_NbOfMeasurementsToFetch, l_Flux, l_Units))
693 MTL_Assert(!l_Flux.empty() && l_Units == UNITS);
694 if (l_Flux.empty() || l_Units != UNITS)
698 F64 l_Average, l_StdDev;
699 l_ComputeAveraging(l_Flux, l_Average, l_StdDev);
703 l_SearchResult.
Freq = l_Average;
704 l_SearchResult.
StdDev =
static_cast<F32
>(l_StdDev);
705 m_rMFCController.l_SendSearchResult(l_SearchResult);
712 }
while (!m_rMFCController.l_IsAbortRequested() && l_OperCond.
OPERation.
INITiated && l_InitiatedContinuous);
723 return l_ReturnError;
733 if (m_PAChannel.empty())
737 if(!l_ConfigureForOperation(rInstrState,l_Error))
742 if (!m_PT2026.
Initiate(l_InitiatedContinuous))
770 m_rMFCController.l_SendSearchProgress(l_SPR);
773 std::this_thread::sleep_for(std::chrono::milliseconds(MEAS_POLLING_PERIOD_MS));
782 if (!m_rMFCController.l_IsAbortRequested())
790 l_ArbMeas.
Flux =
true;
797 if (!m_PT2026.
MeasurementsGet(m_NbOfMeasurementsToFetch, l_ArbMeas, l_Measurements, l_Units))
801 if (l_Measurements.
AdvMeas.
Basic.size() != m_NbOfMeasurementsToFetch || l_Units != UNITS)
811 l_Meas.
Freq = l_MeasIt.Flux_UNITS;
813 l_Meas.
StdDev = l_MeasIt.Deviation_ppm;
817 m_rMFCController.l_SendMeasResult(l_MeasResult);
824 }
while (!m_rMFCController.l_IsAbortRequested() && l_OperCond.
OPERation.
INITiated && l_InitiatedContinuous);
834 return l_ReturnError;
842 rReturnedNormalization.
Access = rNewNormalizationRequest.
Access;
843 rReturnedNormalization.
Table.clear();
845 switch (rNewNormalizationRequest.
Access)
854 for (
auto&& Factor_Hz : l_MFC2x46Normalization)
855 rReturnedNormalization.
Table.push_back(Factor_Hz * 1e-6f);
862 std::vector<U8> l_ROMContent;
879 rReturnedNormalization.
Table.push_back(Factor_Hz * 1e-6f);
886 for (
auto&& Factor_MHz : rNewNormalizationRequest.
Table)
887 l_PT2026Normalization.push_back(Factor_MHz * 1e6f);
897 std::vector<U8> l_ROMContent;
947 auto l_TimeNow = std::chrono::system_clock::now();
948 std::string l_StrDate;
949 l_StrDate=
date::format(
"%FT%TZ", date::floor<std::chrono::seconds>(l_TimeNow));
950 if(l_StrDate.empty())
956 for (
auto&& Factor_MHz : rNewNormalizationRequest.
Table)
960 std::vector<U8> l_NewROMContent;
985 std::vector<U8> l_ROMContent;
1000 std::match_results<std::string::const_iterator> l_DateMatch;
1002 if (std::regex_match(l_PwCamPhysInfo.
NormalizationDate, l_DateMatch, std::regex(
"^([0-9]{4}-[0-9]{2}-[0-9]{2})(T[0-9]{2}:[0-9]{2}:[0-9]{2})(Z?)")))
1003 rNormDate = l_DateMatch[1].str() + l_DateMatch[2].str() +
"Z";
1004 else if (std::regex_match(l_PwCamPhysInfo.
NormalizationDate, l_DateMatch, std::regex(
"^([0-9]{4}-[0-9]{2}-[0-9]{2})(.*)")))
1006 rNormDate = l_DateMatch[1].str() +
"T00:00:00Z";
1008 else if (std::regex_match(l_PwCamPhysInfo.
NormalizationDate, l_DateMatch, std::regex(
"^([0-9]{2})(-[0-9]{2}-)([0-9]{4})(.*)")))
1010 rNormDate = l_DateMatch[3].str() + l_DateMatch[2].str() + l_DateMatch[1].str() +
"T00:00:00Z";
1029 switch (rRBBusyLedState)
1072 rRemoteStartPressed =
true;
1074 rRemoteStartPressed =
false;
1078 rRemoteStartPressed =
false;