Wed Apr 6 11:30:01 2011

Asterisk developer's documentation


chan_usbradio.c File Reference

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

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

Go to the source code of this file.

Data Structures

struct  chan_usbradio_pvt
struct  sound

Defines

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

Enumerations

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

Functions

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

Variables

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


Detailed Description

Channel driver for CM108 USB Cards with Radio Interface.

Author:
Jim Dixon <jim@lambdatel.com>

Steve Henke <w9sh@arrl.net>

See also

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;

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 (  )     {printf(#x" = %d\n",x);}

Definition at line 3144 of file chan_usbradio.c.

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

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

Definition at line 3147 of file chan_usbradio.c.

Referenced by pmrdump().

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

Definition at line 3145 of file chan_usbradio.c.

Referenced by dahdi_setoption(), get_unaligned_uint16(), get_unaligned_uint32(), get_unaligned_uint64(), put_unaligned_uint16(), put_unaligned_uint32(), put_unaligned_uint64(), and sms_readfile().

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

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

Definition at line 120 of file chan_usbradio.c.

Referenced by hidthread(), and store_config().

#define traceusb2 (  ) 

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 void __reg_module ( void   )  [static]

Definition at line 4022 of file chan_usbradio.c.

static void __unreg_module ( void   )  [static]

Definition at line 4022 of file chan_usbradio.c.

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

Definition at line 708 of file chan_usbradio.c.

References id, str, and type.

Referenced by store_config().

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

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

Definition at line 2252 of file chan_usbradio.c.

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

Referenced by handle_console_key().

02253 {
02254    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02255 
02256    if (argc != 2)
02257       return RESULT_SHOWUSAGE; 
02258    o->txtestkey = 1;
02259    return RESULT_SUCCESS;
02260 }

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

Definition at line 2263 of file chan_usbradio.c.

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

Referenced by handle_console_unkey().

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

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

Definition at line 1251 of file chan_usbradio.c.

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

01252 {
01253    struct chan_usbradio_pvt *o = NULL;
01254 
01255    if (!dev)
01256       ast_log(LOG_WARNING, "null dev\n");
01257 
01258    for (o = usbradio_default.next; o && o->name && dev && strcmp(o->name, dev) != 0; o = o->next);
01259    if (!o)
01260    {
01261       ast_log(LOG_WARNING, "could not find <%s>\n", dev ? dev : "--no-device--");
01262    }
01263 
01264    return o;
01265 }

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

Definition at line 1267 of file chan_usbradio.c.

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

Referenced by store_config().

01268 {
01269    struct chan_usbradio_pvt *o = NULL;
01270 
01271    if (!devstr)
01272       ast_log(LOG_WARNING, "null dev\n");
01273 
01274    for (o = usbradio_default.next; o && devstr && strcmp(o->devstr, devstr) != 0; o = o->next);
01275 
01276    return o;
01277 }

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

Definition at line 849 of file chan_usbradio.c.

References EEPROM_END_ADDR, EEPROM_START_ADDR, and read_eeprom().

Referenced by hidthread().

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

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

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

03805 {
03806    char *argv[] = { "radio", "key", NULL };
03807 
03808         switch (cmd) {
03809         case CLI_INIT:
03810                 e->command = "radio key";
03811                 e->usage = key_usage;
03812                 return NULL;
03813         case CLI_GENERATE:
03814                 return NULL;
03815    }
03816    return res2cli(console_key(a->fd, 2, argv));
03817 }

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

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

03821 {
03822    char *argv[] = { "radio", "unkey", NULL };
03823         switch (cmd) {
03824         case CLI_INIT:
03825                 e->command = "radio unkey";
03826                 e->usage = unkey_usage;
03827                 return NULL;
03828         case CLI_GENERATE:
03829                 return NULL;
03830    }
03831    return res2cli(console_unkey(a->fd, 2, argv));
03832 }

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

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

03879 {
03880    char *argv[4] = { "radio", "active", a->argc > 2 ? (char *) a->argv[2] : NULL, };
03881         switch (cmd) {
03882         case CLI_INIT:
03883                 e->command = "radio active";
03884                 e->usage = active_usage;
03885                 return NULL;
03886         case CLI_GENERATE:
03887                 return NULL;
03888    }
03889    return res2cli(radio_active(a->fd, a->argc, argv));
03890 }

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

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

03851 {
03852         switch (cmd) {
03853         case CLI_INIT:
03854                 e->command = "radio debug";
03855                 e->usage = radio_tune_usage;
03856                 return NULL;
03857         case CLI_GENERATE:
03858                 return NULL;
03859    }
03860    return res2cli(radio_set_debug(a->fd, a->argc, NULL /* ignored */));
03861 }

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

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

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

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

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

03836 {
03837    char *argv[5] = { "radio", "tune", a->argc > 2 ? (char *) a->argv[2] : NULL, a->argc > 3 ? (char *) a->argv[3] : NULL };
03838         switch (cmd) {
03839         case CLI_INIT:
03840                 e->command = "radio tune";
03841                 e->usage = radio_tune_usage;
03842                 return NULL;
03843         case CLI_GENERATE:
03844                 return NULL;
03845    }
03846    return res2cli(radio_tune(a->fd, a->argc, argv));
03847 }

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

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

03894 {
03895    char *argv[5] = { "radio", "set", "xdebug", a->argc == 4 ? (char *) a->argv[3] : NULL, };
03896         switch (cmd) {
03897         case CLI_INIT:
03898                 e->command = "radio set xdebug";
03899                 e->usage = active_usage;
03900                 return NULL;
03901         case CLI_GENERATE:
03902                 return NULL;
03903    }
03904    return res2cli(radio_set_xpmr_debug(a->fd, a->argc, argv));
03905 }

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

Definition at line 879 of file chan_usbradio.c.

References C108_PRODUCT_ID, C108_VENDOR_ID, and str.

Referenced by hidthread().

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

static int hid_device_mklist ( void   )  [static]

Definition at line 941 of file chan_usbradio.c.

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

Referenced by load_module().

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

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

Definition at line 810 of file chan_usbradio.c.

References C108_HID_INTERFACE, HID_REPORT_GET, and HID_RT_INPUT.

Referenced by hidthread(), and read_eeprom().

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

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

Definition at line 798 of file chan_usbradio.c.

References C108_HID_INTERFACE, HID_REPORT_SET, and HID_RT_OUTPUT.

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

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

static int hidhdwconfig ( struct chan_usbradio_pvt o  )  [static]

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

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

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

Definition at line 1114 of file chan_usbradio.c.

References ast_debug, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_poll, 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().

01115 {
01116    unsigned char buf[4],bufsave[4],keyed;
01117    char lastrx, txtmp;
01118    int res;
01119    struct usb_device *usb_dev;
01120    struct usb_dev_handle *usb_handle;
01121    struct chan_usbradio_pvt *o = (struct chan_usbradio_pvt *) arg;
01122    struct pollfd pfd = { .events = POLLIN };
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       pfd.fd = o->pttkick[0];
01160       pfd.revents = 0;
01161 
01162       res = ast_poll(&pfd, 1, 50);
01163       if (res < 0) {
01164          ast_log(LOG_WARNING, "poll() failed: %s\n", strerror(errno));
01165          usleep(10000);
01166          continue;
01167       }
01168       if (pfd.revents & POLLIN) {
01169          char c;
01170 
01171          if (read(o->pttkick[0], &c, 1) < 0) {
01172             ast_log(LOG_ERROR, "read() failed: %s\n", strerror(errno));
01173          }
01174       }
01175       if (o->wanteeprom) {
01176          ast_mutex_lock(&o->eepromlock);
01177          if (o->eepromctl == 1) { /* to read */
01178             /* if CS okay */
01179             if (!get_eeprom(usb_handle, o->eeprom)) {
01180                if (o->eeprom[EEPROM_MAGIC_ADDR] != EEPROM_MAGIC) {
01181                   ast_log(LOG_NOTICE, "UNSUCCESSFUL: EEPROM MAGIC NUMBER BAD on channel %s\n", o->name);
01182                } else {
01183                   o->rxmixerset = o->eeprom[EEPROM_RXMIXERSET];
01184                   o->txmixaset = o->eeprom[EEPROM_TXMIXASET];
01185                   o->txmixbset = o->eeprom[EEPROM_TXMIXBSET];
01186                   memcpy(&o->rxvoiceadj, &o->eeprom[EEPROM_RXVOICEADJ], sizeof(float));
01187                   memcpy(&o->rxctcssadj, &o->eeprom[EEPROM_RXCTCSSADJ], sizeof(float));
01188                   o->txctcssadj = o->eeprom[EEPROM_TXCTCSSADJ];
01189                   o->rxsquelchadj = o->eeprom[EEPROM_RXSQUELCHADJ];
01190                   ast_log(LOG_NOTICE,"EEPROM Loaded on channel %s\n",o->name);
01191                }
01192             } else {
01193                ast_log(LOG_NOTICE, "USB Adapter has no EEPROM installed or Checksum BAD on channel %s\n", o->name);
01194             }
01195             hid_set_outputs(usb_handle,bufsave);
01196          }
01197          if (o->eepromctl == 2) { /* to write */
01198             put_eeprom(usb_handle,o->eeprom);
01199             hid_set_outputs(usb_handle,bufsave);
01200             ast_log(LOG_NOTICE, "USB Parameters written to EEPROM on %s\n", o->name);
01201          }
01202          o->eepromctl = 0;
01203          ast_mutex_unlock(&o->eepromlock);
01204       }
01205       buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
01206       hid_get_inputs(usb_handle,buf);
01207       keyed = !(buf[o->hid_io_cor_loc] & o->hid_io_cor);
01208       if (keyed != o->rxhidsq) {
01209          if (o->debuglevel) {
01210             printf("chan_usbradio() hidthread: update rxhidsq = %d\n", keyed);
01211          }
01212          o->rxhidsq=keyed;
01213       }
01214 
01215       /* if change in tx state as controlled by xpmr */
01216       txtmp = o->pmrChan->txPttOut;
01217 
01218       if (o->lasttx != txtmp) {
01219          o->pmrChan->txPttHid = o->lasttx = txtmp;
01220          if (o->debuglevel) {
01221             ast_debug(0, "hidthread: tx set to %d\n", txtmp);
01222          }
01223          buf[o->hid_gpio_loc] = 0;
01224          if (!o->invertptt) {
01225             if (txtmp) {
01226                buf[o->hid_gpio_loc] = o->hid_io_ptt;
01227             }
01228          } else {
01229             if (!txtmp) {
01230                buf[o->hid_gpio_loc] = o->hid_io_ptt;
01231             }
01232          }
01233          buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
01234          memcpy(bufsave, buf, sizeof(buf));
01235          hid_set_outputs(usb_handle, buf);
01236       }
01237       time(&o->lasthidtime);
01238    }
01239    buf[o->hid_gpio_loc] = 0;
01240    if (o->invertptt) {
01241       buf[o->hid_gpio_loc] = o->hid_io_ptt;
01242    }
01243    buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
01244    hid_set_outputs(usb_handle, buf);
01245    pthread_exit(0);
01246 }

static void kickptt ( struct chan_usbradio_pvt o  )  [static]

Definition at line 1102 of file chan_usbradio.c.

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

Referenced by usbradio_read().

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

static int load_module ( void   )  [static]

Definition at line 3927 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, cli_usbradio, config, CONFIG_STATUS_FILEINVALID, default_jbconf, find_desc(), global_jbconf, hid_device_mklist(), LOG_ERROR, LOG_NOTICE, store_config(), usb_list_check(), usbradio_active, and usbradio_tech.

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

static void mixer_write ( struct chan_usbradio_pvt o  )  [static]

Definition at line 3103 of file chan_usbradio.c.

References chan_usbradio_pvt::devicenum, chan_usbradio_pvt::micmax, MIXER_PARAM_MIC_BOOST, MIXER_PARAM_MIC_CAPTURE_SW, MIXER_PARAM_MIC_CAPTURE_VOL, MIXER_PARAM_MIC_PLAYBACK_SW, MIXER_PARAM_MIC_PLAYBACK_VOL, MIXER_PARAM_SPKR_PLAYBACK_SW, MIXER_PARAM_SPKR_PLAYBACK_VOL, chan_usbradio_pvt::rxboostset, chan_usbradio_pvt::rxmixerset, setamixer(), chan_usbradio_pvt::spkrmax, chan_usbradio_pvt::txmixaset, and chan_usbradio_pvt::txmixbset.

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

static int mult_calc ( int  value  )  [static]

Definition at line 3134 of file chan_usbradio.c.

Referenced by mult_set().

03135 {
03136    const int multx=M_Q8;
03137    int pot,mult;
03138 
03139    pot=((int)(value/4)*4)+2;
03140    mult = multx-( ( multx * (3-(value%4)) ) / (pot+2) );
03141    return(mult);
03142 }

static void mult_set ( struct chan_usbradio_pvt o  )  [static]

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

03120 {
03121 
03122    if(o->pmrChan->spsTxOutA) {
03123       o->pmrChan->spsTxOutA->outputGain = 
03124          mult_calc((o->txmixaset * 152) / 1000);
03125    }
03126    if(o->pmrChan->spsTxOutB){
03127       o->pmrChan->spsTxOutB->outputGain = 
03128          mult_calc((o->txmixbset * 152) / 1000);
03129    }
03130 }

static void pmrdump ( struct chan_usbradio_pvt o  )  [static]

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

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

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

Definition at line 863 of file chan_usbradio.c.

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

Referenced by hidthread().

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

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

Definition at line 2563 of file chan_usbradio.c.

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

Referenced by handle_radio_active().

02564 {
02565         if (argc == 2)
02566                 ast_cli(fd, "active (command) USB Radio device is [%s]\n", usbradio_active);
02567         else if (argc != 3)
02568                 return RESULT_SHOWUSAGE;
02569         else {
02570                 struct chan_usbradio_pvt *o;
02571                 if (strcmp(argv[2], "show") == 0) {
02572                         for (o = usbradio_default.next; o; o = o->next)
02573                                 ast_cli(fd, "device [%s] exists\n", o->name);
02574                         return RESULT_SUCCESS;
02575                 }
02576                 o = find_desc(argv[2]);
02577                 if (o == NULL)
02578                         ast_cli(fd, "No device [%s] exists\n", argv[2]);
02579                 else
02580             {
02581                struct chan_usbradio_pvt *ao;
02582                for (ao = usbradio_default.next; ao && ao->name ; ao = ao->next)ao->pmrChan->b.radioactive=0;
02583                     usbradio_active = o->name;
02584                 o->pmrChan->b.radioactive=1;
02585             }
02586         }
02587         return RESULT_SUCCESS;
02588 }

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

Definition at line 2545 of file chan_usbradio.c.

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

Referenced by handle_radio_debug().

02546 {
02547    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02548 
02549    o->debuglevel=1;
02550    ast_cli(fd,"usbradio debug on.\n");
02551    return RESULT_SUCCESS;
02552 }

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

Definition at line 2554 of file chan_usbradio.c.

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

Referenced by handle_radio_debug_off().

02555 {
02556    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02557 
02558    o->debuglevel=0;
02559    ast_cli(fd,"usbradio debug off.\n");
02560    return RESULT_SUCCESS;
02561 }

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

Definition at line 2592 of file chan_usbradio.c.

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

Referenced by handle_set_xdebug().

02593 {
02594    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02595 
02596    if (argc == 4)
02597    {
02598       int i;
02599       i = atoi(argv[3]);
02600       if ((i >= 0) && (i <= 100))
02601       { 
02602          o->pmrChan->tracelevel=i;
02603       }
02604     }
02605    // add ability to set it for a number of frames after which it reverts
02606    ast_cli(fd,"usbradio xdebug on tracelevel %i\n",o->pmrChan->tracelevel);
02607 
02608    return RESULT_SUCCESS;
02609 }

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

Definition at line 2273 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(), frxcapraw, frxcaptrace, frxoutraw, ftxcapraw, ftxcaptrace, ftxoutraw, 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, chan_usbradio_pvt::txtestkey, and usbradio_active.

Referenced by handle_radio_tune().

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

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

Definition at line 822 of file chan_usbradio.c.

References hid_get_inputs(), and hid_set_outputs().

Referenced by get_eeprom().

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

static char* res2cli ( int  r  )  [static]

Definition at line 3789 of file chan_usbradio.c.

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

03791 {
03792    switch (r)
03793    {
03794        case RESULT_SUCCESS:
03795       return(CLI_SUCCESS);
03796        case RESULT_SHOWUSAGE:
03797       return(CLI_SHOWUSAGE);
03798        default:
03799       return(CLI_FAILURE);
03800    }
03801 }

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

Definition at line 1672 of file chan_usbradio.c.

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

01673 {
01674 #ifndef  NEW_ASTERISK
01675    write(o->sndcmd[1], &x, sizeof(x));
01676 #endif
01677 }

static int set_txctcss_level ( struct chan_usbradio_pvt o  )  [static]

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

02521 {                      
02522    if (o->txmixa == TX_OUT_LSD)
02523    {
02524 //    o->txmixaset=(151*o->txctcssadj) / 1000;
02525       o->txmixaset=o->txctcssadj;
02526       mixer_write(o);
02527       mult_set(o);
02528    }
02529    else if (o->txmixb == TX_OUT_LSD)
02530    {
02531 //    o->txmixbset=(151*o->txctcssadj) / 1000;
02532       o->txmixbset=o->txctcssadj;
02533       mixer_write(o);
02534       mult_set(o);
02535    }
02536    else
02537    {
02538       *o->pmrChan->ptxCtcssAdjust=(o->txctcssadj * M_Q8) / 1000;
02539    }
02540    return 0;
02541 }

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

Definition at line 752 of file chan_usbradio.c.

References id, str, and type.

Referenced by mixer_write(), and tune_rxinput().

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

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

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

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

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

Definition at line 1340 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, usbradio_debug, used_blocks(), and chan_usbradio_pvt::w_errors.

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

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

Definition at line 3394 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_device_list, usb_get_usbdev(), usb_list_check(), usbradio_active, usbradio_debug, usbradio_default, ast_variable::value, chan_usbradio_pvt::wanteeprom, and xpmr_config().

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

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

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

02754 {
02755    if (!strcasecmp(s,"no")){
02756       o->rxcdtype = CD_IGNORE;
02757    }
02758    else if (!strcasecmp(s,"usb")){
02759       o->rxcdtype = CD_HID;
02760    }
02761    else if (!strcasecmp(s,"dsp")){
02762       o->rxcdtype = CD_XPMR_NOISE;
02763    }  
02764    else if (!strcasecmp(s,"vox")){
02765       o->rxcdtype = CD_XPMR_VOX;
02766    }  
02767    else if (!strcasecmp(s,"usbinvert")){
02768       o->rxcdtype = CD_HID_INVERT;
02769    }  
02770    else {
02771       ast_log(LOG_WARNING,"Unrecognized rxcdtype parameter: %s\n",s);
02772    }
02773 
02774    //ast_log(LOG_WARNING, "set rxcdtype = %s\n", s);
02775 }

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

Definition at line 2818 of file chan_usbradio.c.

References f, and chan_usbradio_pvt::rxctcssadj.

Referenced by store_config().

02819 {
02820    float f;
02821    sscanf(s, "%30f", &f);
02822    o->rxctcssadj = f;
02823    //ast_log(LOG_WARNING, "set rxctcssadj = %f\n", f);
02824 }

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

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

02686 {
02687    if (!strcasecmp(s,"no")){
02688       o->rxdemod = RX_AUDIO_NONE;
02689    }
02690    else if (!strcasecmp(s,"speaker")){
02691       o->rxdemod = RX_AUDIO_SPEAKER;
02692    }
02693    else if (!strcasecmp(s,"flat")){
02694          o->rxdemod = RX_AUDIO_FLAT;
02695    }  
02696    else {
02697       ast_log(LOG_WARNING,"Unrecognized rxdemod parameter: %s\n",s);
02698    }
02699 
02700    //ast_log(LOG_WARNING, "set rxdemod = %s\n", s);
02701 }

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

Definition at line 2800 of file chan_usbradio.c.

References f, and chan_usbradio_pvt::rxgain.

Referenced by store_config().

02801 {
02802    float f;
02803    sscanf(s, "%30f", &f); 
02804    o->rxgain = f;
02805    //ast_log(LOG_WARNING, "set rxgain = %f\n", f);
02806 }

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

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

02779 {
02780    if (!strcasecmp(s,"no") || !strcasecmp(s,"SD_IGNORE")){
02781       o->rxsdtype = SD_IGNORE;
02782    }
02783    else if (!strcasecmp(s,"usb") || !strcasecmp(s,"SD_HID")){
02784       o->rxsdtype = SD_HID;
02785    }
02786    else if (!strcasecmp(s,"usbinvert") || !strcasecmp(s,"SD_HID_INVERT")){
02787       o->rxsdtype = SD_HID_INVERT;
02788    }  
02789    else if (!strcasecmp(s,"software") || !strcasecmp(s,"SD_XPMR")){
02790       o->rxsdtype = SD_XPMR;
02791    }  
02792    else {
02793       ast_log(LOG_WARNING,"Unrecognized rxsdtype parameter: %s\n",s);
02794    }
02795 
02796    //ast_log(LOG_WARNING, "set rxsdtype = %s\n", s);
02797 }

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

Definition at line 2809 of file chan_usbradio.c.

References f, and chan_usbradio_pvt::rxvoiceadj.

Referenced by store_config().

02810 {
02811    float f;
02812    sscanf(s, "%30f", &f);
02813    o->rxvoiceadj = f;
02814    //ast_log(LOG_WARNING, "set rxvoiceadj = %f\n", f);
02815 }

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

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

02705 {
02706    if (!strcasecmp(s,"no")){
02707       o->txmixa = TX_OUT_OFF;
02708    }
02709    else if (!strcasecmp(s,"voice")){
02710       o->txmixa = TX_OUT_VOICE;
02711    }
02712    else if (!strcasecmp(s,"tone")){
02713          o->txmixa = TX_OUT_LSD;
02714    }  
02715    else if (!strcasecmp(s,"composite")){
02716       o->txmixa = TX_OUT_COMPOSITE;
02717    }  
02718    else if (!strcasecmp(s,"auxvoice")){
02719       o->txmixa = TX_OUT_AUX;
02720    }  
02721    else {
02722       ast_log(LOG_WARNING,"Unrecognized txmixa parameter: %s\n",s);
02723    }
02724 
02725    //ast_log(LOG_WARNING, "set txmixa = %s\n", s);
02726 }

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

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

02729 {
02730    if (!strcasecmp(s,"no")){
02731       o->txmixb = TX_OUT_OFF;
02732    }
02733    else if (!strcasecmp(s,"voice")){
02734       o->txmixb = TX_OUT_VOICE;
02735    }
02736    else if (!strcasecmp(s,"tone")){
02737          o->txmixb = TX_OUT_LSD;
02738    }  
02739    else if (!strcasecmp(s,"composite")){
02740       o->txmixb = TX_OUT_COMPOSITE;
02741    }  
02742    else if (!strcasecmp(s,"auxvoice")){
02743       o->txmixb = TX_OUT_AUX;
02744    }  
02745    else {
02746       ast_log(LOG_WARNING,"Unrecognized txmixb parameter: %s\n",s);
02747    }
02748 
02749    //ast_log(LOG_WARNING, "set txmixb = %s\n", s);
02750 }

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

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

02828 {
02829    if (!strcasecmp(s,"no") || !strcasecmp(s,"TOC_NONE")){
02830       o->txtoctype = TOC_NONE;
02831    }
02832    else if (!strcasecmp(s,"phase") || !strcasecmp(s,"TOC_PHASE")){
02833       o->txtoctype = TOC_PHASE;
02834    }
02835    else if (!strcasecmp(s,"notone") || !strcasecmp(s,"TOC_NOTONE")){
02836       o->txtoctype = TOC_NOTONE;
02837    }  
02838    else {
02839       ast_log(LOG_WARNING,"Unrecognized txtoctype parameter: %s\n",s);
02840    }
02841 }

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

Definition at line 3004 of file chan_usbradio.c.

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

Referenced by radio_tune().

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

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

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

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

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

Definition at line 2938 of file chan_usbradio.c.

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

Referenced by radio_tune().

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

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

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

02845 {
02846    o->txtestkey=1;
02847    o->pmrChan->txPttIn=1;
02848    TxTestTone(o->pmrChan, 1);   // generate 1KHz tone at 7200 peak
02849    if (fd > 0) ast_cli(fd,"Tone output starting on channel %s...\n",o->name);
02850    usleep(5000000);
02851    TxTestTone(o->pmrChan, 0);
02852    if (fd > 0) ast_cli(fd,"Tone output ending on channel %s...\n",o->name);
02853    o->pmrChan->txPttIn=0;
02854    o->txtestkey=0;
02855 }

static void tune_write ( struct chan_usbradio_pvt o  )  [static]

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

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

static int unload_module ( void   )  [static]

Definition at line 3981 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, cli_usbradio, chan_usbradio_pvt::dsp, frxcapraw, frxcaptrace, frxoutraw, ftxcapraw, ftxcaptrace, ftxoutraw, LOG_WARNING, chan_usbradio_pvt::next, chan_usbradio_pvt::owner, chan_usbradio_pvt::pmrChan, chan_usbradio_pvt::sounddev, usbradio_default, and usbradio_tech.

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

static int usb_get_usbdev ( char *  devstr  )  [static]

Definition at line 1019 of file chan_usbradio.c.

References str.

Referenced by store_config().

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

static int usb_list_check ( char *  devstr  )  [static]

Definition at line 1047 of file chan_usbradio.c.

References usb_device_list.

Referenced by load_module(), and store_config().

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

static int usbradio_answer ( struct ast_channel c  )  [static]

Definition at line 1696 of file chan_usbradio.c.

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

01697 {
01698 #ifndef  NEW_ASTERISK
01699    struct chan_usbradio_pvt *o = c->tech_pvt;
01700 #endif
01701 
01702    ast_setstate(c, AST_STATE_UP);
01703 #ifndef  NEW_ASTERISK
01704    o->cursound = -1;
01705    o->nosound = 0;
01706 #endif
01707    return 0;
01708 }

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

Definition at line 1682 of file chan_usbradio.c.

References ast_pthread_create_background, ast_setstate(), AST_STATE_UP, hidthread(), chan_usbradio_pvt::hidthread, chan_usbradio_pvt::lasthidtime, chan_usbradio_pvt::stophid, and ast_channel::tech_pvt.

01683 {
01684    struct chan_usbradio_pvt *o = c->tech_pvt;
01685 
01686    o->stophid = 0;
01687    time(&o->lasthidtime);
01688    ast_pthread_create_background(&o->hidthread, NULL, hidthread, o);
01689    ast_setstate(c, AST_STATE_UP);
01690    return 0;
01691 }

static int usbradio_digit_begin ( struct ast_channel c,
char  digit 
) [static]

Definition at line 1603 of file chan_usbradio.c.

01604 {
01605    return 0;
01606 }

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

Definition at line 1608 of file chan_usbradio.c.

References ast_verbose.

01609 {
01610    /* no better use for received digits than print them */
01611    ast_verbose(" << Console Received digit %c of duration %u ms >> \n", 
01612       digit, duration);
01613    return 0;
01614 }

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

Definition at line 2101 of file chan_usbradio.c.

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

02102 {
02103    struct chan_usbradio_pvt *o = newchan->tech_pvt;
02104    ast_log(LOG_WARNING,"usbradio_fixup()\n");
02105    o->owner = newchan;
02106    return 0;
02107 }

static int usbradio_hangup ( struct ast_channel c  )  [static]

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

01711 {
01712    struct chan_usbradio_pvt *o = c->tech_pvt;
01713 
01714    //ast_log(LOG_NOTICE, "usbradio_hangup()\n");
01715 #ifndef  NEW_ASTERISK
01716    o->cursound = -1;
01717    o->nosound = 0;
01718 #endif
01719    c->tech_pvt = NULL;
01720    o->owner = NULL;
01721    ast_module_unref(ast_module_info->self);
01722    if (o->hookstate) {
01723       if (o->autoanswer || o->autohangup) {
01724          /* Assume auto-hangup too */
01725          o->hookstate = 0;
01726          setformat(o, O_CLOSE);
01727       } else {
01728          /* Make congestion noise */
01729          ring(o, AST_CONTROL_CONGESTION);
01730       }
01731    }
01732    o->stophid = 1;
01733    pthread_join(o->hidthread,NULL);
01734    return 0;
01735 }

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

Definition at line 2109 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, ast_channel::name, ring(), ast_channel::tech_pvt, and chan_usbradio_pvt::txkeyed.

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

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

Definition at line 2169 of file chan_usbradio.c.

References ast_party_caller::ani, 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::caller, chan_usbradio_pvt::cid_name, chan_usbradio_pvt::cid_num, ast_channel::dialed, ast_channel::fds, global_jbconf, language, chan_usbradio_pvt::language, LOG_WARNING, chan_usbradio_pvt::name, ast_channel::nativeformats, ast_party_dialed::number, ast_party_id::number, chan_usbradio_pvt::owner, ast_channel::readformat, setformat(), chan_usbradio_pvt::sounddev, ast_party_dialed::str, ast_party_number::str, ast_channel::tech, ast_channel::tech_pvt, usbradio_tech, ast_party_number::valid, and ast_channel::writeformat.

Referenced by usbradio_request().

02170 {
02171    struct ast_channel *c;
02172 
02173    c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "", ext, ctx, linkedid, 0, "Radio/%s", o->name);
02174    if (c == NULL)
02175       return NULL;
02176    c->tech = &usbradio_tech;
02177    if (o->sounddev < 0)
02178       setformat(o, O_RDWR);
02179    c->fds[0] = o->sounddev;   /* -1 if device closed, override later */
02180    c->nativeformats = AST_FORMAT_SLINEAR;
02181    c->readformat = AST_FORMAT_SLINEAR;
02182    c->writeformat = AST_FORMAT_SLINEAR;
02183    c->tech_pvt = o;
02184 
02185    if (!ast_strlen_zero(o->language))
02186       ast_string_field_set(c, language, o->language);
02187    /* Don't use ast_set_callerid() here because it will
02188     * generate a needless NewCallerID event */
02189    if (!ast_strlen_zero(o->cid_num)) {
02190       c->caller.ani.number.valid = 1;
02191       c->caller.ani.number.str = ast_strdup(o->cid_num);
02192    }
02193    if (!ast_strlen_zero(ext)) {
02194       c->dialed.number.str = ast_strdup(ext);
02195    }
02196 
02197    o->owner = c;
02198    ast_module_ref(ast_module_info->self);
02199    ast_jb_configure(c, &global_jbconf);
02200    if (state != AST_STATE_DOWN) {
02201       if (ast_pbx_start(c)) {
02202          ast_log(LOG_WARNING, "Unable to start PBX on %s\n", c->name);
02203          ast_hangup(c);
02204          o->owner = c = NULL;
02205          /* XXX what about the channel itself ? */
02206          /* XXX what about usecnt ? */
02207       }
02208    }
02209 
02210    return c;
02211 }

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

Definition at line 1782 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, frxcapraw, frxcaptrace, frxoutraw, ftxcaptrace, ftxoutraw, fwrite, ast_frame_subclass::integer, kickptt(), chan_usbradio_pvt::lasthidtime, chan_usbradio_pvt::lastrx, LOG_ERROR, LOG_NOTICE, LOG_WARNING, chan_usbradio_pvt::mute, ast_channel::name, chan_usbradio_pvt::name, 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, soundcard_writeframe(), chan_usbradio_pvt::sounddev, 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, usbradio_tech, chan_usbradio_pvt::usbradio_write_buf, chan_usbradio_pvt::usbradio_write_buf_1, and chan_usbradio_pvt::usbradio_write_dst.

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

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

Definition at line 2214 of file chan_usbradio.c.

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

02215 {
02216    struct ast_channel *c;
02217    struct chan_usbradio_pvt *o = find_desc(data);
02218 
02219    TRACEO(1,("usbradio_request()\n"));
02220 
02221    if (0)
02222    {
02223       ast_log(LOG_WARNING, "usbradio_request type <%s> data 0x%p <%s>\n", type, data, (char *) data);
02224    }
02225    if (o == NULL) {
02226       ast_log(LOG_NOTICE, "Device %s not found\n", (char *) data);
02227       /* XXX we could default to 'dsp' perhaps ? */
02228       return NULL;
02229    }
02230    if ((format & AST_FORMAT_SLINEAR) == 0) {
02231       ast_log(LOG_NOTICE, "Format 0x%" PRIx64 " unsupported\n", format);
02232       return NULL;
02233    }
02234    if (o->owner) {
02235       ast_log(LOG_NOTICE, "Already have a call (chan %p) on the usb channel\n", o->owner);
02236       *cause = AST_CAUSE_BUSY;
02237       return NULL;
02238    }
02239    c = usbradio_new(o, NULL, NULL, AST_STATE_DOWN, requestor ? requestor->linkedid : NULL);
02240    if (c == NULL) {
02241       ast_log(LOG_WARNING, "Unable to create new usb channel\n");
02242       return NULL;
02243    }
02244       
02245    o->b.remoted=0;
02246    xpmr_config(o);
02247 
02248    return c;
02249 }

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

Definition at line 1619 of file chan_usbradio.c.

References ast_log(), ast_verbose, chan_usbradio_pvt::b, 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, usbradio_active, and xpmr_config().

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

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

Definition at line 1739 of file chan_usbradio.c.

References ast_log(), chan_usbradio_pvt::b, errno, f, ftxcapraw, fwrite, LOG_ERROR, ast_channel::tech_pvt, traceusb2, chan_usbradio_pvt::txcapraw, and chan_usbradio_pvt::txkeyed.

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

static int used_blocks ( struct chan_usbradio_pvt o  )  [static]

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

01319 {
01320    struct audio_buf_info info;
01321 
01322    if (ioctl(o->sounddev, SNDCTL_DSP_GETOSPACE, &info)) {
01323       if (!(o->warned & WARN_used_blocks)) {
01324          ast_log(LOG_WARNING, "Error reading output space\n");
01325          o->warned |= WARN_used_blocks;
01326       }
01327       return 1;
01328    }
01329 
01330    if (o->total_blocks == 0) {
01331       if (0)               /* debugging */
01332          ast_log(LOG_WARNING, "fragtotal %d size %d avail %d\n", info.fragstotal, info.fragsize, info.fragments);
01333       o->total_blocks = info.fragments;
01334    }
01335 
01336    return o->total_blocks - info.fragments;
01337 }

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

Definition at line 836 of file chan_usbradio.c.

References hid_set_outputs().

Referenced by put_eeprom().

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

static int xpmr_config ( struct chan_usbradio_pvt o  )  [static]

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

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


Variable Documentation

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

Definition at line 4022 of file chan_usbradio.c.

char active_usage[] [static]

Initial value:

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

Definition at line 2620 of file chan_usbradio.c.

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 4022 of file chan_usbradio.c.

struct ast_cli_entry cli_usbradio[] [static]

Definition at line 3908 of file chan_usbradio.c.

Referenced by load_module(), and unload_module().

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.

Referenced by radio_tune(), unload_module(), and usbradio_read().

FILE * frxcaptrace = NULL [static]

Definition at line 359 of file chan_usbradio.c.

Referenced by radio_tune(), unload_module(), and usbradio_read().

FILE * frxoutraw = NULL [static]

Definition at line 359 of file chan_usbradio.c.

Referenced by radio_tune(), unload_module(), and usbradio_read().

FILE* ftxcapraw = NULL [static]

Definition at line 360 of file chan_usbradio.c.

Referenced by radio_tune(), unload_module(), and usbradio_write().

FILE * ftxcaptrace = NULL [static]

Definition at line 360 of file chan_usbradio.c.

Referenced by radio_tune(), unload_module(), and usbradio_read().

FILE * ftxoutraw = NULL [static]

Definition at line 360 of file chan_usbradio.c.

Referenced by radio_tune(), unload_module(), and usbradio_read().

struct ast_jb_conf global_jbconf [static]

Definition at line 199 of file chan_usbradio.c.

char key_usage[] [static]

Initial value:

   "Usage: radio key\n"
   "       Simulates COR active.\n"

Definition at line 2612 of file chan_usbradio.c.

char radio_tune_usage[] [static]

Definition at line 2628 of file chan_usbradio.c.

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

Definition at line 683 of file chan_usbradio.c.

char unkey_usage[] [static]

Initial value:

   "Usage: radio unkey\n"
   "       Simulates COR un-active.\n"

Definition at line 2616 of file chan_usbradio.c.

char* usb_device_list = NULL [static]

Definition at line 362 of file chan_usbradio.c.

Referenced by store_config(), and usb_list_check().

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.

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

int usbradio_debug [static]

Definition at line 365 of file chan_usbradio.c.

Referenced by soundcard_writeframe(), and store_config().

struct chan_usbradio_pvt usbradio_default [static]

Definition at line 625 of file chan_usbradio.c.

Referenced by find_desc(), find_desc_usb(), radio_active(), store_config(), and unload_module().

struct ast_channel_tech usbradio_tech [static]

Definition at line 685 of file chan_usbradio.c.

Referenced by load_module(), unload_module(), usbradio_new(), and usbradio_read().


Generated on Wed Apr 6 11:30:01 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7