Closed huseyinkozan closed 6 years ago
I need 32bit for location info:
<!-- 65267 -->
<Message id="0xFEF3" name="msg_loc" format="extended">
<Producer>
<NodeRef id="1"/>
</Producer>
<Signal name="lat" offset="0" length="32" endianess="little">
<Value type="signed"/>
</Signal>
<Signal name="lng" offset="32" length="32" endianess="little">
<Value type="signed"/>
</Signal>
</Message>
Are there any reason to avoid Buffer::readInt16LE() and other Buffer functions ?
The Buffer function usually don't work because it is quite common in CAN messages that the signal are not on byte boundaries and have an odd length (e.g. 12bit spanned in 2 bytes).
Maybe we can do bit ops at js level. Like this lib : https://github.com/inolen/bit-buffer
Anyway, I can read buffer directly from channel message. You can close issue if you want.
Here how I am reading:
function onMessage(msg) {
if (msg == undefined) return;
if (msg.rtr) return;
switch (msg.id) {
case 65267:
console.log("onMessage()");
console.log(" data:", msg.data);
console.log(" lat :", msg.data.readInt32LE(0) * Number("1e-7"));
console.log(" lng :", msg.data.readInt32LE(4) * Number("1e-7"));
break;
default:
}
}
Here the output:
onMessage()
data: <Buffer f2 99 95 95 1d d6 ce 49>
lat : -178.5357838
lng : 123.82919969999999
Data comes from ISOBlue Public Data (11052016_ault_wheat_full.zip). But it seems I have wrong prescription about byte layout.
I didn't notice the offset at prescription. Here the right one:
console.log(" lat :", (msg.data.readUInt32LE(0) * Number("1e-7")) - 210);
console.log(" lng :", (msg.data.readUInt32LE(4) * Number("1e-7") - 210);
And output:
onMessage()
data: <Buffer f2 99 95 95 1d d6 ce 49>
lat : 40.96094579999999
lng : -86.1708003
Here the help: https://groups.google.com/d/msg/isoblue/kERbzyyRr90/3xxo9zseCAAJ
I found the issue (see 73b9b8e81cbf138dcdd160d9b7200f36a05cc1b3).
Hi, I tried to read 32 bit but it returns zero. Can you change the test function with below and confirm?
Also, tried to fix the return value type, but no luck: