Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trip #36

Merged
merged 3 commits into from
Feb 19, 2024
Merged

Trip #36

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading