Combining Data for CAN Gateway
Posted: Tue Sep 12, 2023 5:51 am
Hi all,
I'm trying to combine 3 bytes of data to manipulate and forward over CAN to 4 bytes of data
the reasoning behind this is device A calculates it's data different to device B, I'm developing a gateway to go between device A & B.
E.g.
B0=f8, B1=ff, B2=ff
Combined = fffff8, how do I do this bit? I Figured this bit out
string0 = 0xff
string1 = 0xff
string2 = 0xf8
ODOIN = ((string0) << 16 | (string1) << 8 | (string2))
I then need to take 0xfffff8 or 16777208 multiply by 25 = 4211081215, then convert back to 4 bytes to send via CAN, I can do this via modulus but then need to combine again to send as hex
4211081215%16 = 15 = F
4211081215/16 = 263192575 %16 = 15 = F
and so on until I end up with f a f f f f f f then to combine as fa ff ff ff, I'm sure the help with combining initial data will help with this bit too.
Thanks,
Mick
I'm trying to combine 3 bytes of data to manipulate and forward over CAN to 4 bytes of data
the reasoning behind this is device A calculates it's data different to device B, I'm developing a gateway to go between device A & B.
E.g.
B0=f8, B1=ff, B2=ff
Combined = fffff8, how do I do this bit? I Figured this bit out
string0 = 0xff
string1 = 0xff
string2 = 0xf8
ODOIN = ((string0) << 16 | (string1) << 8 | (string2))
I then need to take 0xfffff8 or 16777208 multiply by 25 = 4211081215, then convert back to 4 bytes to send via CAN, I can do this via modulus but then need to combine again to send as hex
4211081215%16 = 15 = F
4211081215/16 = 263192575 %16 = 15 = F
and so on until I end up with f a f f f f f f then to combine as fa ff ff ff, I'm sure the help with combining initial data will help with this bit too.
Thanks,
Mick