Make SmartSource header less verbose.

PostgreSQL NOTIFY has an 8,000 bytes payload limit
and we were going over that.
This commit is contained in:
D. Berge
2020-09-03 23:06:01 +02:00
parent 1a851fefdf
commit a253578a1b

View File

@@ -31,23 +31,23 @@ function parse (buffer) {
throw new NavHeaderError("Expected SmartSource marker not found at position " + s, buf);
}
},
blk_siz: (buf, ctx) => {
return Number(ascii(4));
},
line: (buf, ctx) => {
return ascii(30).trim();
},
shot: (buf, ctx) => {
return Number(ascii(10));
},
mask: (buf, ctx) => {
return Number(ascii(2));
},
trg_mode: (buf, ctx) => {
const trg_mode = ascii(1);
switch (trg_mode) {
@@ -59,81 +59,81 @@ function parse (buffer) {
throw new NavHeaderError("Unknown SmartSource trigger mode: " + trg_mode, buf);
}
},
time: (buf, ctx) => {
const time = ascii(17);
'20/08/30:05:45:58'
return new Date(time.replace(/(\d{2})\/(\d{2})\/(\d{2}):(\d{2}):(\d{2}):(\d{2})/, "20$1-$2-$3T$4:$5:$6Z"));
},
src_number: (buf, ctx) => {
return Number(ascii(1));
},
num_subarray: (buf, ctx) => {
return Number(ascii(1));
},
num_guns: (buf, ctx) => {
return Number(ascii(2));
},
num_active: (buf, ctx) => {
return Number(ascii(2));
},
num_delta: (buf, ctx) => {
return Number(ascii(2));
},
num_auto: (buf, ctx) => {
return Number(ascii(2));
},
num_nofire: (buf, ctx) => {
return Number(ascii(2));
},
spread: (buf, ctx) => {
// Convert to ms
return Number(ascii(4))/10;
},
volume: (buf, ctx) => {
return Number(ascii(6));
},
avg_delta: (buf, ctx) => {
return Number(ascii(5));
},
std_delta: (buf, ctx) => {
return Number(ascii(5));
},
baroPress: (buf, ctx) => {
// Converted to millibars
return Number(ascii(6))/100;
},
manifold: (buf, ctx) => {
return Number(ascii(4)); // PSI
},
spare: (buf, ctx) => {
return ascii(88).trim();
},
};
const gun = {
string: (buf, ctx) => {
return Number(ascii(1));
},
gun: (buf, ctx) => {
return Number(ascii(2));
},
source: (buf, ctx) => {
return Number(ascii(1));
},
@@ -217,12 +217,12 @@ function parse (buffer) {
for (const key of Object.keys(header)) {
smartsource[key] = header[key](buffer, smartsource);
}
smartsource.guns = [];
for (let n=0; n<smartsource.num_guns; n++) {
const gunItem = {};
const gunItem = [];
for (const key of Object.keys(gun)) {
gunItem[key] = gun[key](buffer, gunItem);
gunItem.push(gun[key](buffer, gunItem));
}
smartsource.guns.push(gunItem);
}
@@ -230,7 +230,7 @@ function parse (buffer) {
return smartsource;
}
module.exports = {
name: "SmartSource",
detect,