2023-08-11 03:37:33 +08:00
|
|
|
/* Copyright 2023 Dual Tachyon
|
|
|
|
* https://github.com/DualTachyon
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-08-14 06:27:35 +08:00
|
|
|
#include <string.h>
|
2023-08-11 00:51:57 +08:00
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
const uint32_t *gUpperLimitFrequencyBandTable;
|
|
|
|
const uint32_t *gLowerLimitFrequencyBandTable;
|
|
|
|
|
|
|
|
bool gSetting_350TX;
|
|
|
|
bool gSetting_KILLED;
|
|
|
|
bool gSetting_200TX;
|
|
|
|
bool gSetting_500TX;
|
|
|
|
bool gSetting_350EN;
|
2023-08-15 05:26:27 +08:00
|
|
|
uint8_t gSetting_F_LOCK;
|
2023-08-11 00:51:57 +08:00
|
|
|
bool gSetting_ScrambleEnable;
|
|
|
|
uint8_t gSetting_F_LOCK;
|
|
|
|
|
2023-08-11 21:06:33 +08:00
|
|
|
uint32_t gCustomPasswordKey[4];
|
2023-08-11 00:51:57 +08:00
|
|
|
|
|
|
|
bool bIsCheckExistingPassword;
|
|
|
|
|
|
|
|
uint8_t gEEPROM_1EC0_0[8];
|
|
|
|
uint8_t gEEPROM_1EC0_1[8];
|
|
|
|
uint8_t gEEPROM_1EC0_2[8];
|
|
|
|
uint8_t gEEPROM_1EC0_3[8];
|
|
|
|
|
2023-08-26 19:13:18 +08:00
|
|
|
uint16_t gEEPROM_RSSI_CALIB[3][4];
|
2023-08-11 00:51:57 +08:00
|
|
|
|
|
|
|
uint16_t gEEPROM_1F8A;
|
|
|
|
uint16_t gEEPROM_1F8C;
|
|
|
|
|
2023-08-28 19:05:15 +08:00
|
|
|
uint8_t gMR_ChannelAttributes[207];
|
2023-08-11 00:51:57 +08:00
|
|
|
|
2023-08-16 05:39:26 +08:00
|
|
|
volatile bool gNextTimeslice500ms;
|
2023-08-29 20:26:13 +08:00
|
|
|
volatile uint16_t gBatterySaveCountdown;
|
2023-08-15 06:38:59 +08:00
|
|
|
volatile uint16_t g_2000033A;
|
2023-08-16 05:39:26 +08:00
|
|
|
volatile uint16_t gTxTimerCountdown = 1000;
|
2023-08-15 06:38:59 +08:00
|
|
|
volatile uint16_t g_20000342;
|
2023-08-29 20:26:13 +08:00
|
|
|
volatile uint16_t gFmPlayCountdown = 1;
|
2023-08-15 06:38:59 +08:00
|
|
|
volatile uint16_t g_20000356;
|
2023-08-16 02:02:42 +08:00
|
|
|
uint16_t g_20000362;
|
2023-08-11 22:41:23 +08:00
|
|
|
uint8_t g_2000036B;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint8_t gKeyLockCountdown;
|
2023-08-27 22:01:47 +08:00
|
|
|
uint8_t gRTTECountdown;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t g_2000036E;
|
2023-08-30 07:19:12 +08:00
|
|
|
uint8_t gUpdateStatus;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t g_20000370;
|
2023-08-15 05:26:27 +08:00
|
|
|
uint8_t g_20000371[2];
|
|
|
|
uint8_t g_20000373;
|
2023-08-30 20:21:07 +08:00
|
|
|
uint8_t gFoundCTCSS;
|
|
|
|
uint8_t gFoundCDCSS;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t g_20000377;
|
2023-08-15 21:24:40 +08:00
|
|
|
uint8_t gVFO_RSSI_Level[2];
|
2023-08-31 01:06:08 +08:00
|
|
|
uint8_t gReducedService;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint8_t gBatteryVoltageIndex;
|
2023-08-15 06:38:59 +08:00
|
|
|
volatile uint8_t g_20000381;
|
2023-08-16 02:02:42 +08:00
|
|
|
uint8_t g_20000382;
|
2023-08-15 00:30:30 +08:00
|
|
|
uint8_t g_20000383;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint16_t g_2000038E;
|
2023-08-29 07:37:06 +08:00
|
|
|
volatile int8_t gFM_Step;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint8_t g_20000393;
|
|
|
|
bool g_20000394;
|
2023-08-28 02:52:32 +08:00
|
|
|
uint8_t g_20000395;
|
2023-08-24 20:55:40 +08:00
|
|
|
uint8_t gKeypadLocked;
|
2023-08-27 22:01:47 +08:00
|
|
|
uint8_t g_20000395;
|
|
|
|
uint8_t g_20000396;
|
2023-08-27 19:32:21 +08:00
|
|
|
uint8_t g_20000398;
|
2023-08-31 20:47:25 +08:00
|
|
|
uint8_t gVfoConfigureMode;
|
2023-08-27 22:01:47 +08:00
|
|
|
uint8_t g_2000039B;
|
2023-08-28 06:17:44 +08:00
|
|
|
bool gRequestSaveVFO;
|
2023-08-29 08:21:33 +08:00
|
|
|
uint8_t gRequestSaveChannel;
|
2023-08-28 06:30:42 +08:00
|
|
|
bool gRequestSaveSettings;
|
2023-08-28 06:17:44 +08:00
|
|
|
bool gRequestSaveFM;
|
2023-08-27 19:46:40 +08:00
|
|
|
uint8_t g_200003A0;
|
2023-08-28 06:01:40 +08:00
|
|
|
bool gFlagStartScan;
|
2023-08-28 06:30:42 +08:00
|
|
|
bool gFlagStopScan;
|
2023-08-28 02:52:32 +08:00
|
|
|
bool gFlagAcceptSetting;
|
2023-08-28 03:47:55 +08:00
|
|
|
bool gFlagRefreshSetting;
|
2023-08-28 02:52:32 +08:00
|
|
|
bool gFlagSaveVfo;
|
2023-08-26 21:29:19 +08:00
|
|
|
bool gFlagSaveSettings;
|
2023-08-28 06:17:44 +08:00
|
|
|
uint8_t gFlagSaveChannel;
|
2023-08-26 21:29:19 +08:00
|
|
|
bool gFlagSaveFM;
|
2023-08-31 21:22:08 +08:00
|
|
|
uint8_t gDTMF_RequestPending;
|
2023-08-16 06:46:09 +08:00
|
|
|
bool g_CDCSS_Lost;
|
2023-08-30 20:21:07 +08:00
|
|
|
uint8_t gCDCSSCodeType;
|
2023-08-16 06:46:09 +08:00
|
|
|
bool g_CTCSS_Lost;
|
|
|
|
bool g_CxCSS_TAIL_Found;
|
|
|
|
bool g_VOX_Lost;
|
2023-08-26 19:41:11 +08:00
|
|
|
bool g_SquelchLost;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint8_t gFlashLightState;
|
2023-08-27 22:01:47 +08:00
|
|
|
uint8_t g_200003B4;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint16_t g_200003B6;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint16_t g_200003B8;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t g_200003BC;
|
2023-08-15 05:26:27 +08:00
|
|
|
uint8_t g_200003BD;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t g_200003BE;
|
2023-08-27 22:01:47 +08:00
|
|
|
uint8_t g_200003C0;
|
2023-08-15 05:26:27 +08:00
|
|
|
uint8_t g_200003C3;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint16_t g_200003E2;
|
|
|
|
volatile uint16_t gFlashLightBlinkCounter;
|
2023-08-15 05:26:27 +08:00
|
|
|
uint8_t g_200003FD;
|
2023-08-31 00:59:16 +08:00
|
|
|
uint8_t gLowBatteryCountdown;
|
2023-08-15 21:24:40 +08:00
|
|
|
uint8_t g_20000410;
|
|
|
|
uint8_t g_20000411;
|
2023-08-16 02:02:42 +08:00
|
|
|
uint8_t g_20000413;
|
2023-08-27 08:07:11 +08:00
|
|
|
uint8_t g_20000414;
|
2023-08-16 02:02:42 +08:00
|
|
|
uint8_t g_20000415;
|
|
|
|
uint8_t g_20000416;
|
2023-08-27 08:07:11 +08:00
|
|
|
uint32_t g_20000418;
|
2023-08-15 05:26:27 +08:00
|
|
|
uint8_t g_2000041F;
|
2023-08-15 00:30:30 +08:00
|
|
|
uint8_t g_20000420;
|
2023-08-27 19:46:40 +08:00
|
|
|
uint16_t g_20000422;
|
2023-08-16 02:02:42 +08:00
|
|
|
uint8_t g_20000427;
|
2023-08-26 08:47:17 +08:00
|
|
|
bool gKeyBeingHeld;
|
|
|
|
bool gPttIsPressed;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint8_t gPttDebounceCounter;
|
2023-08-15 00:30:30 +08:00
|
|
|
uint8_t g_20000438;
|
2023-08-27 01:31:27 +08:00
|
|
|
bool g_20000439;
|
2023-08-22 06:47:16 +08:00
|
|
|
uint8_t gMenuListCount;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint8_t g_20000442;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t g_20000458;
|
2023-08-29 23:02:35 +08:00
|
|
|
uint8_t gBackupCROSS_BAND_RX_TX;
|
2023-08-26 08:46:21 +08:00
|
|
|
uint8_t g_CxCSS_Type;
|
|
|
|
uint8_t g_CxCSS_Index;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t g_2000045C;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint8_t g_2000045D;
|
|
|
|
uint8_t g_2000045F;
|
2023-08-29 23:02:35 +08:00
|
|
|
uint8_t gScannerEditState;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t g_20000464;
|
2023-08-26 18:20:06 +08:00
|
|
|
uint8_t gAircopySendCountdown;
|
|
|
|
uint8_t gFSKWriteIndex;
|
2023-08-16 02:02:42 +08:00
|
|
|
uint8_t g_20000474;
|
2023-08-14 05:40:33 +08:00
|
|
|
|
2023-08-30 05:55:07 +08:00
|
|
|
bool gFM_AutoScan;
|
2023-08-11 22:41:23 +08:00
|
|
|
bool gIsNoaaMode;
|
2023-08-15 18:14:43 +08:00
|
|
|
volatile bool gNextTimeslice;
|
2023-08-16 02:02:42 +08:00
|
|
|
uint8_t gNoaaChannel;
|
2023-08-14 19:28:09 +08:00
|
|
|
bool gUpdateDisplay;
|
2023-08-26 18:14:43 +08:00
|
|
|
uint8_t gFmRadioCountdown;
|
2023-08-31 07:05:25 +08:00
|
|
|
uint8_t gFM_ChannelPosition;
|
2023-08-28 02:52:32 +08:00
|
|
|
bool gF_LOCK;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t gScanChannel;
|
|
|
|
uint32_t gScanFrequency;
|
2023-08-15 21:24:40 +08:00
|
|
|
uint8_t gScanPauseMode;
|
2023-08-14 19:28:09 +08:00
|
|
|
uint8_t gScanState;
|
|
|
|
uint8_t gShowChPrefix;
|
2023-08-15 06:38:59 +08:00
|
|
|
volatile uint16_t gSystickCountdown2;
|
2023-08-30 20:21:07 +08:00
|
|
|
volatile uint8_t gFoundCDCSSCountdown;
|
|
|
|
volatile uint8_t gFoundCTCSSCountdown;
|
2023-08-15 06:38:59 +08:00
|
|
|
volatile uint16_t gSystickCountdown11;
|
2023-08-29 20:26:13 +08:00
|
|
|
volatile bool gTxTimeoutReached;
|
2023-08-16 05:39:26 +08:00
|
|
|
volatile bool gNextTimeslice40ms;
|
2023-08-29 20:26:13 +08:00
|
|
|
volatile bool gSchedulePowerSave;
|
2023-08-15 18:14:43 +08:00
|
|
|
volatile bool gBatterySaveCountdownExpired;
|
2023-08-15 06:38:59 +08:00
|
|
|
volatile bool gSystickFlag7;
|
|
|
|
volatile bool gSystickFlag8;
|
|
|
|
volatile bool gSystickFlag9;
|
|
|
|
volatile bool gSystickFlag10;
|
2023-08-29 20:26:13 +08:00
|
|
|
volatile bool gScheduleFM;
|
2023-08-15 06:38:59 +08:00
|
|
|
|
|
|
|
volatile uint16_t ScanPauseDelayIn10msec;
|
2023-08-14 05:40:33 +08:00
|
|
|
|
2023-08-27 19:28:30 +08:00
|
|
|
// Doubts about whether this should be signed or not.
|
|
|
|
int16_t gFM_FrequencyDeviation;
|
2023-08-16 06:46:09 +08:00
|
|
|
|
|
|
|
uint16_t gCurrentRSSI;
|
|
|
|
|
2023-08-29 03:13:33 +08:00
|
|
|
volatile int8_t gStepDirection;
|
|
|
|
|
2023-08-14 19:28:09 +08:00
|
|
|
// --------
|
2023-08-14 06:27:35 +08:00
|
|
|
|
2023-08-14 19:28:09 +08:00
|
|
|
void NUMBER_Get(char *pDigits, uint32_t *pInteger)
|
2023-08-14 06:27:35 +08:00
|
|
|
{
|
|
|
|
uint32_t Value;
|
|
|
|
uint32_t Multiplier;
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
Multiplier = 10000000;
|
|
|
|
Value = 0;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (pDigits[i] > 9) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Value += pDigits[i] * Multiplier;
|
|
|
|
Multiplier /= 10U;
|
|
|
|
}
|
|
|
|
*pInteger = Value;
|
|
|
|
}
|
|
|
|
|
2023-08-14 19:28:09 +08:00
|
|
|
void NUMBER_ToDigits(uint32_t Value, char *pDigits)
|
|
|
|
{
|
|
|
|
uint8_t i;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
uint32_t Result = Value / 10U;
|
|
|
|
|
|
|
|
pDigits[7 - i] = Value - (Result * 10U);
|
|
|
|
Value = Result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-28 01:04:19 +08:00
|
|
|
uint8_t NUMBER_AddWithWraparound(uint8_t Base, int8_t Add, uint8_t LowerLimit, uint8_t UpperLimit)
|
|
|
|
{
|
|
|
|
Base += Add;
|
|
|
|
if (Base == 0xFF || Base < LowerLimit) {
|
|
|
|
return UpperLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Base > UpperLimit) {
|
|
|
|
return LowerLimit;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Base;
|
|
|
|
}
|
|
|
|
|