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