From de767f3bd2629181a5b49d9cccb1d7e494396e6e Mon Sep 17 00:00:00 2001 From: Determinant Date: Thu, 15 Aug 2024 14:22:42 -0700 Subject: improve --- xplane.mjs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'xplane.mjs') diff --git a/xplane.mjs b/xplane.mjs index 54190c9..7b82817 100644 --- a/xplane.mjs +++ b/xplane.mjs @@ -1,8 +1,8 @@ -import dgram from 'node:dgram'; +import dgram from "node:dgram"; const xplaneAddr = "localhost"; const xplanePort = 49000; -const socket = dgram.createSocket('udp4'); +const socket = dgram.createSocket("udp4"); //socket.on('message', (msg, rinfo) => { // console.log(msg, rinfo) @@ -10,7 +10,7 @@ const socket = dgram.createSocket('udp4'); // //socket.bind(10080); -const subscribeDataRef = async (dataRef) => { +export 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"); @@ -21,8 +21,7 @@ const subscribeDataRef = async (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); @@ -30,7 +29,7 @@ export const sendCommand = async (cmd) => { 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}`) + console.info(`x-plane cmd: ${cmd}`); await socket.send(buffer, 0, buffer.length, xplanePort, xplaneAddr); }; -- cgit v1.2.3-70-g09d2