Created
December 1, 2022 01:18
-
-
Save mcauser/757c9134f411dc7a99106a29cd17d48f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment