Skip to content

Encoding the voltage in BMS#83

Open
taishi-dev wants to merge 2 commits into
mainfrom
BMS_System
Open

Encoding the voltage in BMS#83
taishi-dev wants to merge 2 commits into
mainfrom
BMS_System

Conversation

@taishi-dev

Copy link
Copy Markdown

No description provided.

@taishi-dev taishi-dev requested a review from a team as a code owner June 17, 2026 05:19
Comment thread lib/battery/decode.h
* @param frame: CAN frame containing the voltage message. The voltage message is expected to be in data[0] and data[1] of the frame.
* @returns The decoded voltage value in volts. The voltage value is expected to be a 16-bit unsigned integer, where the first byte (data[0]) is the high byte and the second byte (data[1]) is the low byte. The voltage value is calculated as (data[0] << 8) | data[1].
**/
uint16_t decodeVoltageMessage(const CAN::Frame& frame);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that we have this as a method in the message object it is associated with? Biggest concern with this is does it change the way the message is decoded when we decode or encode from or to frames and messages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could have a base struct that the other struct inherent from and that base struct can do the math to calculate the volts

@Hibyehello Hibyehello Jun 19, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just having a proper bitfield should decode the voltage since it is just two concurrent bytes, no math needed. I don't think we'll need a whole function for it.

It's either message 0x1 or 0x4.

@taishi-dev

taishi-dev commented Jun 22, 2026

Copy link
Copy Markdown
Author

I don't think a bitfield decodes packVoltage on its own. The BMS sends the high byte first, but the ESP32 reads memory little-endian, so reading the 16-bit field straight off the frame bytes gives the bytes swapped. That's the reason the current exists.

`(data[0] << 8) | data[1]`

@Hibyehello

Copy link
Copy Markdown
Contributor

I don't think a bitfield decodes packVoltage on its own. The BMS sends the high byte first, but the ESP32 reads memory little-endian, so reading the 16-bit field straight off the frame bytes gives the bytes swapped. That's the reason the current exists.

`(data[0] << 8) | data[1]`

I'm pretty sure that we get to configure what direction the data gets sent to us, so I'd hope that we can just flip that in config. I would love to look at the configs.

@taishi-dev

taishi-dev commented Jun 24, 2026

Copy link
Copy Markdown
Author

Josh was right that this is configurable on the BMS side. I confirmed it in the Orion CANBUS Messages editor: our messages are custom transmit messages, and each field has a Byte Order dropdown that can be set to Little Endian
BMS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants