Dfi now works and all vpdiag compatible, also cleaned up a bit CMDs
This commit is contained in:
@@ -14,6 +14,8 @@ extern uint8_t memWrite;
|
|||||||
|
|
||||||
/* EEprom values in ram */
|
/* EEprom values in ram */
|
||||||
extern float dFi;
|
extern float dFi;
|
||||||
|
extern int8_t s_dfi_code;
|
||||||
|
|
||||||
extern uint8_t inj_mode;
|
extern uint8_t inj_mode;
|
||||||
extern uint8_t requestWriteHours;
|
extern uint8_t requestWriteHours;
|
||||||
|
|
||||||
@@ -21,9 +23,9 @@ extern uint8_t requestWriteHours;
|
|||||||
extern void MEM_Init(void);
|
extern void MEM_Init(void);
|
||||||
extern void MEM_WriteAll(void);
|
extern void MEM_WriteAll(void);
|
||||||
extern void MEM_RetrieveValues(void);
|
extern void MEM_RetrieveValues(void);
|
||||||
extern void MEM_WriteCustom(float c_dFi, uint8_t c_inj_mode);
|
extern void MEM_WriteCustom(int8_t c_dFi, uint8_t c_inj_mode);
|
||||||
extern void IncrementQuartHourCounter(void);
|
extern void IncrementQuartHourCounter(void);
|
||||||
|
extern int8_t GetDfiValue();
|
||||||
|
|
||||||
void MEM_WriteDefault(void);
|
void MEM_WriteDefault(void);
|
||||||
|
|
||||||
|
|||||||
@@ -255,6 +255,8 @@ int ReadAndAckByte_Tmo(uint32_t ms, uint8_t *out){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SendAckPacket(){ uint8_t a = (uint8_t)PACKET_CMD_ACK; SendPacket(&a, 1); }
|
void SendAckPacket(){ uint8_t a = (uint8_t)PACKET_CMD_ACK; SendPacket(&a, 1); }
|
||||||
|
void SendNakPacket(){ uint8_t a = (uint8_t)PACKET_CMD_NAK; SendPacket(&a, 1); }
|
||||||
|
|
||||||
void SendPacket(uint8_t* payload, uint8_t length){
|
void SendPacket(uint8_t* payload, uint8_t length){
|
||||||
uint8_t packetLength = (uint8_t)(length + 2);
|
uint8_t packetLength = (uint8_t)(length + 2);
|
||||||
static uint8_t packet[1 + 1 + MAX_PACKET_SIZE + 1];
|
static uint8_t packet[1 + 1 + MAX_PACKET_SIZE + 1];
|
||||||
|
|||||||
@@ -41,12 +41,14 @@ typedef struct {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
PACKET_CMD_ReadIdent = 0x00,
|
PACKET_CMD_ReadIdent = 0x00,
|
||||||
PACKET_CMD_ReadIdentAdress = 0x01,
|
PACKET_CMD_ReadRam = 0x01,
|
||||||
|
PACKET_CMD_WriteRam = 0x02,
|
||||||
PACKET_CMD_ReadRomEeprom = 0x03,
|
PACKET_CMD_ReadRomEeprom = 0x03,
|
||||||
PACKET_CMD_ActuatorTest = 0x04,
|
PACKET_CMD_ActuatorTest = 0x04,
|
||||||
PACKET_CMD_FaultCodesDelete = 0x05,
|
PACKET_CMD_FaultCodesDelete = 0x05,
|
||||||
PACKET_CMD_End = 0x06,
|
PACKET_CMD_End = 0x06,
|
||||||
PACKET_CMD_FaultCodesRead = 0x07,
|
PACKET_CMD_FaultCodesRead = 0x07,
|
||||||
|
PACKET_CMD_SingleRead = 0x08,
|
||||||
PACKET_CMD_ACK = 0x09,
|
PACKET_CMD_ACK = 0x09,
|
||||||
PACKET_CMD_NAK = 0x0A,
|
PACKET_CMD_NAK = 0x0A,
|
||||||
PACKET_CMD_SoftwareCoding = 0x10,
|
PACKET_CMD_SoftwareCoding = 0x10,
|
||||||
@@ -61,6 +63,7 @@ typedef enum {
|
|||||||
PACKET_CMD_ActuatorTestResponse = 0xF5,
|
PACKET_CMD_ActuatorTestResponse = 0xF5,
|
||||||
PACKET_CMD_AsciiData = 0xF6,
|
PACKET_CMD_AsciiData = 0xF6,
|
||||||
PACKET_CMD_WriteEepromResponse = 0xF9,
|
PACKET_CMD_WriteEepromResponse = 0xF9,
|
||||||
|
PACKET_CMD_SingleReadResponse = 0xFB,
|
||||||
PACKET_CMD_FaultCodesResponse = 0xFC,
|
PACKET_CMD_FaultCodesResponse = 0xFC,
|
||||||
PACKET_CMD_ReadRomEepromResponse = 0xFD
|
PACKET_CMD_ReadRomEepromResponse = 0xFD
|
||||||
} PacketCommand;
|
} PacketCommand;
|
||||||
@@ -83,7 +86,7 @@ typedef struct {
|
|||||||
uint8_t isAckNak;
|
uint8_t isAckNak;
|
||||||
} ParsedPacket;
|
} ParsedPacket;
|
||||||
|
|
||||||
#define KLINE_TXBUF_MAX 32 // enough for KWP1281: 2 header + 16 data + 0x03 + margins
|
#define KLINE_TXBUF_MAX 24 // enough for KWP1281: 2 header + 16 data + 0x03 + margins
|
||||||
|
|
||||||
// === Non-blocking TX "byte pump" ===
|
// === Non-blocking TX "byte pump" ===
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -117,6 +120,7 @@ void KLine_OnByteReceived(uint8_t byte);
|
|||||||
// Legacy/blocking API (still available)
|
// Legacy/blocking API (still available)
|
||||||
void SendPacket(uint8_t* payload, uint8_t length);
|
void SendPacket(uint8_t* payload, uint8_t length);
|
||||||
void SendAckPacket(void);
|
void SendAckPacket(void);
|
||||||
|
void SendNakPacket(void);
|
||||||
void WriteByteAndReadAck(uint8_t b);
|
void WriteByteAndReadAck(uint8_t b);
|
||||||
void WriteByteRaw(uint8_t b);
|
void WriteByteRaw(uint8_t b);
|
||||||
void WriteComplement(uint8_t b);
|
void WriteComplement(uint8_t b);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h> // for roundf
|
#include <math.h> // for roundf
|
||||||
|
|
||||||
|
|
||||||
static int ReceivePacket_Tmo(ParsedPacket *out, uint32_t overall_ms);
|
static int ReceivePacket_Tmo(ParsedPacket *out, uint32_t overall_ms);
|
||||||
static void KLine_HandleWriteEeprom(const uint8_t *body, uint8_t body_len);
|
static void KLine_HandleWriteEeprom(const uint8_t *body, uint8_t body_len);
|
||||||
static void KLine_HandleReadRomEeprom(const uint8_t *body, uint8_t body_len);
|
static void KLine_HandleReadRomEeprom(const uint8_t *body, uint8_t body_len);
|
||||||
@@ -22,7 +23,7 @@ static void KLine_HandleReadIdentAddress(const uint8_t *body, uint8_t body_len);
|
|||||||
static void KLine_HandleReadEeprom(const uint8_t *body, uint8_t body_len);
|
static void KLine_HandleReadEeprom(const uint8_t *body, uint8_t body_len);
|
||||||
static void KLine_HandlePassword(const uint8_t *body, uint8_t body_len);
|
static void KLine_HandlePassword(const uint8_t *body, uint8_t body_len);
|
||||||
static void KLine_HandleEnd(void);
|
static void KLine_HandleEnd(void);
|
||||||
static void KLine_HandleCustomPacket(const uint8_t *body, uint8_t body_len);
|
static void KLine_HandleWriteRam(const uint8_t *body, uint8_t body_len);
|
||||||
static void KLine_TerminateAndRearm(void);
|
static void KLine_TerminateAndRearm(void);
|
||||||
|
|
||||||
extern float dFi;
|
extern float dFi;
|
||||||
@@ -144,7 +145,6 @@ void KLine_Slave_Init(void)
|
|||||||
KLine_Rearm5Baud(); // <— call it here
|
KLine_Rearm5Baud(); // <— call it here
|
||||||
|
|
||||||
//KLine5_ResetToIdle();
|
//KLine5_ResetToIdle();
|
||||||
KLine_SetDFI_Value(dFi);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -288,10 +288,14 @@ void KLine_Service(void)
|
|||||||
Slave_SendAsciiStream_WithAcks(combined, n);
|
Slave_SendAsciiStream_WithAcks(combined, n);
|
||||||
KLine_SessionKick();
|
KLine_SessionKick();
|
||||||
break;
|
break;
|
||||||
case PACKET_CMD_ReadIdentAdress: // readIdentAddressCMD
|
case PACKET_CMD_ReadRam: // readIdentAddressCMD
|
||||||
KLine_HandleReadIdentAddress(&packet.raw[3], (uint8_t)(packet.length - 4));
|
KLine_HandleReadIdentAddress(&packet.raw[3], (uint8_t)(packet.length - 4));
|
||||||
packet.type = PACKET_TYPE_UNKNOWN;
|
packet.type = PACKET_TYPE_UNKNOWN;
|
||||||
break;
|
break;
|
||||||
|
case PACKET_CMD_WriteRam: // readIdentAddressCMD
|
||||||
|
KLine_HandleWriteRam(&packet.raw[2], (uint8_t)(packet.length - 4));
|
||||||
|
packet.type = PACKET_TYPE_UNKNOWN;
|
||||||
|
break;
|
||||||
case PACKET_CMD_FaultCodesRead:
|
case PACKET_CMD_FaultCodesRead:
|
||||||
KLine_DTCResponse(); // <-- respond
|
KLine_DTCResponse(); // <-- respond
|
||||||
break;
|
break;
|
||||||
@@ -321,7 +325,8 @@ void KLine_Service(void)
|
|||||||
break; // early return is fine
|
break; // early return is fine
|
||||||
|
|
||||||
default:
|
default:
|
||||||
KLine_HandleCustomPacket(&packet.raw[2], (uint8_t)(packet.length - 4));
|
SendNakPacket();
|
||||||
|
//KLine_HandleCustomPacket(&packet.raw[2], (uint8_t)(packet.length - 4));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -594,7 +599,7 @@ static size_t KLine_BuildDTCStream(uint8_t *out /*>=64*/)
|
|||||||
{
|
{
|
||||||
KLine_SetDTCList(dtcs, 4); //custom test errors
|
KLine_SetDTCList(dtcs, 4); //custom test errors
|
||||||
|
|
||||||
KLine_SetDFI_Value(dFi); // whatever current DFI value is; this encodes s_dfi_code
|
//KLine_SetDFI_Value(dFi); // whatever current DFI value is; this encodes s_dfi_code
|
||||||
|
|
||||||
size_t w = 0;
|
size_t w = 0;
|
||||||
for (size_t i = 0; i < DTC_TOTAL_RECORDS; ++i) {
|
for (size_t i = 0; i < DTC_TOTAL_RECORDS; ++i) {
|
||||||
@@ -865,7 +870,7 @@ static const uint8_t kReadIdentAddrBody[] = { 0x02, 0x00, 0xC6 };
|
|||||||
|
|
||||||
static const uint8_t kActivateSyncOut[] = { 0x02, 0x88, 0x01, 0x04, 0x06, 0x01 };
|
static const uint8_t kActivateSyncOut[] = { 0x02, 0x88, 0x01, 0x04, 0x06, 0x01 };
|
||||||
|
|
||||||
void KLine_SetDFI_Value(float dfi)
|
/*void KLine_SetDFI_Value(float dfi)
|
||||||
{
|
{
|
||||||
// encode: master decodes as ((int8_t)raw[3]) * 3.0 / 256.0
|
// encode: master decodes as ((int8_t)raw[3]) * 3.0 / 256.0
|
||||||
float scaled = dfi * 256.0f / 3.0f;
|
float scaled = dfi * 256.0f / 3.0f;
|
||||||
@@ -873,7 +878,7 @@ void KLine_SetDFI_Value(float dfi)
|
|||||||
if (val < -128) val = -128;
|
if (val < -128) val = -128;
|
||||||
if (val > 127) val = 127;
|
if (val > 127) val = 127;
|
||||||
s_dfi_code = (int8_t)val;
|
s_dfi_code = (int8_t)val;
|
||||||
}
|
}*/
|
||||||
float KLine_GetDFI(void)
|
float KLine_GetDFI(void)
|
||||||
{
|
{
|
||||||
return ((float)s_dfi_code * 3.0f) / 256.0f;
|
return ((float)s_dfi_code * 3.0f) / 256.0f;
|
||||||
@@ -994,7 +999,12 @@ static void KLine_HandleReadEeprom(const uint8_t *body, uint8_t body_len)
|
|||||||
|
|
||||||
// ---- DFI @ 0x0044, len=2 (requires DFI unlock) ----
|
// ---- DFI @ 0x0044, len=2 (requires DFI unlock) ----
|
||||||
if (addr == 0x0044 && len_req == 0x02) {
|
if (addr == 0x0044 && len_req == 0x02) {
|
||||||
if (!s_eeprom_unlocked_dfi) return;
|
if (!s_eeprom_unlocked_dfi) {
|
||||||
|
SendNakPacket();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//KLine_SetDFI_Value(dFi);
|
||||||
|
int8_t s_dfi_code = GetDfiValue();
|
||||||
|
|
||||||
uint8_t payload[3];
|
uint8_t payload[3];
|
||||||
payload[0] = (uint8_t)PACKET_CMD_ReadEepromResponse; // 0xEF
|
payload[0] = (uint8_t)PACKET_CMD_ReadEepromResponse; // 0xEF
|
||||||
@@ -1142,15 +1152,18 @@ static void KLine_HandleReadIdentAddress(const uint8_t *body, uint8_t body_len)
|
|||||||
}
|
}
|
||||||
uint8_t SYNC_PULSE_OUT;
|
uint8_t SYNC_PULSE_OUT;
|
||||||
|
|
||||||
static void KLine_HandleCustomPacket(const uint8_t *body, uint8_t body_len)
|
static void KLine_HandleWriteRam(const uint8_t *body, uint8_t body_len)
|
||||||
{
|
{
|
||||||
if (body_len < sizeof(kActivateSyncOut)){
|
if (body_len < sizeof(kActivateSyncOut)){
|
||||||
if (memcmp(body, kActivateSyncOut, sizeof(kActivateSyncOut)) == 0){
|
if (memcmp(body, kActivateSyncOut, sizeof(kActivateSyncOut)) == 0){
|
||||||
SYNC_PULSE_OUT = 1;
|
SYNC_PULSE_OUT = 1;
|
||||||
SendAckPacket();
|
SendAckPacket();
|
||||||
KLine_SessionKick();
|
KLine_SessionKick();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendNakPacket();
|
||||||
/*
|
/*
|
||||||
ParsedPacket ack = (ParsedPacket){0};
|
ParsedPacket ack = (ParsedPacket){0};
|
||||||
if (ReceivePacket_Tmo(&ack, 200) && ack.title == PACKET_CMD_ACK) {
|
if (ReceivePacket_Tmo(&ack, 200) && ack.title == PACKET_CMD_ACK) {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ uint32_t quart_hour_counter = 0;
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint8_t isCoded;
|
uint8_t isCoded;
|
||||||
float dFi; //-128,127 -> *3/256 = dfi
|
int8_t dFi; //-128,127 -> *3/256 = dfi
|
||||||
uint8_t inj_mode;
|
uint8_t inj_mode;
|
||||||
uint32_t quart_hour_counter;
|
uint32_t quart_hour_counter;
|
||||||
|
|
||||||
@@ -31,14 +31,16 @@ void MEM_Init(){
|
|||||||
MEM_WriteDefault();
|
MEM_WriteDefault();
|
||||||
}
|
}
|
||||||
if(ee.isCoded == 255){
|
if(ee.isCoded == 255){
|
||||||
MEM_WriteCustom(0.7, 0);
|
MEM_WriteCustom(0.0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void MEM_RetrieveValues(){
|
void MEM_RetrieveValues(){
|
||||||
if(!memInit){
|
if(!memInit){
|
||||||
MEM_Init();
|
MEM_Init();
|
||||||
}
|
}
|
||||||
dFi = ee.dFi;
|
s_dfi_code = ee.dFi;
|
||||||
|
dFi = (float)s_dfi_code * 3.0 / 256;
|
||||||
|
|
||||||
inj_mode = ee.inj_mode;
|
inj_mode = ee.inj_mode;
|
||||||
quart_hour_counter = ee.quart_hour_counter;
|
quart_hour_counter = ee.quart_hour_counter;
|
||||||
|
|
||||||
@@ -49,7 +51,7 @@ void MEM_Cleanup(){ //only after changes to the struct
|
|||||||
}
|
}
|
||||||
void MEM_WriteAll(){
|
void MEM_WriteAll(){
|
||||||
ee.isCoded = 1;
|
ee.isCoded = 1;
|
||||||
ee.dFi = dFi;
|
ee.dFi = s_dfi_code;
|
||||||
ee.inj_mode = inj_mode;
|
ee.inj_mode = inj_mode;
|
||||||
ee.quart_hour_counter = quart_hour_counter;
|
ee.quart_hour_counter = quart_hour_counter;
|
||||||
|
|
||||||
@@ -58,11 +60,11 @@ void MEM_WriteAll(){
|
|||||||
|
|
||||||
void MEM_WriteDefault(){
|
void MEM_WriteDefault(){
|
||||||
ee.isCoded = 1;
|
ee.isCoded = 1;
|
||||||
ee.dFi = 0.0;
|
ee.dFi = 0;
|
||||||
ee.inj_mode = 0;
|
ee.inj_mode = 0;
|
||||||
EE_Write();
|
EE_Write();
|
||||||
}
|
}
|
||||||
void MEM_WriteCustom(float c_dFi, uint8_t c_inj_mode){
|
void MEM_WriteCustom(int8_t c_dFi, uint8_t c_inj_mode){
|
||||||
ee.isCoded = 1;
|
ee.isCoded = 1;
|
||||||
ee.dFi = c_dFi;
|
ee.dFi = c_dFi;
|
||||||
ee.inj_mode = c_inj_mode;
|
ee.inj_mode = c_inj_mode;
|
||||||
@@ -72,3 +74,6 @@ void IncrementQuartHourCounter(){
|
|||||||
quart_hour_counter++;
|
quart_hour_counter++;
|
||||||
memWrite = 1;
|
memWrite = 1;
|
||||||
}
|
}
|
||||||
|
int8_t GetDfiValue(){
|
||||||
|
return ee.dFi;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user