Files
brnQuanFW/ui/messages.c
T
BRNSystemsandClaude Opus 5.5 aabd0f4956 BRN-POCSAG: 171 channels, 26 x 40 char messages, make toggles
EEPROM layout (settings.h), replacing the broken 24 byte layout from
85fb527 (200 x 24 B channels overran the VFOs, attributes and settings;
names were saved at ch*24 but read at ch*20):
- 32 byte channel records with the 10 char name and the 16 bit scrambler
  inside, 171 channels in two areas (0x0000, 0x11E0); VFOs at 0x1020 with
  the same record; attributes moved to 0x0F50.
- Message store from 0x1900: 26 messages of 40 characters.
- Reset VFO no longer wipes the memory channels and messages.
- Static asserts that no area overlaps another or the calibration.

Identity: reports "BRN-POCSAG v4.0" to CHIRP and in the packed image, so
stock / egzumer / F4HWN drivers do not accept the new layout; the name is
shown on the welcome screen.

Make toggles: ENABLE_POCSAG, ENABLE_POCSAG_DEBUG, ENABLE_POCSAG_DEV_TUNING,
ENABLE_OOK_SENDER (POCSAG code and the OOK sender compile out completely).

Fonts: removed the unused big font, big digits and small digits; the 3x5
font is only built with the spectrum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 01:43:05 +01:00

95 lines
3.7 KiB
C

//
// Created by bruno on 3/30/25.
//
#include "messages.h"
#include "../external/printf/printf.h"
// Convert a 32-bit number to a string (10 digits, zero-padded)
void u32_to_str(uint32_t num, char *str) {
for (int i = 9; i >= 0; i--) {
str[i] = '0' + (num % 10);
num /= 10;
}
str[10] = '\0';
}
// Convert an 8-bit number to a 2-digit string (zero-padded)
void u8_to_str(uint8_t num, char *str) {
str[0] = '0' + (num / 100); // Hundreds place
str[1] = '0' + ((num / 10) % 10); // Tens place
str[2] = '0' + (num % 10); // Ones place
str[3] = '\0';
}
// 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[24];
UI_DisplayClear();
if (gEnteringSMS != SMS_NOT_ENTERING) {
if (gEnteringSMS == SMS_ENTERING_DEST) {
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) {
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
// Determine oldest message index (next to be overwritten)
uint8_t startIndex = (msgIndex + 1) % 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;
// Logical order from oldest to newest
gActiveMessage = (startIndex + pageOffset + ixa) % MESSAGES_COUNT;
MESSAGES_GET();
// header: sender (POCSAG: "P:" + RIC), sequence, position in the list, EEPROM slot
// header (max 18 chars): POCSAG "P:<RIC> #nn", SMS "<address> s<seq> #nn"
if (loadedPacket.flags & MESSAGE_FLAG_POCSAG)
sprintf(String, "P:%07lu #%02u", (unsigned long) loadedPacket.src, ixa + pageOffset + 1U);
else
sprintf(String, "%08lu s%03u #%02u", (unsigned long) (loadedPacket.src % 100000000UL),
loadedPacket.seq, ixa + pageOffset + 1U);
// 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();
}