Add option to handle pulses from Swedish rotary phones correctly

Ten pulses represents '0', nine pulses respresent '1', ect...
This commit is contained in:
Andreas Eversberg 2023-04-08 11:17:56 +02:00
parent da2abace4f
commit 2b47760540
3 changed files with 29 additions and 9 deletions

View File

@ -36,7 +36,7 @@ int num_kanal = 1;
#define SUBSCRIBER_MAX 16
static char law = 'a';
static int sweden = 0;
static enum pulse_coding pulse_coding = PULSE_DEFAULT;
static int serving_location = 1; /* private network serving local user */
static const char *socketname = NULL;
static const char *name = "pstn";
@ -127,6 +127,9 @@ static void print_help()
printf(" --sweden\n");
printf(" Translate pulses from Swedish rotary phone into digits. One pulse is\n");
printf(" digit '0', two pulses are digit '1', and so on.\n");
printf(" --new-zealand\n");
printf(" Translate pulses from New Zealand rotary phone into digits. Ten pulses\n");
printf(" area '0', nine pulses digit '9', and so on.\n");
printf(" -r --realtime <prio>\n");
printf(" Set prio: 0 to disable, 99 for maximum (default = %d)\n", rt_prio);
printf(" -C --cc \"<osmo-cc arg>\" [--cc ...]\n");
@ -163,6 +166,7 @@ static void print_recall()
#define OPT_ULAW 265
#define OPT_SERVING 266
#define OPT_SWEDEN 267
#define OPT_NEWZEALAND 268
static void add_options(void)
{
@ -185,6 +189,7 @@ static void add_options(void)
option_add(OPT_ULAW, "ulaw", 0);
option_add(OPT_SERVING, "serving-location", 1);
option_add(OPT_SWEDEN, "sweden", 0);
option_add(OPT_NEWZEALAND, "new-zealand", 0);
option_add('r', "realtime", 1);
option_add('C', "cc", 1);
}
@ -294,7 +299,10 @@ static int handle_options(int short_option, int argi, char **argv)
serving_location = atoi(argv[argi]);;
break;
case OPT_SWEDEN:
sweden = 1;
pulse_coding = PULSE_SWEDEN;
break;
case OPT_NEWZEALAND:
pulse_coding = PULSE_NEWZEALAND;
break;
case 'r':
rt_prio = atoi(argv[argi]);
@ -371,7 +379,7 @@ int main(int argc, char *argv[])
if (!pstn_ep)
goto error;
rc = pstn_init(pstn_ep, name, socketname, subscribers, subscriber_num, serving_location, tx_delay, clip, cid_bell, cid_dtmf, clip_date, enblock, recall, ringing_types_incoming, ringing_type_hold, tones_type, law, sweden);
rc = pstn_init(pstn_ep, name, socketname, subscribers, subscriber_num, serving_location, tx_delay, clip, cid_bell, cid_dtmf, clip_date, enblock, recall, ringing_types_incoming, ringing_type_hold, tones_type, law, pulse_coding);
if (rc) {
PDEBUG(DTEL, DEBUG_ERROR, "Endpoint initializing failed!\n");
goto error;

View File

@ -417,7 +417,7 @@ static void pstn_new_state(pstn_t *pstn, enum pstn_state state)
}
/* initialization and configuration of interface instance */
int pstn_init(pstn_t *pstn, const char *name, const char *socketname, const char **subscribers, int subscriber_num, uint8_t serving_location, int tx_delay, enum pstn_cid_method clip, int cid_bell, int cid_dtmf, int clip_date, int enblock, int recall, int *ringing_types_incoming, int ringing_type_hold, enum tones_type tones_type, char law, int sweden)
int pstn_init(pstn_t *pstn, const char *name, const char *socketname, const char **subscribers, int subscriber_num, uint8_t serving_location, int tx_delay, enum pstn_cid_method clip, int cid_bell, int cid_dtmf, int clip_date, int enblock, int recall, int *ringing_types_incoming, int ringing_type_hold, enum tones_type tones_type, char law, enum pulse_coding pulse_coding)
{
int i;
int rc;
@ -437,7 +437,7 @@ int pstn_init(pstn_t *pstn, const char *name, const char *socketname, const char
pstn->ringing_types_incoming = ringing_types_incoming;
pstn->ringing_type_hold = ringing_type_hold;
pstn->tones_type = tones_type;
pstn->sweden = sweden;
pstn->pulse_coding = pulse_coding;
/* init DTMF detector */
rc = dtmf_decode_init(&pstn->dtmf_dec, pstn, recv_dtmf, 8000, db2level(6.0), db2level(-30.0));
@ -1628,10 +1628,16 @@ static void v5_sig_ind(pstn_t *pstn, uint8_t *data, int len)
called[0] = 'c';
break;
default:
if (pstn->sweden)
switch (pstn->pulse_coding) {
case PULSE_SWEDEN:
called[0] = '0' + (((data[2] & 0x0f) + 9) % 10);
else
break;
case PULSE_NEWZEALAND:
called[0] = '9' - (((data[2] & 0x0f) + 9) % 10);
break;
default:
called[0] = '0' + ((data[2] & 0x0f) % 10);
}
}
/* if we are receiving digits en block */
if (pstn->call[PSTN_CALL_ACTIVE]->state == CALL_STATE_ENBLOCK) {

View File

@ -92,6 +92,12 @@ enum tones_type {
TONES_TYPE_OLDGERMAN,
};
enum pulse_coding {
PULSE_DEFAULT,
PULSE_SWEDEN,
PULSE_NEWZEALAND,
};
struct pstn;
struct call {
@ -131,7 +137,7 @@ typedef struct pstn {
int *ringing_types_incoming;/* cadenced rining on incoming call */
int ringing_type_hold; /* cadenced rining on waiting call */
enum tones_type tones_type; /* what tone set to use */
int sweden; /* swedish rotary phone */
enum pulse_coding pulse_coding; /* pulse mapping */
/* states */
enum pstn_state state;
@ -166,6 +172,6 @@ int add_dial_hint(const char *arg);
void purge_dial_hints(void);
void pstn_destroy(pstn_t *pstn_ep);
pstn_t *pstn_create(void);
int pstn_init(pstn_t *pstn, const char *name, const char *socketname, const char **subscribers, int subscriber_num, uint8_t serving_location, int tx_delay, enum pstn_cid_method clip, int cid_bell, int cid_dtmf, int clip_date, int enblock, int recall, int *ringing_types_incoming, int ringing_type_hold, enum tones_type tones_type, char law, int sweden);
int pstn_init(pstn_t *pstn, const char *name, const char *socketname, const char **subscribers, int subscriber_num, uint8_t serving_location, int tx_delay, enum pstn_cid_method clip, int cid_bell, int cid_dtmf, int clip_date, int enblock, int recall, int *ringing_types_incoming, int ringing_type_hold, enum tones_type tones_type, char law, enum pulse_coding pulse_coding);
void cc_message(osmo_cc_endpoint_t *ep, uint32_t callref, osmo_cc_msg_t *msg);
void rtp_work(pstn_t *pstn_ep);