Newer
Older
/*
* Asterisk -- An open source telephony toolkit.
* Copyright (C) 2002-2005, Jim Dixon, WB6NIL
* Jim Dixon, WB6NIL <jim@lambdatel.com>
* Serious contributions by Steve RoDgers, WA6ZFT <hwstar@rodgers.sdcoxmail.com>
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*
* Radio Repeater / Remote Base program
*
* See http://www.zapatatelephony.org/app_rpt.html
*
* Repeater / Remote Functions:
* "Simple" Mode: * - autopatch access, # - autopatch hangup
* Normal mode:
* See the function list in rpt.conf
*
* To send an asterisk (*) while dialing or talking on phone,
* use the autopatch acess code.
*
*
* status cmds:
*
* 1 - Force ID
* 2 - Give Time of Day
* 3 - Give software Version
*
* cop (control operator) cmds:
*
* 1 - System warm boot
* 2 - System enable
* 3 - System disable
* 4 - Test Tone On
* 5 - Dump System Variables on Console (debug)
* 6 - PTT (phone mode only)
*
* ilink cmds:
*
* 1 - Disconnect specified link
* 2 - Connect specified link -- monitor only
* 3 - Connect specified link -- tranceive
* 4 - Enter command mode on specified link
* 5 - System status
* 6 - Disconnect all links
*
* remote cmds:
*
* 1 - Recall Memory MM (*000-*099) (Gets memory from rpt.conf)
* 2 - Set VFO MMMMM*KKK*O (Mhz digits, Khz digits, Offset)
* 3 - Set Rx PL Tone HHH*D*
* 4 - Set Tx PL Tone HHH*D* (Not currently implemented with DHE RBI-1)
* 5 - Link Status (long)
* 6 - Set operating mode M (FM, USB, LSB, AM, etc)
* 100 - RX PL off (Default)
* 101 - RX PL On
* 102 - TX PL Off (Default)
* 103 - TX PL On
* 104 - Low Power
* 105 - Med Power
* 106 - Hi Power
* 107 - Bump Down 20 Hz
* 108 - Bump Down 100 Hz
* 109 - Bump Down 500 Hz
* 110 - Bump Up 20 Hz
* 111 - Bump Up 100 Hz
* 112 - Bump Up 500 Hz
* 113 - Scan Down Slow
* 114 - Scan Down Medium
* 115 - Scan Down Fast
* 116 - Scan Up Slow
* 117 - Scan Up Medium
* 118 - Scan Up Fast
* 119 - Transmit allowing auto-tune
* 140 - Link Status (brief)
*
*
*/
/* The following is JUST GROSS!! There is some soft of underlying problem,
probably in channel_iax2.c, that causes an IAX2 connection to sometimes
stop transmitting randomly. We have been working for weeks to try to
locate it and fix it, but to no avail We finally decided to put our
tail between our legs, and just make the radio system re-connect upon
network failure. This just shouldnt have to be done. For normal operation,
comment-out the following line */
#define RECONNECT_KLUDGE
/* maximum digits in DTMF buffer, and seconds after * for DTMF command timeout */
#define MAXDTMF 32
#define DTMF_TIMEOUT 3
#define DISC_TIME 10000 /* report disc after 10 seconds of no connect */
#define MAX_RETRIES 5
#define MAXREMSTR 15
#define NODES "nodes"
#define MEMORY "memory"
#define FUNCTIONS "functions"
#define TELEMETRY "telemetry"
#define MORSE "morse"
#define FUNCCHAR '*'
#define ENDCHAR '#'
#define DEFAULT_IOBASE 0x378
#define MAXCONNECTTIME 5000
#define MAXNODESTR 300
#define ACTIONSIZE 32
#define TELEPARAMSIZE 256
#define REM_SCANTIME 100
enum {REM_OFF,REM_MONITOR,REM_TX};
enum{ID,PROC,TERM,COMPLETE,UNKEY,REMDISC,REMALREADY,REMNOTFOUND,REMGO,
CONNECTED,CONNFAIL,STATUS,TIMEOUT,ID1, STATS_TIME,
STATS_VERSION, IDTALKOVER, ARB_ALPHA, TEST_TONE, REV_PATCH};
enum {REM_SIMPLEX,REM_MINUS,REM_PLUS};
enum {REM_LOWPWR,REM_MEDPWR,REM_HIPWR};
enum {DC_INDETERMINATE, DC_REQ_FLUSH, DC_ERROR, DC_COMPLETE, DC_DOKEY};
enum {SOURCE_RPT, SOURCE_LNK, SOURCE_RMT, SOURCE_PHONE, SOURCE_DPHONE};
enum {DLY_TELEM, DLY_ID, DLY_UNKEY, DLY_CALLTERM};
enum {REM_MODE_FM,REM_MODE_USB,REM_MODE_LSB,REM_MODE_AM};
enum {HF_SCAN_OFF,HF_SCAN_DOWN_SLOW,HF_SCAN_DOWN_QUICK,HF_SCAN_DOWN_FAST,HF_SCAN_UP_SLOW,HF_SCAN_UP_QUICK,HF_SCAN_UP_FAST};
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <search.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <dirent.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/io.h>
#include <math.h>
#include <tonezone.h>
#include <linux/zaptel.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/file.h"
#include "asterisk/logger.h"
#include "asterisk/channel.h"
#include "asterisk/callerid.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/translate.h"
#include "asterisk/features.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/config.h"
#include "asterisk/say.h"
#include "asterisk/localtime.h"
static char *tdesc = "Radio Repeater / Remote Base version 0.37 11/03/2005";
static char *app = "Rpt";
static char *synopsis = "Radio Repeater/Remote Base Control System";
static char *descrip =
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
" Rpt(nodename[|options]): Radio Remote Link or Remote Base Link Endpoint Process.\n"
"\n"
" Not specifying an option puts it in normal endpoint mode (where source\n"
" IP and nodename are verified).\n"
"\n"
" Options are as follows:\n"
"\n"
" X - Normal endpoint mode WITHOUT security check. Only specify\n"
" this if you have checked security already (like with an IAX2\n"
" user/password or something).\n"
"\n"
" Rannounce-string[|timeout[|timeout-destination]] - Amateur Radio\n"
" Reverse Autopatch. Caller is put on hold, and announcement (as\n"
" specified by the 'announce-string') is played on radio system.\n"
" Users of radio system can access autopatch, dial specified\n"
" code, and pick up call. Announce-string is list of names of\n"
" recordings, or \"PARKED\" to substitute code for un-parking,\n"
" or \"NODE\" to substitute node number.\n"
"\n"
" P - Phone Control mode. This allows a regular phone user to have\n"
" full control and audio access to the radio system. For the\n"
" user to have DTMF control, the 'phone_functions' parameter\n"
" must be specified for the node in 'rpt.conf'. An additional\n"
" function (cop,6) must be listed so that PTT control is available.\n"
"\n"
" D - Dumb Phone Control mode. This allows a regular phone user to\n"
" have full control and audio access to the radio system. In this\n"
" mode, the PTT is activated for the entire length of the call.\n"
" For the user to have DTMF control (not generally recomended in\n"
" this mode), the 'dphone_functions' parameter must be specified\n"
" for the node in 'rpt.conf'. Otherwise no DTMF control will be\n"
" available to the phone user.\n"
"\n";
static int debug = 0; /* Set this >0 for extra debug output */
static int nrpts = 0;
static char *remote_rig_ft897="ft897";
static char *remote_rig_rbi="rbi";
struct ast_config *cfg;
STANDARD_LOCAL_USER;
LOCAL_USER_DECL;
#define MSWAIT 200
#define HANGTIME 5000
#define TOTIME 180000
#define IDTIME 300000
#define MAXRPTS 20
Jim Dixon
committed
#define POLITEID 30000
#define FUNCTDELAY 1500
struct rpt;
struct rpt_link
{
struct rpt_link *next;
struct rpt_link *prev;
char mode; /* 1 if in tx mode */
char isremote;
char phonemode;
char name[MAXNODESTR]; /* identifier (routing) string */
char lasttx;
char lastrx;
char connected;
char outbound;
long elaptime;
long disctime;
long retrytimer;
struct ast_channel *chan;
struct ast_channel *pchan;
} ;
struct rpt_tele
{
struct rpt_tele *next;
struct rpt_tele *prev;
struct rpt *rpt;
struct ast_channel *chan;
int mode;
struct rpt_link mylink;
char param[TELEPARAMSIZE];
pthread_t threadid;
} ;
struct function_table_tag
{
char action[ACTIONSIZE];
int (*function)(struct rpt *myrpt, char *param, char *digitbuf,
int command_source, struct rpt_link *mylink);
} ;
/* Used to store the morse code patterns */
struct morse_bits
{
int len;
int ddcomb;
} ;
struct telem_defaults
{
char name[20];
char value[80];
} ;
ast_mutex_t lock;
char *rxchanname;
char *txchanname;
char *ourcontext;
char *ourcallerid;
char *acctcode;
char *ident;
char *tonezone;
char *functions;
char *link_functions;
char *phone_functions;
char *dphone_functions;
char *nodes;
struct rpt_link links;
int unkeytocttimer;
char keyed;
char exttx;
char localtx;
char remoterx;
char remotetx;
char remoteon;
char simple;
char *remote;
char tounkeyed;
char tonotify;
char enable;
char dtmfbuf[MAXDTMF];
char rem_dtmfbuf[MAXDTMF];
char cmdnode[50];
struct ast_channel *rxchannel,*txchannel;
struct ast_channel *pchannel,*txpchannel, *remchannel;
struct rpt_tele tele;
pthread_t rpt_call_thread,rpt_thread;
time_t rem_dtmf_time,dtmf_time_rem;
int tailtimer,totimer,idtimer,txconf,conf,callmode,cidx,scantimer;
Jim Dixon
committed
int mustid;
int politeid;
int dtmfidx,rem_dtmfidx;
char mydtmf;
int iobase;
char freq[MAXREMSTR],rxpl[MAXREMSTR],txpl[MAXREMSTR];
char offset;
char powerlevel;
char txplon;
char rxplon;
char remmode;
char tunerequest;
char hfscanmode;
int hfscanstatus;
char lastlinknode[MAXNODESTR];
char funcchar;
char endchar;
int phone_longestfunc;
int dphone_longestfunc;
int link_longestfunc;
int longestfunc;
int longestnode;
int threadrestarts;
time_t disgorgetime;
time_t lastthreadrestarttime;
char nobusyout;
} rpt_vars[MAXRPTS];
/*
* CLI extensions
*/
/* Debug mode */
static int rpt_do_debug(int fd, int argc, char *argv[]);
static char debug_usage[] =
"Usage: rpt debug level {0-7}\n"
" Enables debug messages in app_rpt\n";
static struct ast_cli_entry cli_debug =
{ { "rpt", "debug", "level" }, rpt_do_debug, "Enable app_rpt debugging", debug_usage };
/*
* Telemetry defaults
*/
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
static struct telem_defaults tele_defs[] = {
{"ct1","|t(350,0,100,3072)(500,0,100,3072)(660,0,100,3072)"},
{"ct2","|t(660,880,150,3072)"},
{"ct3","|t(440,0,150,3072)"},
{"ct4","|t(550,0,150,3072)"},
{"ct5","|t(660,0,150,3072)"},
{"ct6","|t(880,0,150,3072)"},
{"ct7","|t(660,440,150,3072)"},
{"ct8","|t(700,1100,150,3072)"},
{"remotemon","|t(1600,0,75,2048)"},
{"remotetx","|t(2000,0,75,2048)(0,0,75,0)(1600,0,75,2048)"},
{"cmdmode","|t(900,904,200,2048)"},
{"functcomplete","|t(1000,0,100,2048)(0,0,100,0)(1000,0,100,2048)"}
} ;
/*
* Forward decl's - these suppress compiler warnings when funcs coded further down the file than thier invokation
*/
static int setrbi(struct rpt *myrpt);
/*
* Define function protos for function table here
*/
static int function_ilink(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
static int function_autopatchup(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
static int function_autopatchdn(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
static int function_status(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
static int function_cop(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
static int function_remote(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
/*
* Function table
*/
static struct function_table_tag function_table[] = {
{"cop", function_cop},
{"autopatchup", function_autopatchup},
{"autopatchdn", function_autopatchdn},
{"ilink", function_ilink},
{"status", function_status},
{"remote", function_remote}
} ;
static int myatoi(char *str)
{
int ret;
if (str == NULL) return -1;
/* leave this %i alone, non-base-10 input is useful here */
if (sscanf(str,"%i",&ret) != 1) return -1;
return ret;
}
/*
* Enable or disable debug output at a given level at the console
*/
static int rpt_do_debug(int fd, int argc, char *argv[])
{
int newlevel;
if (argc != 4)
return RESULT_SHOWUSAGE;
newlevel = myatoi(argv[3]);
if((newlevel < 0) || (newlevel > 7))
return RESULT_SHOWUSAGE;
if(newlevel)
ast_cli(fd, "app_rpt Debugging enabled, previous level: %d, new level: %d\n", debug, newlevel);
else
ast_cli(fd, "app_rpt Debugging disabled\n");
debug = newlevel;
return RESULT_SUCCESS;
}
static int play_tone_pair(struct ast_channel *chan, int f1, int f2, int duration, int amplitude)
{
int res;
if ((res = ast_tonepair_start(chan, f1, f2, duration, amplitude)))
return res;
while(chan->generatordata) {
if (ast_safe_sleep(chan,1)) return -1;
}
return 0;
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
}
static int play_tone(struct ast_channel *chan, int freq, int duration, int amplitude)
{
return play_tone_pair(chan, freq, 0, duration, amplitude);
}
static int play_silence(struct ast_channel *chan, int duration)
{
return play_tone_pair(chan, 0, 0, duration, 0);
}
static int send_morse(struct ast_channel *chan, char *string, int speed, int freq, int amplitude)
{
static struct morse_bits mbits[] = {
{0, 0}, /* SPACE */
{0, 0},
{6, 18},/* " */
{0, 0},
{7, 72},/* $ */
{0, 0},
{0, 0},
{6, 30},/* ' */
{5, 13},/* ( */
{6, 29},/* ) */
{0, 0},
{5, 10},/* + */
{6, 51},/* , */
{6, 33},/* - */
{6, 42},/* . */
{5, 9}, /* / */
{5, 31},/* 0 */
{5, 30},/* 1 */
{5, 28},/* 2 */
{5, 24},/* 3 */
{5, 16},/* 4 */
{5, 0}, /* 5 */
{5, 1}, /* 6 */
{5, 3}, /* 7 */
{5, 7}, /* 8 */
{5, 15},/* 9 */
{6, 7}, /* : */
{6, 21},/* ; */
{0, 0},
{5, 33},/* = */
{0, 0},
{6, 12},/* ? */
{0, 0},
{2, 2}, /* A */
{4, 1}, /* B */
{4, 5}, /* C */
{3, 1}, /* D */
{1, 0}, /* E */
{4, 4}, /* F */
{3, 3}, /* G */
{4, 0}, /* H */
{2, 0}, /* I */
{4, 14},/* J */
{3, 5}, /* K */
{4, 2}, /* L */
{2, 3}, /* M */
{2, 1}, /* N */
{3, 7}, /* O */
{4, 6}, /* P */
{4, 11},/* Q */
{3, 2}, /* R */
{3, 0}, /* S */
{1, 1}, /* T */
{3, 4}, /* U */
{4, 8}, /* V */
{3, 6}, /* W */
{4, 9}, /* X */
{4, 13},/* Y */
{4, 3} /* Z */
};
int dottime;
int dashtime;
int intralettertime;
int interlettertime;
int interwordtime;
int len, ddcomb;
int res;
int c;
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
res = 0;
/* Approximate the dot time from the speed arg. */
dottime = 900/speed;
/* Establish timing releationships */
dashtime = 3 * dottime;
intralettertime = dottime;
interlettertime = dottime * 4 ;
interwordtime = dottime * 7;
for(;(*string) && (!res); string++){
c = *string;
/* Convert lower case to upper case */
if((c >= 'a') && (c <= 'z'))
c -= 0x20;
/* Can't deal with any char code greater than Z, skip it */
if(c > 'Z')
continue;
/* If space char, wait the inter word time */
if(c == ' '){
if(!res)
res = play_silence(chan, interwordtime);
continue;
}
/* Subtract out control char offset to match our table */
c -= 0x20;
/* Get the character data */
len = mbits[c].len;
ddcomb = mbits[c].ddcomb;
/* Send the character */
for(; len ; len--){
if(!res)
res = play_tone(chan, freq, (ddcomb & 1) ? dashtime : dottime, amplitude);
if(!res)
res = play_silence(chan, intralettertime);
ddcomb >>= 1;
}
/* Wait the interletter time */
if(!res)
res = play_silence(chan, interlettertime - intralettertime);
}
/* Wait for all the frames to be sent */
if (!res)
res = ast_waitstream(chan, "");
ast_stopstream(chan);
/*
* Wait for the zaptel driver to physically write the tone blocks to the hardware
*/
for(i = 0; i < 20 ; i++){
flags = ZT_IOMUX_WRITEEMPTY | ZT_IOMUX_NOWAIT;
res = ioctl(chan->fds[0], ZT_IOMUX, &flags);
if(flags & ZT_IOMUX_WRITEEMPTY)
break;
if( ast_safe_sleep(chan, 50)){
res = -1;
break;
}
}
return res;
}
static int send_tone_telemetry(struct ast_channel *chan, char *tonestring)
{
char *stringp;
char *tonesubset;
int f1,f2;
int duration;
int amplitude;
int res;
res = 0;
stringp = ast_strdupa(tonestring);
for(;tonestring;){
tonesubset = strsep(&stringp,")");
if(!tonesubset)
break;
if(sscanf(tonesubset,"(%d,%d,%d,%d", &f1, &f2, &duration, &litude) != 4)
break;
res = play_tone_pair(chan, f1, f2, duration, amplitude);
if(res)
break;
}
if(!res)
res = play_tone_pair(chan, 0, 0, 100, 0); /* This is needed to ensure the last tone segment is timed correctly */
if (!res)
res = ast_waitstream(chan, "");
ast_stopstream(chan);
/*
* Wait for the zaptel driver to physically write the tone blocks to the hardware
*/
for(i = 0; i < 20 ; i++){
flags = ZT_IOMUX_WRITEEMPTY | ZT_IOMUX_NOWAIT;
res = ioctl(chan->fds[0], ZT_IOMUX, &flags);
if(flags & ZT_IOMUX_WRITEEMPTY)
break;
if( ast_safe_sleep(chan, 50)){
res = -1;
break;
}
}
return res;
}
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
static int sayfile(struct ast_channel *mychannel,char *fname)
{
int res;
res = ast_streamfile(mychannel, fname, mychannel->language);
if (!res)
res = ast_waitstream(mychannel, "");
else
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
ast_stopstream(mychannel);
return res;
}
static int saycharstr(struct ast_channel *mychannel,char *str)
{
int res;
res = ast_say_character_str(mychannel,str,NULL,mychannel->language);
if (!res)
res = ast_waitstream(mychannel, "");
else
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
ast_stopstream(mychannel);
return res;
}
static int saynum(struct ast_channel *mychannel, int num)
{
int res;
res = ast_say_number(mychannel, num, NULL, mychannel->language, NULL);
if(!res)
res = ast_waitstream(mychannel, "");
else
ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
ast_stopstream(mychannel);
return res;
}
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
/* Retrieve an int from a config file */
static int retrieve_astcfgint(char *category, char *name, int min, int max, int defl)
{
char *var;
int ret;
var = ast_variable_retrieve(cfg, category, name);
if(var){
ret = myatoi(var);
if(ret < min)
ret = min;
if(ret > max)
ret = max;
}
else
ret = defl;
return ret;
}
static int telem_any(struct ast_channel *chan, char *entry)
{
int res;
char c;
static int morsespeed;
static int morsefreq;
static int morseampl;
static int morseidfreq = 0;
static int morseidampl;
static char mcat[] = MORSE;
res = 0;
if(!morseidfreq){ /* Get the morse parameters if not already loaded */
morsespeed = retrieve_astcfgint( mcat, "speed", 5, 20, 20);
morsefreq = retrieve_astcfgint( mcat, "frequency", 300, 3000, 800);
morseampl = retrieve_astcfgint( mcat, "amplitude", 200, 8192, 4096);
morseidampl = retrieve_astcfgint( mcat, "idamplitude", 200, 8192, 2048);
morseidfreq = retrieve_astcfgint( mcat, "idfrequency", 300, 3000, 330);
}
/* Is it a file, or a tone sequence? */
if(entry[0] == '|'){
c = entry[1];
if((c >= 'a')&&(c <= 'z'))
c -= 0x20;
switch(c){
case 'I': /* Morse ID */
res = send_morse(chan, entry + 2, morsespeed, morseidfreq, morseidampl);
break;
case 'M': /* Morse Message */
res = send_morse(chan, entry + 2, morsespeed, morsefreq, morseampl);
break;
case 'T': /* Tone sequence */
res = send_tone_telemetry(chan, entry + 2);
break;
default:
res = -1;
}
}
else
res = sayfile(chan, entry); /* File */
return res;
}
/*
* This function looks up a telemetry name in the config file, and does a telemetry response as configured.
*
* 4 types of telemtry are handled: Morse ID, Morse Message, Tone Sequence, and a File containing a recording.
*/
static int telem_lookup(struct ast_channel *chan, char *node, char *name)
{
int res;
int i;
char *entry;
char *telemetry;
char *telemetry_save;
res = 0;
telemetry_save = NULL;
entry = NULL;
/* Retrieve the section name for telemetry from the node section */
telemetry = ast_variable_retrieve(cfg, node, TELEMETRY);
if(telemetry){
telemetry_save = ast_strdupa(telemetry);
if(!telemetry_save){
ast_log(LOG_WARNING,"ast_strdupa() failed in telem_lookup()\n");
return res;
}
entry = ast_variable_retrieve(cfg, telemetry_save, name);
}
/* Try to look up the telemetry name */
if(!entry){
/* Telemetry name wasn't found in the config file, use the default */
for(i = 0; i < sizeof(tele_defs)/sizeof(struct telem_defaults) ; i++){
if(!strcasecmp(tele_defs[i].name, name))
entry = tele_defs[i].value;
}
}
if(entry)
telem_any(chan, entry);
else{
ast_log(LOG_WARNING, "Telemetry name not found: %s\n", name);
res = -1;
}
return res;
}
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
/*
* Retrieve a wait interval
*/
static int get_wait_interval(struct rpt *myrpt, int type)
{
int interval;
char *wait_times;
char *wait_times_save;
wait_times_save = NULL;
wait_times = ast_variable_retrieve(cfg, myrpt->name, "wait_times");
if(wait_times){
wait_times_save = ast_strdupa(wait_times);
if(!wait_times_save){
ast_log(LOG_WARNING, "Out of memory in wait_interval()\n");
wait_times = NULL;
}
}
switch(type){
case DLY_TELEM:
if(wait_times)
interval = retrieve_astcfgint(wait_times_save, "telemwait", 500, 5000, 1000);
else
interval = 1000;
break;
case DLY_ID:
if(wait_times)
interval = retrieve_astcfgint(wait_times_save, "idwait",250,5000,500);
else
interval = 500;
break;
case DLY_UNKEY:
if(wait_times)
interval = retrieve_astcfgint(wait_times_save, "unkeywait",500,5000,1000);
else
interval = 1000;
break;
case DLY_CALLTERM:
if(wait_times)
interval = retrieve_astcfgint(wait_times_save, "calltermwait",500,5000,1500);
else
interval = 1500;
break;
default:
return 0;
}
return interval;
}
/*
* Wait a configurable interval of time
*/
static void wait_interval(struct rpt *myrpt, int type, struct ast_channel *chan)
{
int interval;
if((interval = get_wait_interval(myrpt, type)))
ast_safe_sleep(chan,interval);
return;
}
static void *rpt_tele_thread(void *this)
int res = 0,haslink,hastx,hasremote,imdone = 0, unkeys_queued, x;
struct rpt_tele *mytele = (struct rpt_tele *)this;
struct rpt_tele *tlist;
struct rpt *myrpt;
struct rpt_link *l,*m,linkbase;
struct ast_channel *mychannel;
char *p,*ct,*ct_copy,*ident, *nodename;
/* get a pointer to myrpt */
myrpt = mytele->rpt;
/* Snag copies of a few key myrpt variables */
ast_mutex_lock(&myrpt->lock);
nodename = ast_strdupa(myrpt->name);
ident = ast_strdupa(myrpt->ident);
ast_mutex_unlock(&myrpt->lock);
mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
if (!mychannel)
{
fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
remque((struct qelem *)mytele);
ast_mutex_unlock(&myrpt->lock);
free(mytele);