Fri Jun 19 12:10:27 2009

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 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 MAX(a, b)   ((a) > (b) ? (a) : (b))
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
#define MIXER_PARAM_MIC_BOOST   "Auto Gain Control"
#define MIXER_PARAM_MIC_CAPTURE_SW   "Mic Capture Switch"
#define MIXER_PARAM_MIC_CAPTURE_VOL   "Mic Capture Volume"
#define MIXER_PARAM_MIC_PLAYBACK_SW   "Mic Playback Switch"
#define MIXER_PARAM_MIC_PLAYBACK_VOL   "Mic Playback Volume"
#define MIXER_PARAM_SPKR_PLAYBACK_SW   "Speaker Playback Switch"
#define MIXER_PARAM_SPKR_PLAYBACK_VOL   "Speaker Playback Volume"
#define NEW_ASTERISK
#define O_CLOSE   0x444
#define pd(x)   {printf(#x" = %d\n",x);}
#define pf(x)   {printf(#x" = %f\n",x);}
#define pp(x)   {printf(#x" = %p\n",x);}
#define ps(x)   {printf(#x" = %s\n",x);}
#define QUEUE_SIZE   2
#define QUOTECHR   34
#define READERR_THRESHOLD   50
#define RX_CAP_OUT_FILE   "/tmp/rx_cap_out.pcm"
#define RX_CAP_RAW_FILE   "/tmp/rx_cap_in.pcm"
#define RX_CAP_TRACE_FILE   "/tmp/rx_trace.pcm"
#define TEXT_SIZE   256
#define traceusb1(a)
#define traceusb2(a)
#define TX_CAP_OUT_FILE   "/tmp/tx_cap_out.pcm"
#define TX_CAP_RAW_FILE   "/tmp/tx_cap_in.pcm"
#define TX_CAP_TRACE_FILE   "/tmp/tx_trace.pcm"
#define WARN_frag   4
#define WARN_speed   2
#define WARN_used_blocks   1

Enumerations

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

Functions

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

Variables

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

#define BOOST_SCALE   (1<<9)

Definition at line 461 of file chan_usbradio.c.

#define C108_HID_INTERFACE   3

Definition at line 166 of file chan_usbradio.c.

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

#define C108_PRODUCT_ID   0x000c

Definition at line 165 of file chan_usbradio.c.

Referenced by hid_device_init(), and hid_device_mklist().

#define C108_VENDOR_ID   0x0d8c

Definition at line 164 of file chan_usbradio.c.

Referenced by hid_device_init(), and hid_device_mklist().

#define CHAN_USBRADIO   1

Definition at line 82 of file chan_usbradio.c.

#define DEBUG_CAP_RX_OUT   0

Definition at line 85 of file chan_usbradio.c.

#define DEBUG_CAP_TX_OUT   0

Definition at line 86 of file chan_usbradio.c.

#define DEBUG_CAPTURES   1

Definition at line 84 of file chan_usbradio.c.

#define DEBUG_FILETEST   0

Definition at line 87 of file chan_usbradio.c.

#define DEBUG_USBRADIO   0

Definition at line 83 of file chan_usbradio.c.

#define DELIMCHR   ','

Definition at line 105 of file chan_usbradio.c.

Referenced by finddelim().

#define DEV_DSP   "/dev/dsp"

Definition at line 351 of file chan_usbradio.c.

#define EEPROM_CS_ADDR   62

Definition at line 180 of file chan_usbradio.c.

Referenced by put_eeprom().

#define EEPROM_END_ADDR   63

Definition at line 175 of file chan_usbradio.c.

Referenced by get_eeprom().

#define EEPROM_MAGIC   34329

Definition at line 179 of file chan_usbradio.c.

Referenced by hidthread(), and put_eeprom().

#define EEPROM_MAGIC_ADDR   6

Definition at line 178 of file chan_usbradio.c.

Referenced by hidthread(), and put_eeprom().

#define EEPROM_PHYSICAL_LEN   64

Definition at line 176 of file chan_usbradio.c.

#define EEPROM_RXCTCSSADJ   13

Definition at line 185 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_RXMIXERSET   8

Definition at line 181 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_RXSQUELCHADJ   16

Definition at line 187 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_RXVOICEADJ   11

Definition at line 184 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_START_ADDR   6

Definition at line 174 of file chan_usbradio.c.

Referenced by get_eeprom(), and put_eeprom().

#define EEPROM_TEST_ADDR   EEPROM_END_ADDR

Definition at line 177 of file chan_usbradio.c.

#define EEPROM_TXCTCSSADJ   15

Definition at line 186 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_TXMIXASET   9

Definition at line 182 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

#define EEPROM_TXMIXBSET   10

Definition at line 183 of file chan_usbradio.c.

Referenced by hidthread(), and tune_write().

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

Definition at line 334 of file chan_usbradio.c.

#define FRAME_SIZE   160

Definition at line 328 of file chan_usbradio.c.

#define HID_REPORT_GET   0x01

Definition at line 168 of file chan_usbradio.c.

Referenced by hid_get_inputs().

#define HID_REPORT_SET   0x09

Definition at line 169 of file chan_usbradio.c.

Referenced by hid_set_outputs().

#define HID_RT_INPUT   0x01

Definition at line 171 of file chan_usbradio.c.

Referenced by hid_get_inputs().

#define HID_RT_OUTPUT   0x02

Definition at line 172 of file chan_usbradio.c.

Referenced by hid_set_outputs().

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

Definition at line 294 of file chan_usbradio.c.

Referenced by store_config().

#define M_END (  )     x;

Definition at line 292 of file chan_usbradio.c.

Referenced by store_config().

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

Definition at line 293 of file chan_usbradio.c.

Referenced by store_config().

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

Definition at line 290 of file chan_usbradio.c.

Referenced by store_config().

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

Definition at line 296 of file chan_usbradio.c.

Referenced by store_config().

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

Definition at line 295 of file chan_usbradio.c.

Referenced by store_config().

#define MAX ( a,
 )     ((a) > (b) ? (a) : (b))

Definition at line 358 of file chan_usbradio.c.

#define MIN ( a,
 )     ((a) < (b) ? (a) : (b))

Definition at line 355 of file chan_usbradio.c.

#define MIXER_PARAM_MIC_BOOST   "Auto Gain Control"

Definition at line 101 of file chan_usbradio.c.

Referenced by mixer_write(), and tune_rxinput().

#define MIXER_PARAM_MIC_CAPTURE_SW   "Mic Capture Switch"

Definition at line 99 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_MIC_CAPTURE_VOL   "Mic Capture Volume"

Definition at line 100 of file chan_usbradio.c.

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

#define MIXER_PARAM_MIC_PLAYBACK_SW   "Mic Playback Switch"

Definition at line 97 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_MIC_PLAYBACK_VOL   "Mic Playback Volume"

Definition at line 98 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_SPKR_PLAYBACK_SW   "Speaker Playback Switch"

Definition at line 102 of file chan_usbradio.c.

Referenced by mixer_write().

#define MIXER_PARAM_SPKR_PLAYBACK_VOL   "Speaker Playback Volume"

Definition at line 103 of file chan_usbradio.c.

Referenced by mixer_write(), and store_config().

#define NEW_ASTERISK

Definition at line 1 of file chan_usbradio.c.

#define O_CLOSE   0x444

Definition at line 346 of file chan_usbradio.c.

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

Definition at line 3162 of file chan_usbradio.c.

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

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

Definition at line 3165 of file chan_usbradio.c.

Referenced by pmrdump().

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

Definition at line 3163 of file chan_usbradio.c.

Referenced by dahdi_setoption(), get_unaligned_uint16(), get_unaligned_uint32(), put_unaligned_uint16(), put_unaligned_uint32(), sms_readfile(), st_get_mode(), st_get_refresher(), and st_get_se().

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

Definition at line 3164 of file chan_usbradio.c.

Referenced by ast_register_indication(), ast_unregister_indication(), ind_load_module(), playtones_alloc(), playtones_generator(), playtones_release(), and pmrdump().

#define QUEUE_SIZE   2

Definition at line 329 of file chan_usbradio.c.

#define QUOTECHR   34

Definition at line 106 of file chan_usbradio.c.

Referenced by finddelim().

#define READERR_THRESHOLD   50

Definition at line 108 of file chan_usbradio.c.

Referenced by usbradio_read().

#define RX_CAP_OUT_FILE   "/tmp/rx_cap_out.pcm"

Definition at line 91 of file chan_usbradio.c.

Referenced by usbradio_read().

#define RX_CAP_RAW_FILE   "/tmp/rx_cap_in.pcm"

Definition at line 89 of file chan_usbradio.c.

Referenced by radio_tune().

#define RX_CAP_TRACE_FILE   "/tmp/rx_trace.pcm"

Definition at line 90 of file chan_usbradio.c.

Referenced by radio_tune().

#define TEXT_SIZE   256

Definition at line 341 of file chan_usbradio.c.

#define traceusb1 (  ) 

Definition at line 119 of file chan_usbradio.c.

Referenced by hidthread(), and store_config().

#define traceusb2 (  ) 

Definition at line 125 of file chan_usbradio.c.

Referenced by usbradio_read(), and usbradio_write().

#define TX_CAP_OUT_FILE   "/tmp/tx_cap_out.pcm"

Definition at line 95 of file chan_usbradio.c.

Referenced by usbradio_read().

#define TX_CAP_RAW_FILE   "/tmp/tx_cap_in.pcm"

Definition at line 93 of file chan_usbradio.c.

Referenced by radio_tune().

#define TX_CAP_TRACE_FILE   "/tmp/tx_trace.pcm"

Definition at line 94 of file chan_usbradio.c.

Referenced by radio_tune().

#define WARN_frag   4

Definition at line 451 of file chan_usbradio.c.

#define WARN_speed   2

Definition at line 450 of file chan_usbradio.c.

#define WARN_used_blocks   1

Definition at line 449 of file chan_usbradio.c.


Enumeration Type Documentation

anonymous enum

Enumerator:
RX_AUDIO_NONE 
RX_AUDIO_SPEAKER 
RX_AUDIO_FLAT 

Definition at line 375 of file chan_usbradio.c.

anonymous enum

Enumerator:
CD_IGNORE 
CD_XPMR_NOISE 
CD_XPMR_VOX 
CD_HID 
CD_HID_INVERT 

Definition at line 376 of file chan_usbradio.c.

anonymous enum

Enumerator:
SD_IGNORE 
SD_HID 
SD_HID_INVERT 
SD_XPMR 

Definition at line 377 of file chan_usbradio.c.

00377 {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 378 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 379 of file chan_usbradio.c.

anonymous enum

Enumerator:
TOC_NONE 
TOC_PHASE 
TOC_NOTONE 

Definition at line 380 of file chan_usbradio.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 4034 of file chan_usbradio.c.

static void __unreg_module ( void   )  [static]

Definition at line 4034 of file chan_usbradio.c.

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

Definition at line 712 of file chan_usbradio.c.

References id, str, and type.

Referenced by store_config().

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

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

Definition at line 2270 of file chan_usbradio.c.

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

Referenced by handle_console_key().

02271 {
02272    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02273 
02274    if (argc != 2)
02275       return RESULT_SHOWUSAGE; 
02276    o->txtestkey = 1;
02277    return RESULT_SUCCESS;
02278 }

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

Definition at line 2281 of file chan_usbradio.c.

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

Referenced by handle_console_unkey().

02282 {
02283    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02284 
02285    if (argc != 2)
02286       return RESULT_SHOWUSAGE;
02287    o->txtestkey = 0;
02288    return RESULT_SUCCESS;
02289 }

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

Definition at line 1265 of file chan_usbradio.c.

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

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

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

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

01283 {
01284    struct chan_usbradio_pvt *o = NULL;
01285 
01286    if (!devstr)
01287       ast_log(LOG_WARNING, "null dev\n");
01288 
01289    for (o = usbradio_default.next; o && devstr && strcmp(o->devstr, devstr) != 0; o = o->next);
01290 
01291    return o;
01292 }

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

Definition at line 853 of file chan_usbradio.c.

References EEPROM_END_ADDR, EEPROM_START_ADDR, and read_eeprom().

Referenced by hidthread().

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

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

Definition at line 3821 of file chan_usbradio.c.

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

03823 {
03824         switch (cmd) {
03825         case CLI_INIT:
03826                 e->command = "radio key";
03827                 e->usage = key_usage;
03828                 return NULL;
03829         case CLI_GENERATE:
03830                 return NULL;
03831    }
03832    return res2cli(console_key(a->fd,a->argc,a->argv));
03833 }

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

Definition at line 3835 of file chan_usbradio.c.

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

03837 {
03838         switch (cmd) {
03839         case CLI_INIT:
03840                 e->command = "radio unkey";
03841                 e->usage = unkey_usage;
03842                 return NULL;
03843         case CLI_GENERATE:
03844                 return NULL;
03845    }
03846    return res2cli(console_unkey(a->fd,a->argc,a->argv));
03847 }

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

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

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

static char* handle_radio_debug ( 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, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, ast_cli_args::fd, radio_set_debug(), res2cli(), and ast_cli_entry::usage.

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

static char* handle_radio_debug_off ( 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_set_debug_off(), res2cli(), and ast_cli_entry::usage.

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

static char* handle_radio_tune ( 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, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, ast_cli_args::fd, radio_tune(), res2cli(), and ast_cli_entry::usage.

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

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

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

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

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

Definition at line 883 of file chan_usbradio.c.

References C108_PRODUCT_ID, C108_VENDOR_ID, and str.

Referenced by hidthread().

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

static int hid_device_mklist ( void   )  [static]

Definition at line 945 of file chan_usbradio.c.

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

Referenced by load_module().

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

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

Definition at line 814 of file chan_usbradio.c.

References C108_HID_INTERFACE, HID_REPORT_GET, and HID_RT_INPUT.

Referenced by hidthread(), and read_eeprom().

00816 {
00817    usleep(1500);
00818    usb_control_msg(handle,
00819          USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
00820          HID_REPORT_GET,
00821          0 + (HID_RT_INPUT << 8),
00822          C108_HID_INTERFACE,
00823          (char*)inputs, 4, 5000);
00824 }

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

Definition at line 802 of file chan_usbradio.c.

References C108_HID_INTERFACE, HID_REPORT_SET, and HID_RT_OUTPUT.

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

00804 {
00805    usleep(1500);
00806    usb_control_msg(handle,
00807          USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
00808          HID_REPORT_SET,
00809          0 + (HID_RT_OUTPUT << 8),
00810          C108_HID_INTERFACE,
00811          (char*)outputs, 4, 5000);
00812 }

static int hidhdwconfig ( struct chan_usbradio_pvt o  )  [static]

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

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

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

Definition at line 1118 of file chan_usbradio.c.

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

Referenced by usbradio_call().

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

static void kickptt ( struct chan_usbradio_pvt o  )  [static]

Definition at line 1106 of file chan_usbradio.c.

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

Referenced by usbradio_read().

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

static int load_module ( void   )  [static]

Definition at line 3939 of file chan_usbradio.c.

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

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

static void mixer_write ( struct chan_usbradio_pvt o  )  [static]

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

Referenced by mult_set().

03153 {
03154    const int multx=M_Q8;
03155    int pot,mult;
03156 
03157    pot=((int)(value/4)*4)+2;
03158    mult = multx-( ( multx * (3-(value%4)) ) / (pot+2) );
03159    return(mult);
03160 }

static void mult_set ( struct chan_usbradio_pvt o  )  [static]

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

03138 {
03139 
03140    if(o->pmrChan->spsTxOutA) {
03141       o->pmrChan->spsTxOutA->outputGain = 
03142          mult_calc((o->txmixaset * 152) / 1000);
03143    }
03144    if(o->pmrChan->spsTxOutB){
03145       o->pmrChan->spsTxOutB->outputGain = 
03146          mult_calc((o->txmixbset * 152) / 1000);
03147    }
03148 }

static void pmrdump ( struct chan_usbradio_pvt o  )  [static]

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

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

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

Definition at line 867 of file chan_usbradio.c.

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

Referenced by hidthread().

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

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

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

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

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

Definition at line 2563 of file chan_usbradio.c.

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

Referenced by handle_radio_debug().

02564 {
02565    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02566 
02567    o->debuglevel=1;
02568    ast_cli(fd,"usbradio debug on.\n");
02569    return RESULT_SUCCESS;
02570 }

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

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

02573 {
02574    struct chan_usbradio_pvt *o = find_desc(usbradio_active);
02575 
02576    o->debuglevel=0;
02577    ast_cli(fd,"usbradio debug off.\n");
02578    return RESULT_SUCCESS;
02579 }

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

Definition at line 2610 of file chan_usbradio.c.

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

Referenced by handle_set_xdebug().

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

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

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

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

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

Definition at line 826 of file chan_usbradio.c.

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

Referenced by get_eeprom().

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

static char* res2cli ( int  r  )  [static]

Definition at line 3807 of file chan_usbradio.c.

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

Referenced by handle_cli_cmd(), handle_cli_debug(), handle_cli_dump(), handle_cli_fun(), handle_cli_fun1(), handle_cli_local_nodes(), handle_cli_lstats(), handle_cli_nodes(), handle_cli_reload(), handle_cli_restart(), handle_cli_stats(), handle_console_key(), handle_console_unkey(), handle_radio_active(), handle_radio_debug(), handle_radio_debug_off(), handle_radio_tune(), and handle_set_xdebug().

03809 {
03810    switch (r)
03811    {
03812        case RESULT_SUCCESS:
03813       return(CLI_SUCCESS);
03814        case RESULT_SHOWUSAGE:
03815       return(CLI_SHOWUSAGE);
03816        default:
03817       return(CLI_FAILURE);
03818    }
03819 }

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

Definition at line 1692 of file chan_usbradio.c.

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

01693 {
01694 #ifndef  NEW_ASTERISK
01695    write(o->sndcmd[1], &x, sizeof(x));
01696 #endif
01697 }

static int set_txctcss_level ( struct chan_usbradio_pvt o  )  [static]

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

02539 {                      
02540    if (o->txmixa == TX_OUT_LSD)
02541    {
02542 //    o->txmixaset=(151*o->txctcssadj) / 1000;
02543       o->txmixaset=o->txctcssadj;
02544       mixer_write(o);
02545       mult_set(o);
02546    }
02547    else if (o->txmixb == TX_OUT_LSD)
02548    {
02549 //    o->txmixbset=(151*o->txctcssadj) / 1000;
02550       o->txmixbset=o->txctcssadj;
02551       mixer_write(o);
02552       mult_set(o);
02553    }
02554    else
02555    {
02556       *o->pmrChan->ptxCtcssAdjust=(o->txctcssadj * M_Q8) / 1000;
02557    }
02558    return 0;
02559 }

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

Definition at line 756 of file chan_usbradio.c.

References id, str, and type.

Referenced by mixer_write(), and tune_rxinput().

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

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

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

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

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

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

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

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

Definition at line 3412 of file chan_usbradio.c.

References amixer_max(), chan_usbradio_pvt::area, ast_calloc, ast_config_destroy(), ast_config_load, ast_dsp_new(), ast_dsp_set_digitmode(), ast_dsp_set_features(), ast_jb_read_conf(), ast_log(), ast_mutex_init(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create_background, ast_strdup, ast_tvnow(), ast_variable_browse(), chan_usbradio_pvt::autoanswer, chan_usbradio_pvt::autohangup, chan_usbradio_pvt::b, config1, chan_usbradio_pvt::ctx, chan_usbradio_pvt::dcsrxpolarity, chan_usbradio_pvt::dcstxpolarity, chan_usbradio_pvt::debuglevel, chan_usbradio_pvt::devicenum, chan_usbradio_pvt::devstr, chan_usbradio_pvt::dsp, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_MUTECONF, DSP_DIGITMODE_RELAXDTMF, DSP_FEATURE_DIGIT_DETECT, chan_usbradio_pvt::eepromctl, chan_usbradio_pvt::eepromlock, chan_usbradio_pvt::ext, find_desc_usb(), chan_usbradio_pvt::frags, free, global_jbconf, chan_usbradio_pvt::hdwtype, hidhdwconfig(), chan_usbradio_pvt::idleinterval, chan_usbradio_pvt::invertptt, chan_usbradio_pvt::language, chan_usbradio_pvt::lastopen, LOG_ERROR, LOG_NOTICE, LOG_WARNING, chan_usbradio_pvt::loopback, chan_usbradio_pvt::lsdrxpolarity, chan_usbradio_pvt::lsdtxpolarity, M_BOOL, M_END, M_F, M_START, M_STR, M_UINT, chan_usbradio_pvt::micmax, MIXER_PARAM_MIC_CAPTURE_VOL, MIXER_PARAM_SPKR_PLAYBACK_VOL, mixer_write(), chan_usbradio_pvt::mohinterpret, mult_set(), ast_variable::name, chan_usbradio_pvt::name, chan_usbradio_pvt::next, ast_variable::next, chan_usbradio_pvt::overridecontext, chan_usbradio_pvt::pmrChan, chan_usbradio_pvt::queuesize, chan_usbradio_pvt::radioactive, chan_usbradio_pvt::radioduplex, chan_usbradio_pvt::rptnum, chan_usbradio_pvt::rxboostset, chan_usbradio_pvt::rxcdtype, chan_usbradio_pvt::rxcpusaver, chan_usbradio_pvt::rxctcssadj, chan_usbradio_pvt::rxctcssfreqs, chan_usbradio_pvt::rxctcssrelax, chan_usbradio_pvt::rxdemod, chan_usbradio_pvt::rxfreq, chan_usbradio_pvt::rxmixerset, chan_usbradio_pvt::rxpolarity, chan_usbradio_pvt::rxsquelchadj, chan_usbradio_pvt::rxsqvoxadj, chan_usbradio_pvt::rxvoiceadj, s, 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().

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

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

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

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

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

Definition at line 2836 of file chan_usbradio.c.

References f, and chan_usbradio_pvt::rxctcssadj.

Referenced by store_config().

02837 {
02838    float f;
02839    sscanf(s,"%f",&f);
02840    o->rxctcssadj = f;
02841    //ast_log(LOG_WARNING, "set rxctcssadj = %f\n", f);
02842 }

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

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

02704 {
02705    if (!strcasecmp(s,"no")){
02706       o->rxdemod = RX_AUDIO_NONE;
02707    }
02708    else if (!strcasecmp(s,"speaker")){
02709       o->rxdemod = RX_AUDIO_SPEAKER;
02710    }
02711    else if (!strcasecmp(s,"flat")){
02712          o->rxdemod = RX_AUDIO_FLAT;
02713    }  
02714    else {
02715       ast_log(LOG_WARNING,"Unrecognized rxdemod parameter: %s\n",s);
02716    }
02717 
02718    //ast_log(LOG_WARNING, "set rxdemod = %s\n", s);
02719 }

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

Definition at line 2818 of file chan_usbradio.c.

References f, and chan_usbradio_pvt::rxgain.

Referenced by store_config().

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

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

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

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

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

Definition at line 2827 of file chan_usbradio.c.

References f, and chan_usbradio_pvt::rxvoiceadj.

Referenced by store_config().

02828 {
02829    float f;
02830    sscanf(s,"%f",&f);
02831    o->rxvoiceadj = f;
02832    //ast_log(LOG_WARNING, "set rxvoiceadj = %f\n", f);
02833 }

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

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

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

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

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

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

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

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

02846 {
02847    if (!strcasecmp(s,"no") || !strcasecmp(s,"TOC_NONE")){
02848       o->txtoctype = TOC_NONE;
02849    }
02850    else if (!strcasecmp(s,"phase") || !strcasecmp(s,"TOC_PHASE")){
02851       o->txtoctype = TOC_PHASE;
02852    }
02853    else if (!strcasecmp(s,"notone") || !strcasecmp(s,"TOC_NOTONE")){
02854       o->txtoctype = TOC_NOTONE;
02855    }  
02856    else {
02857       ast_log(LOG_WARNING,"Unrecognized txtoctype parameter: %s\n",s);
02858    }
02859 }

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

Definition at line 3022 of file chan_usbradio.c.

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

Referenced by radio_tune().

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

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

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

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

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

Definition at line 2956 of file chan_usbradio.c.

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

Referenced by radio_tune().

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

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

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

02863 {
02864    o->txtestkey=1;
02865    o->pmrChan->txPttIn=1;
02866    TxTestTone(o->pmrChan, 1);   // generate 1KHz tone at 7200 peak
02867    if (fd > 0) ast_cli(fd,"Tone output starting on channel %s...\n",o->name);
02868    usleep(5000000);
02869    TxTestTone(o->pmrChan, 0);
02870    if (fd > 0) ast_cli(fd,"Tone output ending on channel %s...\n",o->name);
02871    o->pmrChan->txPttIn=0;
02872    o->txtestkey=0;
02873 }

static void tune_write ( struct chan_usbradio_pvt o  )  [static]

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

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

static int unload_module ( void   )  [static]

Definition at line 3993 of file chan_usbradio.c.

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

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

static int usb_get_usbdev ( char *  devstr  )  [static]

Definition at line 1023 of file chan_usbradio.c.

References str.

Referenced by store_config().

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

static int usb_list_check ( char *  devstr  )  [static]

Definition at line 1051 of file chan_usbradio.c.

References s, and usb_device_list.

Referenced by load_module(), and store_config().

01052 {
01053 
01054 char *s = usb_device_list;
01055 
01056    if (!s) return(0);
01057    while(*s)
01058    {
01059       if (!strcasecmp(s,devstr)) return(1);
01060       s += strlen(s) + 1;
01061    }
01062    return(0);
01063 }

static int usbradio_answer ( struct ast_channel c  )  [static]

Definition at line 1716 of file chan_usbradio.c.

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

01717 {
01718 #ifndef  NEW_ASTERISK
01719    struct chan_usbradio_pvt *o = c->tech_pvt;
01720 #endif
01721 
01722    ast_setstate(c, AST_STATE_UP);
01723 #ifndef  NEW_ASTERISK
01724    o->cursound = -1;
01725    o->nosound = 0;
01726 #endif
01727    return 0;
01728 }

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

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

01703 {
01704    struct chan_usbradio_pvt *o = c->tech_pvt;
01705 
01706    o->stophid = 0;
01707    time(&o->lasthidtime);
01708    ast_pthread_create_background(&o->hidthread, NULL, hidthread, o);
01709    ast_setstate(c, AST_STATE_UP);
01710    return 0;
01711 }

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

Definition at line 1623 of file chan_usbradio.c.

01624 {
01625    return 0;
01626 }

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

Definition at line 1628 of file chan_usbradio.c.

References ast_verbose.

01629 {
01630    /* no better use for received digits than print them */
01631    ast_verbose(" << Console Received digit %c of duration %u ms >> \n", 
01632       digit, duration);
01633    return 0;
01634 }

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

Definition at line 2121 of file chan_usbradio.c.

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

02122 {
02123    struct chan_usbradio_pvt *o = newchan->tech_pvt;
02124    ast_log(LOG_WARNING,"usbradio_fixup()\n");
02125    o->owner = newchan;
02126    return 0;
02127 }

static int usbradio_hangup ( struct ast_channel c  )  [static]

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

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

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

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

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

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

Definition at line 2189 of file chan_usbradio.c.

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

Referenced by usbradio_request().

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

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

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

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

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

Definition at line 2232 of file chan_usbradio.c.

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

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

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

Definition at line 1639 of file chan_usbradio.c.

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

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

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

Definition at line 1759 of file chan_usbradio.c.

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

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

static int used_blocks ( struct chan_usbradio_pvt o  )  [static]

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

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

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

Definition at line 840 of file chan_usbradio.c.

References buf, and hid_set_outputs().

Referenced by put_eeprom().

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

static int xpmr_config ( struct chan_usbradio_pvt o  )  [static]

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

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


Variable Documentation

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

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

struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 4034 of file chan_usbradio.c.

struct ast_cli_entry cli_usbradio[] [static]

Definition at line 3920 of file chan_usbradio.c.

Referenced by load_module(), and unload_module().

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

Definition at line 361 of file chan_usbradio.c.

char* config1 = "usbradio_tune_%s.conf" [static]

Definition at line 362 of file chan_usbradio.c.

Referenced by store_config().

struct ast_jb_conf default_jbconf [static]

Global jitterbuffer configuration - by default, jb is disabled

Definition at line 190 of file chan_usbradio.c.

FILE* frxcapraw = NULL [static]

Definition at line 364 of file chan_usbradio.c.

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

FILE * frxcaptrace = NULL [static]

Definition at line 364 of file chan_usbradio.c.

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

FILE * frxoutraw = NULL [static]

Definition at line 364 of file chan_usbradio.c.

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

FILE* ftxcapraw = NULL [static]

Definition at line 365 of file chan_usbradio.c.

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

FILE * ftxcaptrace = NULL [static]

Definition at line 365 of file chan_usbradio.c.

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

FILE * ftxoutraw = NULL [static]

Definition at line 365 of file chan_usbradio.c.

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

struct ast_jb_conf global_jbconf [static]

Definition at line 197 of file chan_usbradio.c.

char key_usage[] [static]

Initial value:

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

Definition at line 2630 of file chan_usbradio.c.

char radio_tune_usage[] [static]

Definition at line 2646 of file chan_usbradio.c.

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

Definition at line 687 of file chan_usbradio.c.

char unkey_usage[] [static]

Initial value:

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

Definition at line 2634 of file chan_usbradio.c.

char* usb_device_list = NULL [static]

Definition at line 367 of file chan_usbradio.c.

Referenced by store_config(), and usb_list_check().

int usb_device_list_size = 0 [static]

Definition at line 368 of file chan_usbradio.c.

char* usbradio_active [static]

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

Referenced by soundcard_writeframe(), and store_config().

struct chan_usbradio_pvt usbradio_default [static]

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

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


Generated on Fri Jun 19 12:10:28 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7