Tue Mar 2 17:33:03 2010

Asterisk developer's documentation


chan_usbradio.c File Reference

Channel driver for CM108 USB Cards with Radio Interface. More...

#include "asterisk.h"
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include <sys/io.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/time.h>
#include <stdlib.h>
#include <errno.h>
#include <usb.h>
#include <alsa/asoundlib.h>
#include "./xpmr/xpmr.h"
#include <soundcard.h>
#include "asterisk/lock.h"
#include "asterisk/frame.h"
#include "asterisk/logger.h"
#include "asterisk/callerid.h"
#include "asterisk/channel.h"
#include "asterisk/module.h"
#include "asterisk/options.h"
#include "asterisk/pbx.h"
#include "asterisk/config.h"
#include "asterisk/cli.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/endian.h"
#include "asterisk/stringfields.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/musiconhold.h"
#include "asterisk/dsp.h"
#include "./xpmr/xpmr.c"
Include dependency graph for chan_usbradio.c:

Go to the source code of this file.

Data Structures

struct  chan_usbradio_pvt
struct  sound

Defines

#define BOOST_MAX   40
#define BOOST_SCALE   (1<<9)
#define C108_HID_INTERFACE   3
#define C108_PRODUCT_ID   0x000c
#define C108_VENDOR_ID   0x0d8c
#define CHAN_USBRADIO   1
#define config1   "usbradio_tune_%s.conf"
#define DEBUG_CAP_RX_OUT   0
#define DEBUG_CAP_TX_OUT   0
#define DEBUG_CAPTURES   1
#define DEBUG_FILETEST   0
#define DEBUG_USBRADIO   0
#define DELIMCHR   ','
#define DEV_DSP   "/dev/dsp"
#define EEPROM_CS_ADDR   62
#define EEPROM_END_ADDR   63
#define EEPROM_MAGIC   34329
#define EEPROM_MAGIC_ADDR   6
#define EEPROM_PHYSICAL_LEN   64
#define EEPROM_RXCTCSSADJ   13
#define EEPROM_RXMIXERSET   8
#define EEPROM_RXSQUELCHADJ   16
#define EEPROM_RXVOICEADJ   11
#define EEPROM_START_ADDR   6
#define EEPROM_TEST_ADDR   EEPROM_END_ADDR
#define EEPROM_TXCTCSSADJ   15
#define EEPROM_TXMIXASET   9
#define EEPROM_TXMIXBSET   10
#define FRAGS   ( ( (6 * 5) << 16 ) | 0xc )
#define FRAME_SIZE   160
#define HID_REPORT_GET   0x01
#define HID_REPORT_SET   0x09
#define HID_RT_INPUT   0x01
#define HID_RT_OUTPUT   0x02
#define M_BOOL(tag, dst)   M_F(tag, (dst) = ast_true(__val) )
#define M_END(x)   x;
#define M_F(tag, f)   if (!strcasecmp((__s), tag)) { f; } else
#define M_START(var, val)   char *__s = var; char *__val = val;
#define M_STR(tag, dst)   M_F(tag, ast_copy_string(dst, __val, sizeof(dst)))
#define M_UINT(tag, dst)   M_F(tag, (dst) = strtoul(__val, NULL, 0) )
#define MIXER_PARAM_MIC_BOOST   "Auto Gain Control"
#define MIXER_PARAM_MIC_CAPTURE_SW   "Mic Capture Switch"
#define MIXER_PARAM_MIC_CAPTURE_VOL   "Mic Capture Volume"
#define MIXER_PARAM_MIC_PLAYBACK_SW   "Mic Playback Switch"
#define MIXER_PARAM_MIC_PLAYBACK_VOL   "Mic Playback Volume"
#define MIXER_PARAM_SPKR_PLAYBACK_SW   "Speaker Playback Switch"
#define MIXER_PARAM_SPKR_PLAYBACK_VOL   "Speaker Playback Volume"
#define NEW_ASTERISK
#define O_CLOSE   0x444
#define pd(x)   {printf(#x" = %d\n",x);}
#define pf(x)   {printf(#x" = %f\n",x);}
#define pp(x)   {printf(#x" = %p\n",x);}
#define ps(x)   {printf(#x" = %s\n",x);}
#define QUEUE_SIZE   2
#define QUOTECHR   34
#define READERR_THRESHOLD   50
#define RX_CAP_OUT_FILE   "/tmp/rx_cap_out.pcm"
#define RX_CAP_RAW_FILE   "/tmp/rx_cap_in.pcm"
#define RX_CAP_TRACE_FILE   "/tmp/rx_trace.pcm"
#define TEXT_SIZE   256
#define traceusb1(a)
#define traceusb2(a)
#define TX_CAP_OUT_FILE   "/tmp/tx_cap_out.pcm"
#define TX_CAP_RAW_FILE   "/tmp/tx_cap_in.pcm"
#define TX_CAP_TRACE_FILE   "/tmp/tx_trace.pcm"
#define WARN_frag   4
#define WARN_speed   2
#define WARN_used_blocks   1

Enumerations

enum  { RX_AUDIO_NONE, RX_AUDIO_SPEAKER, RX_AUDIO_FLAT }
enum  {
  CD_IGNORE, CD_XPMR_NOISE, CD_XPMR_VOX, CD_HID,
  CD_HID_INVERT
}
enum  { SD_IGNORE, SD_HID, SD_HID_INVERT, SD_XPMR }
enum  { RX_KEY_CARRIER, RX_KEY_CARRIER_CODE }
enum  {
  TX_OUT_OFF, TX_OUT_VOICE, TX_OUT_LSD, TX_OUT_COMPOSITE,
  TX_OUT_AUX
}
enum  { TOC_NONE, TOC_PHASE, TOC_NOTONE }

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int amixer_max (int devnum, char *param)
static int console_key (int fd, int argc, char *argv[])
static int console_unkey (int fd, int argc, char *argv[])
static struct chan_usbradio_pvtfind_desc (char *dev)
static struct chan_usbradio_pvtfind_desc_usb (char *devstr)
static unsigned short get_eeprom (struct usb_dev_handle *handle, unsigned short *buf)
static char * handle_console_key (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_console_unkey (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_radio_active (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_radio_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_radio_debug_off (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_radio_tune (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_set_xdebug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static struct usb_device * hid_device_init (char *desired_device)
static int hid_device_mklist (void)
static void hid_get_inputs (struct usb_dev_handle *handle, unsigned char *inputs)
static void hid_set_outputs (struct usb_dev_handle *handle, unsigned char *outputs)
static int hidhdwconfig (struct chan_usbradio_pvt *o)
static void * hidthread (void *arg)
static void kickptt (struct chan_usbradio_pvt *o)
static int load_module (void)
static void mixer_write (struct chan_usbradio_pvt *o)
static int mult_calc (int value)
static void mult_set (struct chan_usbradio_pvt *o)
static void pmrdump (struct chan_usbradio_pvt *o)
static void put_eeprom (struct usb_dev_handle *handle, unsigned short *buf)
static int radio_active (int fd, int argc, char *argv[])
static int radio_set_debug (int fd, int argc, char *argv[])
static int radio_set_debug_off (int fd, int argc, char *argv[])
static int radio_set_xpmr_debug (int fd, int argc, char *argv[])
static int radio_tune (int fd, int argc, char *argv[])
static unsigned short read_eeprom (struct usb_dev_handle *handle, int addr)
static char * res2cli (int r)
static void ring (struct chan_usbradio_pvt *o, int x)
static int set_txctcss_level (struct chan_usbradio_pvt *o)
static int setamixer (int devnum, char *param, int v1, int v2)
static int setformat (struct chan_usbradio_pvt *o, int mode)
static int soundcard_writeframe (struct chan_usbradio_pvt *o, short *data)
static struct chan_usbradio_pvtstore_config (struct ast_config *cfg, char *ctg)
static void store_rxcdtype (struct chan_usbradio_pvt *o, char *s)
static void store_rxctcssadj (struct chan_usbradio_pvt *o, char *s)
static void store_rxdemod (struct chan_usbradio_pvt *o, char *s)
static void store_rxgain (struct chan_usbradio_pvt *o, char *s)
static void store_rxsdtype (struct chan_usbradio_pvt *o, char *s)
static void store_rxvoiceadj (struct chan_usbradio_pvt *o, char *s)
static void store_txmixa (struct chan_usbradio_pvt *o, char *s)
static void store_txmixb (struct chan_usbradio_pvt *o, char *s)
static void store_txtoctype (struct chan_usbradio_pvt *o, char *s)
static void tune_rxctcss (int fd, struct chan_usbradio_pvt *o)
static void tune_rxinput (int fd, struct chan_usbradio_pvt *o)
static void tune_rxvoice (int fd, struct chan_usbradio_pvt *o)
static void tune_txoutput (struct chan_usbradio_pvt *o, int value, int fd)
static void tune_write (struct chan_usbradio_pvt *o)
static int unload_module (void)
static int usb_get_usbdev (char *devstr)
static int usb_list_check (char *devstr)
static int usbradio_answer (struct ast_channel *c)
static int usbradio_call (struct ast_channel *c, char *dest, int timeout)
static int usbradio_digit_begin (struct ast_channel *c, char digit)
static int usbradio_digit_end (struct ast_channel *c, char digit, unsigned int duration)
static int usbradio_fixup (struct ast_channel *oldchan, struct ast_channel *newchan)
static int usbradio_hangup (struct ast_channel *c)
static int usbradio_indicate (struct ast_channel *chan, int cond, const void *data, size_t datalen)
static struct ast_channelusbradio_new (struct chan_usbradio_pvt *o, char *ext, char *ctx, int state)
static struct ast_frameusbradio_read (struct ast_channel *chan)
static struct ast_channelusbradio_request (const char *type, int format, void *data, int *cause)
static int usbradio_text (struct ast_channel *c, const char *text)
static int usbradio_write (struct ast_channel *chan, struct ast_frame *f)
static int used_blocks (struct chan_usbradio_pvt *o)
static void write_eeprom (struct usb_dev_handle *handle, int addr, unsigned short data)
static int xpmr_config (struct chan_usbradio_pvt *o)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "usb Console Channel Driver" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, }
static char active_usage []
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_cli_entry cli_usbradio []
static const char * config = "usbradio.conf"
static struct ast_jb_conf default_jbconf
static FILE * frxcapraw = NULL
static FILE * frxcaptrace = NULL
static FILE * frxoutraw = NULL
static FILE * ftxcapraw = NULL
static FILE * ftxcaptrace = NULL
static FILE * ftxoutraw = NULL
static struct ast_jb_conf global_jbconf
static char key_usage []
static char radio_tune_usage []
static char tdesc [] = "USB (CM108) Radio Channel Driver"
static char unkey_usage []
static char * usb_device_list = NULL
static int usb_device_list_size = 0
static char * usbradio_active
static int usbradio_debug
static struct chan_usbradio_pvt usbradio_default
static struct ast_channel_tech usbradio_tech

Detailed Description

Channel driver for CM108 USB Cards with Radio Interface.

Author:
Jim Dixon <jim@lambdatel.com>
Steve Henke <w9sh@arrl.net>
See also
  • Config_usbradio

Definition in file chan_usbradio.c.


Define Documentation

#define BOOST_MAX   40

Definition at line 455 of file chan_usbradio.c.

#define BOOST_SCALE   (1<<9)

Definition at line 454 of file chan_usbradio.c.

#define C108_HID_INTERFACE   3

Definition at line 166 of file chan_usbradio.c.

Referenced by hid_get_inputs(), hid_set_outputs(), and hidthread().

#define C108_PRODUCT_ID   0x000c

Definition at line 165 of file chan_usbradio.c.

Referenced by hid_device_init(), and hid_device_mklist().

#define C108_VENDOR_ID   0x0d8c

Definition at line 164 of file chan_usbradio.c.

Referenced by hid_device_init(), and hid_device_mklist().

#define CHAN_USBRADIO   1

Definition at line 82 of file chan_usbradio.c.

#define config1   "usbradio_tune_%s.conf"

Definition at line 355 of file chan_usbradio.c.

Referenced by store_config().

#define DEBUG_CAP_RX_OUT   0

Definition at line 85 of file chan_usbradio.c.

#define DEBUG_CAP_TX_OUT   0

Definition at line 86 of file chan_usbradio.c.

#define DEBUG_CAPTURES   1

Definition at line 84 of file chan_usbradio.c.

#define DEBUG_FILETEST   0

Definition at line 87 of file chan_usbradio.c.

#define DEBUG_USBRADIO   0

Definition at line 83 of file chan_usbradio.c.

#define DELIMCHR   ','

Definition at line 105 of file chan_usbradio.c.

Referenced by finddelim().

#define DEV_DSP   "/dev/dsp"

Definition at line 351 of file chan_usbradio.c.

#define EEPROM_CS_ADDR   62

Definition at line 180 of file chan_usbradio.c.

Referenced by put_eeprom().

#define EEPROM_END_ADDR   63

Definition at line 175 of file chan_usbradio.c.

Referenced by get_eeprom().

#define EEPROM_MAGIC   34329

Definition at line 179 of file chan_usbradio.c.

Referenced by hidthread(), and put_eeprom().

#define EEPROM_MAGIC_ADDR   6

Definition at line 178 of file chan_usbradio.c.

Referenced by hidthread(), and put_eeprom().

#define EEPROM_PHYSICAL_LEN   64

Definition at line 176 of file chan_usbradio.c.

#define EEPROM_RXCTCSSADJ   13

Definition at line 185 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_RXMIXERSET   8

Definition at line 181 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_RXSQUELCHADJ   16

Definition at line 187 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_RXVOICEADJ   11

Definition at line 184 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_START_ADDR   6

Definition at line 174 of file chan_usbradio.c.

Referenced by get_eeprom(), and put_eeprom().

#define EEPROM_TEST_ADDR   EEPROM_END_ADDR

Definition at line 177 of file chan_usbradio.c.

#define EEPROM_TXCTCSSADJ   15

Definition at line 186 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_TXMIXASET   9

Definition at line 182 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_TXMIXBSET   10

Definition at line 183 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define FRAGS   ( ( (6 * 5) << 16 ) | 0xc )

Definition at line 334 of file chan_usbradio.c.

#define FRAME_SIZE   160

Definition at line 328 of file chan_usbradio.c.

#define HID_REPORT_GET   0x01

Definition at line 168 of file chan_usbradio.c.

Referenced by hid_get_inputs().

#define HID_REPORT_SET   0x09

Definition at line 169 of file chan_usbradio.c.

Referenced by hid_set_outputs().

#define HID_RT_INPUT   0x01

Definition at line 171 of file chan_usbradio.c.

Referenced by hid_get_inputs().

#define HID_RT_OUTPUT   0x02

Definition at line 172 of file chan_usbradio.c.

Referenced by hid_set_outputs().

#define M_BOOL ( tag,
dst   )     M_F(tag, (dst) = ast_true(__val) )

Definition at line 294 of file chan_usbradio.c.

Referenced by store_config().

#define M_END (  )     x;

Definition at line 292 of file chan_usbradio.c.

Referenced by store_config().

#define M_F ( tag,
f   )     if (!strcasecmp((__s), tag)) { f; } else

Definition at line 293 of file chan_usbradio.c.

Referenced by store_config().

#define M_START ( var,
val   )     char *__s = var; char *__val = val;

Definition at line 290 of file chan_usbradio.c.

Referenced by store_config().

#define M_STR ( tag,
dst   )     M_F(tag, ast_copy_string(dst, __val, sizeof(dst)))

Definition at line 296 of file chan_usbradio.c.

Referenced by store_config().

#define M_UINT ( tag,
dst   )     M_F(tag, (dst) = strtoul(__val, NULL, 0) )

Definition at line 295 of file chan_usbradio.c.

Referenced by store_config().

#define MIXER_PARAM_MIC_BOOST   "Auto Gain Control"

Definition at line 101 of file chan_usbradio.c.

Referenced by mixer_write(), and tune_rxinput().

#define MIXER_PARAM_MIC_CAPTURE_SW   "Mic Capture Switch"

Definition at line 99 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_MIC_CAPTURE_VOL   "Mic Capture Volume"

Definition at line 100 of file chan_usbradio.c.

Referenced by mixer_write(), store_config(), and tune_rxinput().

#define MIXER_PARAM_MIC_PLAYBACK_SW   "Mic Playback Switch"

Definition at line 97 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_MIC_PLAYBACK_VOL   "Mic Playback Volume"

Definition at line 98 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_SPKR_PLAYBACK_SW   "Speaker Playback Switch"

Definition at line 102 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_SPKR_PLAYBACK_VOL   "Speaker Playback Volume"

Definition at line 103 of file chan_usbradio.c.

Referenced by mixer_write(), and store_config().

#define NEW_ASTERISK

Definition at line 1 of file chan_usbradio.c.

#define O_CLOSE   0x444

Definition at line 346 of file chan_usbradio.c.

#define pd (  )     {printf(#x" = %d\n",x);}

Definition at line 3155 of file chan_usbradio.c.

Referenced by pcm_write(), playtones_alloc(), and pmrdump().

#define pf (  )     {printf(#x" = %f\n",x);}

Definition at line 3158 of file chan_usbradio.c.

Referenced by pmrdump().

#define pp (  )     {printf(#x" = %p\n",x);}
#define ps (  )     {printf(#x" = %s\n",x);}
#define QUEUE_SIZE   2

Definition at line 329 of file chan_usbradio.c.

#define QUOTECHR   34

Definition at line 106 of file chan_usbradio.c.

Referenced by finddelim().

#define READERR_THRESHOLD   50

Definition at line 108 of file chan_usbradio.c.

Referenced by usbradio_read().

#define RX_CAP_OUT_FILE   "/tmp/rx_cap_out.pcm"

Definition at line 91 of file chan_usbradio.c.

Referenced by usbradio_read().

#define RX_CAP_RAW_FILE   "/tmp/rx_cap_in.pcm"

Definition at line 89 of file chan_usbradio.c.

Referenced by radio_tune().

#define RX_CAP_TRACE_FILE   "/tmp/rx_trace.pcm"

Definition at line 90 of file chan_usbradio.c.

Referenced by radio_tune().

#define TEXT_SIZE   256

Definition at line 341 of file chan_usbradio.c.

#define traceusb1 (  ) 

Definition at line 119 of file chan_usbradio.c.

Referenced by hidthread(), and store_config().

#define traceusb2 (  ) 

Definition at line 125 of file chan_usbradio.c.

Referenced by usbradio_read(), and usbradio_write().

#define TX_CAP_OUT_FILE   "/tmp/tx_cap_out.pcm"

Definition at line 95 of file chan_usbradio.c.

Referenced by usbradio_read().

#define TX_CAP_RAW_FILE   "/tmp/tx_cap_in.pcm"

Definition at line 93 of file chan_usbradio.c.

Referenced by radio_tune().

#define TX_CAP_TRACE_FILE   "/tmp/tx_trace.pcm"

Definition at line 94 of file chan_usbradio.c.

Referenced by radio_tune().

#define WARN_frag   4

Definition at line 444 of file chan_usbradio.c.

#define WARN_speed   2

Definition at line 443 of file chan_usbradio.c.

#define WARN_used_blocks   1

Definition at line 442 of file chan_usbradio.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
RX_AUDIO_NONE 
RX_AUDIO_SPEAKER 
RX_AUDIO_FLAT 

Definition at line 368 of file chan_usbradio.c.

anonymous enum
Enumerator:
CD_IGNORE 
CD_XPMR_NOISE 
CD_XPMR_VOX 
CD_HID 
CD_HID_INVERT 

Definition at line 369 of file chan_usbradio.c.

anonymous enum
Enumerator:
SD_IGNORE 
SD_HID 
SD_HID_INVERT 
SD_XPMR 

Definition at line 370 of file chan_usbradio.c.

00370 {SD_IGNORE,SD_HID,SD_HID_INVERT,SD_XPMR};                 // no,external,externalinvert,software

anonymous enum
Enumerator:
RX_KEY_CARRIER 
RX_KEY_CARRIER_CODE 

Definition at line 371 of file chan_usbradio.c.

anonymous enum
Enumerator:
TX_OUT_OFF 
TX_OUT_VOICE 
TX_OUT_LSD 
TX_OUT_COMPOSITE 
TX_OUT_AUX 

Definition at line 372 of file chan_usbradio.c.

anonymous enum
Enumerator:
TOC_NONE 
TOC_PHASE 
TOC_NOTONE 

Definition at line 373 of file chan_usbradio.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 4027 of file chan_usbradio.c.

static void __unreg_module ( void   )  [static]

Definition at line 4027 of file chan_usbradio.c.

static int amixer_max ( int  devnum,
char *  param 
) [static]

Definition at line 705 of file chan_usbradio.c.

References id, str, and type.

Referenced by store_config().

00706 {
00707 int   rv,type;
00708 char  str[100];
00709 snd_hctl_t *hctl;
00710 snd_ctl_elem_id_t *id;
00711 snd_hctl_elem_t *elem;
00712 snd_ctl_elem_info_t *info;
00713 
00714    sprintf(str,"hw:%d",devnum);
00715    if (snd_hctl_open(&hctl, str, 0)) return(-1);
00716    snd_hctl_load(hctl);
00717    snd_ctl_elem_id_alloca(&id);
00718    snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
00719    snd_ctl_elem_id_set_name(id, param);  
00720    elem = snd_hctl_find_elem(hctl, id);
00721    if (!elem)
00722    {
00723       snd_hctl_close(hctl);
00724       return(-1);
00725    }
00726    snd_ctl_elem_info_alloca(&info);
00727    snd_hctl_elem_info(elem,info);
00728    type = snd_ctl_elem_info_get_type(info);
00729    rv = 0;
00730    switch(type)
00731    {
00732        case SND_CTL_ELEM_TYPE_INTEGER:
00733       rv = snd_ctl_elem_info_get_max(info);
00734       break;
00735        case SND_CTL_ELEM_TYPE_BOOLEAN:
00736       rv = 1;
00737       break;
00738    }
00739    snd_hctl_close(hctl);
00740    return(rv);
00741 }

static int console_key ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2263 of file chan_usbradio.c.

References find_desc(), RESULT_SHOWUSAGE, RESULT_SUCCESS, and chan_usbradio_pvt::txtestkey.

Referenced by handle_console_key().

02264 {
02265    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02266 
02267    if (argc != 2)
02268       return RESULT_SHOWUSAGE; 
02269    o->txtestkey = 1;
02270    return RESULT_SUCCESS;
02271 }

static int console_unkey ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2274 of file chan_usbradio.c.

References find_desc(), RESULT_SHOWUSAGE, RESULT_SUCCESS, and chan_usbradio_pvt::txtestkey.

Referenced by handle_console_unkey().

02275 {
02276    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02277 
02278    if (argc != 2)
02279       return RESULT_SHOWUSAGE;
02280    o->txtestkey = 0;
02281    return RESULT_SUCCESS;
02282 }

static struct chan_usbradio_pvt* find_desc ( char *  dev  )  [static, read]

Definition at line 1258 of file chan_usbradio.c.

References ast_log(), LOG_WARNING, chan_usbradio_pvt::name, and chan_usbradio_pvt::next.

Referenced by console_key(), console_unkey(), load_module(), radio_active(), radio_set_debug(), radio_set_debug_off(), radio_set_xpmr_debug(), radio_tune(), usbradio_request(), and usbradio_text().

01259 {
01260    struct chan_usbradio_pvt *o = NULL;
01261 
01262    if (!dev)
01263       ast_log(LOG_WARNING, "null dev\n");
01264 
01265    for (o = usbradio_default.next; o && o->name && dev && strcmp(o->name, dev) != 0; o = o->next);
01266    if (!o)
01267    {
01268       ast_log(LOG_WARNING, "could not find <%s>\n", dev ? dev : "--no-device--");
01269       pthread_exit(0);
01270    }
01271 
01272    return o;
01273 }

static struct chan_usbradio_pvt* find_desc_usb ( char *  devstr  )  [static, read]

Definition at line 1275 of file chan_usbradio.c.

References ast_log(), chan_usbradio_pvt::devstr, LOG_WARNING, and chan_usbradio_pvt::next.

Referenced by store_config().

01276 {
01277    struct chan_usbradio_pvt *o = NULL;
01278 
01279    if (!devstr)
01280       ast_log(LOG_WARNING, "null dev\n");
01281 
01282    for (o = usbradio_default.next; o && devstr && strcmp(o->devstr, devstr) != 0; o = o->next);
01283 
01284    return o;
01285 }

static unsigned short get_eeprom ( struct usb_dev_handle *  handle,
unsigned short *  buf 
) [static]

Definition at line 846 of file chan_usbradio.c.

References EEPROM_END_ADDR, EEPROM_START_ADDR, and read_eeprom().

Referenced by hidthread().

00848 {
00849 int   i;
00850 unsigned short cs;
00851 
00852    cs = 0xffff;
00853    for(i = EEPROM_START_ADDR; i < EEPROM_END_ADDR; i++)
00854    {
00855       cs += buf[i] = read_eeprom(handle,i);
00856    }
00857    return(cs);
00858 }

static char* handle_console_key ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 3814 of file chan_usbradio.c.

References ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, console_key(), ast_cli_args::fd, res2cli(), and ast_cli_entry::usage.

03816 {
03817         switch (cmd) {
03818         case CLI_INIT:
03819                 e->command = "radio key";
03820                 e->usage = key_usage;
03821                 return NULL;
03822         case CLI_GENERATE:
03823                 return NULL;
03824    }
03825    return res2cli(console_key(a->fd,a->argc,a->argv));
03826 }

static char* handle_console_unkey ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 3828 of file chan_usbradio.c.

References ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, console_unkey(), ast_cli_args::fd, res2cli(), and ast_cli_entry::usage.

03830 {
03831         switch (cmd) {
03832         case CLI_INIT:
03833                 e->command = "radio unkey";
03834                 e->usage = unkey_usage;
03835                 return NULL;
03836         case CLI_GENERATE:
03837                 return NULL;
03838    }
03839    return res2cli(console_unkey(a->fd,a->argc,a->argv));
03840 }

static char* handle_radio_active ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 3884 of file chan_usbradio.c.

References ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, ast_cli_args::fd, radio_active(), res2cli(), and ast_cli_entry::usage.

03886 {
03887         switch (cmd) {
03888         case CLI_INIT:
03889                 e->command = "radio active";
03890                 e->usage = active_usage;
03891                 return NULL;
03892         case CLI_GENERATE:
03893                 return NULL;
03894    }
03895    return res2cli(radio_active(a->fd,a->argc,a->argv));
03896 }

static char* handle_radio_debug ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 3856 of file chan_usbradio.c.

References ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, ast_cli_args::fd, radio_set_debug(), res2cli(), and ast_cli_entry::usage.

03858 {
03859         switch (cmd) {
03860         case CLI_INIT:
03861                 e->command = "radio debug";
03862                 e->usage = radio_tune_usage;
03863                 return NULL;
03864         case CLI_GENERATE:
03865                 return NULL;
03866    }
03867    return res2cli(radio_set_debug(a->fd,a->argc,a->argv));
03868 }

static char* handle_radio_debug_off ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 3870 of file chan_usbradio.c.

References ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, ast_cli_args::fd, radio_set_debug_off(), res2cli(), and ast_cli_entry::usage.

03872 {
03873         switch (cmd) {
03874         case CLI_INIT:
03875                 e->command = "radio debug off";
03876                 e->usage = radio_tune_usage;
03877                 return NULL;
03878         case CLI_GENERATE:
03879                 return NULL;
03880    }
03881    return res2cli(radio_set_debug_off(a->fd,a->argc,a->argv));
03882 }

static char* handle_radio_tune ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 3842 of file chan_usbradio.c.

References ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, ast_cli_args::fd, radio_tune(), res2cli(), and ast_cli_entry::usage.

03844 {
03845         switch (cmd) {
03846         case CLI_INIT:
03847                 e->command = "radio tune";
03848                 e->usage = radio_tune_usage;
03849                 return NULL;
03850         case CLI_GENERATE:
03851                 return NULL;
03852    }
03853    return res2cli(radio_tune(a->fd,a->argc,a->argv));
03854 }

static char* handle_set_xdebug ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
) [static]

Definition at line 3898 of file chan_usbradio.c.

References ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, ast_cli_args::fd, radio_set_xpmr_debug(), res2cli(), and ast_cli_entry::usage.

03900 {
03901         switch (cmd) {
03902         case CLI_INIT:
03903                 e->command = "radio set xdebug";
03904                 e->usage = active_usage;
03905                 return NULL;
03906         case CLI_GENERATE:
03907                 return NULL;
03908    }
03909    return res2cli(radio_set_xpmr_debug(a->fd,a->argc,a->argv));
03910 }

static struct usb_device* hid_device_init ( char *  desired_device  )  [static, read]

Definition at line 876 of file chan_usbradio.c.

References C108_PRODUCT_ID, C108_VENDOR_ID, and str.

Referenced by hidthread().

00877 {
00878     struct usb_bus *usb_bus;
00879     struct usb_device *dev;
00880     char devstr[200],str[200],desdev[200],*cp;
00881     int i;
00882     FILE *fp;
00883 
00884     usb_init();
00885     usb_find_busses();
00886     usb_find_devices();
00887     for (usb_bus = usb_busses;
00888          usb_bus;
00889          usb_bus = usb_bus->next) {
00890         for (dev = usb_bus->devices;
00891              dev;
00892              dev = dev->next) {
00893             if ((dev->descriptor.idVendor
00894                   == C108_VENDOR_ID) &&
00895                 (dev->descriptor.idProduct
00896                   == C108_PRODUCT_ID))
00897       {
00898                         sprintf(devstr,"%s/%s", usb_bus->dirname,dev->filename);
00899          for(i = 0; i < 32; i++)
00900          {
00901             sprintf(str,"/proc/asound/card%d/usbbus",i);
00902             fp = fopen(str,"r");
00903             if (!fp) continue;
00904             if ((!fgets(desdev,sizeof(desdev) - 1,fp)) || (!desdev[0]))
00905             {
00906                fclose(fp);
00907                continue;
00908             }
00909             fclose(fp);
00910             if (desdev[strlen(desdev) - 1] == '\n')
00911                   desdev[strlen(desdev) -1 ] = 0;
00912             if (strcasecmp(desdev,devstr)) continue;
00913             if (i) sprintf(str,"/sys/class/sound/dsp%d/device",i);
00914             else strcpy(str,"/sys/class/sound/dsp/device");
00915             memset(desdev,0,sizeof(desdev));
00916             if (readlink(str,desdev,sizeof(desdev) - 1) == -1)
00917             {
00918                sprintf(str,"/sys/class/sound/controlC%d/device",i);
00919                memset(desdev,0,sizeof(desdev));
00920                if (readlink(str,desdev,sizeof(desdev) - 1) == -1) continue;
00921             }
00922             cp = strrchr(desdev,'/');
00923             if (cp) *cp = 0; else continue;
00924             cp = strrchr(desdev,'/');
00925             if (!cp) continue;
00926             cp++;
00927             break;
00928          }
00929          if (i >= 32) continue;
00930                         if (!strcmp(cp,desired_device)) return dev;
00931       }
00932 
00933         }
00934     }
00935     return NULL;
00936 }

static int hid_device_mklist ( void   )  [static]

Definition at line 938 of file chan_usbradio.c.

References ast_malloc, ast_realloc, C108_PRODUCT_ID, C108_VENDOR_ID, and str.

Referenced by load_module().

00939 {
00940     struct usb_bus *usb_bus;
00941     struct usb_device *dev;
00942     char devstr[200],str[200],desdev[200],*cp;
00943     int i;
00944     FILE *fp;
00945 
00946     usb_device_list = ast_malloc(2);
00947     if (!usb_device_list) return -1;
00948     memset(usb_device_list,0,2);
00949 
00950     usb_init();
00951     usb_find_busses();
00952     usb_find_devices();
00953     for (usb_bus = usb_busses;
00954          usb_bus;
00955          usb_bus = usb_bus->next) {
00956         for (dev = usb_bus->devices;
00957              dev;
00958              dev = dev->next) {
00959             if ((dev->descriptor.idVendor
00960                   == C108_VENDOR_ID) &&
00961                 (dev->descriptor.idProduct
00962                   == C108_PRODUCT_ID))
00963       {
00964                         sprintf(devstr,"%s/%s", usb_bus->dirname,dev->filename);
00965          for(i = 0;i < 32; i++)
00966          {
00967             sprintf(str,"/proc/asound/card%d/usbbus",i);
00968             fp = fopen(str,"r");
00969             if (!fp) continue;
00970             if ((!fgets(desdev,sizeof(desdev) - 1,fp)) || (!desdev[0]))
00971             {
00972                fclose(fp);
00973                continue;
00974             }
00975             fclose(fp);
00976             if (desdev[strlen(desdev) - 1] == '\n')
00977                   desdev[strlen(desdev) -1 ] = 0;
00978             if (strcasecmp(desdev,devstr)) continue;
00979             if (i) sprintf(str,"/sys/class/sound/dsp%d/device",i);
00980             else strcpy(str,"/sys/class/sound/dsp/device");
00981             memset(desdev,0,sizeof(desdev));
00982             if (readlink(str,desdev,sizeof(desdev) - 1) == -1)
00983             {
00984                sprintf(str,"/sys/class/sound/controlC%d/device",i);
00985                memset(desdev,0,sizeof(desdev));
00986                if (readlink(str,desdev,sizeof(desdev) - 1) == -1) continue;
00987             }
00988             cp = strrchr(desdev,'/');
00989             if (cp) *cp = 0; else continue;
00990             cp = strrchr(desdev,'/');
00991             if (!cp) continue;
00992             cp++;
00993             break;
00994          }
00995          if (i >= 32) return -1;
00996          usb_device_list = ast_realloc(usb_device_list,
00997             usb_device_list_size + 2 +
00998                strlen(cp));
00999          if (!usb_device_list) return -1;
01000          usb_device_list_size += strlen(cp) + 2;
01001          i = 0;
01002          while(usb_device_list[i])
01003          {
01004             i += strlen(usb_device_list + i) + 1;
01005          }
01006          strcat(usb_device_list + i,cp);
01007          usb_device_list[strlen(cp) + i + 1] = 0;
01008       }
01009 
01010         }
01011     }
01012     return 0;
01013 }

static void hid_get_inputs ( struct usb_dev_handle *  handle,
unsigned char *  inputs 
) [static]

Definition at line 807 of file chan_usbradio.c.

References C108_HID_INTERFACE, HID_REPORT_GET, and HID_RT_INPUT.

Referenced by hidthread(), and read_eeprom().

00809 {
00810    usleep(1500);
00811    usb_control_msg(handle,
00812          USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
00813          HID_REPORT_GET,
00814          0 + (HID_RT_INPUT << 8),
00815          C108_HID_INTERFACE,
00816          (char*)inputs, 4, 5000);
00817 }

static void hid_set_outputs ( struct usb_dev_handle *  handle,
unsigned char *  outputs 
) [static]

Definition at line 795 of file chan_usbradio.c.

References C108_HID_INTERFACE, HID_REPORT_SET, and HID_RT_OUTPUT.

Referenced by hidthread(), read_eeprom(), and write_eeprom().

00797 {
00798    usleep(1500);
00799    usb_control_msg(handle,
00800          USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
00801          HID_REPORT_SET,
00802          0 + (HID_RT_OUTPUT << 8),
00803          C108_HID_INTERFACE,
00804          (char*)outputs, 4, 5000);
00805 }

static int hidhdwconfig ( struct chan_usbradio_pvt o  )  [static]

Definition at line 1059 of file chan_usbradio.c.

References chan_usbradio_pvt::hdwtype, chan_usbradio_pvt::hid_gpio_ctl, chan_usbradio_pvt::hid_gpio_ctl_loc, chan_usbradio_pvt::hid_gpio_loc, chan_usbradio_pvt::hid_io_cor, chan_usbradio_pvt::hid_io_cor_loc, chan_usbradio_pvt::hid_io_ctcss, chan_usbradio_pvt::hid_io_ctcss_loc, and chan_usbradio_pvt::hid_io_ptt.

Referenced by store_config().

01060 {
01061    if(o->hdwtype==1)   //sphusb
01062    {
01063       o->hid_gpio_ctl      =  0x08; /* set GPIO4 to output mode */
01064       o->hid_gpio_ctl_loc  =  2;    /* For CTL of GPIO */
01065       o->hid_io_cor     =  4; /* GPIO3 is COR */
01066       o->hid_io_cor_loc =  1; /* GPIO3 is COR */
01067       o->hid_io_ctcss      =  2;    /* GPIO 2 is External CTCSS */
01068       o->hid_io_ctcss_loc =  1;  /* is GPIO 2 */
01069       o->hid_io_ptt     =  8;    /* GPIO 4 is PTT */
01070       o->hid_gpio_loc   =  1;    /* For ALL GPIO */
01071    }
01072    else if(o->hdwtype==0)  //dudeusb
01073    {
01074       o->hid_gpio_ctl      =  0x0c; /* set GPIO 3 & 4 to output mode */
01075       o->hid_gpio_ctl_loc  =  2;    /* For CTL of GPIO */
01076       o->hid_io_cor     =  2; /* VOLD DN is COR */
01077       o->hid_io_cor_loc =  0; /* VOL DN COR */
01078       o->hid_io_ctcss      =  2;    /* GPIO 2 is External CTCSS */
01079       o->hid_io_ctcss_loc =  1;  /* is GPIO 2 */
01080       o->hid_io_ptt     =  4;    /* GPIO 3 is PTT */
01081       o->hid_gpio_loc   =  1;    /* For ALL GPIO */
01082    }
01083    else if(o->hdwtype==3)  // custom version
01084    {
01085       o->hid_gpio_ctl      =  0x0c; /* set GPIO 3 & 4 to output mode */
01086       o->hid_gpio_ctl_loc  =  2;    /* For CTL of GPIO */
01087       o->hid_io_cor     =  2; /* VOLD DN is COR */
01088       o->hid_io_cor_loc =  0; /* VOL DN COR */
01089       o->hid_io_ctcss      =  2;    /* GPIO 2 is External CTCSS */
01090       o->hid_io_ctcss_loc =  1;  /* is GPIO 2 */
01091       o->hid_io_ptt     =  4;    /* GPIO 3 is PTT */
01092       o->hid_gpio_loc   =  1;    /* For ALL GPIO */
01093    }
01094 
01095    return 0;
01096 }

static void* hidthread ( void *  arg  )  [static]

Definition at line 1111 of file chan_usbradio.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_select(), buf, C108_HID_INTERFACE, chan_usbradio_pvt::debuglevel, chan_usbradio_pvt::devstr, chan_usbradio_pvt::eeprom, EEPROM_MAGIC, EEPROM_MAGIC_ADDR, EEPROM_RXCTCSSADJ, EEPROM_RXMIXERSET, EEPROM_RXSQUELCHADJ, EEPROM_RXVOICEADJ, EEPROM_TXCTCSSADJ, EEPROM_TXMIXASET, EEPROM_TXMIXBSET, chan_usbradio_pvt::eepromctl, chan_usbradio_pvt::eepromlock, errno, get_eeprom(), hid_device_init(), hid_get_inputs(), chan_usbradio_pvt::hid_gpio_ctl, chan_usbradio_pvt::hid_gpio_ctl_loc, chan_usbradio_pvt::hid_gpio_loc, chan_usbradio_pvt::hid_io_cor, chan_usbradio_pvt::hid_io_cor_loc, chan_usbradio_pvt::hid_io_ptt, hid_set_outputs(), chan_usbradio_pvt::invertptt, chan_usbradio_pvt::lasthidtime, chan_usbradio_pvt::lasttx, LOG_ERROR, LOG_NOTICE, LOG_WARNING, chan_usbradio_pvt::name, chan_usbradio_pvt::pmrChan, chan_usbradio_pvt::pttkick, put_eeprom(), chan_usbradio_pvt::rxctcssadj, chan_usbradio_pvt::rxhidsq, chan_usbradio_pvt::rxmixerset, chan_usbradio_pvt::rxsquelchadj, chan_usbradio_pvt::rxvoiceadj, chan_usbradio_pvt::stophid, traceusb1, chan_usbradio_pvt::txctcssadj, chan_usbradio_pvt::txmixaset, chan_usbradio_pvt::txmixbset, and chan_usbradio_pvt::wanteeprom.

Referenced by usbradio_call().

01112 {
01113    unsigned char buf[4],bufsave[4],keyed;
01114    char lastrx, txtmp;
01115    int res;
01116    struct usb_device *usb_dev;
01117    struct usb_dev_handle *usb_handle;
01118    struct chan_usbradio_pvt *o = (struct chan_usbradio_pvt *) arg;
01119    struct timeval to;
01120    fd_set rfds;
01121 
01122    usb_dev = hid_device_init(o->devstr);
01123    if (usb_dev == NULL) {
01124       ast_log(LOG_ERROR,"USB HID device not found\n");
01125       pthread_exit(NULL);
01126    }
01127    usb_handle = usb_open(usb_dev);
01128    if (usb_handle == NULL) {
01129            ast_log(LOG_ERROR,"Not able to open USB device\n");
01130       pthread_exit(NULL);
01131    }
01132    if (usb_claim_interface(usb_handle,C108_HID_INTERFACE) < 0)
01133    {
01134        if (usb_detach_kernel_driver_np(usb_handle,C108_HID_INTERFACE) < 0) {
01135               ast_log(LOG_ERROR,"Not able to detach the USB device\n");
01136          pthread_exit(NULL);
01137       }
01138       if (usb_claim_interface(usb_handle,C108_HID_INTERFACE) < 0) {
01139               ast_log(LOG_ERROR,"Not able to claim the USB device\n");
01140          pthread_exit(NULL);
01141       }
01142    }
01143    memset(buf,0,sizeof(buf));
01144    buf[2] = o->hid_gpio_ctl;
01145    buf[1] = 0;
01146    hid_set_outputs(usb_handle,buf);
01147    memcpy(bufsave,buf,sizeof(buf));
01148    if (pipe(o->pttkick) == -1)
01149    {
01150        ast_log(LOG_ERROR,"Not able to create pipe\n");
01151       pthread_exit(NULL);
01152    }
01153    traceusb1(("hidthread: Starting normally on %s!!\n",o->name));
01154    lastrx = 0;
01155    // popen 
01156    while(!o->stophid)
01157    {
01158       to.tv_sec = 0;
01159       to.tv_usec = 50000;   // maw sph
01160 
01161       FD_ZERO(&rfds);
01162       FD_SET(o->pttkick[0],&rfds);
01163       /* ast_select emulates linux behaviour in terms of timeout handling */
01164       res = ast_select(o->pttkick[0] + 1, &rfds, NULL, NULL, &to);
01165       if (res < 0) {
01166          ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
01167          usleep(10000);
01168          continue;
01169       }
01170       if (FD_ISSET(o->pttkick[0],&rfds))
01171       {
01172          char c;
01173 
01174          if (read(o->pttkick[0],&c,1) < 0) {
01175             ast_log(LOG_ERROR, "read() failed: %s\n", strerror(errno));
01176          }
01177       }
01178       if(o->wanteeprom)
01179       {
01180          ast_mutex_lock(&o->eepromlock);
01181          if (o->eepromctl == 1)  /* to read */
01182          {
01183             /* if CS okay */
01184             if (!get_eeprom(usb_handle,o->eeprom))
01185             {
01186                if (o->eeprom[EEPROM_MAGIC_ADDR] != EEPROM_MAGIC)
01187                {
01188                   ast_log(LOG_NOTICE,"UNSUCCESSFUL: EEPROM MAGIC NUMBER BAD on channel %s\n",o->name);
01189                }
01190                else
01191                {
01192                   o->rxmixerset = o->eeprom[EEPROM_RXMIXERSET];
01193                   o->txmixaset =    o->eeprom[EEPROM_TXMIXASET];
01194                   o->txmixbset = o->eeprom[EEPROM_TXMIXBSET];
01195                   memcpy(&o->rxvoiceadj,&o->eeprom[EEPROM_RXVOICEADJ],sizeof(float));
01196                   memcpy(&o->rxctcssadj,&o->eeprom[EEPROM_RXCTCSSADJ],sizeof(float));
01197                   o->txctcssadj = o->eeprom[EEPROM_TXCTCSSADJ];
01198                   o->rxsquelchadj = o->eeprom[EEPROM_RXSQUELCHADJ];
01199                   ast_log(LOG_NOTICE,"EEPROM Loaded on channel %s\n",o->name);
01200                }
01201             }
01202             else
01203             {
01204                ast_log(LOG_NOTICE,"USB Adapter has no EEPROM installed or Checksum BAD on channel %s\n",o->name);
01205             }
01206             hid_set_outputs(usb_handle,bufsave);
01207          } 
01208          if (o->eepromctl == 2) /* to write */
01209          {
01210             put_eeprom(usb_handle,o->eeprom);
01211             hid_set_outputs(usb_handle,bufsave);
01212             ast_log(LOG_NOTICE,"USB Parameters written to EEPROM on %s\n",o->name);
01213          }
01214          o->eepromctl = 0;
01215          ast_mutex_unlock(&o->eepromlock);
01216       }
01217       buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
01218       hid_get_inputs(usb_handle,buf);
01219       keyed = !(buf[o->hid_io_cor_loc] & o->hid_io_cor);
01220       if (keyed != o->rxhidsq)
01221       {
01222          if(o->debuglevel)printf("chan_usbradio() hidthread: update rxhidsq = %d\n",keyed);
01223          o->rxhidsq=keyed;
01224       }
01225 
01226       /* if change in tx state as controlled by xpmr */
01227       txtmp=o->pmrChan->txPttOut;
01228             
01229       if (o->lasttx != txtmp)
01230       {
01231          o->pmrChan->txPttHid=o->lasttx = txtmp;
01232          if(o->debuglevel)printf("hidthread: tx set to %d\n",txtmp);
01233          buf[o->hid_gpio_loc] = 0;
01234          if (!o->invertptt)
01235          {
01236             if (txtmp) buf[o->hid_gpio_loc] = o->hid_io_ptt;
01237          }
01238          else
01239          {
01240             if (!txtmp) buf[o->hid_gpio_loc] = o->hid_io_ptt;
01241          }
01242          buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
01243          memcpy(bufsave,buf,sizeof(buf));
01244          hid_set_outputs(usb_handle,buf);
01245       }
01246       time(&o->lasthidtime);
01247    }
01248    buf[o->hid_gpio_loc] = 0;
01249    if (o->invertptt) buf[o->hid_gpio_loc] = o->hid_io_ptt;
01250    buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
01251    hid_set_outputs(usb_handle,buf);
01252    pthread_exit(0);
01253 }

static void kickptt ( struct chan_usbradio_pvt o  )  [static]

Definition at line 1099 of file chan_usbradio.c.

References ast_log(), errno, LOG_ERROR, and chan_usbradio_pvt::pttkick.

Referenced by usbradio_read().

01100 {
01101    char c = 0;
01102    //printf("kickptt  %i  %i  %i\n",o->txkeyed,o->txchankey,o->txtestkey);
01103    if (!o) return;
01104    if (!o->pttkick) return;
01105    if (write(o->pttkick[1],&c,1) < 0) {
01106       ast_log(LOG_ERROR, "write() failed: %s\n", strerror(errno));
01107    }
01108 }

static int load_module ( void   )  [static]

Definition at line 3932 of file chan_usbradio.c.

References ast_category_browse(), ast_channel_register(), ast_cli_register_multiple(), ast_config_destroy(), ast_config_load, ast_log(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, find_desc(), global_jbconf, hid_device_mklist(), LOG_ERROR, LOG_NOTICE, store_config(), and usb_list_check().

03933 {
03934    struct ast_config *cfg = NULL;
03935    char *ctg = NULL;
03936 #ifdef   NEW_ASTERISK
03937    struct ast_flags zeroflag = {0};
03938 #endif
03939 
03940    if (hid_device_mklist()) {
03941       ast_log(LOG_NOTICE, "Unable to make hid list\n");
03942       return AST_MODULE_LOAD_DECLINE;
03943    }
03944 
03945    usb_list_check("");
03946 
03947    usbradio_active = NULL;
03948 
03949    /* Copy the default jb config over global_jbconf */
03950    memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
03951 
03952    /* load config file */
03953 #ifdef   NEW_ASTERISK
03954    if (!(cfg = ast_config_load(config,zeroflag))) {
03955 #else
03956    if (!(cfg = ast_config_load(config))) {
03957 #endif
03958       ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
03959       return AST_MODULE_LOAD_DECLINE;
03960    }
03961 
03962    do {
03963       store_config(cfg, ctg);
03964    } while ( (ctg = ast_category_browse(cfg, ctg)) != NULL);
03965 
03966    ast_config_destroy(cfg);
03967 
03968    if (find_desc(usbradio_active) == NULL) {
03969       ast_log(LOG_NOTICE, "radio active device %s not found\n", usbradio_active);
03970       /* XXX we could default to 'dsp' perhaps ? */
03971       /* XXX should cleanup allocated memory etc. */
03972       return AST_MODULE_LOAD_FAILURE;
03973    }
03974 
03975    if (ast_channel_register(&usbradio_tech)) {
03976       ast_log(LOG_ERROR, "Unable to register channel type 'usb'\n");
03977       return AST_MODULE_LOAD_FAILURE;
03978    }
03979 
03980    ast_cli_register_multiple(cli_usbradio, sizeof(cli_usbradio) / sizeof(struct ast_cli_entry));
03981 
03982    return AST_MODULE_LOAD_SUCCESS;
03983 }

static void mixer_write ( struct chan_usbradio_pvt o  )  [static]
static int mult_calc ( int  value  )  [static]

Definition at line 3145 of file chan_usbradio.c.

Referenced by mult_set().

03146 {
03147    const int multx=M_Q8;
03148    int pot,mult;
03149 
03150    pot=((int)(value/4)*4)+2;
03151    mult = multx-( ( multx * (3-(value%4)) ) / (pot+2) );
03152    return(mult);
03153 }

static void mult_set ( struct chan_usbradio_pvt o  )  [static]

Definition at line 3130 of file chan_usbradio.c.

References mult_calc(), chan_usbradio_pvt::pmrChan, chan_usbradio_pvt::txmixaset, and chan_usbradio_pvt::txmixbset.

Referenced by radio_tune(), set_txctcss_level(), and store_config().

03131 {
03132 
03133    if(o->pmrChan->spsTxOutA) {
03134       o->pmrChan->spsTxOutA->outputGain = 
03135          mult_calc((o->txmixaset * 152) / 1000);
03136    }
03137    if(o->pmrChan->spsTxOutB){
03138       o->pmrChan->spsTxOutB->outputGain = 
03139          mult_calc((o->txmixbset * 152) / 1000);
03140    }
03141 }

static void pmrdump ( struct chan_usbradio_pvt o  )  [static]

Definition at line 3234 of file chan_usbradio.c.

References chan_usbradio_pvt::b, chan_usbradio_pvt::devicenum, chan_usbradio_pvt::devstr, chan_usbradio_pvt::micmax, chan_usbradio_pvt::numrxctcssfreqs, pd, pf, chan_usbradio_pvt::pmrChan, ps, chan_usbradio_pvt::rxboostset, chan_usbradio_pvt::rxcdtype, chan_usbradio_pvt::rxctcss, chan_usbradio_pvt::rxctcssadj, chan_usbradio_pvt::rxdemod, chan_usbradio_pvt::rxmixerset, chan_usbradio_pvt::rxpolarity, chan_usbradio_pvt::rxsdtype, chan_usbradio_pvt::rxsquelchadj, chan_usbradio_pvt::rxvoiceadj, chan_usbradio_pvt::spkrmax, chan_usbradio_pvt::txctcss, chan_usbradio_pvt::txctcssdefault, chan_usbradio_pvt::txctcssfreq, chan_usbradio_pvt::txmixa, chan_usbradio_pvt::txmixaset, chan_usbradio_pvt::txmixb, chan_usbradio_pvt::txmixbset, chan_usbradio_pvt::txpolarity, chan_usbradio_pvt::txprelim, and chan_usbradio_pvt::txtoctype.

Referenced by radio_tune().

03235 {
03236    t_pmr_chan *p;
03237    int i;
03238 
03239    p=o->pmrChan;
03240 
03241    printf("\nodump()\n");
03242 
03243    pd(o->devicenum);
03244    ps(o->devstr);
03245 
03246    pd(o->micmax);
03247    pd(o->spkrmax);
03248 
03249    pd(o->rxdemod);
03250    pd(o->rxcdtype);
03251    pd(o->rxsdtype);
03252    pd(o->txtoctype);
03253 
03254    pd(o->rxmixerset);
03255    pd(o->rxboostset);
03256 
03257    pf(o->rxvoiceadj);
03258    pf(o->rxctcssadj);
03259    pd(o->rxsquelchadj);
03260 
03261    ps(o->txctcssdefault);
03262    ps(o->txctcssfreq);
03263 
03264    pd(o->numrxctcssfreqs);
03265    if(o->numrxctcssfreqs>0)
03266    {
03267       for(i=0;i<o->numrxctcssfreqs;i++)
03268       {
03269          printf(" %i =  %s  %s\n",i,o->rxctcss[i],o->txctcss[i]); 
03270       }
03271    }
03272 
03273    pd(o->b.rxpolarity);
03274    pd(o->b.txpolarity);
03275 
03276    pd(o->txprelim);
03277    pd(o->txmixa);
03278    pd(o->txmixb);
03279    
03280    pd(o->txmixaset);
03281    pd(o->txmixbset);
03282    
03283    printf("\npmrdump()\n");
03284  
03285    pd(p->devicenum);
03286 
03287    printf("prxSquelchAdjust=%i\n",*(o->pmrChan->prxSquelchAdjust));
03288 
03289    pd(p->rxCarrierPoint);
03290    pd(p->rxCarrierHyst);
03291 
03292    pd(*p->prxVoiceAdjust);
03293    pd(*p->prxCtcssAdjust);
03294 
03295    pd(p->rxfreq);
03296    pd(p->txfreq);
03297 
03298    pd(p->rxCtcss->relax);
03299    //pf(p->rxCtcssFreq);   
03300    pd(p->numrxcodes);
03301    if(o->pmrChan->numrxcodes>0)
03302    {
03303       for(i=0;i<o->pmrChan->numrxcodes;i++)
03304       {
03305          printf(" %i = %s\n",i,o->pmrChan->pRxCode[i]); 
03306       }
03307    }
03308 
03309    pd(p->txTocType);
03310    ps(p->pTxCodeDefault);
03311    pd(p->txcodedefaultsmode);
03312    pd(p->numtxcodes);
03313    if(o->pmrChan->numtxcodes>0)
03314    {
03315       for(i=0;i<o->pmrChan->numtxcodes;i++)
03316       {                                       
03317          printf(" %i = %s\n",i,o->pmrChan->pTxCode[i]); 
03318       }
03319    }
03320 
03321    pd(p->b.rxpolarity);
03322    pd(p->b.txpolarity);
03323    pd(p->b.dcsrxpolarity);
03324    pd(p->b.dcstxpolarity);
03325    pd(p->b.lsdrxpolarity);
03326    pd(p->b.lsdtxpolarity);
03327 
03328    pd(p->txMixA);
03329    pd(p->txMixB);
03330     
03331    pd(p->rxDeEmpEnable);
03332    pd(p->rxCenterSlicerEnable);
03333    pd(p->rxCtcssDecodeEnable);
03334    pd(p->rxDcsDecodeEnable);
03335    pd(p->b.ctcssRxEnable);
03336    pd(p->b.dcsRxEnable);
03337    pd(p->b.lmrRxEnable);
03338    pd(p->b.dstRxEnable);
03339    pd(p->smode);
03340 
03341    pd(p->txHpfEnable);
03342    pd(p->txLimiterEnable);
03343    pd(p->txPreEmpEnable);
03344    pd(p->txLpfEnable);
03345 
03346    if(p->spsTxOutA)pd(p->spsTxOutA->outputGain);
03347    if(p->spsTxOutB)pd(p->spsTxOutB->outputGain);
03348    pd(p->txPttIn);
03349    pd(p->txPttOut);
03350 
03351    pd(p->tracetype);
03352 
03353    return;
03354 }

static void put_eeprom ( struct usb_dev_handle *  handle,
unsigned short *  buf 
) [static]

Definition at line 860 of file chan_usbradio.c.

References EEPROM_CS_ADDR, EEPROM_MAGIC, EEPROM_MAGIC_ADDR, EEPROM_START_ADDR, and write_eeprom().

Referenced by hidthread().

00861 {
00862 int   i;
00863 unsigned short cs;
00864 
00865    cs = 0xffff;
00866    buf[EEPROM_MAGIC_ADDR] = EEPROM_MAGIC;
00867    for(i = EEPROM_START_ADDR; i < EEPROM_CS_ADDR; i++)
00868    {
00869       write_eeprom(handle,i,buf[i]);
00870       cs += buf[i];
00871    }
00872    buf[EEPROM_CS_ADDR] = (65535 - cs) + 1;
00873    write_eeprom(handle,i,buf[EEPROM_CS_ADDR]);
00874 }

static int radio_active ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2574 of file chan_usbradio.c.

References ast_cli(), find_desc(), chan_usbradio_pvt::name, chan_usbradio_pvt::next, chan_usbradio_pvt::pmrChan, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

Referenced by handle_radio_active().

02575 {
02576         if (argc == 2)
02577                 ast_cli(fd, "active (command) USB Radio device is [%s]\n", usbradio_active);
02578         else if (argc != 3)
02579                 return RESULT_SHOWUSAGE;
02580         else {
02581                 struct chan_usbradio_pvt *o;
02582                 if (strcmp(argv[2], "show") == 0) {
02583                         for (o = usbradio_default.next; o; o = o->next)
02584                                 ast_cli(fd, "device [%s] exists\n", o->name);
02585                         return RESULT_SUCCESS;
02586                 }
02587                 o = find_desc(argv[2]);
02588                 if (o == NULL)
02589                         ast_cli(fd, "No device [%s] exists\n", argv[2]);
02590                 else
02591             {
02592                struct chan_usbradio_pvt *ao;
02593                for (ao = usbradio_default.next; ao && ao->name ; ao = ao->next)ao->pmrChan->b.radioactive=0;
02594                     usbradio_active = o->name;
02595                 o->pmrChan->b.radioactive=1;
02596             }
02597         }
02598         return RESULT_SUCCESS;
02599 }

static int radio_set_debug ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2556 of file chan_usbradio.c.

References ast_cli(), chan_usbradio_pvt::debuglevel, find_desc(), and RESULT_SUCCESS.

Referenced by handle_radio_debug().

02557 {
02558    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02559 
02560    o->debuglevel=1;
02561    ast_cli(fd,"usbradio debug on.\n");
02562    return RESULT_SUCCESS;
02563 }

static int radio_set_debug_off ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2565 of file chan_usbradio.c.

References ast_cli(), chan_usbradio_pvt::debuglevel, find_desc(), and RESULT_SUCCESS.

Referenced by handle_radio_debug_off().

02566 {
02567    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02568 
02569    o->debuglevel=0;
02570    ast_cli(fd,"usbradio debug off.\n");
02571    return RESULT_SUCCESS;
02572 }

static int radio_set_xpmr_debug ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2603 of file chan_usbradio.c.

References ast_cli(), find_desc(), chan_usbradio_pvt::pmrChan, and RESULT_SUCCESS.

Referenced by handle_set_xdebug().

02604 {
02605    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02606 
02607    if (argc == 4)
02608    {
02609       int i;
02610       i = atoi(argv[3]);
02611       if ((i >= 0) && (i <= 100))
02612       { 
02613          o->pmrChan->tracelevel=i;
02614       }
02615     }
02616    // add ability to set it for a number of frames after which it reverts
02617    ast_cli(fd,"usbradio xdebug on tracelevel %i\n",o->pmrChan->tracelevel);
02618 
02619    return RESULT_SUCCESS;
02620 }

static int radio_tune ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2284 of file chan_usbradio.c.

References ast_cli(), ast_log(), ast_mutex_lock(), ast_mutex_unlock(), chan_usbradio_pvt::b, chan_usbradio_pvt::devstr, chan_usbradio_pvt::eepromctl, chan_usbradio_pvt::eepromlock, find_desc(), LOG_ERROR, LOG_WARNING, mixer_write(), mult_set(), chan_usbradio_pvt::name, chan_usbradio_pvt::pmrChan, pmrdump(), RESULT_SHOWUSAGE, RESULT_SUCCESS, RX_CAP_RAW_FILE, RX_CAP_TRACE_FILE, chan_usbradio_pvt::rxcap2, chan_usbradio_pvt::rxcapraw, chan_usbradio_pvt::rxsquelchadj, set_txctcss_level(), tune_rxctcss(), tune_rxinput(), tune_rxvoice(), tune_txoutput(), tune_write(), TX_CAP_RAW_FILE, TX_CAP_TRACE_FILE, TX_OUT_AUX, TX_OUT_COMPOSITE, TX_OUT_LSD, TX_OUT_VOICE, chan_usbradio_pvt::txcap2, chan_usbradio_pvt::txcapraw, chan_usbradio_pvt::txctcssadj, chan_usbradio_pvt::txmixa, chan_usbradio_pvt::txmixaset, chan_usbradio_pvt::txmixb, chan_usbradio_pvt::txmixbset, and chan_usbradio_pvt::txtestkey.

Referenced by handle_radio_tune().

02285 {
02286    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02287    int i=0;
02288 
02289    if ((argc < 2) || (argc > 4))
02290       return RESULT_SHOWUSAGE; 
02291 
02292    if (argc == 2) /* just show stuff */
02293    {
02294       ast_cli(fd,"Active radio interface is [%s]\n",usbradio_active);
02295       ast_cli(fd,"Output A is currently set to ");
02296       if(o->txmixa==TX_OUT_COMPOSITE)ast_cli(fd,"composite.\n");
02297       else if (o->txmixa==TX_OUT_VOICE)ast_cli(fd,"voice.\n");
02298       else if (o->txmixa==TX_OUT_LSD)ast_cli(fd,"tone.\n");
02299       else if (o->txmixa==TX_OUT_AUX)ast_cli(fd,"auxvoice.\n");
02300       else ast_cli(fd,"off.\n");
02301 
02302       ast_cli(fd,"Output B is currently set to ");
02303       if(o->txmixb==TX_OUT_COMPOSITE)ast_cli(fd,"composite.\n");
02304       else if (o->txmixb==TX_OUT_VOICE)ast_cli(fd,"voice.\n");
02305       else if (o->txmixb==TX_OUT_LSD)ast_cli(fd,"tone.\n");
02306       else if (o->txmixb==TX_OUT_AUX)ast_cli(fd,"auxvoice.\n");
02307       else ast_cli(fd,"off.\n");
02308 
02309       ast_cli(fd,"Tx Voice Level currently set to %d\n",o->txmixaset);
02310       ast_cli(fd,"Tx Tone Level currently set to %d\n",o->txctcssadj);
02311       ast_cli(fd,"Rx Squelch currently set to %d\n",o->rxsquelchadj);
02312       ast_cli(fd,"Device String is %s\n",o->devstr);
02313       return RESULT_SHOWUSAGE;
02314    }
02315 
02316    o->pmrChan->b.tuning=1;
02317 
02318    if (!strcasecmp(argv[2],"rxnoise")) tune_rxinput(fd,o);
02319    else if (!strcasecmp(argv[2],"rxvoice")) tune_rxvoice(fd,o);
02320    else if (!strcasecmp(argv[2],"rxtone")) tune_rxctcss(fd,o);
02321    else if (!strcasecmp(argv[2],"rxsquelch"))
02322    {
02323       if (argc == 3)
02324       {
02325           ast_cli(fd,"Current Signal Strength is %d\n",((32767-o->pmrChan->rxRssi)*1000/32767));
02326           ast_cli(fd,"Current Squelch setting is %d\n",o->rxsquelchadj);
02327          //ast_cli(fd,"Current Raw RSSI        is %d\n",o->pmrChan->rxRssi);
02328           //ast_cli(fd,"Current (real) Squelch setting is %d\n",*(o->pmrChan->prxSquelchAdjust));
02329       } else {
02330          i = atoi(argv[3]);
02331          if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
02332          ast_cli(fd,"Changed Squelch setting to %d\n",i);
02333          o->rxsquelchadj = i;
02334          *(o->pmrChan->prxSquelchAdjust)= ((999 - i) * 32767) / 1000;
02335       }
02336    }
02337    else if (!strcasecmp(argv[2],"txvoice")) {
02338       i = 0;
02339 
02340       if( (o->txmixa!=TX_OUT_VOICE) && (o->txmixb!=TX_OUT_VOICE) &&
02341          (o->txmixa!=TX_OUT_COMPOSITE) && (o->txmixb!=TX_OUT_COMPOSITE)
02342         )
02343       {
02344          ast_log(LOG_ERROR,"No txvoice output configured.\n");
02345       }
02346       else if (argc == 3)
02347       {
02348          if((o->txmixa==TX_OUT_VOICE)||(o->txmixa==TX_OUT_COMPOSITE))
02349             ast_cli(fd,"Current txvoice setting on Channel A is %d\n",o->txmixaset);
02350          else
02351             ast_cli(fd,"Current txvoice setting on Channel B is %d\n",o->txmixbset);
02352       }
02353       else
02354       {
02355          i = atoi(argv[3]);
02356          if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
02357 
02358          if((o->txmixa==TX_OUT_VOICE)||(o->txmixa==TX_OUT_COMPOSITE))
02359          {
02360             o->txmixaset=i;
02361             ast_cli(fd,"Changed txvoice setting on Channel A to %d\n",o->txmixaset);
02362          }
02363          else
02364          {
02365             o->txmixbset=i;   
02366             ast_cli(fd,"Changed txvoice setting on Channel B to %d\n",o->txmixbset);
02367          }
02368          mixer_write(o);
02369          mult_set(o);
02370          ast_cli(fd,"Changed Tx Voice Output setting to %d\n",i);
02371       }
02372       o->pmrChan->b.txCtcssInhibit=1;
02373       tune_txoutput(o,i,fd);
02374       o->pmrChan->b.txCtcssInhibit=0;
02375    }
02376    else if (!strcasecmp(argv[2],"txall")) {
02377       i = 0;
02378 
02379       if( (o->txmixa!=TX_OUT_VOICE) && (o->txmixb!=TX_OUT_VOICE) &&
02380          (o->txmixa!=TX_OUT_COMPOSITE) && (o->txmixb!=TX_OUT_COMPOSITE)
02381         )
02382       {
02383          ast_log(LOG_ERROR,"No txvoice output configured.\n");
02384       }
02385       else if (argc == 3)
02386       {
02387          if((o->txmixa==TX_OUT_VOICE)||(o->txmixa==TX_OUT_COMPOSITE))
02388             ast_cli(fd,"Current txvoice setting on Channel A is %d\n",o->txmixaset);
02389          else
02390             ast_cli(fd,"Current txvoice setting on Channel B is %d\n",o->txmixbset);
02391       }
02392       else
02393       {
02394          i = atoi(argv[3]);
02395          if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
02396 
02397          if((o->txmixa==TX_OUT_VOICE)||(o->txmixa==TX_OUT_COMPOSITE))
02398          {
02399             o->txmixaset=i;
02400             ast_cli(fd,"Changed txvoice setting on Channel A to %d\n",o->txmixaset);
02401          }
02402          else
02403          {
02404             o->txmixbset=i;   
02405             ast_cli(fd,"Changed txvoice setting on Channel B to %d\n",o->txmixbset);
02406          }
02407          mixer_write(o);
02408          mult_set(o);
02409          ast_cli(fd,"Changed Tx Voice Output setting to %d\n",i);
02410       }
02411       tune_txoutput(o,i,fd);
02412    }
02413    else if (!strcasecmp(argv[2],"auxvoice")) {
02414       i = 0;
02415       if( (o->txmixa!=TX_OUT_AUX) && (o->txmixb!=TX_OUT_AUX))
02416       {
02417          ast_log(LOG_WARNING,"No auxvoice output configured.\n");
02418       }
02419       else if (argc == 3)
02420       {
02421          if(o->txmixa==TX_OUT_AUX)
02422             ast_cli(fd,"Current auxvoice setting on Channel A is %d\n",o->txmixaset);
02423          else
02424             ast_cli(fd,"Current auxvoice setting on Channel B is %d\n",o->txmixbset);
02425       }
02426       else
02427       {
02428          i = atoi(argv[3]);
02429          if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
02430          if(o->txmixa==TX_OUT_AUX)
02431          {
02432             o->txmixbset=i;
02433             ast_cli(fd,"Changed auxvoice setting on Channel A to %d\n",o->txmixaset);
02434          }
02435          else
02436          {
02437             o->txmixbset=i;
02438             ast_cli(fd,"Changed auxvoice setting on Channel B to %d\n",o->txmixbset);
02439          }
02440          mixer_write(o);
02441          mult_set(o);
02442       }
02443       //tune_auxoutput(o,i);
02444    }
02445    else if (!strcasecmp(argv[2],"txtone"))
02446    {
02447       if (argc == 3)
02448          ast_cli(fd,"Current Tx CTCSS modulation setting = %d\n",o->txctcssadj);
02449       else
02450       {
02451          i = atoi(argv[3]);
02452          if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
02453          o->txctcssadj = i;
02454          set_txctcss_level(o);
02455          ast_cli(fd,"Changed Tx CTCSS modulation setting to %i\n",i);
02456       }
02457       o->txtestkey=1;
02458       usleep(5000000);
02459       o->txtestkey=0;
02460    }
02461    else if (!strcasecmp(argv[2],"dump")) pmrdump(o);
02462    else if (!strcasecmp(argv[2],"nocap"))    
02463    {
02464       ast_cli(fd,"File capture (trace) was rx=%d tx=%d and now off.\n",o->b.rxcap2,o->b.txcap2);
02465       ast_cli(fd,"File capture (raw)   was rx=%d tx=%d and now off.\n",o->b.rxcapraw,o->b.txcapraw);
02466       o->b.rxcapraw=o->b.txcapraw=o->b.rxcap2=o->b.txcap2=o->pmrChan->b.rxCapture=o->pmrChan->b.txCapture=0;
02467       if (frxcapraw) { fclose(frxcapraw); frxcapraw = NULL; }
02468       if (frxcaptrace) { fclose(frxcaptrace); frxcaptrace = NULL; }
02469       if (frxoutraw) { fclose(frxoutraw); frxoutraw = NULL; }
02470       if (ftxcapraw) { fclose(ftxcapraw); ftxcapraw = NULL; }
02471       if (ftxcaptrace) { fclose(ftxcaptrace); ftxcaptrace = NULL; }
02472       if (ftxoutraw) { fclose(ftxoutraw); ftxoutraw = NULL; }
02473    }
02474    else if (!strcasecmp(argv[2],"rxtracecap")) 
02475    {
02476       if (!frxcaptrace) frxcaptrace= fopen(RX_CAP_TRACE_FILE,"w");
02477       ast_cli(fd,"Trace rx on.\n");
02478       o->b.rxcap2=o->pmrChan->b.rxCapture=1;
02479    }
02480    else if (!strcasecmp(argv[2],"txtracecap")) 
02481    {
02482       if (!ftxcaptrace) ftxcaptrace= fopen(TX_CAP_TRACE_FILE,"w");
02483       ast_cli(fd,"Trace tx on.\n");
02484       o->b.txcap2=o->pmrChan->b.txCapture=1;
02485    }
02486    else if (!strcasecmp(argv[2],"rxcap")) 
02487    {
02488       if (!frxcapraw) frxcapraw = fopen(RX_CAP_RAW_FILE,"w");
02489       ast_cli(fd,"cap rx raw on.\n");
02490       o->b.rxcapraw=1;
02491    }
02492    else if (!strcasecmp(argv[2],"txcap")) 
02493    {
02494       if (!ftxcapraw) ftxcapraw = fopen(TX_CAP_RAW_FILE,"w");
02495       ast_cli(fd,"cap tx raw on.\n");
02496       o->b.txcapraw=1;
02497    }
02498    else if (!strcasecmp(argv[2],"save"))
02499    {
02500       tune_write(o);
02501       ast_cli(fd,"Saved radio tuning settings to usbradio_tune_%s.conf\n",o->name);
02502    }
02503    else if (!strcasecmp(argv[2],"load"))
02504    {
02505       ast_mutex_lock(&o->eepromlock);
02506       while(o->eepromctl)
02507       {
02508          ast_mutex_unlock(&o->eepromlock);
02509          usleep(10000);
02510          ast_mutex_lock(&o->eepromlock);
02511       }
02512       o->eepromctl = 1;  /* request a load */
02513       ast_mutex_unlock(&o->eepromlock);
02514 
02515       ast_cli(fd,"Requesting loading of tuning settings from EEPROM for channel %s\n",o->name);
02516    }
02517    else
02518    {
02519       o->pmrChan->b.tuning=0;
02520       return RESULT_SHOWUSAGE;
02521    }
02522    o->pmrChan->b.tuning=0;
02523    return RESULT_SUCCESS;
02524 }

static unsigned short read_eeprom ( struct usb_dev_handle *  handle,
int  addr 
) [static]

Definition at line 819 of file chan_usbradio.c.

References buf, hid_get_inputs(), and hid_set_outputs().

Referenced by get_eeprom().

00820 {
00821    unsigned char buf[4];
00822 
00823    buf[0] = 0x80;
00824    buf[1] = 0;
00825    buf[2] = 0;
00826    buf[3] = 0x80 | (addr & 0x3f);
00827    hid_set_outputs(handle,buf);
00828    memset(buf,0,sizeof(buf));
00829    hid_get_inputs(handle,buf);
00830    return(buf[1] + (buf[2] << 8));
00831 }

static char* res2cli ( int  r  )  [static]

Definition at line 3800 of file chan_usbradio.c.

References CLI_FAILURE, CLI_SHOWUSAGE, CLI_SUCCESS, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

Referenced by handle_console_key(), handle_console_unkey(), handle_radio_active(), handle_radio_debug(), handle_radio_debug_off(), handle_radio_tune(), and handle_set_xdebug().

03802 {
03803    switch (r)
03804    {
03805        case RESULT_SUCCESS:
03806       return(CLI_SUCCESS);
03807        case RESULT_SHOWUSAGE:
03808       return(CLI_SHOWUSAGE);
03809        default:
03810       return(CLI_FAILURE);
03811    }
03812 }

static void ring ( struct chan_usbradio_pvt o,
int  x 
) [static]

Definition at line 1685 of file chan_usbradio.c.

Referenced by ind_load_module(), usbradio_hangup(), and usbradio_indicate().

01686 {
01687 #ifndef  NEW_ASTERISK
01688    write(o->sndcmd[1], &x, sizeof(x));
01689 #endif
01690 }

static int set_txctcss_level ( struct chan_usbradio_pvt o  )  [static]

Definition at line 2531 of file chan_usbradio.c.

References mixer_write(), mult_set(), chan_usbradio_pvt::pmrChan, TX_OUT_LSD, chan_usbradio_pvt::txctcssadj, chan_usbradio_pvt::txmixa, chan_usbradio_pvt::txmixaset, chan_usbradio_pvt::txmixb, and chan_usbradio_pvt::txmixbset.

Referenced by radio_tune(), and store_config().

02532 {                      
02533    if (o->txmixa == TX_OUT_LSD)
02534    {
02535 //    o->txmixaset=(151*o->txctcssadj) / 1000;
02536       o->txmixaset=o->txctcssadj;
02537       mixer_write(o);
02538       mult_set(o);
02539    }
02540    else if (o->txmixb == TX_OUT_LSD)
02541    {
02542 //    o->txmixbset=(151*o->txctcssadj) / 1000;
02543       o->txmixbset=o->txctcssadj;
02544       mixer_write(o);
02545       mult_set(o);
02546    }
02547    else
02548    {
02549       *o->pmrChan->ptxCtcssAdjust=(o->txctcssadj * M_Q8) / 1000;
02550    }
02551    return 0;
02552 }

static int setamixer ( int  devnum,
char *  param,
int  v1,
int  v2 
) [static]

Definition at line 749 of file chan_usbradio.c.

References id, str, and type.

Referenced by mixer_write(), and tune_rxinput().

00750 {
00751 int   type;
00752 char  str[100];
00753 snd_hctl_t *hctl;
00754 snd_ctl_elem_id_t *id;
00755 snd_ctl_elem_value_t *control;
00756 snd_hctl_elem_t *elem;
00757 snd_ctl_elem_info_t *info;
00758 
00759    sprintf(str,"hw:%d",devnum);
00760    if (snd_hctl_open(&hctl, str, 0)) return(-1);
00761    snd_hctl_load(hctl);
00762    snd_ctl_elem_id_alloca(&id);
00763    snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
00764    snd_ctl_elem_id_set_name(id, param);  
00765    elem = snd_hctl_find_elem(hctl, id);
00766    if (!elem)
00767    {
00768       snd_hctl_close(hctl);
00769       return(-1);
00770    }
00771    snd_ctl_elem_info_alloca(&info);
00772    snd_hctl_elem_info(elem,info);
00773    type = snd_ctl_elem_info_get_type(info);
00774    snd_ctl_elem_value_alloca(&control);
00775    snd_ctl_elem_value_set_id(control, id);    
00776    switch(type)
00777    {
00778        case SND_CTL_ELEM_TYPE_INTEGER:
00779       snd_ctl_elem_value_set_integer(control, 0, v1);
00780       if (v2 > 0) snd_ctl_elem_value_set_integer(control, 1, v2);
00781       break;
00782        case SND_CTL_ELEM_TYPE_BOOLEAN:
00783       snd_ctl_elem_value_set_integer(control, 0, (v1 != 0));
00784       break;
00785    }
00786    if (snd_hctl_elem_write(elem, control))
00787    {
00788       snd_hctl_close(hctl);
00789       return(-1);
00790    }
00791    snd_hctl_close(hctl);
00792    return(0);
00793 }

static int setformat ( struct chan_usbradio_pvt o,
int  mode 
) [static]

Definition at line 1516 of file chan_usbradio.c.

References ast_log(), ast_tvnow(), ast_verbose, chan_usbradio_pvt::devicenum, chan_usbradio_pvt::duplex, errno, ast_channel::fds, chan_usbradio_pvt::frags, chan_usbradio_pvt::lastopen, LOG_WARNING, chan_usbradio_pvt::M_FULL, chan_usbradio_pvt::M_READ, chan_usbradio_pvt::M_UNSET, chan_usbradio_pvt::M_WRITE, O_CLOSE, option_verbose, chan_usbradio_pvt::owner, chan_usbradio_pvt::sounddev, VERBOSE_PREFIX_2, WARN_frag, WARN_speed, and chan_usbradio_pvt::warned.

Referenced by soundcard_writeframe(), usbradio_hangup(), and usbradio_new().

01517 {
01518    int fmt, desired, res, fd;
01519    char device[100];
01520 
01521    if (o->sounddev >= 0) {
01522       ioctl(o->sounddev, SNDCTL_DSP_RESET, 0);
01523       close(o->sounddev);
01524       o->duplex = M_UNSET;
01525       o->sounddev = -1;
01526    }
01527    if (mode == O_CLOSE)    /* we are done */
01528       return 0;
01529    o->lastopen = ast_tvnow();
01530    strcpy(device,"/dev/dsp");
01531    if (o->devicenum)
01532       sprintf(device,"/dev/dsp%d",o->devicenum);
01533    fd = o->sounddev = open(device, mode | O_NONBLOCK);
01534    if (fd < 0) {
01535       ast_log(LOG_WARNING, "Unable to re-open DSP device %d: %s\n", o->devicenum, strerror(errno));
01536       return -1;
01537    }
01538    if (o->owner)
01539       o->owner->fds[0] = fd;
01540 
01541 #if __BYTE_ORDER == __LITTLE_ENDIAN
01542    fmt = AFMT_S16_LE;
01543 #else
01544    fmt = AFMT_S16_BE;
01545 #endif
01546    res = ioctl(fd, SNDCTL_DSP_SETFMT, &fmt);
01547    if (res < 0) {
01548       ast_log(LOG_WARNING, "Unable to set format to 16-bit signed\n");
01549       return -1;
01550    }
01551    switch (mode) {
01552       case O_RDWR:
01553          res = ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
01554          /* Check to see if duplex set (FreeBSD Bug) */
01555          res = ioctl(fd, SNDCTL_DSP_GETCAPS, &fmt);
01556          if (res == 0 && (fmt & DSP_CAP_DUPLEX)) {
01557             if (option_verbose > 1)
01558                ast_verbose(VERBOSE_PREFIX_2 "Console is full duplex\n");
01559             o->duplex = M_FULL;
01560          };
01561          break;
01562       case O_WRONLY:
01563          o->duplex = M_WRITE;
01564          break;
01565       case O_RDONLY:
01566          o->duplex = M_READ;
01567          break;
01568    }
01569 
01570    fmt = 1;
01571    res = ioctl(fd, SNDCTL_DSP_STEREO, &fmt);
01572    if (res < 0) {
01573       ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
01574       return -1;
01575    }
01576    fmt = desired = 48000;                    /* 8000 Hz desired */
01577    res = ioctl(fd, SNDCTL_DSP_SPEED, &fmt);
01578 
01579    if (res < 0) {
01580       ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
01581       return -1;
01582    }
01583    if (fmt != desired) {
01584       if (!(o->warned & WARN_speed)) {
01585          ast_log(LOG_WARNING,
01586              "Requested %d Hz, got %d Hz -- sound may be choppy\n",
01587              desired, fmt);
01588          o->warned |= WARN_speed;
01589       }
01590    }
01591    /*
01592     * on Freebsd, SETFRAGMENT does not work very well on some cards.
01593     * Default to use 256 bytes, let the user override
01594     */
01595    if (o->frags) {
01596       fmt = o->frags;
01597       res = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fmt);
01598       if (res < 0) {
01599          if (!(o->warned & WARN_frag)) {
01600             ast_log(LOG_WARNING,
01601                "Unable to set fragment size -- sound may be choppy\n");
01602             o->warned |= WARN_frag;
01603          }
01604       }
01605    }
01606    /* on some cards, we need SNDCTL_DSP_SETTRIGGER to start outputting */
01607    res = PCM_ENABLE_INPUT | PCM_ENABLE_OUTPUT;
01608    res = ioctl(fd, SNDCTL_DSP_SETTRIGGER, &res);
01609    /* it may fail if we are in half duplex, never mind */
01610    return 0;
01611 }

static int soundcard_writeframe ( struct chan_usbradio_pvt o,
short *  data 
) [static]

Definition at line 1348 of file chan_usbradio.c.

References ast_log(), FRAME_SIZE, LOG_WARNING, chan_usbradio_pvt::pmrChan, chan_usbradio_pvt::queuesize, setformat(), chan_usbradio_pvt::sounddev, used_blocks(), and chan_usbradio_pvt::w_errors.

Referenced by usbradio_read().

01349 {
01350    int res;
01351 
01352    if (o->sounddev < 0)
01353       setformat(o, O_RDWR);
01354    if (o->sounddev < 0)
01355       return 0;            /* not fatal */
01356    //  maw maw sph !!! may or may not be a good thing
01357    //  drop the frame if not transmitting, this keeps from gradually
01358    //  filling the buffer when asterisk clock > usb sound clock
01359    if(!o->pmrChan->txPttIn && !o->pmrChan->txPttOut)
01360    {
01361       //return 0;
01362    }
01363    /*
01364     * Nothing complex to manage the audio device queue.
01365     * If the buffer is full just drop the extra, otherwise write.
01366     * XXX in some cases it might be useful to write anyways after
01367     * a number of failures, to restart the output chain.
01368     */
01369    res = used_blocks(o);
01370    if (res > o->queuesize) {  /* no room to write a block */
01371        // ast_log(LOG_WARNING, "sound device write buffer overflow\n");
01372       if (o->w_errors++ == 0 && (usbradio_debug & 0x4))
01373          ast_log(LOG_WARNING, "write: used %d blocks (%d)\n", res, o->w_errors);
01374       return 0;
01375    }
01376    o->w_errors = 0;
01377 
01378    return write(o->sounddev, ((void *) data), FRAME_SIZE * 2 * 12);
01379 }

static struct chan_usbradio_pvt* store_config ( struct ast_config cfg,
char *  ctg 
) [static, read]

Definition at line 3405 of file chan_usbradio.c.

References amixer_max(), chan_usbradio_pvt::area, ast_calloc, ast_config_destroy(), ast_config_load, ast_dsp_new(), ast_dsp_set_digitmode(), ast_dsp_set_features(), ast_jb_read_conf(), ast_log(), ast_mutex_init(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create_background, ast_strdup, ast_tvnow(), ast_variable_browse(), chan_usbradio_pvt::autoanswer, chan_usbradio_pvt::autohangup, chan_usbradio_pvt::b, config1, chan_usbradio_pvt::ctx, chan_usbradio_pvt::dcsrxpolarity, chan_usbradio_pvt::dcstxpolarity, chan_usbradio_pvt::debuglevel, chan_usbradio_pvt::devicenum, chan_usbradio_pvt::devstr, chan_usbradio_pvt::dsp, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MUTECONF, DSP_DIGITMODE_RELAXDTMF, DSP_FEATURE_DIGIT_DETECT, chan_usbradio_pvt::eepromctl, chan_usbradio_pvt::eepromlock, chan_usbradio_pvt::ext, find_desc_usb(), chan_usbradio_pvt::frags, free, global_jbconf, chan_usbradio_pvt::hdwtype, hidhdwconfig(), chan_usbradio_pvt::idleinterval, chan_usbradio_pvt::invertptt, chan_usbradio_pvt::language, chan_usbradio_pvt::lastopen, LOG_ERROR, LOG_NOTICE, LOG_WARNING, chan_usbradio_pvt::loopback, chan_usbradio_pvt::lsdrxpolarity, chan_usbradio_pvt::lsdtxpolarity, M_BOOL, M_END, M_F, M_START, M_STR, M_UINT, chan_usbradio_pvt::micmax, MIXER_PARAM_MIC_CAPTURE_VOL, MIXER_PARAM_SPKR_PLAYBACK_VOL, mixer_write(), chan_usbradio_pvt::mohinterpret, mult_set(), ast_variable::name, chan_usbradio_pvt::name, chan_usbradio_pvt::next, ast_variable::next, chan_usbradio_pvt::overridecontext, chan_usbradio_pvt::pmrChan, chan_usbradio_pvt::queuesize, chan_usbradio_pvt::radioactive, chan_usbradio_pvt::radioduplex, chan_usbradio_pvt::rptnum, chan_usbradio_pvt::rxboostset, chan_usbradio_pvt::rxcdtype, chan_usbradio_pvt::rxcpusaver, chan_usbradio_pvt::rxctcssadj, chan_usbradio_pvt::rxctcssfreqs, chan_usbradio_pvt::rxctcssrelax, chan_usbradio_pvt::rxdemod, chan_usbradio_pvt::rxfreq, chan_usbradio_pvt::rxmixerset, chan_usbradio_pvt::rxpolarity, chan_usbradio_pvt::rxsquelchadj, chan_usbradio_pvt::rxsqvoxadj, chan_usbradio_pvt::rxvoiceadj, set_txctcss_level(), chan_usbradio_pvt::spkrmax, store_callerid(), store_rxcdtype(), store_rxctcssadj(), store_rxdemod(), store_rxgain(), store_rxsdtype(), store_rxvoiceadj(), store_txmixa(), store_txmixb(), store_txtoctype(), chan_usbradio_pvt::tracelevel, chan_usbradio_pvt::tracetype, traceusb1, chan_usbradio_pvt::turnoffs, TX_OUT_COMPOSITE, TX_OUT_LSD, TX_OUT_VOICE, chan_usbradio_pvt::txcpusaver, chan_usbradio_pvt::txctcssadj, chan_usbradio_pvt::txctcssdefault, chan_usbradio_pvt::txctcssfreq, chan_usbradio_pvt::txctcssfreqs, chan_usbradio_pvt::txfreq, chan_usbradio_pvt::txmixa, chan_usbradio_pvt::txmixaset, chan_usbradio_pvt::txmixb, chan_usbradio_pvt::txmixbset, chan_usbradio_pvt::txpolarity, chan_usbradio_pvt::txprelim, chan_usbradio_pvt::txsettletime, chan_usbradio_pvt::txtoctype, chan_usbradio_pvt::ukey, usb_get_usbdev(), usb_list_check(), ast_variable::value, chan_usbradio_pvt::wanteeprom, and xpmr_config().

Referenced by load_module().

03406 {
03407    struct ast_variable *v;
03408    struct chan_usbradio_pvt *o;
03409    struct ast_config *cfg1;
03410    int i;
03411    char fname[200];
03412 #ifdef   NEW_ASTERISK
03413    struct ast_flags zeroflag = {0};
03414 #endif
03415    if (ctg == NULL) {
03416       traceusb1((" store_config() ctg == NULL\n"));
03417       o = &usbradio_default;
03418       ctg = "general";
03419    } else {
03420       /* "general" is also the default thing */
03421       if (strcmp(ctg, "general") == 0) {
03422          o = &usbradio_default;
03423       } else {
03424           // ast_log(LOG_NOTICE,"ast_calloc for chan_usbradio_pvt of %s\n",ctg);
03425          if (!(o = ast_calloc(1, sizeof(*o))))
03426             return NULL;
03427          *o = usbradio_default;
03428          o->name = ast_strdup(ctg);
03429          if (!usbradio_active) 
03430             usbradio_active = o->name;
03431       }
03432    }
03433    ast_mutex_init(&o->eepromlock);
03434    strcpy(o->mohinterpret, "default");
03435    /* fill other fields from configuration */
03436    for (v = ast_variable_browse(cfg, ctg); v; v = v->next) {
03437       M_START((char *)v->name, (char *)v->value);
03438 
03439       /* handle jb conf */
03440       if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
03441          continue;
03442 
03443 #if   0
03444          M_BOOL("autoanswer", o->autoanswer)
03445          M_BOOL("autohangup", o->autohangup)
03446          M_BOOL("overridecontext", o->overridecontext)
03447          M_STR("context", o->ctx)
03448          M_STR("language", o->language)
03449          M_STR("mohinterpret", o->mohinterpret)
03450          M_STR("extension", o->ext)
03451          M_F("callerid", store_callerid(o, v->value))
03452 #endif
03453          M_UINT("frags", o->frags)
03454          M_UINT("queuesize",o->queuesize)
03455 #if 0
03456          M_UINT("devicenum",o->devicenum)
03457 #endif
03458          M_UINT("debug", usbradio_debug)
03459          M_BOOL("rxcpusaver",o->rxcpusaver)
03460          M_BOOL("txcpusaver",o->txcpusaver)
03461          M_BOOL("invertptt",o->invertptt)
03462          M_F("rxdemod",store_rxdemod(o,(char *)v->value))
03463          M_BOOL("txprelim",o->txprelim);
03464          M_F("txmixa",store_txmixa(o,(char *)v->value))
03465          M_F("txmixb",store_txmixb(o,(char *)v->value))
03466          M_F("carrierfrom",store_rxcdtype(o,(char *)v->value))
03467          M_F("rxsdtype",store_rxsdtype(o,(char *)v->value))
03468           M_UINT("rxsqvox",o->rxsqvoxadj)
03469          M_STR("txctcssdefault",o->txctcssdefault)
03470          M_STR("rxctcssfreqs",o->rxctcssfreqs)
03471          M_STR("txctcssfreqs",o->txctcssfreqs)
03472          M_UINT("rxfreq",o->rxfreq)
03473          M_UINT("txfreq",o->txfreq)
03474          M_F("rxgain",store_rxgain(o,(char *)v->value))
03475          M_BOOL("rxboost",o->rxboostset)
03476          M_UINT("rxctcssrelax",o->rxctcssrelax)
03477          M_F("txtoctype",store_txtoctype(o,(char *)v->value))
03478          M_UINT("hdwtype",o->hdwtype)
03479          M_UINT("eeprom",o->wanteeprom)
03480          M_UINT("duplex",o->radioduplex)
03481          M_UINT("txsettletime",o->txsettletime)
03482          M_BOOL("rxpolarity",o->b.rxpolarity)
03483          M_BOOL("txpolarity",o->b.txpolarity)
03484          M_BOOL("dcsrxpolarity",o->b.dcsrxpolarity)
03485          M_BOOL("dcstxpolarity",o->b.dcstxpolarity)
03486          M_BOOL("lsdrxpolarity",o->b.lsdrxpolarity)
03487          M_BOOL("lsdtxpolarity",o->b.lsdtxpolarity)
03488          M_BOOL("loopback",o->b.loopback)
03489          M_BOOL("radioactive",o->b.radioactive)
03490          M_UINT("rptnum",o->rptnum)
03491          M_UINT("idleinterval",o->idleinterval)
03492          M_UINT("turnoffs",o->turnoffs)
03493          M_UINT("tracetype",o->tracetype)
03494          M_UINT("tracelevel",o->tracelevel)
03495          M_UINT("area",o->area)
03496          M_STR("ukey",o->ukey)
03497          M_END(;
03498          );
03499    }
03500 
03501    o->debuglevel=0;
03502 
03503    if (o == &usbradio_default)      /* we are done with the default */
03504       return NULL;
03505 
03506    snprintf(fname,sizeof(fname) - 1,config1,o->name);
03507 #ifdef   NEW_ASTERISK
03508    cfg1 = ast_config_load(fname,zeroflag);
03509 #else
03510    cfg1 = ast_config_load(fname);
03511 #endif
03512    o->rxmixerset = 500;
03513    o->txmixaset = 500;
03514    o->txmixbset = 500;
03515    o->rxvoiceadj = 0.5;
03516    o->rxctcssadj = 0.5;
03517    o->txctcssadj = 200;
03518    o->rxsquelchadj = 500;
03519    o->devstr[0] = 0;
03520    if (cfg1) {
03521       for (v = ast_variable_browse(cfg1, o->name); v; v = v->next) {
03522    
03523          M_START((char *)v->name, (char *)v->value);
03524          M_UINT("rxmixerset", o->rxmixerset)
03525          M_UINT("txmixaset", o->txmixaset)
03526          M_UINT("txmixbset", o->txmixbset)
03527          M_F("rxvoiceadj",store_rxvoiceadj(o,(char *)v->value))
03528          M_F("rxctcssadj",store_rxctcssadj(o,(char *)v->value))
03529          M_UINT("txctcssadj",o->txctcssadj);
03530          M_UINT("rxsquelchadj", o->rxsquelchadj)
03531          M_STR("devstr", o->devstr)
03532          M_END(;
03533          );
03534       }
03535       ast_config_destroy(cfg1);
03536    } else ast_log(LOG_WARNING,"File %s not found, using default parameters.\n",fname);
03537 
03538    if(o->wanteeprom)
03539    {
03540       ast_mutex_lock(&o->eepromlock);
03541       while(o->eepromctl)
03542       {
03543          ast_mutex_unlock(&o->eepromlock);
03544          usleep(10000);
03545          ast_mutex_lock(&o->eepromlock);
03546       }
03547       o->eepromctl = 1;  /* request a load */
03548       ast_mutex_unlock(&o->eepromlock);
03549    }
03550    /* if our specified one exists in the list */
03551    if ((!usb_list_check(o->devstr)) || find_desc_usb(o->devstr))
03552    {
03553       char *s;
03554 
03555       for(s = usb_device_list; *s; s += strlen(s) + 1)
03556       {
03557          if (!find_desc_usb(s)) break;
03558       }
03559       if (!*s)
03560       {
03561          ast_log(LOG_WARNING,"Unable to assign USB device for channel %s\n",o->name);
03562          goto error;
03563       }
03564       ast_log(LOG_NOTICE,"Assigned USB device %s to usbradio channel %s\n",s,o->name);
03565       strcpy(o->devstr,s);
03566    }
03567 
03568    i = usb_get_usbdev(o->devstr);
03569    if (i < 0)
03570    {
03571            ast_log(LOG_ERROR,"Not able to find alsa USB device\n");
03572       goto error;
03573    }
03574    o->devicenum = i;
03575 
03576    o->micmax = amixer_max(o->devicenum,MIXER_PARAM_MIC_CAPTURE_VOL);
03577    o->spkrmax = amixer_max(o->devicenum,MIXER_PARAM_SPKR_PLAYBACK_VOL);
03578    o->lastopen = ast_tvnow(); /* don't leave it 0 or tvdiff may wrap */
03579    o->dsp = ast_dsp_new();
03580    if (o->dsp)
03581    {
03582 #ifdef   NEW_ASTERISK
03583      ast_dsp_set_features(o->dsp,DSP_FEATURE_DIGIT_DETECT);
03584      ast_dsp_set_digitmode(o->dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
03585 #else
03586      ast_dsp_set_features(o->dsp,DSP_FEATURE_DTMF_DETECT);
03587      ast_dsp_digitmode(o->dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
03588 #endif
03589    }
03590 
03591    if(o->pmrChan==NULL)
03592    {
03593       t_pmr_chan tChan;
03594 
03595       // ast_log(LOG_NOTICE,"createPmrChannel() %s\n",o->name);
03596       memset(&tChan,0,sizeof(t_pmr_chan));
03597 
03598       tChan.pTxCodeDefault = o->txctcssdefault;
03599       tChan.pRxCodeSrc     = o->rxctcssfreqs;
03600       tChan.pTxCodeSrc     = o->txctcssfreqs;
03601 
03602       tChan.rxDemod=o->rxdemod;
03603       tChan.rxCdType=o->rxcdtype;
03604       tChan.rxSqVoxAdj=o->rxsqvoxadj;
03605 
03606       if (o->txprelim) 
03607          tChan.txMod = 2;
03608 
03609       tChan.txMixA = o->txmixa;
03610       tChan.txMixB = o->txmixb;
03611 
03612       tChan.rxCpuSaver=o->rxcpusaver;
03613       tChan.txCpuSaver=o->txcpusaver;
03614 
03615       tChan.b.rxpolarity=o->b.rxpolarity;
03616       tChan.b.txpolarity=o->b.txpolarity;
03617 
03618       tChan.b.dcsrxpolarity=o->b.dcsrxpolarity;
03619       tChan.b.dcstxpolarity=o->b.dcstxpolarity;
03620 
03621       tChan.b.lsdrxpolarity=o->b.lsdrxpolarity;
03622       tChan.b.lsdtxpolarity=o->b.lsdtxpolarity;
03623 
03624       tChan.tracetype=o->tracetype;
03625       tChan.tracelevel=o->tracelevel;
03626       tChan.rptnum=o->rptnum;
03627       tChan.idleinterval=o->idleinterval;
03628       tChan.turnoffs=o->turnoffs;
03629       tChan.area=o->area;
03630       tChan.ukey=o->ukey;
03631       tChan.name=o->name;
03632 
03633       o->pmrChan=createPmrChannel(&tChan,FRAME_SIZE);
03634                             
03635       o->pmrChan->radioDuplex=o->radioduplex;
03636       o->pmrChan->b.loopback=0; 
03637       o->pmrChan->txsettletime=o->txsettletime;
03638       o->pmrChan->rxCpuSaver=o->rxcpusaver;
03639       o->pmrChan->txCpuSaver=o->txcpusaver;
03640 
03641       *(o->pmrChan->prxSquelchAdjust) = 
03642          ((999 - o->rxsquelchadj) * 32767) / 1000;
03643 
03644       *(o->pmrChan->prxVoiceAdjust)=o->rxvoiceadj*M_Q8;
03645       *(o->pmrChan->prxCtcssAdjust)=o->rxctcssadj*M_Q8;
03646       o->pmrChan->rxCtcss->relax=o->rxctcssrelax;
03647       o->pmrChan->txTocType = o->txtoctype;
03648 
03649         if (    (o->txmixa == TX_OUT_LSD) ||
03650                 (o->txmixa == TX_OUT_COMPOSITE) ||
03651                 (o->txmixb == TX_OUT_LSD) ||
03652                 (o->txmixb == TX_OUT_COMPOSITE))
03653         {
03654                 set_txctcss_level(o);
03655         }
03656 
03657       if( (o->txmixa!=TX_OUT_VOICE) && (o->txmixb!=TX_OUT_VOICE) &&
03658          (o->txmixa!=TX_OUT_COMPOSITE) && (o->txmixb!=TX_OUT_COMPOSITE)
03659         )
03660       {
03661          ast_log(LOG_ERROR,"No txvoice output configured.\n");
03662       }
03663    
03664       if( o->txctcssfreq[0] && 
03665           o->txmixa!=TX_OUT_LSD && o->txmixa!=TX_OUT_COMPOSITE  &&
03666          o->txmixb!=TX_OUT_LSD && o->txmixb!=TX_OUT_COMPOSITE
03667         )
03668       {
03669          ast_log(LOG_ERROR,"No txtone output configured.\n");
03670       }
03671       
03672       if(o->b.radioactive)
03673       {
03674           // 20080328 sphenke asdf maw !!!
03675           // this diagnostic option was working but now appears broken
03676          // it's not required for operation so I'll fix it later.
03677          //struct chan_usbradio_pvt *ao;
03678          //for (ao = usbradio_default.next; ao && ao->name ; ao = ao->next)ao->pmrChan->b.radioactive=0;
03679          usbradio_active = o->name;
03680          // o->pmrChan->b.radioactive=1;
03681          //o->b.radioactive=0;
03682          //o->pmrChan->b.radioactive=0;
03683          ast_log(LOG_NOTICE,"radio active set to [%s]\n",o->name);
03684       }
03685    }
03686 
03687    xpmr_config(o);
03688 
03689    TRACEO(1,("store_config() 120\n"));
03690    mixer_write(o);
03691    TRACEO(1,("store_config() 130\n"));
03692    mult_set(o);    
03693    TRACEO(1,("store_config() 140\n"));
03694    hidhdwconfig(o);
03695 
03696    TRACEO(1,("store_config() 200\n"));
03697 
03698 #ifndef  NEW_ASTERISK
03699    if (pipe(o->sndcmd) != 0) {
03700       ast_log(LOG_ERROR, "Unable to create pipe\n");
03701       goto error;
03702    }
03703 
03704    ast_pthread_create_background(&o->sthread, NULL, sound_thread, o);
03705 #endif
03706 
03707    /* link into list of devices */
03708    if (o != &usbradio_default) {
03709       o->next = usbradio_default.next;
03710       usbradio_default.next = o;
03711    }
03712    TRACEO(1,("store_config() complete\n"));
03713    return o;
03714   
03715   error:
03716    if (o != &usbradio_default)
03717       free(o);
03718    return NULL;
03719 }

static void store_rxcdtype ( struct chan_usbradio_pvt o,
char *  s 
) [static]

Definition at line 2764 of file chan_usbradio.c.

References ast_log(), CD_HID, CD_HID_INVERT, CD_IGNORE, CD_XPMR_NOISE, CD_XPMR_VOX, LOG_WARNING, and chan_usbradio_pvt::rxcdtype.

Referenced by store_config().

02765 {
02766    if (!strcasecmp(s,"no")){
02767       o->rxcdtype = CD_IGNORE;
02768    }
02769    else if (!strcasecmp(s,"usb")){
02770       o->rxcdtype = CD_HID;
02771    }
02772    else if (!strcasecmp(s,"dsp")){
02773       o->rxcdtype = CD_XPMR_NOISE;
02774    }  
02775    else if (!strcasecmp(s,"vox")){
02776       o->rxcdtype = CD_XPMR_VOX;
02777    }  
02778    else if (!strcasecmp(s,"usbinvert")){
02779       o->rxcdtype = CD_HID_INVERT;
02780    }  
02781    else {
02782       ast_log(LOG_WARNING,"Unrecognized rxcdtype parameter: %s\n",s);
02783    }
02784 
02785    //ast_log(LOG_WARNING, "set rxcdtype = %s\n", s);
02786 }

static void store_rxctcssadj ( struct chan_usbradio_pvt o,
char *  s 
) [static]

Definition at line 2829 of file chan_usbradio.c.

References ast_debug, f, and chan_usbradio_pvt::rxctcssadj.

Referenced by store_config().

02830 {
02831    float f;
02832    if (sscanf(s, "%30f", &f) == 1)
02833       o->rxctcssadj = f;
02834    ast_debug(4, "set rxctcssadj = %f\n", f);
02835 }

static void store_rxdemod ( struct chan_usbradio_pvt o,
char *  s 
) [static]

Definition at line 2696 of file chan_usbradio.c.

References ast_log(), LOG_WARNING, RX_AUDIO_FLAT, RX_AUDIO_NONE, RX_AUDIO_SPEAKER, and chan_usbradio_pvt::rxdemod.

Referenced by store_config().

02697 {
02698    if (!strcasecmp(s,"no")){
02699       o->rxdemod = RX_AUDIO_NONE;
02700    }
02701    else if (!strcasecmp(s,"speaker")){
02702       o->rxdemod = RX_AUDIO_SPEAKER;
02703    }
02704    else if (!strcasecmp(s,"flat")){
02705          o->rxdemod = RX_AUDIO_FLAT;
02706    }  
02707    else {
02708       ast_log(LOG_WARNING,"Unrecognized rxdemod parameter: %s\n",s);
02709    }
02710 
02711    //ast_log(LOG_WARNING, "set rxdemod = %s\n", s);
02712 }

static void store_rxgain ( struct chan_usbradio_pvt o,
char *  s 
) [static]

Definition at line 2811 of file chan_usbradio.c.

References ast_debug, f, and chan_usbradio_pvt::rxgain.

Referenced by store_config().

02812 {
02813    float f;
02814    if (sscanf(s, "%30f", &f) == 1)
02815       o->rxgain = f;
02816    ast_debug(4, "set rxgain = %f\n", f);
02817 }

static void store_rxsdtype ( struct chan_usbradio_pvt o,
char *  s 
) [static]

Definition at line 2789 of file chan_usbradio.c.

References ast_log(), LOG_WARNING, chan_usbradio_pvt::rxsdtype, SD_HID, SD_HID_INVERT, SD_IGNORE, and SD_XPMR.

Referenced by store_config().

02790 {
02791    if (!strcasecmp(s,"no") || !strcasecmp(s,"SD_IGNORE")){
02792       o->rxsdtype = SD_IGNORE;
02793    }
02794    else if (!strcasecmp(s,"usb") || !strcasecmp(s,"SD_HID")){
02795       o->rxsdtype = SD_HID;
02796    }
02797    else if (!strcasecmp(s,"usbinvert") || !strcasecmp(s,"SD_HID_INVERT")){
02798       o->rxsdtype = SD_HID_INVERT;
02799    }  
02800    else if (!strcasecmp(s,"software") || !strcasecmp(s,"SD_XPMR")){
02801       o->rxsdtype = SD_XPMR;
02802    }  
02803    else {
02804       ast_log(LOG_WARNING,"Unrecognized rxsdtype parameter: %s\n",s);
02805    }
02806 
02807    //ast_log(LOG_WARNING, "set rxsdtype = %s\n", s);
02808 }

static void store_rxvoiceadj ( struct chan_usbradio_pvt o,
char *  s 
) [static]

Definition at line 2820 of file chan_usbradio.c.

References ast_debug, f, and chan_usbradio_pvt::rxvoiceadj.

Referenced by store_config().

02821 {
02822    float f;
02823    if (sscanf(s, "%30f", &f) == 1)
02824       o->rxvoiceadj = f;
02825    ast_debug(4, "set rxvoiceadj = %f\n", f);
02826 }

static void store_txmixa ( struct chan_usbradio_pvt o,
char *  s 
) [static]

Definition at line 2715 of file chan_usbradio.c.

References ast_log(), LOG_WARNING, TX_OUT_AUX, TX_OUT_COMPOSITE, TX_OUT_LSD, TX_OUT_OFF, TX_OUT_VOICE, and chan_usbradio_pvt::txmixa.

Referenced by store_config().

02716 {
02717    if (!strcasecmp(s,"no")){
02718       o->txmixa = TX_OUT_OFF;
02719    }
02720    else if (!strcasecmp(s,"voice")){
02721       o->txmixa = TX_OUT_VOICE;
02722    }
02723    else if (!strcasecmp(s,"tone")){
02724          o->txmixa = TX_OUT_LSD;
02725    }  
02726    else if (!strcasecmp(s,"composite")){
02727       o->txmixa = TX_OUT_COMPOSITE;
02728    }  
02729    else if (!strcasecmp(s,"auxvoice")){
02730       o->txmixa = TX_OUT_AUX;
02731    }  
02732    else {
02733       ast_log(LOG_WARNING,"Unrecognized txmixa parameter: %s\n",s);
02734    }
02735 
02736    //ast_log(LOG_WARNING, "set txmixa = %s\n", s);
02737 }

static void store_txmixb ( struct chan_usbradio_pvt o,
char *  s 
) [static]

Definition at line 2739 of file chan_usbradio.c.

References ast_log(), LOG_WARNING, TX_OUT_AUX, TX_OUT_COMPOSITE, TX_OUT_LSD, TX_OUT_OFF, TX_OUT_VOICE, and chan_usbradio_pvt::txmixb.

Referenced by store_config().

02740 {
02741    if (!strcasecmp(s,"no")){
02742       o->txmixb = TX_OUT_OFF;
02743    }
02744    else if (!strcasecmp(s,"voice")){
02745       o->txmixb = TX_OUT_VOICE;
02746    }
02747    else if (!strcasecmp(s,"tone")){
02748          o->txmixb = TX_OUT_LSD;
02749    }  
02750    else if (!strcasecmp(s,"composite")){
02751       o->txmixb = TX_OUT_COMPOSITE;
02752    }  
02753    else if (!strcasecmp(s,"auxvoice")){
02754       o->txmixb = TX_OUT_AUX;
02755    }  
02756    else {
02757       ast_log(LOG_WARNING,"Unrecognized txmixb parameter: %s\n",s);
02758    }
02759 
02760    //ast_log(LOG_WARNING, "set txmixb = %s\n", s);
02761 }

static void store_txtoctype ( struct chan_usbradio_pvt o,
char *  s 
) [static]

Definition at line 2838 of file chan_usbradio.c.

References ast_log(), LOG_WARNING, TOC_NONE, TOC_NOTONE, TOC_PHASE, and chan_usbradio_pvt::txtoctype.

Referenced by store_config().

02839 {
02840    if (!strcasecmp(s,"no") || !strcasecmp(s,"TOC_NONE")){
02841       o->txtoctype = TOC_NONE;
02842    }
02843    else if (!strcasecmp(s,"phase") || !strcasecmp(s,"TOC_PHASE")){
02844       o->txtoctype = TOC_PHASE;
02845    }
02846    else if (!strcasecmp(s,"notone") || !strcasecmp(s,"TOC_NOTONE")){
02847       o->txtoctype = TOC_NOTONE;
02848    }  
02849    else {
02850       ast_log(LOG_WARNING,"Unrecognized txtoctype parameter: %s\n",s);
02851    }
02852 }

static void tune_rxctcss ( int  fd,
struct chan_usbradio_pvt o 
) [static]

Definition at line 3015 of file chan_usbradio.c.

References ast_cli(), chan_usbradio_pvt::pmrChan, and chan_usbradio_pvt::rxctcssadj.

Referenced by radio_tune().

03016 {
03017    const int target=2400;      // was 4096 pre 20080205
03018    const int tolerance=100;
03019    const float settingmin=0.1;
03020    const float settingmax=8;
03021    const float settingstart=1;
03022    const int maxtries=12;
03023 
03024    float setting;
03025    int tries=0, meas;
03026 
03027    ast_cli(fd,"INFO: RX CTCSS ADJUST START.\n");   
03028    ast_cli(fd,"target=%i tolerance=%i \n",target,tolerance);
03029 
03030    o->pmrChan->b.tuning=1;
03031    o->pmrChan->spsMeasure->source=o->pmrChan->prxCtcssMeasure;
03032    o->pmrChan->spsMeasure->discfactor=400;
03033    o->pmrChan->spsMeasure->enabled=1;
03034 
03035    setting=settingstart;
03036 
03037    while(tries<maxtries)
03038    {
03039       *(o->pmrChan->prxCtcssAdjust)=setting*M_Q8;
03040       usleep(10000);
03041       o->pmrChan->spsMeasure->amax = o->pmrChan->spsMeasure->amin = 0;
03042       usleep(500000);
03043       meas = o->pmrChan->spsMeasure->apeak;
03044       ast_cli(fd,"tries=%i, setting=%f, meas=%i\n",tries,setting,meas);
03045 
03046       if( meas<(target-tolerance) || meas>(target+tolerance) || tries<3){
03047          setting=setting*target/meas;
03048       }
03049       else if(tries>4 && meas>(target-tolerance) && meas<(target+tolerance) )
03050       {
03051          break;
03052       }
03053       if(setting<settingmin)setting=settingmin;
03054       else if(setting>settingmax)setting=settingmax;
03055 
03056       tries++;
03057    }
03058    o->pmrChan->spsMeasure->enabled=0;
03059    ast_cli(fd,"DONE tries=%i, setting=%f, meas=%f\n",tries,setting,(float)meas);
03060    if( meas<(target-tolerance) || meas>(target+tolerance) ){
03061       ast_cli(fd,"ERROR: RX CTCSS GAIN ADJUST FAILED.\n");
03062    }else{
03063       ast_cli(fd,"INFO: RX CTCSS GAIN ADJUST SUCCESS.\n");
03064       o->rxctcssadj=setting;
03065    }
03066    o->pmrChan->b.tuning=0;
03067 }

static void tune_rxinput ( int  fd,
struct chan_usbradio_pvt o 
) [static]

Definition at line 2869 of file chan_usbradio.c.

References ast_cli(), CD_XPMR_NOISE, chan_usbradio_pvt::devicenum, chan_usbradio_pvt::micmax, MIXER_PARAM_MIC_BOOST, MIXER_PARAM_MIC_CAPTURE_VOL, chan_usbradio_pvt::pmrChan, RX_AUDIO_SPEAKER, chan_usbradio_pvt::rxboostset, chan_usbradio_pvt::rxcdtype, chan_usbradio_pvt::rxdemod, chan_usbradio_pvt::rxmixerset, and setamixer().

Referenced by radio_tune().

02870 {
02871    const int target=23000;
02872    const int tolerance=2000;
02873    const int settingmin=1;
02874    const int settingstart=2;
02875    const int maxtries=12;
02876 
02877    float settingmax;
02878    
02879    int setting=0, tries=0, tmpdiscfactor, meas;
02880    int tunetype=0;
02881 
02882    settingmax = o->micmax;
02883 
02884    if(o->pmrChan->rxDemod)tunetype=1;
02885    o->pmrChan->b.tuning=1;
02886 
02887    setting = settingstart;
02888 
02889     ast_cli(fd,"tune rxnoise maxtries=%i, target=%i, tolerance=%i\n",maxtries,target,tolerance);
02890 
02891    while(tries<maxtries)
02892    {
02893       setamixer(o->devicenum,MIXER_PARAM_MIC_CAPTURE_VOL,setting,0);
02894       setamixer(o->devicenum,MIXER_PARAM_MIC_BOOST,o->rxboostset,0);
02895        
02896       usleep(100000);
02897       if(o->rxcdtype!=CD_XPMR_NOISE || o->rxdemod==RX_AUDIO_SPEAKER) 
02898       {
02899          // printf("Measure Direct Input\n");
02900          o->pmrChan->spsMeasure->source = o->pmrChan->spsRx->source;
02901          o->pmrChan->spsMeasure->discfactor=2000;
02902          o->pmrChan->spsMeasure->enabled=1;
02903          o->pmrChan->spsMeasure->amax = o->pmrChan->spsMeasure->amin = 0;
02904          usleep(400000);   
02905          meas=o->pmrChan->spsMeasure->apeak;
02906          o->pmrChan->spsMeasure->enabled=0;  
02907       }
02908       else
02909       {
02910          // printf("Measure HF Noise\n");
02911          tmpdiscfactor=o->pmrChan->spsRx->discfactor;
02912          o->pmrChan->spsRx->discfactor=(i16)2000;
02913          o->pmrChan->spsRx->discounteru=o->pmrChan->spsRx->discounterl=0;
02914          o->pmrChan->spsRx->amax=o->pmrChan->spsRx->amin=0;
02915          usleep(200000);
02916          meas=o->pmrChan->rxRssi;
02917          o->pmrChan->spsRx->discfactor=tmpdiscfactor;
02918          o->pmrChan->spsRx->discounteru=o->pmrChan->spsRx->discounterl=0;
02919          o->pmrChan->spsRx->amax=o->pmrChan->spsRx->amin=0;
02920       }
02921         if(!meas)meas++;
02922       ast_cli(fd,"tries=%i, setting=%i, meas=%i\n",tries,setting,meas);
02923 
02924       if( meas<(target-tolerance) || meas>(target+tolerance) || tries<3){
02925          setting=setting*target/meas;
02926       }
02927       else if(tries>4 && meas>(target-tolerance) && meas<(target+tolerance) )
02928       {
02929          break;
02930       }
02931 
02932       if(setting<settingmin)setting=settingmin;
02933       else if(setting>settingmax)setting=settingmax;
02934 
02935       tries++;
02936    }
02937    ast_cli(fd,"DONE tries=%i, setting=%i, meas=%i\n",tries,
02938       (setting * 1000) / o->micmax,meas);
02939    if( meas<(target-tolerance) || meas>(target+tolerance) ){
02940       ast_cli(fd,"ERROR: RX INPUT ADJUST FAILED.\n");
02941    }else{
02942       ast_cli(fd,"INFO: RX INPUT ADJUST SUCCESS.\n"); 
02943       o->rxmixerset=(setting * 1000) / o->micmax;
02944    }
02945    o->pmrChan->b.tuning=0;
02946 }

static void tune_rxvoice ( int  fd,
struct chan_usbradio_pvt o 
) [static]

Definition at line 2949 of file chan_usbradio.c.

References ast_cli(), chan_usbradio_pvt::pmrChan, and chan_usbradio_pvt::rxvoiceadj.

Referenced by radio_tune().

02950 {
02951    const int target=7200;           // peak
02952    const int tolerance=360;            // peak to peak
02953    const float settingmin=0.1;
02954    const float settingmax=4;
02955    const float settingstart=1;
02956    const int maxtries=12;
02957 
02958    float setting;
02959 
02960    int tries=0, meas;
02961 
02962    ast_cli(fd,"INFO: RX VOICE ADJUST START.\n");   
02963    ast_cli(fd,"target=%i tolerance=%i \n",target,tolerance);
02964 
02965    o->pmrChan->b.tuning=1;
02966    if(!o->pmrChan->spsMeasure)
02967       ast_cli(fd,"ERROR: NO MEASURE BLOCK.\n");
02968 
02969    if(!o->pmrChan->spsMeasure->source || !o->pmrChan->prxVoiceAdjust )
02970       ast_cli(fd,"ERROR: NO SOURCE OR MEASURE SETTING.\n");
02971 
02972    o->pmrChan->spsMeasure->source=o->pmrChan->spsRxOut->sink;
02973    o->pmrChan->spsMeasure->enabled=1;
02974    o->pmrChan->spsMeasure->discfactor=1000;
02975    
02976    setting=settingstart;
02977 
02978    // ast_cli(fd,"ERROR: NO MEASURE BLOCK.\n");
02979 
02980    while(tries<maxtries)
02981    {
02982       *(o->pmrChan->prxVoiceAdjust)=setting*M_Q8;
02983       usleep(10000);
02984       o->pmrChan->spsMeasure->amax = o->pmrChan->spsMeasure->amin = 0;
02985       usleep(1000000);
02986       meas = o->pmrChan->spsMeasure->apeak;
02987       ast_cli(fd,"tries=%i, setting=%f, meas=%i\n",tries,setting,meas);
02988 
02989       if( meas<(target-tolerance) || meas>(target+tolerance) || tries<3){
02990          setting=setting*target/meas;
02991       }
02992       else if(tries>4 && meas>(target-tolerance) && meas<(target+tolerance) )
02993       {
02994          break;
02995       }
02996       if(setting<settingmin)setting=settingmin;
02997       else if(setting>settingmax)setting=settingmax;
02998 
02999       tries++;
03000    }
03001 
03002    o->pmrChan->spsMeasure->enabled=0;
03003 
03004    ast_cli(fd,"DONE tries=%i, setting=%f, meas=%f\n",tries,setting,(float)meas);
03005    if( meas<(target-tolerance) || meas>(target+tolerance) ){
03006       ast_cli(fd,"ERROR: RX VOICE GAIN ADJUST FAILED.\n");
03007    }else{
03008       ast_cli(fd,"INFO: RX VOICE GAIN ADJUST SUCCESS.\n");
03009       o->rxvoiceadj=setting;
03010    }
03011    o->pmrChan->b.tuning=0;
03012 }

static void tune_txoutput ( struct chan_usbradio_pvt o,
int  value,
int  fd 
) [static]

Definition at line 2855 of file chan_usbradio.c.

References ast_cli(), chan_usbradio_pvt::name, chan_usbradio_pvt::pmrChan, and chan_usbradio_pvt::txtestkey.

Referenced by radio_tune().

02856 {
02857    o->txtestkey=1;
02858    o->pmrChan->txPttIn=1;
02859    TxTestTone(o->pmrChan, 1);   // generate 1KHz tone at 7200 peak
02860    if (fd > 0) ast_cli(fd,"Tone output starting on channel %s...\n",o->name);
02861    usleep(5000000);
02862    TxTestTone(o->pmrChan, 0);
02863    if (fd > 0) ast_cli(fd,"Tone output ending on channel %s...\n",o->name);
02864    o->pmrChan->txPttIn=0;
02865    o->txtestkey=0;
02866 }

static void tune_write ( struct chan_usbradio_pvt o  )  [static]

Definition at line 3071 of file chan_usbradio.c.

References ast_mutex_lock(), ast_mutex_unlock(), chan_usbradio_pvt::devicenum, chan_usbradio_pvt::devstr, chan_usbradio_pvt::eeprom, EEPROM_RXCTCSSADJ, EEPROM_RXMIXERSET, EEPROM_RXSQUELCHADJ, EEPROM_RXVOICEADJ, EEPROM_TXCTCSSADJ, EEPROM_TXMIXASET, EEPROM_TXMIXBSET, chan_usbradio_pvt::eepromctl, chan_usbradio_pvt::eepromlock, chan_usbradio_pvt::name, chan_usbradio_pvt::rxctcssadj, chan_usbradio_pvt::rxmixerset, chan_usbradio_pvt::rxsquelchadj, chan_usbradio_pvt::rxvoiceadj, chan_usbradio_pvt::txctcssadj, chan_usbradio_pvt::txmixaset, chan_usbradio_pvt::txmixbset, and chan_usbradio_pvt::wanteeprom.

Referenced by radio_tune().

03072 {
03073    FILE *fp;
03074    char fname[200];
03075 
03076    snprintf(fname,sizeof(fname) - 1,"/etc/asterisk/usbradio_tune_%s.conf",o->name);
03077    fp = fopen(fname,"w");
03078 
03079    fprintf(fp,"[%s]\n",o->name);
03080 
03081    fprintf(fp,"; name=%s\n",o->name);
03082    fprintf(fp,"; devicenum=%i\n",o->devicenum);
03083    fprintf(fp,"devstr=%s\n",o->devstr);
03084    fprintf(fp,"rxmixerset=%i\n",o->rxmixerset);
03085    fprintf(fp,"txmixaset=%i\n",o->txmixaset);
03086    fprintf(fp,"txmixbset=%i\n",o->txmixbset);
03087    fprintf(fp,"rxvoiceadj=%f\n",o->rxvoiceadj);
03088    fprintf(fp,"rxctcssadj=%f\n",o->rxctcssadj);
03089    fprintf(fp,"txctcssadj=%i\n",o->txctcssadj);
03090    fprintf(fp,"rxsquelchadj=%i\n",o->rxsquelchadj);
03091    fclose(fp);
03092 
03093    if(o->wanteeprom)
03094    {
03095       ast_mutex_lock(&o->eepromlock);
03096       while(o->eepromctl)
03097       {
03098          ast_mutex_unlock(&o->eepromlock);
03099          usleep(10000);
03100          ast_mutex_lock(&o->eepromlock);
03101       }
03102       o->eeprom[EEPROM_RXMIXERSET] = o->rxmixerset;
03103       o->eeprom[EEPROM_TXMIXASET] = o->txmixaset;
03104       o->eeprom[EEPROM_TXMIXBSET] = o->txmixbset;
03105       memcpy(&o->eeprom[EEPROM_RXVOICEADJ],&o->rxvoiceadj,sizeof(float));
03106       memcpy(&o->eeprom[EEPROM_RXCTCSSADJ],&o->rxctcssadj,sizeof(float));
03107       o->eeprom[EEPROM_TXCTCSSADJ] = o->txctcssadj;
03108       o->eeprom[EEPROM_RXSQUELCHADJ] = o->rxsquelchadj;
03109       o->eepromctl = 2;  /* request a write */
03110       ast_mutex_unlock(&o->eepromlock);
03111    }
03112 }

static int unload_module ( void   )  [static]

Definition at line 3986 of file chan_usbradio.c.

References ast_channel_unregister(), ast_cli_unregister_multiple(), ast_dsp_free(), ast_log(), ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, chan_usbradio_pvt::dsp, LOG_WARNING, chan_usbradio_pvt::next, chan_usbradio_pvt::owner, chan_usbradio_pvt::pmrChan, and chan_usbradio_pvt::sounddev.

03987 {
03988    struct chan_usbradio_pvt *o;
03989 
03990    ast_log(LOG_WARNING, "unload_module() called\n");
03991 
03992    ast_channel_unregister(&usbradio_tech);
03993    ast_cli_unregister_multiple(cli_usbradio, sizeof(cli_usbradio) / sizeof(struct ast_cli_entry));
03994 
03995    for (o = usbradio_default.next; o; o = o->next) {
03996 
03997       ast_log(LOG_WARNING, "destroyPmrChannel() called\n");
03998       if(o->pmrChan)destroyPmrChannel(o->pmrChan);
03999       
04000       #if DEBUG_CAPTURES == 1
04001       if (frxcapraw) { fclose(frxcapraw); frxcapraw = NULL; }
04002       if (frxcaptrace) { fclose(frxcaptrace); frxcaptrace = NULL; }
04003       if (frxoutraw) { fclose(frxoutraw); frxoutraw = NULL; }
04004       if (ftxcapraw) { fclose(ftxcapraw); ftxcapraw = NULL; }
04005       if (ftxcaptrace) { fclose(ftxcaptrace); ftxcaptrace = NULL; }
04006       if (ftxoutraw) { fclose(ftxoutraw); ftxoutraw = NULL; }
04007       #endif
04008 
04009       close(o->sounddev);
04010 #ifndef  NEW_ASTERISK
04011       if (o->sndcmd[0] > 0) {
04012          close(o->sndcmd[0]);
04013          close(o->sndcmd[1]);
04014       }
04015 #endif
04016       if (o->dsp) ast_dsp_free(o->dsp);
04017       if (o->owner)
04018          ast_softhangup(o->owner, AST_SOFTHANGUP_APPUNLOAD);
04019       if (o->owner)        /* XXX how ??? */
04020          return -1;
04021       /* XXX what about the thread ? */
04022       /* XXX what about the memory allocated ? */
04023    }
04024    return 0;
04025 }

static int usb_get_usbdev ( char *  devstr  )  [static]

Definition at line 1016 of file chan_usbradio.c.

References str.

Referenced by store_config().

01017 {
01018 int   i;
01019 char  str[200],desdev[200],*cp;
01020 
01021    for(i = 0;i < 32; i++)
01022    {
01023       if (i) sprintf(str,"/sys/class/sound/dsp%d/device",i);
01024       else strcpy(str,"/sys/class/sound/dsp/device");
01025       memset(desdev,0,sizeof(desdev));
01026       if (readlink(str,desdev,sizeof(desdev) - 1) == -1)
01027       {
01028          sprintf(str,"/sys/class/sound/controlC%d/device",i);
01029          memset(desdev,0,sizeof(desdev));
01030          if (readlink(str,desdev,sizeof(desdev) - 1) == -1) continue;
01031       }
01032       cp = strrchr(desdev,'/');
01033       if (cp) *cp = 0; else continue;
01034       cp = strrchr(desdev,'/');
01035       if (!cp) continue;
01036       cp++;
01037       if (!strcasecmp(cp,devstr)) break;
01038    }
01039    if (i >= 32) return -1;
01040    return i;
01041 
01042 }

static int usb_list_check ( char *  devstr  )  [static]

Definition at line 1044 of file chan_usbradio.c.

References s.

Referenced by load_module(), and store_config().

01045 {
01046 
01047 char *s = usb_device_list;
01048 
01049    if (!s) return(0);
01050    while(*s)
01051    {
01052       if (!strcasecmp(s,devstr)) return(1);
01053       s += strlen(s) + 1;
01054    }
01055    return(0);
01056 }

static int usbradio_answer ( struct ast_channel c  )  [static]

Definition at line 1709 of file chan_usbradio.c.

References ast_setstate(), AST_STATE_UP, and ast_channel::tech_pvt.

01710 {
01711 #ifndef  NEW_ASTERISK
01712    struct chan_usbradio_pvt *o = c->tech_pvt;
01713 #endif
01714 
01715    ast_setstate(c, AST_STATE_UP);
01716 #ifndef  NEW_ASTERISK
01717    o->cursound = -1;
01718    o->nosound = 0;
01719 #endif
01720    return 0;
01721 }

static int usbradio_call ( struct ast_channel c,
char *  dest,
int  timeout 
) [static]
static int usbradio_digit_begin ( struct ast_channel c,
char  digit 
) [static]

Definition at line 1616 of file chan_usbradio.c.

01617 {
01618    return 0;
01619 }

static int usbradio_digit_end ( struct ast_channel c,
char  digit,
unsigned int  duration 
) [static]

Definition at line 1621 of file chan_usbradio.c.

References ast_verbose.

01622 {
01623    /* no better use for received digits than print them */
01624    ast_verbose(" << Console Received digit %c of duration %u ms >> \n", 
01625       digit, duration);
01626    return 0;
01627 }

static int usbradio_fixup ( struct ast_channel oldchan,
struct ast_channel newchan 
) [static]

Definition at line 2114 of file chan_usbradio.c.

References ast_log(), LOG_WARNING, chan_usbradio_pvt::owner, and ast_channel::tech_pvt.

02115 {
02116    struct chan_usbradio_pvt *o = newchan->tech_pvt;
02117    ast_log(LOG_WARNING,"usbradio_fixup()\n");
02118    o->owner = newchan;
02119    return 0;
02120 }

static int usbradio_hangup ( struct ast_channel c  )  [static]

Definition at line 1723 of file chan_usbradio.c.

References AST_CONTROL_CONGESTION, ast_module_unref(), chan_usbradio_pvt::autoanswer, chan_usbradio_pvt::autohangup, chan_usbradio_pvt::hidthread, chan_usbradio_pvt::hookstate, O_CLOSE, chan_usbradio_pvt::owner, ring(), setformat(), chan_usbradio_pvt::stophid, and ast_channel::tech_pvt.

01724 {
01725    struct chan_usbradio_pvt *o = c->tech_pvt;
01726 
01727    //ast_log(LOG_NOTICE, "usbradio_hangup()\n");
01728 #ifndef  NEW_ASTERISK
01729    o->cursound = -1;
01730    o->nosound = 0;
01731 #endif
01732    c->tech_pvt = NULL;
01733    o->owner = NULL;
01734    ast_module_unref(ast_module_info->self);
01735    if (o->hookstate) {
01736       if (o->autoanswer || o->autohangup) {
01737          /* Assume auto-hangup too */
01738          o->hookstate = 0;
01739          setformat(o, O_CLOSE);
01740       } else {
01741          /* Make congestion noise */
01742          ring(o, AST_CONTROL_CONGESTION);
01743       }
01744    }
01745    o->stophid = 1;
01746    pthread_join(o->hidthread,NULL);
01747    return 0;
01748 }

static int usbradio_indicate ( struct ast_channel chan,
int  cond,
const void *  data,
size_t  datalen 
) [static]

Definition at line 2122 of file chan_usbradio.c.

References AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_log(), ast_moh_start(), ast_moh_stop(), ast_verbose, chan_usbradio_pvt::debuglevel, LOG_WARNING, chan_usbradio_pvt::mohinterpret, ring(), ast_channel::tech_pvt, and chan_usbradio_pvt::txkeyed.

02123 {
02124    struct chan_usbradio_pvt *o = c->tech_pvt;
02125    int res = -1;
02126 
02127    switch (cond) {
02128       case AST_CONTROL_BUSY:
02129       case AST_CONTROL_CONGESTION:
02130       case AST_CONTROL_RINGING:
02131          res = cond;
02132          break;
02133 
02134       case -1:
02135 #ifndef  NEW_ASTERISK
02136          o->cursound = -1;
02137          o->nosound = 0;      /* when cursound is -1 nosound must be 0 */
02138 #endif
02139          return 0;
02140 
02141       case AST_CONTROL_VIDUPDATE:
02142          res = -1;
02143          break;
02144       case AST_CONTROL_HOLD:
02145          ast_verbose(" << Console Has Been Placed on Hold >> \n");
02146          ast_moh_start(c, data, o->mohinterpret);
02147          break;
02148       case AST_CONTROL_UNHOLD:
02149          ast_verbose(" << Console Has Been Retrieved from Hold >> \n");
02150          ast_moh_stop(c);
02151          break;
02152       case AST_CONTROL_PROCEEDING:
02153          ast_verbose(" << Call Proceeding... >> \n");
02154          ast_moh_stop(c);
02155          break;
02156       case AST_CONTROL_PROGRESS:
02157          ast_verbose(" << Call Progress... >> \n");
02158          ast_moh_stop(c);
02159          break;
02160       case AST_CONTROL_RADIO_KEY:
02161          o->txkeyed = 1;
02162          if(o->debuglevel)ast_verbose(" << AST_CONTROL_RADIO_KEY Radio Transmit On. >> \n");
02163          break;
02164       case AST_CONTROL_RADIO_UNKEY:
02165          o->txkeyed = 0;
02166          if(o->debuglevel)ast_verbose(" << AST_CONTROL_RADIO_UNKEY Radio Transmit Off. >> \n");
02167          break;
02168       default:
02169          ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n", cond, c->name);
02170          return -1;
02171    }
02172 
02173    if (res > -1)
02174       ring(o, res);
02175 
02176    return 0;
02177 }

static struct ast_channel* usbradio_new ( struct chan_usbradio_pvt o,
char *  ext,
char *  ctx,
int  state 
) [static, read]

Definition at line 2182 of file chan_usbradio.c.

References ast_channel_alloc, AST_FORMAT_SLINEAR, ast_hangup(), ast_jb_configure(), ast_log(), ast_module_ref(), ast_pbx_start(), AST_STATE_DOWN, ast_strdup, ast_string_field_set, ast_strlen_zero(), ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_dnid, ast_callerid::cid_name, chan_usbradio_pvt::cid_name, ast_callerid::cid_num, chan_usbradio_pvt::cid_num, ast_channel::fds, global_jbconf, language, chan_usbradio_pvt::language, LOG_WARNING, chan_usbradio_pvt::name, ast_channel::nativeformats, chan_usbradio_pvt::owner, ast_channel::readformat, setformat(), chan_usbradio_pvt::sounddev, ast_channel::tech, ast_channel::tech_pvt, and ast_channel::writeformat.

Referenced by usbradio_request().

02183 {
02184    struct ast_channel *c;
02185 
02186    c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "", ext, ctx, 0, "Radio/%s", o->name);
02187    if (c == NULL)
02188       return NULL;
02189    c->tech = &usbradio_tech;
02190    if (o->sounddev < 0)
02191       setformat(o, O_RDWR);
02192    c->fds[0] = o->sounddev;   /* -1 if device closed, override later */
02193    c->nativeformats = AST_FORMAT_SLINEAR;
02194    c->readformat = AST_FORMAT_SLINEAR;
02195    c->writeformat = AST_FORMAT_SLINEAR;
02196    c->tech_pvt = o;
02197 
02198    if (!ast_strlen_zero(o->language))
02199       ast_string_field_set(c, language, o->language);
02200    /* Don't use ast_set_callerid() here because it will
02201     * generate a needless NewCallerID event */
02202    c->cid.cid_num = ast_strdup(o->cid_num);
02203    c->cid.cid_ani = ast_strdup(o->cid_num);
02204    c->cid.cid_name = ast_strdup(o->cid_name);
02205    if (!ast_strlen_zero(ext))
02206       c->cid.cid_dnid = ast_strdup(ext);
02207 
02208    o->owner = c;
02209    ast_module_ref(ast_module_info->self);
02210    ast_jb_configure(c, &global_jbconf);
02211    if (state != AST_STATE_DOWN) {
02212       if (ast_pbx_start(c)) {
02213          ast_log(LOG_WARNING, "Unable to start PBX on %s\n", c->name);
02214          ast_hangup(c);
02215          o->owner = c = NULL;
02216          /* XXX what about the channel itself ? */
02217          /* XXX what about usecnt ? */
02218       }
02219    }
02220 
02221    return c;
02222 }

static struct ast_frame * usbradio_read ( struct ast_channel chan  )  [static, read]

Definition at line 1795 of file chan_usbradio.c.

References ast_channel::_state, AST_CONTROL_RADIO_KEY, AST_CONTROL_RADIO_UNKEY, ast_dsp_process(), AST_FORMAT_SLINEAR, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_NULL, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_queue_frame(), AST_STATE_UP, chan_usbradio_pvt::b, chan_usbradio_pvt::boost, BOOST_SCALE, CD_HID, CD_HID_INVERT, CD_XPMR_NOISE, CD_XPMR_VOX, ast_frame::data, ast_frame::datalen, chan_usbradio_pvt::debuglevel, chan_usbradio_pvt::dsp, errno, f, ast_frame::frametype, kickptt(), chan_usbradio_pvt::lasthidtime, chan_usbradio_pvt::lastrx, LOG_ERROR, LOG_NOTICE, LOG_WARNING, chan_usbradio_pvt::mute, chan_usbradio_pvt::name, ast_frame::offset, chan_usbradio_pvt::owner, chan_usbradio_pvt::pmrChan, ast_frame::ptr, chan_usbradio_pvt::radioduplex, chan_usbradio_pvt::read_f, READERR_THRESHOLD, chan_usbradio_pvt::readerrs, chan_usbradio_pvt::readpos, RX_CAP_OUT_FILE, chan_usbradio_pvt::rxcap2, chan_usbradio_pvt::rxcapraw, chan_usbradio_pvt::rxcarrierdetect, chan_usbradio_pvt::rxcdtype, chan_usbradio_pvt::rxctcssdecode, chan_usbradio_pvt::rxctcssfreq, chan_usbradio_pvt::rxdcsdecode, chan_usbradio_pvt::rxhidsq, chan_usbradio_pvt::rxkeyed, chan_usbradio_pvt::rxlsddecode, ast_frame::samples, soundcard_writeframe(), chan_usbradio_pvt::sounddev, ast_frame::src, ast_frame::subclass, ast_channel::tech_pvt, traceusb2, TX_CAP_OUT_FILE, chan_usbradio_pvt::txcap2, chan_usbradio_pvt::txkeyed, chan_usbradio_pvt::txtestkey, ast_channel_tech::type, chan_usbradio_pvt::usbradio_read_buf, chan_usbradio_pvt::usbradio_read_buf_8k, chan_usbradio_pvt::usbradio_write_buf, chan_usbradio_pvt::usbradio_write_buf_1, and chan_usbradio_pvt::usbradio_write_dst.

01796 {
01797    int res, src, datalen, oldpttout;
01798    int cd,sd;
01799    struct chan_usbradio_pvt *o = c->tech_pvt;
01800    struct ast_frame *f = &o->read_f,*f1;
01801    struct ast_frame wf = { AST_FRAME_CONTROL };
01802    time_t now;
01803 
01804    traceusb2(("usbradio_read()\n"));
01805 
01806    if (o->lasthidtime)
01807    {
01808       time(&now);
01809       if ((now - o->lasthidtime) > 3)
01810       {
01811          ast_log(LOG_ERROR,"HID process has died or something!!\n");
01812          return NULL;
01813       }
01814    }
01815    /* XXX can be simplified returning &ast_null_frame */
01816    /* prepare a NULL frame in case we don't have enough data to return */
01817    memset(f, '\0', sizeof(struct ast_frame));
01818    f->frametype = AST_FRAME_NULL;
01819    f->src = usbradio_tech.type;
01820 
01821    res = read(o->sounddev, o->usbradio_read_buf + o->readpos, 
01822       sizeof(o->usbradio_read_buf) - o->readpos);
01823    if (res < 0)            /* audio data not ready, return a NULL frame */
01824    {
01825       if (errno != EAGAIN) return NULL;
01826       if (o->readerrs++ > READERR_THRESHOLD)
01827       {
01828          ast_log(LOG_ERROR,"Stuck USB read channel [%s], un-sticking it!\n",o->name);
01829          o->readerrs = 0;
01830          return NULL;
01831       }
01832       if (o->readerrs == 1) 
01833          ast_log(LOG_WARNING,"Possibly stuck USB read channel. [%s]\n",o->name);
01834       return f;
01835    }
01836    if (o->readerrs) ast_log(LOG_WARNING,"Nope, USB read channel [%s] wasn't stuck after all.\n",o->name);
01837    o->readerrs = 0;
01838    o->readpos += res;
01839    if (o->readpos < sizeof(o->usbradio_read_buf))  /* not enough samples */
01840       return f;
01841 
01842    if (o->mute)
01843       return f;
01844 
01845    #if DEBUG_CAPTURES == 1
01846    if ((o->b.rxcapraw && frxcapraw) && (fwrite((o->usbradio_read_buf + AST_FRIENDLY_OFFSET),1,FRAME_SIZE * 2 * 2 * 6,frxcapraw) != FRAME_SIZE * 2 * 2 * 6)) {
01847       ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno));
01848    }
01849    #endif
01850 
01851    #if 1
01852    if(o->txkeyed||o->txtestkey)
01853    {
01854       if(!o->pmrChan->txPttIn)
01855       {
01856          o->pmrChan->txPttIn=1;
01857          if(o->debuglevel) ast_log(LOG_NOTICE,"txPttIn = %i, chan %s\n",o->pmrChan->txPttIn,o->owner->name);
01858       }
01859    }
01860    else if(o->pmrChan->txPttIn)
01861    {
01862       o->pmrChan->txPttIn=0;
01863       if(o->debuglevel) ast_log(LOG_NOTICE,"txPttIn = %i, chan %s\n",o->pmrChan->txPttIn,o->owner->name);
01864    }
01865    oldpttout = o->pmrChan->txPttOut;
01866 
01867    PmrRx(         o->pmrChan, 
01868          (i16 *)(o->usbradio_read_buf + AST_FRIENDLY_OFFSET),
01869          (i16 *)(o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET),
01870          (i16 *)(o->usbradio_write_buf_1));
01871 
01872    if (oldpttout != o->pmrChan->txPttOut)
01873    {
01874       if(o->debuglevel) ast_log(LOG_NOTICE,"txPttOut = %i, chan %s\n",o->pmrChan->txPttOut,o->owner->name);
01875       kickptt(o);
01876    }
01877 
01878    #if 0 // to write 48KS/s stereo tx data to a file
01879    if (!ftxoutraw) ftxoutraw = fopen(TX_CAP_OUT_FILE,"w");
01880    if (ftxoutraw) fwrite(o->usbradio_write_buf_1,1,FRAME_SIZE * 2 * 6,ftxoutraw);
01881    #endif
01882 
01883    #if DEBUG_CAPTURES == 1 && XPMR_DEBUG0 == 1
01884     if ((o->b.txcap2 && ftxcaptrace) && (fwrite((o->pmrChan->ptxDebug),1,FRAME_SIZE * 2 * 16,ftxcaptrace) != FRAME_SIZE * 2 * 16)) {
01885       ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno));
01886    }
01887    #endif
01888    
01889    // 160 samples * 2 bytes/sample * 2 chan * 6x oversampling to 48KS/s
01890    datalen = FRAME_SIZE * 24;  
01891    src = 0;             /* read position into f->data */
01892    while (src < datalen) 
01893    {
01894       /* Compute spare room in the buffer */
01895       int l = sizeof(o->usbradio_write_buf) - o->usbradio_write_dst;
01896 
01897       if (datalen - src >= l) 
01898       {  
01899          /* enough to fill a frame */
01900          memcpy(o->usbradio_write_buf + o->usbradio_write_dst, o->usbradio_write_buf_1 + src, l);
01901          soundcard_writeframe(o, (short *) o->usbradio_write_buf);
01902          src += l;
01903          o->usbradio_write_dst = 0;
01904       } 
01905       else 
01906       {           
01907          /* copy residue */
01908          l = datalen - src;
01909          memcpy(o->usbradio_write_buf + o->usbradio_write_dst, o->usbradio_write_buf_1 + src, l);
01910          src += l;         /* but really, we are done */
01911          o->usbradio_write_dst += l;
01912       }
01913    }
01914    #else
01915    static FILE *hInput;
01916    i16 iBuff[FRAME_SIZE*2*6];
01917 
01918    o->pmrChan->b.rxCapture=1;
01919 
01920    if(!hInput)
01921    {
01922       hInput  = fopen("/usr/src/xpmr/testdata/rx_in.pcm","r");
01923       if(!hInput)
01924       {
01925          printf(" Input Data File Not Found.\n");
01926          return 0;
01927       }
01928    }
01929 
01930    if(0==fread((void *)iBuff,2,FRAME_SIZE*2*6,hInput))exit;
01931 
01932    PmrRx(  o->pmrChan, 
01933          (i16 *)iBuff,
01934          (i16 *)(o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET));
01935 
01936    #endif
01937 
01938    #if 0
01939    if (!frxoutraw) frxoutraw = fopen(RX_CAP_OUT_FILE,"w");
01940     if (frxoutraw) fwrite((o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET),1,FRAME_SIZE * 2,frxoutraw);
01941    #endif
01942 
01943    #if DEBUG_CAPTURES == 1 && XPMR_DEBUG0 == 1
01944     if ((frxcaptrace && o->b.rxcap2 && o->pmrChan->b.radioactive) && (fwrite((o->pmrChan->prxDebug),1,FRAME_SIZE * 2 * 16,frxcaptrace) != FRAME_SIZE * 2 * 16 )) {
01945       ast_log(LOG_ERROR, "fwrite() failed: %s\n", strerror(errno));
01946    }
01947    #endif
01948 
01949    cd = 0;
01950    if(o->rxcdtype==CD_HID && (o->pmrChan->rxExtCarrierDetect!=o->rxhidsq))
01951       o->pmrChan->rxExtCarrierDetect=o->rxhidsq;
01952    
01953    if(o->rxcdtype==CD_HID_INVERT && (o->pmrChan->rxExtCarrierDetect==o->rxhidsq))
01954       o->pmrChan->rxExtCarrierDetect=!o->rxhidsq;
01955       
01956    if( (o->rxcdtype==CD_HID        && o->rxhidsq)                  ||
01957       (o->rxcdtype==CD_HID_INVERT && !o->rxhidsq)                 ||
01958       (o->rxcdtype==CD_XPMR_NOISE && o->pmrChan->rxCarrierDetect) ||
01959       (o->rxcdtype==CD_XPMR_VOX   && o->pmrChan->rxCarrierDetect)
01960      )
01961    {
01962       if (!o->pmrChan->txPttOut || o->radioduplex)cd=1;  
01963    }
01964    else
01965    {
01966       cd=0;
01967    }
01968 
01969    if(cd!=o->rxcarrierdetect)
01970    {
01971       o->rxcarrierdetect=cd;
01972       if(o->debuglevel) ast_log(LOG_NOTICE,"rxcarrierdetect = %i, chan %s\n",cd,o->owner->name);
01973       // printf("rxcarrierdetect = %i, chan %s\n",res,o->owner->name);
01974    }
01975 
01976    if(o->pmrChan->b.ctcssRxEnable && o->pmrChan->rxCtcss->decode!=o->rxctcssdecode)
01977    {
01978       if(o->debuglevel)ast_log(LOG_NOTICE,"rxctcssdecode = %i, chan %s\n",o->pmrChan->rxCtcss->decode,o->owner->name);
01979       // printf("rxctcssdecode = %i, chan %s\n",o->pmrChan->rxCtcss->decode,o->owner->name);
01980       o->rxctcssdecode=o->pmrChan->rxCtcss->decode;
01981       strcpy(o->rxctcssfreq, o->pmrChan->rxctcssfreq);
01982    }
01983 
01984    #ifndef HAVE_XPMRX
01985    if(  !o->pmrChan->b.ctcssRxEnable ||
01986       ( o->pmrChan->b.ctcssRxEnable && 
01987          o->pmrChan->rxCtcss->decode>CTCSS_NULL && 
01988          o->pmrChan->smode==SMODE_CTCSS )  
01989    )
01990    {
01991       sd=1; 
01992    }
01993    else
01994    {
01995       sd=0;
01996    }
01997    #else
01998    if( (!o->pmrChan->b.ctcssRxEnable && !o->pmrChan->b.dcsRxEnable && !o->pmrChan->b.lmrRxEnable) ||
01999       ( o->pmrChan->b.ctcssRxEnable && 
02000          o->pmrChan->rxCtcss->decode>CTCSS_NULL && 
02001          o->pmrChan->smode==SMODE_CTCSS ) ||
02002       ( o->pmrChan->b.dcsRxEnable && 
02003          o->pmrChan->decDcs->decode > 0 &&
02004          o->pmrChan->smode==SMODE_DCS )
02005    )
02006    {
02007       sd=1; 
02008    }
02009    else
02010    {
02011       sd=0;
02012    }
02013 
02014    if(o->pmrChan->decDcs->decode!=o->rxdcsdecode)
02015    {                                      
02016       if(o->debuglevel)ast_log(LOG_NOTICE,"rxdcsdecode = %s, chan %s\n",o->pmrChan->rxctcssfreq,o->owner->name);
02017       // printf("rxctcssdecode = %i, chan %s\n",o->pmrChan->rxCtcss->decode,o->owner->name);
02018       o->rxdcsdecode=o->pmrChan->decDcs->decode;
02019       strcpy(o->rxctcssfreq, o->pmrChan->rxctcssfreq);
02020    }                                                                      
02021 
02022    if(o->pmrChan->rptnum && (o->pmrChan->pLsdCtl->cs[o->pmrChan->rptnum].b.rxkeyed != o->rxlsddecode))
02023    {                       
02024       if(o->debuglevel)ast_log(LOG_NOTICE,"rxLSDecode = %s, chan %s\n",o->pmrChan->rxctcssfreq,o->owner->name);
02025       o->rxlsddecode=o->pmrChan->pLsdCtl->cs[o->pmrChan->rptnum].b.rxkeyed;
02026       strcpy(o->rxctcssfreq, o->pmrChan->rxctcssfreq);
02027    }
02028 
02029    if( (o->pmrChan->rptnum>0 && o->pmrChan->smode==SMODE_LSD && o->pmrChan->pLsdCtl->cs[o->pmrChan->rptnum].b.rxkeyed)||
02030        (o->pmrChan->smode==SMODE_DCS && o->pmrChan->decDcs->decode>0) )
02031    {
02032       sd=1;
02033    }
02034    #endif
02035 
02036    if ( cd && sd )
02037    {
02038       //if(!o->rxkeyed)o->pmrChan->dd.b.doitnow=1;
02039       if(!o->rxkeyed && o->debuglevel)ast_log(LOG_NOTICE,"o->rxkeyed = 1, chan %s\n", o->owner->name);
02040       o->rxkeyed = 1;
02041    }
02042    else 
02043    {
02044       //if(o->rxkeyed)o->pmrChan->dd.b.doitnow=1;
02045       if(o->rxkeyed && o->debuglevel)ast_log(LOG_NOTICE,"o->rxkeyed = 0, chan %s\n",o->owner->name);
02046       o->rxkeyed = 0;
02047    }
02048 
02049    // provide rx signal detect conditions
02050    if (o->lastrx && (!o->rxkeyed))
02051    {
02052       o->lastrx = 0;
02053       //printf("AST_CONTROL_RADIO_UNKEY\n");
02054       wf.subclass = AST_CONTROL_RADIO_UNKEY;
02055       ast_queue_frame(o->owner, &wf);
02056    }
02057    else if ((!o->lastrx) && (o->rxkeyed))
02058    {
02059       o->lastrx = 1;
02060       //printf("AST_CONTROL_RADIO_KEY\n");
02061       wf.subclass = AST_CONTROL_RADIO_KEY;
02062       if(o->rxctcssdecode)    
02063         {
02064            wf.data.ptr = o->rxctcssfreq;
02065            wf.datalen = strlen(o->rxctcssfreq) + 1;
02066          TRACEO(1,("AST_CONTROL_RADIO_KEY text=%s\n",o->rxctcssfreq));
02067         }
02068       ast_queue_frame(o->owner, &wf);
02069    }
02070 
02071    o->readpos = AST_FRIENDLY_OFFSET;   /* reset read pointer for next frame */
02072    if (c->_state != AST_STATE_UP)   /* drop data if frame is not up */
02073       return f;
02074    /* ok we can build and deliver the frame to the caller */
02075    f->frametype = AST_FRAME_VOICE;
02076    f->subclass = AST_FORMAT_SLINEAR;
02077    f->samples = FRAME_SIZE;
02078    f->datalen = FRAME_SIZE * 2;
02079    f->data.ptr = o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET;
02080    if (o->boost != BOOST_SCALE) {   /* scale and clip values */
02081       int i, x;
02082       int16_t *p = (int16_t *) f->data.ptr;
02083       for (i = 0; i < f->samples; i++) {
02084          x = (p[i] * o->boost) / BOOST_SCALE;
02085          if (x > 32767)
02086             x = 32767;
02087          else if (x < -32768)
02088             x = -32768;
02089          p[i] = x;
02090       }
02091    }
02092 
02093    f->offset = AST_FRIENDLY_OFFSET;
02094    if (o->dsp)
02095    {
02096        f1 = ast_dsp_process(c,o->dsp,f);
02097        if ((f1->frametype == AST_FRAME_DTMF_END) ||
02098          (f1->frametype == AST_FRAME_DTMF_BEGIN))
02099        {
02100       if ((f1->subclass == 'm') || (f1->subclass == 'u'))
02101       {
02102          f1->frametype = AST_FRAME_NULL;
02103          f1->subclass = 0;
02104          return(f1);
02105       }
02106       if (f1->frametype == AST_FRAME_DTMF_END)
02107          ast_log(LOG_NOTICE,"Got DTMF char %c\n",f1->subclass);
02108       return(f1);
02109        }
02110    }
02111    return f;
02112 }

static struct ast_channel * usbradio_request ( const char *  type,
int  format,
void *  data,
int *  cause 
) [static, read]

Definition at line 2225 of file chan_usbradio.c.

References AST_CAUSE_BUSY, AST_FORMAT_SLINEAR, ast_log(), AST_STATE_DOWN, chan_usbradio_pvt::b, find_desc(), LOG_NOTICE, LOG_WARNING, chan_usbradio_pvt::owner, chan_usbradio_pvt::remoted, usbradio_new(), and xpmr_config().

02226 {
02227    struct ast_channel *c;
02228    struct chan_usbradio_pvt *o = find_desc(data);
02229 
02230    TRACEO(1,("usbradio_request()\n"));
02231 
02232    if (0)
02233    {
02234       ast_log(LOG_WARNING, "usbradio_request type <%s> data 0x%p <%s>\n", type, data, (char *) data);
02235    }
02236    if (o == NULL) {
02237       ast_log(LOG_NOTICE, "Device %s not found\n", (char *) data);
02238       /* XXX we could default to 'dsp' perhaps ? */
02239       return NULL;
02240    }
02241    if ((format & AST_FORMAT_SLINEAR) == 0) {
02242       ast_log(LOG_NOTICE, "Format 0x%x unsupported\n", format);
02243       return NULL;
02244    }
02245    if (o->owner) {
02246       ast_log(LOG_NOTICE, "Already have a call (chan %p) on the usb channel\n", o->owner);
02247       *cause = AST_CAUSE_BUSY;
02248       return NULL;
02249    }
02250    c = usbradio_new(o, NULL, NULL, AST_STATE_DOWN);
02251    if (c == NULL) {
02252       ast_log(LOG_WARNING, "Unable to create new usb channel\n");
02253       return NULL;
02254    }
02255       
02256    o->b.remoted=0;
02257    xpmr_config(o);
02258 
02259    return c;
02260 }

static int usbradio_text ( struct ast_channel c,
const char *  text 
) [static]

Definition at line 1632 of file chan_usbradio.c.

References ast_log(), ast_verbose, chan_usbradio_pvt::b, chan, chan_usbradio_pvt::debuglevel, find_desc(), LOG_ERROR, LOG_NOTICE, chan_usbradio_pvt::pmrChan, chan_usbradio_pvt::remoted, round, chan_usbradio_pvt::set_rxctcssfreqs, chan_usbradio_pvt::set_rxfreq, chan_usbradio_pvt::set_txctcssfreqs, chan_usbradio_pvt::set_txfreq, and xpmr_config().

01633 {
01634    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
01635    double tx,rx;
01636    char cnt,rxs[16],txs[16],txpl[16],rxpl[16];
01637    char pwr,*cmd;
01638 
01639    cmd = alloca(strlen(text) + 10);
01640 
01641    /* print received messages */
01642    if(o->debuglevel)ast_verbose(" << Console Received usbradio text %s >> \n", text);
01643 
01644    cnt=sscanf(text,"%s %s %s %s %s %c",cmd,rxs,txs,rxpl,txpl,&pwr);
01645 
01646    if (strcmp(cmd,"SETCHAN")==0)
01647     { 
01648       u8 chan;
01649       chan=strtod(rxs,NULL);
01650       ppbinout(chan);
01651         if(o->debuglevel)ast_log(LOG_NOTICE,"parse usbradio SETCHAN cmd: %s chan: %i\n",text,chan);
01652         return 0;
01653     }
01654    
01655     if (cnt < 6)
01656     {
01657        ast_log(LOG_ERROR,"Cannot parse usbradio text: %s\n",text);
01658        return 0;
01659     }
01660    else
01661    {
01662       if(o->debuglevel)ast_verbose(" << %s %s %s %s %s %c >> \n", cmd,rxs,txs,rxpl,txpl,pwr);   
01663    }
01664     
01665     if (strcmp(cmd,"SETFREQ")==0)
01666     {
01667         if(o->debuglevel)ast_log(LOG_NOTICE,"parse usbradio SETFREQ cmd: %s\n",text);
01668       tx=strtod(txs,NULL);
01669       rx=strtod(rxs,NULL);
01670       o->set_txfreq = round(tx * (double)1000000);
01671       o->set_rxfreq = round(rx * (double)1000000);
01672       o->pmrChan->txpower = (pwr == 'H');
01673       strcpy(o->set_rxctcssfreqs,rxpl);
01674       strcpy(o->set_txctcssfreqs,txpl);
01675    
01676       o->b.remoted=1;
01677       xpmr_config(o);
01678         return 0;
01679     }
01680    ast_log(LOG_ERROR,"Cannot parse usbradio cmd: %s\n",text);
01681    return 0;
01682 }

static int usbradio_write ( struct ast_channel chan,
struct ast_frame f 
) [static]

Definition at line 1752 of file chan_usbradio.c.

References ast_log(), chan_usbradio_pvt::b, ast_frame::data, ast_frame::datalen, errno, LOG_ERROR, chan_usbradio_pvt::pmrChan, ast_frame::ptr, ast_channel::tech_pvt, traceusb2, chan_usbradio_pvt::txcapraw, and chan_usbradio_pvt::txkeyed.

01753 {
01754    struct chan_usbradio_pvt *o = c->tech_pvt;
01755 
01756    traceusb2(("usbradio_write() o->nosound= %i\n",o->nosound));
01757 
01758 #ifndef  NEW_ASTERISK
01759    /* Immediately return if no sound is enabled */
01760    if (o->nosound)
01761       return 0;
01762    /* Stop any currently playing sound */
01763    o->cursound = -1;
01764 #endif
01765    /*
01766     * we could receive a block which is not a multiple of our
01767     * FRAME_SIZE, so buffer it locally and write to the device
01768     * in FRAME_SIZE chunks.
01769     * Keep the residue stored for future use.
01770     */
01771 
01772    #if DEBUG_CAPTURES == 1 // to write input data to a file   datalen=320
01773    if (ftxcapraw && o->b.txcapraw)
01774    {
01775       i16 i, tbuff[f->datalen];
01776       for(i=0;i<f->datalen;i+=2)
01777       {
01778          tbuff[i]= ((i16*)(f->data.ptr))[i/2];
01779          tbuff[i+1]= o->txkeyed*M_Q13;
01780       }
01781       if (fwrite(tbuff,2,f->datalen,ftxcapraw) != f->datalen) {
01782          ast_log(LOG_ERROR, "write() failed: %s\n", strerror(errno));
01783       }
01784       //fwrite(f->data,1,f->datalen,ftxcapraw);
01785    }
01786    #endif
01787 
01788    // maw just take the data from the network and save it for PmrRx processing
01789 
01790    PmrTx(o->pmrChan,(i16*)f->data.ptr);
01791    
01792    return 0;
01793 }

static int used_blocks ( struct chan_usbradio_pvt o  )  [static]

Definition at line 1326 of file chan_usbradio.c.

References ast_log(), LOG_WARNING, chan_usbradio_pvt::sounddev, chan_usbradio_pvt::total_blocks, WARN_used_blocks, and chan_usbradio_pvt::warned.

Referenced by soundcard_writeframe().

01327 {
01328    struct audio_buf_info info;
01329 
01330    if (ioctl(o->sounddev, SNDCTL_DSP_GETOSPACE, &info)) {
01331       if (!(o->warned & WARN_used_blocks)) {
01332          ast_log(LOG_WARNING, "Error reading output space\n");
01333          o->warned |= WARN_used_blocks;
01334       }
01335       return 1;
01336    }
01337 
01338    if (o->total_blocks == 0) {
01339       if (0)               /* debugging */
01340          ast_log(LOG_WARNING, "fragtotal %d size %d avail %d\n", info.fragstotal, info.fragsize, info.fragments);
01341       o->total_blocks = info.fragments;
01342    }
01343 
01344    return o->total_blocks - info.fragments;
01345 }

static void write_eeprom ( struct usb_dev_handle *  handle,
int  addr,
unsigned short  data 
) [static]

Definition at line 833 of file chan_usbradio.c.

References buf, and hid_set_outputs().

Referenced by put_eeprom().

00835 {
00836 
00837    unsigned char buf[4];
00838 
00839    buf[0] = 0x80;
00840    buf[1] = data & 0xff;
00841    buf[2] = data >> 8;
00842    buf[3] = 0xc0 | (addr & 0x3f);
00843    hid_set_outputs(handle,buf);
00844 }

static int xpmr_config ( struct chan_usbradio_pvt o  )  [static]

Definition at line 3359 of file chan_usbradio.c.

References ast_log(), chan_usbradio_pvt::b, LOG_ERROR, chan_usbradio_pvt::pmrChan, chan_usbradio_pvt::remoted, chan_usbradio_pvt::rxctcssfreqs, chan_usbradio_pvt::rxctcssrelax, chan_usbradio_pvt::rxfreq, chan_usbradio_pvt::set_rxctcssfreqs, chan_usbradio_pvt::set_rxfreq, chan_usbradio_pvt::set_txctcssdefault, chan_usbradio_pvt::set_txctcssfreqs, chan_usbradio_pvt::set_txfreq, chan_usbradio_pvt::txctcssdefault, chan_usbradio_pvt::txctcssfreqs, and chan_usbradio_pvt::txfreq.

Referenced by store_config(), usbradio_request(), and usbradio_text().

03360 {
03361    //ast_log(LOG_NOTICE,"xpmr_config()\n");
03362 
03363    TRACEO(1,("xpmr_config()\n"));
03364 
03365    if(o->pmrChan==NULL)
03366    {
03367       ast_log(LOG_ERROR,"pmr channel structure NULL\n");
03368       return 1;
03369    }
03370 
03371    o->pmrChan->rxCtcss->relax = o->rxctcssrelax;
03372    o->pmrChan->txpower=0;
03373 
03374    if(o->b.remoted)
03375    {
03376       o->pmrChan->pTxCodeDefault = o->set_txctcssdefault;
03377       o->pmrChan->pRxCodeSrc=o->set_rxctcssfreqs;
03378       o->pmrChan->pTxCodeSrc=o->set_txctcssfreqs;
03379 
03380       o->pmrChan->rxfreq=o->set_rxfreq;
03381       o->pmrChan->txfreq=o->set_txfreq;
03382       /* printf(" remoted %s %s --> %s \n",o->pmrChan->txctcssdefault,
03383          o->pmrChan->txctcssfreq,o->pmrChan->rxctcssfreq); */
03384    }
03385    else
03386    {
03387       // set xpmr pointers to source strings
03388 
03389       o->pmrChan->pTxCodeDefault = o->txctcssdefault;
03390       o->pmrChan->pRxCodeSrc     = o->rxctcssfreqs;
03391       o->pmrChan->pTxCodeSrc     = o->txctcssfreqs;
03392    
03393       o->pmrChan->rxfreq = o->rxfreq;
03394       o->pmrChan->txfreq = o->txfreq;
03395    }
03396    
03397    code_string_parse(o->pmrChan);
03398    if(o->pmrChan->rxfreq) o->pmrChan->b.reprog=1;
03399 
03400    return 0;
03401 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "usb Console Channel Driver" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "a9c98e5d177805051735cb5b0b16b0a0" , .load = load_module, .unload = unload_module, } [static]

Definition at line 4027 of file chan_usbradio.c.

char active_usage[] [static]
Initial value:
        "Usage: radio active [device-name]\n"
        "       If used without a parameter, displays which device is the current\n"
        "one being commanded.  If a device is specified, the commanded radio device is changed\n"
        "to the device specified.\n"

Definition at line 2631 of file chan_usbradio.c.

Definition at line 4027 of file chan_usbradio.c.

struct ast_cli_entry cli_usbradio[] [static]

Definition at line 3913 of file chan_usbradio.c.

const char* config = "usbradio.conf" [static]

Definition at line 354 of file chan_usbradio.c.

struct ast_jb_conf default_jbconf [static]

Global jitterbuffer configuration - by default, jb is disabled

Definition at line 190 of file chan_usbradio.c.

FILE* frxcapraw = NULL [static]

Definition at line 357 of file chan_usbradio.c.

FILE * frxcaptrace = NULL [static]

Definition at line 357 of file chan_usbradio.c.

FILE * frxoutraw = NULL [static]

Definition at line 357 of file chan_usbradio.c.

FILE* ftxcapraw = NULL [static]

Definition at line 358 of file chan_usbradio.c.

FILE * ftxcaptrace = NULL [static]

Definition at line 358 of file chan_usbradio.c.

FILE * ftxoutraw = NULL [static]

Definition at line 358 of file chan_usbradio.c.

struct ast_jb_conf global_jbconf [static]

Definition at line 197 of file chan_usbradio.c.

Referenced by load_module(), store_config(), and usbradio_new().

char key_usage[] [static]
Initial value:
   "Usage: radio key\n"
   "       Simulates COR active.\n"

Definition at line 2623 of file chan_usbradio.c.

char radio_tune_usage[] [static]

Definition at line 2639 of file chan_usbradio.c.

char tdesc[] = "USB (CM108) Radio Channel Driver" [static]

Definition at line 680 of file chan_usbradio.c.

char unkey_usage[] [static]
Initial value:
   "Usage: radio unkey\n"
   "       Simulates COR un-active.\n"

Definition at line 2627 of file chan_usbradio.c.

char* usb_device_list = NULL [static]

Definition at line 360 of file chan_usbradio.c.

int usb_device_list_size = 0 [static]

Definition at line 361 of file chan_usbradio.c.

char* usbradio_active [static]

Definition at line 658 of file chan_usbradio.c.

int usbradio_debug [static]

Definition at line 363 of file chan_usbradio.c.

Definition at line 623 of file chan_usbradio.c.

Definition at line 682 of file chan_usbradio.c.


Generated on 2 Mar 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1