Send msg on apps & bug fix
This commit is contained in:
@@ -16,11 +16,13 @@ var loaded_map_name = null;
|
||||
var loaded_map_data = [];
|
||||
|
||||
var throttle_output = 0;
|
||||
var ERPM = 0;
|
||||
|
||||
var enabled = false;
|
||||
|
||||
var channel = can.createRawChannel(can_conf.network_id, true);
|
||||
|
||||
// Some test messages...
|
||||
// 404#0000245E00710186
|
||||
// 019#02
|
||||
// 050#9702
|
||||
@@ -128,17 +130,25 @@ channel.addListener("onMessage", async function (message) {
|
||||
break;
|
||||
case can_conf.apps_id:
|
||||
const apps_percentage = ((message.data[1] << 8) | message.data[0]) / 1000;
|
||||
var max_current = 0;
|
||||
throttle_output = 0;
|
||||
|
||||
if (loaded_map_name !== null) {
|
||||
throttle_output = loaded_map_data[getMapIndex(map_throttle, apps_percentage)][2];
|
||||
} else {
|
||||
throttle_output = 0;
|
||||
max_current = loaded_map_data[getMapIndex(map_rpm, ERPM / can_conf.motor_poles)][(throttle_output > 0) ? 0 : 1];
|
||||
}
|
||||
|
||||
let current = throttle_output * max_current * 10;
|
||||
channel.send({
|
||||
id: (throttle_output > 0) ? current_id : brake_current_id,
|
||||
ext: false,
|
||||
data: Buffer.from([(current >> 8) & 0xFF, current & 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
|
||||
});
|
||||
|
||||
break;
|
||||
case erpm_id:
|
||||
if (enabled && (loaded_map_name !== null)) {
|
||||
const ERPM = message.data[0] << 3 * 8 | message.data[1] << 2 * 8 | message.data[2] << 8 | message.data[3];
|
||||
if ((enabled == true) && (loaded_map_name !== null)) {
|
||||
ERPM = message.data[0] << 3 * 8 | message.data[1] << 2 * 8 | message.data[2] << 8 | message.data[3];
|
||||
|
||||
let max_current = loaded_map_data[getMapIndex(map_rpm, ERPM / can_conf.motor_poles)][(throttle_output > 0) ? 0 : 1];
|
||||
let current = throttle_output * max_current * 10;
|
||||
@@ -147,7 +157,7 @@ channel.addListener("onMessage", async function (message) {
|
||||
ext: false,
|
||||
data: Buffer.from([(current >> 8) & 0xFF, current & 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF])
|
||||
});
|
||||
} else if (enabled && (loaded_map_data === null)) {
|
||||
} else if ((enabled == true) && (loaded_map_name === null)) {
|
||||
channel.send({
|
||||
id: brake_current_id,
|
||||
ext: false,
|
||||
|
||||
Reference in New Issue
Block a user