[asterisk-commits] jdixon: branch jdixon/chan_usbradio-1.4 r150886 - /team/jdixon/chan_usbradio-...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Oct 17 21:52:53 CDT 2008


Author: jdixon
Date: Fri Oct 17 21:52:52 2008
New Revision: 150886

URL: http://svn.digium.com/view/asterisk?view=rev&rev=150886
Log:
Added new-newkey mode and phone VOX mode for remote bases

Modified:
    team/jdixon/chan_usbradio-1.4/apps/app_rpt.c

Modified: team/jdixon/chan_usbradio-1.4/apps/app_rpt.c
URL: http://svn.digium.com/view/asterisk/team/jdixon/chan_usbradio-1.4/apps/app_rpt.c?view=diff&rev=150886&r1=150885&r2=150886
==============================================================================
--- team/jdixon/chan_usbradio-1.4/apps/app_rpt.c (original)
+++ team/jdixon/chan_usbradio-1.4/apps/app_rpt.c Fri Oct 17 21:52:52 2008
@@ -22,7 +22,7 @@
 /*! \file
  *
  * \brief Radio Repeater / Remote Base program 
- *  version 0.152 10/6/08 
+ *  version 0.153 10/17/08 
  * 
  * \author Jim Dixon, WB6NIL <jim at lambdatel.com>
  *
@@ -176,7 +176,6 @@
 #define ast_strdup strdup
 #endif
 
-
 #define	MAXDTMF 32
 #define	MAXMACRO 2048
 #define	MAXLINKLIST 512
@@ -284,6 +283,8 @@
 #define	VOX_RECOVER_MS 500
 #define	SIMPLEX_PATCH_DELAY 25
 #define	SIMPLEX_PHONE_DELAY 25
+
+#define	RX_LINGER_TIME 50
 
 #define	STATPOST_PROGRAM "/usr/bin/wget,-q,--output-document=/dev/null,--no-check-certificate"
 
@@ -382,7 +383,7 @@
 /*! Stop the tones from playing */
 void ast_playtones_stop(struct ast_channel *chan);
 
-static  char *tdesc = "Radio Repeater / Remote Base  version 0.152  10/6/2008";
+static  char *tdesc = "Radio Repeater / Remote Base  version 0.153  10/17/2008";
 
 static char *app = "Rpt";
 
@@ -466,6 +467,7 @@
 
 char *discstr = "!!DISCONNECT!!";
 char *newkeystr = "!NEWKEY!";
+char *newkey1str = "!NEWKEY1!";
 static char *remote_rig_ft897="ft897";
 static char *remote_rig_rbi="rbi";
 static char *remote_rig_kenwood="kenwood";
@@ -483,7 +485,7 @@
 LOCAL_USER_DECL;
 #endif
 
-#define	MSWAIT 200
+#define	MSWAIT 20
 #define	HANGTIME 5000
 #define	TOTIME 180000
 #define	IDTIME 300000
@@ -560,6 +562,7 @@
 	long 	retrytimer;
 	long	retxtimer;
 	long	rerxtimer;
+	long	rxlingertimer;
 	int	retries;
 	int	max_retries;
 	int	reconnects;
@@ -846,10 +849,16 @@
 	int keyposttimer;			
 	char newkey;
 	char inpadtest;
+	long rxlingertimer;
 #ifdef OLD_ASTERISK
 	AST_LIST_HEAD(, ast_frame) txq;
 #else
 	AST_LIST_HEAD_NOLOCK(, ast_frame) txq;
+#endif
+#ifdef OLD_ASTERISK
+	AST_LIST_HEAD(, ast_frame) rxq;
+#else
+	AST_LIST_HEAD_NOLOCK(, ast_frame) rxq;
 #endif
 	char txrealkeyed;
 #ifdef	__RPT_NOTCH
@@ -1171,6 +1180,9 @@
 		}
 	} else v->enacount = 0;
 	return(v->lastvox);
+
+
+
 }
 
 
@@ -5779,10 +5791,15 @@
 static void send_newkey(struct ast_channel *chan)
 {
 
+	ast_sendtext(chan,newkey1str);
+	return;
+}
+
+static void send_old_newkey(struct ast_channel *chan)
+{
 	ast_sendtext(chan,newkeystr);
 	return;
 }
-
 
 /* 
  * Connect a link 
@@ -6936,7 +6953,16 @@
         }
         if (!strcmp(tmp,newkeystr))
         {
-		mylink->newkey = 1;
+		if (!mylink->newkey)
+		{
+			send_old_newkey(mylink->chan);
+			mylink->newkey = 1;
+		}
+                return;
+        }
+        if (!strcmp(tmp,newkey1str))
+        {
+		mylink->newkey = 2;
                 return;
         }
 	if (tmp[0] == 'L')
@@ -10640,7 +10666,16 @@
 	if (!strcmp(tmp,discstr)) return 0;
         if (!strcmp(tmp,newkeystr))
         {
-		myrpt->newkey = 1;
+		if (!myrpt->newkey) 
+		{
+			send_old_newkey(myrpt->rxchannel);
+			myrpt->newkey = 1;
+		}
+                return 0;
+        }
+        if (!strcmp(tmp,newkey1str))
+        {
+		myrpt->newkey = 2;
                 return 0;
         }
 
@@ -12064,6 +12099,27 @@
 		while(l != &myrpt->links)
 		{
 			int myrx,mymaxct;
+			
+			if (l->rxlingertimer) l->rxlingertimer -= elap;
+			if (l->rxlingertimer < 0) l->rxlingertimer = 0;
+
+			if ((l->newkey == 2) && l->lastrealrx && (!l->rxlingertimer))
+			{
+				l->lastrealrx = 0;
+				l->rerxtimer = 0;
+				if (l->lastrx1)
+				{
+					if (myrpt->p.archivedir)
+					{
+						char str[100];
+							sprintf(str,"RXUNKEY,%s",l->name);
+						donodelog(myrpt,str);
+					}
+					l->lastrx1 = 0;
+					if(myrpt->p.duplex) 
+						rpt_telemetry(myrpt,LINKUNKEY,l);
+				}
+			}				
 
 			if (l->voxtotimer) l->voxtotimer -= elap;
 			if (l->voxtotimer < 0) l->voxtotimer = 0;
@@ -12122,7 +12178,7 @@
 							myrpt->name,lstr,l->name);
 				}
 			}
-			if (l->newkey)
+			if (l->newkey == 1)
 			{
 				if ((l->retxtimer += elap) >= REDUNDANT_TX_TIME)
 				{
@@ -12805,7 +12861,7 @@
 				{
 					if (totx)
 					{
-						ast_indicate(l->chan,AST_CONTROL_RADIO_KEY);
+						if (l->newkey < 2) ast_indicate(l->chan,AST_CONTROL_RADIO_KEY);
 					}
 					else
 					{
@@ -12904,6 +12960,23 @@
 				{
 					int ismuted,n1;
 
+					l->rxlingertimer = RX_LINGER_TIME;
+					if ((l->newkey == 2) && (!l->lastrealrx))
+					{
+						l->lastrealrx = 1;
+						l->rerxtimer = 0;
+						if (!l->lastrx1)
+						{
+							if (myrpt->p.archivedir)
+							{
+								char str[100];
+
+								sprintf(str,"RXKEY,%s",l->name);
+								donodelog(myrpt,str);
+							}
+							l->lastrx1 = 1;
+						}
+					}
 					if (((l->phonemode) && (l->phonevox)) || 
 					    (!strncasecmp(l->chan->name,"echolink",8)) ||
 						(!strncasecmp(l->chan->name,"irlp",4)))
@@ -13049,7 +13122,7 @@
 							l->reconnects++;
 					}
 					/* if RX key */
-					if (f->subclass == AST_CONTROL_RADIO_KEY)
+					if ((f->subclass == AST_CONTROL_RADIO_KEY) && (l->newkey < 2))
 					{
 						if (debug == 7 ) printf("@@@@ rx key\n");
 						l->lastrealrx = 1;
@@ -13069,6 +13142,7 @@
 					/* if RX un-key */
 					if (f->subclass == AST_CONTROL_RADIO_UNKEY)
 					{
+
 						if (debug == 7) printf("@@@@ rx un-key\n");
 						l->lastrealrx = 0;
 						l->rerxtimer = 0;
@@ -13175,7 +13249,9 @@
 				}
 				if (f->frametype == AST_FRAME_VOICE)
 				{
-					if (l->chan) ast_write(l->chan,f);
+					if (l->chan && ((l->newkey < 2) || l->lasttx ||
+					    strncasecmp(l->chan->name,"IAX",3)))
+						ast_write(l->chan,f);
 				}
 				if (f->frametype == AST_FRAME_CONTROL)
 				{
@@ -13552,7 +13628,7 @@
 
 static int rpt_exec(struct ast_channel *chan, void *data)
 {
-	int res=-1,i,rem_totx,rem_rx,remkeyed,n,phone_mode = 0;
+	int res=-1,i,x,rem_totx,rem_rx,remkeyed,n,phone_mode = 0;
 	int iskenwood_pci4,authtold,authreq,setting,notremming,reming;
 	int ismuted,dtmfed,phone_vox = 0, phone_monitor = 0;
 #ifdef	OLD_ASTERISK
@@ -13560,7 +13636,7 @@
 #endif
 	char tmp[256], keyed = 0,keyed1 = 0;
 	char *options,*stringp,*tele,c,*altp,*memp;
-	char sx[320],*sy;
+	char sx[320],*sy,myfirst;
 	struct	rpt *myrpt;
 	struct ast_frame *f,*f1,*f2;
 	struct ast_channel *who;
@@ -13568,7 +13644,7 @@
 	struct	rpt_link *l;
 	ZT_CONFINFO ci;  /* conference info */
 	ZT_PARAMS par;
-	int ms,elap,nullfd;
+	int ms,elap,nullfd,n1,myrx;
 	time_t t,last_timeout_warning;
 	struct	zt_radio_param z;
 	struct rpt_tele *telem;
@@ -14190,6 +14266,7 @@
 #ifdef	OLD_ASTERISK
 	LOCAL_USER_ADD(u);
 #endif
+	voxinit_rpt(myrpt,1);
 	rpt_mutex_unlock(&myrpt->lock);
 	/* find our index, and load the vars initially */
 	for(i = 0; i < nrpts; i++)
@@ -14500,6 +14577,7 @@
 	if (myrpt->rxchannel != myrpt->txchannel)
 		cs[n++] = myrpt->txchannel;
 	if (!phone_mode) send_newkey(chan);
+	myfirst = 0;
 	/* start un-locked */
 	for(;;) 
 	{
@@ -14618,6 +14696,37 @@
 			if (myrpt->dtmf_local_timer > 1) myrpt->dtmf_local_timer -= elap;
 			if (myrpt->dtmf_local_timer < 1) myrpt->dtmf_local_timer = 1;
 		}
+		if (myrpt->voxtotimer) myrpt->voxtotimer -= elap;
+		if (myrpt->voxtotimer < 0) myrpt->voxtotimer = 0;
+		myrx = keyed;
+		if (phone_mode && phone_vox)
+		{
+			myrx = (!AST_LIST_EMPTY(&myrpt->rxq));
+			if (myrpt->voxtotimer <= 0)
+			{
+				if (myrpt->voxtostate)
+				{
+					myrpt->voxtotimer = myrpt->p.voxtimeout_ms;
+					myrpt->voxtostate = 0;
+				}				
+				else
+				{
+					myrpt->voxtotimer = myrpt->p.voxrecover_ms;
+					myrpt->voxtostate = 1;
+				}
+			}
+			if (!myrpt->voxtostate)
+				myrx = myrx || myrpt->wasvox ;
+		}
+		keyed = myrx;
+		if (myrpt->rxlingertimer) myrpt->rxlingertimer -= elap;
+		if (myrpt->rxlingertimer < 0) myrpt->rxlingertimer = 0;
+
+		if ((myrpt->newkey == 2) && keyed && (!myrpt->rxlingertimer))
+		{
+			myrpt->rerxtimer = 0;
+			keyed = 0;
+		}
 		rpt_mutex_lock(&myrpt->lock);
 		do_dtmf_local(myrpt,0);
 		rpt_mutex_unlock(&myrpt->lock);
@@ -14656,7 +14765,7 @@
 		if (rem_rx && (!myrpt->remoterx))
 		{
 			myrpt->remoterx = 1;
-			ast_indicate(chan,AST_CONTROL_RADIO_KEY);
+			if (myrpt->newkey < 2) ast_indicate(chan,AST_CONTROL_RADIO_KEY);
 		}
 		if ((!rem_rx) && (myrpt->remoterx))
 		{
@@ -14677,7 +14786,7 @@
 				break; /* if not logged in, hang up after a time */
 			}
 		}
-		if (myrpt->newkey)
+		if (myrpt->newkey == 1)
 		{
 			if ((myrpt->retxtimer += elap) >= REDUNDANT_TX_TIME)
 			{
@@ -14784,6 +14893,58 @@
 			}
 			if (f->frametype == AST_FRAME_VOICE)
 			{
+				if (myrpt->newkey == 2)
+				{
+					myrpt->rxlingertimer = RX_LINGER_TIME;
+					if (!keyed)
+					{
+						keyed = 1;
+						myrpt->rerxtimer = 0;
+					}
+				}
+				if (phone_mode && phone_vox)
+				{
+					n1 = dovox(&myrpt->vox,
+						f->data,f->datalen / 2);
+					if (n1 != myrpt->wasvox)
+					{
+						if (debug) ast_log(LOG_DEBUG,"Remote  vox %d\n",n1);
+						myrpt->wasvox = n1;
+						myrpt->voxtostate = 0;
+						if (n1) myrpt->voxtotimer = myrpt->p.voxtimeout_ms;
+						else myrpt->voxtotimer = 0;
+					}
+					if (n1)
+					{
+						if (!myfirst)
+						{
+						    x = 0;
+						    AST_LIST_TRAVERSE(&myrpt->rxq, f1,
+							frame_list) x++;
+						    for(;x < myrpt->p.simplexphonedelay; x++)
+						    {
+							f1 = ast_frdup(f);
+							memset(f1->data,0,f1->datalen);
+								AST_LIST_INSERT_TAIL(&myrpt->rxq,
+									f1,frame_list);
+						    }
+						    myfirst = 1;
+						}
+						f1 = ast_frdup(f);
+						AST_LIST_INSERT_TAIL(&myrpt->rxq,f1,frame_list);
+					} else myfirst = 0; 
+					x = 0;
+					AST_LIST_TRAVERSE(&myrpt->rxq, f1,frame_list) x++;
+					if (!x)
+					{
+						memset(f->data,0,f->datalen);
+					}
+					else
+					{
+						ast_frfree(f);
+						f = AST_LIST_REMOVE_HEAD(&myrpt->rxq,frame_list);
+					}
+				}
 				if (ioctl(chan->fds[0], ZT_GETCONFMUTE, &ismuted) == -1)
 				{
 					ismuted = 0;
@@ -14863,7 +15024,7 @@
 					break;
 				}
 				/* if RX key */
-				if (f->subclass == AST_CONTROL_RADIO_KEY)
+				if ((f->subclass == AST_CONTROL_RADIO_KEY) && (myrpt->newkey < 2))
 				{
 					if (debug == 7) printf("@@@@ rx key\n");
 					keyed = 1;
@@ -14942,7 +15103,9 @@
 			}
 			if (f->frametype == AST_FRAME_VOICE)
 			{
-				ast_write(chan,f);
+				if ((myrpt->newkey < 2) || myrpt->remoterx ||
+				    strncasecmp(chan->name,"IAX",3))
+					ast_write(chan,f);
 			}
 			if (f->frametype == AST_FRAME_CONTROL)
 			{




More information about the asterisk-commits mailing list