Try out the fsk
All checks were successful
Build Firmware / build (push) Successful in 2m30s

This commit is contained in:
2025-03-31 21:53:23 +02:00
parent 101bde7463
commit f1904e03fe
16 changed files with 446 additions and 246 deletions

View File

@@ -91,6 +91,7 @@
#include "ui/menu.h"
#include "ui/status.h"
#include "ui/ui.h"
#include "messages.h"
static bool flagSaveVfo;
static bool flagSaveSettings;
@@ -760,6 +761,7 @@ static void CheckRadioInterrupts(void) {
}
#endif
}
FSK_HANDLE_IRQ(interrupts.__raw);
}
}

View File

@@ -3,7 +3,9 @@
//
#include "fskmodem.h"
#include "eeprom.h"
//#include "messages.h"
#include "driver/uart.h"
#include "../ui/messages.h"
uint16_t TONE2_FREQ;
@@ -15,6 +17,13 @@ uint8_t *dataPTR = dataPacket.data;
SMSEnteringState gEnteringSMS = SMS_NOT_ENTERING;
typedef enum {
Receiving,
Ready
} RXState;
RXState rxState = Ready;
void MSG_ConfigureFSK(bool rx) {
BK4819_WriteRegister(BK4819_REG_70, TONE2_ENABLE_BIT | (96U << 0));
@@ -115,25 +124,25 @@ uint16_t calculateCRC(uint8_t *data, size_t length) {
void processReceivedPacket(DataPacket *packet) {
char String[31 + DataPacketDataSize];
char String[18];
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) {
if (packet->dest == gEeprom.FSKSRCAddress) {
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP);
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);
MESSAGES_SAVE();
UI_DisplayPopup(String);
#ifdef ENABLE_FEAT_F4HWN
if (isMainOnly()) {
UI_PrintStringSmallNormal(String, 2, 0, 5);
} else {
UI_PrintStringSmallNormal(String, 2, 0, 3);
}
UI_PrintStringSmallNormal(String, 2, 0, 5);
} else {
UI_PrintStringSmallNormal(String, 2, 0, 3);
}
#else
UI_PrintStringSmallNormal(String, 2, 0, 3);
@@ -147,7 +156,7 @@ void processReceivedPacket(DataPacket *packet) {
}
}
memset(packet, 0, DataPacketDataSize); // Clear data after processing (example action)
memset(packet, 0, sizeof(DataPacket)); // Clear data after processing (example action)
}
@@ -315,4 +324,65 @@ void prepareDataPacket() {
Data[0]++;
EEPROM_WriteBuffer(SEQParameterEEPROM, Data);
dataPacket.ttl = 20;
}
void FSK_HANDLE_IRQ(unsigned short irq) {
//const uint16_t rx_sync_flags = BK4819_ReadRegister(BK4819_REG_0B);
const bool rx_sync = (irq & BK4819_REG_02_FSK_RX_SYNC) != 0;
const bool rx_fifo_almost_full = (irq & BK4819_REG_02_FSK_FIFO_ALMOST_FULL) != 0;
const bool rx_finished = (irq & BK4819_REG_02_FSK_RX_FINISHED) != 0;
//UART_printf("\nMSG : S%i, F%i, E%i | %i", rx_sync, rx_fifo_almost_full, rx_finished, irq);
if (rx_sync) {
// prevent listening to fsk data and squelch (kamilsss655)
// CTCSS codes seem to false trigger the rx_sync
if (gCurrentCodeType == CODE_TYPE_OFF)
AUDIO_AudioPathOff();
gFSKWriteIndex = 0;
memset(&inBoundPacket, 0, sizeof(DataPacket));
rxState = Receiving;
UART_String("Sync\n");
}
if (rx_fifo_almost_full && rxState == Receiving) {
const uint16_t count = BK4819_ReadRegister(BK4819_REG_5E) & (7u << 0); // Almost full threshold
uint16_t *ptr = (uint16_t *) &inBoundPacket;
size_t wordCount = sizeof(inBoundPacket) / sizeof(uint16_t);
for (uint16_t i = 0; i < count && gFSKWriteIndex < wordCount; i++) {
ptr[gFSKWriteIndex++] = BK4819_ReadRegister(BK4819_REG_5F);
UART_Send((const void *) &ptr[gFSKWriteIndex - 1], 2);
}
SYSTEM_DelayMs(10);
}
if (rx_finished) {
// Turn off green LED
BK4819_FskClearFifo();
rxState = Ready;
UART_String("FSK end\n");
if (gFSKWriteIndex > 2) {
// 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);
//}
}
APP_EndTransmission();
FUNCTION_Select(FUNCTION_FOREGROUND);
gUpdateStatus = true;
gUpdateDisplay = true;
gFlagEndTransmission = false;
gFSKWriteIndex = 0;
}
}

View File

@@ -78,16 +78,16 @@
#define FSK_CRC_ON (1U << 6)
#define FSK_CRC_OFF (0U << 6)
#define DataPacketDataSize (35)
#define DataPacketDataSize (37)
#define SEQParameterEEPROM 0x1BD0;
#define SEQParameterEEPROM 0x1BD0
typedef struct {
uint32_t dest;
uint32_t src;
uint8_t seq;
uint8_t ttl;
uint8_t flags;
uint32_t dest; //4bytes
uint32_t src; //4bytes
uint8_t seq; //1bytes
uint8_t ttl; //1bytes
uint8_t flags; //1bytes
uint8_t data[DataPacketDataSize];
} DataPacket;
@@ -115,4 +115,6 @@ extern SMSEnteringState gEnteringSMS;
extern uint8_t *dataPTR;
void FSK_HANDLE_IRQ(unsigned short irq);
#endif //UV_K5_FIRMWARE_CUSTOM_FSKMODEM_H

View File

@@ -49,21 +49,6 @@
#include "ui/ui.h"
#include <stdlib.h>
#define T9Count 9
const char T9Table[10][T9Count] = {
{'#', '(', ')', ';', ':', '<', '>', '/', '0'},
{',', '.', '?', '&', '!', ' ', '-', '_', '1'},
{'a', 'b', 'c', 'A', 'B', 'C', '[', ']', '2'},
{'d', 'e', 'f', 'D', 'E', 'F', '@', '%', '3'},
{'g', 'h', 'i', 'G', 'H', 'I', '~', '$', '4'},
{'j', 'k', 'l', 'J', 'K', 'L', '|', '*', '5'},
{'m', 'n', 'o', 'M', 'N', 'O', '{', '}', '6'},
{'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S', '7'},
{'t', 'u', 'v', 'T', 'U', 'V', '"', '\'', '8'},
{'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z', '9'}
};
static void toggle_chan_scanlist(void) { // toggle the selected channels scanlist setting
if (SCANNER_IsScanning())
@@ -691,6 +676,11 @@ static void MAIN_Key_MENU(bool bKeyPressed, bool bKeyHeld) {
return;
}
if (gWasFKeyPressed && bKeyPressed) {
gRequestDisplayScreen = DISPLAY_MESSAGES;
return;
}
if (!bKeyPressed && !gDTMF_InputMode) { // menu key released
const bool bFlag = !gInputBoxIndex;
gInputBoxIndex = 0;
@@ -906,11 +896,6 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
gPttWasReleased = true;
}
void updatePrevChar(KEY_Code_t Key) {
if (Key != prevKey) {
prevKey = Key;
}
}
void MAIN_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
#ifdef ENABLE_FMRADIO
@@ -939,101 +924,6 @@ void MAIN_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
// Key = KEY_SIDE2; // what's this doing ???
// }
if (Key == KEY_9 && bKeyHeld) {
if (bKeyPressed) {
if (gEnteringSMS == SMS_NOT_ENTERING) {
gEnteringSMS = SMS_ENTERING_DEST;
updatePrevChar(Key);
return;
}
}
}
if (Key == KEY_MENU) {
if (gEnteringSMS == SMS_ENTERING_DEST) {
if (bKeyPressed) {
memset(dataPacket.data, 0, DataPacketDataSize);
prepareDataPacket();
dataPacket.flags = 126;
gEnteringSMS = SMS_ENTERING_MESSAGE;
}
return;
}
if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
if (bKeyPressed) {
if (strlen((char *) dataPacket.data)) {
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)) {
RADIO_PrepareTX();
BK4819_SetScramble(gCurrentVfo->SCRAMBLING_TYPE);
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, true);
MSG_FSKSendData(&dataPacket);
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
//MSG_EnableRX(true);
gVfoConfigureMode = VFO_CONFIGURE;
dataPTR = dataPacket.data;
memset(dataPacket.data, 0, DataPacketDataSize);
}
gEnteringSMS = SMS_NOT_ENTERING;
}
}
return;
}
}
if (Key == KEY_EXIT && gEnteringSMS != SMS_NOT_ENTERING) {
if (bKeyHeld) {
if (bKeyPressed) {
gEnteringSMS = SMS_NOT_ENTERING;
dataPTR = dataPacket.data;
memset(dataPacket.data, 0, DataPacketDataSize);
}
} else {
if (bKeyPressed) {
if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
if (dataPacket.data <= dataPTR) {
*dataPTR = '\0';
if (dataPacket.data < dataPTR) {
dataPTR--;
}
*dataPTR = '\0';
}
} else if (gEnteringSMS == SMS_ENTERING_DEST) {
dataPacket.dest /= 10;
}
}
}
updatePrevChar(Key);
return;
}
if (gEnteringSMS != SMS_NOT_ENTERING && !bKeyHeld) {
if (!dataPTR) {
dataPTR = dataPacket.data;
}
if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
if (bKeyPressed) {
if (prevKey != Key) {
dataPTR++;
if (dataPTR - dataPacket.data >= DataPacketDataSize) {
dataPTR = dataPacket.data;
}
prevLetter = 0;
}
*(dataPTR - 1) = T9Table[Key][(prevLetter++) % T9Count];
updatePrevChar(Key);
}
return;
} else if (gEnteringSMS == SMS_ENTERING_DEST) {
if (bKeyPressed) {
dataPacket.dest *= 10;
dataPacket.dest += Key;
prevLetter = 0;
}
return;
}
}
switch (Key) {
#ifdef ENABLE_FEAT_F4HWN
case KEY_SIDE1:

View File

@@ -3,3 +3,187 @@
//
#include "messages.h"
#include "ui/ui.h"
#include "driver/uart.h"
#define T9Count 9
const char T9Table[10][T9Count] = {
{'#', '(', ')', ';', ':', '<', '>', '/', '0'},
{',', '.', '?', '&', '!', ' ', '-', '_', '1'},
{'a', 'b', 'c', 'A', 'B', 'C', '[', ']', '2'},
{'d', 'e', 'f', 'D', 'E', 'F', '@', '%', '3'},
{'g', 'h', 'i', 'G', 'H', 'I', '~', '$', '4'},
{'j', 'k', 'l', 'J', 'K', 'L', '|', '*', '5'},
{'m', 'n', 'o', 'M', 'N', 'O', '{', '}', '6'},
{'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S', '7'},
{'t', 'u', 'v', 'T', 'U', 'V', '"', '\'', '8'},
{'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z', '9'}
};
uint8_t gActiveMessage = 0;
StoredPacket loadedPacket;
void MESSAGES_SAVE() {
uint8_t Data[8];
EEPROM_ReadBuffer(SEQParameterEEPROM, Data, 8);
uint8_t msgIndex = Data[1];
if (msgIndex >= MESSAGES_COUNT) {
msgIndex = 0;
}
Data[1]++;
EEPROM_WriteBuffer(SEQParameterEEPROM, Data);
EEPROM_WriteBuffer(MESSAGES_START + (msgIndex * sizeof(StoredPacket)) + 0,
(uint8_t *) &inBoundPacket + 4); // metadata
EEPROM_WriteBuffer(MESSAGES_START + (msgIndex * sizeof(StoredPacket)) + 8,
(uint8_t *) &inBoundPacket + 12); // message part 1
EEPROM_WriteBuffer(MESSAGES_START + (msgIndex * sizeof(StoredPacket)) + 16,
(uint8_t *) &inBoundPacket + 20); // message part 2
EEPROM_WriteBuffer(MESSAGES_START + (msgIndex * sizeof(StoredPacket)) + 24,
(uint8_t *) &inBoundPacket + 28); // message part 3
EEPROM_WriteBuffer(MESSAGES_START + (msgIndex * sizeof(StoredPacket)) + 32,
(uint8_t *) &inBoundPacket + 36); // message part 4
}
void MESSAGES_GET() {
EEPROM_ReadBuffer(MESSAGES_START + (gActiveMessage * sizeof(StoredPacket)), &loadedPacket, sizeof(StoredPacket));
}
void MESSAGES_DELETE() {
}
void updatePrevChar(KEY_Code_t Key) {
if (Key != prevKey) {
prevKey = Key;
}
}
void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
if (gEnteringSMS != SMS_NOT_ENTERING && !bKeyHeld && Key <= KEY_9) {
if (!dataPTR || dataPTR < dataPacket.data) {
dataPTR = dataPacket.data;
}
if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
if (bKeyPressed) {
if (prevKey != Key) {
dataPTR++;
if (dataPTR - dataPacket.data >= DataPacketDataSize) {
dataPTR = dataPacket.data;
}
prevLetter = 0;
}
*(dataPTR - 1) = T9Table[Key][(prevLetter++) % T9Count];
updatePrevChar(Key);
}
return;
} else if (gEnteringSMS == SMS_ENTERING_DEST) {
if (bKeyPressed) {
dataPacket.dest *= 10;
dataPacket.dest += Key;
prevLetter = 0;
}
return;
}
}
switch (Key) {
case KEY_PTT:
case KEY_MENU:
if (gEnteringSMS == SMS_NOT_ENTERING) {
if (bKeyPressed) {
gEnteringSMS = SMS_ENTERING_DEST;
updatePrevChar(Key);
}
} else if (gEnteringSMS == SMS_ENTERING_DEST) {
if (bKeyPressed) {
memset(dataPacket.data, 0, DataPacketDataSize);
prepareDataPacket();
dataPacket.flags = 126;
gEnteringSMS = SMS_ENTERING_MESSAGE;
}
return;
} else if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
if (bKeyPressed) {
if (strlen((char *) dataPacket.data)) {
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)) {
RADIO_PrepareTX();
BK4819_SetScramble(gCurrentVfo->SCRAMBLING_TYPE);
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, true);
MSG_FSKSendData(&dataPacket);
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
MSG_EnableRX(true);
gVfoConfigureMode = VFO_CONFIGURE;
dataPTR = dataPacket.data;
memset(dataPacket.data, 0, DataPacketDataSize);
}
gEnteringSMS = SMS_NOT_ENTERING;
}
}
return;
}
break;
case KEY_UP:
if (bKeyPressed) {
gActiveMessage++;
if (gActiveMessage >= MESSAGES_COUNT) {
gActiveMessage = 0;
}
MESSAGES_GET();
}
break;
case KEY_DOWN:
if (bKeyPressed) {
gActiveMessage--;
if (gActiveMessage >= MESSAGES_COUNT) {
gActiveMessage = MESSAGES_COUNT - 1;
}
MESSAGES_GET();
}
break;
case KEY_EXIT:
if (gEnteringSMS != SMS_NOT_ENTERING) {
if (bKeyHeld) {
if (bKeyPressed) {
gEnteringSMS = SMS_NOT_ENTERING;
dataPTR = dataPacket.data;
memset(dataPacket.data, 0, DataPacketDataSize);
}
} else {
if (bKeyPressed) {
if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
if (dataPacket.data <= dataPTR) {
*dataPTR = '\0';
if (dataPacket.data < dataPTR) {
dataPTR--;
}
*dataPTR = '\0';
}
} else if (gEnteringSMS == SMS_ENTERING_DEST) {
dataPacket.dest /= 10;
}
}
}
} else {
if (bKeyPressed) {
updatePrevChar(Key);
gRequestDisplayScreen = DISPLAY_MAIN;
}
}
break;
default:
if (!bKeyHeld && bKeyPressed)
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break;
}
}

View File

@@ -2,21 +2,30 @@
// Created by bruno on 3/30/25.
//
#ifndef BRNQUANFW_MESSAGES_H
#define BRNQUANFW_MESSAGES_H
//#ifndef BRNQUANFW_MESSAGES_H
//#define BRNQUANFW_MESSAGES_H
#include "fskmodem.h"
#include "../driver/keyboard.h"
#include "../driver/eeprom.h"
#define MESSAGES_START 0X1D00;
#define MESSAGES_COUNT 6;
#define MESSAGES_START (0x1D00)
#define MESSAGES_COUNT (6)
typedef struct {
uint32_t src;
uint8_t seq;
uint8_t ttl;
uint8_t flags;
uint8_t data[DataPacketDataSize];
} StoredPacket;
extern uint8_t gActiveMessage;
extern StoredPacket loadedPacket;
void MESSAGES_GET();
void MESSAGES_DELETE();
void SCANNER_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
void SCANNER_Stop(void);
void SCANNER_TimeSlice10ms(void);
void SCANNER_TimeSlice500ms(void);
bool SCANNER_IsScanning(void);
void MESSAGES_SAVE();
void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
#endif //BRNQUANFW_MESSAGES_H
//#endif //BRNQUANFW_MESSAGES_H