Like I explained it indeed looks like that, but (luckily!) it doesn’t do anything. As you quoted from my explanation: JavaScript works with 32 bits for bitwise operators, so it will handle 0xFFFFFFFF00000000
as if it were 0x00000000
here.
Just try 0xFFFFFFFF00000000 | 0xFFFFFFFF00000000
to see that evaluates to zero.
Even more, if it would have an effect, then it would erroneously set bits that did not need to be set, as the value was already 32 bits, so would already be negative if applicable.
The following gives the same output for your example payload of 02863D68 FAC29BAF 4B45 60 04D2 FB2E
in the 1.5.x user manual:
/**
* Decoder for Dragino LGT-92.
*
* Based on the JSON format of the example decoder from the 1.5 user
* manual, but with typo fixed in "Longitud", "FW" added for firmware,
* and returning a true JSON boolean for the Alarm flag.
*
* 2020-01-19 Copied fix for FW from LGT92-v1.5.0_decoder_20191129.txt
*/
function Decoder(bytes, port) {
return {
// GPS coordinates; signed 32 bits integer, MSB; unit: °
// When power is low (<2.84v), GPS won’t be able to get location
// info and GPS feature will be disabled and the location field
// will be filled with 0x0FFFFFFF, 0x0FFFFFFF.
Latitude:
(bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3]) / 1000000,
Longitude:
(bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7]) / 1000000,
// Alarm status; boolean
ALARM_status: (bytes[8] & 0x40) > 0,
// Battery; 14 bits; unit: V
BatV: ((bytes[8] & 0x3f)<<8 | bytes[9]) / 1000,
// Motion detection mode; 2 bits
MD: {
"0": "Disable",
"1": "Move",
"2": "Collide",
"3": "User"
}[bytes[10]>>6],
// LED status for position, uplink and downlink; 1 bit
LON: (bytes[10] & 0x20) ? "ON" : "OFF",
// Firmware version; 5 bits
FW: 150 + (bytes[10] & 0x1f),
// In firmware version v1.5, Roll and Pitch are disabled by default.
// Roll; signed 16 bits integer, MSB; unit: °
// Sign-extend to 32 bits to support negative values: shift 16 bytes
// too far to the left, followed by sign-propagating right shift
Roll: (bytes[11]<<24>>16 | bytes[12]) / 100,
// Pitch; signed 16 bits integer, MSB, unit: °
Pitch: (bytes[13]<<24>>16 | bytes[14]) / 100,
};
}
{
"ALARM_status": true,
"BatV": 2.885,
"FW": 150,
"LON": "ON",
"Latitude": 42.351976,
"Longitude": -87.909457,
"MD": "Move",
"Pitch": -12.34,
"Roll": 12.34
}