diff --git a/CanSpamTransmitter.c b/CanSpamTransmitter.c index 0c66f1f..9b5d922 100644 --- a/CanSpamTransmitter.c +++ b/CanSpamTransmitter.c @@ -100,6 +100,24 @@ static eTimeEventTransmit isEventTransmitter(tCanSpamTransmitter *env) { if (env->time_CCU_HVC_Req_Msg < env->timeMs) { env->time_CCU_HVC_Req_Msg = env->timeMs + CCU_HVC_Req_Msg_CYC; + // Rolling Counter [0 - 15] + if (ccu_candb_tx.CCU_HVC_Req_Msg.CCU_HVC_Req_RC > 15) { + ccu_candb_tx.CCU_HVC_Req_Msg.CCU_HVC_Req_RC = 0; + } else { + ++ccu_candb_tx.CCU_HVC_Req_Msg.CCU_HVC_Req_RC; + } + + // Checksum XOR8 of the data field this message + // Checksum computed as per XOR algorithm: + // Byte 1 XOR byte 2 .... XOR byte n-1. (n = packet length.) + + uint8_t d0 = (uint8_t) ((ccu_candb_tx.CCU_HVC_Req_Msg.CCU_eCompSpeedReq_Val_ro & (0xFFU))); + uint8_t d1 = (uint8_t) ((ccu_candb_tx.CCU_HVC_Req_Msg.CCU_eCompReq_Stat & (0x01U)) | + ((ccu_candb_tx.CCU_HVC_Req_Msg.CCU_LowTempValve_Req & (0x03U)) << 1U) | + ((ccu_candb_tx.CCU_HVC_Req_Msg.CCU_HVC_Req_RC & (0x0FU)) << 4U)); + + ccu_candb_tx.CCU_HVC_Req_Msg.CCU_HVC_Req_CS = d0 ^ d1; + env->can_id = Pack_CCU_HVC_Req_Msg_candb(&ccu_candb_tx.CCU_HVC_Req_Msg, env->canFrame.data, &env->canFrame.dlc, &env->ide); @@ -151,6 +169,33 @@ static eTimeEventTransmit isEventTransmitter(tCanSpamTransmitter *env) { if (env->time_CCU_Msg1 < env->timeMs) { env->time_CCU_Msg1 = env->timeMs + CCU_Msg1_CYC; + // Rolling Counter [0 - 15] + if (ccu_candb_tx.CCU_Msg1.CCU_MSG1_RC > 15) { + ccu_candb_tx.CCU_Msg1.CCU_MSG1_RC = 0; + } else { + ++ccu_candb_tx.CCU_Msg1.CCU_MSG1_RC; + } + + // Checksum XOR8 of the data field this message + // Checksum computed as per XOR algorithm: + // Byte 1 XOR byte 2 .... XOR byte n-1. (n = packet length.) + uint8_t d0 = (uint8_t) ((ccu_candb_tx.CCU_Msg1.CCU_MirrorHeating_Req & (0x03U)) | + ((ccu_candb_tx.CCU_Msg1.CCU_RecirculationLed_Cmd & (0x01U)) << 2U) | + ((ccu_candb_tx.CCU_Msg1.CCU_DefrostLed_Req & (0x01U)) << 3U) | + ((ccu_candb_tx.CCU_Msg1.CCU_SideWindowHeating_Req & (0x03U)) << 4U) | + ((ccu_candb_tx.CCU_Msg1.CCU_RearWindowHeating_Req & (0x03U)) << 6U)); + uint8_t d1 = (uint8_t) ((ccu_candb_tx.CCU_Msg1.CCU_FrontWindowHeating_Req & (0x03U)) | + ((ccu_candb_tx.CCU_Msg1.CCU_EmergAirCleaning_Stat & (0x01U)) << 2U) | + ((ccu_candb_tx.CCU_Msg1.CCU_FireExtinguishSys_Stat & (0x01U)) << 3U)); + uint8_t d3 = (uint8_t) ((ccu_candb_tx.CCU_Msg1.CCU_FLAutoPsngrLed_Cmd & (0x01U)) | + ((ccu_candb_tx.CCU_Msg1.CCU_FRAutoPsngrLed_Cmd & (0x01U)) << 1U) | + ((ccu_candb_tx.CCU_Msg1.CCU_RLAutoPsngrLed_Cmd & (0x01U)) << 2U) | + ((ccu_candb_tx.CCU_Msg1.CCU_RRAutoPsngrLed_Cmd & (0x01U)) << 3U) | + ((ccu_candb_tx.CCU_Msg1.CCU_AC_MaxLed_Cmd & (0x01U)) << 4U)); + uint8_t d6 = (uint8_t) (((ccu_candb_tx.CCU_Msg1.CCU_MSG1_RC & (0x0FU)) << 4U)); + + ccu_candb_tx.CCU_Msg1.CCU_MSG1_CS = d0 ^ d1 ^ d3 ^ d6; + env->can_id = Pack_CCU_Msg1_candb(&ccu_candb_tx.CCU_Msg1, env->canFrame.data, &env->canFrame.dlc, &env->ide); return event_CCU_Msg1; @@ -167,6 +212,25 @@ static eTimeEventTransmit isEventTransmitter(tCanSpamTransmitter *env) { if (env->time_CCU_Msg3 < env->timeMs) { env->time_CCU_Msg3 = env->timeMs + CCU_Msg3_CYC; + // Rolling Counter [0 - 15] + if (ccu_candb_tx.CCU_Msg3.CCU_MSG3_RC > 15) { + ccu_candb_tx.CCU_Msg3.CCU_MSG3_RC = 0; + } else { + ++ccu_candb_tx.CCU_Msg3.CCU_MSG3_RC; + } + + // Checksum XOR8 of the data field this message + // Checksum computed as per XOR algorithm: + // Byte 1 XOR byte 2 .... XOR byte n-1. (n = packet length.) + + uint8_t d0 = (uint8_t) ((ccu_candb_tx.CCU_Msg3.CCU_FAN_Req & (0x7FU))); + uint8_t d1 = (uint8_t) ((ccu_candb_tx.CCU_Msg3.CCU_RestMode_Stat & (0x03U))); + uint8_t d2 = (uint8_t) ((ccu_candb_tx.CCU_Msg3.CCU_IncarTempSum_Val_ro & (0xFFU))); + uint8_t d3 = (uint8_t) ((ccu_candb_tx.CCU_Msg3.CCU_MSG3_RC & (0x0FU))); + + ccu_candb_tx.CCU_Msg3.CCU_MSG3_CS = d0 ^ d1 ^ d2 ^ d3; + + env->can_id = Pack_CCU_Msg3_candb(&ccu_candb_tx.CCU_Msg3, env->canFrame.data, &env->canFrame.dlc, &env->ide); return event_CCU_Msg3; diff --git a/CanSpamTransmitter.h b/CanSpamTransmitter.h index d7a31c9..ad3247a 100644 --- a/CanSpamTransmitter.h +++ b/CanSpamTransmitter.h @@ -14,13 +14,14 @@ #define CCU_Stat2_SEND 1 #define CCU_Stat3_SEND 1 #define CCU_Errors_SEND 1 -#define CCU_Requests_SEND 0 -#define CCU_HVC_Req_Msg_SEND 0 -#define CCU_VCU_Msg1_SEND 0 -#define CCU_VCU_Msg2_SEND 0 -#define CCU_Msg1_SEND 0 -#define CCU_Msg3_SEND 0 -#define CU_AC_Ctrl_SEND 0 + +#define CCU_Requests_SEND 1 +#define CCU_HVC_Req_Msg_SEND 1 +#define CCU_VCU_Msg1_SEND 1 +#define CCU_VCU_Msg2_SEND 1 +#define CCU_Msg1_SEND 1 +#define CCU_Msg3_SEND 1 +#define CU_AC_Ctrl_SEND 1 typedef enum {