From 2e301c67e21618bf3fd6d4bc1c70e569ba599cee Mon Sep 17 00:00:00 2001 From: Determinant Date: Wed, 14 Aug 2024 22:13:43 -0700 Subject: get loupedeck to work with X-Plane --- xplane.mjs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 xplane.mjs (limited to 'xplane.mjs') diff --git a/xplane.mjs b/xplane.mjs new file mode 100644 index 0000000..54190c9 --- /dev/null +++ b/xplane.mjs @@ -0,0 +1,37 @@ +import dgram from 'node:dgram'; + +const xplaneAddr = "localhost"; +const xplanePort = 49000; +const socket = dgram.createSocket('udp4'); + +//socket.on('message', (msg, rinfo) => { +// console.log(msg, rinfo) +//}); +// +//socket.bind(10080); + +const subscribeDataRef = async (dataRef) => { + //const dataRef = "sim/flightmodel/position/indicated_airspeed"; + let buffer = Buffer.alloc(4 + 1 + 4 * 2 + 400); + let off = buffer.write("RREF"); + off = buffer.writeUInt8(0, off); // null terminated + off = buffer.writeInt32LE(1, off); // xint frequency + off = buffer.writeInt32LE(0, off); // xint client + off += buffer.write(dataRef, off); // char[400] dataref + off = buffer.writeUInt8(0, off); // null terminated + console.log(Array.from(buffer)); + await socket.send(buffer, 0, buffer.length, xplanePort, xplaneAddr); +} + + +export const sendCommand = async (cmd) => { + let buffer = Buffer.alloc(4 + 1 + cmd.length + 1); + let off = buffer.write("CMND"); + off = buffer.writeUInt8(0, off); // null terminated + off += buffer.write(cmd, off); // command + off = buffer.writeUInt8(0, off); // null terminated + console.info(`sent command: ${cmd}`) + await socket.send(buffer, 0, buffer.length, xplanePort, xplaneAddr); +}; + +//command("sim/GPS/g1000n1_hdg_down"); -- cgit v1.2.3-70-g09d2