Digital Matter Oyster LoRaWANGPS device

37 views
Skip to first unread message

Toni Juola

unread,
Mar 15, 2019, 6:30:58 AM3/15/19
to LoRaWAN Server Users
Hi!

Asking for help from the ultimate experts of Erlang. Is someone able to convert this parser function from JavaScript to Erlang language?


function Decoder(bytes, port)

{

 var decoded = {};

 if (port === 1)

 {

 decoded.type = "position";

 decoded.latitudeDeg = bytes[0] + bytes[1] * 256 +

 bytes[2] * 65536 + bytes[3] * 16777216;

 if (decoded.latitudeDeg >= 0x80000000) // 2^31

 decoded.latitudeDeg -= 0x100000000; // 2^32

 decoded.latitudeDeg /= 1e7;

 

 decoded.longitudeDeg = bytes[4] + bytes[5] * 256 +

 bytes[6] * 65536 + bytes[7] * 16777216;

 if (decoded.longitudeDeg >= 0x80000000) // 2^31

 decoded.longitudeDeg -= 0x100000000; // 2^32

 decoded.longitudeDeg /= 1e7;

 decoded.inTrip = ((bytes[8] & 0x1) !== 0) ? true : false;

 decoded.fixFailed = ((bytes[8] & 0x2) !== 0) ? true : false;

 decoded.headingDeg = (bytes[8] >> 2) * 5.625;

 

 decoded.speedKmph = bytes[9];

 decoded.batV = bytes[10] * 0.025;

 decoded.manDown = null;

 }

 else if (port === 4)

 {

 decoded.type = "position";

 decoded.latitudeDeg = bytes[0] + bytes[1] * 256 + bytes[2] * 65536;

 if (decoded.latitudeDeg >= 0x800000) // 2^23

 decoded.latitudeDeg -= 0x1000000; // 2^24

 decoded.latitudeDeg *= 256e-7;

 

 decoded.longitudeDeg = bytes[3] + bytes[4] * 256 + bytes[5] * 65536;

 if (decoded.longitudeDeg >= 0x800000) // 2^23

 decoded.longitudeDeg -= 0x1000000; // 2^24

 decoded.longitudeDeg *= 256e-7;

 decoded.headingDeg = (bytes[6] & 0x7) * 45;

 decoded.speedKmph = (bytes[6] >> 3) * 5;

 decoded.batV = bytes[7] * 0.025;

 decoded.inTrip = ((bytes[8] & 0x1) !== 0) ? true : false;

 decoded.fixFailed = ((bytes[8] & 0x2) !== 0) ? true : false;

 decoded.manDown = ((bytes[8] & 0x4) !== 0) ? true : false;

 }

 else if (port === 2)

 {

 decoded.type = "downlink ack";

 decoded.sequence = (bytes[0] & 0x7F);

 decoded.accepted = ((bytes[0] & 0x80) !== 0) ? true : false;

 decoded.fwMaj = bytes[1];

 decoded.fwMin = bytes[2];

 }

 else if (port === 3)

 {decoded.type = "stats";

 decoded.initialBatV = 4.0 + 0.100 * (bytes[0] & 0xF);

 decoded.txCount = 32 * ((bytes[0] >> 4) + (bytes[1] & 0x7F) * 16);

 decoded.tripCount = 32 * ((bytes[1] >> 7) + (bytes[2] & 0xFF) * 2

 + (bytes[3] & 0x0F) * 512);

 decoded.gpsSuccesses = 32 * ((bytes[3] >> 4) + (bytes[4] & 0x3F) * 16);

 decoded.gpsFails = 32 * ((bytes[4] >> 6) + (bytes[5] & 0x3F) * 4);

 decoded.aveGpsFixS = 1 * ((bytes[5] >> 6) + (bytes[6] & 0x7F) * 4);

 decoded.aveGpsFailS = 1 * ((bytes[6] >> 7) + (bytes[7] & 0xFF) * 2);

 decoded.aveGpsFreshenS = 1 * ((bytes[7] >> 8) + (bytes[8] & 0xFF) * 1);

 decoded.wakeupsPerTrip = 1 * ((bytes[8] >> 8) + (bytes[9] & 0x7F) * 1);

 decoded.uptimeWeeks = 1 * ((bytes[9] >> 7) + (bytes[10] & 0xFF) * 2);

 }

 

 return decoded;

}


BR,


Stonde

Александр Тищенко

unread,
Mar 19, 2019, 2:21:37 AM3/19/19
to Toni Juola, LoRaWAN Server Users
Hi Tony!
Sorry, missed your message:) Can do tonight MSK time, if still needed.

пт, 15 марта 2019 г. в 13:30, Toni Juola <juol...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "LoRaWAN Server Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lorawan-serve...@googlegroups.com.
To post to this group, send email to lorawan...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lorawan-server/ca265e2e-aca6-4658-8f57-ecb5e402740a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Alexander Tishchenko +7 (916) 704-6157 ati...@gmail.com

Toni Juola

unread,
Mar 19, 2019, 2:24:40 AM3/19/19
to LoRaWAN Server Users
Hi Alexander!

No problem! Yeah still needed badly. This Erlang is causing some serious headache :D But if you can solve this one I would be forever grateful.

BR,

Stonde

Toni Juola

unread,
Mar 20, 2019, 2:44:29 AM3/20/19
to LoRaWAN Server Users
Hi Alexander,

Sorry for bothering, but did you have time to look at this yet? :)


tiistai 19. maaliskuuta 2019 8.21.37 UTC+2 Alexander Tishchenko kirjoitti:

Alexander Tishchenko

unread,
Mar 20, 2019, 4:33:03 AM3/20/19
to Toni Juola, LoRaWAN Server Users
Yeah had a look. Will send you today.

С уважением,
Александр Тищенко


20 марта 2019 г., в 9:44, Toni Juola <juol...@gmail.com> написал(а):

Alexander Tishchenko

unread,
Mar 20, 2019, 9:35:34 AM3/20/19
to Toni Juola, LoRaWAN Server Users

Toni Juola

unread,
Mar 20, 2019, 10:16:21 AM3/20/19
to LoRaWAN Server Users
Howdy Alexander,

Yeah, that is correct doc to use where unclear :)

Br,

Stonde

Александр Тищенко

unread,
Mar 21, 2019, 10:14:33 AM3/21/19
to Toni Juola, LoRaWAN Server Users
Hello Toni,
Please find attached %)


WBR,
Alexander Tishchenko



ср, 20 мар. 2019 г. в 17:16, Toni Juola <juol...@gmail.com>:
fun.erl

Toni Juola

unread,
Mar 21, 2019, 2:21:08 PM3/21/19
to LoRaWAN Server Users
Thank you a thousand times Alexander! Gonna test this soon!

-Toni
Reply all
Reply to author
Forward
0 new messages