Rev 14 | Rev 16 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 14 | Rev 15 | ||
---|---|---|---|
Line 28... | Line 28... | ||
28 | #include "libPlx/plx.h" |
28 | #include "libPlx/plx.h" |
29 | #include "libSerial/serial.h" |
29 | #include "libSerial/serial.h" |
30 | #include "libIgnTiming/timing.h" |
30 | #include "libIgnTiming/timing.h" |
31 | #include "libIgnTiming/edis.h" |
31 | #include "libIgnTiming/edis.h" |
32 | #include "saveTiming.h" |
32 | #include "saveTiming.h" |
- | 33 | #include "libPLX/commsLib.h" |
|
33 | /* USER CODE END Includes */ |
34 | /* USER CODE END Includes */ |
34 | 35 | ||
35 | /* Private typedef -----------------------------------------------------------*/ |
36 | /* Private typedef -----------------------------------------------------------*/ |
36 | /* USER CODE BEGIN PTD */ |
37 | /* USER CODE BEGIN PTD */ |
37 | 38 | ||
Line 61... | Line 62... | ||
61 | 62 | ||
62 | UART_HandleTypeDef huart2; |
63 | UART_HandleTypeDef huart2; |
63 | 64 | ||
64 | /* USER CODE BEGIN PV */ |
65 | /* USER CODE BEGIN PV */ |
65 | int const T100MS = 100; |
66 | int const T100MS = 100; |
66 | // index for all observations |
- | |
67 | char obsIndex[PLX_MAX_OBS]; |
- | |
68 | 67 | ||
69 | int const DISPLAY_REINITIALISE = 60 * 1000; |
68 | int const DISPLAY_REINITIALISE = 60 * 1000; |
70 | // compensated pressure in mb * 100 |
69 | // compensated pressure in mb * 100 |
71 | uint32_t comp_pres = 0; |
70 | uint32_t comp_pres = 0; |
72 | // compensated temperature |
71 | // compensated temperature |
73 | int32_t comp_temp = -10000; |
72 | int32_t comp_temp = -10000; |
74 | 73 | ||
75 | int32_t timing = 0; |
74 | int32_t timing = 0; |
- | 75 | ||
- | 76 | /// A timer flag used to tell the PLX scanning code that it is time to send a frame |
|
- | 77 | int8_t timerFlag = 0; |
|
- | 78 | /// @brief count of how many consecutive timeouts before auto sending begins |
|
- | 79 | int8_t timeoutCount = 0; |
|
- | 80 | ||
76 | /* USER CODE END PV */ |
81 | /* USER CODE END PV */ |
77 | 82 | ||
78 | /* Private function prototypes -----------------------------------------------*/ |
83 | /* Private function prototypes -----------------------------------------------*/ |
79 | void SystemClock_Config(void); |
84 | void SystemClock_Config(void); |
80 | static void MX_GPIO_Init(void); |
85 | static void MX_GPIO_Init(void); |
Line 93... | Line 98... | ||
93 | { |
98 | { |
94 | for (int i = 0; i < sizeof(PLX_SensorInfo); ++i) |
99 | for (int i = 0; i < sizeof(PLX_SensorInfo); ++i) |
95 | PutCharSerial(uc, info->bytes[i]); |
100 | PutCharSerial(uc, info->bytes[i]); |
96 | } |
101 | } |
97 | 102 | ||
98 | void processObservations() |
103 | void libPLXcallbackResetSerialTimeout() |
- | 104 | { |
|
- | 105 | timerFlag = 0; |
|
- | 106 | timeoutCount = 0; |
|
- | 107 | } |
|
- | 108 | ||
- | 109 | void libPLXcallbackSendUserData() |
|
99 | { |
110 | { |
100 | // send MAP |
111 | // send MAP |
101 | PLX_SensorInfo info; |
112 | PLX_SensorInfo info; |
102 | ConvToPLXInstance(obsIndex[PLX_MAP]++, &info); |
113 | ConvToPLXInstance(libPLXgetNextInstance(PLX_MAP), &info); |
103 | ConvToPLXAddr(PLX_MAP, &info); |
114 | ConvToPLXAddr(PLX_MAP, &info); |
104 | ConvToPLXReading(ConveriMFDData2Raw(PLX_MAP, PRESSURE_kPa, (float)(comp_pres) / 100.0), &info); |
115 | ConvToPLXReading(ConveriMFDData2Raw(PLX_MAP, PRESSURE_kPa, (float)(comp_pres) / 100.0), &info); |
105 | sendInfo(&uc2, &info); |
116 | sendInfo(&uc2, &info); |
106 | 117 | ||
107 | ConvToPLXInstance(obsIndex[PLX_Timing]++, &info); |
118 | ConvToPLXInstance(libPLXgetNextInstance(PLX_Timing), &info); |
108 | ConvToPLXAddr(PLX_Timing, &info); |
119 | ConvToPLXAddr(PLX_Timing, &info); |
109 | ConvToPLXReading(ConveriMFDData2Raw(PLX_Timing, 0, (float)(timing) / TIMING_SCALE), &info); |
120 | ConvToPLXReading(ConveriMFDData2Raw(PLX_Timing, 0, (float)(timing) / TIMING_SCALE), &info); |
110 | sendInfo(&uc2, &info); |
121 | sendInfo(&uc2, &info); |
111 | } |
122 | } |
112 | 123 | ||
Line 193... | Line 204... | ||
193 | 204 | ||
194 | uint32_t displayOff = lastTick + 10000; |
205 | uint32_t displayOff = lastTick + 10000; |
195 | uint32_t displayReinitialise = lastTick + DISPLAY_REINITIALISE; // every minute, reinitialise display because of risk of noise |
206 | uint32_t displayReinitialise = lastTick + DISPLAY_REINITIALISE; // every minute, reinitialise display because of risk of noise |
196 | 207 | ||
197 | uint8_t intensity = 2; |
208 | uint8_t intensity = 2; |
198 | uint32_t timeout = 0; |
- | |
199 | uint8_t send = 0; // enable sending our PLX data when non zero |
- | |
200 | ResetRxBuffer(&uc2); |
- | |
201 | 209 | ||
202 | // used to store data |
- | |
203 | PLX_SensorInfo info; |
- | |
204 | // counter of information |
210 | /// @brief time of next auto send if needed |
205 | int infoCount = -1; |
211 | uint32_t timeout = 0; |
206 | memset(obsIndex, 0, PLX_MAX_OBS); // zero incoming obsevation index |
- | |
207 | 212 | ||
208 | // dont do this loadTimingInfoFromNvram(); |
213 | ResetRxBuffer(&uc2); |
209 | 214 | ||
- | 215 | resetPLX(); |
|
210 | // HAL_IWDG_Init(&hiwdg); |
216 | // HAL_IWDG_Init(&hiwdg); |
211 | /* USER CODE END 2 */ |
217 | /* USER CODE END 2 */ |
212 | 218 | ||
213 | /* Infinite loop */ |
219 | /* Infinite loop */ |
214 | /* USER CODE BEGIN WHILE */ |
220 | /* USER CODE BEGIN WHILE */ |
Line 285... | Line 291... | ||
285 | cc_feed_timing(timing); |
291 | cc_feed_timing(timing); |
286 | int microsecs = mapTimingToMicroseconds(timing, 0); |
292 | int microsecs = mapTimingToMicroseconds(timing, 0); |
287 | __HAL_TIM_SET_AUTORELOAD(&htim1, microsecs + SAW_DELAY); |
293 | __HAL_TIM_SET_AUTORELOAD(&htim1, microsecs + SAW_DELAY); |
288 | } |
294 | } |
289 | } |
295 | } |
290 | // Handle PLX |
- | |
291 | // poll the input for a stop bit or timeout |
- | |
292 | if (PollSerial(&uc2)) |
- | |
293 | { |
- | |
294 | HAL_IWDG_Refresh(&hiwdg); |
- | |
295 | timeout = HAL_GetTick() + T100MS * 2; |
- | |
296 | char c = GetCharSerial(&uc2); |
- | |
297 | - | ||
298 | if (c != PLX_Stop) |
- | |
299 | { |
- | |
300 | PutCharSerial(&uc2, c); // echo all but the stop bit |
- | |
301 | } |
- | |
302 | else |
- | |
303 | { // must be a stop character |
- | |
304 | send = 1; // start our sending process |
- | |
305 | } |
- | |
306 | // look up the i |
- | |
307 | if (c == PLX_Start) |
- | |
308 | { |
- | |
309 | infoCount = 0; |
- | |
310 | } |
- | |
311 | else |
- | |
312 | { |
- | |
313 | info.bytes[infoCount++] = c; |
- | |
314 | // process the sensor info field : discover maximum observation index |
- | |
315 | if (infoCount == sizeof(PLX_SensorInfo)) |
- | |
316 | { |
- | |
317 | infoCount = 0; |
- | |
318 | int addr = ConvPLXAddr(&info); |
- | |
319 | if (addr < PLX_MAX_OBS && (obsIndex[addr] <= info.Instance)) |
- | |
320 | obsIndex[addr] = info.Instance + 1; |
- | |
321 | } |
- | |
322 | } |
- | |
323 | - | ||
324 | if (c == PLX_Stop) |
- | |
325 | infoCount = -1; |
- | |
326 | } |
- | |
327 | 296 | ||
328 | // sort out auto-sending |
297 | // sort out auto-sending |
329 | if (HAL_GetTick() > timeout) |
298 | if (HAL_GetTick() > timeout) |
330 | { |
299 | { |
331 | PutCharSerial(&uc2, PLX_Start); |
- | |
332 | timeout = HAL_GetTick() + T100MS; |
300 | timeout = HAL_GetTick() + T100MS; |
- | 301 | if (timeoutCount < 2) |
|
- | 302 | timeoutCount++; |
|
- | 303 | else |
|
333 | send = 1; |
304 | timerFlag = 1; |
334 | } |
305 | } |
335 | 306 | ||
336 | if (send) |
- | |
337 | { |
- | |
338 | send = 0; |
307 | // Handle PLX |
339 | - | ||
340 | // send the observations |
- | |
341 | processObservations(); |
- | |
342 | memset(obsIndex, 0, PLX_MAX_OBS); // zero incoming obsevation index |
- | |
343 | // |
- | |
344 | PutCharSerial(&uc2, PLX_Stop); |
308 | libPLXpollData(&uc2, timerFlag); |
345 | } |
- | |
346 | 309 | ||
347 | /* USER CODE END WHILE */ |
310 | /* USER CODE END WHILE */ |
348 | 311 | ||
349 | /* USER CODE BEGIN 3 */ |
312 | /* USER CODE BEGIN 3 */ |
350 | watchdogWrite(); |
313 | watchdogWrite(); |