Test out some things
All checks were successful
Build Firmware / build (push) Successful in 22s

This commit is contained in:
2025-03-05 22:35:45 +01:00
parent 72558f93f3
commit 8dd68d74a6
18 changed files with 203 additions and 123 deletions

View File

@@ -440,7 +440,7 @@ static void ACTION_Scan_FM(bool bRestart)
static void ACTION_AlarmOr1750(const bool b1750)
{
if(gEeprom.KEY_LOCK && gEeprom.KEY_LOCK_PTT)
if(gEeprom.KEY_LOCK)
return;
#if defined(ENABLE_ALARM)

View File

@@ -970,13 +970,13 @@ void APP_Update(void) {
&& gScanStateDir == SCAN_OFF
&& !gPttIsPressed
&& gCurrentFunction != FUNCTION_POWER_SAVE
#ifdef ENABLE_VOICE
#ifdef ENABLE_VOICE
&& gVoiceWriteIndex == 0
#endif
#ifdef ENABLE_FMRADIO
#endif
#ifdef ENABLE_FMRADIO
&& !gFmRadioMode
#endif
#ifdef ENABLE_DTMF_CALLING
#endif
#ifdef ENABLE_DTMF_CALLING
&& gDTMF_CallState == DTMF_CALL_STATE_NONE
#endif
) {
@@ -1012,10 +1012,10 @@ void APP_Update(void) {
|| gScanStateDir != SCAN_OFF
|| gCssBackgroundScan
|| gScreenToDisplay != DISPLAY_MAIN
#ifdef ENABLE_FMRADIO
#ifdef ENABLE_FMRADIO
|| gFmRadioMode
#endif
#ifdef ENABLE_DTMF_CALLING
#endif
#ifdef ENABLE_DTMF_CALLING
|| gDTMF_CallState != DTMF_CALL_STATE_NONE
#endif
#ifdef ENABLE_NOAA
@@ -1395,6 +1395,10 @@ void APP_TimeSlice10ms(void) {
SCANNER_TimeSlice10ms();
if (gEnteringSMS == SMS_NOT_ENTERING) {
MSG_FSKReceiveData();
}
#ifdef ENABLE_AIRCOPY
if (gScreenToDisplay == DISPLAY_AIRCOPY && gAircopyState == AIRCOPY_TRANSFER && gAirCopyIsSendMode == 1) {
if (!AIRCOPY_SendMessage()) {
@@ -1818,8 +1822,8 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
bool lowBatPopup = gLowBattery && !gLowBatteryConfirmed && gScreenToDisplay == DISPLAY_MAIN;
if ((gEeprom.KEY_LOCK || lowBatPopup) && gCurrentFunction != FUNCTION_TRANSMIT)
{ // keyboard is locked or low battery popup
if ((gEeprom.KEY_LOCK || lowBatPopup) &&
gCurrentFunction != FUNCTION_TRANSMIT) { // keyboard is locked or low battery popup
// close low battery popup
if (Key == KEY_EXIT && bKeyPressed && lowBatPopup) {

View File

@@ -98,6 +98,88 @@ void MSG_ConfigureFSK(bool rx) {
}
uint16_t calculateCRC(uint8_t *data, size_t length) {
uint16_t crc = 0xFFFF; // Example CRC-16 initialization
for (size_t i = 0; i < length; i++) {
crc ^= data[i];
for (uint8_t j = 0; j < 8; j++) {
if (crc & 1) {
crc = (crc >> 1) ^ 0xA001; // Example polynomial (CRC-16-IBM)
} else {
crc >>= 1;
}
}
}
return crc;
}
void processReceivedPacket(DataPacket *packet) {
char String[31 + DataPacketDataSize];
char numBuf[11]; // Enough for any 64-bit unsigned integer
const unsigned int vfo = (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? gEeprom.RX_VFO
: gEeprom.TX_VFO;
if (dataPacket.dest == gEeprom.FSKSRCAddress) {
BK4819_PlaySingleTone(1000, 250, 127, true);
strcpy(String, "SMS by ");
itoa(packet->src, numBuf); // Convert number to string
strcat(String, numBuf);
strcat(String, ": ");
strcat(String, (char *)packet->data);
UI_DisplayPopup(String);
#ifdef ENABLE_FEAT_F4HWN
if (isMainOnly()) {
UI_PrintStringSmallNormal(String, 2, 0, 5);
} else {
UI_PrintStringSmallNormal(String, 2, 0, 3);
}
#else
UI_PrintStringSmallNormal(String, 2, 0, 3);
#endif
} else if (VfoState[vfo] == VFO_STATE_NORMAL && !TX_freq_check(gCurrentVfo->freq_config_TX.Frequency)) {
if (packet->ttl--) {
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, true);
MSG_FSKSendData(packet);
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
}
}
memset(packet, 0, DataPacketDataSize); // Clear data after processing (example action)
}
bool MSG_FSKReceiveData() {
if (!(BK4819_ReadRegister(BK4819_REG_0C) & (1U << 1))) {
return false; // No data available
}
// Read the received data from FIFO
uint16_t *ptr = (uint16_t *) &inBoundPacket;
size_t wordCount = sizeof(inBoundPacket) / sizeof(uint16_t);
for (size_t i = 0; i < wordCount; i++) {
ptr[i] = BK4819_ReadRegister(BK4819_REG_5F);
}
// Clear the RX interrupt flag
BK4819_WriteRegister(BK4819_REG_02, 0);
// Validate checksum (assuming last 2 bytes are CRC-16)
size_t dataLength = sizeof(inBoundPacket.data) - 2;
uint16_t receivedCRC = (inBoundPacket.data[dataLength] << 8) | inBoundPacket.data[dataLength + 1];
uint16_t calculatedCRC = calculateCRC(inBoundPacket.data, dataLength);
if (receivedCRC == calculatedCRC) {
processReceivedPacket(&inBoundPacket);
return true;
}
return false; // CRC check failed
}
void MSG_EnableRX(const bool enable) {
if (enable) {
@@ -111,8 +193,14 @@ void MSG_EnableRX(const bool enable) {
}
}
void MSG_FSKSendData() {
void MSG_FSKSendData(DataPacket *dataPacketIn) {
bool isAudioOn = gEnableSpeaker;
if (gEnableSpeaker) {
AUDIO_AudioPathOff();
BK4819_EnterTxMute();
gEnableSpeaker = false;
}
// turn off CTCSS/CDCSS during FFSK
const uint16_t css_val = BK4819_ReadRegister(BK4819_REG_51);
BK4819_WriteRegister(BK4819_REG_51, 0);
@@ -163,8 +251,8 @@ void MSG_FSKSendData() {
SYSTEM_DelayMs(100);
{ // load the entire packet data into the TX FIFO buffer
uint16_t *ptr = (uint16_t *) &dataPacket;
size_t wordCount = sizeof(dataPacket) / sizeof(uint16_t);
uint16_t *ptr = (uint16_t *) dataPacketIn;
size_t wordCount = sizeof(*dataPacketIn) / sizeof(uint16_t);
for (size_t i = 0; i < wordCount; i++) {
BK4819_WriteRegister(BK4819_REG_5F, ptr[i]);
@@ -211,9 +299,16 @@ void MSG_FSKSendData() {
gUpdateDisplay = true;
gFlagEndTransmission = false;
if (isAudioOn) {
AUDIO_AudioPathOn();
gEnableSpeaker = true;
BK4819_ExitTxMute();
}
}
void prepareDataPacket() {
dataPacket.src = gEeprom.FSKSRCAddress;
dataPacket.seq = seq++;
dataPacket.ttl = 20;
}

View File

@@ -14,6 +14,11 @@
#include "../driver/system.h"
#include "../misc.h"
#include "../app/app.h"
#include <string.h>
#include "../audio.h"
#include <stdio.h>
#include "../ui/helper.h"
#include "../ui/main.h"
// REG_70 bit definitions
#define TONE1_ENABLE_BIT (1U << 15)
@@ -73,22 +78,27 @@
#define FSK_CRC_ON (1U << 6)
#define FSK_CRC_OFF (0U << 6)
#define DataPacketDataSize (36)
#define DataPacketDataSize (35)
typedef struct {
uint32_t dest;
uint32_t src;
uint8_t seq;
uint8_t ttl;
uint8_t flags;
uint8_t data[DataPacketDataSize];
} DataPacket;
void prepareDataPacket();
void MSG_FSKSendData();
void MSG_FSKSendData(DataPacket *dataPacketIn);
void MSG_EnableRX(bool enable);
void processReceivedPacket(DataPacket *packet);
uint16_t calculateCRC(uint8_t *data, size_t length);
bool MSG_FSKReceiveData();
extern DataPacket dataPacket;
extern DataPacket inBoundPacket;

View File

@@ -968,19 +968,15 @@ void MAIN_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
const unsigned int vfo = (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? gEeprom.RX_VFO
: gEeprom.TX_VFO;
if (VfoState[vfo] == VFO_STATE_NORMAL && !TX_freq_check(gCurrentVfo->freq_config_TX.Frequency)) {
AUDIO_AudioPathOff();
gEnableSpeaker = false;
RADIO_PrepareTX();
if (gCurrentVfo->SCRAMBLING_TYPE > 0)
BK4819_EnableScramble(gCurrentVfo->SCRAMBLING_TYPE - 1);
else
BK4819_DisableScramble();
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, true);
MSG_FSKSendData();
MSG_FSKSendData(&dataPacket);
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
AUDIO_AudioPathOn();
gEnableSpeaker = true;
BK4819_ExitTxMute();
MSG_EnableRX(true);
gVfoConfigureMode = VFO_CONFIGURE;
dataPTR = dataPacket.data;

View File

@@ -390,12 +390,6 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) {
//*pMin = 0;
*pMax = ARRAY_SIZE(gSubMenu_SET_TOT) - 1;
break;
#ifdef ENABLE_FEAT_F4HWN_CTR
case MENU_SET_CTR:
*pMin = 1;
*pMax = 15;
break;
#endif
#ifdef ENABLE_FEAT_F4HWN_INV
case MENU_SET_INV:
//*pMin = 0;
@@ -855,17 +849,9 @@ void MENU_AcceptSetting(void) {
case MENU_SET_EOT:
gSetting_set_eot = gSubMenuSelection;
break;
#ifdef ENABLE_FEAT_F4HWN_CTR
case MENU_SET_CTR:
gSetting_set_ctr = gSubMenuSelection;
break;
#endif
case MENU_SET_INV:
gSetting_set_inv = gSubMenuSelection;
break;
case MENU_SET_LCK:
gSetting_set_lck = gSubMenuSelection;
break;
#ifdef ENABLE_FEAT_F4HWN_NARROWER
case MENU_SET_NFM:
gSetting_set_nfm = gSubMenuSelection;
@@ -1262,17 +1248,9 @@ void MENU_ShowCurrentSetting(void) {
case MENU_SET_EOT:
gSubMenuSelection = gSetting_set_eot;
break;
#ifdef ENABLE_FEAT_F4HWN_CTR
case MENU_SET_CTR:
gSubMenuSelection = gSetting_set_ctr;
break;
#endif
case MENU_SET_INV:
gSubMenuSelection = gSetting_set_inv;
break;
case MENU_SET_LCK:
gSubMenuSelection = gSetting_set_lck;
break;
#ifdef ENABLE_FEAT_F4HWN_NARROWER
case MENU_SET_NFM:
gSubMenuSelection = gSetting_set_nfm;

View File

@@ -856,7 +856,7 @@ static void ShowChannelName(uint32_t f) {
#endif
static void DrawF(uint32_t f) {
sprintf(String, "%u.%05u", f / 100000, f % 100000);
sprintf(String, "%lu.%05lu", f / 100000, f % 100000);
UI_PrintStringSmallNormal(String, 8, 127, 0);
sprintf(String, "%3s", gModulationStr[settings.modulationType]);
@@ -879,19 +879,19 @@ static void DrawNums() {
}
if (IsCenterMode()) {
sprintf(String, "%u.%05u \x7F%u.%02uk", currentFreq / 100000,
sprintf(String, "%lu.%05lu \x7F%lu.%02luk", currentFreq / 100000,
currentFreq % 100000, settings.frequencyChangeStep / 100,
settings.frequencyChangeStep % 100);
GUI_DisplaySmallest(String, 36, 39, false, true);
} else {
sprintf(String, "%u.%05u", GetFStart() / 100000, GetFStart() % 100000);
sprintf(String, "%lu.%05lu", GetFStart() / 100000, GetFStart() % 100000);
GUI_DisplaySmallest(String, 0, 49, false, true);
sprintf(String, "\x7F%u.%02uk", settings.frequencyChangeStep / 100,
sprintf(String, "\x7F%lu.%02luk", settings.frequencyChangeStep / 100,
settings.frequencyChangeStep % 100);
GUI_DisplaySmallest(String, 48, 10, false, true);
sprintf(String, "%u.%05u", GetFEnd() / 100000, GetFEnd() % 100000);
sprintf(String, "%lu.%05lu", GetFEnd() / 100000, GetFEnd() % 100000);
GUI_DisplaySmallest(String, 93, 49, false, true);
}
}