-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from rnd-ash/74-feature-maxx-other-custom-ecu-…
…byte-aligned-can-layer Feature maxx other custom ecu byte aligned can layer
- Loading branch information
Showing
17 changed files
with
1,162 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# For compatibility with CAN (EWM) gear selector | ||
ECU EWM | ||
FRAME EWM_230h (0x00000230) | ||
SIGNAL W_S, OFFSET: 0, LEN: 1, DESC: Driving program, DATA TYPE BOOL | ||
SIGNAL FPT, OFFSET: 1, LEN: 1, DESC: Driving program button actuated, DATA TYPE BOOL | ||
SIGNAL KD, OFFSET: 2, LEN: 1, DESC: Kickdown, DATA TYPE BOOL | ||
SIGNAL SPERR, OFFSET: 3, LEN: 1, DESC: barrier magnet energized, DATA TYPE BOOL | ||
SIGNAL WHC, OFFSET: 4, LEN: 4, DESC: gear selector lever position (NAG only), DATA TYPE ENUM | ||
ENUM D, RAW: 5, DESC: selector lever in position "D" | ||
ENUM N, RAW: 6, DESC: selector lever in position "N" | ||
ENUM R, RAW: 7, DESC: selector lever in position "R" | ||
ENUM P, RAW: 8, DESC: selector lever in position "P" | ||
ENUM PLUS, RAW: 9, DESC: selector lever in position "+" | ||
ENUM MINUS, RAW: 10, DESC: selector lever in position "-" | ||
ENUM N_ZW_D, RAW: 11, DESC: selector lever in intermediate position "N-D" | ||
ENUM R_ZW_N, RAW: 12, DESC: selector lever in intermediate position "R-N" | ||
ENUM P_ZW_R, RAW: 13, DESC: selector lever in intermediate position "P-R" | ||
ENUM SNV, RAW: 15, DESC: selector lever position unplausible | ||
ECU UN52 | ||
FRAME UN52_400h (0x00000400) | ||
SIGNAL T_GEAR, OFFSET: 0, LEN: 8, DESC: Target gear, DATA TYPE ENUM | ||
ENUM P, RAW: 0, DESC: Park | ||
ENUM N, RAW: 1, DESC: Neutral | ||
ENUM R1, RAW: 2, DESC: Reverse 1 | ||
ENUM R2, RAW: 3, DESC: Reverse 2 | ||
ENUM D1, RAW: 4, DESC: Drive 1 | ||
ENUM D2, RAW: 5, DESC: Drive 2 | ||
ENUM D3, RAW: 6, DESC: Drive 3 | ||
ENUM D4, RAW: 7, DESC: Drive 4 | ||
ENUM D5, RAW: 8, DESC: Drive 5 | ||
ENUM D6, RAW: 9, DESC: Drive 6 | ||
ENUM D7, RAW: 10, DESC: Drive 7 | ||
ENUM D8, RAW: 11, DESC: Drive 8 | ||
ENUM D9, RAW: 12, DESC: Drive 9 | ||
ENUM ABORT, RAW: 13, DESC: Shift abort | ||
ENUM SNV, RAW: 255, DESC: Signal not available | ||
SIGNAL A_GEAR, OFFSET: 8, LEN: 8, DESC: Actual gear, DATA TYPE ENUM | ||
ENUM P, RAW: 0, DESC: Park | ||
ENUM N, RAW: 1, DESC: Neutral | ||
ENUM R1, RAW: 2, DESC: Reverse 1 | ||
ENUM R2, RAW: 3, DESC: Reverse 2 | ||
ENUM D1, RAW: 4, DESC: Drive 1 | ||
ENUM D2, RAW: 5, DESC: Drive 2 | ||
ENUM D3, RAW: 6, DESC: Drive 3 | ||
ENUM D4, RAW: 7, DESC: Drive 4 | ||
ENUM D5, RAW: 8, DESC: Drive 5 | ||
ENUM D6, RAW: 9, DESC: Drive 6 | ||
ENUM D7, RAW: 10, DESC: Drive 7 | ||
ENUM D8, RAW: 11, DESC: Drive 8 | ||
ENUM D9, RAW: 12, DESC: Drive 9 | ||
ENUM P_FREE, RAW: 13, DESC: Power free (Loss of drive detected) | ||
ENUM SNV, RAW: 255, DESC: Signal not available | ||
SIGNAL PROFILE, OFFSET: 16, LEN: 8, DESC: Profile, DATA TYPE ENUM | ||
ENUM P_S, RAW: 0, DESC: S profile | ||
ENUM P_C, RAW: 1, DESC: C profile | ||
ENUM P_W, RAW: 2, DESC: W profile | ||
ENUM P_A, RAW: 3, DESC: A profile | ||
ENUM P_M, RAW: 4, DESC: M profile | ||
ENUM P_R, RAW: 5, DESC: R profile | ||
ENUM P_U, RAW: 6, DESC: User custom profile | ||
ENUM SNV, RAW: 255, DESC: Profile not available | ||
SIGNAL INPUT_RPM, OFFSET: 24, LEN: 16, DESC: Transmission input speed, DATA TYPE NUMBER(_MULTIPLIER_: 1.0, _OFFSET_: 0.0) | ||
SIGNAL OUTPUT_RPM, OFFSET: 40, LEN: 16, DESC: Transmission output speed, DATA TYPE NUMBER(_MULTIPLIER_: 1.0, _OFFSET_: 0.0) | ||
SIGNAL T_OEL, OFFSET: 48, LEN: 8, DESC: Oil temperature, DATA TYPE NUMBER(_MULTIPLIER_: 1.0, _OFFSET_: 50.0) | ||
SIGNAL G_SHIFT, OFFSET: 56, LEN: 1, DESC: Garage shifting, DATA TYPE BOOL | ||
SIGNAL GB_OK, OFFSET: 57, LEN: 1, DESC: Gearbox OK, DATA TYPE BOOL | ||
FRAME UN52_410h (0x00000410) | ||
SIGNAL TRQ_REQ_CTRL0, OFFSET: 0, LEN: 1, DESC: Torque request control bit 0, DATA TYPE BOOL | ||
SIGNAL TRQ_REQ_CTRL1, OFFSET: 1, LEN: 1, DESC: Torque request control bit 1, DATA TYPE BOOL | ||
SIGNAL TRQ_REQ_MIN, OFFSET: 2, LEN: 1, DESC: Torque request min request, DATA TYPE BOOL | ||
SIGNAL TRQ_REQ_MAX, OFFSET: 3, LEN: 1, DESC: Torque request max request, DATA TYPE BOOL | ||
SIGNAL TRQ_REQ_TOGGLE, OFFSET: 4, LEN: 1, DESC: Torque request watchdog toggle bit, DATA TYPE BOOL | ||
SIGNAL TRQ_REQ_TRQ, OFFSET: 48, LEN: 16, DESC: Torque request target (Nm), DATA TYPE NUMBER(_MULTIPLIER_: 4.0, _OFFSET_: -500.0) | ||
|
||
ECU ENGINE | ||
FRAME ENGINE_100h (0x00000100) | ||
SIGNAL T_COOLANT, OFFSET: 0, LEN: 8, DESC: Engine coolant temperature, DATA TYPE NUMBER(_MULTIPLIER_: 1.0, _OFFSET_: 40.0) | ||
SIGNAL T_OIL, OFFSET: 8, LEN: 8, DESC: Engine oil temperature, DATA TYPE NUMBER(_MULTIPLIER_: 1.0, _OFFSET_: 40.0) | ||
SIGNAL RPM, OFFSET: 16, LEN: 16, DESC: Engine RPM, DATA TYPE NUMBER(_MULTIPLIER_: 1.0, _OFFSET_: 0.0) | ||
SIGNAL PEDAL, OFFSET: 32, LEN: 8, DESC: Pedal position (%), DATA TYPE NUMBER(_MULTIPLIER_: 1.0, _OFFSET_: 0.4) | ||
SIGNAL KD, OFFSET: 40, LEN: 1, DESC: Kickdown pressed, DATA TYPE BOOL | ||
|
||
FRAME ENGINE_102h (0x00000120) | ||
SIGNAL MAX_TORQUE, OFFSET: 0, LEN: 16, DESC: Maximum engine torque (Nm), DATA TYPE NUMBER(_MULTIPLIER_: 4.0, _OFFSET_: -500.0) | ||
SIGNAL MIN_TORQUE, OFFSET: 16, LEN: 16, DESC: Minimum engine torque (Nm), DATA TYPE NUMBER(_MULTIPLIER_: 4.0, _OFFSET_: -500.0) | ||
SIGNAL DRIVER_TORQUE, OFFSET: 32, LEN: 16, DESC: Driver requested engine torque (Nm), DATA TYPE NUMBER(_MULTIPLIER_: 4.0, _OFFSET_: -500.0) | ||
SIGNAL STATIC_TORQUE, OFFSET: 48, LEN: 16, DESC: Static engine torque (Nm), DATA TYPE NUMBER(_MULTIPLIER_: 4.0, _OFFSET_: -500.0) | ||
|
||
ECU WHEELS | ||
FRAME WHEELS_300h (0x00000300) | ||
SIGNAL RPM_2X_FL, OFFSET: 0, LEN: 16, DESC: Front left wheel speed, DATA TYPE NUMBER(_MULTIPLIER_: 2.0, _OFFSET_: 0.0) | ||
SIGNAL RPM_2X_FR, OFFSET: 16, LEN: 16, DESC: Front right wheel speed, DATA TYPE NUMBER(_MULTIPLIER_: 2.0, _OFFSET_: 0.0) | ||
SIGNAL RPM_2X_RL, OFFSET: 24, LEN: 16, DESC: Rear left wheel speed, DATA TYPE NUMBER(_MULTIPLIER_: 2.0, _OFFSET_: 0.0) | ||
SIGNAL RPM_2X_RR, OFFSET: 32, LEN: 16, DESC: Rear right wheel speed, DATA TYPE NUMBER(_MULTIPLIER_: 2.0, _OFFSET_: 0.0) | ||
|
||
ECU BRAKES | ||
FRAME BRAKES_310h (0x00000310) | ||
SIGNAL BRAKE, OFFSET: 0, LEN: 1, DESC: Brake pressed, DATA TYPE BOOL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
/** | ||
* AUTOGENERATED BY convert.py | ||
* DO NOT EDIT THIS FILE! | ||
* | ||
* IF MODIFICATIONS NEED TO BE MADE, MODIFY can_data.txt! | ||
* | ||
* CAN Defintiion for ECU 'BRAKES' | ||
*/ | ||
|
||
#ifndef ECU_BRAKES_H | ||
#define ECU_BRAKES_H | ||
|
||
#include <stdint.h> | ||
|
||
|
||
|
||
|
||
class ECU_BRAKES { | ||
public: | ||
/** | ||
* @brief Imports the CAN frame given the CAN ID, CAN Contents, and current timestamp | ||
* | ||
* Returns true if the frame was imported successfully, and false if import failed (Due to non-matching CAN ID). | ||
* | ||
* NOTE: The endianness of the value cannot be guaranteed. It is up to the caller to correct the byte order! | ||
*/ | ||
bool import_frames(uint64_t value, uint32_t can_id, uint32_t timestamp_now) { | ||
uint8_t idx = 0; | ||
bool add = true; | ||
switch(can_id) { | ||
default: | ||
add = false; | ||
break; | ||
} | ||
if (add) { | ||
LAST_FRAME_TIMES[idx] = timestamp_now; | ||
FRAME_DATA[idx] = value; | ||
} | ||
return add; | ||
} | ||
|
||
private: | ||
uint64_t FRAME_DATA[0]; | ||
uint32_t LAST_FRAME_TIMES[0]; | ||
}; | ||
#endif // ECU_BRAKES_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
|
||
/** | ||
* AUTOGENERATED BY convert.py | ||
* DO NOT EDIT THIS FILE! | ||
* | ||
* IF MODIFICATIONS NEED TO BE MADE, MODIFY can_data.txt! | ||
* | ||
* CAN Defintiion for ECU 'ENGINE' | ||
*/ | ||
|
||
#ifndef ECU_ENGINE_H | ||
#define ECU_ENGINE_H | ||
|
||
#include <stdint.h> | ||
|
||
#define ENGINE_100_CUSTOMCAN_CAN_ID 0x0100 | ||
#define ENGINE_102_CUSTOMCAN_CAN_ID 0x0120 | ||
|
||
|
||
|
||
typedef union { | ||
uint64_t raw; | ||
uint8_t bytes[8]; | ||
struct { | ||
/** BITFIELD PADDING. DO NOT CHANGE **/ | ||
uint32_t __PADDING1__: 23; | ||
/** Kickdown pressed **/ | ||
bool KD: 1; | ||
/** Pedal position (%) **/ | ||
uint8_t PEDAL: 8; | ||
/** Engine RPM **/ | ||
uint16_t RPM: 16; | ||
/** Engine oil temperature **/ | ||
uint8_t T_OIL: 8; | ||
/** Engine coolant temperature **/ | ||
uint8_t T_COOLANT: 8; | ||
} __attribute__((packed)); | ||
/** Gets CAN ID of ENGINE_100_CUSTOMCAN **/ | ||
uint32_t get_canid(){ return ENGINE_100_CUSTOMCAN_CAN_ID; } | ||
} ENGINE_100_CUSTOMCAN; | ||
|
||
|
||
|
||
typedef union { | ||
uint64_t raw; | ||
uint8_t bytes[8]; | ||
struct { | ||
/** Static engine torque (Nm) **/ | ||
uint16_t STATIC_TORQUE: 16; | ||
/** Driver requested engine torque (Nm) **/ | ||
uint16_t DRIVER_TORQUE: 16; | ||
/** Minimum engine torque (Nm) **/ | ||
uint16_t MIN_TORQUE: 16; | ||
/** Maximum engine torque (Nm) **/ | ||
uint16_t MAX_TORQUE: 16; | ||
} __attribute__((packed)); | ||
/** Gets CAN ID of ENGINE_102_CUSTOMCAN **/ | ||
uint32_t get_canid(){ return ENGINE_102_CUSTOMCAN_CAN_ID; } | ||
} ENGINE_102_CUSTOMCAN; | ||
|
||
|
||
|
||
class ECU_ENGINE { | ||
public: | ||
/** | ||
* @brief Imports the CAN frame given the CAN ID, CAN Contents, and current timestamp | ||
* | ||
* Returns true if the frame was imported successfully, and false if import failed (Due to non-matching CAN ID). | ||
* | ||
* NOTE: The endianness of the value cannot be guaranteed. It is up to the caller to correct the byte order! | ||
*/ | ||
bool import_frames(uint64_t value, uint32_t can_id, uint32_t timestamp_now) { | ||
uint8_t idx = 0; | ||
bool add = true; | ||
switch(can_id) { | ||
case ENGINE_100_CUSTOMCAN_CAN_ID: | ||
idx = 0; | ||
break; | ||
case ENGINE_102_CUSTOMCAN_CAN_ID: | ||
idx = 1; | ||
break; | ||
default: | ||
add = false; | ||
break; | ||
} | ||
if (add) { | ||
LAST_FRAME_TIMES[idx] = timestamp_now; | ||
FRAME_DATA[idx] = value; | ||
} | ||
return add; | ||
} | ||
|
||
/** Sets data in pointer to ENGINE_100 | ||
* | ||
* If this function returns false, then the CAN Frame is invalid or has not been seen | ||
* on the CANBUS network yet. Meaning it's data cannot be used. | ||
* | ||
* If the function returns true, then the pointer to 'dest' has been updated with the new CAN data | ||
*/ | ||
bool get_ENGINE_100(const uint32_t now, const uint32_t max_expire_time, ENGINE_100_CUSTOMCAN* dest) const { | ||
bool ret = false; | ||
if (dest != nullptr && LAST_FRAME_TIMES[0] <= now && now - LAST_FRAME_TIMES[0] < max_expire_time) { | ||
dest->raw = FRAME_DATA[0]; | ||
ret = true; | ||
} | ||
return ret; | ||
} | ||
|
||
/** Sets data in pointer to ENGINE_102 | ||
* | ||
* If this function returns false, then the CAN Frame is invalid or has not been seen | ||
* on the CANBUS network yet. Meaning it's data cannot be used. | ||
* | ||
* If the function returns true, then the pointer to 'dest' has been updated with the new CAN data | ||
*/ | ||
bool get_ENGINE_102(const uint32_t now, const uint32_t max_expire_time, ENGINE_102_CUSTOMCAN* dest) const { | ||
bool ret = false; | ||
if (dest != nullptr && LAST_FRAME_TIMES[1] <= now && now - LAST_FRAME_TIMES[1] < max_expire_time) { | ||
dest->raw = FRAME_DATA[1]; | ||
ret = true; | ||
} | ||
return ret; | ||
} | ||
|
||
private: | ||
uint64_t FRAME_DATA[2]; | ||
uint32_t LAST_FRAME_TIMES[2]; | ||
}; | ||
#endif // ECU_ENGINE_H |
Oops, something went wrong.