# Decoding Trackio (Tabs Object Locator) GPS data with Node-RED JS

**URL:** <https://www.thethingsnetwork.org/forum/t/decoding-trackio-tabs-object-locator-gps-data-with-node-red-js/24276>\
**Category:** End Devices (Nodes)\
**Created:** [March 24, 2019, 5:11pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-trackio-tabs-object-locator-gps-data-with-node-red-js/24276 "2019-03-24T17:11:36Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![arjanvanb](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/arjanvanb/32/46626_2.png) [@arjanvanb](https://www.thethingsnetwork.org/forum/u/arjanvanb)\
**Post date:** [March 24, 2019, 6:16pm UTC](https://www.thethingsnetwork.org/forum/t/decoding-trackio-tabs-object-locator-gps-data-with-node-red-js/24276/4 "2019-03-24T18:16:07Z")

</div>

> [@IoTLatam](#):
>
> parse a multy-byte value that uses a fraction of those bytes for other purposes

First, apply a mask to ignore the high bits, like `bytes[6] & 0x0F`. Next, JavaScript’s bitwise operators always assume two’s complement, when handling 32 bits. But, as you’re ignoring the high bits, some [sign extension](https://en.wikipedia.org/wiki/Sign_extension) for the 3 or 4 bits that you’re ignoring is still needed… Something like, very much untested:

```javascript
// LSB, and bits 28-31 reserved for future use. Sign-extend to handle
// negative values; 0b00001000 = 0x08 and 0b11110000 = 0xF0:
var lat = bytes[3] | bytes[4]<<8 | bytes[5]<<16 
  | (bytes[6] & 0x0F | (bytes[6] & 0x08 ? 0xF0 : 0x00))<<24;

// LSB, and bits 29-31 used for accuracy. Sign-extend to handle
// negative values; 0b00010000 = 0x10 and 0b11100000 = 0xE0:
var lng = bytes[7] | bytes[8]<<8 | bytes[9]<<16
  | (bytes[10] & 0x1F | (bytes[10] & 0x10 ? 0xE0 : 0x00))<<24;

var accuracy = bytes[10]>>5;

```

Probably easier to shift 4 and 3 bytes too far to the left, and shift it back, as the bitwise operator `>>` is the [sign-propagating right shift](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Right_shift):

```javascript
// LSB, ignoring the 4 and 3 high bits, and sign-extending to 32 bits
// to support negative values, by shifting 4 or 3 bytes too far to
// the left (discarding those bits, as only 32 bits are preserved),
// followed by a sign-propagating right shift:
var lat = bytes[3] | bytes[4]<<8 | bytes[5]<<16 | bytes[6]<<28>>4;
var lng = bytes[7] | bytes[8]<<8 | bytes[9]<<16 | bytes[10]<<27>>3;

```

To parse a few bits from a single byte, see:

> [@Abeeway Microtracker Decoder](https://www.thethingsnetwork.org/forum/t/abeeway-microtracker-decoder/22473/7):
>
> ```javascript
> // Gets the unsigned numeric value of the given zero-based bit(s)
> function bits(value, lsb, msb) {
> var len = msb - lsb + 1;
> var mask = (1<<len) - 1;
> return value>>lsb & mask;
> }
> 
> // Gets the boolean value of the given bit
> function bit(value, bit) {
> return (value & (1<<bit)) > 0;
> }
> 
> ```

…which you can use for:

```javascript
var voltage = (25 + bits(byte[1], 0, 3)) / 10;
var capacity = 100 * (bits(byte[1], 4, 7) / 15);
var accuracy = bits(byte[10], 5, 7);

```

---

_[View the full topic](https://www.thethingsnetwork.org/forum/t/decoding-trackio-tabs-object-locator-gps-data-with-node-red-js/24276)._
