Encoding the voltage in BMS#83
Conversation
| * @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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
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. |

No description provided.