@@ -77,16 +77,19 @@ class CommonHelix {
7777 if (active){
7878 end ();
7979 }
80+
81+ allocateDecoder ();
82+
8083 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 ());
8285 frame_buffer = new uint8_t [maxFrameSize ()];
8386 }
8487 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 ());
8689 pwm_buffer = new short [maxPWMSize ()];
8790 }
8891 if (pwm_buffer==nullptr || frame_buffer==nullptr ){
89- LOG (Error, " Not enough memory for buffers" );
92+ LOG_HELIX (Error, " Not enough memory for buffers" );
9093 active = false ;
9194 return ;
9295 }
@@ -108,7 +111,7 @@ class CommonHelix {
108111 */
109112
110113 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);
112115 size_t start = 0 ;
113116 if (active){
114117 uint8_t * ptr8 = (uint8_t * )in_ptr;
@@ -118,15 +121,15 @@ class CommonHelix {
118121 // we have some space left in the buffer
119122 int written_len = writeFrame (ptr8+start, write_len);
120123 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);
122125 write_len = min (in_size - start, static_cast <size_t >(maxFrameSize ()-buffer_size));
123126 // add delay - e.g. needed by esp32 and esp8266
124127 if (delay_ms>0 ){
125128 delay (delay_ms);
126129 }
127130 }
128131 } else {
129- LOG (Warning, " CommonHelix not active" );
132+ LOG_HELIX (Warning, " CommonHelix not active" );
130133 }
131134
132135 return start;
@@ -156,6 +159,8 @@ class CommonHelix {
156159 Print *out = nullptr ;
157160#endif
158161
162+ virtual void allocateDecoder () = 0;
163+
159164 // / Provides the maximum frame size - this is allocated on the heap and you can reduce the heap size my minimizing this value
160165 virtual size_t maxFrameSize () = 0;
161166
@@ -180,23 +185,23 @@ class CommonHelix {
180185
181186 // / we add the data to the buffer until it is full
182187 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);
184189 int buffer_size_old = buffer_size;
185190 int process_size = min ((int )(maxFrameSize () - buffer_size), in_size);
186191 memmove (frame_buffer+buffer_size, in_ptr, process_size);
187192 buffer_size += process_size;
188193 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);
190195 }
191196 assert (buffer_size<=maxFrameSize ());
192197
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 );
194199 return process_size;
195200 }
196201
197202 // / appends the data to the frame buffer and decodes
198203 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);
200205 size_t result = 0 ;
201206 // in the beginning we ingnore all data until we found the first synch word
202207 result = appendToBuffer (in_ptr, in_size);
@@ -205,39 +210,39 @@ class CommonHelix {
205210 if (r.isValid (maxFrameSize ())){
206211 decode (r);
207212 } 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 ());
209214 }
210215 frame_counter++;
211216 return result;
212217 }
213218
214219 // / returns valid start and end synch word.
215220 Range synchronizeFrame () {
216- LOG (Debug, " synchronizeFrame" );
221+ LOG_HELIX (Debug, " synchronizeFrame" );
217222 Range range = frameRange ();
218223 if (range.start <0 ){
219224 // there is no Synch in the buffer at all -> we can ignore all data
220225 range.end = -1 ;
221- LOG (Debug, " -> no synch" )
226+ LOG_HELIX (Debug, " -> no synch" )
222227 if (buffer_size==maxFrameSize ()) {
223228 buffer_size = 0 ;
224- LOG (Debug, " -> buffer cleared" );
229+ LOG_HELIX (Debug, " -> buffer cleared" );
225230 }
226231 } else if (range.start >0 ) {
227232 // 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 );
229234 buffer_size -= range.start ;
230235 assert (buffer_size<=maxFrameSize ());
231236
232237 memmove (frame_buffer, frame_buffer + range.start , buffer_size);
233238 range.end -= range.start ;
234239 range.start = 0 ;
235- LOG (Debug, " -> we are at beginning of synch word" );
240+ LOG_HELIX (Debug, " -> we are at beginning of synch word" );
236241 } 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" );
238243 if (range.end <0 && buffer_size == maxFrameSize ()){
239244 buffer_size = 0 ;
240- LOG (Debug, " -> buffer cleared" );
245+ LOG_HELIX (Debug, " -> buffer cleared" );
241246 }
242247 }
243248 return range;
@@ -248,7 +253,7 @@ class CommonHelix {
248253 Range result;
249254 result.start = findSynchWord (0 );
250255 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 );
252257 return result;
253258 }
254259
0 commit comments