-
Notifications
You must be signed in to change notification settings - Fork 46
/
eoseventparser.cpp
140 lines (122 loc) · 4.04 KB
/
eoseventparser.cpp
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
/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
This software may be distributed and modified under the terms of the GNU
General Public License version 2 (GPL2) as published by the Free Software
Foundation and appearing in the file GPL2.TXT included in the packaging of
this file. Please note that GPL2 Section 2[b] requires that all works based
on this software must also be made publicly available under the terms of
the GPL2 ("Copyleft").
Contact information
-------------------
Circuits At Home, LTD
Web : http://www.circuitsathome.com
e-mail : support@circuitsathome.com
*/
#include "eoseventparser.h"
bool EOSEventParser::EventRecordParse(uint8_t **pp, uint16_t *pcntdn)
{
switch (nRecStage) {
case 0:
// Retrieves the size of the event record
if (!valueParser.Parse(pp, pcntdn))
return false;
nRecSize = (uint16_t)varBuffer;
// if (nRecSize == 8) { // empty event
// PTPTRACE("Skipping Empty Event\r\n");
// return true;
// }
PTPTRACE2("Event Record Size: ",nRecSize);
// calculates the number of event parameters ( size / 4 - 1 )
paramCountdown = (nRecSize >> 2) - 1;
paramCount = 1;
nRecSize -= 4;
nRecStage ++;
case 1:
for (; paramCountdown; paramCountdown--, paramCount++, nRecSize -= 4) {
if (!valueParser.Parse(pp, pcntdn)) {
PTPTRACE("EvtRecordParse: Value Parser stopped.\r\n");
return false;
}
switch (paramCount) {
// Event Code
case 1:
eosEvent.eventCode = (uint16_t)varBuffer;
// if (eosEvent.eventCode == EOS_EC_ObjectCreated) {
// PTPTRACE2("Object Created: ",eosEvent.eventCode);
// }
break;
// Property Code
case 2:
eosEvent.propCode = (uint32_t)varBuffer;
break;
// C189 - Property Value, C18A - Enumerator Type
case 3:
eosEvent.propValue = varBuffer;
if (pHandler)
{
if (eosEvent.eventCode == EOS_EC_DevPropChanged) {
pHandler->OnPropertyChanged(&eosEvent);
}
if (eosEvent.eventCode == EOS_EC_ObjectCreated) {
uint8_t* pbuf = valueParser.GetBuffer();
pHandler->OnObjectCreated(&eosEvent, pbuf);
}
}
break;
// C18A/enumType == 3 - Size of enumerator array
case 4:
if (eosEvent.eventCode == EOS_EC_DevPropValuesAccepted)
if (pHandler)
pHandler->OnAcceptedListSize(&eosEvent, (const uint16_t)varBuffer);
break;
// C18A/enumType == 3 - Enumerator Values
default:
if (eosEvent.eventCode == EOS_EC_DevPropValuesAccepted)
if (pHandler)
pHandler->OnPropertyValuesAccepted(&eosEvent, paramCount-5, varBuffer);
} // switch (paramCount)
} // for
nRecStage ++;
case 2:
if (nRecSize)
if (!byteSkipper.Skip(pp, pcntdn, nRecSize))
return false;
nRecSize = 0;
nRecStage = 0;
} // switch(nRecStage...
return true;
}
void EOSEventParser::InitEOSEventStruct()
{
eosEvent.eventCode = constInitialEventCode;
eosEvent.propCode = 0;
eosEvent.propValue = 0;
}
void EOSEventParser::Parse(const uint16_t len, const uint8_t *pbuf,
const uint32_t &offset __attribute__ ((unused)))
{
uint8_t *p = (uint8_t*) pbuf;
uint16_t cntdn = len;
switch (nStage) {
case 0:
p += 12;
cntdn -= 12;
nStage ++;
case 1:
theBuffer.valueSize = 4;
valueParser.Initialize(&theBuffer);
InitEOSEventStruct();
nStage ++;
case 2:
while (1) {
if (!EventRecordParse(&p, &cntdn)) {
PTPTRACE("Event Record Parse finished\r\n");
return;
}
if (IsLastEventRecord()) {
break;
}
InitEOSEventStruct();
}
nStage = 0;
} //switch(nStage...
}