Rev 65 | Rev 67 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 65 | Rev 66 | ||
|---|---|---|---|
| Line 258... | Line 258... | ||
| 258 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
258 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
| 259 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
259 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
| 260 | 260 | ||
| 261 | setRmcCallback(&rmc_callback); |
261 | setRmcCallback(&rmc_callback); |
| 262 | 262 | ||
| - | 263 | // data timeout |
|
| - | 264 | uint32_t timeout = 0; // |
|
| - | 265 | ||
| - | 266 | uint32_t nextTick = 0; |
|
| - | 267 | uint8_t log = 0; |
|
| - | 268 | // PLX decoder protocols |
|
| - | 269 | char PLXPacket = 0; |
|
| - | 270 | for (i = 0; i < MAXRDG; i++) |
|
| - | 271 | { |
|
| - | 272 | Info[i].Max = 0; |
|
| - | 273 | Info[i].Min = 0xFFF; |
|
| - | 274 | Info[i].sum = 0; |
|
| - | 275 | Info[i].count = 0; |
|
| - | 276 | Info[i].updated = 0; |
|
| - | 277 | Info[i].lastUpdated = 0; |
|
| - | 278 | } |
|
| - | 279 | ||
| - | 280 | int PLXPtr = 0; |
|
| - | 281 | int logCount = 0; |
|
| - | 282 | ||
| 263 | /* USER CODE END 2 */ |
283 | /* USER CODE END 2 */ |
| 264 | 284 | ||
| 265 | /* Infinite loop */ |
285 | /* Infinite loop */ |
| 266 | /* USER CODE BEGIN WHILE */ |
286 | /* USER CODE BEGIN WHILE */ |
| 267 | while (1) |
287 | while (1) |
| Line 280... | Line 300... | ||
| 280 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, |
300 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, |
| 281 | GPIO_PIN_RESET); |
301 | GPIO_PIN_RESET); |
| 282 | } |
302 | } |
| 283 | } |
303 | } |
| 284 | 304 | ||
| 285 | uint32_t timeout = 0; // |
- | |
| 286 | - | ||
| 287 | uint32_t nextTick = 0; |
- | |
| 288 | uint8_t log = 0; |
- | |
| 289 | uint8_t logCount = 1000 / LOGGER_INTERVAL; |
305 | // Handle the bluetooth pairing / reset function by pressing both buttons. |
| 290 | // PLX decoder protocols |
- | |
| 291 | char PLXPacket = 0; |
- | |
| 292 | for (i = 0; i < MAXRDG; i++) |
306 | if ((push_pos[0] == 1) && (push_pos[1] == 1)) |
| 293 | { |
307 | { |
| 294 | Info[i].Max = 0; |
- | |
| 295 | Info[i].Min = 0xFFF; // 12 bit max value |
308 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
| 296 | Info[i].sum = 0; // |
309 | GPIO_PIN_RESET); |
| 297 | Info[i].count = 0; |
- | |
| 298 | } |
310 | } |
| 299 | - | ||
| 300 | int PLXPtr = 0; |
- | |
| 301 | - | ||
| 302 | while (1) |
311 | else |
| 303 | { |
312 | { |
| - | 313 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
|
| - | 314 | GPIO_PIN_SET); |
|
| - | 315 | } |
|
| 304 | 316 | ||
| 305 | // poll GPS Position/time on UART4 |
317 | // poll GPS Position/time on UART4 |
| 306 | (void)updateLocation(&loc, &uc4); |
318 | (void)updateLocation(&loc, &uc4); |
| 307 | if (loc.valid == 'V') |
319 | if (loc.valid == 'V') |
| 308 | memset(loc.time, '-', 6); |
320 | memset(loc.time, '-', 6); |
| 309 | 321 | ||
| 310 | // if permitted, log data from RMC packet |
322 | // if permitted, log data from RMC packet |
| 311 | if (rmc_length && btConnected()) |
323 | if (btConnected()) |
| - | 324 | { |
|
| - | 325 | // Any RMC data, send it, reset the logger timeout |
|
| - | 326 | if (rmc_length) |
|
| 312 | { |
327 | { |
| 313 | sendString(&uc3, rmc_buff, rmc_length); |
328 | sendString(&uc3, (const char *)rmc_buff, rmc_length); |
| 314 | rmc_length = 0; |
329 | rmc_length = 0; |
| 315 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
330 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
| 316 | logCount = 0; |
331 | log = 1; // send out associated data over Bluetooth because triggered by recieving RMC |
| 317 | log = 1; |
332 | logCount = 0; // first sample set this second numbered 0 |
| 318 | } |
333 | } |
| 319 | 334 | ||
| 320 | // time several counted logger intervals after RMC recieved, enable logger each timeout. |
335 | // Timeout for data logging regularly |
| 321 | if (logCount < ((1000 / LOGGER_INTERVAL) - 1) && HAL_GetTick() > nextTick) |
336 | if (HAL_GetTick() > nextTick) |
| 322 | { |
337 | { |
| 323 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
338 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
| 324 | ++logCount; |
339 | logCount++; |
| - | 340 | if (logCount > (1000 / LOGGER_INTERVAL)) |
|
| - | 341 | logCount = 0; |
|
| 325 | log = 1; |
342 | log = 1; |
| 326 | } |
343 | } |
| 327 | 344 | ||
| 328 | // Handle the bluetooth pairing / reset function by pressing both buttons. |
- | |
| 329 | if ((push_pos[0] == 1) && (push_pos[1] == 1)) |
345 | if (log) |
| 330 | { |
346 | { |
| - | 347 | log = 0; |
|
| 331 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
348 | // Send items to BT if it is in connected state |
| - | 349 | for (int i = 0; i < PLXItems; ++i) |
|
| - | 350 | { |
|
| - | 351 | char outbuff[100]; |
|
| - | 352 | ||
| - | 353 | int cnt = small_sprintf(outbuff, |
|
| - | 354 | "$PLLOG,%d,%d,%d,%ld", |
|
| - | 355 | logCount, |
|
| - | 356 | Info[i].observation, |
|
| - | 357 | Info[i].instance, |
|
| - | 358 | Info[i].count == 0 ? 0 : Info[i].sum / Info[i].count); |
|
| - | 359 | ||
| - | 360 | // NMEA style checksum |
|
| - | 361 | int ck; |
|
| - | 362 | int sum = 0; |
|
| - | 363 | for (ck = 1; ck < cnt; ck++) |
|
| - | 364 | sum += outbuff[ck]; |
|
| - | 365 | cnt += small_sprintf(outbuff + cnt, "*%02X\n", |
|
| 332 | GPIO_PIN_RESET); |
366 | sum & 0xFF); |
| - | 367 | sendString(&uc3, outbuff, cnt); |
|
| - | 368 | } |
|
| 333 | } |
369 | } |
| - | 370 | } |
|
| - | 371 | ||
| - | 372 | // determine if we are getting any data from the interface |
|
| - | 373 | uint16_t cc = SerialCharsReceived(&uc1); |
|
| 334 | else |
374 | int chr; |
| - | 375 | if (cc == 0) |
|
| - | 376 | { |
|
| - | 377 | timeout++; |
|
| - | 378 | if (btConnected() && (timeout % 1000 == 0)) |
|
| 335 | { |
379 | { |
| 336 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
380 | const char msg[] = "Timeout\r\n"; |
| 337 | GPIO_PIN_SET); |
381 | sendString(&uc3, msg, sizeof(msg)); |
| 338 | } |
382 | } |
| 339 | 383 | ||
| 340 | uint16_t cc = SerialCharsReceived(&uc1); |
- | |
| 341 | int chr; |
- | |
| 342 | if (cc == 0) |
384 | if (timeout > 60000) |
| 343 | { |
385 | { |
| 344 | timeout++; |
- | |
| 345 | if (timeout % 1000 == 0) |
- | |
| 346 | { |
- | |
| 347 | const char msg[] = "Timeout\r\n"; |
- | |
| 348 | sendString(&uc3, msg, sizeof(msg)); |
- | |
| 349 | } |
- | |
| 350 | - | ||
| 351 | if (timeout > 60000) |
- | |
| 352 | { |
- | |
| 353 | 386 | ||
| 354 | // do turn off screen |
387 | // do turn off screen |
| 355 | } |
- | |
| 356 | } |
388 | } |
| - | 389 | // wait for a bit if nothing came in. |
|
| - | 390 | HAL_Delay(10); |
|
| - | 391 | } |
|
| 357 | 392 | ||
| - | 393 | /// process the observation list |
|
| 358 | for (chr = 0; chr < cc; chr++) |
394 | for (chr = 0; chr < cc; chr++) |
| 359 | { |
395 | { |
| 360 | char c = GetCharSerial(&uc1); |
396 | char c = GetCharSerial(&uc1); |
| 361 | 397 | ||
| 362 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
398 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
| 363 | { |
399 | { |
| 364 | PLXPtr = 0; // reset the pointer |
400 | PLXPtr = 0; // reset the pointer |
| 365 | PLXPacket = 1; |
401 | PLXPacket = 1; |
| 366 | timeout = 0; // Reset the timer |
402 | timeout = 0; // Reset the timer |
| 367 | } |
403 | } |
| 368 | else if (c == PLX_Stop) |
404 | else if (c == PLX_Stop) |
| - | 405 | { |
|
| - | 406 | if (PLXPacket) |
|
| 369 | { |
407 | { |
| - | 408 | // we can now decode the selected parameter |
|
| - | 409 | PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total |
|
| - | 410 | // saturate the rotary switch position |
|
| - | 411 | ||
| 370 | if (PLXPacket) |
412 | // process min/max |
| - | 413 | for (i = 0; i < PLXItems; i++) |
|
| 371 | { |
414 | { |
| 372 | // we can now decode the selected parameter |
- | |
| 373 | PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total |
415 | Info[i].observation = ConvPLX(Data.Sensor[i].AddrH, |
| 374 | // saturate the rotary switch position |
416 | Data.Sensor[i].AddrL); |
| 375 | 417 | ||
| - | 418 | Info[i].instance = Data.Sensor[i].Instance; |
|
| - | 419 | Info[i].data = ConvPLX(Data.Sensor[i].ReadingH, |
|
| - | 420 | Data.Sensor[i].ReadingL); |
|
| 376 | // process min/max |
421 | if (Info[i].data > Info[i].Max) |
| - | 422 | { |
|
| - | 423 | Info[i].Max = Info[i].data; |
|
| - | 424 | } |
|
| 377 | for (i = 0; i < PLXItems; i++) |
425 | if (Info[i].data < Info[i].Min) |
| 378 | { |
426 | { |
| 379 | Info[i].observation = ConvPLX(Data.Sensor[i].AddrH, |
- | |
| 380 | Data.Sensor[i].AddrL); |
- | |
| 381 | Info[i].instance = Data.Sensor[i].Instance; |
- | |
| 382 | Info[i].data = ConvPLX(Data.Sensor[i].ReadingH, |
- | |
| 383 | Data.Sensor[i].ReadingL); |
- | |
| 384 | if (Info[i].data > Info[i].Max) |
- | |
| 385 | { |
- | |
| 386 | Info[i].Max = Info[i].data; |
- | |
| 387 | } |
- | |
| 388 | if (Info[i].data < Info[i].Min) |
- | |
| 389 | { |
- | |
| 390 | Info[i].Min = Info[i].data; |
427 | Info[i].Min = Info[i].data; |
| 391 | } |
- | |
| 392 | // take an avarage |
- | |
| 393 | Info[i].sum += Info[i].data; |
- | |
| 394 | Info[i].count++; |
- | |
| 395 | - | ||
| 396 | // Send items to BT if it is in connected state |
- | |
| 397 | if (log && btConnected()) |
- | |
| 398 | { |
- | |
| 399 | - | ||
| 400 | char outbuff[100]; |
- | |
| 401 | - | ||
| 402 | int cnt = small_sprintf(outbuff, |
- | |
| 403 | "$PLLOG,%d,%d,%d,%ld", |
- | |
| 404 | logCount, |
- | |
| 405 | Info[i].observation, |
- | |
| 406 | Info[i].instance, |
- | |
| 407 | Info[i].count == 0 ? 0 : Info[i].sum / Info[i].count); |
- | |
| 408 | - | ||
| 409 | // NMEA style checksum |
- | |
| 410 | int ck; |
- | |
| 411 | int sum = 0; |
- | |
| 412 | for (ck = 1; ck < cnt; ck++) |
- | |
| 413 | sum += outbuff[ck]; |
- | |
| 414 | cnt += small_sprintf(outbuff + cnt, "*%02X\n", |
- | |
| 415 | sum & 0xFF); |
- | |
| 416 | sendString(&uc3, outbuff, cnt); |
- | |
| 417 | } |
- | |
| 418 | } |
428 | } |
| - | 429 | // take an average |
|
| - | 430 | Info[i].sum += Info[i].data; |
|
| 419 | log = 0; |
431 | Info[i].count++; |
| 420 | // now to display the information |
432 | // note the last update time |
| 421 | int suppress = DisplayCurrent(0, -1); |
433 | Info[i].lastUpdated = HAL_GetTick(); |
| 422 | DisplayCurrent(1, suppress); |
434 | Info[i].updated = 1; // it has been updated |
| 423 | } |
435 | } |
| 424 | PLXPtr = 0; |
436 | PLXPtr = 0; |
| 425 | PLXPacket = 0; |
437 | PLXPacket = 0; |
| 426 | } |
438 | } |
| 427 | else if (c > PLX_Stop) // illegal char, restart reading |
439 | else if (c > PLX_Stop) // illegal char, restart reading |
| Line 433... | Line 445... | ||
| 433 | { |
445 | { |
| 434 | Data.Bytes[PLXPtr++] = c; |
446 | Data.Bytes[PLXPtr++] = c; |
| 435 | } |
447 | } |
| 436 | } |
448 | } |
| 437 | 449 | ||
| 438 | HAL_Delay(1); |
450 | int suppress = -1; |
| 439 | - | ||
| 440 | for (i = 0; i < MAX_DISPLAYS; i++) |
451 | for (i = 0; i < MAX_DISPLAYS; i++) |
| - | 452 | { // now to display the information |
|
| - | 453 | DisplayCurrent(i, suppress); |
|
| 441 | { |
454 | |
| 442 | if (dial_pos[i] < 0) |
455 | if (dial_pos[i] < 0) |
| 443 | dial_pos[i] = PLXItems - 1; |
456 | dial_pos[i] = PLXItems - 1; |
| 444 | if (dial_pos[i] >= PLXItems) |
457 | if (dial_pos[i] >= PLXItems) |
| 445 | dial_pos[i] = 0; |
458 | dial_pos[i] = 0; |
| 446 | 459 | ||
| Line 454... | Line 467... | ||
| 454 | cc_check_nvram(i); |
467 | cc_check_nvram(i); |
| 455 | if (contexts[i].knobPos >= 0) |
468 | if (contexts[i].knobPos >= 0) |
| 456 | dial_pos[i] = contexts[i].knobPos; |
469 | dial_pos[i] = contexts[i].knobPos; |
| 457 | } |
470 | } |
| 458 | } |
471 | } |
| 459 | /* USER CODE END WHILE */ |
- | |
| 460 | - | ||
| 461 | /* USER CODE BEGIN 3 */ |
- | |
| 462 | } |
472 | } |
| - | 473 | /* USER CODE END WHILE */ |
|
| - | 474 | ||
| - | 475 | /* USER CODE BEGIN 3 */ |
|
| - | 476 | ||
| 463 | /* USER CODE END 3 */ |
477 | /* USER CODE END 3 */ |
| 464 | } |
478 | } |
| 465 | - | ||
| 466 | /** |
479 | /** |
| 467 | * @brief System Clock Configuration |
480 | * @brief System Clock Configuration |
| 468 | * @retval None |
481 | * @retval None |
| 469 | */ |
482 | */ |
| 470 | void SystemClock_Config(void) |
483 | void SystemClock_Config(void) |