Bits are allocated from lowest bit to highest bit. This means that the lowest two bits of the byte that contains 0x03 are used for the Aux input. The remaining bits of the byte are used for the battery current (as bits 0 … 5 of the current). This means that Aux input is 0x03 (meaning that the AUX input setting is set to “None”) and the battery current is 0.
I was talking about the battery current. I edited my response to make this more clear.
Your image shows that the bits containing 0x03 is used in the battery current, but I am saying that the two bits that make up the 0x3 are for the Aux input.
Hi Thomas,
ok lets try this - my full value is 02E1100289A30204C617FFFF660500000000030000000080FE00
The part value I have to focus for Aux value + Battery Currentis is “030000”.
This in binary is 0000110000000000000000
The first 2 bit are 00 - no AUX - this is correct.
The rest 00110000000000000000 would be without little endian a decimal value 786432.
How do I need to convert this into little endian because there are only 22 bit available?
This means I have to fill up 2 more bit at the end 00110000 00000000 000000
Via little Endian would it be 000000000000000000110000 which would be 30 in decimal.
03 00 00 in binary is:
Byte 0: 00000011
Byte 1: 00000000
Byte 2: 00000000
This makes the first two bits 11 = 0x03, and 0x03 means “AUX input none”.
The remaining bits are all 0, so the battery current is 0.
This is correct. But you don’t have to do any bit swapping of any sorts. The lowest 2 bits of byte 1 are used for the Aux value and the remaining bits for the Battery Current. So when I write the complete battery current from most significant bit to least significant bit it becomes:
11111111_11011011_111000. This is a 22 bit signed number (which in this case is negative because the most significant bit is set) and the value is -2312, meaning -2.312A.
And example of how you can come to the value -2312 is by sign extending the bit to 32 bits (prefix the bit pattern with the most significant bit until it contains 32 bits) and then treat this is as 32 signed integer. So the bitmask becomes (MSB to LSB):
11111111_11111111_11110110_11111000 => 0xFFFFF6F8 => -2312
The Consumed Ah consists of the next 20 bits, so this means 2 full bytes and then the lowest 4 bits of the next byte. As the value stored inside is not a signed value, there is no need for the special bit extending and it can just be extended using 0’s.
And to already answer a possible next question, the SOC takes the next 4 bits (so the upper 4 bits of the last byte of the Consumed Ah) and then lowest 6 bits of the next byte. And this is also unsigned so it can be extended using 0’s.
The misunderstanding is that all data is little endian so the bytes need to be reversed.
byte 1 = 01010000 (0x50)
byte 2 = 00000011 (0x03)
byte 3 = 00010000 (0x10)
So Consumed Ah in bits is: 0000_00000011_01010000.
Extending this to a 32 unsigned integer becomes: 00000000_00000000_00000011_01010000, which is 848.