comparison Small_CPU/Src/wireless.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 /**
2 ******************************************************************************
3 * @file wireless.c
4 * @author heinrichs weikamp gmbh
5 * @date 02-July-2015
6 * @version V0.0.2
7 * @since 24-March-2016
8 * @brief Data transfer via magnetic field using Manchester code
9 *
10 @verbatim
11 ==============================================================================
12 ##### How to use #####
13 ==============================================================================
14 history:
15 160324 V 0.0.2 für Bonex Sender (Only in old hardware. No longer supported)
16
17
18 PA2 triggers to falling edge
19 PA1 triggers to rising edge
20 see baseCPU2.c definitions of ports for details
21 time base is the systick of CMSIS with SysTick->VAL for sub ms info
22
23
24 start id is 4 ms low (fall to rise time)
25 old: followed by 2 ms high (but can continue with high on sending '0' next (Hi->Lo)
26 160324: followed by bit 0: high to low of byte 1
27
28 even index numbers are falling edge
29 odd index numbers are rising edge
30
31 first bit ('1' or '0' can be evaluated with triggerTimeDiffArray[2] (falling edge)
32 if it is much longer than 2ms than the first bit is '0'
33 if it is 2ms than it is '1'
34
35 // Manchester code: 1 = low to high; 0 = high to low;
36 bits are either
37 rising edge at the middle of the bit transfer -> 1
38 falling edge at the middle of the bit transfer -> 0
39
40 an array is used with even index for falling and odd for rising
41 the next time difference array entry is set to 0 to identify the loss of any edge
42 the time index is stored as microseconds
43 and generated by systick and SysTick->VAL (that is counting down from ->LOAD)
44
45 old: startTime is the first falling edge, hence the ver first falling edge of the start byte)
46 160324: startTime is the first rising edge
47
48 160324: total transfer time (excluding start with 8 ms) 10*8*2ms + 2ms (stop bit) = 162 ms
49
50 Definition: first bit is always '0'
51 old: to recognize second start bit easily!
52 old: hence after 2 ms there is a falling edge!
53 160324: after 1 ms is a falling edge of first bit with value 0
54
55 160324:
56 Measurement of send data: length 162 ms including stop bit
57 81 bit
58
59 @endverbatim
60 ******************************************************************************
61 * @attention
62 *
63 * <h2><center>&copy; COPYRIGHT(c) 2016 heinrichs weikamp</center></h2>
64 *
65 ******************************************************************************
66 */
67 /* Includes ------------------------------------------------------------------*/
68 #include "stm32f4xx_hal.h"
69 #include "wireless.h"
70 #include "scheduler.h"
71
72 /* array starts with first falling edge
73 * old: beginning of first start byte,
74 * old: data starts on 3
75 * new: beginning of first bit that is always 0 -> high->low
76 * new: data starts on 0
77 */
78
79 #define ttdaSize (1200)
80
81 #define TIMEOUTSIZE (20000)
82
83 #define WIRELESS_OK (0)
84 #define WIRELESS_FAIL (1)
85
86 #define FALLING (0)
87 #define RISING (1)
88
89 //#define STEP_HALFBIT (1010)
90 #define STEP_HALFBIT (1000)
91 #define LIMIT_STARTBIT (5000)
92 #define MIN_TIME_STARTBIT (3800)
93 #define MAX_TIME_FIRST_STARTBIT (5200)
94 #define MIN_TIME_BOTH_STARTBITS (MIN_TIME_STARTBIT + MIN_TIME_STARTBIT)
95 #define MAX_TIME_BOTH_STARTBITS (MAX_TIME_FIRST_STARTBIT + 4200)
96 // includes necessary start bit (2000 us) and timing issues
97 #define HELPER_MAX_DATA_LENGTH_TOLERANCE (10*STEP_HALFBIT)
98 #define HELPER_MAX_DATA_BYTES (10) ///< 160324: 10, before 8
99 #define MAX_DATA_BITS (HELPER_MAX_DATA_BYTES*8)
100 #define MAX_DATA_LENGTH ((STEP_HALFBIT*2*MAX_DATA_BITS) + HELPER_MAX_DATA_LENGTH_TOLERANCE)
101
102 #define MAX_DIFF_IN_MS ((MAX_DATA_LENGTH+999)/1000)
103
104 void wireless_reset(uint32_t timeMain, uint32_t timeSub);
105
106 /* triggerTimeDiffArray in us with max 65 ms */
107
108 int32_t triggerNewArray[ttdaSize][2];
109
110 int32_t triggerNewArrayDebugStartBits[20][2];
111
112 //uint16_t triggerTimeDiffArray[ttdaSize];
113 uint16_t ttdaPointer;
114 uint32_t startTimeMain;
115
116 uint32_t subDivisorX1000;
117 uint8_t blockDataCapture = 0;
118 uint8_t evaluateRequest = 0; ///<
119
120 uint8_t found_first_4ms_high = 0; ///<
121 uint8_t found_second_4ms_low = 0; ///<
122
123
124
125
126 // ===============================================================================
127 // wireless_init
128 /// @brief has to be called once to initialize the variables
129 // ===============================================================================
130 void wireless_init(void)
131 {
132 subDivisorX1000 = SysTick->LOAD; ///< never changes
133 wireless_reset(0,0);
134 ttdaPointer = 0; ///< is set back again by timeout or on error
135 blockDataCapture = 0;
136 //triggerTimeDiffArray[0] = 0;
137 }
138
139
140 /**
141 ******************************************************************************
142 * @brief RECORDING functions
143 * @author heinrichs weikamp gmbh
144 * @date 03-July-2015
145 * @version V0.0.1
146 * @since 03-July-2015
147 ******************************************************************************
148 */
149
150
151 // ===============================================================================
152 // wireless_getTime
153 /// @brief RECORDING
154 ///
155 /// @param
156 // ===============================================================================
157 void wireless_getTime(uint32_t *timeMain, uint32_t *timeSub)
158 {
159 uint32_t timeSub2, timeMain2;
160
161 *timeSub = SysTick->VAL;
162 *timeMain = HAL_GetTick();
163 timeSub2 = SysTick->VAL;
164 timeMain2 = HAL_GetTick();
165
166 /*
167 static uint32_t difference = 0;
168 if(ttdaPointer == 1)
169 difference = 7; //& breakpoint
170 */
171
172 if((timeSub2 > *timeSub) && (timeMain2 == *timeMain))
173 *timeMain -= 1;
174
175 *timeSub = subDivisorX1000 - *timeSub;
176 *timeSub *= 1000;
177 *timeSub /= subDivisorX1000;
178 }
179
180
181
182 /* stored value _could be_ in multiples of 2 us
183 * to have 1000 for each byte
184 * 0000 is beginning of start bit (always 1)
185 * 1000 is beginning of first bit (if timing is perfect, otherwise less or more)
186 * ...
187 * XXXX000 is beginning of XXXX bit
188 *
189 */
190
191 // ===============================================================================
192 // wireless_time0keeper
193 /// @brief RECORDING
194 ///
195 /// @param
196 /// @return still in us
197 // ===============================================================================
198 int32_t wireless_time0keeper(uint8_t store1_or_diffOut0, uint32_t timeMain, uint32_t timeSub)
199 {
200 static uint32_t storeMain = 0, storeSub = 0;
201
202 /* store time0 */
203 if(store1_or_diffOut0)
204 {
205 storeMain = timeMain;
206 storeSub = timeSub;
207 return 0;
208 }
209
210 /* evaluate time difference */
211 int32_t diff = 0;
212
213 if((timeMain < storeMain) || ((timeMain - storeMain) > MAX_DIFF_IN_MS))
214 return -1;
215
216 diff = timeMain - storeMain;
217 diff *= 1000;
218 diff += timeSub;
219 diff -= storeSub;
220
221 return diff;
222 }
223
224
225 // ===============================================================================
226 // wireless_save_time0
227 /// @brief RECORDING
228 ///
229 /// @param
230 // ===============================================================================
231 void wireless_save_time0(uint32_t timeMain, uint32_t timeSub)
232 {
233 wireless_time0keeper(1, timeMain, timeSub);
234 }
235
236
237 // ===============================================================================
238 // wireless_get_time_since_time0
239 /// @brief RECORDING
240 ///
241 /// @param
242 /// @return
243 // ===============================================================================
244 int32_t wireless_get_time_since_time0(uint32_t timeMain, uint32_t timeSub)
245 {
246 return wireless_time0keeper(0, timeMain, timeSub);
247 }
248
249
250 // ===============================================================================
251 // wireless_get_time_since_previous
252 /// @brief RECORDING
253 ///
254 /// @param
255 /// @return
256 // ===============================================================================
257 int32_t wireless_get_time_since_previous(uint8_t fallingOrRising, uint32_t timeMain, uint32_t timeSub)
258 {
259 int32_t absoluteTimeDiff = wireless_time0keeper(0, timeMain, timeSub);
260
261 if(fallingOrRising == FALLING) // same array
262 {
263 return (absoluteTimeDiff - triggerNewArray[ttdaPointer][FALLING]);
264 }
265 else
266 if(ttdaPointer > 0)
267 {
268 return (absoluteTimeDiff - triggerNewArray[ttdaPointer - 1][RISING]);
269 }
270 else // not possible
271 return -1;
272 }
273
274
275 // ===============================================================================
276 // wireless_reset
277 /// @brief RECORDING
278 ///
279 /// @param
280 // ===============================================================================
281 void wireless_reset(uint32_t timeMain, uint32_t timeSub)
282 {
283 found_first_4ms_high = 0;
284 found_second_4ms_low = 0;
285 ttdaPointer = 0;
286 startTimeMain = 0;
287 evaluateRequest = 0;
288 wireless_save_time0(timeMain, timeSub);
289 triggerNewArray[ttdaPointer][FALLING] = 0;
290 triggerNewArray[ttdaPointer][RISING] = 0;
291 }
292
293
294
295
296 // ===============================================================================
297 // wireless_trigger_FallingEdgeSignalHigh
298 /// @brief RECORDING
299 ///
300 // ===============================================================================
301 void wireless_trigger_FallingEdgeSignalHigh(void)
302 {
303 uint32_t timeSub, timeMain;
304 int32_t timeDifference;
305
306 wireless_getTime(&timeMain, &timeSub);
307
308 if((blockDataCapture) || (evaluateRequest == 1))
309 return;
310
311 if(evaluateRequest == 2)
312 wireless_reset(0, 0);
313
314 if(!found_first_4ms_high) // trying to get first start 4ms
315 {
316 if(ttdaPointer == 0)
317 {
318 wireless_reset(timeMain, timeSub);
319 }
320 else
321 {
322 timeDifference = wireless_get_time_since_time0(timeMain, timeSub);
323 if((timeDifference > 0) && (timeDifference <= LIMIT_STARTBIT))
324 {
325 triggerNewArray[ttdaPointer][0] = timeDifference;
326 }
327 else
328 {
329 wireless_reset(timeMain, timeSub);
330 }
331 }
332 }
333 else // here comes the very important time0 for all following data
334 if(!found_second_4ms_low) ///< the beginning of the very first is recorded here :-)
335 {
336 timeDifference = wireless_get_time_since_time0(timeMain, timeSub);
337 if((timeDifference > 0) && (timeDifference >= MIN_TIME_BOTH_STARTBITS) && (timeDifference <= MAX_TIME_BOTH_STARTBITS))
338 {
339 // now we are ready for data
340 for(int i=0;i<20;i++)
341 {
342 if(i <= ttdaPointer)
343 {
344 triggerNewArrayDebugStartBits[i][FALLING] = triggerNewArray[i][FALLING];
345 triggerNewArrayDebugStartBits[i][RISING] = triggerNewArray[i][FALLING];
346 }
347 else
348 {
349 triggerNewArrayDebugStartBits[i][FALLING] = 0;
350 triggerNewArrayDebugStartBits[i][RISING] = 0;
351 }
352 }
353 wireless_reset(timeMain, timeSub); ///< reset all including ttdaPointer and more
354 startTimeMain = timeMain; ///< set again
355 found_first_4ms_high = 1; ///< set again
356 found_second_4ms_low = 1; ///< set now: ready for recording
357 }
358 }
359 else
360 {
361 timeDifference = wireless_get_time_since_time0(timeMain, timeSub);
362
363 if((timeDifference > MAX_DATA_LENGTH) || (ttdaPointer > (ttdaSize - 2)))
364 {
365 evaluateRequest = 1;
366 }
367 else
368 {
369 triggerNewArray[ttdaPointer][FALLING] = timeDifference;
370 triggerNewArray[ttdaPointer][RISING] = 0;
371 }
372 }
373 }
374
375
376 // ===============================================================================
377 // wireless_trigger_RisingEdgeSilence
378 /// @brief RECORDING
379 ///
380 // ===============================================================================
381 void wireless_trigger_RisingEdgeSilence(void)
382 {
383 uint32_t timeSub, timeMain;
384 int32_t timeDifference;
385
386 wireless_getTime(&timeMain, &timeSub);
387
388 if((blockDataCapture) || (evaluateRequest == 1))
389 return;
390
391 if(evaluateRequest == 2)
392 {
393 wireless_reset(0, 0);
394 return; // Falling Edge first
395 }
396
397 timeDifference = wireless_get_time_since_time0(timeMain, timeSub);
398
399 if(!found_first_4ms_high)
400 {
401 if((timeDifference > 0) && (timeDifference <= MAX_TIME_FIRST_STARTBIT))
402 {
403 triggerNewArray[ttdaPointer++][RISING] = timeDifference;
404 triggerNewArray[ttdaPointer][FALLING] = 0;
405
406 if(timeDifference >= MIN_TIME_STARTBIT) ///< start bit is the 4 ms
407 {
408 found_first_4ms_high = 1;
409 found_second_4ms_low = 0;
410 }
411 }
412 }
413 else
414 {
415 if((timeDifference > MAX_DATA_LENGTH) || (ttdaPointer > (ttdaSize - 2)))
416 {
417 evaluateRequest = 1;
418 }
419 else
420 {
421 triggerNewArray[ttdaPointer++][RISING] = timeDifference;
422 triggerNewArray[ttdaPointer][FALLING] = 0;
423 }
424 }
425 }
426
427
428 // ===============================================================================
429 // wireless_position_next
430 /// @brief RECORDING
431 ///
432 /// @param
433 /// @return
434 // ===============================================================================
435 uint8_t wireless_position_next(uint16_t *ttdaPointerNow, uint8_t *typeNow)
436 {
437 if(*typeNow == FALLING)
438 *typeNow = RISING;
439 else if(*ttdaPointerNow < (ttdaSize - 1))
440 {
441 *ttdaPointerNow += 1;
442 *typeNow = FALLING;
443 }
444 else
445 {
446 return WIRELESS_FAIL;
447 }
448 return WIRELESS_OK;
449
450 }
451
452
453 // ===============================================================================
454 // wireless_position_previous
455 /// @brief RECORDING
456 ///
457 /// @param
458 /// @return
459 // ===============================================================================
460 uint8_t wireless_position_previous(uint16_t *ttdaPointerNow, uint8_t *typeNow)
461 {
462 if(*typeNow == RISING)
463 *typeNow = FALLING;
464 else if(*ttdaPointerNow > 0)
465 {
466 *ttdaPointerNow -= 1;
467 *typeNow = RISING;
468 }
469 else
470 {
471 return WIRELESS_FAIL;
472 }
473 return WIRELESS_OK;
474 }
475
476
477 // ===============================================================================
478 // wireless_position_compare
479 /// @brief RECORDING
480 ///
481 /// @param
482 /// @return
483 // ===============================================================================
484 int8_t wireless_position_compare(uint16_t ttdaPointerLeft, uint8_t typeLeft, uint16_t ttdaPointerRight, uint8_t typeRight)
485 {
486 if(ttdaPointerLeft < ttdaPointerRight)
487 return -1;
488 else
489 if(ttdaPointerLeft > ttdaPointerRight)
490 return 1;
491 else
492 if(typeLeft < typeRight)
493 return -1;
494 else
495 if(typeLeft > typeRight)
496 return 1;
497 else
498 return 0;
499 }
500
501
502 // ===============================================================================
503 // wireless_debug
504 /// @brief
505 ///
506 /// @param
507 /// @return
508 // ===============================================================================
509 /* outlined because of errors while compiling
510 void wireless_debug(int8_t *adcData, uint16_t max_size_adc)
511 {
512 // debug
513 uint32_t dataVisual[201];
514 uint8_t dataVisualValue[201];
515 int8_t dataVisualResult[201];
516
517 dataVisualValue[0] = 1;
518
519 for(int i=0;i<201;i++)
520 dataVisualResult[i] = -1;
521
522 for(int i=0;i<201-4;i +=4)
523 {
524 dataVisualValue[i] = 1;
525 dataVisualValue[i+1] = 1;
526 dataVisualValue[i+2] = 0;
527 dataVisualValue[i+3] = 0;
528 }
529
530 dataVisual[0] = triggerNewArray[0][FALLING];
531
532 int j = 1;
533 uint32_t valueStore = 0;
534 for(int i=0;i<50;i++)
535 {
536 valueStore = triggerNewArray[i][FALLING];
537 dataVisual[j++] = valueStore;
538 dataVisual[j++] = valueStore + 1;
539 valueStore = triggerNewArray[i][RISING];
540 dataVisual[j++] = valueStore;
541 dataVisual[j++] = valueStore + 1;
542 }
543
544
545 if(max_size_adc > 0)
546 {
547 int jStep = 0;
548 int jData = 0;
549 for(int i=0;i<201;i++)
550 {
551 if(dataVisual[i] >= jStep)
552 {
553 if(adcData[jData] > 0)
554 dataVisualResult[i] = 1;
555 else
556 dataVisualResult[i] = 0;
557 jStep += STEP_HALFBIT + STEP_HALFBIT;
558 jData++;
559 if(jData >= max_size_adc)
560 break;
561 }
562 }
563 }
564 }
565 */
566
567 // ===============================================================================
568 // wireless_debug_test_failed_AACCF1010203
569 /// @brief
570 ///
571 /// @param
572 /// @return
573 // ===============================================================================
574 uint8_t wireless_debug_test_failed_AACCF1010203(uint8_t *data)
575 {
576 if(data[0] != 0xAA)
577 return 1;
578 if(data[1] != 0xCC)
579 return 1;
580 if(data[2] != 0xF1)
581 return 1;
582 if(data[3] != 0x01)
583 return 1;
584 if(data[4] != 0x02)
585 return 0;
586 if(data[5] != 0x03)
587 return 1;
588
589 return 0;
590 }
591
592
593 // ===============================================================================
594 // wireless_check_crc_failed
595 /// @brief
596 ///
597 /// @param
598 /// @return
599 // ===============================================================================
600 uint8_t wireless_check_crc_failed(uint8_t *dataOut, uint8_t maxData)
601 {
602 return (wireless_debug_test_failed_AACCF1010203(dataOut));
603 }
604
605
606 /**
607 ******************************************************************************
608 * @brief EVALUATION functions
609 * @author heinrichs weikamp gmbh
610 * @date 03-July-2015
611 * @version V0.0.2
612 * @since 14-July-2015
613 ******************************************************************************
614 */
615
616 // ===============================================================================
617 // wireless_time0keeper
618 /// @brief EVALUATION
619 ///
620 /// @param
621 /// @return
622 // ===============================================================================
623 uint8_t wireless_evaluate_internal_loop(uint8_t *dataOut, uint8_t maxData, int32_t shift, uint8_t *confidence)
624 {
625 // variables
626 int iOut = 0;
627 int jAdc = 0;
628
629 int8_t adcData[MAX_DATA_BITS];
630 uint16_t adcPointer = 0;
631
632 int8_t bitLeft = 0;
633 int8_t bitRight = 0;
634
635 uint16_t ttdaPointerStart = 0;
636 uint16_t ttdaPointerEnd = 0;
637 uint8_t typeStart = RISING;
638 uint8_t typeEnd = RISING;
639 int32_t startTimeHalfBit = 0;
640 int32_t endTimeHalfBit = 0;
641 int32_t startOfThisPeak = 0;
642 int32_t endOfThisPeak = 0;
643 uint8_t wirelessErrorStatus = 0;
644 uint8_t timeToStop = 0;
645 int32_t valueSingle = 0;
646 int32_t halfbitTemp = 0;
647 int confidenceTemp = 0;
648
649 // safety end for all loops coming
650 triggerNewArray[ttdaPointer][RISING] = INT32_MAX;
651
652 ttdaPointerStart = 0;
653 ttdaPointerEnd = 0;
654 typeStart = RISING;
655 typeEnd = RISING;
656 startTimeHalfBit = 0;
657 endTimeHalfBit = shift;
658 adcPointer = 0;
659
660 while(!timeToStop)
661 {
662 // start is latest start
663 ttdaPointerEnd = ttdaPointerStart;
664 typeEnd = typeStart;
665 for(int doItTwice=0;doItTwice<2;doItTwice++)
666 {
667 startTimeHalfBit = endTimeHalfBit;
668 endTimeHalfBit += STEP_HALFBIT;
669 // find the end for this half bit; this will include values that continue to the next halfbit and negative values
670 while(triggerNewArray[ttdaPointerEnd][typeEnd] < endTimeHalfBit)
671 wireless_position_next(&ttdaPointerEnd,&typeEnd);
672
673 if(triggerNewArray[ttdaPointerEnd][typeEnd] == INT32_MAX)
674 {
675 timeToStop = 1;
676 break;
677 }
678 startOfThisPeak = startTimeHalfBit;
679 wirelessErrorStatus = 0;
680 halfbitTemp = 0;
681 while(!wirelessErrorStatus && (wireless_position_compare(ttdaPointerStart,typeStart, ttdaPointerEnd,typeEnd) <= 0))
682 {
683 endOfThisPeak = triggerNewArray[ttdaPointerStart][typeStart];
684 if(endOfThisPeak <= startOfThisPeak)
685 {
686 wireless_position_next(&ttdaPointerStart,&typeStart);
687 }
688 else
689 {
690 // TODO: what about time difference errors?
691 if(endOfThisPeak >= endTimeHalfBit)
692 valueSingle = endTimeHalfBit - startOfThisPeak;
693 else
694 valueSingle = endOfThisPeak - startOfThisPeak;
695
696 if(typeStart == RISING)
697 {
698 halfbitTemp += valueSingle;
699 }
700 // next, also valid for every next halfbit
701 if(endOfThisPeak <= endTimeHalfBit)
702 {
703 startOfThisPeak = endOfThisPeak;
704 wireless_position_next(&ttdaPointerStart,&typeStart);
705 }
706 else
707 {
708 startOfThisPeak = endTimeHalfBit;
709 }
710 // should not be necessary, anyway
711 if(startOfThisPeak == endTimeHalfBit)
712 break;
713 }
714 }
715 // store
716 halfbitTemp *= 100;
717 halfbitTemp /= STEP_HALFBIT;
718 if(halfbitTemp > 100) halfbitTemp = 100;
719 if(doItTwice == 0)
720 {
721 bitLeft = halfbitTemp;
722 }
723 else
724 {
725 bitRight = halfbitTemp;
726 }
727 }
728 // Gewichtung und Bit Generierung
729 adcData[adcPointer++] = (int8_t)((bitLeft - bitRight)); // possitive value
730 if(adcPointer >= MAX_DATA_BITS)
731 timeToStop = 1;
732 }
733
734 // Auswertung
735 jAdc = 0;
736 iOut = 0;
737
738 for(int i=0;i<maxData;i++)
739 {
740 dataOut[i] = 0;
741 for(int j=0;j<8;j++)
742 {
743 dataOut[i] *= 2;
744 if((adcData[jAdc++] > 0))
745 dataOut[i] |= 1;
746 if(jAdc >= adcPointer)
747 {
748 j++;
749 while(j<8)
750 {
751 jAdc = adcPointer + 1; // end signal
752 dataOut[i] *= 2;
753 j++;
754 }
755 break;
756 }
757 }
758 if(jAdc > adcPointer)
759 break;
760 iOut++;
761 }
762
763 confidenceTemp = 0;
764 for(int i=0;i<adcPointer;i++)
765 {
766 if(adcData[i] < 0)
767 confidenceTemp -= adcData[i];
768 else
769 confidenceTemp += adcData[i];
770 }
771 // confidence in adcData is 0 to 127 only
772 confidenceTemp *= 2;
773 *confidence = (uint8_t)(confidenceTemp/adcPointer);
774
775 /*
776 if( (iOut>= 5) && wireless_debug_test_failed_AACCF1010203(dataOut))
777 wireless_debug(adcData,MAX_DATA_BITS);
778 */
779 return iOut;
780
781 }
782
783
784 // ===============================================================================
785 // wireless_evaluate_crc_error
786 /// @brief EVALUATION
787 ///
788 /// @param
789 /// @return
790 // ===============================================================================
791 uint8_t wireless_evaluate_crc_error(uint8_t *dataIn, uint8_t maxData)
792 {
793 uint8_t crcTest = 0;
794 for(int i=0; i< maxData; i++)
795 crcTest ^= dataIn[i];
796
797 return crcTest;
798 }
799
800
801 // ===============================================================================
802 // wireless_evaluate
803 /// @brief EVALUATION
804 ///
805 /// @param
806 /// @return
807 // ===============================================================================
808 uint8_t wireless_evaluate(uint8_t *dataOut, uint8_t maxData, uint8_t *confidence)
809 {
810 uint32_t timeTick;
811 uint32_t timeElapsed;
812
813 timeTick = HAL_GetTick();
814 timeElapsed = time_elapsed_ms(startTimeMain,timeTick);
815
816 uint8_t start = 0;
817 int iOut = 0;
818
819 // check condition for start
820 if(evaluateRequest == 2)
821 return 0;
822
823 if(evaluateRequest == 1)
824 start = 1;
825
826 if((ttdaPointer > 10) && (timeElapsed > (MAX_DATA_LENGTH/1000)))
827 start = 1;
828
829 if(!start)
830 return 0;
831
832 // start
833 blockDataCapture = 1;
834
835 // evaluate
836 iOut = wireless_evaluate_internal_loop(dataOut, maxData, 0, confidence);
837
838
839 /*
840 for(int i=0; i>=-500; i -= 100)
841 {
842 iOut = wireless_evaluate_internal_loop(dataOut, maxData, i, confidence);
843 if(iOut < 5)
844 break;
845 if(wireless_check_crc_failed(dataOut,iOut) == 0)
846 break;
847 }
848 */
849 // end
850 evaluateRequest = 2;
851 blockDataCapture = 0;
852
853 return iOut;
854 }
855
856 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/