now also on a pager
This commit is contained in:
No files matched your search
+102
-8
@@ -53,15 +53,15 @@ uint8_t SMSResponseCounterTarget = 6;
|
||||
#define POCSAG_INVERT 1
|
||||
#endif
|
||||
|
||||
// REG_40<11:0> FM deviation for POCSAG (+-4.5 kHz nominal). Value from the
|
||||
// uv-k5-pocsag reference; measure with an SDR and adjust if needed.
|
||||
// REG_40<11:0> FM deviation for POCSAG (+-4.5 kHz nominal). 899 (reference fork)
|
||||
// gave a ~6 kHz tone spacing; tune live with keys 2/8 on the messages screen.
|
||||
#ifndef POCSAG_DEVIATION
|
||||
#define POCSAG_DEVIATION 0x383U
|
||||
#define POCSAG_DEVIATION 963U // measured: decodes on a CC1101 POCSAG receiver at Tone2 gain 127
|
||||
#endif
|
||||
|
||||
// REG_70<6:0> Tone2 gain = FSK TX level (0..127). 96 is what the stock aircopy/SMS use.
|
||||
// REG_70<6:0> Tone2 gain = FSK TX level (0..127). Max: the BK4819 FSK shift is on the low side.
|
||||
#ifndef POCSAG_TONE2_GAIN
|
||||
#define POCSAG_TONE2_GAIN 96U
|
||||
#define POCSAG_TONE2_GAIN 127U
|
||||
#endif
|
||||
|
||||
#define POCSAG_REG58 0x03C1U // FSK 1.2K TX/RX, 1.2K RX BW, 0xAA/0x55 preamble, RX gain 3, FSK on
|
||||
@@ -79,6 +79,25 @@ uint8_t SMSResponseCounterTarget = 6;
|
||||
(2U << 4) | /* 25 kHz channel mode */ \
|
||||
(1U << 3))
|
||||
|
||||
// Runtime-tunable TX deviation (REG_40<11:0>), keys 2/8 on the messages screen.
|
||||
uint16_t gPocsagDeviation = POCSAG_DEVIATION;
|
||||
|
||||
void POCSAG_AdjustDeviation(const int delta)
|
||||
{
|
||||
char text[12] = "DEV ";
|
||||
int value = (int) gPocsagDeviation + delta;
|
||||
|
||||
if (value < 0x40)
|
||||
value = 0x40;
|
||||
if (value > 0x0FFF)
|
||||
value = 0x0FFF;
|
||||
gPocsagDeviation = (uint16_t) value;
|
||||
|
||||
itoa(gPocsagDeviation, text + 4);
|
||||
UI_DisplayPopup(text);
|
||||
gUpdateDisplay = true;
|
||||
}
|
||||
|
||||
static uint16_t POCSAG_Raw16(const uint16_t logical)
|
||||
{
|
||||
return POCSAG_INVERT ? (uint16_t) ~logical : logical;
|
||||
@@ -502,7 +521,7 @@ static void MSG_POCSAGSendData(DataPacket *packet)
|
||||
BK4819_WriteRegister(BK4819_REG_7E, saved[7] & 0xFFC0U); // DC filters off
|
||||
BK4819_WriteRegister(BK4819_REG_4B, saved[5] | (1U << 5)); // ALC off
|
||||
BK4819_WriteRegister(BK4819_REG_43, POCSAG_REG43); // 25 kHz channel for +-4.5 kHz
|
||||
BK4819_WriteRegister(BK4819_REG_40, (saved[3] & 0xE000U) | (1U << 12) | (POCSAG_DEVIATION & 0x0FFFU));
|
||||
BK4819_WriteRegister(BK4819_REG_40, (saved[3] & 0xE000U) | (1U << 12) | (gPocsagDeviation & 0x0FFFU));
|
||||
|
||||
POCSAG_ConfigureModem(false);
|
||||
BK4819_WriteRegister(BK4819_REG_3F, BK4819_REG_3F_FSK_TX_FINISHED);
|
||||
@@ -684,13 +703,87 @@ void prepareDataPacket() {
|
||||
dataPacket.ttl = 20;
|
||||
}
|
||||
|
||||
// UART debug log for POCSAG RX (38400 8N1 on the programming cable):
|
||||
// "PS" chip locked on the preamble (FSK RX sync)
|
||||
// "PF <n>" capture finished, n bytes
|
||||
// "PD <hex>" raw captured bytes (logical bits, as stored)
|
||||
// "PR <ric> <m>" decoded a page (any RIC), "PX" nothing decodable
|
||||
#ifndef POCSAG_DEBUG_UART
|
||||
#define POCSAG_DEBUG_UART 1
|
||||
#endif
|
||||
|
||||
#if POCSAG_DEBUG_UART
|
||||
static void POCSAG_Log(const char *text)
|
||||
{
|
||||
UART_Send(text, strlen(text));
|
||||
}
|
||||
|
||||
static void POCSAG_LogNumber(const char *tag, const uint32_t value)
|
||||
{
|
||||
char number[12];
|
||||
itoa(value, number);
|
||||
POCSAG_Log(tag);
|
||||
POCSAG_Log(number);
|
||||
}
|
||||
|
||||
static void POCSAG_LogHex(const char *tag, const uint8_t *data, const size_t size)
|
||||
{
|
||||
static const char digits[] = "0123456789ABCDEF";
|
||||
POCSAG_Log(tag);
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
const char pair[2] = {digits[data[i] >> 4], digits[data[i] & 15U]};
|
||||
UART_Send(pair, 2);
|
||||
}
|
||||
POCSAG_Log("\r\n");
|
||||
}
|
||||
#else
|
||||
#define POCSAG_Log(text) do { } while (0)
|
||||
#define POCSAG_LogNumber(tag, value) do { } while (0)
|
||||
#define POCSAG_LogHex(tag, data, size) do { } while (0)
|
||||
#endif
|
||||
|
||||
static void POCSAG_SwapBytePairs(void)
|
||||
{
|
||||
for (size_t i = 0; i + 1U < pocsagRxSize; i += 2U) {
|
||||
const uint8_t b = pocsagRxBuffer[i];
|
||||
pocsagRxBuffer[i] = pocsagRxBuffer[i + 1U];
|
||||
pocsagRxBuffer[i + 1U] = b;
|
||||
}
|
||||
}
|
||||
|
||||
// The RX FIFO byte order has not been verified on hardware: try both.
|
||||
static bool POCSAG_TryDecode(const uint32_t ric, uint32_t *sender, char *message, const size_t capacity)
|
||||
{
|
||||
if (POCSAG_Decode(pocsagRxBuffer, pocsagRxSize, ric, sender, message, capacity))
|
||||
return true;
|
||||
POCSAG_SwapBytePairs();
|
||||
const bool ok = POCSAG_Decode(pocsagRxBuffer, pocsagRxSize, ric, sender, message, capacity);
|
||||
POCSAG_SwapBytePairs();
|
||||
return ok;
|
||||
}
|
||||
|
||||
static void MSG_POCSAGStoreReceived(void)
|
||||
{
|
||||
uint32_t sender;
|
||||
char message[POCSAG_MAX_MESSAGE_LENGTH + 1U];
|
||||
|
||||
if (!POCSAG_Decode(pocsagRxBuffer, pocsagRxSize, gEeprom.FSKSRCAddress,
|
||||
&sender, message, sizeof(message)) || message[0] == '\0')
|
||||
POCSAG_LogNumber("PF ", pocsagRxSize);
|
||||
POCSAG_Log("\r\n");
|
||||
POCSAG_LogHex("PD ", pocsagRxBuffer, pocsagRxSize);
|
||||
|
||||
#if POCSAG_DEBUG_UART
|
||||
if (POCSAG_TryDecode(POCSAG_ANY_RIC, &sender, message, sizeof(message))) {
|
||||
POCSAG_LogNumber("PR ", sender);
|
||||
POCSAG_Log(" ");
|
||||
POCSAG_Log(message);
|
||||
POCSAG_Log("\r\n");
|
||||
} else {
|
||||
POCSAG_Log("PX\r\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!POCSAG_TryDecode(gEeprom.FSKSRCAddress, &sender, message, sizeof(message)) ||
|
||||
message[0] == '\0')
|
||||
return;
|
||||
|
||||
if (pocsagDuplicateTimeout > 0 && sender == lastPocsagSender &&
|
||||
@@ -722,6 +815,7 @@ static void POCSAG_HandleIRQ(const bool rx_sync, const bool rx_fifo_almost_full,
|
||||
pocsagRxSize = 0;
|
||||
rxState = Receiving;
|
||||
AUDIO_AudioPathOff();
|
||||
POCSAG_Log("PS\r\n");
|
||||
}
|
||||
|
||||
if (rx_fifo_almost_full && rxState == Receiving) {
|
||||
|
||||
@@ -132,4 +132,8 @@ void FSK_HANDLE_IRQ(unsigned short irq);
|
||||
|
||||
void FSKModem_TimeSlice500ms(void);
|
||||
|
||||
// POCSAG TX deviation (BK4819 REG_40<11:0>), adjustable at runtime for tuning.
|
||||
extern uint16_t gPocsagDeviation;
|
||||
void POCSAG_AdjustDeviation(int delta);
|
||||
|
||||
#endif //UV_K5_FIRMWARE_CUSTOM_FSKMODEM_H
|
||||
@@ -95,6 +95,13 @@ void MESSAGES_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) {
|
||||
return;
|
||||
}
|
||||
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 &&
|
||||
(Key == KEY_2 || Key == KEY_8)) {
|
||||
if (bKeyPressed && !bKeyHeld)
|
||||
POCSAG_AdjustDeviation(Key == KEY_2 ? 0x40 : -0x40);
|
||||
return;
|
||||
}
|
||||
if (gEnteringSMS != SMS_NOT_ENTERING && Key <= KEY_9) {
|
||||
if (!bKeyHeld) {
|
||||
if (!dataPTR || dataPTR < dataPacket.data) {
|
||||
|
||||
+3
-2
@@ -94,7 +94,7 @@ static bool decode_after_address(const uint8_t *input, const size_t input_bits,
|
||||
return false;
|
||||
|
||||
const uint32_t found_capcode = (((address >> 13) & 0x3FFFFUL) << 3) | frame;
|
||||
if (found_capcode != capcode)
|
||||
if (capcode != POCSAG_ANY_RIC && found_capcode != capcode)
|
||||
return false;
|
||||
|
||||
if (sender != NULL)
|
||||
@@ -207,7 +207,8 @@ bool POCSAG_Decode(const uint8_t *input, const size_t input_size, const uint32_t
|
||||
{
|
||||
const size_t input_bits = input_size * 8U;
|
||||
|
||||
if (input == NULL || message == NULL || message_capacity == 0 || capcode > POCSAG_MAX_RIC)
|
||||
if (input == NULL || message == NULL || message_capacity == 0 ||
|
||||
(capcode > POCSAG_MAX_RIC && capcode != POCSAG_ANY_RIC))
|
||||
return false;
|
||||
|
||||
message[0] = '\0';
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#define POCSAG_IDLE_WORD 0x7A89C197UL
|
||||
|
||||
#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
|
||||
#define POCSAG_PREAMBLE_BYTES 72U // 576 bits of 1010..., the minimum the spec allows
|
||||
#define POCSAG_BATCH_WORDS 16U
|
||||
|
||||
@@ -86,6 +86,11 @@ int main(void)
|
||||
}
|
||||
}
|
||||
|
||||
// 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)));
|
||||
assert(sender == 1234567U && strcmp(decoded, "Ahoj") == 0);
|
||||
|
||||
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));
|
||||
|
||||
Reference in New Issue
Block a user