diff --git a/vendor/jooby/mtx1.js b/vendor/jooby/mtx1.js index d77883eaf8..3764075a60 100644 --- a/vendor/jooby/mtx1.js +++ b/vendor/jooby/mtx1.js @@ -14,7 +14,7 @@ const MAX_DATA_SEGMENT_SIZE = 50; * bytes - byte array containing the downlink payload */ function encodeDownlink ( input ) { - let bytes = toBytes(input.data.commands); // FRMPayload (byte array) + let bytes = toBytes(input.data.commands); // send nothing if not fit in a single data segment if ( bytes.length > MAX_DATA_SEGMENT_SIZE ) { @@ -23,12 +23,7 @@ function encodeDownlink ( input ) { bytes = setDataSegment(bytes); } - return { - bytes, - fPort: 1, - warnings: [], // optional - errors: [], // optional (if set, the encoding failed) - }; + return {bytes, fPort: 1}; } @@ -37,32 +32,33 @@ function encodeDownlink ( input ) { Input is an object with the following fields: * bytes - byte array containing the uplink payload, e.g. [255, 230, 255, 0] - * fPort - downlink fPort + * fPort - uplink fPort Output must be an object with the following fields: * data - object representing the decoded payload */ -function decodeDownlink ( input ) { +function decodeUplink ( input ) { + const data = {bytes: input.bytes, message: null}; const segment = getDataSegment(input.bytes); - let message = null; + const warnings = []; + const errors = []; // just a single data segment if ( segment ) { - message = fromBytes(segment); - - // there may be a message.error (e.g. mismatched LRC) - // in that case message.message will contain everything parsed successfully - // it should be used with caution + const decodeResult = fromBytes(segment); + + if ( decodeResult.error ) { + errors.push(decodeResult.error); + // there may be some partially decoded result + data.message = decodeResult.message; + } else { + data.message = decodeResult; + } + } else { + warnings.push('should be present one data segment'); } - return { - data: { - bytes: input.bytes, - message - }, - warnings: [], // optional - errors: [] // optional (if set, the decoding failed) - }; + return {data, warnings, errors}; } @@ -71,32 +67,13 @@ function decodeDownlink ( input ) { Input is an object with the following fields: * bytes - byte array containing the uplink payload, e.g. [255, 230, 255, 0] - * fPort - uplink fPort + * fPort - downlink fPort Output must be an object with the following fields: * data - object representing the decoded payload */ -function decodeUplink ( input ) { - const segment = getDataSegment(input.bytes); - let message = null; - - // just a single data segment - if ( segment ) { - message = fromBytes(segment); - - // there may be a message.error (e.g. mismatched LRC) - // in that case message.message will contain everything parsed successfully - // it should be used with caution - } - - return { - data: { - bytes: input.bytes, - message - }, - warnings: [], // optional - errors: [] // optional (if set, the decoding failed) - }; +function decodeDownlink ( input ) { + return decodeUplink(input); }