Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
kmalinich committed Jun 10, 2024
1 parent f544c89 commit 94755d4
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 187 deletions.
5 changes: 3 additions & 2 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ async function emit(topic, data) {
case 'temperature.intake.c' :
case 'temperature.oil.c' : break;

case 'vehicle.dsc.torque_reduction_1' :
case 'vehicle.dsc.torque_reduction_2' : break;
case 'vehicle.dsc.torque_intervention_asc' :
case 'vehicle.dsc.torque_intervention_asc_lm' :
case 'vehicle.dsc.torque_intervention_msr' : break;

case 'vehicle.ignition_level' : break;

Expand Down
7 changes: 4 additions & 3 deletions lib/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ async function status_reset_basic() {
status.vehicle.speed.kmh = 0;
status.vehicle.speed.mph = 0;

// Reset torque reduction values
status.vehicle.dsc.torque_reduction_1 = 0;
status.vehicle.dsc.torque_reduction_2 = 0;
// Reset torque intervention values
status.vehicle.dsc.torque_intervention_asc = 0;
status.vehicle.dsc.torque_intervention_asc_lm = 0;
status.vehicle.dsc.torque_intervention_msr = 0;

status.vehicle.dsc.active = false;

Expand Down
5 changes: 3 additions & 2 deletions lib/status-vehicle-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ function apply() {
rear : 0,
},

torque_reduction_1 : 0,
torque_reduction_2 : 0,
torque_intervention_asc : 0,
torque_intervention_asc_lm : 0,
torque_intervention_msr : 0,
},

key : {
Expand Down
60 changes: 47 additions & 13 deletions modules/DME.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/* eslint key-spacing : */


// References:
// https://www.ms4x.net/index.php?title=Siemens_MS43_CAN_Bus

const convert = require('node-unit-conversion');


Expand Down Expand Up @@ -50,6 +53,10 @@ function encode_316(rpm = 10000) {

// CAN ARBID 0x316 (DME1)
//
// https://www.ms4x.net/index.php?title=Siemens_MS43_CAN_Bus
//
// Refresh Rate: 10ms
//
// byte 0, bit 0 : Something is pushed here, but I'm having a hard time tracing what it is. Appears it would always be 1 if everything is running normally
// byte 0, bit 1 : ??
// byte 0, bit 2 : 1 if DSC OK
Expand Down Expand Up @@ -100,21 +107,27 @@ function parse_316(data) {

// CAN ARBID 0x329 (DME2)
//
// Refresh rate: 10ms
//
// byte 0 : ??
// byte 1 : coolant temp
// byte 2 : atmospheric pressure
//
// byte 3, bit 0 : clutch switch (0 = engaged, 1 = disengage/neutral)
// byte 3, bit 2 : Hardcoded to 1 (on MSS54, could be used on other DMEs)
// byte 3, bit 4 : possibly motor status (0 = on, 1 = off)
// byte 3, bits 5+6+7 : tank evap duty cycle?
// byte 3, bit 0 : clutch switch state (0 = engaged, 1 = disengage/neutral)
// byte 3, bit 1 : idle regulator state (0 = idle above threshold, 1 = idle below threshold)
// byte 3, bit 2 : Acknowledgment of ACC1 CAN message
// byte 3, bit 3 : Engine running state (0 = engine stopped, 1 = engine running)
// byte 3, bit 4 : STATE_CRU_CAN (possibly)
// byte 3, bit 5 : STATE_MSW_CAN[0]
// byte 3, bit 6 : STATE_MSW_CAN[1]
// byte 3, bit 8 : STATE_MSW_CAN[2]
//
// byte 4 : driver desired torque, relative (0x00 - 0xFE)
// byte 5 : throttle position (0x00 - 0xFE)
//
// byte 6, bit 2 : kickdown switch depressed
// byte 6, bit 1 : brake light switch error
// byte 6, bit 0 : brake pedal depressed
// byte 6, bit 0 : brake switch state (0 = not depressed, 1 = depressed)
// byte 6, bit 1 : brake switch status (0 = OK, 1 = fault)
// byte 6, bit 2 : kickdown switch state (0 = not depressed, 1 = depressed)
//
// byte 7 : ??
function parse_329(data) {
Expand Down Expand Up @@ -207,7 +220,10 @@ function parse_329(data) {
}


// CAN ARBID 0x338
// CAN ARBID 0x338 (DME3)
//
// Refresh rate: 1000ms and at signal change
//
// MS45/MSD80/MSV80 only
//
// byte2, bit 0 : Sport on (request by SMG transmission)
Expand Down Expand Up @@ -235,10 +251,16 @@ function parse_338(data) {

// CAN ARBID 0x545 (DME4)
//
// byte 0, bit 1 : Check engine
// Refresh Rate: 10ms
//
// byte 0, bit 0 : Unused
// byte 0, bit 1 : Check engine light
// byte 0, bit 2 : Unused
// byte 0, bit 3 : Cruise
// byte 0, bit 4 : EML
// byte 0, bit 7 : Check gas cap
// byte 0, bit 4 : Engine malfunction light
// byte 0, bit 5 : Unused
// byte 0, bit 6 : Check gas cap
// byte 0, bit 7 : Unused
//
// byte 1 : Fuel consumption LSB
// byte 2 : Fuel consumption MSB
Expand All @@ -247,10 +269,10 @@ function parse_338(data) {
// byte 3, bit 1 : Oil level warning (yellow)
// byte 3, bit 2 : Oil level error (red)
// byte 3, bit 3 : Coolant overtemperature light

// byte 3, bit 4 : M3/M5 tachometer light
// byte 3, bit 5 : M3/M5 tachometer light
// byte 3, bit 6 : M3/M5 tachometer light
// byte 3, bit 7 : Upshift indicator

// byte 4 : Oil temperature (ºC = X - 48)
//
Expand Down Expand Up @@ -311,18 +333,24 @@ function parse_545(data) {
return data;
}

// https://www.ms4x.net/index.php?title=CAN_Bus_ID_0x610_ICL1
function parse_610(data) {
data.value = 'VIN/info';

return data;
}


// https://www.ms4x.net/index.php?title=CAN_Bus_ID_0x615_ICL3
//
// Refresh rate: 200ms

// byte 0 : Odometer LSB
// byte 1 : Odometer MSB
// byte 2 : Fuel level
// byte 2 : FTL_CAN - Fuel Tank Level (Bits 0-6, Bit 7: FTL_RES_CAN [Fuel Tank Level Reserve Switch])
// byte 3 : Running clock LSB
// byte 4 : Running clock MSB
// byte 5 : FTL_CAN_L - Fuel Tank Level Driver Side (Bits 0-5)
//
// Running clock = minutes since last time battery power was lost
//
Expand Down Expand Up @@ -364,6 +392,12 @@ function parse_613(data) {
}

// ARBID: 0x615 sent from the instrument cluster
//
// This is actually sent by IKE
//
// https://www.ms4x.net/index.php?title=CAN_Bus_ID_0x615_ICL3
//
// Refresh rate: 200ms
function parse_615(data) {
data.value = 'A/C request/Outside air temp/Parking brake/door contacts';

Expand Down
40 changes: 26 additions & 14 deletions modules/DSC.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const convert = require('node-unit-conversion');

// References:
// https://www.ms4x.net/index.php?title=CAN_Bus_ID_0x1F5_LWS1
// https://www.ms4x.net/index.php?title=CAN_Bus_ID_0x1F0_ASC2


// Parse wheel speed LSB and MSB into KPH value
function parse_wheel(byte0, byte1) {
Expand Down Expand Up @@ -53,6 +57,10 @@ function encode_1a1(speed = 0) {

// 0x153
//
// https://www.ms4x.net/index.php?title=CAN_Bus_ID_0x153_ASC1
//
// Refresh rate: 10ms for ASC and 20ms for DSC
//
// Example
// B0 B1 B2 B3 B4 B5 B6 B7
// 00 E0 3D FF 00 FE FF 08
Expand Down Expand Up @@ -90,11 +98,11 @@ function encode_1a1(speed = 0) {
// Byte 1, bit 7 : Speed LSB

// Byte 2 : Speed MSB [Signal startbit: 12, Bit length: 12, 0x0008 = 1 km/hr]
// Byte 3 : Torque reduction 1
// Byte 4 :
// Byte 5 :
// Byte 6 : Torque reduction 2
// Byte 7 :
// Byte 3 : Torque intervention for ASC function
// Byte 4 : Torque intervention for MSR function
// Byte 5 : Unused
// Byte 6 : Torque intervention for ASC LM function
// Byte 7 : Alive counter
function parse_153(data) {
data.command = 'bro';
data.value = 'Speed/DSC light';
Expand All @@ -113,16 +121,18 @@ function parse_153(data) {
dsc : {
active : !(bitmask.test(data.msg[1], 0x01) && bitmask.test(data.msg[0], 0x04)),

torque_reduction_1 : num.round2(100 - (data.msg[3] / 2.55)),
torque_reduction_2 : num.round2(100 - (data.msg[6] / 2.55)),
torque_intervention_asc : num.round2(100 - (data.msg[3] * 0.390625)),
torque_intervention_asc_lm : num.round2(100 - (data.msg[6] * 0.390625)),
torque_intervention_msr : num.round2(100 - (data.msg[4] * 0.390625)),
},
},
};

// update.status('vehicle.brake', parse.vehicle.brake);
update.status('vehicle.dsc.torque_reduction_1', parse.vehicle.dsc.torque_reduction_1);
update.status('vehicle.dsc.torque_reduction_2', parse.vehicle.dsc.torque_reduction_2);
update.status('vehicle.dsc.active', parse.vehicle.dsc.active, false);
update.status('vehicle.dsc.active', parse.vehicle.dsc.active, false);
update.status('vehicle.dsc.torque_intervention_asc', parse.vehicle.dsc.torque_intervention_asc);
update.status('vehicle.dsc.torque_intervention_asc_lm', parse.vehicle.dsc.torque_intervention_asc_lm);
update.status('vehicle.dsc.torque_intervention_msr', parse.vehicle.dsc.torque_intervention_msr);

return data;
}
Expand Down Expand Up @@ -311,8 +321,9 @@ function init_listeners() {
update.on('status.engine.running', data => {
switch (data.new) {
case false : {
update.status('vehicle.dsc.torque_reduction_1', 0);
update.status('vehicle.dsc.torque_reduction_2', 0);
update.status('vehicle.dsc.torque_intervention_asc', 0);
update.status('vehicle.dsc.torque_intervention_asc_lm', 0);
update.status('vehicle.dsc.torque_intervention_msr', 0);
}
}
});
Expand All @@ -321,8 +332,9 @@ function init_listeners() {
update.on('status.vehicle.ignition', data => {
if (data.new === 'run') return;

update.status('vehicle.dsc.torque_reduction_1', 0);
update.status('vehicle.dsc.torque_reduction_2', 0);
update.status('vehicle.dsc.torque_intervention_asc', 0);
update.status('vehicle.dsc.torque_intervention_asc_lm', 0);
update.status('vehicle.dsc.torque_intervention_msr', 0);
});

log.module('Initialized listeners');
Expand Down
Loading

0 comments on commit 94755d4

Please sign in to comment.