Subversion Repositories DashDisplay

Rev

Rev 73 | Rev 75 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 73 Rev 74
Line 82... Line 82...
82
                         .Min = 0xFFF,
82
                         .Min = 0xFFF,
83
                         .sum = 0,
83
                         .sum = 0,
84
                         .count = 0,
84
                         .count = 0,
85
                         .updated = 0,
85
                         .updated = 0,
86
                         .lastUpdated = 0,
86
                         .lastUpdated = 0,
87
                         .observation = PLX_MAX_OBS,
87
                         .observation.Obs = PLX_MAX_OBS,
88
                         .instance = PLX_MAX_INST};
88
                         .observation.Instance = PLX_MAX_INST};
89
 
89
 
90
/// \brief storage for incoming data
90
/// \brief storage for incoming data
91
data_t Data;
91
data_t Data;
92
 
92
 
93
uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT;
93
uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT;
94
 
94
 
95
// location for GPS data
95
// location for GPS data
96
Location loc;
96
Location loc;
97
 
97
 
-
 
98
/// @brief Time when the logged data will be sent
-
 
99
uint32_t nextTickReload = 0;
-
 
100
 
98
/* USER CODE END PV */
101
/* USER CODE END PV */
99
 
102
 
100
/* Private function prototypes -----------------------------------------------*/
103
/* Private function prototypes -----------------------------------------------*/
101
void SystemClock_Config(void);
104
void SystemClock_Config(void);
102
static void MX_GPIO_Init(void);
105
static void MX_GPIO_Init(void);
Line 143... Line 146...
143
  setBaud(ctl, baudRate);
146
  setBaud(ctl, baudRate);
144
  HAL_Delay(100);
147
  HAL_Delay(100);
145
}
148
}
146
 
149
 
147
// workspace for RMC data read from GPS module.
150
// workspace for RMC data read from GPS module.
148
uint8_t rmc_buff[80];
-
 
149
volatile uint16_t rmc_length;
151
volatile uint16_t rmc_length;
150
 
152
 
151
uint8_t rmc_callback(uint8_t *data, uint16_t length)
153
uint8_t rmc_callback(uint8_t *data, uint16_t length)
152
{
154
{
-
 
155
  // send it back out
153
  rmc_length = length < sizeof(rmc_buff) ? length : sizeof(rmc_buff);
156
  rmc_length = length;
-
 
157
 
154
  memcpy(rmc_buff, data, length);
158
  sendString(&uc3, (const char *)data, length);
-
 
159
 
-
 
160
  nextTickReload = HAL_GetTick() + LOGGER_INTERVAL;
-
 
161
 
155
  return 0;
162
  return 0;
156
}
163
}
157
 
164
 
158
// check if bluetooth connected
165
// check if bluetooth connected
159
uint8_t btConnected()
166
uint8_t btConnected()
Line 166... Line 173...
166
uint8_t isUnused(int index)
173
uint8_t isUnused(int index)
167
{
174
{
168
  if (index < 0 || index > MAXRDG)
175
  if (index < 0 || index > MAXRDG)
169
    return false;
176
    return false;
170
 
177
 
171
  return Info[index].instance == PLX_MAX_INST && Info[index].observation == PLX_MAX_OBS;
178
  return Info[index].observation.Instance == PLX_MAX_INST && Info[index].observation.Obs == PLX_MAX_OBS;
172
}
179
}
173
 
180
 
174
/// @brief Determine if an entry is currently valid
181
/// @brief Determine if an entry is currently valid
175
/// @param index the number of the array entry to display
182
/// @param index the number of the array entry to display
176
/// @return true if the entry contains data which is fresh
183
/// @return true if the entry contains data which is fresh
Line 303... Line 310...
303
  uint32_t timeout = 0; //
310
  uint32_t timeout = 0; //
304
 
311
 
305
  // used in NMEA style logging
312
  // used in NMEA style logging
306
  uint32_t nextTick = 0;    ///< time to send next
313
  uint32_t nextTick = 0;    ///< time to send next
307
  uint32_t offsetTicks = 0; ///< time to print as offset in mS for each loop
314
  uint32_t offsetTicks = 0; ///< time to print as offset in mS for each loop
308
  //
315
 
309
  uint8_t log = 0;
-
 
310
  // PLX decoder protocols
316
  // PLX decoder protocols
311
  char PLXPacket = 0;
317
  char PLXPacket = 0;
312
 
318
 
313
  for (i = 0; i < MAXRDG; i++)
319
  for (i = 0; i < MAXRDG; i++)
314
  {
320
  {
Line 377... Line 383...
377
 
383
 
378
    // if permitted, log data from RMC packet
384
    // if permitted, log data from RMC packet
379
    if (btConnected())
385
    if (btConnected())
380
    {
386
    {
381
      // Any RMC data, send it, reset the logger timeout
387
      // Any RMC data, send it, reset the logger timeout
382
      if (rmc_length)
-
 
383
      {
-
 
384
        sendString(&uc3, (const char *)rmc_buff, rmc_length);
-
 
385
        rmc_length = 0;
-
 
386
        offsetTicks = 0;
-
 
387
        nextTick = HAL_GetTick() + LOGGER_INTERVAL;
-
 
388
        log = 1;
-
 
389
      }
-
 
390
 
388
 
391
      // Timeout for data logging regularly
389
      // Timeout for data logging regularly
392
      if (HAL_GetTick() > nextTick)
390
      if (HAL_GetTick() > nextTick)
393
      {
391
      {
394
        offsetTicks += LOGGER_INTERVAL;
392
        nextTick = nextTickReload;
395
        nextTick = HAL_GetTick() + LOGGER_INTERVAL;
393
        nextTickReload += LOGGER_INTERVAL;
396
        if (offsetTicks < (1000))
-
 
397
          log = 1;
-
 
398
      }
-
 
399
 
-
 
400
      if (log)
-
 
401
      {
394
   
402
        log = 0;
-
 
403
        // Send items  to BT if it is in connected state
395
        // Send items  to BT if it is in connected state
404
 
-
 
-
 
396
        // print timestamp as a $PLTIM record.
405
        char linebuff[20];
397
        char linebuff[20];
406
        strftime(linebuff, sizeof(linebuff), "%H%M%S", &loc.tv);
398
        strftime(linebuff, sizeof(linebuff), "%H%M%S", &loc.tv);
-
 
399
 
-
 
400
        char outbuff[100];
-
 
401
        int cnt = small_sprintf(outbuff, "$PLTIM,%s.%03lu\n", linebuff, offsetTicks);
-
 
402
        sendString(&uc3, outbuff, cnt);
-
 
403
        offsetTicks += LOGGER_INTERVAL;
-
 
404
       
-
 
405
               if (offsetTicks >= (1000))
-
 
406
        {
-
 
407
          offsetTicks = 0;
-
 
408
          loc.tv.tm_sec++;
-
 
409
          if (loc.tv.tm_sec >= 60)
-
 
410
          {
-
 
411
            loc.tv.tm_sec = 0;
-
 
412
            loc.tv.tm_min++;
-
 
413
            if (loc.tv.tm_min >= 60)
-
 
414
            {
-
 
415
              loc.tv.tm_hour++;
-
 
416
              if (loc.tv.tm_hour >= 24)
-
 
417
                loc.tv.tm_hour = 0;
-
 
418
            }
-
 
419
          }
-
 
420
        }
-
 
421
 
-
 
422
       
-
 
423
       
-
 
424
       
-
 
425
       
-
 
426
       
407
        for (int i = 0; i < MAXRDG; ++i)
427
        for (int i = 0; i < MAXRDG; ++i)
408
        {
428
        {
409
          if (!isValid(i))
429
          if (!isValid(i))
410
            continue;
430
            continue;
411
          char outbuff[100];
431
          // print logger items as $PLLOG record
412
 
-
 
413
          int cnt = small_sprintf(outbuff,
432
          int cnt = small_sprintf(outbuff,
414
                                  "$PLLOG,%s.%03lu,%d,%d,%ld",
433
                                  "$PLLOG,%d,%d,%ld",
415
                                  linebuff,
-
 
416
                                  offsetTicks,
-
 
417
                                  Info[i].observation,
434
                                  Info[i].observation.Obs,
418
                                  Info[i].instance,
435
                                  Info[i].observation.Instance,
419
                                  Info[i].count == 0 ? 0 : Info[i].sum / Info[i].count);
436
                                  Info[i].count == 0 ? 0 : Info[i].sum / Info[i].count);
-
 
437
          Info[i].count = 0;
-
 
438
          Info[i].sum = 0;
420
 
439
 
421
          // NMEA style checksum
440
          // NMEA style checksum
422
          int ck;
441
          int ck;
423
          int sum = 0;
442
          int sum = 0;
424
          for (ck = 1; ck < cnt; ck++)
443
          for (ck = 1; ck < cnt; ck++)
Line 446... Line 465...
446
      {
465
      {
447
 
466
 
448
        // do turn off screen
467
        // do turn off screen
449
      }
468
      }
450
      // wait for a bit if nothing came in.
469
      // wait for a bit if nothing came in.
451
      HAL_Delay(10);
470
      HAL_Delay(1);
452
    }
471
    }
453
 
472
 
454
    /// process the observation list
473
    /// process the observation list
455
    for (chr = 0; chr < cc; chr++)
474
    for (chr = 0; chr < cc; chr++)
456
    {
475
    {
Line 487... Line 506...
487
 
506
 
488
            // search for the item in the list
507
            // search for the item in the list
489
            int j;
508
            int j;
490
            for (j = 0; j < MAXRDG; ++j)
509
            for (j = 0; j < MAXRDG; ++j)
491
            {
510
            {
492
              if ((Info[j].observation == observation) && (Info[j].instance == instance))
511
              if ((Info[j].observation.Obs == observation) && (Info[j].observation.Instance == instance))
493
                break;
512
                break;
494
            }
513
            }
495
            // fallen off the end of the list of existing items without a match, so j points at next new item
514
            // fallen off the end of the list of existing items without a match, so j points at next new item
496
            //
515
            //
497
            // Find an unused slot
516
            // Find an unused slot
Line 513... Line 532...
513
 
532
 
514
            // give up if we are going to fall off the end of the array
533
            // give up if we are going to fall off the end of the array
515
            if (j > MAXRDG)
534
            if (j > MAXRDG)
516
              break;
535
              break;
517
 
536
 
518
            Info[j].observation = observation;
537
            Info[j].observation.Obs = observation;
519
 
538
 
520
            Info[j].instance = instance;
539
            Info[j].observation.Instance = instance;
521
            Info[j].data = ConvPLX(Data.Sensor[j].ReadingH,
540
            Info[j].data = ConvPLX(Data.Sensor[j].ReadingH,
522
                                   Data.Sensor[j].ReadingL);
541
                                   Data.Sensor[j].ReadingL);
523
            if (Info[j].data > Info[j].Max)
542
            if (Info[j].data > Info[j].Max)
524
            {
543
            {
525
              Info[j].Max = Info[j].data;
544
              Info[j].Max = Info[j].data;