Skip to content

Commit

Permalink
Fix Alarm bypassing TX restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
JuantAldea committed Dec 5, 2023
1 parent 13b7b27 commit dcdcc1b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 72 deletions.
123 changes: 56 additions & 67 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,28 @@ VFO_Info_t *gCurrentVfo;
DCS_CodeType_t gCurrentCodeType;
VfoState_t VfoState[2];

const char gModulationStr[][4] =
{
"FM",
"AM",
"USB",
const char gModulationStr[MODULATION_UKNOWN][4] = {
[MODULATION_FM]="FM",
[MODULATION_AM]="AM",
[MODULATION_USB]="USB",

#ifdef ENABLE_BYP_RAW_DEMODULATORS
"BYP",
"RAW"
[MODULATION_BYP]="BYP",
[MODULATION_RAW]="RAW"
#endif
};

const char VfoStateStr[_VFO_STATE_LAST_ELEMENT][sizeof("TX DISABLE") + 1] = {
[VFO_STATE_NORMAL]="",
[VFO_STATE_BUSY]="BUSY",
[VFO_STATE_BAT_LOW]="BAT LOW",
[VFO_STATE_TX_DISABLE]="TX DISABLE",
[VFO_STATE_TIMEOUT]="TIMEOUT",
[VFO_STATE_ALARM]="ALARM",
[VFO_STATE_VOLTAGE_HIGH]="VOLT HIGH"
};


bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO)
{ // return true if the channel appears valid

Expand Down Expand Up @@ -977,97 +987,76 @@ void RADIO_PrepareTX(void)

RADIO_SelectCurrentVfo();

#if defined(ENABLE_ALARM) && defined(ENABLE_TX1750)
if (gAlarmState == ALARM_STATE_OFF ||
gAlarmState == ALARM_STATE_TX1750 ||
(gAlarmState == ALARM_STATE_ALARM && gEeprom.ALARM_MODE == ALARM_MODE_TONE))
#elif defined(ENABLE_ALARM)
if (gAlarmState == ALARM_STATE_OFF ||
(gAlarmState == ALARM_STATE_ALARM && gEeprom.ALARM_MODE == ALARM_MODE_TONE))
#elif defined(ENABLE_TX1750)
if (gAlarmState == ALARM_STATE_OFF ||
gAlarmState == ALARM_STATE_TX1750)
#endif
{
#ifndef ENABLE_TX_WHEN_AM
if (gCurrentVfo->Modulation != MODULATION_FM)
{ // not allowed to TX if in AM mode
State = VFO_STATE_TX_DISABLE;
}
else
#endif
if (gSerialConfigCountDown_500ms > 0)
{ // TX is disabled or config upload/download in progress
State = VFO_STATE_TX_DISABLE;
}
else
if (TX_freq_check(gCurrentVfo->pTX->Frequency) == 0)
{ // TX frequency is allowed
if (gCurrentVfo->BUSY_CHANNEL_LOCK && gCurrentFunction == FUNCTION_RECEIVE)
State = VFO_STATE_BUSY; // busy RX'ing a station
else
if (gBatteryDisplayLevel == 0)
State = VFO_STATE_BAT_LOW; // charge your battery !
else
if (gBatteryDisplayLevel > 6)
State = VFO_STATE_VOLTAGE_HIGH; // over voltage .. this is being a pain
}
else
State = VFO_STATE_TX_DISABLE; // TX frequency not allowed
if (TX_freq_check(gCurrentVfo->pTX->Frequency) != 0) {
// TX frequency not allowed
State = VFO_STATE_TX_DISABLE;
} else if (gSerialConfigCountDown_500ms > 0) {
// TX is disabled or config upload/download in progress
State = VFO_STATE_TX_DISABLE;
} else if (gCurrentVfo->BUSY_CHANNEL_LOCK && gCurrentFunction == FUNCTION_RECEIVE) {
// busy RX'ing a station
State = VFO_STATE_BUSY;
} else if (gBatteryDisplayLevel == 0) {
// charge your battery !git co
State = VFO_STATE_BAT_LOW;
} else if (gBatteryDisplayLevel > 6) {
// over voltage .. this is being a pain
State = VFO_STATE_VOLTAGE_HIGH;
}
#ifndef ENABLE_TX_WHEN_AM
else if (gCurrentVfo->Modulation == MODULATION_FM) {
// not allowed to TX if in AM mode
State = VFO_STATE_TX_DISABLE;
}
#endif

if (State != VFO_STATE_NORMAL)
{ // TX not allowed
if (State != VFO_STATE_NORMAL) {
// TX not allowed
RADIO_SetVfoState(State);

#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
gAlarmState = ALARM_STATE_OFF;
#endif
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
gAlarmState = ALARM_STATE_OFF;
#endif

#ifdef ENABLE_DTMF_CALLING
#ifdef ENABLE_DTMF_CALLING
gDTMF_ReplyState = DTMF_REPLY_NONE;
#endif
#endif
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
return;
}

// TX is allowed

#ifdef ENABLE_DTMF_CALLING
if (gDTMF_ReplyState == DTMF_REPLY_ANI)
{
if (gDTMF_CallMode == DTMF_CALL_MODE_DTMF)
{
gDTMF_IsTx = true;
gDTMF_CallState = DTMF_CALL_STATE_NONE;
#ifdef ENABLE_DTMF_CALLING
if (gDTMF_ReplyState == DTMF_REPLY_ANI) {
if (gDTMF_CallMode == DTMF_CALL_MODE_DTMF) {
gDTMF_IsTx = true;
gDTMF_CallState = DTMF_CALL_STATE_NONE;
gDTMF_TxStopCountdown_500ms = DTMF_txstop_countdown_500ms;
}
else
{
} else {
gDTMF_IsTx = false;
gDTMF_CallState = DTMF_CALL_STATE_CALL_OUT;
gDTMF_IsTx = false;
}
}
#endif
#endif

FUNCTION_Select(FUNCTION_TRANSMIT);

gTxTimerCountdown_500ms = 0; // no timeout

#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
if (gAlarmState == ALARM_STATE_OFF)
if (gAlarmState == ALARM_STATE_OFF)
#endif
{
if (gEeprom.TX_TIMEOUT_TIMER == 0)
gTxTimerCountdown_500ms = 60; // 30 sec
else
if (gEeprom.TX_TIMEOUT_TIMER < (ARRAY_SIZE(gSubMenu_TOT) - 1))
else if (gEeprom.TX_TIMEOUT_TIMER < (ARRAY_SIZE(gSubMenu_TOT) - 1))
gTxTimerCountdown_500ms = 120 * gEeprom.TX_TIMEOUT_TIMER; // minutes
else
gTxTimerCountdown_500ms = 120 * 15; // 15 minutes
}
gTxTimeoutReached = false;

gTxTimeoutReached = false;
gFlagEndTransmission = false;
gRTTECountdown = 0;

Expand Down
5 changes: 3 additions & 2 deletions radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ enum VfoState_t
VFO_STATE_TX_DISABLE,
VFO_STATE_TIMEOUT,
VFO_STATE_ALARM,
VFO_STATE_VOLTAGE_HIGH
VFO_STATE_VOLTAGE_HIGH,
_VFO_STATE_LAST_ELEMENT
};
typedef enum VfoState_t VfoState_t;

extern const char VfoStateStr[_VFO_STATE_LAST_ELEMENT][12];
typedef enum {
MODULATION_FM,
MODULATION_AM,
Expand Down
5 changes: 2 additions & 3 deletions ui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,8 @@ void UI_DisplayMain(void)

if (state != VFO_STATE_NORMAL)
{
const char *state_list[] = {"", "BUSY", "BAT LOW", "TX DISABLE", "TIMEOUT", "ALARM", "VOLT HIGH"};
if (state < ARRAY_SIZE(state_list))
UI_PrintString(state_list[state], 31, 0, line, 8);
if (state < ARRAY_SIZE(VfoStateStr))
UI_PrintString(VfoStateStr[state], 31, 0, line, 8);
}
else if (gInputBoxIndex > 0 && IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num]) && gEeprom.TX_VFO == vfo_num)
{ // user entering a frequency
Expand Down

0 comments on commit dcdcc1b

Please sign in to comment.