Skip to content

Commit

Permalink
Twizy OBD2: fix presence alert handling, added diag session & signals
Browse files Browse the repository at this point in the history
  • Loading branch information
dexterbg committed Aug 17, 2019
1 parent 7cebec4 commit 5360c7b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
33 changes: 23 additions & 10 deletions vehicle/OVMS.V3/components/vehicle_renaulttwizy/src/rt_obd2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ using namespace std;
#define CLUSTER_RXID 0x763
#define CLUSTER_PID_VIN 0x81
#define CLUSTER_PID_DTC 0x13
#define SESSION_EXTDIAG 0xC0

const OvmsVehicle::poll_pid_t twizy_poll_default[] = {
// Note: poller ticker cycles at 3600 seconds = max period
// { txid, rxid, type, pid, { period_off, period_drive, period_charge } }
{ CLUSTER_TXID, CLUSTER_RXID, VEHICLE_POLL_TYPE_OBDIIGROUP, CLUSTER_PID_VIN, { 0, 3600, 3600 } },
{ CLUSTER_TXID, CLUSTER_RXID, VEHICLE_POLL_TYPE_OBDIIGROUP, CLUSTER_PID_DTC, { 0, 10, 60 } },
{ CLUSTER_TXID, CLUSTER_RXID, VEHICLE_POLL_TYPE_OBDIISESSION, SESSION_EXTDIAG, { 0, 10, 60 } },
{ CLUSTER_TXID, CLUSTER_RXID, VEHICLE_POLL_TYPE_OBDIIGROUP, CLUSTER_PID_VIN, { 0, 3600, 3600 } },
{ CLUSTER_TXID, CLUSTER_RXID, VEHICLE_POLL_TYPE_OBDIIGROUP, CLUSTER_PID_DTC, { 0, 10, 60 } },
{ 0, 0, 0, 0, { 0, 0, 0 } }
};

Expand Down Expand Up @@ -132,11 +134,13 @@ void OvmsVehicleRenaultTwizy::IncomingPollReply(
switch (pid) {

// VIN:
case CLUSTER_PID_VIN:
case CLUSTER_PID_VIN: {
// payload = 17 chars VIN + 2 bytes checksum
ESP_LOGD(TAG, "OBD2: got VIN='%s'", rxbuf.substr(0,17).c_str());
*StdMetrics.ms_v_vin = rxbuf.substr(0,17);
string vin = rxbuf.substr(0,17);
ESP_LOGD(TAG, "OBD2: got VIN='%s'", vin.c_str());
if (vin[0]) *StdMetrics.ms_v_vin = vin;
break;
}

// DTC:
case CLUSTER_PID_DTC:
Expand All @@ -147,15 +151,20 @@ void OvmsVehicleRenaultTwizy::IncomingPollReply(
// alert processing done by ticker
break;

// Ignored:
case SESSION_EXTDIAG:
ESP_LOGV(TAG, "OBD2: ignored reply [%02x %02x]", type, pid);
break;

// Unknown: output
default: {
char *buf = NULL;
size_t rlen = rxbuf.size(), offset = 0;
while (rlen) {
do {
rlen = FormatHexDump(&buf, rxbuf.data() + offset, rlen, 16);
offset += 16;
ESP_LOGW(TAG, "OBD2: unhandled reply: %s", buf);
}
ESP_LOGW(TAG, "OBD2: unhandled reply [%02x %02x]: %s", type, pid, buf ? buf : "-");
} while (rlen);
if (buf)
free(buf);
break;
Expand Down Expand Up @@ -283,9 +292,13 @@ void OvmsVehicleRenaultTwizy::ObdTicker10()
dtcbuf.append(new_dtc ? "NEW " : "UPD ");
FormatDTC(dtcbuf, i, n);
ESP_LOGW(TAG, "OBD2 Cluster DTC %s", dtcbuf.c_str());

// …signal:
MyEvents.SignalEvent(n.FailPresent ? "vehicle.dtc.present" : "vehicle.dtc.stored",
(void*)dtcbuf.data(), dtcbuf.size());

// …add to alert:
if (!twizy_cluster_dtc_inhibit_alert || new_present) {
if (new_present || (n!=e && !twizy_cluster_dtc_inhibit_alert)) {
alertbuf.append(dtcbuf);
alertbuf.append("\n");
}
Expand All @@ -301,7 +314,7 @@ void OvmsVehicleRenaultTwizy::ObdTicker10()

if (!alertbuf.empty())
{
MyNotify.NotifyStringf("alert", "vehicle.status.dtc", "DTC update (%d stored, %d present):\n%s",
MyNotify.NotifyStringf("alert", "vehicle.dtc", "DTC update (%d stored, %d present):\n%s",
cnt_stored, cnt_present, alertbuf.c_str());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct __attribute__ ((__packed__)) cluster_dtc {
// Bytes 8…11
uint8_t IgnitionCycle; // ? 0xFF = off
uint8_t TimeCounter; // ? reoccurrence count? normally 0
uint8_t BL; // Battery SOC level [%]
int8_t BL; // Battery SOC level [%]
int8_t Speed; // [kph] / 0xFF


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "ovms_log.h"
static const char *TAG = "v-twizy";

#define VERSION "1.2.1"
#define VERSION "1.2.2"

#include <stdio.h>
#include <string>
Expand Down

0 comments on commit 5360c7b

Please sign in to comment.