diff --git a/app/app.c b/app/app.c index b87fbf0..4a6e8fc 100644 --- a/app/app.c +++ b/app/app.c @@ -1803,10 +1803,11 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gKeyLockCountdown = 30; // 15 seconds #ifdef ENABLE_DTMF_DECODER - if (Key == KEY_EXIT && bKeyPressed && bKeyHeld) - { // clear the DTMF RX display buffer + if (Key == KEY_EXIT && bKeyPressed && bKeyHeld && gDTMF_ReceivedSaved[0] > 0) + { // clear the live DTMF RX if the EXIT key is held gDTMF_RecvTimeoutSaved = 0; gDTMF_ReceivedSaved[0] = '\0'; + gUpdateDisplay = true; } #endif diff --git a/app/dtmf.c b/app/dtmf.c index 12968a6..5b222c9 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -15,6 +15,7 @@ */ #include +#include // NULL #ifdef ENABLE_FMRADIO #include "app/fm.h" @@ -161,7 +162,7 @@ void DTMF_Append(char Code) if (gDTMF_InputIndex == 0) { memset(gDTMF_InputBox, '-', sizeof(gDTMF_InputBox)); - gDTMF_InputBox[14] = 0; + gDTMF_InputBox[sizeof(gDTMF_InputBox) - 1] = 0; } else if (gDTMF_InputIndex >= sizeof(gDTMF_InputBox)) @@ -295,12 +296,15 @@ void DTMF_HandleRequest(void) void DTMF_Reply(void) { - char String[20]; - const char *pString; uint16_t Delay; + char String[20]; + const char *pString = NULL; switch (gDTMF_ReplyState) { + case DTMF_REPLY_NONE: + return; + case DTMF_REPLY_ANI: if (gDTMF_CallMode == DTMF_CALL_MODE_DTMF) { @@ -308,6 +312,7 @@ void DTMF_Reply(void) } else { + // append out ID code onto the end of the DTMF code to send sprintf(String, "%s%c%s", gDTMF_String, gEeprom.DTMF_SEPARATE_CODE, gEeprom.ANI_DTMF_ID); pString = String; } @@ -334,16 +339,15 @@ void DTMF_Reply(void) gDTMF_ReplyState = DTMF_REPLY_NONE; + if (pString == NULL) + return; + Delay = gEeprom.DTMF_PRELOAD_TIME; if (gEeprom.DTMF_SIDE_TONE) { GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - gEnableSpeaker = true; - - Delay = gEeprom.DTMF_PRELOAD_TIME; - if (gEeprom.DTMF_PRELOAD_TIME < 60) - Delay = 60; + Delay = (gEeprom.DTMF_PRELOAD_TIME < 60) ? 60 : gEeprom.DTMF_PRELOAD_TIME; } SYSTEM_DelayMs(Delay); diff --git a/app/dtmf.h b/app/dtmf.h index 63bfad8..7a39b18 100644 --- a/app/dtmf.h +++ b/app/dtmf.h @@ -21,34 +21,34 @@ #include enum DTMF_State_t { - DTMF_STATE_0 = 0U, - DTMF_STATE_TX_SUCC = 1U, - DTMF_STATE_CALL_OUT_RSP = 2U, + DTMF_STATE_0 = 0, + DTMF_STATE_TX_SUCC, + DTMF_STATE_CALL_OUT_RSP }; typedef enum DTMF_State_t DTMF_State_t; enum DTMF_CallState_t { - DTMF_CALL_STATE_NONE = 0U, - DTMF_CALL_STATE_CALL_OUT = 1U, - DTMF_CALL_STATE_RECEIVED = 2U, + DTMF_CALL_STATE_NONE = 0, + DTMF_CALL_STATE_CALL_OUT, + DTMF_CALL_STATE_RECEIVED }; typedef enum DTMF_CallState_t DTMF_CallState_t; enum DTMF_ReplyState_t { - DTMF_REPLY_NONE = 0U, - DTMF_REPLY_ANI = 1U, - DTMF_REPLY_AB = 2U, - DTMF_REPLY_AAAAA = 3U, + DTMF_REPLY_NONE = 0, + DTMF_REPLY_ANI, + DTMF_REPLY_AB, + DTMF_REPLY_AAAAA }; typedef enum DTMF_ReplyState_t DTMF_ReplyState_t; enum DTMF_CallMode_t { - DTMF_CALL_MODE_NOT_GROUP = 0U, - DTMF_CALL_MODE_GROUP = 1U, - DTMF_CALL_MODE_DTMF = 2U, + DTMF_CALL_MODE_NOT_GROUP = 0, + DTMF_CALL_MODE_GROUP, + DTMF_CALL_MODE_DTMF }; typedef enum DTMF_CallMode_t DTMF_CallMode_t; @@ -94,4 +94,3 @@ void DTMF_HandleRequest(void); void DTMF_Reply(void); #endif - diff --git a/app/generic.c b/app/generic.c index fdbe80e..98ba712 100644 --- a/app/generic.c +++ b/app/generic.c @@ -179,16 +179,22 @@ void GENERIC_Key_PTT(bool bKeyPressed) if (gDTMF_InputMode) { - if (gDTMF_InputIndex || gDTMF_PreviousIndex) + if (gDTMF_InputIndex > 0 || gDTMF_PreviousIndex > 0) { if (gDTMF_InputIndex == 0) gDTMF_InputIndex = gDTMF_PreviousIndex; gDTMF_InputBox[gDTMF_InputIndex] = 0; - if (gDTMF_InputIndex == 3) - gDTMF_CallMode = DTMF_CheckGroupCall(gDTMF_InputBox, 3); - else + #if 0 + if (gDTMF_InputIndex == 3) + gDTMF_CallMode = DTMF_CheckGroupCall(gDTMF_InputBox, 3); // this will cause our ID tobe appened to the DTMF code + else + #else + if (gDTMF_InputIndex == 3 && gTxVfo->DTMF_DECODING_ENABLE > 0) + gDTMF_CallMode = DTMF_CheckGroupCall(gDTMF_InputBox, 3); // this will cause our ID tobe appened to the DTMF code + else + #endif gDTMF_CallMode = DTMF_CALL_MODE_DTMF; strcpy(gDTMF_String, gDTMF_InputBox); diff --git a/app/main.c b/app/main.c index 422c57c..8fc5814 100644 --- a/app/main.c +++ b/app/main.c @@ -509,7 +509,7 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) { gKeyInputCountdown = key_input_timeout_500ms; gDTMF_InputMode = true; - memmove(gDTMF_InputBox, gDTMF_String, 15); + memmove(gDTMF_InputBox, gDTMF_String, sizeof(gDTMF_InputBox)); gDTMF_InputIndex = 0; gRequestDisplayScreen = DISPLAY_MAIN; return; diff --git a/board.c b/board.c index 5d3e35c..e58e45f 100644 --- a/board.c +++ b/board.c @@ -648,37 +648,51 @@ void BOARD_EEPROM_Init(void) if (DTMF_ValidateCodes((char *)Data, 8)) memmove(gEeprom.ANI_DTMF_ID, Data, 8); else - // Original firmware overflows into the next string - memmove(gEeprom.ANI_DTMF_ID, "123\0\0\0\0", 8); - + { + memset(gEeprom.ANI_DTMF_ID, 0, sizeof(gEeprom.ANI_DTMF_ID)); + strcpy(gEeprom.ANI_DTMF_ID, "123"); + } + // 0EE8..0EEF EEPROM_ReadBuffer(0x0EE8, Data, 8); if (DTMF_ValidateCodes((char *)Data, 8)) memmove(gEeprom.KILL_CODE, Data, 8); else - memmove(gEeprom.KILL_CODE, "ABCD9\0\0", 8); - + { + memset(gEeprom.KILL_CODE, 0, sizeof(gEeprom.KILL_CODE)); + strcpy(gEeprom.KILL_CODE, "ABCD9"); + } + // 0EF0..0EF7 EEPROM_ReadBuffer(0x0EF0, Data, 8); if (DTMF_ValidateCodes((char *)Data, 8)) memmove(gEeprom.REVIVE_CODE, Data, 8); else - memmove(gEeprom.REVIVE_CODE, "9DCBA\0\0", 8); - + { + memset(gEeprom.REVIVE_CODE, 0, sizeof(gEeprom.REVIVE_CODE)); + strcpy(gEeprom.REVIVE_CODE, "9DCBA"); + } + // 0EF8..0F07 EEPROM_ReadBuffer(0x0EF8, Data, 16); if (DTMF_ValidateCodes((char *)Data, 16)) memmove(gEeprom.DTMF_UP_CODE, Data, 16); else - memmove(gEeprom.DTMF_UP_CODE, "12345\0\0\0\0\0\0\0\0\0\0", 16); - + { + memset(gEeprom.DTMF_UP_CODE, 0, sizeof(gEeprom.DTMF_UP_CODE)); + strcpy(gEeprom.DTMF_UP_CODE, "12345"); + } + // 0F08..0F17 EEPROM_ReadBuffer(0x0F08, Data, 16); if (DTMF_ValidateCodes((char *)Data, 16)) memmove(gEeprom.DTMF_DOWN_CODE, Data, 16); else - memmove(gEeprom.DTMF_DOWN_CODE, "54321\0\0\0\0\0\0\0\0\0\0", 16); - + { + memset(gEeprom.DTMF_DOWN_CODE, 0, sizeof(gEeprom.DTMF_DOWN_CODE)); + strcpy(gEeprom.DTMF_DOWN_CODE, "54321"); + } + // 0F18..0F1F EEPROM_ReadBuffer(0x0F18, Data, 8); gEeprom.SCAN_LIST_DEFAULT = (Data[0] < 2) ? Data[0] : false; diff --git a/driver/bk4819.c b/driver/bk4819.c index 55f0742..9f0ab67 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -14,6 +14,8 @@ * limitations under the License. */ +#include // NULL + #include "bk4819.h" #include "bsp/dp32g030/gpio.h" #include "bsp/dp32g030/portcon.h" @@ -818,6 +820,10 @@ void BK4819_PlayDTMF(char Code) void BK4819_PlayDTMFString(const char *pString, bool bDelayFirst, uint16_t FirstCodePersistTime, uint16_t HashCodePersistTime, uint16_t CodePersistTime, uint16_t CodeInternalTime) { unsigned int i; + + if (pString == NULL) + return; + for (i = 0; pString[i]; i++) { uint16_t Delay; diff --git a/firmware b/firmware index df10284..63cd268 100644 Binary files a/firmware and b/firmware differ diff --git a/firmware.bin b/firmware.bin index e906558..279b8c0 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 533fde5..85ad4f5 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/main.c b/main.c index e03bf3e..bf9e3d3 100644 --- a/main.c +++ b/main.c @@ -74,7 +74,7 @@ void Main(void) memset(&gEeprom, 0, sizeof(gEeprom)); memset(gDTMF_String, '-', sizeof(gDTMF_String)); - gDTMF_String[14] = 0; + gDTMF_String[sizeof(gDTMF_String) - 1] = 0; BK4819_Init();