Skip to content

Commit 0b9213b

Browse files
committed
Fix message parsing
1 parent 76374d0 commit 0b9213b

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

hardware/Comm5TCP.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ m_szIPAddress(IPAddress)
4141
m_usIPPort=usIPPort;
4242
lastKnownSensorState = 0;
4343
initSensorData = true;
44-
reqState = Idle;
4544
notificationEnabled = false;
4645
m_bReceiverStarted = false;
4746
}
@@ -95,6 +94,7 @@ void Comm5TCP::OnDisconnect()
9594
void Comm5TCP::Do_Work()
9695
{
9796
bool bFirstTime = true;
97+
int count = 0;
9898
while (!m_stoprequested)
9999
{
100100
m_LastHeartbeat = mytime(NULL);
@@ -111,6 +111,10 @@ void Comm5TCP::Do_Work()
111111
{
112112
sleep_milliseconds(40);
113113
update();
114+
if (count++ >= 100) {
115+
count = 0;
116+
querySensorState();
117+
}
114118
}
115119
}
116120
_log.Log(LOG_STATUS, "Comm5 MA-5XXX: TCP/IP Worker stopped...");
@@ -131,7 +135,6 @@ void Comm5TCP::processSensorData(const std::string& line)
131135
}
132136
lastKnownSensorState = sensorbitfield;
133137
initSensorData = false;
134-
reqState = Idle;
135138
}
136139

137140
void Comm5TCP::ParseData(const unsigned char* data, const size_t len)
@@ -153,13 +156,8 @@ void Comm5TCP::ParseData(const unsigned char* data, const size_t len)
153156
bool on = (relaybitfield & (1 << i)) != 0 ? true : false;
154157
SendSwitch(i + 1, 1, 255, on, 0, "Relay " + boost::lexical_cast<std::string>(i + 1));
155158
}
156-
reqState = Idle;
157-
} else if (reqState == QuerySensorState && startsWith(line, "210")) {
158-
processSensorData(line);
159-
} else if (startsWith(line, "210 OK")) {
160-
// Command executed
161-
reqState = Idle;
162-
} else if (notificationEnabled && startsWith(line, "210")) {
159+
}
160+
else if (startsWith(line, "210") && (!startsWith(line, "210 OK"))) {
163161
processSensorData(line);
164162
}
165163
}
@@ -171,13 +169,11 @@ void Comm5TCP::ParseData(const unsigned char* data, const size_t len)
171169
void Comm5TCP::queryRelayState()
172170
{
173171
write("OUTPUTS\n");
174-
reqState = QueryRelayState;
175172
}
176173

177174
void Comm5TCP::querySensorState()
178175
{
179176
write("QUERY\n");
180-
reqState = QuerySensorState;
181177
}
182178

183179
void Comm5TCP::enableNotifications()

hardware/Comm5TCP.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ class Comm5TCP : public CDomoticzHardwareBase, ASyncTCP
2121

2222
bool Connect();
2323

24-
enum RequestState {
25-
Idle,
26-
QueryRelayState,
27-
QuerySensorState
28-
} reqState;
29-
3024
protected:
3125
void OnConnect();
3226
void OnDisconnect();
@@ -50,7 +44,7 @@ class Comm5TCP : public CDomoticzHardwareBase, ASyncTCP
5044

5145
std::string buffer;
5246
bool initSensorData;
53-
int lastKnownSensorState;
47+
unsigned int lastKnownSensorState;
5448

5549
bool notificationEnabled;
5650

0 commit comments

Comments
 (0)