C++Instrument Catalog MFC 1.2
Metrolab C++InstrumentCatalog for MFC
Loading...
Searching...
No Matches
USBRemoteBoxController.cpp
Go to the documentation of this file.
1
5
7
8using namespace MTL;
9using namespace MTL::Instrument;
10
11const std::string CUSBRemoteBoxController::RSRC_FILTER = "USB[0-9]+::0x1BFA::0x1F6D::[0-9]+::RAW";
12const int CUSBRemoteBoxController::REFRESH_RATE_MS = 100;
13
15
17 : m_rRsrcMan(rRM),
18 m_RBCat(rCatInstance),
19 m_ASManagerNotifier(&CUSBRemoteBoxController::l_PostManagerNotification, this),
20 m_pRemoteBox(nullptr),
21 m_Timer(&CUSBRemoteBoxController::l_PostTimerEvent, this)
22{
23 m_RBCat.oUSBRemoteBusyState.Subscribe(m_ASManagerNotifier);
24}
25
27{
28 m_Timer.Stop();
29 if (nullptr != m_pRemoteBox)
30 {
31 m_LEDs.LEDs.ON = false;
32 m_LEDs.LEDs.BUSY = false;
33 m_pRemoteBox->Update(m_LEDs, m_Buttons);
34
35 delete m_pRemoteBox;
36 m_pRemoteBox = nullptr;
37 }
38}
39
41{
43 m_Timer.Start(std::chrono::milliseconds(REFRESH_RATE_MS));
44}
45
51
52void CUSBRemoteBoxController::l_PostTimerEvent()
53{
55}
56
57void CUSBRemoteBoxController::l_PostManagerNotification(CAsyncNotification * pASNot)
58{
60}
61
62void CUSBRemoteBoxController::l_Refresh()
63{
64 try
65 {
66 // If no remote is currently connected
67 if (nullptr == m_pRemoteBox)
68 {
69 // Find new resources
70 CResourceList l_RSL;
71 m_rRsrcMan.FindResources(l_RSL, RSRC_FILTER);
72 if (!l_RSL.empty())
73 {
74 m_pRemoteBox = new CUSBRemoteBox(m_rRsrcMan, l_RSL.front());
75 if (!m_pRemoteBox->Connect())
76 throw CUSBRemoteBoxControllerException("Could not connect to the usb remote box", MTL__LOCATION__);
77
78 m_LEDs.LEDs.ON = true;
79 m_LEDs.LEDs.BUSY = false;
80 if (!m_pRemoteBox->Update(m_LEDs, m_Buttons))
81 throw CUSBRemoteBoxControllerException("Could not update remote box state", MTL__LOCATION__);
82 }
83 }
84
85 // Check RB state, if any
86 if (nullptr != m_pRemoteBox)
87 {
88 if (!m_pRemoteBox->Update(m_LEDs, m_Buttons))
89 throw CUSBRemoteBoxControllerException("Could not update remote box state", MTL__LOCATION__);
90
91 // Send relevant signals
92 if (m_Buttons.BUTs.ResetEvent)
93 m_RBCat.cUSBRemoteBoxReset.RequestControl(true);
94 if (m_Buttons.BUTs.StartEvent)
95 m_RBCat.cUSBRemoteBoxStart.RequestControl(true);
96 }
97 }
99 {
100 MTL_Unused(rE);
101 if (nullptr != m_pRemoteBox)
102 {
103 delete m_pRemoteBox;
104 m_pRemoteBox = nullptr;
105 }
106 }
107}
108
109void CUSBRemoteBoxController::l_SetBusyState(bool Busy)
110{
111 try
112 {
113 if (nullptr != m_pRemoteBox)
114 {
115 m_LEDs.LEDs.BUSY = Busy;
116 if (!m_pRemoteBox->Update(m_LEDs, m_Buttons))
117 throw CUSBRemoteBoxControllerException("Could not update remote box state", MTL__LOCATION__);
118 }
119 }
121 {
122 MTL_Unused(rE);
123 if (nullptr != m_pRemoteBox)
124 {
125 delete m_pRemoteBox;
126 m_pRemoteBox = nullptr;
127 }
128 }
129}
130
131void CUSBRemoteBoxController::l_ThreadTask(eEventType EvtType, sUSBRemoteBoxControllerMailBoxMsg * pMsg)
132{
133 switch (EvtType)
134 {
135 case eEventType::kExit:
136 break;
137 case eEventType::kUserMsg:
138 if (nullptr != pMsg)
139 {
140 switch (pMsg->MsgType)
141 {
143 l_Refresh();
144 break;
146 l_AsyncManagerNotificationHandler(pMsg->pCatNot);
147 break;
148 }
149 }
150 break;
151 }
152}
153
154void CUSBRemoteBoxController::l_AsyncManagerNotificationHandler(CAsyncNotification * pASNot)
155{
156// CObserverNotifier_untyped & rNotifier = pASNot->Notifier();
157 CObserver_untyped & rVar = pASNot->Observer();
158
159 const CAsyncSnapshotNotification * l_pASNot = static_cast<CAsyncSnapshotNotification *>(pASNot);
160
161 if (rVar.Is(m_RBCat.oUSBRemoteBusyState))
162 {
163 const bool * l_pVal = static_cast<const bool *>(l_pASNot->DataCopy());
164 l_SetBusyState(*l_pVal);
165 }
166
167 delete pASNot;
168}
CException< CUSBRemoteBoxController > CUSBRemoteBoxControllerException
#define MTL_Unused(x)
Definition Helpers.h:105
#define MTL__LOCATION__
Definition Helpers.h:24
void l_SendMsg(const UserMsgT &rMsg)
enum MTL::sUSBRemoteBoxControllerMailBoxMsg::eMsgType MsgType
CUSBRemoteBoxController(CVISAResourceManager &rRM, CMFCManagerCatalog &rCatInstance)
Exception to be thrown.
Definition Exception.h:17
VISA Resource Manager class.