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

@@ -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;
}