From 85845da0b8dbf1eea8d76e4def1fd956ee928f77 Mon Sep 17 00:00:00 2001 From: Kwstas Drakontidis Date: Thu, 12 Jun 2025 11:15:42 +0200 Subject: [PATCH] Test file --- test.js | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 test.js diff --git a/test.js b/test.js new file mode 100644 index 0000000..1bdb004 --- /dev/null +++ b/test.js @@ -0,0 +1,66 @@ +const can = require("socketcan"); + +var channel = can.createRawChannel("vcan0", true); + +const INVR_ID = 0x04; +const ERPM_ID = (0x20 << 5) | INVR_ID; +const APPS_ID = 0x50; +const SELC_ID = 0x19; +const MXCU_ID = (0x01 << 5) | INVR_ID; +const MXBC_ID = (0x02 << 5) | INVR_ID; + +var APPS = 0; +var ERPM = 0; + +// SELECT +(function sendSELC() { + channel.send({ + id: SELC_ID, + ext: false, + data: Buffer.from([0x02]) // ENABLE CONTROL BY TELEMETRY + }); +})(); + +// APPS +function sendAPPS() { + APPS = Math.floor(Math.random() * 1000); + console.log(`APPS: ${APPS / 10}%`); + channel.send({ + id: APPS_ID, + ext: false, + data: Buffer.from([APPS & 0xFF, APPS >> 8]) // SEND APPS PERCENTAGE + }); + + setTimeout(sendAPPS, Math.floor(Math.random() * 5000)); +} + +// ERPM +(function sendERPM() { + ERPM = Math.floor(Math.random() * 65000); + console.log(`ERPM: ${ERPM}`); + + channel.send({ + id: ERPM_ID, + ext: false, + data: Buffer.from([(ERPM >> 8 * 3) & 0xFF, (ERPM >> 8 * 2) & 0xFF, (ERPM >> 8) & 0xFF, ERPM & 0xFF, 0x00, 0x71, 0x01, 0x86]) // SEND ERPM + }); + + setTimeout(sendERPM, Math.floor(Math.random() * 10000)); +})(); + +sendAPPS(); + +channel.addListener("onMessage", async function (message) { + switch (message.id) { + case MXCU_ID: + console.log(`CURRENT: ${message.data[0] << 8 | message.data[1]}`); + break; + case MXBC_ID: + console.log(`BRAKE: ${message.data[0] << 8 | message.data[1]}`); + break; + default: + break; + } +}); + +channel.start(); \ No newline at end of file