another attempt
This commit is contained in:
No files matched your search
+96
-32
@@ -15,7 +15,7 @@ DataPacket dataPacket;
|
||||
|
||||
DataPacket inBoundPacket;
|
||||
|
||||
uint8_t *dataPTR = dataPacket.data;
|
||||
char *dataPTR = gMessageText;
|
||||
|
||||
SMSEnteringState gEnteringSMS = SMS_NOT_ENTERING;
|
||||
|
||||
@@ -67,7 +67,20 @@ uint8_t SMSResponseCounterTarget = 6;
|
||||
#define POCSAG_REG58 0x03C1U // FSK 1.2K TX/RX, 1.2K RX BW, 0xAA/0x55 preamble, RX gain 3, FSK on
|
||||
#define POCSAG_REG59 ((6U << 4) | FSK_SYNC_LEN_BIT) // 7 byte chip preamble, 4 byte sync, no scramble
|
||||
#define POCSAG_REG5C 0xAA30U // CRC off
|
||||
#define POCSAG_REG72 0x3065U // 1200 baud (1200 * 10.32444)
|
||||
// POCSAG 512 / 1200 / 2400 baud, selected by the modem mode
|
||||
static uint16_t POCSAG_Baud(void)
|
||||
{
|
||||
switch (gEeprom.FSKMode) {
|
||||
case MOD_POCSAG_512: return 512;
|
||||
case MOD_POCSAG_2400: return 2400;
|
||||
default: return 1200;
|
||||
}
|
||||
}
|
||||
|
||||
// REG_72 = baud * 10.32444 (1200 -> 0x3065)
|
||||
#define POCSAG_REG72(baud) ((uint16_t) (((uint32_t) (baud) * 103244UL + 5000UL) / 10000UL))
|
||||
// wider FSK RX bandwidth for 2400 baud
|
||||
#define POCSAG_REG58_FOR(baud) (POCSAG_REG58 | ((baud) > 1200U ? FSK_RX_BW_2_4K_FFSK_1200_2400 : FSK_RX_BW_1_2K))
|
||||
#define POCSAG_RX_BYTES POCSAG_MAX_FRAME_SIZE // captured after the chip locks on the preamble
|
||||
#define POCSAG_CHIP_SYNC 0xAAAAU // logical preamble pattern
|
||||
|
||||
@@ -108,8 +121,9 @@ static void POCSAG_ConfigureModem(const bool rx)
|
||||
// The FSK modulator is driven through Tone2: with Tone2 disabled / gain 0 the
|
||||
// carrier barely shifts. The gain (together with REG_40) sets the FSK deviation.
|
||||
BK4819_WriteRegister(BK4819_REG_70, TONE2_ENABLE_BIT | (POCSAG_TONE2_GAIN & TONE2_GAIN_MASK));
|
||||
BK4819_WriteRegister(BK4819_REG_72, POCSAG_REG72);
|
||||
BK4819_WriteRegister(BK4819_REG_58, POCSAG_REG58);
|
||||
const uint16_t baud = POCSAG_Baud();
|
||||
BK4819_WriteRegister(BK4819_REG_72, POCSAG_REG72(baud));
|
||||
BK4819_WriteRegister(BK4819_REG_58, POCSAG_REG58_FOR(baud));
|
||||
|
||||
if (rx) {
|
||||
// "FSK" channel bandwidth: BK4819_SetFilterBandwidth() leaves REG_43 alone,
|
||||
@@ -129,7 +143,8 @@ static void POCSAG_ConfigureModem(const bool rx)
|
||||
|
||||
BK4819_WriteRegister(BK4819_REG_59, FSK_CLEAR_TX_FIFO | FSK_CLEAR_RX_FIFO | POCSAG_REG59);
|
||||
BK4819_WriteRegister(BK4819_REG_59, POCSAG_REG59);
|
||||
BK4819_WriteRegister(BK4819_REG_02, 0);
|
||||
// No REG_02 write here: this also runs from inside the interrupt loop (RX re-arm)
|
||||
// and clearing REG_02 there drops pending events such as squelch close.
|
||||
}
|
||||
|
||||
static uint8_t pocsagRxBuffer[POCSAG_RX_BYTES];
|
||||
@@ -138,10 +153,40 @@ static uint32_t lastPocsagSender;
|
||||
static char lastPocsagMessage[POCSAG_MAX_MESSAGE_LENGTH + 1U];
|
||||
static uint8_t pocsagDuplicateTimeout;
|
||||
|
||||
// New page alert: yellow (red + green) LED flashing and a speaker beep. The beep
|
||||
// waits until RX has ended, AUDIO_PlayBeep() does nothing while receiving.
|
||||
#define POCSAG_ALERT_FLASHES 10U // 500 ms half periods
|
||||
static uint8_t pocsagAlertTicks;
|
||||
static bool pocsagBeepPending;
|
||||
|
||||
static void POCSAG_StartAlert(void)
|
||||
{
|
||||
pocsagAlertTicks = POCSAG_ALERT_FLASHES;
|
||||
pocsagBeepPending = true;
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, true);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, true);
|
||||
}
|
||||
|
||||
static void POCSAG_AlertTimeSlice500ms(void)
|
||||
{
|
||||
if (pocsagAlertTicks > 0) {
|
||||
pocsagAlertTicks--;
|
||||
const bool on = (pocsagAlertTicks & 1U) != 0;
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, on);
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2_GREEN, on);
|
||||
}
|
||||
|
||||
if (pocsagBeepPending && !FUNCTION_IsRx() && gCurrentFunction != FUNCTION_TRANSMIT) {
|
||||
pocsagBeepPending = false;
|
||||
AUDIO_PlayBeep(BEEP_880HZ_60MS_DOUBLE_BEEP); // not affected by the key beep setting
|
||||
}
|
||||
}
|
||||
|
||||
void FSKModem_TimeSlice500ms(void) {
|
||||
if (gEeprom.FSKMode == MOD_POCSAG_1200) {
|
||||
if (MODEM_IS_POCSAG(gEeprom.FSKMode)) {
|
||||
if (pocsagDuplicateTimeout > 0)
|
||||
pocsagDuplicateTimeout--;
|
||||
POCSAG_AlertTimeSlice500ms();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -175,7 +220,7 @@ void FSKModem_TimeSlice500ms(void) {
|
||||
}
|
||||
|
||||
void MSG_ConfigureFSK(bool rx) {
|
||||
if (gEeprom.FSKMode == MOD_POCSAG_1200) {
|
||||
if (MODEM_IS_POCSAG(gEeprom.FSKMode)) {
|
||||
POCSAG_ConfigureModem(rx);
|
||||
return;
|
||||
}
|
||||
@@ -438,10 +483,11 @@ void processReceivedPacket(DataPacket *packet) {
|
||||
strcpy(String, "SMS by ");
|
||||
itoa(packet->src, numBuf); // Convert number to string
|
||||
strcat(String, numBuf);
|
||||
MESSAGES_SAVE();
|
||||
MESSAGES_SAVE(inBoundPacket.src, inBoundPacket.seq, inBoundPacket.ttl, inBoundPacket.flags,
|
||||
inBoundPacket.data, DataPacketDataSize);
|
||||
gRequestDisplayScreen = DISPLAY_MESSAGES;
|
||||
GUI_SelectNextDisplay(gRequestDisplayScreen);
|
||||
gActiveMessageBank = MESSAGES_COUNT / 3 - 1;
|
||||
MESSAGES_ShowNewest();
|
||||
UI_DisplayPopup(String);
|
||||
inBoundPacket.flags |= 0x40;
|
||||
inBoundPacket.dest = inBoundPacket.src;
|
||||
@@ -464,7 +510,24 @@ void processReceivedPacket(DataPacket *packet) {
|
||||
}
|
||||
}
|
||||
|
||||
static void MSG_POCSAGStoreReceived(void);
|
||||
|
||||
// The chip locks somewhere in the preamble, so it usually has not collected all
|
||||
// POCSAG_RX_BYTES when the carrier drops. Squelch close / VFO switching re-arms
|
||||
// RX through here: decode what was captured before it is thrown away.
|
||||
static void POCSAG_FlushCapture(void)
|
||||
{
|
||||
if (!MODEM_IS_POCSAG(gEeprom.FSKMode) || rxState != Receiving)
|
||||
return;
|
||||
|
||||
rxState = Ready;
|
||||
if (pocsagRxSize >= 4U * 3U) // at least sync + address + one message word
|
||||
MSG_POCSAGStoreReceived();
|
||||
pocsagRxSize = 0;
|
||||
}
|
||||
|
||||
void MSG_EnableRX(const bool enable) {
|
||||
POCSAG_FlushCapture();
|
||||
|
||||
if (enable) {
|
||||
MSG_ConfigureFSK(true);
|
||||
@@ -477,17 +540,14 @@ void MSG_EnableRX(const bool enable) {
|
||||
}
|
||||
}
|
||||
|
||||
static void MSG_POCSAGSendData(DataPacket *packet)
|
||||
void MSG_POCSAGSend(const uint32_t ric, const char *text)
|
||||
{
|
||||
uint8_t frame[POCSAG_MAX_FRAME_SIZE];
|
||||
char message[DataPacketDataSize + 1U];
|
||||
size_t frameSize;
|
||||
const unsigned int vfo = (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) ? gEeprom.RX_VFO
|
||||
: gEeprom.TX_VFO;
|
||||
|
||||
memcpy(message, packet->data, DataPacketDataSize);
|
||||
message[DataPacketDataSize] = '\0';
|
||||
if (!POCSAG_Encode(packet->dest, message, frame, sizeof(frame), &frameSize)) {
|
||||
if (!POCSAG_Encode(ric, text, frame, sizeof(frame), &frameSize)) {
|
||||
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
|
||||
return;
|
||||
}
|
||||
@@ -533,8 +593,10 @@ static void MSG_POCSAGSendData(DataPacket *packet)
|
||||
SYSTEM_DelayMs(20);
|
||||
BK4819_FskEnableTx();
|
||||
|
||||
// ~(208 + 11) bytes at 1200 baud = 1.46 s; allow 3 s.
|
||||
for (unsigned int timeout = 0; timeout < 600U; timeout++) {
|
||||
// chip preamble/sync + frame, plus 1 s margin (512 baud: ~4.4 s)
|
||||
const unsigned int timeoutMs =
|
||||
(unsigned int) (((frameSize + 11U) * 8U * 1000U) / POCSAG_Baud()) + 1000U;
|
||||
for (unsigned int timeout = 0; timeout < timeoutMs / 5U; timeout++) {
|
||||
SYSTEM_DelayMs(5);
|
||||
if (BK4819_ReadRegister(BK4819_REG_0C) & 1U) {
|
||||
BK4819_WriteRegister(BK4819_REG_02, 0);
|
||||
@@ -566,12 +628,15 @@ static void MSG_POCSAGSendData(DataPacket *packet)
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
|
||||
MSG_EnableRX(true);
|
||||
gVfoConfigureMode = VFO_CONFIGURE;
|
||||
dataPTR = dataPacket.data;
|
||||
dataPTR = gMessageText;
|
||||
}
|
||||
|
||||
void MSG_FSKSendData(DataPacket *dataPacketIn) {
|
||||
if (gEeprom.FSKMode == MOD_POCSAG_1200) {
|
||||
MSG_POCSAGSendData(dataPacketIn);
|
||||
if (MODEM_IS_POCSAG(gEeprom.FSKMode)) { // e.g. UART command 0x06FF
|
||||
char text[DataPacketDataSize + 1U];
|
||||
memcpy(text, dataPacketIn->data, DataPacketDataSize);
|
||||
text[DataPacketDataSize] = '\0';
|
||||
MSG_POCSAGSend(dataPacketIn->dest, text);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -688,7 +753,7 @@ void MSG_FSKSendData(DataPacket *dataPacketIn) {
|
||||
BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);
|
||||
MSG_EnableRX(true);
|
||||
gVfoConfigureMode = VFO_CONFIGURE;
|
||||
dataPTR = dataPacket.data;
|
||||
dataPTR = gMessageText;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -771,9 +836,13 @@ static void MSG_POCSAGStoreReceived(void)
|
||||
POCSAG_Log("\r\n");
|
||||
POCSAG_LogHex("PD ", pocsagRxBuffer, pocsagRxSize);
|
||||
|
||||
// monitor mode: accept pages for every RIC, otherwise only our own
|
||||
const uint32_t ric = gEeprom.POCSAG_MONITOR ? POCSAG_ANY_RIC : gEeprom.FSKSRCAddress;
|
||||
const bool decoded = POCSAG_TryDecode(ric, &sender, message, sizeof(message));
|
||||
|
||||
#if POCSAG_DEBUG_UART
|
||||
if (POCSAG_TryDecode(POCSAG_ANY_RIC, &sender, message, sizeof(message))) {
|
||||
POCSAG_LogNumber("PR ", sender);
|
||||
if (decoded || POCSAG_TryDecode(POCSAG_ANY_RIC, &sender, message, sizeof(message))) {
|
||||
POCSAG_LogNumber(decoded ? "PR " : "PO ", sender); // PO: page for another RIC
|
||||
POCSAG_Log(" ");
|
||||
POCSAG_Log(message);
|
||||
POCSAG_Log("\r\n");
|
||||
@@ -782,8 +851,7 @@ static void MSG_POCSAGStoreReceived(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!POCSAG_TryDecode(gEeprom.FSKSRCAddress, &sender, message, sizeof(message)) ||
|
||||
message[0] == '\0')
|
||||
if (!decoded || message[0] == '\0')
|
||||
return;
|
||||
|
||||
if (pocsagDuplicateTimeout > 0 && sender == lastPocsagSender &&
|
||||
@@ -794,14 +862,10 @@ static void MSG_POCSAGStoreReceived(void)
|
||||
strcpy(lastPocsagMessage, message);
|
||||
pocsagDuplicateTimeout = 20;
|
||||
|
||||
memset(&inBoundPacket, 0, sizeof(inBoundPacket));
|
||||
inBoundPacket.dest = gEeprom.FSKSRCAddress;
|
||||
inBoundPacket.src = sender;
|
||||
inBoundPacket.flags = MESSAGE_FLAG_POCSAG;
|
||||
memcpy(inBoundPacket.data, message, strlen(message) + 1U);
|
||||
MESSAGES_SAVE();
|
||||
MESSAGES_SAVE(sender, 0, 0, MESSAGE_FLAG_POCSAG, (const uint8_t *) message, strlen(message));
|
||||
POCSAG_StartAlert();
|
||||
|
||||
gActiveMessageBank = MESSAGES_COUNT / 3U - 1U;
|
||||
MESSAGES_ShowNewest();
|
||||
gRequestDisplayScreen = DISPLAY_MESSAGES;
|
||||
GUI_SelectNextDisplay(DISPLAY_MESSAGES);
|
||||
UI_DisplayPopup("POCSAG received");
|
||||
@@ -852,7 +916,7 @@ void FSK_HANDLE_IRQ(unsigned short irq) {
|
||||
|
||||
//UART_printf("\nMSG : S%i, F%i, E%i | %i", rx_sync, rx_fifo_almost_full, rx_finished, irq);
|
||||
|
||||
if (gEeprom.FSKMode == MOD_POCSAG_1200) {
|
||||
if (MODEM_IS_POCSAG(gEeprom.FSKMode)) {
|
||||
POCSAG_HandleIRQ(rx_sync, rx_fifo_almost_full, rx_finished);
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-1
@@ -122,7 +122,7 @@ typedef enum {
|
||||
extern SMSEnteringState gEnteringSMS;
|
||||
extern SMSResponseState gSMSResponseState;
|
||||
|
||||
extern uint8_t *dataPTR;
|
||||
extern char *dataPTR; // cursor into gMessageText (app/messages.h)
|
||||
|
||||
extern bool gGotACK;
|
||||
|
||||
@@ -132,6 +132,9 @@ void FSK_HANDLE_IRQ(unsigned short irq);
|
||||
|
||||
void FSKModem_TimeSlice500ms(void);
|
||||
|
||||
// Transmit an alphanumeric POCSAG page to the given RIC.
|
||||
void MSG_POCSAGSend(uint32_t ric, const char *text);
|
||||
|
||||
// POCSAG TX deviation (BK4819 REG_40<11:0>), adjustable at runtime for tuning.
|
||||
extern uint16_t gPocsagDeviation;
|
||||
void POCSAG_AdjustDeviation(int delta);
|
||||
|
||||
+1
-1
@@ -676,7 +676,7 @@ static void MAIN_Key_MENU(bool bKeyPressed, bool bKeyHeld) {
|
||||
if (gWasFKeyPressed && bKeyPressed) {
|
||||
MESSAGES_GET();
|
||||
gRequestDisplayScreen = DISPLAY_MESSAGES;
|
||||
gActiveMessageBank = MESSAGES_COUNT / 3 - 1;
|
||||
MESSAGES_ShowNewest();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+15
-3
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "app/pocsag.h"
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(ENABLE_OVERLAY)
|
||||
@@ -239,6 +240,7 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) {
|
||||
#endif
|
||||
case MENU_BCL:
|
||||
case MENU_BEEP:
|
||||
case MENU_PMON:
|
||||
case MENU_S_ADD1:
|
||||
case MENU_S_ADD2:
|
||||
case MENU_S_ADD3:
|
||||
@@ -270,7 +272,8 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) {
|
||||
break;
|
||||
|
||||
case MENU_FSKSRC:
|
||||
*pMax = INT32_MAX;
|
||||
// POCSAG: own RIC (21 bits, 7 digits); SMS: 32 bit address (8 digit input box)
|
||||
*pMax = MODEM_IS_POCSAG(gEeprom.FSKMode) ? (int32_t) POCSAG_MAX_RIC : 99999999;
|
||||
*pMin = 0;
|
||||
break;
|
||||
|
||||
@@ -566,6 +569,11 @@ void MENU_AcceptSetting(void) {
|
||||
gEeprom.BEEP_CONTROL = gSubMenuSelection;
|
||||
break;
|
||||
|
||||
case MENU_PMON:
|
||||
gEeprom.POCSAG_MONITOR = gSubMenuSelection;
|
||||
gFlagReconfigureVfos = true;
|
||||
break;
|
||||
|
||||
#ifdef ENABLE_VOICE
|
||||
case MENU_VOICE:
|
||||
gEeprom.VOICE_PROMPT = gSubMenuSelection;
|
||||
@@ -952,6 +960,10 @@ void MENU_ShowCurrentSetting(void) {
|
||||
case MENU_BEEP:
|
||||
gSubMenuSelection = gEeprom.BEEP_CONTROL;
|
||||
break;
|
||||
|
||||
case MENU_PMON:
|
||||
gSubMenuSelection = gEeprom.POCSAG_MONITOR;
|
||||
break;
|
||||
#ifdef ENABLE_VOICE
|
||||
case MENU_VOICE:
|
||||
gSubMenuSelection = gEeprom.VOICE_PROMPT;
|
||||
@@ -1161,7 +1173,7 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
uint8_t Offset;
|
||||
int32_t Min;
|
||||
int32_t Max;
|
||||
uint16_t Value = 0;
|
||||
uint32_t Value = 0; // was uint16_t: truncated FSKSRC above 65535
|
||||
|
||||
if (bKeyHeld || !bKeyPressed)
|
||||
return;
|
||||
@@ -1313,7 +1325,7 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
if (Offset == gInputBoxIndex)
|
||||
gInputBoxIndex = 0;
|
||||
|
||||
if (Value <= Max) {
|
||||
if (Value <= (uint32_t) Max) {
|
||||
gSubMenuSelection = Value;
|
||||
return;
|
||||
}
|
||||
|
||||
+76
-48
@@ -11,8 +11,11 @@
|
||||
#define T9Count 9
|
||||
|
||||
// 0x1E00+ holds the radio calibration; the message store must never reach it.
|
||||
_Static_assert(MESSAGES_START + MESSAGES_COUNT * sizeof(StoredPacket) <= 0x1E00,
|
||||
"message store overlaps calibration EEPROM");
|
||||
_Static_assert(sizeof(StoredPacket) == MESSAGES_SLOT_SIZE, "StoredPacket layout");
|
||||
_Static_assert(MESSAGES_START + MESSAGES_COUNT * MESSAGES_SLOT_SIZE <= MESSAGES_END,
|
||||
"message store overlaps calibration EEPROM: lower MESSAGES_COUNT or POCSAG_MAX_MESSAGE_LENGTH");
|
||||
_Static_assert(MESSAGES_PER_PAGE >= 1U, "POCSAG_MAX_MESSAGE_LENGTH too long for the display");
|
||||
_Static_assert(MESSAGES_COUNT >= 1U && MESSAGES_COUNT <= 36U, "MESSAGES_COUNT out of range");
|
||||
|
||||
const char T9Table[10][T9Count] = {
|
||||
{'#', '(', ')', ';', ':', '<', '>', '/', '0'},
|
||||
@@ -33,9 +36,18 @@ uint8_t gActiveMessageBank = 0;
|
||||
|
||||
StoredPacket loadedPacket;
|
||||
|
||||
char gMessageText[MESSAGES_TEXT_LENGTH + 1U];
|
||||
|
||||
uint8_t gKeyTimeout = 0;
|
||||
|
||||
void MESSAGES_SAVE() {
|
||||
static size_t MESSAGES_MaxTextLength(void)
|
||||
{
|
||||
// the SMS packet carries DataPacketDataSize bytes including the terminator
|
||||
return MODEM_IS_POCSAG(gEeprom.FSKMode) ? MESSAGES_TEXT_LENGTH : DataPacketDataSize - 1U;
|
||||
}
|
||||
|
||||
void MESSAGES_SAVE(const uint32_t src, const uint8_t seq, const uint8_t ttl, const uint8_t flags,
|
||||
const uint8_t *text, size_t length) {
|
||||
uint8_t Data[8];
|
||||
StoredPacket stored;
|
||||
EEPROM_ReadBuffer(SEQParameterEEPROM, Data, 8);
|
||||
@@ -45,16 +57,20 @@ void MESSAGES_SAVE() {
|
||||
msgIndex = 0;
|
||||
Data[1] = msgIndex;
|
||||
EEPROM_WriteBuffer(SEQParameterEEPROM, Data);
|
||||
|
||||
memset(&stored, 0, sizeof(stored));
|
||||
stored.src = inBoundPacket.src;
|
||||
stored.seq = inBoundPacket.seq;
|
||||
stored.ttl = inBoundPacket.ttl;
|
||||
stored.flags = inBoundPacket.flags;
|
||||
memcpy(stored.data, inBoundPacket.data, sizeof(stored.data));
|
||||
stored.src = src;
|
||||
stored.seq = seq;
|
||||
stored.ttl = ttl;
|
||||
stored.flags = flags;
|
||||
if (length > MESSAGES_TEXT_LENGTH)
|
||||
length = MESSAGES_TEXT_LENGTH;
|
||||
for (size_t i = 0; i < length && text[i] != '\0'; i++)
|
||||
stored.data[i] = text[i];
|
||||
|
||||
const uint16_t address = MESSAGES_START + (msgIndex * sizeof(StoredPacket));
|
||||
for (unsigned int offset = 0; offset < sizeof(stored); offset += 8U)
|
||||
EEPROM_WriteBuffer(address + offset, (const uint8_t *)&stored + offset);
|
||||
|
||||
EEPROM_WriteBuffer(address + offset, (const uint8_t *) &stored + offset);
|
||||
}
|
||||
|
||||
void MESSAGES_GET() {
|
||||
@@ -64,13 +80,28 @@ void MESSAGES_GET() {
|
||||
loadedPacket.seq = dataPacket.seq;
|
||||
loadedPacket.ttl = dataPacket.ttl;
|
||||
loadedPacket.flags = dataPacket.flags;
|
||||
memcpy(loadedPacket.data, dataPacket.data, sizeof(dataPacket.data));
|
||||
memcpy(loadedPacket.data, gMessageText, MESSAGES_TEXT_LENGTH);
|
||||
} else {
|
||||
EEPROM_ReadBuffer(MESSAGES_START + (gActiveMessage * sizeof(StoredPacket)), &loadedPacket,
|
||||
sizeof(StoredPacket));
|
||||
}
|
||||
}
|
||||
|
||||
void MESSAGES_GetText(char *text) {
|
||||
size_t i = 0;
|
||||
for (; i < MESSAGES_TEXT_LENGTH; i++) {
|
||||
const uint8_t c = loadedPacket.data[i];
|
||||
if (c == 0x00 || c == 0xFF) // NUL padding or erased EEPROM
|
||||
break;
|
||||
text[i] = (c < 0x20 || c > 0x7E) ? '?' : (char) c;
|
||||
}
|
||||
text[i] = '\0';
|
||||
}
|
||||
|
||||
void MESSAGES_ShowNewest(void) {
|
||||
gActiveMessageBank = MESSAGES_PAGES - 1U; // pages run oldest .. newest
|
||||
}
|
||||
|
||||
void MESSAGES_DELETE() {
|
||||
|
||||
}
|
||||
@@ -89,6 +120,22 @@ void MESSAGES_TimeSlice500ms(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void MESSAGES_ClearText(void) {
|
||||
memset(gMessageText, 0, sizeof(gMessageText));
|
||||
dataPTR = gMessageText;
|
||||
}
|
||||
|
||||
static void MESSAGES_Send(void) {
|
||||
if (MODEM_IS_POCSAG(gEeprom.FSKMode)) {
|
||||
MSG_POCSAGSend(dataPacket.dest, gMessageText);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(dataPacket.data, 0, DataPacketDataSize);
|
||||
memcpy(dataPacket.data, gMessageText, DataPacketDataSize - 1U);
|
||||
MSG_FSKSendData(&dataPacket);
|
||||
}
|
||||
|
||||
void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
if(Key == KEY_STAR) {
|
||||
gRequestDisplayScreen = DISPLAY_OOKSENDER;
|
||||
@@ -96,7 +143,7 @@ void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
}
|
||||
gKeyTimeout = 1;
|
||||
// POCSAG deviation tuning: 2 = more, 8 = less (send a page and check it on an SDR)
|
||||
if (gEeprom.FSKMode == MOD_POCSAG_1200 && gEnteringSMS == SMS_NOT_ENTERING &&
|
||||
if (MODEM_IS_POCSAG(gEeprom.FSKMode) && gEnteringSMS == SMS_NOT_ENTERING &&
|
||||
(Key == KEY_2 || Key == KEY_8)) {
|
||||
if (bKeyPressed && !bKeyHeld)
|
||||
POCSAG_AdjustDeviation(Key == KEY_2 ? 0x40 : -0x40);
|
||||
@@ -104,14 +151,14 @@ void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
}
|
||||
if (gEnteringSMS != SMS_NOT_ENTERING && Key <= KEY_9) {
|
||||
if (!bKeyHeld) {
|
||||
if (!dataPTR || dataPTR < dataPacket.data) {
|
||||
dataPTR = dataPacket.data;
|
||||
if (!dataPTR || dataPTR < gMessageText) {
|
||||
dataPTR = gMessageText;
|
||||
}
|
||||
}
|
||||
if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
|
||||
if (bKeyPressed) {
|
||||
if (prevKey != Key) {
|
||||
if (dataPTR - dataPacket.data >= DataPacketDataSize - 1) {
|
||||
if ((size_t) (dataPTR - gMessageText) >= MESSAGES_MaxTextLength()) {
|
||||
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +180,7 @@ void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
if (bKeyPressed) {
|
||||
const uint32_t dest = dataPacket.dest * 10U + Key;
|
||||
// in POCSAG mode the destination is the pager RIC (21 bits)
|
||||
if (gEeprom.FSKMode == MOD_POCSAG_1200 && dest > POCSAG_MAX_RIC) {
|
||||
if (MODEM_IS_POCSAG(gEeprom.FSKMode) && dest > POCSAG_MAX_RIC) {
|
||||
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
|
||||
return;
|
||||
}
|
||||
@@ -156,16 +203,16 @@ void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
}
|
||||
} else if (gEnteringSMS == SMS_ENTERING_DEST) {
|
||||
if (bKeyPressed) {
|
||||
memset(dataPacket.data, 0, DataPacketDataSize);
|
||||
MESSAGES_ClearText();
|
||||
prepareDataPacket();
|
||||
dataPacket.flags = 0x80 | (gCurrentVfo->OUTPUT_POWER & 0x07);
|
||||
gEnteringSMS = SMS_ENTERING_MESSAGE;
|
||||
gEnteringSMS = SMS_ENTERING_MESSAGE;
|
||||
}
|
||||
return;
|
||||
} else if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
|
||||
if (bKeyPressed) {
|
||||
if (strlen((char *) dataPacket.data)) {
|
||||
MSG_FSKSendData(&dataPacket);
|
||||
if (strlen(gMessageText)) {
|
||||
MESSAGES_Send();
|
||||
gEnteringSMS = SMS_NOT_ENTERING;
|
||||
}
|
||||
}
|
||||
@@ -173,33 +220,15 @@ void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
}
|
||||
break;
|
||||
case KEY_UP:
|
||||
if (gEnteringSMS == SMS_NOT_ENTERING) {
|
||||
if (bKeyPressed) {
|
||||
gActiveMessageBank++;
|
||||
gActiveMessage = gActiveMessageBank * 3;
|
||||
if (gActiveMessage > MESSAGES_COUNT) {
|
||||
gActiveMessage = 0;
|
||||
}
|
||||
if (gActiveMessageBank >= MESSAGES_COUNT / 3) {
|
||||
gActiveMessageBank = 0;
|
||||
}
|
||||
MESSAGES_GET();
|
||||
}
|
||||
if (gEnteringSMS == SMS_NOT_ENTERING && bKeyPressed) {
|
||||
gActiveMessageBank = (uint8_t) ((gActiveMessageBank + 1U) % MESSAGES_PAGES);
|
||||
gUpdateDisplay = true;
|
||||
}
|
||||
break;
|
||||
case KEY_DOWN:
|
||||
if (gEnteringSMS == SMS_NOT_ENTERING) {
|
||||
if (bKeyPressed) {
|
||||
gActiveMessageBank--;
|
||||
gActiveMessage = gActiveMessageBank * 3;
|
||||
if (gActiveMessage >= MESSAGES_COUNT) {
|
||||
gActiveMessage = MESSAGES_COUNT - 1;
|
||||
}
|
||||
if (gActiveMessageBank > MESSAGES_COUNT / 3) {
|
||||
gActiveMessageBank = MESSAGES_COUNT / 3 - 1;
|
||||
}
|
||||
MESSAGES_GET();
|
||||
}
|
||||
if (gEnteringSMS == SMS_NOT_ENTERING && bKeyPressed) {
|
||||
gActiveMessageBank = gActiveMessageBank ? gActiveMessageBank - 1U : MESSAGES_PAGES - 1U;
|
||||
gUpdateDisplay = true;
|
||||
}
|
||||
break;
|
||||
case KEY_EXIT:
|
||||
@@ -207,15 +236,14 @@ void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
if (bKeyHeld) {
|
||||
if (bKeyPressed) {
|
||||
gEnteringSMS = SMS_NOT_ENTERING;
|
||||
dataPTR = dataPacket.data;
|
||||
memset(dataPacket.data, 0, DataPacketDataSize);
|
||||
MESSAGES_ClearText();
|
||||
}
|
||||
} else {
|
||||
if (bKeyPressed) {
|
||||
if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
|
||||
if (dataPacket.data <= dataPTR) {
|
||||
if (gMessageText <= dataPTR) {
|
||||
*dataPTR = '\0';
|
||||
if (dataPacket.data < dataPTR) {
|
||||
if (gMessageText < dataPTR) {
|
||||
dataPTR--;
|
||||
}
|
||||
*dataPTR = '\0';
|
||||
|
||||
+33
-7
@@ -2,25 +2,46 @@
|
||||
// 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"
|
||||
|
||||
#include "pocsag.h"
|
||||
|
||||
// Message store: MESSAGES_COUNT slots between MESSAGES_START and the calibration
|
||||
// data at MESSAGES_END. Override MESSAGES_COUNT / POCSAG_MAX_MESSAGE_LENGTH with -D;
|
||||
// changing either moves the slots (old stored messages read back as garbage).
|
||||
#define MESSAGES_START (0x1C08)
|
||||
#define MESSAGES_END (0x1E00)
|
||||
#ifndef MESSAGES_COUNT
|
||||
#define MESSAGES_COUNT (12)
|
||||
#endif
|
||||
#define MESSAGE_FLAG_POCSAG (0x20U)
|
||||
|
||||
typedef struct {
|
||||
#define MESSAGES_TEXT_LENGTH POCSAG_MAX_MESSAGE_LENGTH
|
||||
#define MESSAGES_HEADER_SIZE 7U // src, seq, ttl, flags
|
||||
// EEPROM is written in 8 byte blocks, so slots are a multiple of 8 bytes
|
||||
#define MESSAGES_SLOT_SIZE (((MESSAGES_HEADER_SIZE + MESSAGES_TEXT_LENGTH + 7U) / 8U) * 8U)
|
||||
|
||||
// Display: 18 small-font characters per line, header line + text lines per message
|
||||
#define MESSAGES_LINE_CHARS 18U
|
||||
#define MESSAGES_TEXT_LINES ((MESSAGES_TEXT_LENGTH + MESSAGES_LINE_CHARS - 1U) / MESSAGES_LINE_CHARS)
|
||||
#define MESSAGES_PER_PAGE (8U / (1U + MESSAGES_TEXT_LINES))
|
||||
#define MESSAGES_PAGES ((MESSAGES_COUNT + MESSAGES_PER_PAGE - 1U) / MESSAGES_PER_PAGE)
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint32_t src;
|
||||
uint8_t seq;
|
||||
uint8_t ttl;
|
||||
uint8_t flags;
|
||||
uint8_t data[DataPacketDataSize];
|
||||
uint8_t reserved[12];
|
||||
uint8_t data[MESSAGES_SLOT_SIZE - MESSAGES_HEADER_SIZE]; // text, NUL padded
|
||||
} StoredPacket;
|
||||
|
||||
// Text being typed / last sent (SMS mode sends the first DataPacketDataSize - 1 chars)
|
||||
extern char gMessageText[MESSAGES_TEXT_LENGTH + 1U];
|
||||
|
||||
extern uint8_t gActiveMessage;
|
||||
extern uint8_t gActiveMessageBank;
|
||||
|
||||
@@ -30,8 +51,13 @@ extern uint8_t gKeyTimeout;
|
||||
|
||||
void MESSAGES_GET();
|
||||
void MESSAGES_DELETE();
|
||||
void MESSAGES_SAVE();
|
||||
void MESSAGES_SAVE(uint32_t src, uint8_t seq, uint8_t ttl, uint8_t flags,
|
||||
const uint8_t *text, size_t length);
|
||||
// loadedPacket text as a NUL terminated string (buffer of MESSAGES_TEXT_LENGTH + 1)
|
||||
void MESSAGES_GetText(char *text);
|
||||
// show the newest messages page
|
||||
void MESSAGES_ShowNewest(void);
|
||||
void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
|
||||
void MESSAGES_TimeSlice500ms(void);
|
||||
|
||||
//#endif //BRNQUANFW_MESSAGES_H
|
||||
#endif //BRNQUANFW_MESSAGES_H
|
||||
+13
-4
@@ -57,6 +57,15 @@ static uint32_t read_word(const uint8_t *input, const size_t bit_offset, const b
|
||||
return invert ? ~word : word;
|
||||
}
|
||||
|
||||
// Sync codeword match with up to POCSAG_SYNC_MAX_ERRORS wrong bits (like multimon-ng);
|
||||
// an exact match loses the whole batch on a single bit error.
|
||||
#define POCSAG_SYNC_MAX_ERRORS 2U
|
||||
|
||||
static unsigned sync_errors(const uint32_t word)
|
||||
{
|
||||
return (unsigned)__builtin_popcountl(word ^ POCSAG_SYNC_WORD);
|
||||
}
|
||||
|
||||
static bool is_valid_codeword(const uint32_t word)
|
||||
{
|
||||
return make_codeword(word >> 11) == word;
|
||||
@@ -109,7 +118,7 @@ static bool decode_after_address(const uint8_t *input, const size_t input_bits,
|
||||
uint32_t codeword = read_word(input, position, invert);
|
||||
|
||||
// Messages may continue across a batch boundary.
|
||||
if (codeword == POCSAG_SYNC_WORD)
|
||||
if (sync_errors(codeword) <= POCSAG_SYNC_MAX_ERRORS)
|
||||
continue;
|
||||
|
||||
// Idle or a new address codeword ends the message.
|
||||
@@ -213,12 +222,12 @@ bool POCSAG_Decode(const uint8_t *input, const size_t input_size, const uint32_t
|
||||
|
||||
message[0] = '\0';
|
||||
for (size_t bit = 0; bit + 32U <= input_bits; bit++) {
|
||||
const uint32_t word = read_word(input, bit, false);
|
||||
const unsigned errors = sync_errors(read_word(input, bit, false));
|
||||
bool invert;
|
||||
|
||||
if (word == POCSAG_SYNC_WORD)
|
||||
if (errors <= POCSAG_SYNC_MAX_ERRORS)
|
||||
invert = false;
|
||||
else if (word == (uint32_t)~POCSAG_SYNC_WORD)
|
||||
else if (32U - errors <= POCSAG_SYNC_MAX_ERRORS)
|
||||
invert = true;
|
||||
else
|
||||
continue;
|
||||
|
||||
+7
-3
@@ -10,15 +10,19 @@
|
||||
|
||||
#define POCSAG_MAX_RIC 0x1FFFFFUL // 21 bit capcode (2097151)
|
||||
#define POCSAG_ANY_RIC 0xFFFFFFFFUL // POCSAG_Decode(): accept any address
|
||||
#define POCSAG_MAX_MESSAGE_LENGTH 20U
|
||||
// Longest alphanumeric message (TX and RX). Also the stored message length, see
|
||||
// app/messages.h. Up to 45 fits the fixed two-batch TX frame (checked in pocsag.c).
|
||||
#ifndef POCSAG_MAX_MESSAGE_LENGTH
|
||||
#define POCSAG_MAX_MESSAGE_LENGTH 33U
|
||||
#endif
|
||||
#define POCSAG_PREAMBLE_BYTES 72U // 576 bits of 1010..., the minimum the spec allows
|
||||
#define POCSAG_BATCH_WORDS 16U
|
||||
#define POCSAG_BATCH_BYTES (4U + POCSAG_BATCH_WORDS * 4U)
|
||||
#define POCSAG_BATCH_COUNT 2U
|
||||
|
||||
// Every frame produced by POCSAG_Encode() is exactly this long: preamble + two batches.
|
||||
// Two batches always hold the address plus a 20 character message followed by at least
|
||||
// one idle codeword (the address sits in slot <= 14, the message needs <= 7 codewords).
|
||||
// Two batches always hold the address plus a POCSAG_MAX_MESSAGE_LENGTH message followed
|
||||
// by at least one idle codeword (the address sits in slot <= 14).
|
||||
#define POCSAG_MAX_FRAME_SIZE (POCSAG_PREAMBLE_BYTES + POCSAG_BATCH_COUNT * POCSAG_BATCH_BYTES)
|
||||
|
||||
// Encodes an alphanumeric page for the given 21 bit capcode (RIC).
|
||||
|
||||
+4
-1
@@ -137,7 +137,7 @@ void SETTINGS_InitEEPROM(void) {
|
||||
gEeprom.KEY_2_LONG_PRESS_ACTION = (Data[4] < ACTION_OPT_LEN) ? Data[4] : ACTION_OPT_NONE;
|
||||
gEeprom.SCAN_RESUME_MODE = (Data[5] < 105) ? Data[5] : 14;
|
||||
gEeprom.AUTO_KEYPAD_LOCK = (Data[6] < 41) ? Data[6] : 0;
|
||||
gEeprom.FSKMode = (Data[7] <= MOD_POCSAG_1200) ? Data[7] : MOD_FSK_1200;
|
||||
gEeprom.FSKMode = (Data[7] <= MOD_POCSAG_2400) ? Data[7] : MOD_FSK_1200;
|
||||
// 0E98..0E9F
|
||||
#ifdef ENABLE_PWRON_PASSWORD
|
||||
EEPROM_ReadBuffer(0x0E98, Data, 8);
|
||||
@@ -234,6 +234,8 @@ void SETTINGS_InitEEPROM(void) {
|
||||
gEeprom.FSKSRCAddress |= Data[1] << 8;
|
||||
gEeprom.FSKSRCAddress |= Data[2] << 16;
|
||||
gEeprom.FSKSRCAddress |= Data[3] << 24;
|
||||
// 0x0F25 held leftover scan list bytes before, so ON is a magic value
|
||||
gEeprom.POCSAG_MONITOR = Data[5] == 0x5A;
|
||||
#ifdef ENABLE_FMRADIO
|
||||
gEeprom.BK1080_AGC_ENABLED = Data[4] & 0x01;
|
||||
gEeprom.BK1080_BLEND_CONFIG = (Data[4] >> 1) & 0x03;
|
||||
@@ -646,6 +648,7 @@ void SETTINGS_SaveSettings(void) {
|
||||
((gEeprom.BK1080_BLEND_CONFIG & 0x03) << 1) |
|
||||
((gEeprom.BK1080_DEEMPHASIS_CONFIG & 0x03) << 3));
|
||||
#endif
|
||||
State[5] = gEeprom.POCSAG_MONITOR ? 0x5A : 0x00;
|
||||
|
||||
EEPROM_WriteBuffer(0x0F20, State);
|
||||
|
||||
|
||||
+6
-1
@@ -36,9 +36,13 @@ typedef enum ModemModulation {
|
||||
MOD_AFSK_1200, // for good conditions
|
||||
MOD_AFSK_2400,
|
||||
MOD_NOAA_SAME,
|
||||
MOD_POCSAG_1200
|
||||
MOD_POCSAG_1200,
|
||||
MOD_POCSAG_512, // appended so stored settings keep their meaning
|
||||
MOD_POCSAG_2400
|
||||
} ModemModulation;
|
||||
|
||||
#define MODEM_IS_POCSAG(mode) ((mode) >= MOD_POCSAG_1200 && (mode) <= MOD_POCSAG_2400)
|
||||
|
||||
enum POWER_OnDisplayMode_t {
|
||||
#ifdef ENABLE_FEAT_F4HWN
|
||||
POWER_ON_DISPLAY_MODE_ALL,
|
||||
@@ -312,6 +316,7 @@ typedef struct {
|
||||
|
||||
ModemModulation FSKMode;
|
||||
uint32_t FSKSRCAddress;
|
||||
bool POCSAG_MONITOR; // POCSAG: receive pages for every RIC
|
||||
} EEPROM_Config_t;
|
||||
|
||||
extern EEPROM_Config_t gEeprom;
|
||||
|
||||
+34
-1
@@ -86,6 +86,25 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
// Radio RX: the chip locks anywhere in the preamble and the capture is cut off
|
||||
// when the transmission ends (decoded on squelch close), in both FIFO byte orders.
|
||||
assert(POCSAG_Encode(1234567U, "12345678901234567890", frame, sizeof(frame), NULL));
|
||||
for (size_t lock = 0; lock < POCSAG_PREAMBLE_BYTES; lock++) {
|
||||
const size_t size = sizeof(frame) - lock;
|
||||
assert(POCSAG_Decode(frame + lock, size, 1234567U, NULL, decoded, sizeof(decoded)));
|
||||
assert(strcmp(decoded, "12345678901234567890") == 0);
|
||||
}
|
||||
|
||||
// Sync codeword with 2 bit errors (both batches) still decodes, also inverted.
|
||||
assert(POCSAG_Encode(1234567U, "sync errors", frame, sizeof(frame), NULL));
|
||||
frame[POCSAG_PREAMBLE_BYTES] ^= 0x81U;
|
||||
frame[POCSAG_PREAMBLE_BYTES + POCSAG_BATCH_BYTES + 2U] ^= 0x18U;
|
||||
assert(POCSAG_Decode(frame, sizeof(frame), 1234567U, NULL, decoded, sizeof(decoded)));
|
||||
assert(strcmp(decoded, "sync errors") == 0);
|
||||
invert(frame, sizeof(frame));
|
||||
assert(POCSAG_Decode(frame, sizeof(frame), 1234567U, NULL, decoded, sizeof(decoded)));
|
||||
assert(strcmp(decoded, "sync errors") == 0);
|
||||
|
||||
// Monitor mode: any address decodes and reports the RIC.
|
||||
assert(POCSAG_Encode(1234567U, "Ahoj", frame, sizeof(frame), NULL));
|
||||
assert(POCSAG_Decode(frame, sizeof(frame), POCSAG_ANY_RIC, &sender, decoded, sizeof(decoded)));
|
||||
@@ -93,7 +112,21 @@ int main(void)
|
||||
|
||||
assert(!POCSAG_Encode(0x200000U, "bad", frame, sizeof(frame), NULL));
|
||||
assert(!POCSAG_Encode(123U, "", frame, sizeof(frame), NULL));
|
||||
assert(!POCSAG_Encode(123U, "123456789012345678901", frame, sizeof(frame), NULL));
|
||||
// longest message, for every frame position, then one character too many
|
||||
{
|
||||
char longest[POCSAG_MAX_MESSAGE_LENGTH + 2U];
|
||||
for (size_t i = 0; i < POCSAG_MAX_MESSAGE_LENGTH + 1U; i++)
|
||||
longest[i] = (char) ('A' + i % 26U);
|
||||
longest[POCSAG_MAX_MESSAGE_LENGTH] = '\0';
|
||||
for (uint32_t ric = 0; ric < 8U; ric++) {
|
||||
assert(POCSAG_Encode(1000000U + ric, longest, frame, sizeof(frame), NULL));
|
||||
assert(POCSAG_Decode(frame, sizeof(frame), 1000000U + ric, NULL, decoded, sizeof(decoded)));
|
||||
assert(strcmp(decoded, longest) == 0);
|
||||
}
|
||||
longest[POCSAG_MAX_MESSAGE_LENGTH] = 'X';
|
||||
longest[POCSAG_MAX_MESSAGE_LENGTH + 1U] = '\0';
|
||||
assert(!POCSAG_Encode(123U, longest, frame, sizeof(frame), NULL));
|
||||
}
|
||||
assert(!POCSAG_Encode(123U, "ok", frame, sizeof(frame) - 1U, NULL));
|
||||
|
||||
puts("pocsag tests passed");
|
||||
|
||||
@@ -87,6 +87,7 @@ const t_menu_item MenuList[] =
|
||||
{"ChDisp", MENU_MDF}, // was "MDF"
|
||||
{"FSKMod", MENU_FSKMOD},
|
||||
{"FSKSRC", MENU_FSKSRC}, // was "AUTOLk"
|
||||
{"PocMon", MENU_PMON}, // POCSAG monitor: receive all RICs
|
||||
{"BLTime", MENU_ABR}, // was "ABR"
|
||||
{"BLMin", MENU_ABR_MIN},
|
||||
{"BLMax", MENU_ABR_MAX},
|
||||
@@ -234,7 +235,9 @@ const char gSubMenu_FSKMod[][8] =
|
||||
"A1200",
|
||||
"A2400",
|
||||
"NOAA",
|
||||
"POCSAG"
|
||||
"PCS1200",
|
||||
"PCS512",
|
||||
"PCS2400"
|
||||
};
|
||||
|
||||
const char gSubMenu_ROGER[][6] =
|
||||
@@ -632,6 +635,7 @@ UI_PrintStringSmallNormal(String, 2, 0, 6);
|
||||
#endif
|
||||
case MENU_BCL:
|
||||
case MENU_BEEP:
|
||||
case MENU_PMON:
|
||||
case MENU_S_ADD1:
|
||||
case MENU_S_ADD2:
|
||||
case MENU_S_ADD3:
|
||||
|
||||
@@ -83,6 +83,7 @@ enum {
|
||||
MENU_D_LIVE_DEC,
|
||||
MENU_FSKSRC,
|
||||
MENU_FSKMOD,
|
||||
MENU_PMON,
|
||||
MENU_ROGER,
|
||||
MENU_BAT_TXT,
|
||||
MENU_AM,
|
||||
@@ -144,7 +145,7 @@ extern const char gSubMenu_SET_PTT[2][4];
|
||||
#endif
|
||||
|
||||
extern const char *const gSubMenu_PTT_ID[5];
|
||||
extern const char gSubMenu_FSKMod[8][8];
|
||||
extern const char gSubMenu_FSKMod[10][8];
|
||||
extern const char gSubMenu_ROGER[3][6];
|
||||
extern const char gSubMenu_RESET[2][4];
|
||||
extern const char *const gSubMenu_F_LOCK[F_LOCK_LEN];
|
||||
|
||||
+34
-20
@@ -23,21 +23,38 @@ void u8_to_str(uint8_t num, char *str) {
|
||||
}
|
||||
|
||||
|
||||
// Print text wrapped over `lines` display lines starting at `line`.
|
||||
static void UI_PrintWrapped(const char *text, const uint8_t line, const uint8_t lines) {
|
||||
char chunk[MESSAGES_LINE_CHARS + 1U];
|
||||
const size_t length = strlen(text);
|
||||
|
||||
for (uint8_t l = 0; l < lines && l * MESSAGES_LINE_CHARS < length; l++) {
|
||||
strncpy(chunk, text + l * MESSAGES_LINE_CHARS, MESSAGES_LINE_CHARS);
|
||||
chunk[MESSAGES_LINE_CHARS] = '\0';
|
||||
UI_PrintStringSmallNormal(chunk, 1, 0, line + l);
|
||||
}
|
||||
}
|
||||
|
||||
void UI_DisplayMessages(void) {
|
||||
char String[19];
|
||||
UI_DisplayClear();
|
||||
if (gEnteringSMS != SMS_NOT_ENTERING) {
|
||||
if (gEnteringSMS == SMS_ENTERING_DEST) {
|
||||
UI_PrintString(gEeprom.FSKMode == MOD_POCSAG_1200 ? "RIC" : "SMS dest", 0, 0, 0 /*, 8 */);
|
||||
UI_PrintString(MODEM_IS_POCSAG(gEeprom.FSKMode) ? "RIC" : "SMS dest", 0, 0, 0 /*, 8 */);
|
||||
u32_to_str(dataPacket.dest, String);
|
||||
UI_PrintStringSmallNormal(String, 0, 0, 2);
|
||||
} else if (gEnteringSMS == SMS_ENTERING_MESSAGE) {
|
||||
UI_PrintString("SMS data", 0, 0, 0 /*, 8 */);
|
||||
UI_PrintStringSmallNormal((const char *) dataPacket.data, 1, 0, 1);
|
||||
memset(gFrameBuffer[1] + 2 + (7 * strlen((const char *) dataPacket.data)), gKeyTimeout == 0 ? 0xFF : 0x80,
|
||||
6);
|
||||
const size_t length = strlen(gMessageText);
|
||||
UI_PrintString(MODEM_IS_POCSAG(gEeprom.FSKMode) ? "Page text" : "SMS data", 0, 0, 0 /*, 8 */);
|
||||
UI_PrintWrapped(gMessageText, 1, MESSAGES_TEXT_LINES);
|
||||
// cursor block after the last character
|
||||
const uint8_t cursorLine = 1U + length / MESSAGES_LINE_CHARS;
|
||||
if (length < MESSAGES_TEXT_LENGTH && cursorLine < 8U)
|
||||
memset(gFrameBuffer[cursorLine] + 2 + (7 * (length % MESSAGES_LINE_CHARS)),
|
||||
gKeyTimeout == 0 ? 0xFF : 0x80, 6);
|
||||
}
|
||||
} else {
|
||||
char text[MESSAGES_TEXT_LENGTH + 1U];
|
||||
uint8_t Data[8];
|
||||
EEPROM_ReadBuffer(SEQParameterEEPROM, Data, 8);
|
||||
uint8_t msgIndex = Data[1]; // index of latest written message
|
||||
@@ -45,21 +62,16 @@ void UI_DisplayMessages(void) {
|
||||
// Determine oldest message index (next to be overwritten)
|
||||
uint8_t startIndex = (msgIndex + 1) % MESSAGES_COUNT;
|
||||
|
||||
// Each bank shows 3 messages
|
||||
uint8_t messagesPerPage = 3;
|
||||
|
||||
// Compute offset for scrolling (0 = newest, higher = older)
|
||||
uint8_t pageOffset = gActiveMessageBank * messagesPerPage;
|
||||
|
||||
for (uint8_t ixa = 0; ixa < messagesPerPage; ixa++) {
|
||||
// Logical order from oldest to newest
|
||||
uint8_t logicalIndex = (startIndex + pageOffset + ixa) % MESSAGES_COUNT;
|
||||
// Pages run from oldest to newest
|
||||
uint8_t pageOffset = gActiveMessageBank * MESSAGES_PER_PAGE;
|
||||
|
||||
for (uint8_t ixa = 0; ixa < MESSAGES_PER_PAGE; ixa++) {
|
||||
// If out of stored range, stop
|
||||
if (pageOffset + ixa >= MESSAGES_COUNT)
|
||||
break;
|
||||
|
||||
gActiveMessage = logicalIndex;
|
||||
// Logical order from oldest to newest
|
||||
gActiveMessage = (startIndex + pageOffset + ixa) % MESSAGES_COUNT;
|
||||
MESSAGES_GET();
|
||||
|
||||
// Build the display string
|
||||
@@ -71,22 +83,24 @@ void UI_DisplayMessages(void) {
|
||||
memcpy(String + 2, capcodeString + 3, 7);
|
||||
String[9] = ' ';
|
||||
} else {
|
||||
u32_to_str(gActiveMessage == MESSAGES_COUNT ? dataPacket.dest : loadedPacket.src, &String[0]);
|
||||
u32_to_str(loadedPacket.src, &String[0]);
|
||||
}
|
||||
String[10] = '-';
|
||||
u8_to_str(loadedPacket.seq, &String[11]);
|
||||
String[14] = '-';
|
||||
|
||||
// Display a visual index (0,1,2,3... not EEPROM slot)
|
||||
uint8_t visualIndex = ixa + (gActiveMessageBank * 3);
|
||||
uint8_t visualIndex = ixa + pageOffset;
|
||||
String[15] = (visualIndex < 10) ? ('0' + visualIndex) : ('A' + visualIndex - 10);
|
||||
String[16] = '-';
|
||||
String[17] = (gActiveMessage < 10) ? ('0' + gActiveMessage) : ('A' + gActiveMessage - 10);
|
||||
String[18] = 0;
|
||||
|
||||
// Print both metadata and message
|
||||
UI_PrintString(String, 2, 0, ixa * 2);
|
||||
UI_PrintString((const char *) loadedPacket.data, 2, 0, ixa * 2 + 1);
|
||||
// header line, then the text wrapped over MESSAGES_TEXT_LINES lines
|
||||
const uint8_t line = ixa * (1U + MESSAGES_TEXT_LINES);
|
||||
UI_PrintString(String, 2, 0, line);
|
||||
MESSAGES_GetText(text);
|
||||
UI_PrintWrapped(text, line + 1U, MESSAGES_TEXT_LINES);
|
||||
}
|
||||
}
|
||||
ST7565_BlitFullScreen();
|
||||
|
||||
Reference in New Issue
Block a user