@@ -77,16 +77,19 @@ class CommonHelix {
77
77
if (active){
78
78
end ();
79
79
}
80
+
81
+ allocateDecoder ();
82
+
80
83
if (frame_buffer == nullptr ) {
81
- LOG (Info," allocating frame_buffer with %zu bytes" , maxFrameSize ());
84
+ LOG_HELIX (Info," allocating frame_buffer with %zu bytes" , maxFrameSize ());
82
85
frame_buffer = new uint8_t [maxFrameSize ()];
83
86
}
84
87
if (pwm_buffer == nullptr ) {
85
- LOG (Info," allocating pwm_buffer with %zu bytes" , maxPWMSize ());
88
+ LOG_HELIX (Info," allocating pwm_buffer with %zu bytes" , maxPWMSize ());
86
89
pwm_buffer = new short [maxPWMSize ()];
87
90
}
88
91
if (pwm_buffer==nullptr || frame_buffer==nullptr ){
89
- LOG (Error, " Not enough memory for buffers" );
92
+ LOG_HELIX (Error, " Not enough memory for buffers" );
90
93
active = false ;
91
94
return ;
92
95
}
@@ -108,7 +111,7 @@ class CommonHelix {
108
111
*/
109
112
110
113
virtual size_t write (const void *in_ptr, size_t in_size) {
111
- LOG (Debug, " write %zu" , in_size);
114
+ LOG_HELIX (Debug, " write %zu" , in_size);
112
115
size_t start = 0 ;
113
116
if (active){
114
117
uint8_t * ptr8 = (uint8_t * )in_ptr;
@@ -118,15 +121,15 @@ class CommonHelix {
118
121
// we have some space left in the buffer
119
122
int written_len = writeFrame (ptr8+start, write_len);
120
123
start += written_len;
121
- LOG (Info," -> Written %zu of %zu - Counter %zu" , start, in_size, frame_counter);
124
+ LOG_HELIX (Info," -> Written %zu of %zu - Counter %zu" , start, in_size, frame_counter);
122
125
write_len = min (in_size - start, static_cast <size_t >(maxFrameSize ()-buffer_size));
123
126
// add delay - e.g. needed by esp32 and esp8266
124
127
if (delay_ms>0 ){
125
128
delay (delay_ms);
126
129
}
127
130
}
128
131
} else {
129
- LOG (Warning, " CommonHelix not active" );
132
+ LOG_HELIX (Warning, " CommonHelix not active" );
130
133
}
131
134
132
135
return start;
@@ -156,6 +159,8 @@ class CommonHelix {
156
159
Print *out = nullptr ;
157
160
#endif
158
161
162
+ virtual void allocateDecoder () = 0;
163
+
159
164
// / Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my minimizing this value
160
165
virtual size_t maxFrameSize () = 0;
161
166
@@ -180,23 +185,23 @@ class CommonHelix {
180
185
181
186
// / we add the data to the buffer until it is full
182
187
size_t appendToBuffer (const void *in_ptr, int in_size){
183
- LOG (Info, " appendToBuffer: %d (at %p)" , in_size, frame_buffer);
188
+ LOG_HELIX (Info, " appendToBuffer: %d (at %p)" , in_size, frame_buffer);
184
189
int buffer_size_old = buffer_size;
185
190
int process_size = min ((int )(maxFrameSize () - buffer_size), in_size);
186
191
memmove (frame_buffer+buffer_size, in_ptr, process_size);
187
192
buffer_size += process_size;
188
193
if (buffer_size>maxFrameSize ()){
189
- LOG (Error, " Increase MAX_FRAME_SIZE > %zu" , buffer_size);
194
+ LOG_HELIX (Error, " Increase MAX_FRAME_SIZE > %zu" , buffer_size);
190
195
}
191
196
assert (buffer_size<=maxFrameSize ());
192
197
193
- LOG (Debug, " appendToBuffer %d + %d -> %u" , buffer_size_old, process_size, buffer_size );
198
+ LOG_HELIX (Debug, " appendToBuffer %d + %d -> %u" , buffer_size_old, process_size, buffer_size );
194
199
return process_size;
195
200
}
196
201
197
202
// / appends the data to the frame buffer and decodes
198
203
size_t writeFrame (const void *in_ptr, size_t in_size){
199
- LOG (Debug, " writeFrame %zu" , in_size);
204
+ LOG_HELIX (Debug, " writeFrame %zu" , in_size);
200
205
size_t result = 0 ;
201
206
// in the beginning we ingnore all data until we found the first synch word
202
207
result = appendToBuffer (in_ptr, in_size);
@@ -205,39 +210,39 @@ class CommonHelix {
205
210
if (r.isValid (maxFrameSize ())){
206
211
decode (r);
207
212
} else {
208
- LOG (Warning, " -> invalid frame size: %d / max: %d" , (int ) r.end -r.start , (int ) maxFrameSize ());
213
+ LOG_HELIX (Warning, " -> invalid frame size: %d / max: %d" , (int ) r.end -r.start , (int ) maxFrameSize ());
209
214
}
210
215
frame_counter++;
211
216
return result;
212
217
}
213
218
214
219
// / returns valid start and end synch word.
215
220
Range synchronizeFrame () {
216
- LOG (Debug, " synchronizeFrame" );
221
+ LOG_HELIX (Debug, " synchronizeFrame" );
217
222
Range range = frameRange ();
218
223
if (range.start <0 ){
219
224
// there is no Synch in the buffer at all -> we can ignore all data
220
225
range.end = -1 ;
221
- LOG (Debug, " -> no synch" )
226
+ LOG_HELIX (Debug, " -> no synch" )
222
227
if (buffer_size==maxFrameSize ()) {
223
228
buffer_size = 0 ;
224
- LOG (Debug, " -> buffer cleared" );
229
+ LOG_HELIX (Debug, " -> buffer cleared" );
225
230
}
226
231
} else if (range.start >0 ) {
227
232
// make sure that buffer starts with a synch word
228
- LOG (Debug, " -> moving to new start %d" ,range.start );
233
+ LOG_HELIX (Debug, " -> moving to new start %d" ,range.start );
229
234
buffer_size -= range.start ;
230
235
assert (buffer_size<=maxFrameSize ());
231
236
232
237
memmove (frame_buffer, frame_buffer + range.start , buffer_size);
233
238
range.end -= range.start ;
234
239
range.start = 0 ;
235
- LOG (Debug, " -> we are at beginning of synch word" );
240
+ LOG_HELIX (Debug, " -> we are at beginning of synch word" );
236
241
} else if (range.start ==0 ) {
237
- LOG (Debug, " -> we are at beginning of synch word" );
242
+ LOG_HELIX (Debug, " -> we are at beginning of synch word" );
238
243
if (range.end <0 && buffer_size == maxFrameSize ()){
239
244
buffer_size = 0 ;
240
- LOG (Debug, " -> buffer cleared" );
245
+ LOG_HELIX (Debug, " -> buffer cleared" );
241
246
}
242
247
}
243
248
return range;
@@ -248,7 +253,7 @@ class CommonHelix {
248
253
Range result;
249
254
result.start = findSynchWord (0 );
250
255
result.end = findSynchWord (result.start +SYNCH_WORD_LEN);
251
- LOG (Debug, " -> frameRange -> %d - %d" , result.start , result.end );
256
+ LOG_HELIX (Debug, " -> frameRange -> %d - %d" , result.start , result.end );
252
257
return result;
253
258
}
254
259
0 commit comments