Refactor code handling binary sequence requests.

Instead of the user giving the recipe for the payload, it now
only handles predefined payload configurations. Those are
denoted by the `type` query parameter. The only valid value
as of this commit is `type=2`.

Look at lib/binary/bundle.js for the definition of a type 2
bundle.
This commit is contained in:
D. Berge
2025-08-01 16:47:50 +02:00
parent cc8d790ad8
commit e464f5f887
4 changed files with 171 additions and 46 deletions

View File

@@ -1,55 +1,11 @@
const { bundle } = require('../../../../lib/binary');
const { sequence } = require('../../../../lib/db');
const { MSGTYPE, encode } = require('../../../../lib/binary');
module.exports = async function (req, res, next) {
try {
const json = await sequence.get(req.params.project, req.params.sequence, req.query);
let msgType, geometry, error;
switch (req.query.geometry) {
case "F":
case "FINAL":
msgType = MSGTYPE.FINAL_OPT;
geometry = "geometryfinal";
error = "errorfinal";
break;
case "f":
case "final":
msgType = MSGTYPE.FINAL;
geometry = "geometryfinal";
error = "errorfinal";
break;
case "R":
case "RAW":
msgType = MSGTYPE.RAW_OPT;
geometry = "geometryraw";
error = "errorraw";
break;
case "r":
case "raw":
msgType = MSGTYPE.RAW;
geometry = "geometryraw";
error = "errorraw";
break;
case "P":
case "PREPLOT":
msgType = MSGTYPE.PREPLOT_RAWERROR_OPT;
geometry = "geometrypreplot";
error = ["errorfinal", "errorraw"];
break;
case "p":
case "preplot":
default:
msgType = MSGTYPE.PREPLOT;
geometry = "geometrypreplot";
break;
}
const endianness = req.query.endianness != "big";
const data = encode(json, geometry, error, msgType, endianness);
const data = bundle(json, {type: req.query.type});
console.log("bundle", data);
res.status(200).send(Buffer.from(data));