-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclsDeviceListManager.c
185 lines (150 loc) · 3.92 KB
/
clsDeviceListManager.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the ig-logger project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Original author: Christian Kaiser <[email protected]>
*/
#include "logig.h"
#include <math.h>
#include <GPFProt.hpp>
#include "clsExcept.h"
#include "clsLocalNet.h"
virtual DWORD clsDeviceListManager::ThreadFunction(void)
{
INT nEvent = 0;
while (ThreadWait(5000,nEvent,1,_evMSGEvent.Handle()))
{
if (nEvent < -1)
{
_chk_utildebug("clsDeviceListManager::ThreadFunction: threadWait aborted!");
break;
}
switch (nEvent)
{
case -1:
{
clsCritObj CO(_CritOfNetDeviceList);
_NetDeviceList.clear();
}
break;
default:
_chk_utildebug("unexpected thread event... %x",nEvent);
break;
case 0:
if (!_ToDoList.isEmpty())
{
clsIGMessage Msg;
{
clsCritObj CO(_CritOfToDoList);
Msg = _ToDoList.get();
}
// 01 00 00 00 01 FE
const BYTE* pPayload = Msg.Payload();
BYTE nNetwork = *pPayload++; // just an assumption...
{
clsCritObj CO(_CritOfNetDeviceList);
_NetDeviceList.clear();
for (int nDevice = 0; nDevice < (Msg.PayloadSize()-1)/2; ++nDevice)
{
enLocalNetID nID = (enLocalNetID)pPayload[2*nDevice];
enLocalNetType nType = (enLocalNetType)pPayload[2*nDevice+1];
clsLocalNetID Device(nID,nType);
_NetDeviceList[clsLocalNetID(nID,nType)] = "";
}
_NetDeviceList[clsLocalNetID(IGID_NODE_0E,IGTYPE_NODE_0E)] = "Net 0E";
_NetDeviceList[clsLocalNetID(IGID_PC,IGTYPE_PC)] = "PC";
}
clsIGMessage MsgOut(Msg);
BYTE arData[MAX_MSG_SIZE];
BYTE* pCur = arData;
*pCur++ = nNetwork;
for (clsDeviceListIter Device(_NetDeviceList); ++Device; )
{
*pCur++ = (BYTE)Device.key().nID();
*pCur++ = (BYTE)Device.key().nType();
}
MsgOut.SetPayload(arData,pCur-arData);
_IGInterface.Post(MsgOut);
#if 0
{
String s;
for (clsDeviceListIter Device(_NetDeviceList); ++Device; )
{
s.AddStrSeparated(", ",
String::Format("%s='%s'",
(LPCTSTR)sLocalNetID(Device.key()),
(LPCTSTR)Device.value()));
}
printf("Net devices : %s\n",(LPCTSTR)s);
}
#endif
clsCritObj CO1(_CritOfToDoList);
if (_ToDoList.isEmpty())
{
_evMSGEvent.Reset();
}
}
break;
}
}
return(0);
}
clsDeviceListManager::clsDeviceListManager(clsIGInterface& IGInterface)
: clsThreadBase(TEXT("clsDeviceListManager"))
, _IGInterface(IGInterface)
, _evMSGEvent(TRUE,FALSE)
{
ThreadStart();
}
clsDeviceListManager::~clsDeviceListManager()
{
ThreadJoin();
}
void clsDeviceListManager::Clear()
{
{
clsCritObj CO1(_CritOfToDoList);
_ToDoList.clear();
}
{
clsCritObj CO2(_CritOfNetDeviceList);
_NetDeviceList.clear();
}
_evMSGEvent.Reset();
}
void clsDeviceListManager::OnDeviceList(const clsIGMessage& Msg)
{
_chk_debug(+1,">clsLocalNet::OnDeviceList");
clsCritObj CO(_CritOfToDoList);
_ToDoList.append(Msg);
_evMSGEvent.Set();
_chk_debug(-1,"<clsLocalNet::OnDeviceList");
}
bool clsDeviceListManager::ContainsNode(enLocalNetID nNode)
{
clsCritObj CO(_CritOfNetDeviceList);
for (clsDeviceListIter Device(_NetDeviceList); ++Device; )
{
if (Device.key().nID() == nNode)
return(true);
}
return(false);
}
bool clsDeviceListManager::ContainsDatalogger()
{
return(ContainsNode(IGID_DATALOGGER));
}
bool clsDeviceListManager::ContainsSensorcard()
{
for (enLocalNetID nDevice = IGID_SENSORCARD_FIRST; nDevice <= IGID_SENSORCARD_LAST; nDevice = (enLocalNetID)(nDevice+1))
{
if (ContainsNode(nDevice))
return(true);
}
return(false);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */