Tue Aug 24 20:34:59 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/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 int amixer_max (int devnum, char *param)
 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"usb Console Channel Driver")
static int console_key (int fd, int argc, char *argv[])
static int console_unkey (int fd, int argc, char *argv[])
static struct chan_usbradio_pvt * find_desc (char *dev)
static struct chan_usbradio_pvt * find_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_pvt * store_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_channel * usbradio_new (struct chan_usbradio_pvt *o, char *ext, char *ctx, int state)
static struct ast_frame * usbradio_read (struct ast_channel *chan)
static struct ast_channel * usbradio_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 char active_usage []
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 457 of file chan_usbradio.c.

#define BOOST_SCALE   (1<<9)

Definition at line 456 of file chan_usbradio.c.

#define C108_HID_INTERFACE   3

Definition at line 167 of file chan_usbradio.c.

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

#define C108_PRODUCT_ID   0x000c

Definition at line 166 of file chan_usbradio.c.

Referenced by hid_device_init(), and hid_device_mklist().

#define C108_VENDOR_ID   0x0d8c

Definition at line 165 of file chan_usbradio.c.

Referenced by hid_device_init(), and hid_device_mklist().

#define CHAN_USBRADIO   1

Definition at line 83 of file chan_usbradio.c.

#define config1   "usbradio_tune_%s.conf"

Definition at line 357 of file chan_usbradio.c.

Referenced by store_config().

#define DEBUG_CAP_RX_OUT   0

Definition at line 86 of file chan_usbradio.c.

#define DEBUG_CAP_TX_OUT   0

Definition at line 87 of file chan_usbradio.c.

#define DEBUG_CAPTURES   1

Definition at line 85 of file chan_usbradio.c.

#define DEBUG_FILETEST   0

Definition at line 88 of file chan_usbradio.c.

#define DEBUG_USBRADIO   0

Definition at line 84 of file chan_usbradio.c.

#define DELIMCHR   ','

Definition at line 106 of file chan_usbradio.c.

#define DEV_DSP   "/dev/dsp"

Definition at line 353 of file chan_usbradio.c.

#define EEPROM_CS_ADDR   62

Definition at line 181 of file chan_usbradio.c.

Referenced by put_eeprom().

#define EEPROM_END_ADDR   63

Definition at line 176 of file chan_usbradio.c.

Referenced by get_eeprom().

#define EEPROM_MAGIC   34329

Definition at line 180 of file chan_usbradio.c.

Referenced by hidthread(), and put_eeprom().

#define EEPROM_MAGIC_ADDR   6

Definition at line 179 of file chan_usbradio.c.

Referenced by hidthread(), and put_eeprom().

#define EEPROM_PHYSICAL_LEN   64

Definition at line 177 of file chan_usbradio.c.

#define EEPROM_RXCTCSSADJ   13

Definition at line 186 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_RXMIXERSET   8

Definition at line 182 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_RXSQUELCHADJ   16

Definition at line 188 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_RXVOICEADJ   11

Definition at line 185 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_START_ADDR   6

Definition at line 175 of file chan_usbradio.c.

Referenced by get_eeprom(), and put_eeprom().

#define EEPROM_TEST_ADDR   EEPROM_END_ADDR

Definition at line 178 of file chan_usbradio.c.

#define EEPROM_TXCTCSSADJ   15

Definition at line 187 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_TXMIXASET   9

Definition at line 183 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_TXMIXBSET   10

Definition at line 184 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

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

Definition at line 336 of file chan_usbradio.c.

#define FRAME_SIZE   160

Definition at line 330 of file chan_usbradio.c.

#define HID_REPORT_GET   0x01

Definition at line 169 of file chan_usbradio.c.

Referenced by hid_get_inputs().

#define HID_REPORT_SET   0x09

Definition at line 170 of file chan_usbradio.c.

Referenced by hid_set_outputs().

#define HID_RT_INPUT   0x01

Definition at line 172 of file chan_usbradio.c.

Referenced by hid_get_inputs().

#define HID_RT_OUTPUT   0x02

Definition at line 173 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 296 of file chan_usbradio.c.

Referenced by store_config().

#define M_END ( x   )     x;

Definition at line 294 of file chan_usbradio.c.

Referenced by store_config().

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

Definition at line 295 of file chan_usbradio.c.

Referenced by store_config().

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

Definition at line 292 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 298 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 297 of file chan_usbradio.c.

Referenced by store_config().

#define MIXER_PARAM_MIC_BOOST   "Auto Gain Control"

Definition at line 102 of file chan_usbradio.c.

Referenced by mixer_write(), and tune_rxinput().

#define MIXER_PARAM_MIC_CAPTURE_SW   "Mic Capture Switch"

Definition at line 100 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_MIC_CAPTURE_VOL   "Mic Capture Volume"

Definition at line 101 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 98 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_MIC_PLAYBACK_VOL   "Mic Playback Volume"

Definition at line 99 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_SPKR_PLAYBACK_SW   "Speaker Playback Switch"

Definition at line 103 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_SPKR_PLAYBACK_VOL   "Speaker Playback Volume"

Definition at line 104 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 348 of file chan_usbradio.c.

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

Definition at line 3156 of file chan_usbradio.c.

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

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

Definition at line 3159 of file chan_usbradio.c.

Referenced by pmrdump().

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

Definition at line 3158 of file chan_usbradio.c.

Referenced by playtones_alloc(), playtones_generator(), playtones_release(), and pmrdump().

#define QUEUE_SIZE   2

Definition at line 331 of file chan_usbradio.c.

#define QUOTECHR   34

Definition at line 107 of file chan_usbradio.c.

#define READERR_THRESHOLD   50

Definition at line 109 of file chan_usbradio.c.

Referenced by usbradio_read().

#define RX_CAP_OUT_FILE   "/tmp/rx_cap_out.pcm"

Definition at line 92 of file chan_usbradio.c.

Referenced by usbradio_read().

#define RX_CAP_RAW_FILE   "/tmp/rx_cap_in.pcm"

Definition at line 90 of file chan_usbradio.c.

Referenced by radio_tune().

#define RX_CAP_TRACE_FILE   "/tmp/rx_trace.pcm"

Definition at line 91 of file chan_usbradio.c.

Referenced by radio_tune().

#define TEXT_SIZE   256

Definition at line 343 of file chan_usbradio.c.

#define traceusb1 ( a   ) 

Definition at line 120 of file chan_usbradio.c.

Referenced by hidthread(), and store_config().

#define traceusb2 ( a   ) 

Definition at line 126 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 96 of file chan_usbradio.c.

Referenced by usbradio_read().

#define TX_CAP_RAW_FILE   "/tmp/tx_cap_in.pcm"

Definition at line 94 of file chan_usbradio.c.

Referenced by radio_tune().

#define TX_CAP_TRACE_FILE   "/tmp/tx_trace.pcm"

Definition at line 95 of file chan_usbradio.c.

Referenced by radio_tune().

#define WARN_frag   4

Definition at line 446 of file chan_usbradio.c.

#define WARN_speed   2

Definition at line 445 of file chan_usbradio.c.

#define WARN_used_blocks   1

Definition at line 444 of file chan_usbradio.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
RX_AUDIO_NONE 
RX_AUDIO_SPEAKER 
RX_AUDIO_FLAT 

Definition at line 370 of file chan_usbradio.c.

anonymous enum
Enumerator:
CD_IGNORE 
CD_XPMR_NOISE 
CD_XPMR_VOX 
CD_HID 
CD_HID_INVERT 

Definition at line 371 of file chan_usbradio.c.

anonymous enum
Enumerator:
SD_IGNORE 
SD_HID 
SD_HID_INVERT 
SD_XPMR 

Definition at line 372 of file chan_usbradio.c.

00372 {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 373 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 374 of file chan_usbradio.c.

anonymous enum
Enumerator:
TOC_NONE 
TOC_PHASE 
TOC_NOTONE 

Definition at line 375 of file chan_usbradio.c.


Function Documentation

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

Definition at line 707 of file chan_usbradio.c.

References id, str, and type.

Referenced by store_config().

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

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"usb Console Channel Driver"   
)
static int console_key ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 2264 of file chan_usbradio.c.

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

Referenced by handle_console_key().

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

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

Definition at line 2275 of file chan_usbradio.c.

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

Referenced by handle_console_unkey().

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

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

Definition at line 1260 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().

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

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

Definition at line 1276 of file chan_usbradio.c.

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

Referenced by store_config().

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

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

Definition at line 848 of file chan_usbradio.c.

References EEPROM_END_ADDR, EEPROM_START_ADDR, and read_eeprom().

Referenced by hidthread().

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

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

Definition at line 3815 of file chan_usbradio.c.

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

03817 {
03818    char *argv[] = { "radio", "key", NULL };
03819 
03820         switch (cmd) {
03821         case CLI_INIT:
03822                 e->command = "radio key";
03823                 e->usage = key_usage;
03824                 return NULL;
03825         case CLI_GENERATE:
03826                 return NULL;
03827    }
03828    return res2cli(console_key(a->fd, 2, argv));
03829 }

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

Definition at line 3831 of file chan_usbradio.c.

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

03833 {
03834    char *argv[] = { "radio", "unkey", NULL };
03835         switch (cmd) {
03836         case CLI_INIT:
03837                 e->command = "radio unkey";
03838                 e->usage = unkey_usage;
03839                 return NULL;
03840         case CLI_GENERATE:
03841                 return NULL;
03842    }
03843    return res2cli(console_unkey(a->fd, 2, argv));
03844 }

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

Definition at line 3889 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.

03891 {
03892    char *argv[4] = { "radio", "active", a->argc > 2 ? (char *) a->argv[2] : NULL, };
03893         switch (cmd) {
03894         case CLI_INIT:
03895                 e->command = "radio active";
03896                 e->usage = active_usage;
03897                 return NULL;
03898         case CLI_GENERATE:
03899                 return NULL;
03900    }
03901    return res2cli(radio_active(a->fd, a->argc, argv));
03902 }

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

Definition at line 3861 of file chan_usbradio.c.

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

03863 {
03864         switch (cmd) {
03865         case CLI_INIT:
03866                 e->command = "radio debug";
03867                 e->usage = radio_tune_usage;
03868                 return NULL;
03869         case CLI_GENERATE:
03870                 return NULL;
03871    }
03872    return res2cli(radio_set_debug(a->fd, a->argc, NULL /* ignored */));
03873 }

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

Definition at line 3875 of file chan_usbradio.c.

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

03877 {
03878         switch (cmd) {
03879         case CLI_INIT:
03880                 e->command = "radio debug off";
03881                 e->usage = radio_tune_usage;
03882                 return NULL;
03883         case CLI_GENERATE:
03884                 return NULL;
03885    }
03886    return res2cli(radio_set_debug_off(a->fd, a->argc, NULL /* ignored */));
03887 }

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

Definition at line 3846 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.

03848 {
03849    char *argv[5] = { "radio", "tune", a->argc > 2 ? (char *) a->argv[2] : NULL, a->argc > 3 ? (char *) a->argv[3] : NULL };
03850         switch (cmd) {
03851         case CLI_INIT:
03852                 e->command = "radio tune";
03853                 e->usage = radio_tune_usage;
03854                 return NULL;
03855         case CLI_GENERATE:
03856                 return NULL;
03857    }
03858    return res2cli(radio_tune(a->fd, a->argc, argv));
03859 }

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

Definition at line 3904 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.

03906 {
03907    char *argv[5] = { "radio", "set", "xdebug", a->argc == 4 ? (char *) a->argv[3] : NULL, };
03908         switch (cmd) {
03909         case CLI_INIT:
03910                 e->command = "radio set xdebug";
03911                 e->usage = active_usage;
03912                 return NULL;
03913         case CLI_GENERATE:
03914                 return NULL;
03915    }
03916    return res2cli(radio_set_xpmr_debug(a->fd, a->argc, argv));
03917 }

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

Definition at line 878 of file chan_usbradio.c.

References C108_PRODUCT_ID, C108_VENDOR_ID, and str.

Referenced by hidthread().

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

static int hid_device_mklist ( void   )  [static]

Definition at line 940 of file chan_usbradio.c.

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

Referenced by load_module().

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

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

Definition at line 809 of file chan_usbradio.c.

References C108_HID_INTERFACE, HID_REPORT_GET, and HID_RT_INPUT.

Referenced by hidthread(), and read_eeprom().

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

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

Definition at line 797 of file chan_usbradio.c.

References C108_HID_INTERFACE, HID_REPORT_SET, and HID_RT_OUTPUT.

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

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

static int hidhdwconfig ( struct chan_usbradio_pvt *  o  )  [static]

Definition at line 1061 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().

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

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

Definition at line 1113 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().

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

static void kickptt ( struct chan_usbradio_pvt *  o  )  [static]

Definition at line 1101 of file chan_usbradio.c.

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

Referenced by usbradio_read().

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

static int load_module ( void   )  [static]

Definition at line 3939 of file chan_usbradio.c.

References ARRAY_LEN, 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_SUCCESS, CONFIG_STATUS_FILEINVALID, find_desc(), global_jbconf, hid_device_mklist(), LOG_ERROR, LOG_NOTICE, store_config(), and usb_list_check().

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

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

Definition at line 3146 of file chan_usbradio.c.

Referenced by mult_set().

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

static void mult_set ( struct chan_usbradio_pvt *  o  )  [static]

Definition at line 3131 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().

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

static void pmrdump ( struct chan_usbradio_pvt *  o  )  [static]

Definition at line 3235 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().

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

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

Definition at line 862 of file chan_usbradio.c.

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

Referenced by hidthread().

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

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

Definition at line 2575 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().

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

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

Definition at line 2557 of file chan_usbradio.c.

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

Referenced by handle_radio_debug().

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

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

Definition at line 2566 of file chan_usbradio.c.

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

Referenced by handle_radio_debug_off().

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

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

Definition at line 2604 of file chan_usbradio.c.

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

Referenced by handle_set_xdebug().

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

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

Definition at line 2285 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().

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

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

Definition at line 821 of file chan_usbradio.c.

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

Referenced by get_eeprom().

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

static char* res2cli ( int  r  )  [static]

Definition at line 3801 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().

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

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

Definition at line 1686 of file chan_usbradio.c.

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

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

static int set_txctcss_level ( struct chan_usbradio_pvt *  o  )  [static]

Definition at line 2532 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().

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

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

Definition at line 751 of file chan_usbradio.c.

References id, str, and type.

Referenced by mixer_write(), and tune_rxinput().

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

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

Definition at line 1517 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().

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

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

Definition at line 1349 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().

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

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

Definition at line 3406 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, CONFIG_STATUS_FILEINVALID, 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().

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

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

Definition at line 2765 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().

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

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

Definition at line 2830 of file chan_usbradio.c.

References f, and chan_usbradio_pvt::rxctcssadj.

Referenced by store_config().

02831 {
02832    float f;
02833    sscanf(s, "%30f", &f);
02834    o->rxctcssadj = f;
02835    //ast_log(LOG_WARNING, "set rxctcssadj = %f\n", f);
02836 }

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

Definition at line 2697 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().

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

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

Definition at line 2812 of file chan_usbradio.c.

References f, and chan_usbradio_pvt::rxgain.

Referenced by store_config().

02813 {
02814    float f;
02815    sscanf(s, "%30f", &f); 
02816    o->rxgain = f;
02817    //ast_log(LOG_WARNING, "set rxgain = %f\n", f);
02818 }

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

Definition at line 2790 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().

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

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

Definition at line 2821 of file chan_usbradio.c.

References f, and chan_usbradio_pvt::rxvoiceadj.

Referenced by store_config().

02822 {
02823    float f;
02824    sscanf(s, "%30f", &f);
02825    o->rxvoiceadj = f;
02826    //ast_log(LOG_WARNING, "set rxvoiceadj = %f\n", f);
02827 }

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

Definition at line 2716 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().

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

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

Definition at line 2740 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().

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

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

Definition at line 2839 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().

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

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

Definition at line 3016 of file chan_usbradio.c.

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

Referenced by radio_tune().

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

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

Definition at line 2870 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().

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

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

Definition at line 2950 of file chan_usbradio.c.

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

Referenced by radio_tune().

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

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

Definition at line 2856 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().

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

static void tune_write ( struct chan_usbradio_pvt *  o  )  [static]

Definition at line 3072 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().

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

static int unload_module ( void   )  [static]

Definition at line 3993 of file chan_usbradio.c.

References ARRAY_LEN, 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.

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

static int usb_get_usbdev ( char *  devstr  )  [static]

Definition at line 1018 of file chan_usbradio.c.

References str.

Referenced by store_config().

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

static int usb_list_check ( char *  devstr  )  [static]

Definition at line 1046 of file chan_usbradio.c.

References s.

Referenced by load_module(), and store_config().

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

static int usbradio_answer ( struct ast_channel *  c  )  [static]

Definition at line 1710 of file chan_usbradio.c.

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

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

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 1617 of file chan_usbradio.c.

01618 {
01619    return 0;
01620 }

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

Definition at line 1622 of file chan_usbradio.c.

References ast_verbose.

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

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

Definition at line 2115 of file chan_usbradio.c.

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

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

static int usbradio_hangup ( struct ast_channel *  c  )  [static]

Definition at line 1724 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.

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

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

Definition at line 2123 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.

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

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

Definition at line 2183 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().

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

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

Definition at line 1796 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, fwrite, 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.

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

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

Definition at line 2226 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().

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

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

Definition at line 1633 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, chan_usbradio_pvt::set_rxctcssfreqs, chan_usbradio_pvt::set_rxfreq, chan_usbradio_pvt::set_txctcssfreqs, chan_usbradio_pvt::set_txfreq, and xpmr_config().

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

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

Definition at line 1753 of file chan_usbradio.c.

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

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

static int used_blocks ( struct chan_usbradio_pvt *  o  )  [static]

Definition at line 1327 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().

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

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

Definition at line 835 of file chan_usbradio.c.

References buf, and hid_set_outputs().

Referenced by put_eeprom().

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

static int xpmr_config ( struct chan_usbradio_pvt *  o  )  [static]

Definition at line 3360 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().

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


Variable Documentation

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 2632 of file chan_usbradio.c.

struct ast_cli_entry cli_usbradio[] [static]

Definition at line 3920 of file chan_usbradio.c.

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

Definition at line 356 of file chan_usbradio.c.

struct ast_jb_conf default_jbconf [static]

Global jitterbuffer configuration - by default, jb is disabled

Definition at line 191 of file chan_usbradio.c.

FILE* frxcapraw = NULL [static]

Definition at line 359 of file chan_usbradio.c.

FILE * frxcaptrace = NULL [static]

Definition at line 359 of file chan_usbradio.c.

FILE * frxoutraw = NULL [static]

Definition at line 359 of file chan_usbradio.c.

FILE* ftxcapraw = NULL [static]

Definition at line 360 of file chan_usbradio.c.

FILE * ftxcaptrace = NULL [static]

Definition at line 360 of file chan_usbradio.c.

FILE * ftxoutraw = NULL [static]

Definition at line 360 of file chan_usbradio.c.

struct ast_jb_conf global_jbconf [static]

Definition at line 199 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 2624 of file chan_usbradio.c.

char radio_tune_usage[] [static]

Definition at line 2640 of file chan_usbradio.c.

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

Definition at line 682 of file chan_usbradio.c.

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

Definition at line 2628 of file chan_usbradio.c.

char* usb_device_list = NULL [static]

Definition at line 362 of file chan_usbradio.c.

int usb_device_list_size = 0 [static]

Definition at line 363 of file chan_usbradio.c.

char* usbradio_active [static]

Definition at line 660 of file chan_usbradio.c.

int usbradio_debug [static]

Definition at line 365 of file chan_usbradio.c.

Definition at line 625 of file chan_usbradio.c.

Definition at line 684 of file chan_usbradio.c.


Generated on 24 Aug 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1