Test file

This commit is contained in:
2025-06-12 11:15:42 +02:00
parent 5fe201182a
commit 85845da0b8
+66
View File
@@ -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();