diff --git a/CanSpamTransmitter.c b/CanSpamTransmitter.c index 8d01374..91dccac 100644 --- a/CanSpamTransmitter.c +++ b/CanSpamTransmitter.c @@ -102,7 +102,7 @@ static eTimeEventTransmit isEventTransmitter(tCanSpamTransmitter *env) { env->time_CCU_HVC_Req_Msg = env->timeMs + CCU_HVC_Req_Msg_CYC; // Rolling Counter [0 - 15] - if (env->CCU_HVC_Req_Msg_CCU_HVC_Req_RC > 15) { + if (env->CCU_HVC_Req_Msg_CCU_HVC_Req_RC >= 15) { env->CCU_HVC_Req_Msg_CCU_HVC_Req_RC = 0; } else { ++env->CCU_HVC_Req_Msg_CCU_HVC_Req_RC; @@ -174,12 +174,15 @@ static eTimeEventTransmit isEventTransmitter(tCanSpamTransmitter *env) { 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; + if (env->CCU_Msg1_CCU_MSG1_RC >= 15) { + env->CCU_Msg1_CCU_MSG1_RC = 0; } else { - ++ccu_candb_tx.CCU_Msg1.CCU_MSG1_RC; + ++env->CCU_Msg1_CCU_MSG1_RC; } + ccu_candb_tx.CCU_Msg1.CCU_MSG1_RC = env->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.) @@ -217,7 +220,7 @@ static eTimeEventTransmit isEventTransmitter(tCanSpamTransmitter *env) { env->time_CCU_Msg3 = env->timeMs + CCU_Msg3_CYC; // Rolling Counter [0 - 15] - if (env->CCU_Msg3_CCU_MSG3_RC > 15) { + if (env->CCU_Msg3_CCU_MSG3_RC >= 15) { env->CCU_Msg3_CCU_MSG3_RC = 0; } else { ++env->CCU_Msg3_CCU_MSG3_RC; diff --git a/CanSpamTransmitter.h b/CanSpamTransmitter.h index 22f5bcc..17fb762 100644 --- a/CanSpamTransmitter.h +++ b/CanSpamTransmitter.h @@ -62,6 +62,7 @@ typedef struct { uint32_t time_CCU_AC_Ctrl; uint8_t CCU_HVC_Req_Msg_CCU_HVC_Req_RC; + uint8_t CCU_Msg1_CCU_MSG1_RC; uint8_t CCU_Msg3_CCU_MSG3_RC; bool isMute;