Skip to content

Instantly share code, notes, and snippets.

@mcauser
Created December 1, 2022 01:18
Show Gist options
  • Select an option

  • Save mcauser/757c9134f411dc7a99106a29cd17d48f to your computer and use it in GitHub Desktop.

Select an option

Save mcauser/757c9134f411dc7a99106a29cd17d48f to your computer and use it in GitHub Desktop.

Revisions

  1. mcauser created this gist Dec 1, 2022.
    32 changes: 32 additions & 0 deletions helium mappers decoder
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    // My Functions > Add a core function
    // name: Mappers Decoder
    // based on https://github.com/hkicko/CubeCell-GPS-Helium-Mapper
    function Decoder(bytes, port) {
    var decoded = {};

    var latitude = ((bytes[0]<<16)>>>0) + ((bytes[1]<<8)>>>0) + bytes[2];
    latitude = (latitude / 16777215.0 * 180) - 90;

    var longitude = ((bytes[3]<<16)>>>0) + ((bytes[4]<<8)>>>0) + bytes[5];
    longitude = (longitude / 16777215.0 * 360) - 180;

    switch (port)
    {
    case 2:
    decoded.latitude = latitude;
    decoded.longitude = longitude;

    var altValue = ((bytes[6]<<8)>>>0) + bytes[7];
    var sign = bytes[6] & (1 << 7);
    if(sign) decoded.altitude = 0xFFFF0000 | altValue;
    else decoded.altitude = altValue;

    decoded.speed = parseFloat((((bytes[8]))/1.609).toFixed(2));
    decoded.battery = parseFloat((bytes[9]/100 + 2).toFixed(2));
    decoded.sats = bytes[10];
    decoded.accuracy = 2.5; // Bogus Accuracy required by Cargo/Mapper integration
    break;
    }

    return decoded;
    }