Merge pull request #23 from dron0gus/sent-move-to-lib

SENT: updates
This commit is contained in:
rusefillc 2024-12-14 11:11:40 -05:00 committed by GitHub
commit fa7cc2db4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 19 deletions

View File

@ -11,8 +11,8 @@
#include <stdint.h>
/* Maximum slow shannel mailboxes, DO NOT CHANGE */
#define SENT_SLOW_CHANNELS_MAX 16
/* Maximum slow shannel mailboxes */
#define SENT_SLOW_CHANNELS_MAX 32
/* collect statistic */
#define SENT_STATISTIC_COUNTERS 1
@ -44,7 +44,8 @@ struct sent_channel_stat {
uint32_t RestartCnt;
/* Slow channel */
uint32_t sc;
uint32_t sc12; //12-bit data, 8-bit message ID
uint32_t sc16; //16-bit data, 4-bit message ID
uint32_t scCrcErr;
uint32_t getTotalError() {
@ -75,8 +76,7 @@ private:
/* fast channel last received valid message */
uint32_t rxLast;
/* slow channel shift registers and flags */
uint16_t scMsgFlags;
/* slow channel shift registers */
uint32_t scShift2; /* shift register for bit 2 from status nibble */
uint32_t scShift3; /* shift register for bit 3 from status nibble */
uint32_t scCrcShift; /* shift register for special order for CRC6 calculation */
@ -106,6 +106,7 @@ public:
struct {
uint16_t data;
uint8_t id;
bool valid;
} scMsg[SENT_SLOW_CHANNELS_MAX];
/* Statistic counters */

View File

@ -2,7 +2,7 @@
#include "ch.h"
#include "hal.h"
#include "sent_constants.h"
#include "sent_decoder.h"
class SentGmFuelSensor {
public:

View File

@ -72,7 +72,6 @@ void sent_channel::restart() {
/* reset slow channels */
SlowChannelDecoderReset();
scMsgFlags = 0;
#if SENT_STATISTIC_COUNTERS
statistic.ShortIntervalErr = 0;
@ -81,7 +80,8 @@ void sent_channel::restart() {
statistic.CrcErrCnt = 0;
statistic.FrameCnt = 0;
statistic.PauseCnt = 0;
statistic.sc = 0;
statistic.sc12 = 0;
statistic.sc16 = 0;
statistic.scCrcErr = 0;
statistic.RestartCnt++;
#endif
@ -366,7 +366,7 @@ int sent_channel::StoreSlowChannelValue(uint8_t id, uint16_t data)
/* Update already allocated messagebox? */
for (i = 0; i < SENT_SLOW_CHANNELS_MAX; i++) {
if ((scMsgFlags & BIT(i)) && (scMsg[i].id == id)) {
if ((scMsg[i].valid) && (scMsg[i].id == id)) {
scMsg[i].data = data;
return 0;
}
@ -374,11 +374,11 @@ int sent_channel::StoreSlowChannelValue(uint8_t id, uint16_t data)
/* New message? Allocate messagebox */
for (i = 0; i < SENT_SLOW_CHANNELS_MAX; i++) {
if (!(scMsgFlags & BIT(i)))
if (scMsg[i].valid == false)
{
scMsg[i].data = data;
scMsg[i].id = id;
scMsgFlags |= (1 << i);
scMsg[i].valid = true;
return 0;
}
}
@ -392,7 +392,7 @@ int sent_channel::GetSlowChannelValue(uint8_t id)
size_t i;
for (i = 0; i < SENT_SLOW_CHANNELS_MAX; i++) {
if ((scMsgFlags & BIT(i)) && (scMsg[i].id == id)) {
if ((scMsg[i].valid) && (scMsg[i].id == id)) {
return scMsg[i].data;
}
}
@ -432,26 +432,28 @@ int sent_channel::SlowChannelDecoder()
/* 0b11.1111.0xxx.xx0x.xxx0 ? */
if ((scShift3 & 0x3f821) == 0x3f000) {
uint8_t id;
/* C-flag: configuration bit is used to indicate 16 bit format */
bool sc16Bit = !!(scShift3 & (1 << 10));
uint8_t crc = (scShift2 >> 12) & 0x3f;
#if SENT_STATISTIC_COUNTERS
statistic.sc++;
if (sc16Bit) {
statistic.sc16++;
} else {
statistic.sc12++;
}
#endif
if (crc == crc6(scCrcShift)) {
/* C-flag: configuration bit is used to indicate 16 bit format */
bool sc16Bit = !!(scShift3 & (1 << 10));
if (!sc16Bit) {
/* 12 bit message, 8 bit ID */
id = ((scShift3 >> 1) & 0x0f) |
uint8_t id = ((scShift3 >> 1) & 0x0f) |
((scShift3 >> 2) & 0xf0);
uint16_t data = scShift2 & 0x0fff; /* 12 bit */
/* TODO: add crc check */
return StoreSlowChannelValue(id, data);
} else {
/* 16 bit message, 4 bit ID */
id = (scShift3 >> 6) & 0x0f;
uint8_t id = (scShift3 >> 6) & 0x0f;
uint16_t data = (scShift2 & 0x0fff) |
(((scShift3 >> 1) & 0x0f) << 12);
@ -473,6 +475,10 @@ void sent_channel::SlowChannelDecoderReset()
/* packet is incorrect, reset slow channel state machine */
scShift2 = 0;
scShift3 = 0;
for (size_t i = 0; i < SENT_SLOW_CHANNELS_MAX; i++) {
scMsg[i].valid = false;
}
}
/* This is correct for Si7215 */