C++ Instrument Catalog
MFCManager.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 // Standard includes
9 #include <iostream>
10 #include <atomic>
11 #include <exception>
12 #include <unordered_map>
13 
14 // Personnal includes
15 #include "InstrumentCatalog.h"
16 #include "MFCController.h"
17 #include "MFC3045Device.h"
18 #include "MFC2x46Device.h"
19 #include "USBRemoteBoxController.h"
20 #include "Helpers.h"
21 #include "MFCManagerCatalog.h"
22 
23 using namespace MTL;
24 using namespace MTL::Instrument;
25 using namespace MTL::ThreadedMailbox;
26 
27 namespace MTL {
28  //--------------------------------------------------------------------------//
29  // MFC MANAGER
30  //--------------------------------------------------------------------------//
32  CAsyncNotification * pCatNot; // Global catalog notification
33  CAsyncNotification * pContrNot; // Controller notification
35  : pCatNot(nullptr), pContrNot(nullptr) {}
37  : pCatNot(pCat), pContrNot(pContr) {}
38  };
39  class CMFCManager : private CThreadedMailBox<sMFCManagerMailBoxMsg>
40  {
41  //--------------------------------------------------------------------------//
42  // Utilities
43  //--------------------------------------------------------------------------//
44  private:
45  typedef std::string tUniqueID;
46  struct sPrettyResource {
47  std::string PrettyName;
48  sParsedResource ParsedResource;
49  };
50  typedef std::unordered_map<tUniqueID, sPrettyResource> tResourceMap;
51  tResourceMap l_PrettyResourceNameList(const CParsedResourceList & rRsrcList);
52 
53  private:
54  //--------------------------------------------------------------------------//
55  // Class attributes
56  //--------------------------------------------------------------------------//
58  CMFCManagerCatalog m_ContCatInstance;
59  CMFCManagerInterface m_ContCat;
60  CAsyncDynamicNotifier m_ADNotifier;
61  CAsyncSnaphsotNotifier m_ASControllerNotifier;
62  CVISAResourceManager m_RsrcManager;
63  tResourceMap m_RsrcListMap;
64  CMFCDevice * m_pMFCDevice = nullptr;
65  CMFCController m_MFCController;
66  CMFCManagerCatalog::eControllerState m_MFCControllerState;
67  CUSBRemoteBoxController m_RBController;
69 
70  std::string m_DefaultPAConfScriptFilePath; // Path of the default PA configuration script (if no specific file exists)
71  std::string m_CustomPAConfScriptDirectory; // Directory containing PA specific configuration scripts
72 
73  // Local versions of controls
74  CInstrumentCatalog::tInstrumentList m_PrettyInstrList;
76  //CInstrumentCatalog::sProbeArrayInformation m_PAInfo; // no need to keep in Manager
77  //CInstrumentCatalog::sProbeArrayAngle m_PAAngle;
79  // Normalization is ephemeral
80  // Search result is ephemeral
81  // Measurement results are ephemeral
82  // Error is ephemeral
83  // Local versions of observers
87  // Instrument calibration date is ephemeral
88  // Normalization returned is ephemeral
89 
90  //--------------------------------------------------------------------------//
91  // Local private methods
92  //--------------------------------------------------------------------------//
93  // Handlers for new values of catalog observers
94  void l_ClearInstrumentInfo();
95  void l_NewInstrumentCurrent(const CInstrumentCatalog::sInstrumentConnection & rNewInstr);
96  void l_NewMFC3045SerialSettings(const CInstrumentCatalog::sMFC3045SerialPortSettings & rNewSerialSett);
97  void l_NewInstrumentState(const CInstrumentCatalog::sInstrumentState & rNewInstrState);
98  void l_NewNormalizationRequest(const CInstrumentCatalog::sNormalization & rNewNormalizationRequest);
99  void l_NewRBBusyLedState(const CInstrumentCatalog::eRemoteBoxBusyLedState & rNewRBBusyLedState);
100 
101  // Private operations
102  bool l_UpdateRBBusyLedState(const CInstrumentCatalog::eRemoteBoxBusyLedState & rNewRBBusyLedState);
103  void l_UpdateInstrumentStatus();
104  CInstrumentCatalog::sError l_MFCDeviceToCatalogError(const CMFCDevice::sMFCDeviceError & rMFCDeviceError, const int Code=0);
105  void l_SendError(CInstrumentCatalog::eErrorLevel Level, int Code, std::string Descr, std::string Source);
106  void l_SendError(CInstrumentCatalog::sError Error);
107  void l_Log(const CInstrumentCatalog::sLogMessage & rMessage);
108  void l_UpdateSPR(uint8_t SearchProgress);
109 
110  // Local Thread
111  void l_ThreadTask(CThreadedMailBox::eEventType EvtType, sMFCManagerMailBoxMsg * pMsg);
112  // Lives in the main thread (outside of this class)
113  void l_CatalogNotificationHandler(CAsyncNotification * pANot);
114  void l_ControllerNotificationHandler(CAsyncNotification * pASNot);
115 
116  //--------------------------------------------------------------------------//
117  // Catalog Notification handling
118  //--------------------------------------------------------------------------//
119  public :
120  void PostCatalogNotification(CAsyncNotification * pANot); // Receives asynchronous notifications from global catalog
121  //--------------------------------------------------------------------------//
122  // MFCManager Catalog Notification handling
123  //--------------------------------------------------------------------------//
124  void PostControllerNotification(CAsyncNotification * pASNot); // Receives asyncrhonous notifications from MFCController
125 
126  //--------------------------------------------------------------------------//
127  // MFC Controller Interface
128  //--------------------------------------------------------------------------//
129  public:
130  void SlotControllerThreadIsReady();
131 
132  void SlotControllerState(CMFCManagerCatalog::eControllerState State);
133  void SlotInstrumentList(CParsedResourceList List);
134  void SlotPAInfo(CInstrumentCatalog::sProbeArrayInformation PAInfo);
135  void SlotInstrConfig(CInstrumentCatalog::sInstrumentConfiguration InstrConfig);
136  void SlotProbeArrayAngle(CInstrumentCatalog::sProbeArrayAngle Angle);
137  void SlotRemoteBoxTriggerEvent();
138  void SlotSearchProgress(U8 Progress);
139  void SlotSearchResult(CInstrumentCatalog::sSearchResult SearRes);
140  void SlotMeasResult(CInstrumentCatalog::sMeasurementResults MeasRes);
141  void SlotControllerError(CMFCDevice::sMFCDeviceError error);
142  void SlotControllerLogMessage(CInstrumentCatalog::sLogMessage Message);
143 
144  //--------------------------------------------------------------------------//
145  // Remote Box Controller Interface
146  //--------------------------------------------------------------------------//
147  public :
148  void SlotRBReset();
149  void SlotRBStart();
150 
151  public:
152  //--------------------------------------------------------------------------//
153  // Constructor / Destructor
154  //--------------------------------------------------------------------------//
155  CMFCManager(CInstrumentCatalog & rCatalog, const std::string & rDefaultPAConfScriptFilePath, const std::string & rCustomPAConfScriptDir);
156  virtual ~CMFCManager();
157 
158  //--------------------------------------------------------------------------//
159  // Class control
160  //--------------------------------------------------------------------------//
161  void SyncControls();
162  void SyncObservers();
163  void Subscribe();
164  void Operate();
165 
166  public:
167  void Terminate();
168  }; // class CMFCManager
169 
170 } // namespace MTL
MFCManagerCatalog.h
MTL::CInstrumentCatalog::tInstrumentList
std::vector< sInstrumentConnection > tInstrumentList
Definition: InstrumentCatalog.h:54
MTL::CInstrumentCatalog::eErrorLevel
eErrorLevel
Definition: InstrumentCatalog.h:289
MTL::InstrumentCatalogInterface::CAsyncSnaphsotNotifier
Definition: CatalogInterface.h:299
MTL::CInstrumentCatalog::sInstrumentStatus
Definition: InstrumentCatalog.h:229
MTL::CInstrumentCatalog::sMeasurementResults
Definition: InstrumentCatalog.h:267
MTL::CInstrumentCatalog::sSearchResult
Definition: InstrumentCatalog.h:250
MTL::ThreadedMailbox::CThreadedMailBox
Definition: ThreadedMailbox.h:222
MTL::sMFCManagerMailBoxMsg
Definition: MFCManager.h:31
MFC2x46Device.h
MTL::ThreadedMailbox::CThreadedMailBox::eEventType
eEventType
Definition: ThreadedMailbox.h:228
MTL::sMFCManagerMailBoxMsg::pCatNot
CAsyncNotification * pCatNot
Definition: MFCManager.h:32
MTL::CInstrumentCatalog::sLogMessage
Definition: InstrumentCatalog.h:319
Helpers.h
Collection of utility macros for error messages.
MTL::CInstrumentCatalog::sError
Definition: InstrumentCatalog.h:294
MTL::CInstrumentCatalog::sInstrumentState
Definition: InstrumentCatalog.h:212
MTL::CUSBRemoteBoxController
Definition: USBRemoteBoxController.h:33
MTL::CMFCDevice::sMFCDeviceError
Definition: MFCDevice.h:30
MTL::CInstrumentCatalog::sMFC3045SerialPortSettings
Definition: InstrumentCatalog.h:81
MTL
Definition: CPT2026PeripheralROM.h:19
MTL::Instrument
Definition: MFC3045.h:25
MTL::CMFCDevice
Definition: MFCDevice.h:24
MTL::CInstrumentCatalog::eRemoteBoxBusyLedState
eRemoteBoxBusyLedState
Definition: InstrumentCatalog.h:242
MTL::Instrument::sParsedResource
Definition: VISAInstrumentTypes.h:234
MTL::CMFCManagerCatalog::eControllerState
eControllerState
Definition: MFCManagerCatalog.h:24
MTL::CMFCManagerInterface
Definition: MFCManagerCatalog.h:55
MTL::CInstrumentCatalog::sProbeArrayInformation
Definition: InstrumentCatalog.h:145
MTL::sMFCManagerMailBoxMsg::sMFCManagerMailBoxMsg
sMFCManagerMailBoxMsg()
Definition: MFCManager.h:34
MTL::CInstrManCatalogInterface
Definition: InstrumentCatalog.h:606
MFC3045Device.h
InstrumentCatalog.h
MTL::ThreadedMailbox
Definition: ThreadedMailbox.h:17
MFCController.h
MTL::InstrumentCatalogInterface::CAsyncNotification
Definition: CatalogInterface.h:144
MTL::InstrumentCatalogInterface::CAsyncDynamicNotifier
Definition: CatalogInterface.h:285
MTL::CMFCController
Definition: MFCController.h:34
MTL::sMFCManagerMailBoxMsg::pContrNot
CAsyncNotification * pContrNot
Definition: MFCManager.h:33
MTL::CMFCManager
Definition: MFCManager.h:39
MTL::CMFCManagerCatalog
Definition: MFCManagerCatalog.h:19
MTL::sMFCManagerMailBoxMsg::sMFCManagerMailBoxMsg
sMFCManagerMailBoxMsg(CAsyncNotification *pCat, CAsyncNotification *pContr)
Definition: MFCManager.h:36
MTL::CInstrumentCatalog::sInstrumentInformation
Definition: InstrumentCatalog.h:106
MTL::CInstrumentCatalog
Definition: InstrumentCatalog.h:22
MTL::CInstrumentCatalog::sInstrumentConnection
Definition: InstrumentCatalog.h:38
MTL::CInstrumentCatalog::sProbeArrayAngle
Definition: InstrumentCatalog.h:306
USBRemoteBoxController.h
MTL::Instrument::CVISAResourceManager
VISA Resource Manager class.
Definition: VISAInstrument.h:35
MTL::CInstrumentCatalog::sInstrumentConfiguration
Definition: InstrumentCatalog.h:116
MTL::CInstrumentCatalog::sNormalization
Definition: InstrumentCatalog.h:282
MTL::Instrument::CParsedResourceList
Definition: VISAInstrumentTypes.h:253