From f163a56efc9f563109945934f13715e175bdd5f8 Mon Sep 17 00:00:00 2001 From: Andrey Gusakov Date: Sat, 14 Dec 2024 19:06:10 +0300 Subject: [PATCH 1/2] SENT: support more than 16 Slow Channel mailboxes --- sent/include/sent_decoder.h | 11 ++++++----- sent/src/sent_decoder.cpp | 32 +++++++++++++++++++------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/sent/include/sent_decoder.h b/sent/include/sent_decoder.h index eab7f59..542a5bf 100644 --- a/sent/include/sent_decoder.h +++ b/sent/include/sent_decoder.h @@ -11,8 +11,8 @@ #include -/* 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 */ diff --git a/sent/src/sent_decoder.cpp b/sent/src/sent_decoder.cpp index ffce4d0..e64f9ac 100644 --- a/sent/src/sent_decoder.cpp +++ b/sent/src/sent_decoder.cpp @@ -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 */ From b1e18e49ec3c99329a192f71460b3419395bf196 Mon Sep 17 00:00:00 2001 From: Andrey Gusakov Date: Sat, 14 Dec 2024 19:06:38 +0300 Subject: [PATCH 2/2] SENT: GM fuel sensor: fix include Actually to be removed. --- sent/include/sent_gm_fuel_sensor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sent/include/sent_gm_fuel_sensor.h b/sent/include/sent_gm_fuel_sensor.h index fe15617..9b9aeec 100644 --- a/sent/include/sent_gm_fuel_sensor.h +++ b/sent/include/sent_gm_fuel_sensor.h @@ -2,7 +2,7 @@ #include "ch.h" #include "hal.h" -#include "sent_constants.h" +#include "sent_decoder.h" class SentGmFuelSensor { public: