mirror of
https://github.com/OneOfEleven/uv-k5-firmware-custom.git
synced 2025-06-20 06:58:39 +03:00
Various DTMF bug fixes and renames
This commit is contained in:
194
app/dtmf.c
194
app/dtmf.c
@ -22,6 +22,7 @@
|
||||
#endif
|
||||
#include "app/scanner.h"
|
||||
#include "bsp/dp32g030/gpio.h"
|
||||
#include "audio.h"
|
||||
#include "driver/bk4819.h"
|
||||
#include "driver/eeprom.h"
|
||||
#include "driver/gpio.h"
|
||||
@ -33,12 +34,16 @@
|
||||
#include "ui/ui.h"
|
||||
|
||||
char gDTMF_String[15];
|
||||
char gDTMF_InputBox[15];
|
||||
|
||||
char gDTMF_Received[16];
|
||||
uint8_t gDTMF_WriteIndex = 0;
|
||||
char gDTMF_InputBox[15];
|
||||
uint8_t gDTMF_InputIndex = 0;
|
||||
bool gDTMF_InputMode = false;
|
||||
uint8_t gDTMF_PreviousIndex = 0;
|
||||
uint8_t gDTMF_RecvTimeout = 0;
|
||||
|
||||
char gDTMF_RX[17];
|
||||
uint8_t gDTMF_RX_index = 0;
|
||||
uint8_t gDTMF_RX_timeout = 0;
|
||||
bool gDTMF_RX_pending = false;
|
||||
|
||||
char gDTMF_RX_live[20];
|
||||
uint8_t gDTMF_RX_live_timeout = 0;
|
||||
@ -48,12 +53,9 @@ char gDTMF_ID[4];
|
||||
char gDTMF_Caller[4];
|
||||
char gDTMF_Callee[4];
|
||||
DTMF_State_t gDTMF_State;
|
||||
bool gDTMF_DecodeRing;
|
||||
uint8_t gDTMF_DecodeRingCountdown_500ms;
|
||||
uint8_t gDTMFChosenContact;
|
||||
uint8_t gDTMF_AUTO_RESET_TIME;
|
||||
uint8_t gDTMF_InputIndex;
|
||||
bool gDTMF_InputMode;
|
||||
DTMF_CallState_t gDTMF_CallState;
|
||||
DTMF_ReplyState_t gDTMF_ReplyState;
|
||||
DTMF_CallMode_t gDTMF_CallMode;
|
||||
@ -61,14 +63,22 @@ bool gDTMF_IsTx;
|
||||
uint8_t gDTMF_TxStopCountdown_500ms;
|
||||
bool gDTMF_IsGroupCall;
|
||||
|
||||
bool DTMF_ValidateCodes(char *pCode, uint8_t Size)
|
||||
void DTMF_clear_RX(void)
|
||||
{
|
||||
gDTMF_RX_timeout = 0;
|
||||
gDTMF_RX_index = 0;
|
||||
gDTMF_RX_pending = false;
|
||||
memset(gDTMF_RX, 0, sizeof(gDTMF_RX));
|
||||
}
|
||||
|
||||
bool DTMF_ValidateCodes(char *pCode, const unsigned int size)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (pCode[0] == 0xFF || pCode[0] == 0)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < Size; i++)
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (pCode[i] == 0xFF || pCode[i] == 0)
|
||||
{
|
||||
@ -121,16 +131,16 @@ bool DTMF_FindContact(const char *pContact, char *pResult)
|
||||
return false;
|
||||
}
|
||||
|
||||
char DTMF_GetCharacter(const uint8_t code)
|
||||
char DTMF_GetCharacter(const unsigned int code)
|
||||
{
|
||||
const char list[] = "0123456789ABCD*#";
|
||||
return (code < ARRAY_SIZE(list)) ? list[code] : 0xFF;
|
||||
}
|
||||
|
||||
bool DTMF_CompareMessage(const char *pMsg, const char *pTemplate, uint8_t Size, bool bCheckGroup)
|
||||
bool DTMF_CompareMessage(const char *pMsg, const char *pTemplate, const unsigned int size, const bool bCheckGroup)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < Size; i++)
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
if (pMsg[i] != pTemplate[i])
|
||||
{
|
||||
@ -140,58 +150,69 @@ bool DTMF_CompareMessage(const char *pMsg, const char *pTemplate, uint8_t Size,
|
||||
}
|
||||
}
|
||||
|
||||
return DTMF_CALL_MODE_NOT_GROUP;
|
||||
return true;
|
||||
}
|
||||
|
||||
DTMF_CallMode_t DTMF_CheckGroupCall(const char *pMsg, uint32_t Size)
|
||||
DTMF_CallMode_t DTMF_CheckGroupCall(const char *pMsg, const unsigned int size)
|
||||
{
|
||||
uint32_t i;
|
||||
for (i = 0; i < Size; i++)
|
||||
unsigned int i;
|
||||
for (i = 0; i < size; i++)
|
||||
if (pMsg[i] == gEeprom.DTMF_GROUP_CALL_CODE)
|
||||
break;
|
||||
return (i != Size) ? DTMF_CALL_MODE_GROUP : DTMF_CALL_MODE_NOT_GROUP;
|
||||
|
||||
return (i < size) ? DTMF_CALL_MODE_GROUP : DTMF_CALL_MODE_NOT_GROUP;
|
||||
}
|
||||
|
||||
void DTMF_Append(char Code)
|
||||
void DTMF_Append(const char code)
|
||||
{
|
||||
if (gDTMF_InputIndex == 0)
|
||||
{
|
||||
memset(gDTMF_InputBox, '-', sizeof(gDTMF_InputBox));
|
||||
gDTMF_InputBox[sizeof(gDTMF_InputBox) - 1] = 0;
|
||||
}
|
||||
else
|
||||
if (gDTMF_InputIndex >= sizeof(gDTMF_InputBox))
|
||||
return;
|
||||
|
||||
gDTMF_InputBox[gDTMF_InputIndex++] = Code;
|
||||
if (gDTMF_InputIndex < sizeof(gDTMF_InputBox))
|
||||
gDTMF_InputBox[gDTMF_InputIndex++] = code;
|
||||
}
|
||||
|
||||
void DTMF_HandleRequest(void)
|
||||
{
|
||||
char String[20];
|
||||
uint8_t Offset;
|
||||
{ // proccess the RX'ed DTMF characters
|
||||
|
||||
if (!gDTMF_RequestPending)
|
||||
return;
|
||||
char String[20];
|
||||
unsigned int Offset;
|
||||
|
||||
gDTMF_RequestPending = false;
|
||||
if (!gDTMF_RX_pending)
|
||||
return; // nothing new received
|
||||
|
||||
if (gScanState != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF)
|
||||
{ // we're busy scanning
|
||||
DTMF_clear_RX();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (!gRxVfo->DTMF_DECODING_ENABLE && !gSetting_KILLED)
|
||||
{ // D-DCD is disabled or we're alive
|
||||
DTMF_clear_RX();
|
||||
return;
|
||||
}
|
||||
|
||||
gDTMF_RX_pending = false;
|
||||
|
||||
if (gDTMF_RX_index >= 9)
|
||||
{ // look for the KILL code
|
||||
|
||||
if (gDTMF_WriteIndex >= 9)
|
||||
{
|
||||
Offset = gDTMF_WriteIndex - 9;
|
||||
sprintf(String, "%s%c%s", gEeprom.ANI_DTMF_ID, gEeprom.DTMF_SEPARATE_CODE, gEeprom.KILL_CODE);
|
||||
|
||||
if (DTMF_CompareMessage(gDTMF_Received + Offset, String, 9, true))
|
||||
{
|
||||
Offset = gDTMF_RX_index - strlen(String);
|
||||
|
||||
if (DTMF_CompareMessage(gDTMF_RX + Offset, String, strlen(String), true))
|
||||
{ // bugger
|
||||
|
||||
if (gEeprom.PERMIT_REMOTE_KILL)
|
||||
{
|
||||
gSetting_KILLED = true;
|
||||
gSetting_KILLED = true; // oooerr !
|
||||
|
||||
DTMF_clear_RX();
|
||||
|
||||
SETTINGS_SaveSettings();
|
||||
|
||||
@ -212,82 +233,117 @@ void DTMF_HandleRequest(void)
|
||||
|
||||
gDTMF_CallState = DTMF_CALL_STATE_NONE;
|
||||
|
||||
gUpdateDisplay = true;
|
||||
gUpdateStatus = true;
|
||||
gUpdateDisplay = true;
|
||||
gUpdateStatus = true;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (gDTMF_RX_index >= 9)
|
||||
{ // look for the REVIVE code
|
||||
|
||||
sprintf(String, "%s%c%s", gEeprom.ANI_DTMF_ID, gEeprom.DTMF_SEPARATE_CODE, gEeprom.REVIVE_CODE);
|
||||
if (DTMF_CompareMessage(gDTMF_Received + Offset, String, 9, true))
|
||||
{
|
||||
|
||||
Offset = gDTMF_RX_index - strlen(String);
|
||||
|
||||
if (DTMF_CompareMessage(gDTMF_RX + Offset, String, strlen(String), true))
|
||||
{ // shit, we're back !
|
||||
|
||||
gSetting_KILLED = false;
|
||||
|
||||
DTMF_clear_RX();
|
||||
|
||||
SETTINGS_SaveSettings();
|
||||
|
||||
gDTMF_ReplyState = DTMF_REPLY_AB;
|
||||
gDTMF_CallState = DTMF_CALL_STATE_NONE;
|
||||
|
||||
gUpdateDisplay = true;
|
||||
gUpdateStatus = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (gDTMF_WriteIndex >= 2)
|
||||
{
|
||||
if (DTMF_CompareMessage(gDTMF_Received + (gDTMF_WriteIndex - 2), "AB", 2, true))
|
||||
{
|
||||
gDTMF_State = DTMF_STATE_TX_SUCC;
|
||||
gUpdateDisplay = true;
|
||||
return;
|
||||
if (gDTMF_RX_index >= 2)
|
||||
{ // look for ACK reply
|
||||
|
||||
strcpy(String, "AB");
|
||||
|
||||
Offset = gDTMF_RX_index - strlen(String);
|
||||
|
||||
if (DTMF_CompareMessage(gDTMF_RX + Offset, String, strlen(String), true))
|
||||
{ // ends with "AB"
|
||||
|
||||
if (gDTMF_ReplyState != DTMF_REPLY_NONE) // 1of11
|
||||
// if (gDTMF_CallState != DTMF_CALL_STATE_NONE) // 1of11
|
||||
// if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT) // 1of11
|
||||
{
|
||||
gDTMF_State = DTMF_STATE_TX_SUCC;
|
||||
DTMF_clear_RX();
|
||||
gUpdateDisplay = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT && gDTMF_CallMode == DTMF_CALL_MODE_NOT_GROUP && gDTMF_WriteIndex >= 9)
|
||||
{
|
||||
Offset = gDTMF_WriteIndex - 9;
|
||||
|
||||
if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT &&
|
||||
gDTMF_CallMode == DTMF_CALL_MODE_NOT_GROUP &&
|
||||
gDTMF_RX_index >= 9)
|
||||
{ // waiting for a reply
|
||||
|
||||
sprintf(String, "%s%c%s", gDTMF_String, gEeprom.DTMF_SEPARATE_CODE, "AAAAA");
|
||||
|
||||
if (DTMF_CompareMessage(gDTMF_Received + Offset, String, 9, false))
|
||||
{
|
||||
Offset = gDTMF_RX_index - strlen(String);
|
||||
|
||||
if (DTMF_CompareMessage(gDTMF_RX + Offset, String, strlen(String), false))
|
||||
{ // we got a response
|
||||
gDTMF_State = DTMF_STATE_CALL_OUT_RSP;
|
||||
DTMF_clear_RX();
|
||||
gUpdateDisplay = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (gSetting_KILLED || gDTMF_CallState != DTMF_CALL_STATE_NONE)
|
||||
{ // we've been killed or expecting a reply
|
||||
return;
|
||||
}
|
||||
|
||||
if (gDTMF_WriteIndex >= 7)
|
||||
{
|
||||
Offset = gDTMF_WriteIndex - 7;
|
||||
|
||||
sprintf(String, "%s%c", gEeprom.ANI_DTMF_ID, gEeprom.DTMF_SEPARATE_CODE);
|
||||
if (gDTMF_RX_index >= 7)
|
||||
{ // see if we're being called
|
||||
|
||||
gDTMF_IsGroupCall = false;
|
||||
|
||||
if (DTMF_CompareMessage(gDTMF_Received + Offset, String, 4, true))
|
||||
{
|
||||
sprintf(String, "%s%c", gEeprom.ANI_DTMF_ID, gEeprom.DTMF_SEPARATE_CODE);
|
||||
|
||||
Offset = gDTMF_RX_index - strlen(String) - 3;
|
||||
|
||||
if (DTMF_CompareMessage(gDTMF_RX + Offset, String, strlen(String), true))
|
||||
{ // it's for us !
|
||||
|
||||
gDTMF_CallState = DTMF_CALL_STATE_RECEIVED;
|
||||
|
||||
memmove(gDTMF_Callee, gDTMF_Received + Offset + 0, 3);
|
||||
memmove(gDTMF_Caller, gDTMF_Received + Offset + 4, 3);
|
||||
memset(gDTMF_Callee, 0, sizeof(gDTMF_Callee));
|
||||
memset(gDTMF_Caller, 0, sizeof(gDTMF_Caller));
|
||||
memmove(gDTMF_Callee, gDTMF_RX + Offset + 0, 3);
|
||||
memmove(gDTMF_Caller, gDTMF_RX + Offset + 4, 3);
|
||||
|
||||
DTMF_clear_RX();
|
||||
|
||||
gUpdateDisplay = true;
|
||||
|
||||
switch (gEeprom.DTMF_DECODE_RESPONSE)
|
||||
{
|
||||
case 3:
|
||||
gDTMF_DecodeRing = true;
|
||||
case DTMF_DEC_RESPONSE_BOTH:
|
||||
gDTMF_DecodeRingCountdown_500ms = DTMF_decode_ring_countdown_500ms;
|
||||
// Fallthrough
|
||||
case 2:
|
||||
case DTMF_DEC_RESPONSE_REPLY:
|
||||
gDTMF_ReplyState = DTMF_REPLY_AAAAA;
|
||||
break;
|
||||
case 1:
|
||||
gDTMF_DecodeRing = true;
|
||||
case DTMF_DEC_RESPONSE_RING:
|
||||
gDTMF_DecodeRingCountdown_500ms = DTMF_decode_ring_countdown_500ms;
|
||||
break;
|
||||
default:
|
||||
gDTMF_DecodeRing = false;
|
||||
case DTMF_DEC_RESPONSE_NONE:
|
||||
gDTMF_DecodeRingCountdown_500ms = 0;
|
||||
gDTMF_ReplyState = DTMF_REPLY_NONE;
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user