4 int32_t Restore_long(int idx
);
5 int16_t Restore_short(int idx
);
6 uint8_t Restore_byte(int idx
);
7 void pitlab_encodeTargetData(uint8_t c
);
8 void preProcessHexString(void);
9 void processPitlabFrame(void);
10 uint8_t hex2int(uint8_t *a
, uint8_t len
);
12 Telemetry packet on USART port is always 10 ASCII characters as follow:
14 ('A'+ N) //packet numer 'N': 'A'=0, 'B'=1 'C'=2 etc
15 32 bit data in HEX format, MSB first
31 //uint8_t type is single, unsigned byte (unsigned char)
32 uint8_t lsRxData
[5]; //bufor na kolejne bajty odczytane z komunikatu (dan Hex zamienione na bajty)
35 enum PitlabDataState
{
42 static uint8_t dataState
= IDLE
;
45 int32_t Restore_long(int idx
)
47 return (int32_t)lsRxData
[idx
] + ((int32_t)lsRxData
[idx
+1] << 8) + ((int32_t)lsRxData
[idx
+2] << 16) + ((int32_t)lsRxData
[idx
+3] << 24);
50 int16_t Restore_short(int idx
)
52 return (int16_t)lsRxData
[idx
] + ((int16_t)lsRxData
[idx
+1] << 8);
55 uint8_t Restore_byte(int idx
)
61 void pitlab_encodeTargetData(uint8_t c
) {
63 if (dataState
== IDLE
&& c
== '$') {
65 dataState
= STATE_START1
;
67 } else if (dataState
== STATE_START1
) {
68 lsRxData
[0] = c
- 'A';
69 dataState
=STATE_START2
;
71 } else if (dataState
== STATE_START2
) {
72 hexString
[dataIdx
++] = c
;
74 dataState
= STATE_DATA
;
76 if (dataState
== STATE_DATA
){
77 preProcessHexString();
83 void preProcessHexString(void){
84 uint8_t str_buffer
[2];
86 for(uint8_t i
= 1; i
< 5; i
++){
87 for(uint8_t j
= 0; j
< 2; ++j
){
88 str_buffer
[j
] = hexString
[sIdx
++];
90 lsRxData
[5-i
] = hex2int(str_buffer
,2);
94 void processPitlabFrame(void){
98 telemetry_sats
= (uint16_t)Restore_byte(4);
100 case 10: // 10 = K, pos 3 : Absolute altitude, 1 = B, pos 2 : Relative altitude
101 telemetry_alt
= (int16_t)Restore_short(3);
105 gps_lon
= Restore_long(1);
106 telemetry_lon
= (int32_t)(round(((double)gps_lon
* 100.0)/60.0));
109 gps_lat
= Restore_long(1);
110 telemetry_lat
= (int32_t)(round(((double)gps_lat
* 100.0)/60.0));
111 if(telemetry_sats
>= 5) gotFix
= true;
116 uint8_t hex2int(uint8_t *a
, uint8_t len
)
123 val
+= (a
[i
]-48)*(1<<(4*(len
-1-i
)));
125 val
+= (a
[i
]-55)*(1<<(4*(len
-1-i
)));