@@ -69,6 +69,17 @@ void initBMS() {
6969 memset (cellVoltages, 0 , sizeof (cellVoltages));
7070}
7171
72+ /* *
73+ * Check if this is a BMS message ID
74+ */
75+ bool isBMSMessage (uint32_t id) {
76+ return (id == BMS_BASIC_INFO_1 || id == BMS_BASIC_INFO_2 || id == BMS_CYCLE_INFO ||
77+ id == BMS_TEMPERATURE ||
78+ (id >= BMS_BATTERY_ID_BASE && id <= (BMS_BATTERY_ID_BASE + 2 )) ||
79+ ((id >> 24 ) == 0x18 && ((id >> 8 ) & 0xFF ) == 0x28 &&
80+ ((id >> 16 ) & 0xFF ) >= 0xC8 && ((id >> 16 ) & 0xFF ) < (0xC8 + BMS_MAX_CELLS/4 )));
81+ }
82+
7283/* *
7384 * Parse BMS CAN packet and update internal data
7485 */
@@ -173,38 +184,14 @@ bool isBMSConnected() {
173184}
174185
175186/* *
176- * Update BMS data by reading from TWAI and processing messages
177- * This function should be called regularly to check for new BMS messages
178- * Processes only a limited number of messages per call to avoid blocking
187+ * Update BMS telemetry structure with latest parsed data
188+ * Called by unified CAN bus after BMS messages are processed
179189 */
180190void updateBMSData () {
181191 if (!bmsTwaiInitialized) {
182192 return ;
183193 }
184194
185- // Process only a few messages per call to avoid blocking the ESC
186- int messagesProcessed = 0 ;
187- const int maxMessagesPerCall = 10 ;
188-
189- twai_message_t message;
190- while (messagesProcessed < maxMessagesPerCall && twai_receive (&message, 0 ) == ESP_OK) {
191- messagesProcessed++;
192-
193- // Only process messages that could be from BMS
194- uint32_t id = message.identifier ;
195-
196- // Check if this is a BMS message ID
197- if (id == BMS_BASIC_INFO_1 || id == BMS_BASIC_INFO_2 || id == BMS_CYCLE_INFO ||
198- id == BMS_TEMPERATURE ||
199- (id >= BMS_BATTERY_ID_BASE && id <= (BMS_BATTERY_ID_BASE + 2 )) ||
200- ((id >> 24 ) == 0x18 && ((id >> 8 ) & 0xFF ) == 0x28 &&
201- ((id >> 16 ) & 0xFF ) >= 0xC8 && ((id >> 16 ) & 0xFF ) < (0xC8 + BMS_MAX_CELLS/4 ))) {
202-
203- parseBMSPacket (&message);
204- }
205- // Other messages are ignored and will be available for ESC processing
206- }
207-
208195 // Update connection status
209196 bool connected = isBMSConnected ();
210197 if (connected != (bmsTelemetryData.bmsState == TelemetryState::CONNECTED)) {
0 commit comments