Skip to content
Snippets Groups Projects
Commit d44391b4 authored by Adrien van den Bossche's avatar Adrien van den Bossche
Browse files

Add `valid_gnss_position` flag

parent d03325d4
No related branches found
No related tags found
No related merge requests found
...@@ -13,17 +13,18 @@ module.exports = function(RED) { ...@@ -13,17 +13,18 @@ module.exports = function(RED) {
var hdr_raw = parseInt(buff[len]); var hdr_raw = parseInt(buff[len]);
hdr.altitude_presence_flag = (hdr_raw & 0x80) ? true : false; hdr.altitude_presence_flag = (hdr_raw & 0x80) ? true : false;
hdr.dop_presence_flag = (hdr_raw & 0x40) ? true : false; hdr.dop_presence_flag = (hdr_raw & 0x40) ? true : false;
hdr.valid_gnss_position = (hdr_raw & 0x20) ? true : false;
p.header = hdr; p.header = hdr;
len += 1; len += 1;
// Latitude // If the message has a valid_gnss_position
p.latitude = buff.readFloatLE(len); if (p.header.valid_gnss_position ) {
len += 4; p.latitude = buff.readFloatLE(len);
len += 4;
// Longitude p.longitude = buff.readFloatLE(len);
p.longitude = buff.readFloatLE(len); len += 4;
len += 4; }
// If the message contains the altitude field // If the message contains the altitude field
if (p.header.altitude_presence_flag ) { if (p.header.altitude_presence_flag ) {
p.altitude = buff.readFloatLE(len); p.altitude = buff.readFloatLE(len);
......
...@@ -6,27 +6,28 @@ module.exports = function(RED) { ...@@ -6,27 +6,28 @@ module.exports = function(RED) {
const buff = Buffer.alloc(128); const buff = Buffer.alloc(128);
var len = 0; var len = 0;
var valid_gnss_position = false;
var altitude_presence_flag = false; var altitude_presence_flag = false;
var dop_presence_flag = false; var dop_presence_flag = false;
// Check mandatory fields
if (typeof msg.payload.latitude === 'undefined') return;
if (typeof msg.payload.longitude === 'undefined') return;
// Check optional fields // Check optional fields
if ( (typeof msg.payload.latitude !== 'undefined') && (typeof msg.payload.longitude !== 'undefined') ) valid_gnss_position = true;
if (typeof msg.payload.altitude !== 'undefined') altitude_presence_flag = true; if (typeof msg.payload.altitude !== 'undefined') altitude_presence_flag = true;
if (typeof msg.payload.dop !== 'undefined') dop_presence_flag = true; if (typeof msg.payload.dop !== 'undefined') dop_presence_flag = true;
// Make header // Make header
if (altitude_presence_flag) buff[len] |= 0x80; if (altitude_presence_flag) buff[len] |= 0x80;
if (dop_presence_flag) buff[len] |= 0x40; if (dop_presence_flag) buff[len] |= 0x40;
if (valid_gnss_position) buff[len] |= 0x20;
len += 1; len += 1;
// Make latitude and longitude fields // Make latitude and longitude fields
buff.writeFloatLE(msg.payload.latitude, len); if ( valid_gnss_position ) {
len += 4; buff.writeFloatLE(msg.payload.latitude, len);
buff.writeFloatLE(msg.payload.longitude, len); len += 4;
len += 4; buff.writeFloatLE(msg.payload.longitude, len);
len += 4;
}
// Make altitude field if present // Make altitude field if present
if ( altitude_presence_flag ) { if ( altitude_presence_flag ) {
......
{ {
"name": "node-red-contrib-locapack", "name": "node-red-contrib-locapack",
"version": "0.0.5", "version": "0.0.6",
"description": "Some nodes to interact with LocaPack devices using the LocaPack protocol", "description": "Some nodes to interact with LocaPack devices using the LocaPack protocol",
"dependencies": { "dependencies": {
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment