From c2a01fb7dd4b3571dc23c4af75a07af881f7a859 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sun, 21 Nov 2021 09:28:53 +0100 Subject: [PATCH] POCSAG: Fixed handling of loopback and scanning feature --- src/pocsag/frame.c | 15 ++++++++++----- src/pocsag/main.c | 27 ++++++++++++++++++++++----- src/pocsag/pocsag.c | 44 ++++++++++++++++++++++++++++++++++++++++---- src/pocsag/pocsag.h | 6 +----- 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/src/pocsag/frame.c b/src/pocsag/frame.c index edaf2f5..12ccd10 100644 --- a/src/pocsag/frame.c +++ b/src/pocsag/frame.c @@ -343,10 +343,12 @@ int64_t get_codeword(pocsag_t *pocsag) if (msg->data_index == msg->data_length) { pocsag->current_msg = NULL; msg->data_index = 0; - if (msg->repeat || pocsag->sender.loopback) + if (msg->repeat) msg->repeat--; - else + else { pocsag_msg_destroy(msg); + pocsag_msg_done(pocsag); + } } /* prevent 'use-after-free' from this point on */ msg = NULL; @@ -379,10 +381,12 @@ int64_t get_codeword(pocsag_t *pocsag) msg->bit_index = 0; } else { /* if message is not to be repeated, remove message */ - if (msg->repeat || pocsag->sender.loopback) + if (msg->repeat) msg->repeat--; - else + else { pocsag_msg_destroy(msg); + pocsag_msg_done(pocsag); + } /* prevent 'use-after-free' from this point on */ msg = NULL; } @@ -437,7 +441,8 @@ static void done_rx_msg(pocsag_t *pocsag) text[j++] = pocsag->rx_msg_data[i]; } text[j] = '\0'; - PDEBUG_CHAN(DPOCSAG, DEBUG_INFO, " -> Message text is \"%s\".\n", text); + if ((pocsag->rx_msg_function == POCSAG_FUNCTION_NUMERIC || pocsag->rx_msg_function == POCSAG_FUNCTION_ALPHA) && text[0]) + PDEBUG_CHAN(DPOCSAG, DEBUG_INFO, " -> Message text is \"%s\".\n", text); pocsag_msg_receive(pocsag->language, pocsag->sender.kanal, pocsag->rx_msg_ric, pocsag->rx_msg_function, text); } } diff --git a/src/pocsag/main.c b/src/pocsag/main.c index da5e55f..24d50d5 100644 --- a/src/pocsag/main.c +++ b/src/pocsag/main.c @@ -80,9 +80,13 @@ void print_help(const char *arg0) printf(" Translate German spcial characters from/to UTF-8.\n"); printf(" -S --scan \n"); printf(" Scan through given IDs once (no repetition). This can be useful to find\n"); - printf(" the RIC of a vintage receiver. Note that scanning all RICs from 0\n"); - printf(" through 2097151 would take about 16.5 Hours at 1200 Baud and known sub\n"); - printf(" RIC.\n"); + printf(" the RIC of a vintage pager. Note that scanning all RICs from 0 through\n"); + printf(" 2097151 would take about 16.5 Hours at 1200 Baud and known sub RIC.\n"); + printf(" Use -F to select function of the pager. Short messages with 5 numeric\n"); + printf(" or 2 alphanumeric characters are sent without increase in scanning\n"); + printf(" time. The upper 5 digits of the RIC are sent as message, if numeric\n"); + printf(" function was selected. The upper 3 digits of the RIC are sent as\n"); + printf(" message (2 digits hexadecimal), if alphanumeric function was selected.\n"); printf("\n"); printf("File: %s\n", MSG_SEND); printf(" Write \",0,message\" to it to send a numerical message.\n"); @@ -179,7 +183,7 @@ static int handle_options(int short_option, int argi, char **argv) return -EINVAL; } scan_to = atoi(argv[argi++]) + 1; - if (scan_to > 2097151) { + if (scan_to > 2097151 + 1) { fprintf(stderr, "Given RIC to scan to is out of range!\n"); return -EINVAL; } @@ -251,6 +255,9 @@ int main(int argc, char *argv[]) int i; double frequency; + /* pocsag does not use emphasis, so disable it */ + uses_emphasis = 0; + /* init common tones */ init_besetzton(); @@ -292,13 +299,23 @@ int main(int argc, char *argv[]) num_device = 1; /* use default */ if (num_kanal != num_device) { fprintf(stderr, "You need to specify as many sound devices as you have channels.\n"); - exit(0); + goto fail; } /* TX is default */ if (!tx && !rx) tx = 1; + /* TX & RX if loopback */ + if (loopback) + tx = rx = 1; + + /* no TX, no scanning */ + if (!tx && scan_to > scan_from) { + fprintf(stderr, "You need to enable TX, in order to scan.\n"); + goto fail; + } + /* create pipe for message sendy */ unlink(MSG_SEND); rc = mkfifo(MSG_SEND, 0666); diff --git a/src/pocsag/pocsag.c b/src/pocsag/pocsag.c index bb0c1eb..d7ca70f 100644 --- a/src/pocsag/pocsag.c +++ b/src/pocsag/pocsag.c @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -#define CHAN procsag->sender.kanal +#define CHAN pocsag->sender.kanal #include #include @@ -265,6 +265,36 @@ void pocsag_msg_destroy(pocsag_msg_t *msg) pocsag_display_status(); } +static int pocsag_scan_or_loopback(pocsag_t *pocsag) +{ + if (pocsag->scan_from < pocsag->scan_to) { + char message[16]; + + switch (pocsag->default_function) { + case POCSAG_FUNCTION_NUMERIC: + sprintf(message, "%05d", pocsag->scan_from / 100); + break; + case POCSAG_FUNCTION_ALPHA: + sprintf(message, "%02x", pocsag->scan_from / 10000); + break; + default: + message[0] = '\0'; + } + PDEBUG_CHAN(DPOCSAG, DEBUG_NOTICE, "Transmitting %s message '%s' with RIC '%d'.\n", pocsag_function_name[pocsag->default_function], message, pocsag->scan_from); + pocsag_msg_create(pocsag, 0, pocsag->scan_from, pocsag->default_function, message); + pocsag->scan_from++; + return 1; + } + + if (pocsag->sender.loopback) { + PDEBUG(DPOCSAG, DEBUG_INFO, "Sending message for loopback test.\n"); + pocsag_msg_create(pocsag, 0, 1234567, POCSAG_FUNCTION_NUMERIC, "1234"); + return 1; + } + + return 0; +} + void pocsag_msg_receive(enum pocsag_language language, const char *channel, uint32_t ric, enum pocsag_function function, const char *message) { char text[256 + strlen(message) * 4], *p; @@ -346,8 +376,7 @@ int pocsag_create(const char *kanal, double frequency, const char *device, int u PDEBUG(DPOCSAG, DEBUG_NOTICE, "Created 'Kanal' %s\n", kanal); - if (pocsag->sender.loopback) - pocsag_msg_create(pocsag, 0, 1234567, POCSAG_FUNCTION_NUMERIC, "1234"); + pocsag_scan_or_loopback(pocsag); return 0; @@ -371,7 +400,7 @@ void pocsag_destroy(sender_t *sender) free(pocsag); } -/* application sends ud a message, we need to deliver */ +/* application sends us a message, we need to deliver */ void pocsag_msg_send(enum pocsag_language language, const char *text) { char buffer[strlen(text) + 1], *p = buffer, *ric_string, *function_string, *message; @@ -505,6 +534,13 @@ int call_down_setup(int callref, const char __attribute__((unused)) *caller_id, return 0; } +/* message was transmitted */ +void pocsag_msg_done(pocsag_t *pocsag) +{ + /* start scanning, if enabled, otherwise send loopback sequence, if enabled */ + pocsag_scan_or_loopback(pocsag); +} + void call_down_answer(int __attribute__((unused)) callref) { } diff --git a/src/pocsag/pocsag.h b/src/pocsag/pocsag.h index 311e81a..2ebadd8 100644 --- a/src/pocsag/pocsag.h +++ b/src/pocsag/pocsag.h @@ -65,10 +65,6 @@ typedef struct pocsag { /* calls */ pocsag_msg_t *msg_list; /* linked list of all calls */ - /* display measurements */ - dispmeasparam_t *dmp_tone_level; - dispmeasparam_t *dmp_tone_quality; - /* dsp states */ double fsk_deviation; /* deviation of FSK signal on sound card */ double fsk_polarity; /* polarity of FSK signal (-1.0 = bit '1' is down) */ @@ -108,4 +104,4 @@ void pocsag_msg_send(enum pocsag_language language, const char *text); void pocsag_msg_destroy(pocsag_msg_t *msg); void pocsag_get_id(pocsag_t *euro, char *id); void pocsag_receive_id(pocsag_t *euro, char *id); - +void pocsag_msg_done(pocsag_t *pocsag);