15#if defined(MFC_NORMALIZATION_ENABLED)
16#include "MFCProLicInterface.h"
19#define LOG(__msg__, __level__,__location__) l_Log(CInstrumentCatalog::sLogMessage(__level__, "MFCManager", __msg__, __location__))
21#define NO_SEARCH_SPR 0
22#define SEARCH_ENDED_SPR 100
41 if (rNotifier.
Is(m_ADNotifier))
44 l_NewInstrumentCurrent(rCurrentInstr.
ReadCurrent());
50 if (rNotifier.
Is(m_ADNotifier))
53 l_NewMFC3045SerialSettings(rMFC3045SerialSett.
ReadCurrent());
59 if (rNotifier.
Is(m_ADNotifier))
68 if (rNotifier.
Is(m_ADNotifier))
77 if (rNotifier.
Is(m_ADNotifier))
80 l_NewNormalizationRequest(rNormalizationRequest.
ReadCurrent());
87 if (rNotifier.
Is(m_ADNotifier))
89 l_GetDongleLicenseInfo();
95 if (rNotifier.
Is(m_ADNotifier))
98 l_DongleLicenseUpdateRequest(rLicenseUpdateRequest.
ReadCurrent());
104void CMFCManager::l_ControllerNotificationHandler(CAsyncNotification * pASNot)
106 CObserver_untyped & rVar = pASNot->
Observer();
108 const CAsyncSnapshotNotification * l_pASNot =
static_cast<CAsyncSnapshotNotification *
>(pASNot);
110 if (rVar.
Is(m_ContCat.oState))
115 else if (rVar.
Is(m_ContCat.oInstrumentList))
117 const CParsedResourceList * l_pVal =
static_cast<const CParsedResourceList *
>(l_pASNot->
DataCopy());
120 else if (rVar.
Is(m_ContCat.oPAInfo))
122 const CInstrumentCatalog::sProbeArrayInformation * l_pVal =
static_cast<const CInstrumentCatalog::sProbeArrayInformation *
>(l_pASNot->
DataCopy());
125 else if (rVar.
Is(m_ContCat.oInstrumentConfiguration))
127 const CInstrumentCatalog::sInstrumentConfiguration * l_pVal =
static_cast<const CInstrumentCatalog::sInstrumentConfiguration *
>(l_pASNot->
DataCopy());
130 else if (rVar.
Is(m_ContCat.oSearchProgress))
132 const U8 * l_pVal =
static_cast<const U8 *
>(l_pASNot->
DataCopy());
135 else if (rVar.
Is(m_ContCat.oSearchResult))
137 const CInstrumentCatalog::sSearchResult * l_pVal =
static_cast<const CInstrumentCatalog::sSearchResult *
>(l_pASNot->
DataCopy());
140 else if (rVar.
Is(m_ContCat.oMeasResults))
142 const CInstrumentCatalog::sMeasurementResults * l_pVal =
static_cast<const CInstrumentCatalog::sMeasurementResults *
>(l_pASNot->
DataCopy());
145 else if (rVar.
Is(m_ContCat.oError))
147 const CMFCDevice::sMFCDeviceError * l_pVal =
static_cast<const CMFCDevice::sMFCDeviceError *
>(l_pASNot->
DataCopy());
150 else if (rVar.
Is(m_ContCat.oLogMessage))
152 const CInstrumentCatalog::sLogMessage * l_pVal =
static_cast<const CInstrumentCatalog::sLogMessage *
>(l_pASNot->
DataCopy());
155 else if (rVar.
Is(m_ContCat.oRemoteBoxStart))
159 else if (rVar.
Is(m_ContCat.oUSBRemoteBoxStart))
167void CMFCManager::l_ClearInstrumentInfo()
173 m_InstrInfo = CInstrumentCatalog::sInstrumentInformation();
174 m_Cat.cProbeArrayInformation.rRequestControl(CInstrumentCatalog::sProbeArrayInformation());
175 m_Cat.cInstrumentInformation.rRequestControl(CInstrumentCatalog::sInstrumentInformation());
176 m_Cat.cInstrumentConfiguration.rRequestControl(CInstrumentCatalog::sInstrumentConfiguration());
185 m_MFCController.Terminate();
189 if(
nullptr != m_pMFCDevice)
193 m_pMFCDevice =
nullptr;
198 l_ClearInstrumentInfo();
200 m_MFCController.ScanInstruments(&m_RsrcManager);
205 m_Cat.cProbeArrayInformation.rRequestControl(CInstrumentCatalog::sProbeArrayInformation());
206 m_InstrInfo = CInstrumentCatalog::sInstrumentInformation();
208 auto l_InstrIt = m_RsrcListMap.find(rNewInstr.
UniqueID);
209 if (l_InstrIt == m_RsrcListMap.end())
214 m_pMFCDevice =
new CMFC3045Device(m_MFCController, m_RsrcManager, l_InstrIt->second.ParsedResource.Name, m_MFC3045SerialSett);
219 m_pMFCDevice =
new CMFC2x46Device(m_MFCController, m_RsrcManager, l_InstrIt->second.ParsedResource.Name, m_CustomPAConfScriptDirectory);
222 CMFCDevice::sMFCDeviceError l_RetError;
223 l_RetError = m_pMFCDevice->Connect(m_InstrInfo);
228 m_InstrInfo.InstrumentConnection = rNewInstr;
231 m_Cat.cInstrumentInformation.rRequestControl(m_InstrInfo);
234 if(!l_UpdateRBBusyLedState(m_RBBusyLedState))
238 m_MFCController.ScanPA(m_pMFCDevice);
246 l_ClearInstrumentInfo();
249 if(
nullptr != m_pMFCDevice)
252 m_pMFCDevice =
nullptr;
256 m_MFCController.ScanInstruments(&m_RsrcManager);
266 CInstrumentCatalog::sInstrumentConnection l_CurrentInstr;
267 m_Cat.oInstrumentCurrent.rReadCurrent(l_CurrentInstr);
274 m_MFCController.Terminate();
277 SlotPAInfo(CInstrumentCatalog::sProbeArrayInformation());
278 CMFCDevice::sMFCDeviceError l_RetError;
279 l_RetError = m_pMFCDevice->ChangeSerialParmsOnConnectedInstr(rNewSerialSett);
282 l_SendError(l_RetError);
285 throw CMFCManagerException(
"Serial settings change failed. Instrument serial settings might be corrupted. Set default instrument settings by pressing remote Start button untill end of led blinking while resetting the instrument.",
MTL__LOCATION__);
291 m_MFC3045SerialSett = rNewSerialSett;
294 m_pMFCDevice =
nullptr;
295 l_NewInstrumentCurrent(l_CurrentInstr);
303 l_NewInstrumentCurrent(CInstrumentCatalog::sInstrumentConnection());
305 m_MFC3045SerialSett = rNewSerialSett;
314 m_MFCController.Terminate();
317 m_InstrState = rNewInstrState;
325 if (
nullptr != m_pMFCDevice)
326 m_MFCController.ScanPA(m_pMFCDevice);
328 m_MFCController.ScanInstruments(&m_RsrcManager);
333 m_MFCController.SetInstrumentState(m_pMFCDevice, m_InstrState);
342#if defined(MFC_NORMALIZATION_ENABLED)
344 m_MFCController.Terminate();
348 CMFCDevice::sMFCDeviceError l_RetError;
350 if(m_LicInfo.LicenseIsExpired)
351 l_GetDongleLicenseInfo();
353 if (
nullptr == m_pMFCDevice)
357 CInstrumentCatalog::sNormalization l_ReturnedNormalization(rNewNormalizationRequest);
359 l_RetError = m_pMFCDevice->NewNormalizationRequest(rNewNormalizationRequest, l_ReturnedNormalization);
366 m_Cat.cNormalizationReturned.rRequestControl(l_ReturnedNormalization);
370 m_MFCController.UpdateNormalizationDate();
373 catch (CMFCDevice::sMFCDeviceError & rE)
376 CInstrumentCatalog::sNormalization l_ReturnNormFailed;
377 l_ReturnNormFailed.
Access = rNewNormalizationRequest.
Access;
379 m_Cat.cNormalizationReturned.rRequestControl(l_ReturnNormFailed);
380 l_GetDongleLicenseInfo();
387 if (
nullptr != m_pMFCDevice)
388 m_MFCController.ScanPA(m_pMFCDevice);
390 m_MFCController.ScanInstruments(&m_RsrcManager);
395void CMFCManager::l_GetDongleLicenseInfo()
399#if defined(MFC_NORMALIZATION_ENABLED)
403 CMFCDevice::sMFCDeviceError l_Error;
404 CInstrumentCatalog::sLicenseInformation l_LicenseInfo;
405 l_Error = CMFCProLicInterface::DongleGetLicenseInfo(l_LicenseInfo);
410 m_LicInfo = l_LicenseInfo;
411 m_Cat.cLicenseInfoReturned.RequestControl(l_LicenseInfo);
413 catch (CMFCDevice::sMFCDeviceError & rE)
415 m_LicInfo = CInstrumentCatalog::sLicenseInformation();
416 m_Cat.cLicenseInfoReturned.RequestControl(m_LicInfo);
427#if defined(MFC_NORMALIZATION_ENABLED)
429 CInstrumentCatalog::sLicenseUpdate l_LicenseUpdate = rLicenseUpdateRequest;
432 CMFCDevice::sMFCDeviceError l_Error;
433 l_Error = CMFCProLicInterface::DongleUpdateLicense(l_LicenseUpdate);
439 l_GetDongleLicenseInfo();
441 catch (CMFCDevice::sMFCDeviceError & rE)
446 m_Cat.cLicenseUpdateReturned.RequestControl(l_LicenseUpdate);
457 m_MFCController.Terminate();
460 if(
nullptr != m_pMFCDevice)
462 if(!l_UpdateRBBusyLedState(rNewRBBusyLedState))
465 m_RBBusyLedState = rNewRBBusyLedState;
472 if (
nullptr != m_pMFCDevice)
473 m_MFCController.ScanPA(m_pMFCDevice);
475 m_MFCController.ScanInstruments(&m_RsrcManager);
486 if (
nullptr == m_pMFCDevice)
489 CMFCDevice::sMFCDeviceError l_RetError;
491 switch (m_InstrInfo.Type)
495 l_RetError = m_pMFCDevice->SetRBBusyLedState(rNewRBBusyLedState);
502 l_RetError = m_pMFCDevice->SetRBBusyLedState(rNewRBBusyLedState);
520 catch (CMFCDevice::sMFCDeviceError & rE)
529void CMFCManager::l_UpdateInstrumentStatus()
536 switch (m_MFCControllerState)
547 if (0 == m_Cat.cProbeArrayInformation.ReadCurrent().NbProbes())
563 m_Cat.cInstrumentStatus.rRequestControl(m_InstrStatus);
566 m_ContCat.cUSBRemoteBusyState.RequestControl(l_Busy);
571 switch(rMFCDeviceError.
Level)
609 m_Cat.cError.rRequestControl(Error);
614 m_Cat.cLogMessage.rRequestControl(rMessage);
617void CMFCManager::l_UpdateSPR(uint8_t SearchProgress)
619 m_InstrStatus.SearchProgress = SearchProgress;
626 case eEventType::kExit:
628 case eEventType::kUserMsg:
632 l_CatalogNotificationHandler(pMsg->
pCatNot);
635 l_ControllerNotificationHandler(pMsg->
pContrNot);
658 m_MFCController.ScanInstruments(&m_RsrcManager);
667 switch (m_MFCControllerState)
676 m_MFCController.ScanPA(m_pMFCDevice);
679 m_MFCController.ScanPA(m_pMFCDevice);
685 m_MFCControllerState = State;
688 l_UpdateInstrumentStatus();
698 m_RsrcListMap = l_PrettyResourceNameList(NewResourceList);
701 m_PrettyInstrList.clear();
702 for (
auto & l_it : m_RsrcListMap)
705 l_InsCon.
Label = l_it.second.PrettyName;
707 switch (l_it.second.ParsedResource.Info.Type())
722 m_PrettyInstrList.push_back(l_InsCon);
724 m_Cat.cInstrumentList.rRequestControl(m_PrettyInstrList);
731 if(
nullptr !=m_pMFCDevice)
735 m_PADisconnected =
true;
736 else if (m_PADisconnected)
738 m_PADisconnected =
false;
740 m_pMFCDevice->SetRBBusyLedState(m_RBBusyLedState);
742 m_Cat.cProbeArrayInformation.rRequestControl(PAInfo);
747 l_UpdateInstrumentStatus();
754 m_Cat.cInstrumentConfiguration.rRequestControl(InstrConfig);
761 m_Cat.cProbeArrayAngle.rRequestControl(Angle);
775 l_UpdateSPR(Progress);
776 l_UpdateInstrumentStatus();
784 l_UpdateInstrumentStatus();
785 m_Cat.cSearchResult.rRequestControl(SearRes);
793 l_UpdateInstrumentStatus();
794 m_Cat.cMeasurementResults.rRequestControl(MeasRes);
804 switch (m_MFCControllerState)
811 m_MFCController.Terminate();
819 m_MFCController.Terminate();
820 l_ClearInstrumentInfo();
836 m_MFCController.ScanPA(m_pMFCDevice);
867 m_ContCat(m_ContCatInstance),
870 m_pMFCDevice(nullptr),
871 m_MFCController(m_ContCatInstance, rCustomPAConfScriptDir),
872 m_RBController(m_RsrcManager, m_ContCatInstance),
873 m_CustomPAConfScriptDirectory(rCustomPAConfScriptDir)
895 m_Cat.cInstrumentStatus.rRequestControl(m_InstrStatus);
899#if defined(MFC_NORMALIZATION_ENABLED)
901 m_Cat.cLicenseInfoReturned.rRequestControl(m_LicInfo);
910 m_Cat.oInstrumentCurrent.rReadCurrent(m_Instr);
911 m_Cat.oMFC3045SerialPortSettings.rReadCurrent(m_MFC3045SerialSett);
912 m_Cat.oInstrumentState.rReadCurrent(m_InstrState);
913 m_Cat.oRemoteBoxBusyLedState.rReadCurrent(m_RBBusyLedState);
923 m_Cat.oInstrumentCurrent.Subscribe(m_ADNotifier);
924 m_Cat.oMFC3045SerialPortSettings.Subscribe(m_ADNotifier);
925 m_Cat.oInstrumentState.Subscribe(m_ADNotifier);
926 m_Cat.oNormalizationRequest.Subscribe(m_ADNotifier);
927 m_Cat.oLicenseInfoRequest.Subscribe(m_ADNotifier);
928 m_Cat.oLicenseUpdateRequest.Subscribe(m_ADNotifier);
929 m_Cat.oRemoteBoxBusyLedState.Subscribe(m_ADNotifier);
932 m_ContCat.oState.Subscribe(m_ASControllerNotifier);
933 m_ContCat.oInstrumentList.Subscribe(m_ASControllerNotifier);
934 m_ContCat.oPAInfo.Subscribe(m_ASControllerNotifier);
935 m_ContCat.oInstrumentConfiguration.Subscribe(m_ASControllerNotifier);
936 m_ContCat.oSearchProgress.Subscribe(m_ASControllerNotifier);
937 m_ContCat.oSearchResult.Subscribe(m_ASControllerNotifier);
938 m_ContCat.oMeasResults.Subscribe(m_ASControllerNotifier);
939 m_ContCat.oError.Subscribe(m_ASControllerNotifier);
940 m_ContCat.oLogMessage.Subscribe(m_ASControllerNotifier);
941 m_ContCat.oRemoteBoxStart.Subscribe(m_ASControllerNotifier);
944 m_ContCat.oUSBRemoteBoxStart.Subscribe(m_ASControllerNotifier);
952 m_RsrcManager.Initialize();
955 m_MFCController.Operate();
958 m_RBController.Operate();
964 m_MFCController.ScanInstruments(&m_RsrcManager);
972 m_RBController.Terminate();
974 m_MFCController.Terminate();
977 m_pMFCDevice =
nullptr;
980CMFCManager::tResourceMap CMFCManager::l_PrettyResourceNameList(
const CParsedResourceList & rRsrcList)
988 CMFCManager::tResourceMap l_ReturnedList;
990 std::regex l_reg(
"([^:]+)+");
991 std::sregex_token_iterator l_end;
992 for (
auto & l_RsrcIt : rRsrcList)
994 std::string l_Alias(l_RsrcIt.Info.Alias());
996 std::sregex_token_iterator l_TokIt(l_RsrcIt.Name.begin(), l_RsrcIt.Name.end(), l_reg);
997 std::vector<std::string> l_Tokens(l_TokIt, l_end);
999 if (l_Tokens.size() >= 2 && l_RsrcIt.Info.Class() ==
"INSTR" && l_Tokens.back() ==
"INSTR")
1002 if (l_Tokens[0].find(
"USB") == 0 && l_Tokens.size() == 5 && l_Tokens[1] ==
"0x1BFA" && l_Tokens[2] ==
"0x07EA")
1005 std::string l_InstrName =
"PT2026 " + l_Tokens[3];
1006 l_ReturnedList.insert(std::pair<tUniqueID, sPrettyResource>(l_RsrcIt.Name, { l_InstrName, l_RsrcIt }));
1009 else if (0 == l_Tokens[0].find(
"TCPIP") && 4 == l_Tokens.size())
1011 if(std::string::npos != l_Tokens[1].find(
"PT2026") || std::string::npos != l_Tokens[1].find(
"pt2026"))
1014 std::string l_InstrName = l_Tokens[1];
1015 l_ReturnedList.insert(std::pair<tUniqueID, sPrettyResource>(l_RsrcIt.Name, { l_InstrName, l_RsrcIt }));
1017 else if(std::string::npos != l_Alias.find(
"PT2026") ||std::string::npos != l_Alias.find(
"pt2026"))
1020 l_ReturnedList.insert(std::pair<tUniqueID, sPrettyResource>(l_RsrcIt.Name, { l_Alias, l_RsrcIt }));
1025 else if (l_Tokens[0].find(
"ASRL") == 0)
1028 U8 l_COMnumber =
static_cast<U8
>(l_RsrcIt.Info.Number());
1029 std::string l_InstrName =
"INSTR - COM" + std::to_string(l_COMnumber);
1030 l_ReturnedList.insert(std::pair<tUniqueID, sPrettyResource>(l_RsrcIt.Name, { l_InstrName, l_RsrcIt }));
1035 return l_ReturnedList;
#define LOG(__msg__, __level__, __location__)
CException< CMFCManager > CMFCManagerException
Exception handling utilities.
Collection of utility macros for error messages.
Platform Dependent Definitions.
static constexpr I32 FATAL_ERROR_CODE
static constexpr I32 ERROR_CODE
static std::string l_Dump(const tInstrumentList &rInsList)
static constexpr I32 WARNING_ERROR_CODE
tInstrumentUniqueID UniqueID
eConnectionInterface Interface
eOperatingMode OperatingMode
eNormalizationAccess Access
CObserver< CInstrumentCatalog::sLicenseInformation > oLicenseInfoRequest
CObserver< CInstrumentCatalog::sLicenseUpdate > oLicenseUpdateRequest
CObserver< CInstrumentCatalog::sInstrumentConnection > oInstrumentCurrent
CObserver< CInstrumentCatalog::eRemoteBoxBusyLedState > oRemoteBoxBusyLedState
CObserver< CInstrumentCatalog::sNormalization > oNormalizationRequest
CObserver< CInstrumentCatalog::sInstrumentState > oInstrumentState
CObserver< CInstrumentCatalog::sMFC3045SerialPortSettings > oMFC3045SerialPortSettings
enum MTL::CMFCDevice::sMFCDeviceError::eLevel Level
CAsyncNotification * pCatNot
CAsyncNotification * pContrNot
void SlotPAInfo(CInstrumentCatalog::sProbeArrayInformation PAInfo)
void PostCatalogNotification(CAsyncNotification *pANot)
void SlotControllerState(CMFCManagerCatalog::eControllerState State)
void SlotControllerError(CMFCDevice::sMFCDeviceError error)
void SlotSearchResult(CInstrumentCatalog::sSearchResult SearRes)
void SlotMeasResult(CInstrumentCatalog::sMeasurementResults MeasRes)
void SlotInstrumentList(CParsedResourceList List)
CMFCManager(CInstrumentCatalog &rCatalog, const std::string &rCustomPAConfScriptDir)
void SlotControllerThreadIsReady()
void SlotProbeArrayAngle(CInstrumentCatalog::sProbeArrayAngle Angle)
void SlotInstrConfig(CInstrumentCatalog::sInstrumentConfiguration InstrConfig)
void PostControllerNotification(CAsyncNotification *pASNot)
void SlotRemoteBoxTriggerEvent()
void SlotControllerLogMessage(CInstrumentCatalog::sLogMessage Message)
void SlotSearchProgress(U8 Progress)
void l_SendMsg(const UserMsgT &rMsg)
DataType ReadCurrent(void)
bool Is(const CObserver_untyped &rObs)
CObserver_untyped & Observer() const
CObserverNotifier_untyped & Notifier() const
const void * DataCopy() const
bool Is(CObserverNotifier_untyped &rNot)
const char * message() const noexcept
Return the message.
const char * context() const noexcept
Return the context.