[svn-commits] jdixon: branch jdixon/chan_usbradio-1.4 r116696 - /team/jdixon/chan_usbradio-...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Thu May 15 17:45:06 CDT 2008
Author: jdixon
Date: Thu May 15 17:45:06 2008
New Revision: 116696
URL: http://svn.digium.com/view/asterisk?view=rev&rev=116696
Log:
Many fixes and works now with 1.6
Modified:
team/jdixon/chan_usbradio-1.4/channels/chan_usbradio.c
Modified: team/jdixon/chan_usbradio-1.4/channels/chan_usbradio.c
URL: http://svn.digium.com/view/asterisk/team/jdixon/chan_usbradio-1.4/channels/chan_usbradio.c?view=diff&rev=116696&r1=116695&r2=116696
==============================================================================
--- team/jdixon/chan_usbradio-1.4/channels/chan_usbradio.c (original)
+++ team/jdixon/chan_usbradio-1.4/channels/chan_usbradio.c Thu May 15 17:45:06 2008
@@ -1,3 +1,4 @@
+/* #define NEW_ASTERISK */
/*
* Asterisk -- An open source telephony toolkit.
*
@@ -34,13 +35,6 @@
/*** MODULEINFO
<depend>ossaudio</depend>
- <depend>usb</depend>
- <member name="RADIO_RTX" displayname="Build RTX/DTX Radio Programming">
- <defaultenabled>no</defaultenabled>
- </member>
- <member name="RADIO_XPMRX" displayname="Build Experimental Radio Protocols">
- <defaultenabled>no</defaultenabled>
- </member>
***/
// 20070918 1600 EDT sph at xelatec.com changing to rx driven streams
@@ -140,11 +134,15 @@
#include "asterisk/musiconhold.h"
#include "asterisk/dsp.h"
+#ifndef NEW_ASTERISK
+
/* ringtones we use */
#include "busy.h"
#include "ringtone.h"
#include "ring10.h"
#include "answer.h"
+
+#endif
#define C108_VENDOR_ID 0x0d8c
#define C108_PRODUCT_ID 0x000c
@@ -381,6 +379,8 @@
int repeat;
};
+#ifndef NEW_ASTERISK
+
static struct sound sounds[] = {
{ AST_CONTROL_RINGING, "RINGING", ringtone, sizeof(ringtone)/2, 16000, 32000, 1 },
{ AST_CONTROL_BUSY, "BUSY", busy, sizeof(busy)/2, 4000, 4000, 1 },
@@ -390,6 +390,7 @@
{ -1, NULL, 0, 0, 0, 0 }, /* end marker */
};
+#endif
/*
* descriptor for one of our channels.
@@ -402,6 +403,7 @@
struct chan_usbradio_pvt *next;
char *name;
+#ifndef NEW_ASTERISK
/*
* cursound indicates which in struct sound we play. -1 means nothing,
* any other value is a valid sound, in which case sampsent indicates
@@ -413,6 +415,7 @@
int cursound; /* index of sound to send */
int sampsent; /* # of sound samples sent */
int nosound; /* set to block audio from the PBX */
+#endif
int pttkick[2];
int total_blocks; /* total blocks in the output device */
@@ -446,7 +449,9 @@
int spkrmax;
int micmax;
+#ifndef NEW_ASTERISK
pthread_t sthread;
+#endif
pthread_t hidthread;
int stophid;
@@ -515,6 +520,7 @@
char rxcdtype;
char rxsdtype;
int rxsquelchadj; /* this copy needs to be here for initialization */
+ int rxsqvoxadj;
char txtoctype;
char txprelim;
@@ -605,7 +611,9 @@
// maw add additional defaults !!!
static struct chan_usbradio_pvt usbradio_default = {
+#ifndef NEW_ASTERISK
.cursound = -1,
+#endif
.sounddev = -1,
.duplex = M_UNSET, /* XXX check this */
.autoanswer = 1,
@@ -1356,6 +1364,8 @@
return write(o->sounddev, ((void *) data), FRAME_SIZE * 2 * 12);
}
+#ifndef NEW_ASTERISK
+
/*
* Handler for 'sound writable' events from the sound thread.
* Builds a frame from the high level description of the sounds,
@@ -1481,6 +1491,8 @@
}
return NULL; /* Never reached */
}
+
+#endif
/*
* reset and close the device if opened,
@@ -1658,7 +1670,9 @@
/* Play ringtone 'x' on device 'o' */
static void ring(struct chan_usbradio_pvt *o, int x)
{
+#ifndef NEW_ASTERISK
write(o->sndcmd[1], &x, sizeof(x));
+#endif
}
/*
@@ -1680,11 +1694,15 @@
*/
static int usbradio_answer(struct ast_channel *c)
{
+#ifndef NEW_ASTERISK
struct chan_usbradio_pvt *o = c->tech_pvt;
+#endif
ast_setstate(c, AST_STATE_UP);
+#ifndef NEW_ASTERISK
o->cursound = -1;
o->nosound = 0;
+#endif
return 0;
}
@@ -1693,8 +1711,10 @@
struct chan_usbradio_pvt *o = c->tech_pvt;
//ast_log(LOG_NOTICE, "usbradio_hangup()\n");
+#ifndef NEW_ASTERISK
o->cursound = -1;
o->nosound = 0;
+#endif
c->tech_pvt = NULL;
o->owner = NULL;
ast_module_unref(ast_module_info->self);
@@ -1721,11 +1741,13 @@
traceusb2(("usbradio_write() o->nosound= %i\n",o->nosound));
+#ifndef NEW_ASTERISK
/* Immediately return if no sound is enabled */
if (o->nosound)
return 0;
/* Stop any currently playing sound */
o->cursound = -1;
+#endif
/*
* we could receive a block which is not a multiple of our
* FRAME_SIZE, so buffer it locally and write to the device
@@ -1787,15 +1809,15 @@
if (errno != EAGAIN) return NULL;
if (o->readerrs++ > READERR_THRESHOLD)
{
- ast_log(LOG_ERROR,"Stuck USB read channel [%s], un-sticking it!!\n",o->name);
+ ast_log(LOG_ERROR,"Stuck USB read channel [%s], un-sticking it!\n",o->name);
o->readerrs = 0;
return NULL;
}
if (o->readerrs == 1)
- ast_log(LOG_ERROR,"Possibly stuck USB read channel??? [%s]\n",o->name);
+ ast_log(LOG_WARNING,"Possibly stuck USB read channel. [%s]\n",o->name);
return f;
}
- if (o->readerrs) ast_log(LOG_ERROR,"Nope, USB read channel [%s] wasn't stuck after all\n",o->name);
+ if (o->readerrs) ast_log(LOG_WARNING,"Nope, USB read channel [%s] wasn't stuck after all.\n",o->name);
o->readerrs = 0;
o->readpos += res;
if (o->readpos < sizeof(o->usbradio_read_buf)) /* not enough samples */
@@ -2088,8 +2110,10 @@
break;
case -1:
+#ifndef NEW_ASTERISK
o->cursound = -1;
o->nosound = 0; /* when cursound is -1 nosound must be 0 */
+#endif
return 0;
case AST_CONTROL_VIDUPDATE:
@@ -2603,6 +2627,8 @@
" load (tuning settings from EEPROM)\n"
"\n All [newsetting]'s are values 0-999\n\n";
+#ifndef NEW_ASTERISK
+
static struct ast_cli_entry cli_usbradio[] = {
{ { "radio", "key", NULL },
console_key, "Simulate Rx Signal Present",
@@ -2633,6 +2659,7 @@
active_usage, NULL, NULL },
};
+#endif
/*
* store the callerid components
@@ -2845,7 +2872,7 @@
setamixer(o->devicenum,MIXER_PARAM_MIC_BOOST,o->rxboostset,0);
usleep(100000);
- if(o->rxcdtype==CD_XPMR_VOX || o->rxdemod==RX_AUDIO_SPEAKER)
+ if(o->rxcdtype!=CD_XPMR_NOISE || o->rxdemod==RX_AUDIO_SPEAKER)
{
// printf("Measure Direct Input\n");
o->pmrChan->spsMeasure->source = o->pmrChan->spsRx->source;
@@ -3360,7 +3387,9 @@
struct ast_config *cfg1;
int i;
char fname[200];
-
+#ifdef NEW_ASTERISK
+ struct ast_flags zeroflag = {0};
+#endif
if (ctg == NULL) {
traceusb1((" store_config() ctg == NULL\n"));
o = &usbradio_default;
@@ -3383,7 +3412,7 @@
strcpy(o->mohinterpret, "default");
/* fill other fields from configuration */
for (v = ast_variable_browse(cfg, ctg); v; v = v->next) {
- M_START(v->name, v->value);
+ M_START((char *)v->name, (char *)v->value);
/* handle jb conf */
if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
@@ -3408,21 +3437,22 @@
M_BOOL("rxcpusaver",o->rxcpusaver)
M_BOOL("txcpusaver",o->txcpusaver)
M_BOOL("invertptt",o->invertptt)
- M_F("rxdemod",store_rxdemod(o,v->value))
+ M_F("rxdemod",store_rxdemod(o,(char *)v->value))
M_BOOL("txprelim",o->txprelim);
- M_F("txmixa",store_txmixa(o,v->value))
- M_F("txmixb",store_txmixb(o,v->value))
- M_F("carrierfrom",store_rxcdtype(o,v->value))
- M_F("rxsdtype",store_rxsdtype(o,v->value))
+ M_F("txmixa",store_txmixa(o,(char *)v->value))
+ M_F("txmixb",store_txmixb(o,(char *)v->value))
+ M_F("carrierfrom",store_rxcdtype(o,(char *)v->value))
+ M_F("rxsdtype",store_rxsdtype(o,(char *)v->value))
+ M_UINT("rxsqvox",o->rxsqvoxadj)
M_STR("txctcssdefault",o->txctcssdefault)
M_STR("rxctcssfreqs",o->rxctcssfreqs)
M_STR("txctcssfreqs",o->txctcssfreqs)
M_UINT("rxfreq",o->rxfreq)
M_UINT("txfreq",o->txfreq)
- M_F("rxgain",store_rxgain(o,v->value))
+ M_F("rxgain",store_rxgain(o,(char *)v->value))
M_BOOL("rxboost",o->rxboostset)
M_UINT("rxctcssrelax",o->rxctcssrelax)
- M_F("txtoctype",store_txtoctype(o,v->value))
+ M_F("txtoctype",store_txtoctype(o,(char *)v->value))
M_UINT("hdwtype",o->hdwtype)
M_UINT("eeprom",o->wanteeprom)
M_UINT("duplex",o->radioduplex)
@@ -3452,7 +3482,11 @@
return NULL;
snprintf(fname,sizeof(fname) - 1,config1,o->name);
+#ifdef NEW_ASTERISK
+ cfg1 = ast_config_load(fname,zeroflag);
+#else
cfg1 = ast_config_load(fname);
+#endif
o->rxmixerset = 500;
o->txmixaset = 500;
o->txmixbset = 500;
@@ -3464,12 +3498,12 @@
if (cfg1) {
for (v = ast_variable_browse(cfg1, o->name); v; v = v->next) {
- M_START(v->name, v->value);
+ M_START((char *)v->name, (char *)v->value);
M_UINT("rxmixerset", o->rxmixerset)
M_UINT("txmixaset", o->txmixaset)
M_UINT("txmixbset", o->txmixbset)
- M_F("rxvoiceadj",store_rxvoiceadj(o,v->value))
- M_F("rxctcssadj",store_rxctcssadj(o,v->value))
+ M_F("rxvoiceadj",store_rxvoiceadj(o,(char *)v->value))
+ M_F("rxctcssadj",store_rxctcssadj(o,(char *)v->value))
M_UINT("txctcssadj",o->txctcssadj);
M_UINT("rxsquelchadj", o->rxsquelchadj)
M_STR("devstr", o->devstr)
@@ -3540,6 +3574,7 @@
tChan.rxDemod=o->rxdemod;
tChan.rxCdType=o->rxcdtype;
+ tChan.rxSqVoxAdj=o->rxsqvoxadj;
if (o->txprelim)
tChan.txMod = 2;
@@ -3633,12 +3668,14 @@
TRACEO(1,("store_config() 200\n"));
+#ifndef NEW_ASTERISK
if (pipe(o->sndcmd) != 0) {
ast_log(LOG_ERROR, "Unable to create pipe\n");
goto error;
}
ast_pthread_create_background(&o->sthread, NULL, sound_thread, o);
+#endif
/* link into list of devices */
if (o != &usbradio_default) {
@@ -3729,6 +3766,133 @@
}
#endif
+#ifdef NEW_ASTERISK
+
+static char *res2cli(int r)
+
+{
+ switch (r)
+ {
+ case RESULT_SUCCESS:
+ return(CLI_SUCCESS);
+ case RESULT_SHOWUSAGE:
+ return(CLI_SHOWUSAGE);
+ default:
+ return(CLI_FAILURE);
+ }
+}
+
+static char *handle_console_key(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio key";
+ e->usage = key_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(console_key(a->fd,a->argc,a->argv));
+}
+
+static char *handle_console_unkey(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio unkey";
+ e->usage = unkey_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(console_unkey(a->fd,a->argc,a->argv));
+}
+
+static char *handle_radio_tune(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio tune";
+ e->usage = radio_tune_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_tune(a->fd,a->argc,a->argv));
+}
+
+static char *handle_radio_debug(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio debug";
+ e->usage = radio_tune_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_set_debug(a->fd,a->argc,a->argv));
+}
+
+static char *handle_radio_debug_off(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio debug off";
+ e->usage = radio_tune_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_set_debug_off(a->fd,a->argc,a->argv));
+}
+
+static char *handle_radio_active(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio active";
+ e->usage = active_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_active(a->fd,a->argc,a->argv));
+}
+
+static char *handle_set_xdebug(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio set xdebug";
+ e->usage = active_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_set_xpmr_debug(a->fd,a->argc,a->argv));
+}
+
+
+static struct ast_cli_entry cli_usbradio[] = {
+ AST_CLI_DEFINE(handle_console_key,"Simulate Rx Signal Present"),
+ AST_CLI_DEFINE(handle_console_unkey,"Simulate Rx Signal Loss"),
+ AST_CLI_DEFINE(handle_radio_tune,"Radio Tune"),
+ AST_CLI_DEFINE(handle_radio_debug,"Radio Debug On"),
+ AST_CLI_DEFINE(handle_radio_debug_off,"Radio Debug Off"),
+ AST_CLI_DEFINE(handle_radio_active,"Change commanded device"),
+ AST_CLI_DEFINE(handle_set_xdebug,"Radio set xpmr debug level")
+};
+
+#endif
+
#include "./xpmr/xpmr.c"
#ifdef HAVE_XPMRX
#include "./xpmrx/xpmrx.c"
@@ -3740,6 +3904,9 @@
{
struct ast_config *cfg = NULL;
char *ctg = NULL;
+#ifdef NEW_ASTERISK
+ struct ast_flags zeroflag = {0};
+#endif
if (hid_device_mklist()) {
ast_log(LOG_NOTICE, "Unable to make hid list\n");
@@ -3754,7 +3921,11 @@
memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
/* load config file */
+#ifdef NEW_ASTERISK
+ if (!(cfg = ast_config_load(config,zeroflag))) {
+#else
if (!(cfg = ast_config_load(config))) {
+#endif
ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
return AST_MODULE_LOAD_DECLINE;
}
@@ -3807,10 +3978,12 @@
#endif
close(o->sounddev);
+#ifndef NEW_ASTERISK
if (o->sndcmd[0] > 0) {
close(o->sndcmd[0]);
close(o->sndcmd[1]);
}
+#endif
if (o->dsp) ast_dsp_free(o->dsp);
if (o->owner)
ast_softhangup(o->owner, AST_SOFTHANGUP_APPUNLOAD);
More information about the svn-commits
mailing list