Skip to content

Commit

Permalink
Trip (#36)
Browse files Browse the repository at this point in the history
* Add trip to OBD
* Update obd.dbc for custom service PIDs
  • Loading branch information
techie66 authored Feb 19, 2024
1 parent cfb6920 commit 254cc02
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
16 changes: 14 additions & 2 deletions data/obd2.dbc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion data/realdash_obd2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion src/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ int obd2_process(const can_frame &frame, bike_data &log_data, const int can_s)
}
}

else if ( obd2Request.mode == 53u ) { // Custom Service
else if ( obd2Request.mode == 0x35 ) { // Custom Service
switch (obd2Request.pid) {
case 1u: {
_status = EXIT_SUCCESS;
Expand Down Expand Up @@ -664,6 +664,27 @@ int obd2_process(const can_frame &frame, bike_data &log_data, const int can_s)
}
break;

case 4u: {
_status = EXIT_SUCCESS;
error_message(DEBUG, "OBD2: Trip A");
struct can_frame _response;
uint32_t fixed_trip ( log_data.trip * 1.609344 / 10.0 ); // convert to tenths (0.1)
_response.data[0]= 6u;
_response.data[1]= 0x75; // Custom Service
_response.data[2]= 4u; // Custom PID
_response.data[3]= fixed_trip >> 24 ;
_response.data[4]= fixed_trip >> 16 ;
_response.data[5]= fixed_trip >> 8 ;
_response.data[6]= fixed_trip ;
_response.can_dlc = 8;
_response.can_id = OBD2_OBD2_FRAME_ID;
if (write(can_s, &_response, sizeof(struct can_frame)) != sizeof(struct can_frame)) {
error_message(ERROR, "OBD2: Response Write failed");
return EXIT_FAILURE;
}
}
break;

default:
error_message(WARN, "WARN:Unknown OBD2 MODE:PID: %X:%X", obd2Request.mode, obd2Request.pid);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ int main(int argc, char *argv[])
log_data.alt_rpm = enData.rpm;
log_data.speed = enData.speed;
log_data.odometer = enData.odometer;
log_data.trip = enData.trip;
log_data.trip = (log_data.odometer - enData.trip) ; //enData.trip marks trip reset
// log_data.systemvoltage = fcData.systemVoltage;
log_data.batteryvoltage = enData.batteryVoltage;
log_data.power = trailing_average_power(log_data);
Expand Down

0 comments on commit 254cc02

Please sign in to comment.