-
Notifications
You must be signed in to change notification settings - Fork 0
/
cep.cpp
204 lines (164 loc) · 4.96 KB
/
cep.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include "cep.h"
/*****************************************************/
// FIFO part
/*****************************************************/
streamFilteredJoin1_Fifo::streamFilteredJoin1_Fifo()
{}
streamFilteredJoin1_Fifo::~streamFilteredJoin1_Fifo()
{}
void streamFilteredJoin1_Fifo::checkTrigger()
{
if (!m1_isEmpty() && !m2_isEmpty())
{
// pop all the events
m1_popEvent();
m2_popEvent();
// May need to surround this with another guard on all
// the events. So pop should reconstruct the events.
// create the output event
// See the rest of the generated ThingML code
}
}
/*****************************************************/
// m1 handling part
/*****************************************************/
int streamFilteredJoin1_Fifo::m1_length()
{
if (m1_fifo_tail >= m1_fifo_head)
return m1_fifo_tail - m1_fifo_head;
return m1_fifo_tail + M1_FIFO_SIZE - m1_fifo_head;
}
int streamFilteredJoin1_Fifo::m1_available()
{
return M1_FIFO_SIZE - 1 - m1_length();
}
inline boolean streamFilteredJoin1_Fifo::m1_isFull()
{
return m1_fifo_head == ((m1_fifo_tail + 1) % M1_FIFO_SIZE);
}
inline boolean streamFilteredJoin1_Fifo::m1_isEmpty()
{
return m1_fifo_head == m1_fifo_tail;
}
void streamFilteredJoin1_Fifo::m1_queueEvent(int param)
{
if (m1_available() >= M1_ELEMENT_SIZE)
{
union stamp_t {
unsigned long time;
byte time_buffer[TIMESTAMP_DATASIZE];
} stamp;
stamp.time = millis();
m1_fifo[m1_fifo_tail ] = stamp.time_buffer[3] & 0xFF;
m1_fifo[m1_fifo_tail + 1] = stamp.time_buffer[2] & 0xFF;
m1_fifo[m1_fifo_tail + 2] = stamp.time_buffer[1] & 0xFF;
m1_fifo[m1_fifo_tail + 3] = stamp.time_buffer[0] & 0xFF;
union param_t {
int content;
byte buffer[2];
} param_un;
param_un.content = param;
m1_fifo[m1_fifo_tail + 4] = param_un.buffer[1] & 0xFF;
m1_fifo[m1_fifo_tail + 5] = param_un.buffer[0] & 0xFF;
m1_fifo_tail = (m1_fifo_tail + M1_ELEMENT_SIZE) % M1_FIFO_SIZE;
}
checkTrigger();
}
void streamFilteredJoin1_Fifo::m1_popEvent()
{
// For optimize purposes the guard should be removed
// because we manage when the method is called
if (!m1_isEmpty())
{
union stamp_t {
unsigned long time;
byte time_buffer[TIMESTAMP_DATASIZE];
} stamp;
stamp.time_buffer[3] = m1_fifo[m1_fifo_head];
stamp.time_buffer[2] = m1_fifo[(m1_fifo_head + 1) % M1_FIFO_SIZE];
stamp.time_buffer[1] = m1_fifo[(m1_fifo_head + 2) % M1_FIFO_SIZE];
stamp.time_buffer[0] = m1_fifo[(m1_fifo_head + 3) % M1_FIFO_SIZE];
union param_t {
int content;
byte buffer[2];
} param;
param.buffer[1] = m1_fifo[(m1_fifo_head + 4) % M1_FIFO_SIZE];
param.buffer[0] = m1_fifo[(m1_fifo_head + 5) % M1_FIFO_SIZE];
m1_fifo_head = (m1_fifo_head + M1_ELEMENT_SIZE) % M1_FIFO_SIZE;
}
}
/*****************************************************/
// m2 handling part
/*****************************************************/
int streamFilteredJoin1_Fifo::m2_length()
{
if (m2_fifo_tail >= m2_fifo_head)
return m2_fifo_tail - m2_fifo_head;
return m2_fifo_tail + M2_FIFO_SIZE - m2_fifo_head;
}
int streamFilteredJoin1_Fifo::m2_available()
{
return M2_FIFO_SIZE - 1 - m2_length();
}
inline boolean streamFilteredJoin1_Fifo::m2_isFull()
{
return m2_fifo_head == ((m2_fifo_tail + 1) % M2_FIFO_SIZE);
}
inline boolean streamFilteredJoin1_Fifo::m2_isEmpty()
{
return m2_fifo_head == m2_fifo_tail;
}
void streamFilteredJoin1_Fifo::m2_queueEvent()
{
if (m2_available() >= M2_ELEMENT_SIZE)
{
union stamp_t {
unsigned long time;
byte time_buffer[TIMESTAMP_DATASIZE];
} stamp;
stamp.time = millis();
m2_fifo[m2_fifo_tail ] = stamp.time_buffer[3] & 0xFF;
m2_fifo[(m2_fifo_tail + 1) % M2_FIFO_SIZE] = stamp.time_buffer[2] & 0xFF;
m2_fifo[(m2_fifo_tail + 2) % M2_FIFO_SIZE] = stamp.time_buffer[1] & 0xFF;
m2_fifo[(m2_fifo_tail + 3) % M2_FIFO_SIZE] = stamp.time_buffer[0] & 0xFF;
m2_fifo_tail = (m2_fifo_tail + M2_ELEMENT_SIZE) % M2_FIFO_SIZE;
}
checkTrigger();
}
void streamFilteredJoin1_Fifo::m2_popEvent()
{
if (!m2_isEmpty())
{
union stamp_t {
unsigned long time;
byte time_buffer[TIMESTAMP_DATASIZE];
} stamp;
stamp.time_buffer[3] = m2_fifo[m2_fifo_head];
stamp.time_buffer[2] = m2_fifo[(m2_fifo_head + 1) % M2_FIFO_SIZE];
stamp.time_buffer[1] = m2_fifo[(m2_fifo_head + 2) % M2_FIFO_SIZE];
stamp.time_buffer[0] = m2_fifo[(m2_fifo_head + 3) % M2_FIFO_SIZE];
m2_fifo_head = (m2_fifo_head + M2_ELEMENT_SIZE) % M2_FIFO_SIZE;
}
}
void streamFilteredJoin1_Fifo::dump()
{
// int i = m1_fifo_head;
// EventElement tmpEventElmt;
// String lb = "<";
// String co = ",";
// String rb = ">";
//
// while (i != m1_fifo_tail)
// {
// tmpEventElmt = fifo[i];
//
// //if (tmpEventElmt.code == 0) {
// // byte c[] = (*tmpEventElmt.content);
// //}
// ////Serial.print(lb + tmpEventElmt.code + co + c[0] + rb);
//
// i = (i +1)%FIFO_SIZE;
// }
// //Serial.println();
//
}