summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorJim Dixon <telesistant@hotmail.com>2008-05-16 00:51:14 +0000
committerJim Dixon <telesistant@hotmail.com>2008-05-16 00:51:14 +0000
commit76707a409c8cce29ae8a001e3b3c1e6b43b078d0 (patch)
tree4442fe9b29cb1bfb68f9e8e538932f64de425e60 /channels
parent5168282ba1030064777679caaca672787e743975 (diff)
Bring all app_rpt and chan_usbradio stuff up to date
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@116731 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r--channels/Makefile6
-rw-r--r--channels/chan_usbradio.c3706
-rwxr-xr-xchannels/xpmr/sinetabx.h30
-rwxr-xr-xchannels/xpmr/xpmr.c2254
-rwxr-xr-xchannels/xpmr/xpmr.h620
-rwxr-xr-xchannels/xpmr/xpmr_coef.h344
6 files changed, 4834 insertions, 2126 deletions
diff --git a/channels/Makefile b/channels/Makefile
index 34bd8e092..4ceec696d 100644
--- a/channels/Makefile
+++ b/channels/Makefile
@@ -101,3 +101,9 @@ misdn/isdn_lib.o: ASTCFLAGS+=-Wno-strict-aliasing
$(if $(filter chan_misdn,$(EMBEDDED_MODS)),modules.link,chan_misdn.so): misdn_config.o misdn/isdn_lib.o misdn/isdn_msg_parser.o
$(if $(filter chan_oss,$(EMBEDDED_MODS)),modules.link,chan_oss.so): console_video.o vgrabbers.o console_board.o
+
+chan_usbradio.o: ./xpmr/xpmr.c ./xpmr/xpmr.h ./xpmr/xpmr_coef.h
+
+chan_usbradio.so: LIBS+=-lusb -lasound
+
+
diff --git a/channels/chan_usbradio.c b/channels/chan_usbradio.c
index f7c05a670..f94ccd1da 100644
--- a/channels/chan_usbradio.c
+++ b/channels/chan_usbradio.c
@@ -1,8 +1,9 @@
+#define NEW_ASTERISK
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2005, Digium, Inc.
- * Copyright (C) 2007, Jim Dixon
+ * Copyright (C) 2007 - 2008, Jim Dixon
*
* Jim Dixon, WB6NIL <jim@lambdatel.com>
* Steve Henke, W9SH <w9sh@arrl.net>
@@ -33,31 +34,47 @@
*/
/*** MODULEINFO
- <depend>asound</depend>
- <depend>usb</depend>
+ <depend>ossaudio</depend>
+ <depend>usb</depend>
<defaultenabled>no</defaultenabled>
+ <member name="RADIO_RTX" displayname="Build RTX/DTX Radio Programming">
+ <defaultenabled>no</defaultenabled>
+ </member>
+ <member name="RADIO_XPMRX" displayname="Build Experimental Radio Protocols">
+ <defaultenabled>no</defaultenabled>
+ </member>
***/
+// 20070918 1600 EDT sph@xelatec.com changing to rx driven streams
+
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+#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>
-#define CHAN_USBRADIO 1
+//#define HAVE_XPMRX 1
+#ifdef RADIO_XPMRX
+#define HAVE_XPMRX 1
+#endif
+#define CHAN_USBRADIO 1
#define DEBUG_USBRADIO 0
#define DEBUG_CAPTURES 1
-
#define DEBUG_CAP_RX_OUT 0
#define DEBUG_CAP_TX_OUT 0
-
#define DEBUG_FILETEST 0
#define RX_CAP_RAW_FILE "/tmp/rx_cap_in.pcm"
@@ -76,18 +93,27 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define MIXER_PARAM_SPKR_PLAYBACK_SW "Speaker Playback Switch"
#define MIXER_PARAM_SPKR_PLAYBACK_VOL "Speaker Playback Volume"
+#define DELIMCHR ','
+#define QUOTECHR 34
+
+#define READERR_THRESHOLD 50
+
#include "./xpmr/xpmr.h"
+#ifdef HAVE_XPMRX
+#include "./xpmrx/xpmrx.h"
+#include "./xpmrx/bitweight.h"
+#endif
#if 0
-#define traceusb1(a, ...) ast_debug(4, a __VA_ARGS__)
+#define traceusb1(a) {printf a;}
#else
-#define traceusb1(a, ...)
+#define traceusb1(a)
#endif
#if 0
-#define traceusb2(a, ...) ast_debug(4, a __VA_ARGS__)
+#define traceusb2(a) {printf a;}
#else
-#define traceusb2(a, ...)
+#define traceusb2(a)
#endif
#ifdef __linux
@@ -100,9 +126,11 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#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"
@@ -114,6 +142,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/musiconhold.h"
#include "asterisk/dsp.h"
+#ifndef NEW_ASTERISK
+
+/* ringtones we use */
+#include "busy.h"
+#include "ringtone.h"
+#include "ring10.h"
+#include "answer.h"
+
+#endif
+
#define C108_VENDOR_ID 0x0d8c
#define C108_PRODUCT_ID 0x000c
#define C108_HID_INTERFACE 3
@@ -124,6 +162,21 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#define HID_RT_INPUT 0x01
#define HID_RT_OUTPUT 0x02
+#define EEPROM_START_ADDR 6
+#define EEPROM_END_ADDR 63
+#define EEPROM_PHYSICAL_LEN 64
+#define EEPROM_TEST_ADDR EEPROM_END_ADDR
+#define EEPROM_MAGIC_ADDR 6
+#define EEPROM_MAGIC 34329
+#define EEPROM_CS_ADDR 62
+#define EEPROM_RXMIXERSET 8
+#define EEPROM_TXMIXASET 9
+#define EEPROM_TXMIXBSET 10
+#define EEPROM_RXVOICEADJ 11
+#define EEPROM_RXCTCSSADJ 13
+#define EEPROM_TXCTCSSADJ 15
+#define EEPROM_RXSQUELCHADJ 16
+
/*! Global jitterbuffer configuration - by default, jb is disabled */
static struct ast_jb_conf default_jbconf =
{
@@ -134,14 +187,15 @@ static struct ast_jb_conf default_jbconf =
};
static struct ast_jb_conf global_jbconf;
-/*!
+/*
* usbradio.conf parameters are
START_CONFIG
[general]
- ; General config options, with default values shown.
- ; You should use one section per device, with [general] being used
- ; for the device.
+ ; General config options which propigate to all devices, with
+ ; default values shown. You may have as many devices as the
+ ; system will allow. You must use one section per device, with
+ ; [usb] generally (although its up to you) being the first device.
;
;
; debug = 0x0 ; misc debug flags, default is 0
@@ -151,10 +205,11 @@ START_CONFIG
; Set hardware type here
; hdwtype=0 ; 0=limey, 1=sph
- ; rxboostset=0 ; no rx gain boost
+ ; rxboost=0 ; no rx gain boost
; rxctcssrelax=1 ; reduce talkoff from radios w/o CTCSS Tx HPF
- ; rxctcssfreq=100.0 ; rx ctcss freq in floating point. must be in table
- ; txctcssfreq=100.0 ; tx ctcss freq, any frequency permitted
+ ; rxctcssfreqs=100.0,123.0 ; list of rx ctcss freq in floating point. must be in table
+ ; txctcssfreqs=100.0,123.0 ; list tx ctcss freq, any frequency permitted
+ ; txctcssdefault=100.0 ; default tx ctcss freq, any frequency permitted
; carrierfrom=dsp ;no,usb,usbinvert,dsp,vox
; ctcssfrom=dsp ;no,usb,dsp
@@ -191,12 +246,47 @@ START_CONFIG
; jblog = no ; Enables jitterbuffer frame logging. Defaults to "no".
;-----------------------------------------------------------------------------------
+[usb]
+
+; First channel unique config
+
+[usb1]
+
+; Second channel config
END_CONFIG
*/
-/*!
+/*
+ * Helper macros to parse config arguments. They will go in a common
+ * header file if their usage is globally accepted. In the meantime,
+ * we define them here. Typical usage is as below.
+ * Remember to open a block right before M_START (as it declares
+ * some variables) and use the M_* macros WITHOUT A SEMICOLON:
+ *
+ * {
+ * M_START(v->name, v->value)
+ *
+ * M_BOOL("dothis", x->flag1)
+ * M_STR("name", x->somestring)
+ * M_F("bar", some_c_code)
+ * M_END(some_final_statement)
+ * ... other code in the block
+ * }
+ *
+ * XXX NOTE these macros should NOT be replicated in other parts of asterisk.
+ * Likely we will come up with a better way of doing config file parsing.
+ */
+#define M_START(var, val) \
+ char *__s = var; char *__val = val;
+#define M_END(x) x;
+#define M_F(tag, f) if (!strcasecmp((__s), tag)) { f; } else
+#define M_BOOL(tag, dst) M_F(tag, (dst) = ast_true(__val) )
+#define M_UINT(tag, dst) M_F(tag, (dst) = strtoul(__val, NULL, 0) )
+#define M_STR(tag, dst) M_F(tag, ast_copy_string(dst, __val, sizeof(dst)))
+
+/*
* The following parameters are used in the driver:
*
* FRAME_SIZE the size of an audio frame, in samples.
@@ -227,7 +317,7 @@ END_CONFIG
*/
#define FRAME_SIZE 160
-#define QUEUE_SIZE 20
+#define QUEUE_SIZE 2
#if defined(__FreeBSD__)
#define FRAGS 0x8
@@ -260,19 +350,22 @@ END_CONFIG
#endif
static char *config = "usbradio.conf"; /* default config file */
-static char *config1 = "usbradio_tune.conf"; /* tune config file */
+static char *config1 = "usbradio_tune_%s.conf"; /* tune config file */
static FILE *frxcapraw = NULL, *frxcaptrace = NULL, *frxoutraw = NULL;
static FILE *ftxcapraw = NULL, *ftxcaptrace = NULL, *ftxoutraw = NULL;
+static char *usb_device_list = NULL;
+static int usb_device_list_size = 0;
+
static int usbradio_debug;
-#if 0 /* maw asdf sph */
+#if 0 //maw asdf sph
static int usbradio_debug_level = 0;
#endif
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}; /* no,external,externalinvert,software */
+enum {SD_IGNORE,SD_HID,SD_HID_INVERT,SD_XPMR}; // no,external,externalinvert,software
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};
@@ -280,6 +373,34 @@ enum {TOC_NONE,TOC_PHASE,TOC_NOTONE};
/* DECLARE STRUCTURES */
/*
+ * Each sound is made of 'datalen' samples of sound, repeated as needed to
+ * generate 'samplen' samples of data, then followed by 'silencelen' samples
+ * of silence. The loop is repeated if 'repeat' is set.
+ */
+struct sound {
+ int ind;
+ char *desc;
+ short *data;
+ int datalen;
+ int samplen;
+ int silencelen;
+ int repeat;
+};
+
+#ifndef NEW_ASTERISK
+
+static struct sound sounds[] = {
+ { AST_CONTROL_RINGING, "RINGING", ringtone, sizeof(ringtone)/2, 16000, 32000, 1 },
+ { AST_CONTROL_BUSY, "BUSY", busy, sizeof(busy)/2, 4000, 4000, 1 },
+ { AST_CONTROL_CONGESTION, "CONGESTION", busy, sizeof(busy)/2, 2000, 2000, 1 },
+ { AST_CONTROL_RING, "RING10", ring10, sizeof(ring10)/2, 16000, 32000, 1 },
+ { AST_CONTROL_ANSWER, "ANSWER", answer, sizeof(answer)/2, 2200, 0, 0 },
+ { -1, NULL, 0, 0, 0, 0 }, /* end marker */
+};
+
+#endif
+
+/*
* descriptor for one of our channels.
* There is one used for 'default' values (from the [general] entry in
* the configuration file), and then one instance for each device
@@ -290,8 +411,22 @@ struct chan_usbradio_pvt {
struct chan_usbradio_pvt *next;
char *name;
+#ifndef NEW_ASTERISK
+ /*
+ * cursound indicates which in struct sound we play. -1 means nothing,
+ * any other value is a valid sound, in which case sampsent indicates
+ * the next sample to send in [0..samplen + silencelen]
+ * nosound is set to disable the audio data from the channel
+ * (so we can play the tones etc.).
+ */
+ int sndcmd[2]; /* Sound command pipe */
+ int cursound; /* index of sound to send */
+ int sampsent; /* # of sound samples sent */
+ int nosound; /* set to block audio from the PBX */
+#endif
- int total_blocks; /* total blocks in the output device */
+ int pttkick[2];
+ int total_blocks; /* total blocks in the output device */
int sounddev;
enum { M_UNSET, M_FULL, M_READ, M_WRITE } duplex;
i16 cdMethod;
@@ -301,11 +436,11 @@ struct chan_usbradio_pvt {
unsigned int queuesize; /* max fragments in queue */
unsigned int frags; /* parameter for SETFRAGMENT */
- int warned; /* various flags used for warnings */
+ int warned; /* various flags used for warnings */
#define WARN_used_blocks 1
#define WARN_speed 2
#define WARN_frag 4
- int w_errors; /* overfull in the write path */
+ int w_errors; /* overfull in the write path */
struct timeval lastopen;
int overridecontext;
@@ -315,109 +450,178 @@ struct chan_usbradio_pvt {
* be representable in 16 bits to avoid overflows.
*/
#define BOOST_SCALE (1<<9)
-#define BOOST_MAX 40 /* slightly less than 7 bits */
- int boost; /* input boost, scaled by BOOST_SCALE */
+#define BOOST_MAX 40 /* slightly less than 7 bits */
+ int boost; /* input boost, scaled by BOOST_SCALE */
char devicenum;
+ char devstr[128];
int spkrmax;
int micmax;
+#ifndef NEW_ASTERISK
pthread_t sthread;
+#endif
pthread_t hidthread;
- int stophid;
+ int stophid;
+ FILE *hkickhid;
+
struct ast_channel *owner;
- char ext[AST_MAX_EXTENSION];
- char ctx[AST_MAX_CONTEXT];
- char language[MAX_LANGUAGE];
- char cid_name[256]; /* XXX */
- char cid_num[256]; /* XXX */
- char mohinterpret[MAX_MUSICCLASS];
+ char ext[AST_MAX_EXTENSION];
+ char ctx[AST_MAX_CONTEXT];
+ char language[MAX_LANGUAGE];
+ char cid_name[256]; /*XXX */
+ char cid_num[256]; /*XXX */
+ char mohinterpret[MAX_MUSICCLASS];
/* buffers used in usbradio_write, 2 per int by 2 channels by 6 times oversampling (48KS/s) */
- char usbradio_write_buf[FRAME_SIZE * 2 * 2 * 6];
- char usbradio_write_buf_1[FRAME_SIZE * 2 * 2 * 6];
+ char usbradio_write_buf[FRAME_SIZE * 2 * 2 * 6];
+ char usbradio_write_buf_1[FRAME_SIZE * 2 * 2* 6];
- int usbradio_write_dst;
+ int usbradio_write_dst;
/* buffers used in usbradio_read - AST_FRIENDLY_OFFSET space for headers
* plus enough room for a full frame
*/
- char usbradio_read_buf[FRAME_SIZE * (2 * 12) + AST_FRIENDLY_OFFSET];
- char usbradio_read_buf_8k[FRAME_SIZE * 2 + AST_FRIENDLY_OFFSET];
- int readpos; /* read position above */
- struct ast_frame read_f; /* returned by usbradio_read */
-
+ char usbradio_read_buf[FRAME_SIZE * (2 * 12) + AST_FRIENDLY_OFFSET];
+ char usbradio_read_buf_8k[FRAME_SIZE * 2 + AST_FRIENDLY_OFFSET];
+ int readpos; /* read position above */
+ struct ast_frame read_f; /* returned by usbradio_read */
+
+ char debuglevel;
+ char radioduplex; //
+ char wanteeprom;
+
+ int tracetype;
+ int tracelevel;
+ char area;
+ char rptnum;
+ int idleinterval;
+ int turnoffs;
+ int txsettletime;
+ char ukey[48];
+
+ char lastrx;
+ char rxhidsq;
+ char rxcarrierdetect; // status from pmr channel
+ char rxctcssdecode; // status from pmr channel
+
+ int rxdcsdecode;
+ int rxlsddecode;
+
+ char rxkeytype;
+ char rxkeyed; // indicates rx signal present
+
+ char lasttx;
+ char txkeyed; // tx key request from upper layers
+ char txchankey;
+ char txtestkey;
+
+ time_t lasthidtime;
+ struct ast_dsp *dsp;
- char debuglevel;
- char radioduplex;
+ t_pmr_chan *pmrChan;
- char lastrx;
- char rxhidsq;
- char rxcarrierdetect; /*!< status from pmr channel */
- char rxctcssdecode; /*!< status from pmr channel */
+ char rxcpusaver;
+ char txcpusaver;
- char rxkeytype;
- char rxkeyed; /*!< indicates rx signal present */
+ char rxdemod;
+ float rxgain;
+ char rxcdtype;
+ char rxsdtype;
+ int rxsquelchadj; /* this copy needs to be here for initialization */
+ int rxsqvoxadj;
+ char txtoctype;
- char lasttx;
- char txkeyed; /*! tx key request from upper layers */
- char txchankey;
- char txtestkey;
+ char txprelim;
+ float txctcssgain;
+ char txmixa;
+ char txmixb;
- time_t lasthidtime;
- struct ast_dsp *dsp;
+ char invertptt;
- t_pmr_chan *pmrChan;
+ char rxctcssrelax;
+ float rxctcssgain;
- char rxcpusaver;
- char txcpusaver;
+ char txctcssdefault[16]; // for repeater operation
+ char rxctcssfreqs[512]; // a string
+ char txctcssfreqs[512];
- char rxdemod;
- float rxgain;
- char rxcdtype;
- char rxsdtype;
- int rxsquelchadj; /*!< this copy needs to be here for initialization */
- char txtoctype;
+ char txctcssfreq[32]; // encode now
+ char rxctcssfreq[32]; // decode now
- char txprelim;
- float txctcssgain;
- char txmixa;
- char txmixb;
-
- char invertptt;
-
- char rxctcssrelax;
- float rxctcssgain;
- float rxctcssfreq;
- float txctcssfreq;
-
- int rxmixerset;
- int rxboostset;
- float rxvoiceadj;
- float rxctcssadj;
- int txmixaset;
- int txmixbset;
+ char numrxctcssfreqs; // how many
+ char numtxctcssfreqs;
+
+ char *rxctcss[CTCSS_NUM_CODES]; // pointers to strings
+ char *txctcss[CTCSS_NUM_CODES];
+
+ int txfreq; // in Hz
+ int rxfreq;
+
+ // start remote operation info
+ char set_txctcssdefault[16]; // for remote operation
+ char set_txctcssfreq[16]; // encode now
+ char set_rxctcssfreq[16]; // decode now
+
+ char set_numrxctcssfreqs; // how many
+ char set_numtxctcssfreqs;
+
+ char set_rxctcssfreqs[16]; // a string
+ char set_txctcssfreqs[16];
+
+ char *set_rxctcss; // pointers to strings
+ char *set_txctcss;
+
+ int set_txfreq; // in Hz
+ int set_rxfreq;
+ // end remote operation info
+
+ int rxmixerset;
+ int rxboostset;
+ float rxvoiceadj;
+ float rxctcssadj;
+ int txmixaset;
+ int txmixbset;
int txctcssadj;
int hdwtype;
- int hid_gpio_ctl;
- int hid_gpio_ctl_loc;
- int hid_io_cor;
- int hid_io_cor_loc;
- int hid_io_ctcss;
- int hid_io_ctcss_loc;
- int hid_io_ptt;
- int hid_gpio_loc;
+ int hid_gpio_ctl;
+ int hid_gpio_ctl_loc;
+ int hid_io_cor;
+ int hid_io_cor_loc;
+ int hid_io_ctcss;
+ int hid_io_ctcss_loc;
+ int hid_io_ptt;
+ int hid_gpio_loc;
struct {
- unsigned rxcapraw:1;
+ unsigned rxcapraw:1;
unsigned txcapraw:1;
unsigned txcap2:1;
unsigned rxcap2:1;
- } b;
+ unsigned rxplmon:1;
+ unsigned remoted:1;
+ unsigned txpolarity:1;
+ unsigned rxpolarity:1;
+ unsigned dcstxpolarity:1;
+ unsigned dcsrxpolarity:1;
+ unsigned lsdtxpolarity:1;
+ unsigned lsdrxpolarity:1;
+ unsigned loopback:1;
+ unsigned radioactive:1;
+ }b;
+ unsigned short eeprom[EEPROM_PHYSICAL_LEN];
+ char eepromctl;
+ ast_mutex_t eepromlock;
+
+ struct usb_dev_handle *usb_handle;
+ int readerrs;
};
-/* maw add additional defaults !!! */
+// maw add additional defaults !!!
static struct chan_usbradio_pvt usbradio_default = {
+#ifndef NEW_ASTERISK
+ .cursound = -1,
+#endif
.sounddev = -1,
.duplex = M_UNSET, /* XXX check this */
.autoanswer = 1,
@@ -429,26 +633,29 @@ static struct chan_usbradio_pvt usbradio_default = {
.readpos = AST_FRIENDLY_OFFSET, /* start here on reads */
.lastopen = { 0, 0 },
.boost = BOOST_SCALE,
+ .wanteeprom = 1,
+ .area = 0,
+ .rptnum = 0,
};
/* DECLARE FUNCTION PROTOTYPES */
-static void store_txtoctype(struct chan_usbradio_pvt *o, const char *s);
-static int hidhdwconfig(struct chan_usbradio_pvt *o);
-static int set_txctcss_level(struct chan_usbradio_pvt *o);
+static void store_txtoctype(struct chan_usbradio_pvt *o, char *s);
+static int hidhdwconfig(struct chan_usbradio_pvt *o);
+static int set_txctcss_level(struct chan_usbradio_pvt *o);
static void pmrdump(struct chan_usbradio_pvt *o);
static void mult_set(struct chan_usbradio_pvt *o);
static int mult_calc(int value);
static void mixer_write(struct chan_usbradio_pvt *o);
-static void tune_rxinput(struct chan_usbradio_pvt *o);
-static void tune_rxvoice(struct chan_usbradio_pvt *o);
-static void tune_rxctcss(struct chan_usbradio_pvt *o);
-static void tune_txoutput(struct chan_usbradio_pvt *o, int value);
+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_rxctcss(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 char *usbradio_active; /* the active device */
-static int setformat(struct chan_usbradio_pvt *o, int mode);
+static int setformat(struct chan_usbradio_pvt *o, int mode);
static struct ast_channel *usbradio_request(const char *type, int format, void *data
, int *cause);
@@ -462,6 +669,7 @@ static int usbradio_call(struct ast_channel *c, char *dest, int timeout);
static int usbradio_write(struct ast_channel *chan, struct ast_frame *f);
static int usbradio_indicate(struct ast_channel *chan, int cond, const void *data, size_t datalen);
static int usbradio_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
+static int xpmr_config(struct chan_usbradio_pvt *o);
#if DEBUG_FILETEST == 1
static int RxTestIt(struct chan_usbradio_pvt *o);
@@ -494,36 +702,35 @@ Note: must add -lasound to end of linkage */
static int amixer_max(int devnum,char *param)
{
- int rv,type;
- char str[15];
- snd_hctl_t *hctl;
- snd_ctl_elem_id_t *id;
- snd_hctl_elem_t *elem;
- snd_ctl_elem_info_t *info;
-
- snprintf(str, sizeof(str), "hw:%d", devnum);
- if (snd_hctl_open(&hctl, str, 0))
- return -1;
+int rv,type;
+char str[100];
+snd_hctl_t *hctl;
+snd_ctl_elem_id_t *id;
+snd_hctl_elem_t *elem;
+snd_ctl_elem_info_t *info;
+
+ sprintf(str,"hw:%d",devnum);
+ if (snd_hctl_open(&hctl, str, 0)) return(-1);
snd_hctl_load(hctl);
- id = alloca(snd_ctl_elem_id_sizeof());
- memset(id, 0, snd_ctl_elem_id_sizeof());
+ snd_ctl_elem_id_alloca(&id);
snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
snd_ctl_elem_id_set_name(id, param);
elem = snd_hctl_find_elem(hctl, id);
- if (!elem) {
+ if (!elem)
+ {
snd_hctl_close(hctl);
- return -1;
+ return(-1);
}
- info = alloca(snd_ctl_elem_info_sizeof());
- memset(info, 0, snd_ctl_elem_info_sizeof());
+ snd_ctl_elem_info_alloca(&info);
snd_hctl_elem_info(elem,info);
type = snd_ctl_elem_info_get_type(info);
rv = 0;
- switch (type) {
- case SND_CTL_ELEM_TYPE_INTEGER:
+ switch(type)
+ {
+ case SND_CTL_ELEM_TYPE_INTEGER:
rv = snd_ctl_elem_info_get_max(info);
break;
- case SND_CTL_ELEM_TYPE_BOOLEAN:
+ case SND_CTL_ELEM_TYPE_BOOLEAN:
rv = 1;
break;
}
@@ -531,205 +738,515 @@ static int amixer_max(int devnum,char *param)
return(rv);
}
-/*! \brief Call with: devnum: alsa major device number, param: ascii Formal
+/* Call with: devnum: alsa major device number, param: ascii Formal
Parameter Name, val1, first or only value, val2 second value, or 0
if only 1 value. Values: 0-99 (percent) or 0-1 for baboon.
Note: must add -lasound to end of linkage */
-static int setamixer(int devnum, char *param, int v1, int v2)
+static int setamixer(int devnum,char *param, int v1, int v2)
{
- int type;
- char str[15];
- snd_hctl_t *hctl;
- snd_ctl_elem_id_t *id;
- snd_ctl_elem_value_t *control;
- snd_hctl_elem_t *elem;
- snd_ctl_elem_info_t *info;
-
- snprintf(str, sizeof(str), "hw:%d", devnum);
- if (snd_hctl_open(&hctl, str, 0))
- return -1;
+int type;
+char str[100];
+snd_hctl_t *hctl;
+snd_ctl_elem_id_t *id;
+snd_ctl_elem_value_t *control;
+snd_hctl_elem_t *elem;
+snd_ctl_elem_info_t *info;
+
+ sprintf(str,"hw:%d",devnum);
+ if (snd_hctl_open(&hctl, str, 0)) return(-1);
snd_hctl_load(hctl);
- id = alloca(snd_ctl_elem_id_sizeof());
- memset(id, 0, snd_ctl_elem_id_sizeof());
+ snd_ctl_elem_id_alloca(&id);
snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
snd_ctl_elem_id_set_name(id, param);
elem = snd_hctl_find_elem(hctl, id);
- if (!elem) {
+ if (!elem)
+ {
snd_hctl_close(hctl);
- return -1;
+ return(-1);
}
- info = alloca(snd_ctl_elem_info_sizeof());
- memset(info, 0, snd_ctl_elem_info_sizeof());
+ snd_ctl_elem_info_alloca(&info);
snd_hctl_elem_info(elem,info);
type = snd_ctl_elem_info_get_type(info);
- control = alloca(snd_ctl_elem_value_sizeof());
- memset(control, 0, snd_ctl_elem_value_sizeof());
+ snd_ctl_elem_value_alloca(&control);
snd_ctl_elem_value_set_id(control, id);
- switch (type) {
- case SND_CTL_ELEM_TYPE_INTEGER:
+ switch(type)
+ {
+ case SND_CTL_ELEM_TYPE_INTEGER:
snd_ctl_elem_value_set_integer(control, 0, v1);
if (v2 > 0) snd_ctl_elem_value_set_integer(control, 1, v2);
break;
- case SND_CTL_ELEM_TYPE_BOOLEAN:
+ case SND_CTL_ELEM_TYPE_BOOLEAN:
snd_ctl_elem_value_set_integer(control, 0, (v1 != 0));
break;
}
- if (snd_hctl_elem_write(elem, control)) {
+ if (snd_hctl_elem_write(elem, control))
+ {
snd_hctl_close(hctl);
return(-1);
}
snd_hctl_close(hctl);
- return 0;
+ return(0);
}
static void hid_set_outputs(struct usb_dev_handle *handle,
unsigned char *outputs)
{
+ usleep(1500);
usb_control_msg(handle,
- USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
- HID_REPORT_SET,
- 0 + (HID_RT_OUTPUT << 8),
- C108_HID_INTERFACE,
- (char *)outputs, 4, 5000);
+ USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
+ HID_REPORT_SET,
+ 0 + (HID_RT_OUTPUT << 8),
+ C108_HID_INTERFACE,
+ (char*)outputs, 4, 5000);
}
static void hid_get_inputs(struct usb_dev_handle *handle,
unsigned char *inputs)
{
+ usleep(1500);
usb_control_msg(handle,
- USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
- HID_REPORT_GET,
- 0 + (HID_RT_INPUT << 8),
- C108_HID_INTERFACE,
- (char *)inputs, 4, 5000);
+ USB_ENDPOINT_IN + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
+ HID_REPORT_GET,
+ 0 + (HID_RT_INPUT << 8),
+ C108_HID_INTERFACE,
+ (char*)inputs, 4, 5000);
}
-static struct usb_device *hid_device_init(void)
+static unsigned short read_eeprom(struct usb_dev_handle *handle, int addr)
{
- struct usb_bus *usb_bus;
- struct usb_device *dev;
+ unsigned char buf[4];
- usb_init();
- usb_find_busses();
- usb_find_devices();
- for (usb_bus = usb_busses; usb_bus; usb_bus = usb_bus->next) {
- for (dev = usb_bus->devices; dev; dev = dev->next) {
- if ((dev->descriptor.idVendor == C108_VENDOR_ID) && (dev->descriptor.idProduct == C108_PRODUCT_ID))
- return dev;
- }
+ buf[0] = 0x80;
+ buf[1] = 0;
+ buf[2] = 0;
+ buf[3] = 0x80 | (addr & 0x3f);
+ hid_set_outputs(handle,buf);
+ memset(buf,0,sizeof(buf));
+ hid_get_inputs(handle,buf);
+ return(buf[1] + (buf[2] << 8));
+}
+
+static void write_eeprom(struct usb_dev_handle *handle, int addr,
+ unsigned short data)
+{
+
+ unsigned char buf[4];
+
+ buf[0] = 0x80;
+ buf[1] = data & 0xff;
+ buf[2] = data >> 8;
+ buf[3] = 0xc0 | (addr & 0x3f);
+ hid_set_outputs(handle,buf);
+}
+
+static unsigned short get_eeprom(struct usb_dev_handle *handle,
+ unsigned short *buf)
+{
+int i;
+unsigned short cs;
+
+ cs = 0xffff;
+ for(i = EEPROM_START_ADDR; i < EEPROM_END_ADDR; i++)
+ {
+ cs += buf[i] = read_eeprom(handle,i);
}
- return NULL;
+ return(cs);
}
-static int hidhdwconfig(struct chan_usbradio_pvt *o)
-{
- if (o->hdwtype == 1) { /*sphusb */
- o->hid_gpio_ctl = 0x08; /* set GPIO4 to output mode */
- o->hid_gpio_ctl_loc = 2; /* For CTL of GPIO */
- o->hid_io_cor = 4; /* GPIO3 is COR */
- o->hid_io_cor_loc = 1; /* GPIO3 is COR */
- o->hid_io_ctcss = 2; /* GPIO 2 is External CTCSS */
- o->hid_io_ctcss_loc = 1; /* is GPIO 2 */
- o->hid_io_ptt = 8; /* GPIO 4 is PTT */
- o->hid_gpio_loc = 1; /* For ALL GPIO */
- } else if (o->hdwtype == 0) { /* dudeusb */
- o->hid_gpio_ctl = 0x0c;/* set GPIO 3 & 4 to output mode */
- o->hid_gpio_ctl_loc = 2; /* For CTL of GPIO */
- o->hid_io_cor = 2; /* VOLD DN is COR */
- o->hid_io_cor_loc = 0; /* VOL DN COR */
- o->hid_io_ctcss = 2; /* GPIO 2 is External CTCSS */
- o->hid_io_ctcss_loc = 1; /* is GPIO 2 */
- o->hid_io_ptt = 4; /* GPIO 3 is PTT */
- o->hid_gpio_loc = 1; /* For ALL GPIO */
- } else if (o->hdwtype == 3) { /* custom version */
- o->hid_gpio_ctl = 0x0c; /* set GPIO 3 & 4 to output mode */
- o->hid_gpio_ctl_loc = 2; /* For CTL of GPIO */
- o->hid_io_cor = 2; /* VOLD DN is COR */
- o->hid_io_cor_loc = 0; /* VOL DN COR */
- o->hid_io_ctcss = 2; /* GPIO 2 is External CTCSS */
- o->hid_io_ctcss_loc = 1; /* is GPIO 2 */
- o->hid_io_ptt = 4; /* GPIO 3 is PTT */
- o->hid_gpio_loc = 1; /* For ALL GPIO */
+static void put_eeprom(struct usb_dev_handle *handle,unsigned short *buf)
+{
+int i;
+unsigned short cs;
+
+ cs = 0xffff;
+ buf[EEPROM_MAGIC_ADDR] = EEPROM_MAGIC;
+ for(i = EEPROM_START_ADDR; i < EEPROM_CS_ADDR; i++)
+ {
+ write_eeprom(handle,i,buf[i]);
+ cs += buf[i];
+ }
+ buf[EEPROM_CS_ADDR] = (65535 - cs) + 1;
+ write_eeprom(handle,i,buf[EEPROM_CS_ADDR]);
+}
+
+static struct usb_device *hid_device_init(char *desired_device)
+{
+ struct usb_bus *usb_bus;
+ struct usb_device *dev;
+ char devstr[200],str[200],desdev[200],*cp;
+ int i;
+ FILE *fp;
+
+ usb_init();
+ usb_find_busses();
+ usb_find_devices();
+ for (usb_bus = usb_busses;
+ usb_bus;
+ usb_bus = usb_bus->next) {
+ for (dev = usb_bus->devices;
+ dev;
+ dev = dev->next) {
+ if ((dev->descriptor.idVendor
+ == C108_VENDOR_ID) &&
+ (dev->descriptor.idProduct
+ == C108_PRODUCT_ID))
+ {
+ sprintf(devstr,"%s/%s", usb_bus->dirname,dev->filename);
+ for(i = 0; i < 32; i++)
+ {
+ sprintf(str,"/proc/asound/card%d/usbbus",i);
+ fp = fopen(str,"r");
+ if (!fp) continue;
+ if ((!fgets(desdev,sizeof(desdev) - 1,fp)) || (!desdev[0]))
+ {
+ fclose(fp);
+ continue;
+ }
+ fclose(fp);
+ if (desdev[strlen(desdev) - 1] == '\n')
+ desdev[strlen(desdev) -1 ] = 0;
+ if (strcasecmp(desdev,devstr)) continue;
+ if (i) sprintf(str,"/sys/class/sound/dsp%d/device",i);
+ else strcpy(str,"/sys/class/sound/dsp/device");
+ memset(desdev,0,sizeof(desdev));
+ if (readlink(str,desdev,sizeof(desdev) - 1) == -1)
+ {
+ sprintf(str,"/sys/class/sound/controlC%d/device",i);
+ memset(desdev,0,sizeof(desdev));
+ if (readlink(str,desdev,sizeof(desdev) - 1) == -1) continue;
+ }
+ cp = strrchr(desdev,'/');
+ if (cp) *cp = 0; else continue;
+ cp = strrchr(desdev,'/');
+ if (!cp) continue;
+ cp++;
+ break;
+ }
+ if (i >= 32) continue;
+ if (!strcmp(cp,desired_device)) return dev;
+ }
+
+ }
+ }
+ return NULL;
+}
+
+static int hid_device_mklist(void)
+{
+ struct usb_bus *usb_bus;
+ struct usb_device *dev;
+ char devstr[200],str[200],desdev[200],*cp;
+ int i;
+ FILE *fp;
+
+ usb_device_list = ast_malloc(2);
+ if (!usb_device_list) return -1;
+ memset(usb_device_list,0,2);
+
+ usb_init();
+ usb_find_busses();
+ usb_find_devices();
+ for (usb_bus = usb_busses;
+ usb_bus;
+ usb_bus = usb_bus->next) {
+ for (dev = usb_bus->devices;
+ dev;
+ dev = dev->next) {
+ if ((dev->descriptor.idVendor
+ == C108_VENDOR_ID) &&
+ (dev->descriptor.idProduct
+ == C108_PRODUCT_ID))
+ {
+ sprintf(devstr,"%s/%s", usb_bus->dirname,dev->filename);
+ for(i = 0;i < 32; i++)
+ {
+ sprintf(str,"/proc/asound/card%d/usbbus",i);
+ fp = fopen(str,"r");
+ if (!fp) continue;
+ if ((!fgets(desdev,sizeof(desdev) - 1,fp)) || (!desdev[0]))
+ {
+ fclose(fp);
+ continue;
+ }
+ fclose(fp);
+ if (desdev[strlen(desdev) - 1] == '\n')
+ desdev[strlen(desdev) -1 ] = 0;
+ if (strcasecmp(desdev,devstr)) continue;
+ if (i) sprintf(str,"/sys/class/sound/dsp%d/device",i);
+ else strcpy(str,"/sys/class/sound/dsp/device");
+ memset(desdev,0,sizeof(desdev));
+ if (readlink(str,desdev,sizeof(desdev) - 1) == -1)
+ {
+ sprintf(str,"/sys/class/sound/controlC%d/device",i);
+ memset(desdev,0,sizeof(desdev));
+ if (readlink(str,desdev,sizeof(desdev) - 1) == -1) continue;
+ }
+ cp = strrchr(desdev,'/');
+ if (cp) *cp = 0; else continue;
+ cp = strrchr(desdev,'/');
+ if (!cp) continue;
+ cp++;
+ break;
+ }
+ if (i >= 32) return -1;
+ usb_device_list = ast_realloc(usb_device_list,
+ usb_device_list_size + 2 +
+ strlen(cp));
+ if (!usb_device_list) return -1;
+ usb_device_list_size += strlen(cp) + 2;
+ i = 0;
+ while(usb_device_list[i])
+ {
+ i += strlen(usb_device_list + i) + 1;
+ }
+ strcat(usb_device_list + i,cp);
+ usb_device_list[strlen(cp) + i + 1] = 0;
+ }
+
+ }
+ }
+ return 0;
+}
+
+/* returns internal formatted string from external one */
+static int usb_get_usbdev(char *devstr)
+{
+int i;
+char str[200],desdev[200],*cp;
+
+ for(i = 0;i < 32; i++)
+ {
+ if (i) sprintf(str,"/sys/class/sound/dsp%d/device",i);
+ else strcpy(str,"/sys/class/sound/dsp/device");
+ memset(desdev,0,sizeof(desdev));
+ if (readlink(str,desdev,sizeof(desdev) - 1) == -1)
+ {
+ sprintf(str,"/sys/class/sound/controlC%d/device",i);
+ memset(desdev,0,sizeof(desdev));
+ if (readlink(str,desdev,sizeof(desdev) - 1) == -1) continue;
+ }
+ cp = strrchr(desdev,'/');
+ if (cp) *cp = 0; else continue;
+ cp = strrchr(desdev,'/');
+ if (!cp) continue;
+ cp++;
+ if (!strcasecmp(cp,devstr)) break;
}
+ if (i >= 32) return -1;
+ return i;
- return 0;
}
+static int usb_list_check(char *devstr)
+{
+
+char *s = usb_device_list;
+ if (!s) return(0);
+ while(*s)
+ {
+ if (!strcasecmp(s,devstr)) return(1);
+ s += strlen(s) + 1;
+ }
+ return(0);
+}
+
+
+static int hidhdwconfig(struct chan_usbradio_pvt *o)
+{
+ if(o->hdwtype==1) //sphusb
+ {
+ o->hid_gpio_ctl = 0x08; /* set GPIO4 to output mode */
+ o->hid_gpio_ctl_loc = 2; /* For CTL of GPIO */
+ o->hid_io_cor = 4; /* GPIO3 is COR */
+ o->hid_io_cor_loc = 1; /* GPIO3 is COR */
+ o->hid_io_ctcss = 2; /* GPIO 2 is External CTCSS */
+ o->hid_io_ctcss_loc = 1; /* is GPIO 2 */
+ o->hid_io_ptt = 8; /* GPIO 4 is PTT */
+ o->hid_gpio_loc = 1; /* For ALL GPIO */
+ }
+ else if(o->hdwtype==0) //dudeusb
+ {
+ o->hid_gpio_ctl = 0x0c; /* set GPIO 3 & 4 to output mode */
+ o->hid_gpio_ctl_loc = 2; /* For CTL of GPIO */
+ o->hid_io_cor = 2; /* VOLD DN is COR */
+ o->hid_io_cor_loc = 0; /* VOL DN COR */
+ o->hid_io_ctcss = 2; /* GPIO 2 is External CTCSS */
+ o->hid_io_ctcss_loc = 1; /* is GPIO 2 */
+ o->hid_io_ptt = 4; /* GPIO 3 is PTT */
+ o->hid_gpio_loc = 1; /* For ALL GPIO */
+ }
+ else if(o->hdwtype==3) // custom version
+ {
+ o->hid_gpio_ctl = 0x0c; /* set GPIO 3 & 4 to output mode */
+ o->hid_gpio_ctl_loc = 2; /* For CTL of GPIO */
+ o->hid_io_cor = 2; /* VOLD DN is COR */
+ o->hid_io_cor_loc = 0; /* VOL DN COR */
+ o->hid_io_ctcss = 2; /* GPIO 2 is External CTCSS */
+ o->hid_io_ctcss_loc = 1; /* is GPIO 2 */
+ o->hid_io_ptt = 4; /* GPIO 3 is PTT */
+ o->hid_gpio_loc = 1; /* For ALL GPIO */
+ }
+
+ return 0;
+}
+/*
+*/
+static void kickptt(struct chan_usbradio_pvt *o)
+{
+ char c = 0;
+ //printf("kickptt %i %i %i\n",o->txkeyed,o->txchankey,o->txtestkey);
+ if (!o) return;
+ if (!o->pttkick) return;
+ write(o->pttkick[1],&c,1);
+}
+/*
+*/
static void *hidthread(void *arg)
{
- unsigned char buf[4], keyed;
+ unsigned char buf[4],bufsave[4],keyed;
char lastrx, txtmp;
+ int res;
struct usb_device *usb_dev;
struct usb_dev_handle *usb_handle;
- struct chan_usbradio_pvt *o = arg;
+ struct chan_usbradio_pvt *o = (struct chan_usbradio_pvt *) arg;
+ struct timeval to;
+ fd_set rfds;
- usb_dev = hid_device_init();
+ usb_dev = hid_device_init(o->devstr);
if (usb_dev == NULL) {
- ast_log(LOG_ERROR, "USB HID device not found\n");
+ ast_log(LOG_ERROR,"USB HID device not found\n");
pthread_exit(NULL);
}
usb_handle = usb_open(usb_dev);
if (usb_handle == NULL) {
- ast_log(LOG_ERROR, "Not able to open USB device\n");
+ ast_log(LOG_ERROR,"Not able to open USB device\n");
pthread_exit(NULL);
}
- if (usb_claim_interface(usb_handle, C108_HID_INTERFACE) < 0) {
- if (usb_detach_kernel_driver_np(usb_handle, C108_HID_INTERFACE) < 0) {
- ast_log(LOG_ERROR, "Not able to detach the USB device\n");
+ if (usb_claim_interface(usb_handle,C108_HID_INTERFACE) < 0)
+ {
+ if (usb_detach_kernel_driver_np(usb_handle,C108_HID_INTERFACE) < 0) {
+ ast_log(LOG_ERROR,"Not able to detach the USB device\n");
pthread_exit(NULL);
}
- if (usb_claim_interface(usb_handle, C108_HID_INTERFACE) < 0) {
- ast_log(LOG_ERROR, "Not able to claim the USB device\n");
+ if (usb_claim_interface(usb_handle,C108_HID_INTERFACE) < 0) {
+ ast_log(LOG_ERROR,"Not able to claim the USB device\n");
pthread_exit(NULL);
}
}
- memset(buf, 0, sizeof(buf));
+ memset(buf,0,sizeof(buf));
buf[2] = o->hid_gpio_ctl;
buf[1] = 0;
- hid_set_outputs(usb_handle, buf);
- traceusb1("hidthread: Starting normally!!\n");
+ hid_set_outputs(usb_handle,buf);
+ memcpy(bufsave,buf,sizeof(buf));
+ if (pipe(o->pttkick) == -1)
+ {
+ ast_log(LOG_ERROR,"Not able to create pipe\n");
+ pthread_exit(NULL);
+ }
+ traceusb1(("hidthread: Starting normally on %s!!\n",o->name));
lastrx = 0;
- while (!o->stophid) {
+ // popen
+ while(!o->stophid)
+ {
+ to.tv_sec = 0;
+ to.tv_usec = 50000; // maw sph
+
+ FD_ZERO(&rfds);
+ FD_SET(o->pttkick[0],&rfds);
+ /* ast_select emulates linux behaviour in terms of timeout handling */
+ res = ast_select(o->pttkick[0] + 1, &rfds, NULL, NULL, &to);
+ if (res < 0) {
+ ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
+ usleep(10000);
+ continue;
+ }
+ if (FD_ISSET(o->pttkick[0],&rfds))
+ {
+ char c;
+
+ read(o->pttkick[0],&c,1);
+ }
+ if(o->wanteeprom)
+ {
+ ast_mutex_lock(&o->eepromlock);
+ if (o->eepromctl == 1) /* to read */
+ {
+ /* if CS okay */
+ if (!get_eeprom(usb_handle,o->eeprom))
+ {
+ if (o->eeprom[EEPROM_MAGIC_ADDR] != EEPROM_MAGIC)
+ {
+ ast_log(LOG_NOTICE,"UNSUCCESSFUL: EEPROM MAGIC NUMBER BAD on channel %s\n",o->name);
+ }
+ else
+ {
+ o->rxmixerset = o->eeprom[EEPROM_RXMIXERSET];
+ o->txmixaset = o->eeprom[EEPROM_TXMIXASET];
+ o->txmixbset = o->eeprom[EEPROM_TXMIXBSET];
+ memcpy(&o->rxvoiceadj,&o->eeprom[EEPROM_RXVOICEADJ],sizeof(float));
+ memcpy(&o->rxctcssadj,&o->eeprom[EEPROM_RXCTCSSADJ],sizeof(float));
+ o->txctcssadj = o->eeprom[EEPROM_TXCTCSSADJ];
+ o->rxsquelchadj = o->eeprom[EEPROM_RXSQUELCHADJ];
+ ast_log(LOG_NOTICE,"EEPROM Loaded on channel %s\n",o->name);
+ }
+ }
+ else
+ {
+ ast_log(LOG_NOTICE,"USB Adapter has no EEPROM installed or Checksum BAD on channel %s\n",o->name);
+ }
+ hid_set_outputs(usb_handle,bufsave);
+ }
+ if (o->eepromctl == 2) /* to write */
+ {
+ put_eeprom(usb_handle,o->eeprom);
+ hid_set_outputs(usb_handle,bufsave);
+ ast_log(LOG_NOTICE,"USB Parameters written to EEPROM on %s\n",o->name);
+ }
+ o->eepromctl = 0;
+ ast_mutex_unlock(&o->eepromlock);
+ }
buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
- hid_get_inputs(usb_handle, buf);
+ hid_get_inputs(usb_handle,buf);
keyed = !(buf[o->hid_io_cor_loc] & o->hid_io_cor);
- if (keyed != o->rxhidsq) {
- if (o->debuglevel)
- ast_log(LOG_NOTICE, "chan_usbradio() hidthread: update rxhidsq = %d\n", keyed);
- o->rxhidsq = keyed;
+ if (keyed != o->rxhidsq)
+ {
+ if(o->debuglevel)printf("chan_usbradio() hidthread: update rxhidsq = %d\n",keyed);
+ o->rxhidsq=keyed;
}
- /* if change in tx stuff */
- txtmp = 0;
- if (o->txkeyed || o->txchankey || o->txtestkey || o->pmrChan->txPttOut)
- txtmp = 1;
-
- if (o->lasttx != txtmp) {
- o->lasttx = txtmp;
- if (o->debuglevel)
- ast_log(LOG_NOTICE, "hidthread: tx set to %d\n", txtmp);
+ /* if change in tx state as controlled by xpmr */
+ txtmp=o->pmrChan->txPttOut;
+
+ if (o->lasttx != txtmp)
+ {
+ o->pmrChan->txPttHid=o->lasttx = txtmp;
+ if(o->debuglevel)printf("hidthread: tx set to %d\n",txtmp);
buf[o->hid_gpio_loc] = 0;
- if (txtmp)
- buf[o->hid_gpio_loc] = o->hid_io_ptt;
+ if (!o->invertptt)
+ {
+ if (txtmp) buf[o->hid_gpio_loc] = o->hid_io_ptt;
+ }
+ else
+ {
+ if (!txtmp) buf[o->hid_gpio_loc] = o->hid_io_ptt;
+ }
buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
- hid_set_outputs(usb_handle, buf);
+ memcpy(bufsave,buf,sizeof(buf));
+ hid_set_outputs(usb_handle,buf);
}
-
time(&o->lasthidtime);
- usleep(50000);
}
buf[o->hid_gpio_loc] = 0;
- if (o->invertptt)
- buf[o->hid_gpio_loc] = o->hid_io_ptt;
+ if (o->invertptt) buf[o->hid_gpio_loc] = o->hid_io_ptt;
buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
- hid_set_outputs(usb_handle, buf);
+ hid_set_outputs(usb_handle,buf);
pthread_exit(0);
}
-/*! \brief
+/*
* returns a pointer to the descriptor with the given name
*/
static struct chan_usbradio_pvt *find_desc(char *dev)
@@ -740,14 +1257,28 @@ static struct chan_usbradio_pvt *find_desc(char *dev)
ast_log(LOG_WARNING, "null dev\n");
for (o = usbradio_default.next; o && o->name && dev && strcmp(o->name, dev) != 0; o = o->next);
-
if (!o)
+ {
ast_log(LOG_WARNING, "could not find <%s>\n", dev ? dev : "--no-device--");
+ pthread_exit(0);
+ }
+
+ return o;
+}
+
+static struct chan_usbradio_pvt *find_desc_usb(char *devstr)
+{
+ struct chan_usbradio_pvt *o = NULL;
+
+ if (!devstr)
+ ast_log(LOG_WARNING, "null dev\n");
+
+ for (o = usbradio_default.next; o && devstr && strcmp(o->devstr, devstr) != 0; o = o->next);
return o;
}
-/*! \brief
+/*
* split a string in extension-context, returns pointers to malloc'ed
* strings.
* If we do not have 'overridecontext' then the last @ is considered as
@@ -783,7 +1314,7 @@ static char *ast_ext_ctx(const char *src, char **ext, char **ctx)
}
#endif
-/*! \brief
+/*
* Returns the number of blocks used in the audio output channel
*/
static int used_blocks(struct chan_usbradio_pvt *o)
@@ -799,14 +1330,15 @@ static int used_blocks(struct chan_usbradio_pvt *o)
}
if (o->total_blocks == 0) {
- ast_debug(4, "fragtotal %d size %d avail %d\n", info.fragstotal, info.fragsize, info.fragments);
+ if (0) /* debugging */
+ ast_log(LOG_WARNING, "fragtotal %d size %d avail %d\n", info.fragstotal, info.fragsize, info.fragments);
o->total_blocks = info.fragments;
}
return o->total_blocks - info.fragments;
}
-/*! \brief Write an exactly FRAME_SIZE sized frame */
+/* Write an exactly FRAME_SIZE sized frame */
static int soundcard_writeframe(struct chan_usbradio_pvt *o, short *data)
{
int res;
@@ -815,6 +1347,13 @@ static int soundcard_writeframe(struct chan_usbradio_pvt *o, short *data)
setformat(o, O_RDWR);
if (o->sounddev < 0)
return 0; /* not fatal */
+ // maw maw sph !!! may or may not be a good thing
+ // drop the frame if not transmitting, this keeps from gradually
+ // filling the buffer when asterisk clock > usb sound clock
+ if(!o->pmrChan->txPttIn && !o->pmrChan->txPttOut)
+ {
+ //return 0;
+ }
/*
* Nothing complex to manage the audio device queue.
* If the buffer is full just drop the extra, otherwise write.
@@ -823,6 +1362,7 @@ static int soundcard_writeframe(struct chan_usbradio_pvt *o, short *data)
*/
res = used_blocks(o);
if (res > o->queuesize) { /* no room to write a block */
+ // ast_log(LOG_WARNING, "sound device write buffer overflow\n");
if (o->w_errors++ == 0 && (usbradio_debug & 0x4))
ast_log(LOG_WARNING, "write: used %d blocks (%d)\n", res, o->w_errors);
return 0;
@@ -832,6 +1372,136 @@ static int soundcard_writeframe(struct chan_usbradio_pvt *o, short *data)
return write(o->sounddev, ((void *) data), FRAME_SIZE * 2 * 12);
}
+#ifndef NEW_ASTERISK
+
+/*
+ * Handler for 'sound writable' events from the sound thread.
+ * Builds a frame from the high level description of the sounds,
+ * and passes it to the audio device.
+ * The actual sound is made of 1 or more sequences of sound samples
+ * (s->datalen, repeated to make s->samplen samples) followed by
+ * s->silencelen samples of silence. The position in the sequence is stored
+ * in o->sampsent, which goes between 0 .. s->samplen+s->silencelen.
+ * In case we fail to write a frame, don't update o->sampsent.
+ */
+static void send_sound(struct chan_usbradio_pvt *o)
+{
+ short myframe[FRAME_SIZE];
+ int ofs, l, start;
+ int l_sampsent = o->sampsent;
+ struct sound *s;
+
+ if (o->cursound < 0) /* no sound to send */
+ return;
+
+ s = &sounds[o->cursound];
+
+ for (ofs = 0; ofs < FRAME_SIZE; ofs += l) {
+ l = s->samplen - l_sampsent; /* # of available samples */
+ if (l > 0) {
+ start = l_sampsent % s->datalen; /* source offset */
+ if (l > FRAME_SIZE - ofs) /* don't overflow the frame */
+ l = FRAME_SIZE - ofs;
+ if (l > s->datalen - start) /* don't overflow the source */
+ l = s->datalen - start;
+ bcopy(s->data + start, myframe + ofs, l * 2);
+ if (0)
+ ast_log(LOG_WARNING, "send_sound sound %d/%d of %d into %d\n", l_sampsent, l, s->samplen, ofs);
+ l_sampsent += l;
+ } else { /* end of samples, maybe some silence */
+ static const short silence[FRAME_SIZE] = { 0, };
+
+ l += s->silencelen;
+ if (l > 0) {
+ if (l > FRAME_SIZE - ofs)
+ l = FRAME_SIZE - ofs;
+ bcopy(silence, myframe + ofs, l * 2);
+ l_sampsent += l;
+ } else { /* silence is over, restart sound if loop */
+ if (s->repeat == 0) { /* last block */
+ o->cursound = -1;
+ o->nosound = 0; /* allow audio data */
+ if (ofs < FRAME_SIZE) /* pad with silence */
+ bcopy(silence, myframe + ofs, (FRAME_SIZE - ofs) * 2);
+ }
+ l_sampsent = 0;
+ }
+ }
+ }
+ l = soundcard_writeframe(o, myframe);
+ if (l > 0)
+ o->sampsent = l_sampsent; /* update status */
+}
+
+static void *sound_thread(void *arg)
+{
+ char ign[4096];
+ struct chan_usbradio_pvt *o = (struct chan_usbradio_pvt *) arg;
+
+ /*
+ * Just in case, kick the driver by trying to read from it.
+ * Ignore errors - this read is almost guaranteed to fail.
+ */
+ read(o->sounddev, ign, sizeof(ign));
+ for (;;) {
+ fd_set rfds, wfds;
+ int maxfd, res;
+
+ FD_ZERO(&rfds);
+ FD_ZERO(&wfds);
+ FD_SET(o->sndcmd[0], &rfds);
+ maxfd = o->sndcmd[0]; /* pipe from the main process */
+ if (o->cursound > -1 && o->sounddev < 0)
+ setformat(o, O_RDWR); /* need the channel, try to reopen */
+ else if (o->cursound == -1 && o->owner == NULL)
+ {
+ setformat(o, O_CLOSE); /* can close */
+ }
+ if (o->sounddev > -1) {
+ if (!o->owner) { /* no one owns the audio, so we must drain it */
+ FD_SET(o->sounddev, &rfds);
+ maxfd = MAX(o->sounddev, maxfd);
+ }
+ if (o->cursound > -1) {
+ FD_SET(o->sounddev, &wfds);
+ maxfd = MAX(o->sounddev, maxfd);
+ }
+ }
+ /* ast_select emulates linux behaviour in terms of timeout handling */
+ res = ast_select(maxfd + 1, &rfds, &wfds, NULL, NULL);
+ if (res < 1) {
+ ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
+ sleep(1);
+ continue;
+ }
+ if (FD_ISSET(o->sndcmd[0], &rfds)) {
+ /* read which sound to play from the pipe */
+ int i, what = -1;
+
+ read(o->sndcmd[0], &what, sizeof(what));
+ for (i = 0; sounds[i].ind != -1; i++) {
+ if (sounds[i].ind == what) {
+ o->cursound = i;
+ o->sampsent = 0;
+ o->nosound = 1; /* block audio from pbx */
+ break;
+ }
+ }
+ if (sounds[i].ind == -1)
+ ast_log(LOG_WARNING, "invalid sound index: %d\n", what);
+ }
+ if (o->sounddev > -1) {
+ if (FD_ISSET(o->sounddev, &rfds)) /* read and ignore errors */
+ read(o->sounddev, ign, sizeof(ign));
+ if (FD_ISSET(o->sounddev, &wfds))
+ send_sound(o);
+ }
+ }
+ return NULL; /* Never reached */
+}
+
+#endif
+
/*
* reset and close the device if opened,
* then open and initialize it in the desired mode,
@@ -840,7 +1510,7 @@ static int soundcard_writeframe(struct chan_usbradio_pvt *o, short *data)
static int setformat(struct chan_usbradio_pvt *o, int mode)
{
int fmt, desired, res, fd;
- char device[20];
+ char device[100];
if (o->sounddev >= 0) {
ioctl(o->sounddev, SNDCTL_DSP_RESET, 0);
@@ -850,12 +1520,10 @@ static int setformat(struct chan_usbradio_pvt *o, int mode)
}
if (mode == O_CLOSE) /* we are done */
return 0;
- if (ast_tvdiff_ms(ast_tvnow(), o->lastopen) < 1000)
- return -1; /* don't open too often */
o->lastopen = ast_tvnow();
- strcpy(device, "/dev/dsp");
+ strcpy(device,"/dev/dsp");
if (o->devicenum)
- snprintf(device + strlen("/dev/dsp"), sizeof(device) - strlen("/dev/dsp"), "%d", o->devicenum);
+ sprintf(device,"/dev/dsp%d",o->devicenum);
fd = o->sounddev = open(device, mode | O_NONBLOCK);
if (fd < 0) {
ast_log(LOG_WARNING, "Unable to re-open DSP device %d: %s\n", o->devicenum, strerror(errno));
@@ -880,7 +1548,8 @@ static int setformat(struct chan_usbradio_pvt *o, int mode)
/* Check to see if duplex set (FreeBSD Bug) */
res = ioctl(fd, SNDCTL_DSP_GETCAPS, &fmt);
if (res == 0 && (fmt & DSP_CAP_DUPLEX)) {
- ast_verb(2, "Console is full duplex\n");
+ if (option_verbose > 1)
+ ast_verbose(VERBOSE_PREFIX_2 "Console is full duplex\n");
o->duplex = M_FULL;
};
break;
@@ -946,18 +1615,74 @@ 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)
{
/* no better use for received digits than print them */
- ast_verb(0, " << Console Received digit %c of duration %u ms >> \n",
+ ast_verbose(" << Console Received digit %c of duration %u ms >> \n",
digit, duration);
return 0;
}
-
+/*
+ SETFREQ - sets spi programmable xcvr
+ SETCHAN - sets binary parallel xcvr
+*/
static int usbradio_text(struct ast_channel *c, const char *text)
{
+ struct chan_usbradio_pvt *o = find_desc(usbradio_active);
+ double tx,rx;
+ char cnt,rxs[16],txs[16],txpl[16],rxpl[16];
+ char pwr,*cmd;
+
+ cmd = alloca(strlen(text) + 10);
+
/* print received messages */
- ast_verb(0, " << Console Received text %s >> \n", text);
+ if(o->debuglevel)ast_verbose(" << Console Received usbradio text %s >> \n", text);
+
+ cnt=sscanf(text,"%s %s %s %s %s %c",cmd,rxs,txs,rxpl,txpl,&pwr);
+
+ if (strcmp(cmd,"SETCHAN")==0)
+ {
+ u8 chan;
+ chan=strtod(rxs,NULL);
+ ppbinout(chan);
+ if(o->debuglevel)ast_log(LOG_NOTICE,"parse usbradio SETCHAN cmd: %s chan: %i\n",text,chan);
+ return 0;
+ }
+
+ if (cnt < 6)
+ {
+ ast_log(LOG_ERROR,"Cannot parse usbradio text: %s\n",text);
+ return 0;
+ }
+ else
+ {
+ if(o->debuglevel)ast_verbose(" << %s %s %s %s %s %c >> \n", cmd,rxs,txs,rxpl,txpl,pwr);
+ }
+
+ if (strcmp(cmd,"SETFREQ")==0)
+ {
+ if(o->debuglevel)ast_log(LOG_NOTICE,"parse usbradio SETFREQ cmd: %s\n",text);
+ tx=strtod(txs,NULL);
+ rx=strtod(rxs,NULL);
+ o->set_txfreq = round(tx * (double)1000000);
+ o->set_rxfreq = round(rx * (double)1000000);
+ o->pmrChan->txpower = (pwr == 'H');
+ strcpy(o->set_rxctcssfreqs,rxpl);
+ strcpy(o->set_txctcssfreqs,txpl);
+
+ o->b.remoted=1;
+ xpmr_config(o);
+ return 0;
+ }
+ ast_log(LOG_ERROR,"Cannot parse usbradio cmd: %s\n",text);
return 0;
}
+/* Play ringtone 'x' on device 'o' */
+static void ring(struct chan_usbradio_pvt *o, int x)
+{
+#ifndef NEW_ASTERISK
+ write(o->sndcmd[1], &x, sizeof(x));
+#endif
+}
+
/*
* handler for incoming calls. Either autoanswer, or start ringing
*/
@@ -965,6 +1690,7 @@ static int usbradio_call(struct ast_channel *c, char *dest, int timeout)
{
struct chan_usbradio_pvt *o = c->tech_pvt;
+ o->stophid = 0;
time(&o->lasthidtime);
ast_pthread_create_background(&o->hidthread, NULL, hidthread, o);
ast_setstate(c, AST_STATE_UP);
@@ -976,8 +1702,15 @@ static int usbradio_call(struct ast_channel *c, char *dest, int timeout)
*/
static int usbradio_answer(struct ast_channel *c)
{
- ast_setstate(c, AST_STATE_UP);
+#ifndef NEW_ASTERISK
+ struct chan_usbradio_pvt *o = c->tech_pvt;
+#endif
+ ast_setstate(c, AST_STATE_UP);
+#ifndef NEW_ASTERISK
+ o->cursound = -1;
+ o->nosound = 0;
+#endif
return 0;
}
@@ -985,6 +1718,11 @@ static int usbradio_hangup(struct ast_channel *c)
{
struct chan_usbradio_pvt *o = c->tech_pvt;
+ //ast_log(LOG_NOTICE, "usbradio_hangup()\n");
+#ifndef NEW_ASTERISK
+ o->cursound = -1;
+ o->nosound = 0;
+#endif
c->tech_pvt = NULL;
o->owner = NULL;
ast_module_unref(ast_module_info->self);
@@ -993,10 +1731,13 @@ static int usbradio_hangup(struct ast_channel *c)
/* Assume auto-hangup too */
o->hookstate = 0;
setformat(o, O_CLOSE);
+ } else {
+ /* Make congestion noise */
+ ring(o, AST_CONTROL_CONGESTION);
}
}
o->stophid = 1;
- pthread_join(o->hidthread, NULL);
+ pthread_join(o->hidthread,NULL);
return 0;
}
@@ -1004,11 +1745,17 @@ static int usbradio_hangup(struct ast_channel *c)
/* used for data coming from the network */
static int usbradio_write(struct ast_channel *c, struct ast_frame *f)
{
- int src,datalen;
struct chan_usbradio_pvt *o = c->tech_pvt;
- traceusb2("usbradio_write() o->nosound=%d\n", o->nosound); /*sph maw asdf */
+ traceusb2(("usbradio_write() o->nosound= %i\n",o->nosound));
+#ifndef NEW_ASTERISK
+ /* Immediately return if no sound is enabled */
+ if (o->nosound)
+ return 0;
+ /* Stop any currently playing sound */
+ o->cursound = -1;
+#endif
/*
* we could receive a block which is not a multiple of our
* FRAME_SIZE, so buffer it locally and write to the device
@@ -1016,93 +1763,70 @@ static int usbradio_write(struct ast_channel *c, struct ast_frame *f)
* Keep the residue stored for future use.
*/
- if (o->txkeyed || o->txtestkey)
- o->pmrChan->txPttIn = 1;
- else
- o->pmrChan->txPttIn = 0;
-
- #if DEBUG_CAPTURES == 1 /* to write input data to a file datalen=320 */
- if (ftxcapraw && o->b.txcapraw) {
+ #if DEBUG_CAPTURES == 1 // to write input data to a file datalen=320
+ if (ftxcapraw && o->b.txcapraw)
+ {
i16 i, tbuff[f->datalen];
- for (i = 0; i < f->datalen; i += 2) {
- tbuff[i] = ((i16 *)(f->data))[i / 2];
- tbuff[i + 1] = o->txkeyed * M_Q13;
+ for(i=0;i<f->datalen;i+=2)
+ {
+ tbuff[i]= ((i16*)(f->data))[i/2];
+ tbuff[i+1]= o->txkeyed*M_Q13;
}
- fwrite(tbuff, 2, f->datalen, ftxcapraw);
- /*fwrite(f->data,1,f->datalen,ftxcapraw); */
+ fwrite(tbuff,2,f->datalen,ftxcapraw);
+ //fwrite(f->data,1,f->datalen,ftxcapraw);
}
#endif
- PmrTx(o->pmrChan,(i16*)f->data,(i16*)o->usbradio_write_buf_1);
-
- #if 0 /* to write 48KS/s stereo data to a file */
- if (!ftxoutraw) ftxoutraw = fopen(TX_CAP_OUT_FILE,"w");
- if (ftxoutraw) fwrite(o->usbradio_write_buf_1,1,f->datalen * 2 * 6,ftxoutraw);
- #endif
-
- #if DEBUG_CAPTURES == 1
- if (o->b.txcap2 && ftxcaptrace)
- fwrite((o->pmrChan->ptxDebug), 1, FRAME_SIZE * 2 * 16, ftxcaptrace);
- #endif
-
- src = 0; /* read position into f->data */
- datalen = f->datalen * 12;
- while (src < datalen) {
- /* Compute spare room in the buffer */
- int l = sizeof(o->usbradio_write_buf) - o->usbradio_write_dst;
+ // maw just take the data from the network and save it for PmrRx processing
- if (datalen - src >= l) { /* enough to fill a frame */
- memcpy(o->usbradio_write_buf + o->usbradio_write_dst, o->usbradio_write_buf_1 + src, l);
- soundcard_writeframe(o, (short *) o->usbradio_write_buf);
- src += l;
- o->usbradio_write_dst = 0;
- } else { /* copy residue */
- l = datalen - src;
- memcpy(o->usbradio_write_buf + o->usbradio_write_dst, o->usbradio_write_buf_1 + src, l);
- src += l; /* but really, we are done */
- o->usbradio_write_dst += l;
- }
- }
+ PmrTx(o->pmrChan,(i16*)f->data);
+
return 0;
}
static struct ast_frame *usbradio_read(struct ast_channel *c)
{
- int res;
+ int res, src, datalen, oldpttout;
+ int cd,sd;
struct chan_usbradio_pvt *o = c->tech_pvt;
- struct ast_frame *f = &o->read_f, *f1;
+ struct ast_frame *f = &o->read_f,*f1;
struct ast_frame wf = { AST_FRAME_CONTROL };
time_t now;
- traceusb2("usbradio_read()\n"); /* sph maw asdf */
+ traceusb2(("usbradio_read()\n"));
- if (o->lasthidtime) {
+ if (o->lasthidtime)
+ {
time(&now);
- if ((now - o->lasthidtime) > 3) {
- ast_log(LOG_ERROR, "HID process has died or something!!\n");
+ if ((now - o->lasthidtime) > 3)
+ {
+ ast_log(LOG_ERROR,"HID process has died or something!!\n");
return NULL;
}
}
- if (o->lastrx && (!o->rxkeyed)) {
- o->lastrx = 0;
- wf.subclass = AST_CONTROL_RADIO_UNKEY;
- ast_queue_frame(o->owner, &wf);
- } else if ((!o->lastrx) && (o->rxkeyed)) {
- o->lastrx = 1;
- wf.subclass = AST_CONTROL_RADIO_KEY;
- ast_queue_frame(o->owner, &wf);
- }
/* XXX can be simplified returning &ast_null_frame */
/* prepare a NULL frame in case we don't have enough data to return */
- memset(f, 0, sizeof(struct ast_frame));
+ bzero(f, sizeof(struct ast_frame));
f->frametype = AST_FRAME_NULL;
f->src = usbradio_tech.type;
res = read(o->sounddev, o->usbradio_read_buf + o->readpos,
sizeof(o->usbradio_read_buf) - o->readpos);
if (res < 0) /* audio data not ready, return a NULL frame */
+ {
+ if (errno != EAGAIN) return NULL;
+ if (o->readerrs++ > READERR_THRESHOLD)
+ {
+ ast_log(LOG_ERROR,"Stuck USB read channel [%s], un-sticking it!\n",o->name);
+ o->readerrs = 0;
+ return NULL;
+ }
+ if (o->readerrs == 1)
+ ast_log(LOG_WARNING,"Possibly stuck USB read channel. [%s]\n",o->name);
return f;
-
+ }
+ if (o->readerrs) ast_log(LOG_WARNING,"Nope, USB read channel [%s] wasn't stuck after all.\n",o->name);
+ o->readerrs = 0;
o->readpos += res;
if (o->readpos < sizeof(o->usbradio_read_buf)) /* not enough samples */
return f;
@@ -1111,78 +1835,224 @@ static struct ast_frame *usbradio_read(struct ast_channel *c)
return f;
#if DEBUG_CAPTURES == 1
- if (o->b.rxcapraw && frxcapraw)
- fwrite((o->usbradio_read_buf + AST_FRIENDLY_OFFSET), 1, FRAME_SIZE * 2 * 2 * 6, frxcapraw);
+ if (o->b.rxcapraw && frxcapraw) fwrite((o->usbradio_read_buf + AST_FRIENDLY_OFFSET),1,FRAME_SIZE * 2 * 2 * 6,frxcapraw);
#endif
#if 1
- PmrRx( o->pmrChan,
+ if(o->txkeyed||o->txtestkey)
+ {
+ if(!o->pmrChan->txPttIn)
+ {
+ o->pmrChan->txPttIn=1;
+ if(o->debuglevel) ast_log(LOG_NOTICE,"txPttIn = %i, chan %s\n",o->pmrChan->txPttIn,o->owner->name);
+ }
+ }
+ else if(o->pmrChan->txPttIn)
+ {
+ o->pmrChan->txPttIn=0;
+ if(o->debuglevel) ast_log(LOG_NOTICE,"txPttIn = %i, chan %s\n",o->pmrChan->txPttIn,o->owner->name);
+ }
+ oldpttout = o->pmrChan->txPttOut;
+
+ PmrRx( o->pmrChan,
(i16 *)(o->usbradio_read_buf + AST_FRIENDLY_OFFSET),
- (i16 *)(o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET));
+ (i16 *)(o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET),
+ (i16 *)(o->usbradio_write_buf_1));
+
+ if (oldpttout != o->pmrChan->txPttOut)
+ {
+ if(o->debuglevel) ast_log(LOG_NOTICE,"txPttOut = %i, chan %s\n",o->pmrChan->txPttOut,o->owner->name);
+ kickptt(o);
+ }
+
+ #if 0 // to write 48KS/s stereo tx data to a file
+ if (!ftxoutraw) ftxoutraw = fopen(TX_CAP_OUT_FILE,"w");
+ if (ftxoutraw) fwrite(o->usbradio_write_buf_1,1,FRAME_SIZE * 2 * 6,ftxoutraw);
+ #endif
+ #if DEBUG_CAPTURES == 1 && XPMR_DEBUG0 == 1
+ if (o->b.txcap2 && ftxcaptrace) fwrite((o->pmrChan->ptxDebug),1,FRAME_SIZE * 2 * 16,ftxcaptrace);
+ #endif
+
+ // 160 samples * 2 bytes/sample * 2 chan * 6x oversampling to 48KS/s
+ datalen = FRAME_SIZE * 24;
+ src = 0; /* read position into f->data */
+ while (src < datalen)
+ {
+ /* Compute spare room in the buffer */
+ int l = sizeof(o->usbradio_write_buf) - o->usbradio_write_dst;
+
+ if (datalen - src >= l)
+ {
+ /* enough to fill a frame */
+ memcpy(o->usbradio_write_buf + o->usbradio_write_dst, o->usbradio_write_buf_1 + src, l);
+ soundcard_writeframe(o, (short *) o->usbradio_write_buf);
+ src += l;
+ o->usbradio_write_dst = 0;
+ }
+ else
+ {
+ /* copy residue */
+ l = datalen - src;
+ memcpy(o->usbradio_write_buf + o->usbradio_write_dst, o->usbradio_write_buf_1 + src, l);
+ src += l; /* but really, we are done */
+ o->usbradio_write_dst += l;
+ }
+ }
#else
static FILE *hInput;
- i16 iBuff[FRAME_SIZE * 2 * 6];
+ i16 iBuff[FRAME_SIZE*2*6];
- o->pmrChan->b.rxCapture = 1;
+ o->pmrChan->b.rxCapture=1;
- if(!hInput) {
- hInput = fopen("/usr/src/xpmr/testdata/rx_in.pcm", "r");
- if(!hInput) {
- ast_log(LOG_ERROR, " Input Data File Not Found.\n");
+ if(!hInput)
+ {
+ hInput = fopen("/usr/src/xpmr/testdata/rx_in.pcm","r");
+ if(!hInput)
+ {
+ printf(" Input Data File Not Found.\n");
return 0;
}
}
- if (0 == fread((void *)iBuff, 2, FRAME_SIZE * 2 * 6, hInput))
- exit;
+ if(0==fread((void *)iBuff,2,FRAME_SIZE*2*6,hInput))exit;
- PmrRx( o->pmrChan,
+ PmrRx( o->pmrChan,
(i16 *)iBuff,
(i16 *)(o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET));
#endif
#if 0
- if (!frxoutraw) frxoutraw = fopen(RX_CAP_OUT_FILE, "w");
- if (frxoutraw) fwrite((o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET), 1, FRAME_SIZE * 2, frxoutraw);
+ if (!frxoutraw) frxoutraw = fopen(RX_CAP_OUT_FILE,"w");
+ if (frxoutraw) fwrite((o->usbradio_read_buf_8k + AST_FRIENDLY_OFFSET),1,FRAME_SIZE * 2,frxoutraw);
#endif
- #if DEBUG_CAPTURES == 1
- if (frxcaptrace && o->b.rxcap2) fwrite((o->pmrChan->prxDebug), 1, FRAME_SIZE * 2 * 16, frxcaptrace);
+ #if DEBUG_CAPTURES == 1 && XPMR_DEBUG0 == 1
+ if (frxcaptrace && o->b.rxcap2 && o->pmrChan->b.radioactive) fwrite((o->pmrChan->prxDebug),1,FRAME_SIZE * 2 * 16,frxcaptrace);
#endif
- if (o->rxcdtype == CD_HID && (o->pmrChan->rxExtCarrierDetect != o->rxhidsq))
- o->pmrChan->rxExtCarrierDetect = o->rxhidsq;
- if (o->rxcdtype == CD_HID_INVERT && (o->pmrChan->rxExtCarrierDetect == o->rxhidsq))
- o->pmrChan->rxExtCarrierDetect = !o->rxhidsq;
+ cd = 0;
+ if(o->rxcdtype==CD_HID && (o->pmrChan->rxExtCarrierDetect!=o->rxhidsq))
+ o->pmrChan->rxExtCarrierDetect=o->rxhidsq;
+
+ if(o->rxcdtype==CD_HID_INVERT && (o->pmrChan->rxExtCarrierDetect==o->rxhidsq))
+ o->pmrChan->rxExtCarrierDetect=!o->rxhidsq;
- if ( (o->rxcdtype == CD_HID && o->rxhidsq) ||
- (o->rxcdtype == CD_HID_INVERT && !o->rxhidsq) ||
- (o->rxcdtype == CD_XPMR_NOISE && o->pmrChan->rxCarrierDetect) ||
- (o->rxcdtype == CD_XPMR_VOX && o->pmrChan->rxCarrierDetect) )
- res = 1;
+ if( (o->rxcdtype==CD_HID && o->rxhidsq) ||
+ (o->rxcdtype==CD_HID_INVERT && !o->rxhidsq) ||
+ (o->rxcdtype==CD_XPMR_NOISE && o->pmrChan->rxCarrierDetect) ||
+ (o->rxcdtype==CD_XPMR_VOX && o->pmrChan->rxCarrierDetect)
+ )
+ {
+ if (!o->pmrChan->txPttOut || o->radioduplex)cd=1;
+ }
else
- res = 0;
+ {
+ cd=0;
+ }
- if (res != o->rxcarrierdetect) {
- o->rxcarrierdetect = res;
- if (o->debuglevel)
- ast_debug(4, "rxcarrierdetect = %d\n", res);
+ if(cd!=o->rxcarrierdetect)
+ {
+ o->rxcarrierdetect=cd;
+ if(o->debuglevel) ast_log(LOG_NOTICE,"rxcarrierdetect = %i, chan %s\n",cd,o->owner->name);
+ // printf("rxcarrierdetect = %i, chan %s\n",res,o->owner->name);
}
- if (o->pmrChan->rxCtcss->decode != o->rxctcssdecode) {
- if (o->debuglevel)
- ast_debug(4, "rxctcssdecode = %d\n", o->pmrChan->rxCtcss->decode);
- o->rxctcssdecode = o->pmrChan->rxCtcss->decode;
+ if(o->pmrChan->b.ctcssRxEnable && o->pmrChan->rxCtcss->decode!=o->rxctcssdecode)
+ {
+ if(o->debuglevel)ast_log(LOG_NOTICE,"rxctcssdecode = %i, chan %s\n",o->pmrChan->rxCtcss->decode,o->owner->name);
+ // printf("rxctcssdecode = %i, chan %s\n",o->pmrChan->rxCtcss->decode,o->owner->name);
+ o->rxctcssdecode=o->pmrChan->rxCtcss->decode;
+ strcpy(o->rxctcssfreq, o->pmrChan->rxctcssfreq);
}
- if ( ( o->rxctcssfreq && (o->rxctcssdecode == o->pmrChan->rxCtcssIndex)) ||
- ( !o->rxctcssfreq && o->rxcarrierdetect) )
- o->rxkeyed = 1;
+ #ifndef HAVE_XPMRX
+ if( !o->pmrChan->b.ctcssRxEnable ||
+ ( o->pmrChan->b.ctcssRxEnable &&
+ o->pmrChan->rxCtcss->decode>CTCSS_NULL &&
+ o->pmrChan->smode==SMODE_CTCSS )
+ )
+ {
+ sd=1;
+ }
+ else
+ {
+ sd=0;
+ }
+ #else
+ if( (!o->pmrChan->b.ctcssRxEnable && !o->pmrChan->b.dcsRxEnable && !o->pmrChan->b.lmrRxEnable) ||
+ ( o->pmrChan->b.ctcssRxEnable &&
+ o->pmrChan->rxCtcss->decode>CTCSS_NULL &&
+ o->pmrChan->smode==SMODE_CTCSS ) ||
+ ( o->pmrChan->b.dcsRxEnable &&
+ o->pmrChan->decDcs->decode > 0 &&
+ o->pmrChan->smode==SMODE_DCS )
+ )
+ {
+ sd=1;
+ }
else
+ {
+ sd=0;
+ }
+
+ if(o->pmrChan->decDcs->decode!=o->rxdcsdecode)
+ {
+ if(o->debuglevel)ast_log(LOG_NOTICE,"rxdcsdecode = %s, chan %s\n",o->pmrChan->rxctcssfreq,o->owner->name);
+ // printf("rxctcssdecode = %i, chan %s\n",o->pmrChan->rxCtcss->decode,o->owner->name);
+ o->rxdcsdecode=o->pmrChan->decDcs->decode;
+ strcpy(o->rxctcssfreq, o->pmrChan->rxctcssfreq);
+ }
+
+ if(o->pmrChan->rptnum && (o->pmrChan->pLsdCtl->cs[o->pmrChan->rptnum].b.rxkeyed != o->rxlsddecode))
+ {
+ if(o->debuglevel)ast_log(LOG_NOTICE,"rxLSDecode = %s, chan %s\n",o->pmrChan->rxctcssfreq,o->owner->name);
+ o->rxlsddecode=o->pmrChan->pLsdCtl->cs[o->pmrChan->rptnum].b.rxkeyed;
+ strcpy(o->rxctcssfreq, o->pmrChan->rxctcssfreq);
+ }
+
+ if( (o->pmrChan->rptnum>0 && o->pmrChan->smode==SMODE_LSD && o->pmrChan->pLsdCtl->cs[o->pmrChan->rptnum].b.rxkeyed)||
+ (o->pmrChan->smode==SMODE_DCS && o->pmrChan->decDcs->decode>0) )
+ {
+ sd=1;
+ }
+ #endif
+
+ if ( cd && sd )
+ {
+ //if(!o->rxkeyed)o->pmrChan->dd.b.doitnow=1;
+ if(!o->rxkeyed && o->debuglevel)ast_log(LOG_NOTICE,"o->rxkeyed = 1, chan %s\n", o->owner->name);
+ o->rxkeyed = 1;
+ }
+ else
+ {
+ //if(o->rxkeyed)o->pmrChan->dd.b.doitnow=1;
+ if(o->rxkeyed && o->debuglevel)ast_log(LOG_NOTICE,"o->rxkeyed = 0, chan %s\n",o->owner->name);
o->rxkeyed = 0;
+ }
+ // provide rx signal detect conditions
+ if (o->lastrx && (!o->rxkeyed))
+ {
+ o->lastrx = 0;
+ //printf("AST_CONTROL_RADIO_UNKEY\n");
+ wf.subclass = AST_CONTROL_RADIO_UNKEY;
+ ast_queue_frame(o->owner, &wf);
+ }
+ else if ((!o->lastrx) && (o->rxkeyed))
+ {
+ o->lastrx = 1;
+ //printf("AST_CONTROL_RADIO_KEY\n");
+ wf.subclass = AST_CONTROL_RADIO_KEY;
+ if(o->rxctcssdecode)
+ {
+ wf.data = o->rxctcssfreq;
+ wf.datalen = strlen(o->rxctcssfreq) + 1;
+ TRACEO(1,("AST_CONTROL_RADIO_KEY text=%s\n",o->rxctcssfreq));
+ }
+ ast_queue_frame(o->owner, &wf);
+ }
o->readpos = AST_FRIENDLY_OFFSET; /* reset read pointer for next frame */
if (c->_state != AST_STATE_UP) /* drop data if frame is not up */
@@ -1207,13 +2077,22 @@ static struct ast_frame *usbradio_read(struct ast_channel *c)
}
f->offset = AST_FRIENDLY_OFFSET;
- if (o->dsp) {
- f1 = ast_dsp_process(c, o->dsp, f);
- if ((f1->frametype == AST_FRAME_DTMF_END) || (f1->frametype == AST_FRAME_DTMF_BEGIN)) {
- if (f1->frametype == AST_FRAME_DTMF_END)
- ast_log(LOG_NOTICE,"Got DTMF char %c\n",f1->subclass);
- return f1;
+ if (o->dsp)
+ {
+ f1 = ast_dsp_process(c,o->dsp,f);
+ if ((f1->frametype == AST_FRAME_DTMF_END) ||
+ (f1->frametype == AST_FRAME_DTMF_BEGIN))
+ {
+ if ((f1->subclass == 'm') || (f1->subclass == 'u'))
+ {
+ f1->frametype = AST_FRAME_NULL;
+ f1->subclass = 0;
+ return(f1);
}
+ if (f1->frametype == AST_FRAME_DTMF_END)
+ ast_log(LOG_NOTICE,"Got DTMF char %c\n",f1->subclass);
+ return(f1);
+ }
}
return f;
}
@@ -1229,43 +2108,58 @@ static int usbradio_fixup(struct ast_channel *oldchan, struct ast_channel *newch
static int usbradio_indicate(struct ast_channel *c, int cond, const void *data, size_t datalen)
{
struct chan_usbradio_pvt *o = c->tech_pvt;
- int res = 0;
+ int res = -1;
switch (cond) {
- case AST_CONTROL_BUSY:
- case AST_CONTROL_CONGESTION:
- case AST_CONTROL_RINGING:
- case -1:
- res = -1;
- break;
- case AST_CONTROL_PROGRESS:
- case AST_CONTROL_PROCEEDING:
- case AST_CONTROL_VIDUPDATE:
- break;
- case AST_CONTROL_HOLD:
- ast_verb(0, " << Console Has Been Placed on Hold >> \n");
- ast_moh_start(c, data, o->mohinterpret);
- break;
- case AST_CONTROL_UNHOLD:
- ast_verb(0, " << Console Has Been Retrieved from Hold >> \n");
- ast_moh_stop(c);
- break;
- case AST_CONTROL_RADIO_KEY:
- o->txkeyed = 1;
- if (o->debuglevel)
- ast_verb(0, " << Radio Transmit On. >> \n");
- break;
- case AST_CONTROL_RADIO_UNKEY:
- o->txkeyed = 0;
- if (o->debuglevel)
- ast_verb(0, " << Radio Transmit Off. >> \n");
- break;
- default:
- ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n", cond, c->name);
- return -1;
+ case AST_CONTROL_BUSY:
+ case AST_CONTROL_CONGESTION:
+ case AST_CONTROL_RINGING:
+ res = cond;
+ break;
+
+ case -1:
+#ifndef NEW_ASTERISK
+ o->cursound = -1;
+ o->nosound = 0; /* when cursound is -1 nosound must be 0 */
+#endif
+ return 0;
+
+ case AST_CONTROL_VIDUPDATE:
+ res = -1;
+ break;
+ case AST_CONTROL_HOLD:
+ ast_verbose(" << Console Has Been Placed on Hold >> \n");
+ ast_moh_start(c, data, o->mohinterpret);
+ break;
+ case AST_CONTROL_UNHOLD:
+ ast_verbose(" << Console Has Been Retrieved from Hold >> \n");
+ ast_moh_stop(c);
+ break;
+ case AST_CONTROL_PROCEEDING:
+ ast_verbose(" << Call Proceeding... >> \n");
+ ast_moh_stop(c);
+ break;
+ case AST_CONTROL_PROGRESS:
+ ast_verbose(" << Call Progress... >> \n");
+ ast_moh_stop(c);
+ break;
+ case AST_CONTROL_RADIO_KEY:
+ o->txkeyed = 1;
+ if(o->debuglevel)ast_verbose(" << AST_CONTROL_RADIO_KEY Radio Transmit On. >> \n");
+ break;
+ case AST_CONTROL_RADIO_UNKEY:
+ o->txkeyed = 0;
+ if(o->debuglevel)ast_verbose(" << AST_CONTROL_RADIO_UNKEY Radio Transmit Off. >> \n");
+ break;
+ default:
+ ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n", cond, c->name);
+ return -1;
}
- return res;
+ if (res > -1)
+ ring(o, res);
+
+ return 0;
}
/*
@@ -1274,11 +2168,8 @@ static int usbradio_indicate(struct ast_channel *c, int cond, const void *data,
static struct ast_channel *usbradio_new(struct chan_usbradio_pvt *o, char *ext, char *ctx, int state)
{
struct ast_channel *c;
- char device[15] = "dsp";
- if (o->devicenum)
- snprintf(device + 3, sizeof(device) - 3, "%d", o->devicenum);
- c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "", ext, ctx, 0, "usbRadio/%s", device);
+ c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "", ext, ctx, 0, "Radio/%s", o->name);
if (c == NULL)
return NULL;
c->tech = &usbradio_tech;
@@ -1315,13 +2206,19 @@ static struct ast_channel *usbradio_new(struct chan_usbradio_pvt *o, char *ext,
return c;
}
-
+/*
+*/
static struct ast_channel *usbradio_request(const char *type, int format, void *data, int *cause)
{
struct ast_channel *c;
struct chan_usbradio_pvt *o = find_desc(data);
- ast_debug(4, "usbradio_request ty <%s> data 0x%p <%s>\n", type, data, (char *) data);
+ TRACEO(1,("usbradio_request()\n"));
+
+ if (0)
+ {
+ ast_log(LOG_WARNING, "usbradio_request type <%s> data 0x%p <%s>\n", type, data, (char *) data);
+ }
if (o == NULL) {
ast_log(LOG_NOTICE, "Device %s not found\n", (char *) data);
/* XXX we could default to 'dsp' perhaps ? */
@@ -1341,260 +2238,275 @@ static struct ast_channel *usbradio_request(const char *type, int format, void *
ast_log(LOG_WARNING, "Unable to create new usb channel\n");
return NULL;
}
+
+ o->b.remoted=0;
+ xpmr_config(o);
+
return c;
}
-
-static char *handle_cli_radio_key(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+/*
+*/
+static int console_key(int fd, int argc, char *argv[])
{
- struct chan_usbradio_pvt *o = NULL;
-
- switch (cmd) {
- case CLI_INIT:
- e->command = "radio key";
- e->usage =
- "Usage: radio key\n"
- " Simulates COR active.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
-
- if (a->argc != 2)
- return CLI_SHOWUSAGE;
+ struct chan_usbradio_pvt *o = find_desc(usbradio_active);
- o = find_desc(usbradio_active);
+ if (argc != 2)
+ return RESULT_SHOWUSAGE;
o->txtestkey = 1;
-
- return CLI_SUCCESS;
+ return RESULT_SUCCESS;
}
-
-static char *handle_cli_radio_unkey(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+/*
+*/
+static int console_unkey(int fd, int argc, char *argv[])
{
- struct chan_usbradio_pvt *o = NULL;
-
- switch (cmd) {
- case CLI_INIT:
- e->command = "radio unkey";
- e->usage =
- "Usage: radio unkey\n"
- " Simulates COR un-active.\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
-
- if (a->argc != 2)
- return CLI_SHOWUSAGE;
+ struct chan_usbradio_pvt *o = find_desc(usbradio_active);
- o = find_desc(usbradio_active);
+ if (argc != 2)
+ return RESULT_SHOWUSAGE;
o->txtestkey = 0;
-
- return CLI_SUCCESS;
+ return RESULT_SUCCESS;
}
-static char *handle_cli_radio_tune(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+static int radio_tune(int fd, int argc, char *argv[])
{
- struct chan_usbradio_pvt *o = NULL;
- int i = 0;
-
- switch (cmd) {
- case CLI_INIT:
- e->command = "radio tune [rxnoise|rxvoice|rxtone|rxsquelch|rxcap|rxtracecap|"
- "txvoice|txtone|txcap|txtracecap|auxvoice|nocap|dump|save]";
- /* radio tune 6 3000 measured tx value */
- e->usage =
- "Usage: radio tune <function>\n"
- " rxnoise\n"
- " rxvoice\n"
- " rxtone\n"
- " rxsquelch [newsetting]\n"
- " rxcap\n"
- " rxtracecap\n"
- " txvoice [newsetting]\n"
- " txtone [newsetting]\n"
- " txcap\n"
- " txtracecap\n"
- " auxvoice [newsetting]\n"
- " nocap\n"
- " dump\n"
- " save (settings to tuning file)\n"
- "\n"
- " All [newsetting]s are values 0-999\n";
- return NULL;
- case CLI_GENERATE:
- return NULL;
- }
-
- if ((a->argc < 2) || (a->argc > 4))
- return CLI_SHOWUSAGE;
-
- if (a->argc == 2) { /* just show stuff */
- ast_cli(a->fd, "Output A is currently set to %s.\n",
- o->txmixa == TX_OUT_COMPOSITE ? "composite" :
- o->txmixa == TX_OUT_VOICE ? "voice" :
- o->txmixa == TX_OUT_LSD ? "tone" :
- o->txmixa == TX_OUT_AUX ? "auxvoice" :
- "off");
-
- ast_cli(a->fd, "Output B is currently set to %s.\n",
- o->txmixb == TX_OUT_COMPOSITE ? "composite" :
- o->txmixb == TX_OUT_VOICE ? "voice" :
- o->txmixb == TX_OUT_LSD ? "tone" :
- o->txmixb == TX_OUT_AUX ? "auxvoice" :
- "off");
-
- ast_cli(a->fd, "Tx Voice Level currently set to %d\n", o->txmixaset);
- ast_cli(a->fd, "Tx Tone Level currently set to %d\n", o->txctcssadj);
- ast_cli(a->fd, "Rx Squelch currently set to %d\n", o->rxsquelchadj);
- return CLI_SHOWUSAGE;
- }
-
- o = find_desc(usbradio_active);
-
- if (!strcasecmp(a->argv[2], "rxnoise"))
- tune_rxinput(o);
- else if (!strcasecmp(a->argv[2], "rxvoice"))
- tune_rxvoice(o);
- else if (!strcasecmp(a->argv[2], "rxtone"))
- tune_rxctcss(o);
- else if (!strcasecmp(a->argv[2], "rxsquelch")) {
- if (a->argc == 3) {
- ast_cli(a->fd, "Current Signal Strength is %d\n", ((32767 - o->pmrChan->rxRssi) * 1000 / 32767));
- ast_cli(a->fd, "Current Squelch setting is %d\n", o->rxsquelchadj);
-#if 0
- ast_cli(a->fd,"Current Raw RSSI is %d\n",o->pmrChan->rxRssi);
- ast_cli(a->fd,"Current (real) Squelch setting is %d\n",*(o->pmrChan->prxSquelchAdjust));
-#endif
+ struct chan_usbradio_pvt *o = find_desc(usbradio_active);
+ int i=0;
+
+ if ((argc < 2) || (argc > 4))
+ return RESULT_SHOWUSAGE;
+
+ if (argc == 2) /* just show stuff */
+ {
+ ast_cli(fd,"Active radio interface is [%s]\n",usbradio_active);
+ ast_cli(fd,"Output A is currently set to ");
+ if(o->txmixa==TX_OUT_COMPOSITE)ast_cli(fd,"composite.\n");
+ else if (o->txmixa==TX_OUT_VOICE)ast_cli(fd,"voice.\n");
+ else if (o->txmixa==TX_OUT_LSD)ast_cli(fd,"tone.\n");
+ else if (o->txmixa==TX_OUT_AUX)ast_cli(fd,"auxvoice.\n");
+ else ast_cli(fd,"off.\n");
+
+ ast_cli(fd,"Output B is currently set to ");
+ if(o->txmixb==TX_OUT_COMPOSITE)ast_cli(fd,"composite.\n");
+ else if (o->txmixb==TX_OUT_VOICE)ast_cli(fd,"voice.\n");
+ else if (o->txmixb==TX_OUT_LSD)ast_cli(fd,"tone.\n");
+ else if (o->txmixb==TX_OUT_AUX)ast_cli(fd,"auxvoice.\n");
+ else ast_cli(fd,"off.\n");
+
+ ast_cli(fd,"Tx Voice Level currently set to %d\n",o->txmixaset);
+ ast_cli(fd,"Tx Tone Level currently set to %d\n",o->txctcssadj);
+ ast_cli(fd,"Rx Squelch currently set to %d\n",o->rxsquelchadj);
+ ast_cli(fd,"Device String is %s\n",o->devstr);
+ return RESULT_SHOWUSAGE;
+ }
+
+ o->pmrChan->b.tuning=1;
+
+ if (!strcasecmp(argv[2],"rxnoise")) tune_rxinput(fd,o);
+ else if (!strcasecmp(argv[2],"rxvoice")) tune_rxvoice(fd,o);
+ else if (!strcasecmp(argv[2],"rxtone")) tune_rxctcss(fd,o);
+ else if (!strcasecmp(argv[2],"rxsquelch"))
+ {
+ if (argc == 3)
+ {
+ ast_cli(fd,"Current Signal Strength is %d\n",((32767-o->pmrChan->rxRssi)*1000/32767));
+ ast_cli(fd,"Current Squelch setting is %d\n",o->rxsquelchadj);
+ //ast_cli(fd,"Current Raw RSSI is %d\n",o->pmrChan->rxRssi);
+ //ast_cli(fd,"Current (real) Squelch setting is %d\n",*(o->pmrChan->prxSquelchAdjust));
} else {
- i = atoi(a->argv[3]);
- if ((i < 0) || (i > 999))
- return CLI_SHOWUSAGE;
- ast_cli(a->fd, "Changed Squelch setting to %d\n", i);
+ i = atoi(argv[3]);
+ if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
+ ast_cli(fd,"Changed Squelch setting to %d\n",i);
o->rxsquelchadj = i;
- *(o->pmrChan->prxSquelchAdjust) = ((999 - i) * 32767) / 1000;
+ *(o->pmrChan->prxSquelchAdjust)= ((999 - i) * 32767) / 1000;
}
- } else if (!strcasecmp(a->argv[2], "txvoice")) {
+ }
+ else if (!strcasecmp(argv[2],"txvoice")) {
i = 0;
- if ((o->txmixa != TX_OUT_VOICE) && (o->txmixb != TX_OUT_VOICE) &&
- (o->txmixa != TX_OUT_COMPOSITE) && (o->txmixb != TX_OUT_COMPOSITE)) {
- ast_log(LOG_ERROR, "No txvoice output configured.\n");
- } else if (a->argc == 3) {
- if ((o->txmixa == TX_OUT_VOICE) || (o->txmixa == TX_OUT_COMPOSITE))
- ast_cli(a->fd, "Current txvoice setting on Channel A is %d\n", o->txmixaset);
+ if( (o->txmixa!=TX_OUT_VOICE) && (o->txmixb!=TX_OUT_VOICE) &&
+ (o->txmixa!=TX_OUT_COMPOSITE) && (o->txmixb!=TX_OUT_COMPOSITE)
+ )
+ {
+ ast_log(LOG_ERROR,"No txvoice output configured.\n");
+ }
+ else if (argc == 3)
+ {
+ if((o->txmixa==TX_OUT_VOICE)||(o->txmixa==TX_OUT_COMPOSITE))
+ ast_cli(fd,"Current txvoice setting on Channel A is %d\n",o->txmixaset);
else
- ast_cli(a->fd, "Current txvoice setting on Channel B is %d\n", o->txmixbset);
- } else {
- i = atoi(a->argv[3]);
- if ((i < 0) || (i > 999))
- return CLI_SHOWUSAGE;
-
- if ((o->txmixa == TX_OUT_VOICE) || (o->txmixa == TX_OUT_COMPOSITE)) {
- o->txmixaset = i;
- ast_cli(a->fd, "Changed txvoice setting on Channel A to %d\n", o->txmixaset);
- } else {
- o->txmixbset = i;
- ast_cli(a->fd, "Changed txvoice setting on Channel B to %d\n", o->txmixbset);
+ ast_cli(fd,"Current txvoice setting on Channel B is %d\n",o->txmixbset);
+ }
+ else
+ {
+ i = atoi(argv[3]);
+ if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
+
+ if((o->txmixa==TX_OUT_VOICE)||(o->txmixa==TX_OUT_COMPOSITE))
+ {
+ o->txmixaset=i;
+ ast_cli(fd,"Changed txvoice setting on Channel A to %d\n",o->txmixaset);
+ }
+ else
+ {
+ o->txmixbset=i;
+ ast_cli(fd,"Changed txvoice setting on Channel B to %d\n",o->txmixbset);
}
mixer_write(o);
mult_set(o);
- ast_cli(a->fd, "Changed Tx Voice Output setting to %d\n", i);
+ ast_cli(fd,"Changed Tx Voice Output setting to %d\n",i);
}
- tune_txoutput(o,i);
- } else if (!strcasecmp(a->argv[2], "auxvoice")) {
+ o->pmrChan->b.txCtcssInhibit=1;
+ tune_txoutput(o,i,fd);
+ o->pmrChan->b.txCtcssInhibit=0;
+ }
+ else if (!strcasecmp(argv[2],"txall")) {
i = 0;
- if ( (o->txmixa != TX_OUT_AUX) && (o->txmixb != TX_OUT_AUX))
- ast_log(LOG_WARNING, "No auxvoice output configured.\n");
- else if (a->argc == 3) {
- if (o->txmixa == TX_OUT_AUX)
- ast_cli(a->fd, "Current auxvoice setting on Channel A is %d\n", o->txmixaset);
+
+ if( (o->txmixa!=TX_OUT_VOICE) && (o->txmixb!=TX_OUT_VOICE) &&
+ (o->txmixa!=TX_OUT_COMPOSITE) && (o->txmixb!=TX_OUT_COMPOSITE)
+ )
+ {
+ ast_log(LOG_ERROR,"No txvoice output configured.\n");
+ }
+ else if (argc == 3)
+ {
+ if((o->txmixa==TX_OUT_VOICE)||(o->txmixa==TX_OUT_COMPOSITE))
+ ast_cli(fd,"Current txvoice setting on Channel A is %d\n",o->txmixaset);
else
- ast_cli(a->fd, "Current auxvoice setting on Channel B is %d\n", o->txmixbset);
- } else {
- i = atoi(a->argv[3]);
- if ((i < 0) || (i > 999))
- return CLI_SHOWUSAGE;
- if (o->txmixa == TX_OUT_AUX) {
- o->txmixbset = i;
- ast_cli(a->fd, "Changed auxvoice setting on Channel A to %d\n", o->txmixaset);
- } else {
- o->txmixbset = i;
- ast_cli(a->fd, "Changed auxvoice setting on Channel B to %d\n", o->txmixbset);
+ ast_cli(fd,"Current txvoice setting on Channel B is %d\n",o->txmixbset);
+ }
+ else
+ {
+ i = atoi(argv[3]);
+ if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
+
+ if((o->txmixa==TX_OUT_VOICE)||(o->txmixa==TX_OUT_COMPOSITE))
+ {
+ o->txmixaset=i;
+ ast_cli(fd,"Changed txvoice setting on Channel A to %d\n",o->txmixaset);
+ }
+ else
+ {
+ o->txmixbset=i;
+ ast_cli(fd,"Changed txvoice setting on Channel B to %d\n",o->txmixbset);
+ }
+ mixer_write(o);
+ mult_set(o);
+ ast_cli(fd,"Changed Tx Voice Output setting to %d\n",i);
+ }
+ tune_txoutput(o,i,fd);
+ }
+ else if (!strcasecmp(argv[2],"auxvoice")) {
+ i = 0;
+ if( (o->txmixa!=TX_OUT_AUX) && (o->txmixb!=TX_OUT_AUX))
+ {
+ ast_log(LOG_WARNING,"No auxvoice output configured.\n");
+ }
+ else if (argc == 3)
+ {
+ if(o->txmixa==TX_OUT_AUX)
+ ast_cli(fd,"Current auxvoice setting on Channel A is %d\n",o->txmixaset);
+ else
+ ast_cli(fd,"Current auxvoice setting on Channel B is %d\n",o->txmixbset);
+ }
+ else
+ {
+ i = atoi(argv[3]);
+ if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
+ if(o->txmixa==TX_OUT_AUX)
+ {
+ o->txmixbset=i;
+ ast_cli(fd,"Changed auxvoice setting on Channel A to %d\n",o->txmixaset);
+ }
+ else
+ {
+ o->txmixbset=i;
+ ast_cli(fd,"Changed auxvoice setting on Channel B to %d\n",o->txmixbset);
}
mixer_write(o);
mult_set(o);
}
- /* tune_auxoutput(o,i); */
- } else if (!strcasecmp(a->argv[2], "txtone")) {
- if (a->argc == 3)
- ast_cli(a->fd, "Current Tx CTCSS modulation setting = %d\n", o->txctcssadj);
- else {
- i = atoi(a->argv[3]);
- if ((i < 0) || (i > 999))
- return CLI_SHOWUSAGE;
+ //tune_auxoutput(o,i);
+ }
+ else if (!strcasecmp(argv[2],"txtone"))
+ {
+ if (argc == 3)
+ ast_cli(fd,"Current Tx CTCSS modulation setting = %d\n",o->txctcssadj);
+ else
+ {
+ i = atoi(argv[3]);
+ if ((i < 0) || (i > 999)) return RESULT_SHOWUSAGE;
o->txctcssadj = i;
set_txctcss_level(o);
- ast_cli(a->fd, "Changed Tx CTCSS modulation setting to %i\n", i);
+ ast_cli(fd,"Changed Tx CTCSS modulation setting to %i\n",i);
}
- o->txtestkey = 1;
+ o->txtestkey=1;
usleep(5000000);
- o->txtestkey = 0;
- } else if (!strcasecmp(a->argv[2],"dump"))
- pmrdump(o);
- else if (!strcasecmp(a->argv[2],"nocap")) {
- ast_cli(a->fd, "File capture (trace) was rx=%d tx=%d and now off.\n", o->b.rxcap2, o->b.txcap2);
- ast_cli(a->fd, "File capture (raw) was rx=%d tx=%d and now off.\n", o->b.rxcapraw, o->b.txcapraw);
- o->b.rxcapraw = o->b.txcapraw = o->b.rxcap2 = o->b.txcap2 = o->pmrChan->b.rxCapture = o->pmrChan->b.txCapture = 0;
- if (frxcapraw) {
- fclose(frxcapraw);
- frxcapraw = NULL;
- }
- if (frxcaptrace) {
- fclose(frxcaptrace);
- frxcaptrace = NULL;
- }
- if (frxoutraw) {
- fclose(frxoutraw);
- frxoutraw = NULL;
- }
- if (ftxcapraw) {
- fclose(ftxcapraw);
- ftxcapraw = NULL;
- }
- if (ftxcaptrace) {
- fclose(ftxcaptrace);
- ftxcaptrace = NULL;
- }
- if (ftxoutraw) {
- fclose(ftxoutraw);
- ftxoutraw = NULL;
- }
- } else if (!strcasecmp(a->argv[2], "rxtracecap")) {
- if (!frxcaptrace)
- frxcaptrace = fopen(RX_CAP_TRACE_FILE, "w");
- ast_cli(a->fd, "Trace rx on.\n");
- o->b.rxcap2 = o->pmrChan->b.rxCapture = 1;
- } else if (!strcasecmp(a->argv[2], "txtracecap")) {
- if (!ftxcaptrace)
- ftxcaptrace = fopen(TX_CAP_TRACE_FILE, "w");
- ast_cli(a->fd, "Trace tx on.\n");
- o->b.txcap2 = o->pmrChan->b.txCapture = 1;
- } else if (!strcasecmp(a->argv[2], "rxcap")) {
- if (!frxcapraw)
- frxcapraw = fopen(RX_CAP_RAW_FILE, "w");
- ast_cli(a->fd, "cap rx raw on.\n");
- o->b.rxcapraw = 1;
- } else if (!strcasecmp(a->argv[2], "txcap")) {
- if (!ftxcapraw)
- ftxcapraw = fopen(TX_CAP_RAW_FILE, "w");
- ast_cli(a->fd, "cap tx raw on.\n");
- o->b.txcapraw = 1;
- } else if (!strcasecmp(a->argv[2], "save")) {
+ o->txtestkey=0;
+ }
+ else if (!strcasecmp(argv[2],"dump")) pmrdump(o);
+ else if (!strcasecmp(argv[2],"nocap"))
+ {
+ ast_cli(fd,"File capture (trace) was rx=%d tx=%d and now off.\n",o->b.rxcap2,o->b.txcap2);
+ ast_cli(fd,"File capture (raw) was rx=%d tx=%d and now off.\n",o->b.rxcapraw,o->b.txcapraw);
+ o->b.rxcapraw=o->b.txcapraw=o->b.rxcap2=o->b.txcap2=o->pmrChan->b.rxCapture=o->pmrChan->b.txCapture=0;
+ if (frxcapraw) { fclose(frxcapraw); frxcapraw = NULL; }
+ if (frxcaptrace) { fclose(frxcaptrace); frxcaptrace = NULL; }
+ if (frxoutraw) { fclose(frxoutraw); frxoutraw = NULL; }
+ if (ftxcapraw) { fclose(ftxcapraw); ftxcapraw = NULL; }
+ if (ftxcaptrace) { fclose(ftxcaptrace); ftxcaptrace = NULL; }
+ if (ftxoutraw) { fclose(ftxoutraw); ftxoutraw = NULL; }
+ }
+ else if (!strcasecmp(argv[2],"rxtracecap"))
+ {
+ if (!frxcaptrace) frxcaptrace= fopen(RX_CAP_TRACE_FILE,"w");
+ ast_cli(fd,"Trace rx on.\n");
+ o->b.rxcap2=o->pmrChan->b.rxCapture=1;
+ }
+ else if (!strcasecmp(argv[2],"txtracecap"))
+ {
+ if (!ftxcaptrace) ftxcaptrace= fopen(TX_CAP_TRACE_FILE,"w");
+ ast_cli(fd,"Trace tx on.\n");
+ o->b.txcap2=o->pmrChan->b.txCapture=1;
+ }
+ else if (!strcasecmp(argv[2],"rxcap"))
+ {
+ if (!frxcapraw) frxcapraw = fopen(RX_CAP_RAW_FILE,"w");
+ ast_cli(fd,"cap rx raw on.\n");
+ o->b.rxcapraw=1;
+ }
+ else if (!strcasecmp(argv[2],"txcap"))
+ {
+ if (!ftxcapraw) ftxcapraw = fopen(TX_CAP_RAW_FILE,"w");
+ ast_cli(fd,"cap tx raw on.\n");
+ o->b.txcapraw=1;
+ }
+ else if (!strcasecmp(argv[2],"save"))
+ {
tune_write(o);
- ast_cli(a->fd, "Saved radio tuning settings to usbradio_tune.conf\n");
- } else
- return CLI_SHOWUSAGE;
- return CLI_SUCCESS;
+ ast_cli(fd,"Saved radio tuning settings to usbradio_tune_%s.conf\n",o->name);
+ }
+ else if (!strcasecmp(argv[2],"load"))
+ {
+ ast_mutex_lock(&o->eepromlock);
+ while(o->eepromctl)
+ {
+ ast_mutex_unlock(&o->eepromlock);
+ usleep(10000);
+ ast_mutex_lock(&o->eepromlock);
+ }
+ o->eepromctl = 1; /* request a load */
+ ast_mutex_unlock(&o->eepromlock);
+
+ ast_cli(fd,"Requesting loading of tuning settings from EEPROM for channel %s\n",o->name);
+ }
+ else
+ {
+ o->pmrChan->b.tuning=0;
+ return RESULT_SHOWUSAGE;
+ }
+ o->pmrChan->b.tuning=0;
+ return RESULT_SUCCESS;
}
/*
@@ -1604,491 +2516,599 @@ static char *handle_cli_radio_tune(struct ast_cli_entry *e, int cmd, struct ast_
*/
static int set_txctcss_level(struct chan_usbradio_pvt *o)
{
- if (o->txmixa == TX_OUT_LSD) {
- o->txmixaset = (151 * o->txctcssadj) / 1000;
+ if (o->txmixa == TX_OUT_LSD)
+ {
+// o->txmixaset=(151*o->txctcssadj) / 1000;
+ o->txmixaset=o->txctcssadj;
mixer_write(o);
mult_set(o);
- } else if (o->txmixb == TX_OUT_LSD) {
- o->txmixbset = (151 * o->txctcssadj) / 1000;
+ }
+ else if (o->txmixb == TX_OUT_LSD)
+ {
+// o->txmixbset=(151*o->txctcssadj) / 1000;
+ o->txmixbset=o->txctcssadj;
mixer_write(o);
mult_set(o);
- } else {
- *o->pmrChan->ptxCtcssAdjust = (o->txctcssadj * M_Q8) / 1000;
+ }
+ else
+ {
+ *o->pmrChan->ptxCtcssAdjust=(o->txctcssadj * M_Q8) / 1000;
}
return 0;
}
/*
CLI debugging on and off
*/
-static char *handle_cli_radio_set_debug_deprecated(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+static int radio_set_debug(int fd, int argc, char *argv[])
{
- struct chan_usbradio_pvt *o = NULL;
-
- switch (cmd) {
- case CLI_INIT:
- e->command = "radio set debug [off]";
- e->usage =
- "Usage: radio set debug [off]\n"
- " Enable/Disable radio debugging.\n";
- case CLI_GENERATE:
- return NULL;
- }
- if (a->argc < 3 || a->argc > 4)
- return CLI_SHOWUSAGE;
- if (a->argc == 4 && strncasecmp(a->argv[3], "off", 3))
- return CLI_SHOWUSAGE;
-
- o = find_desc(usbradio_active);
+ struct chan_usbradio_pvt *o = find_desc(usbradio_active);
- if (a->argc == 3)
- o->debuglevel = 1;
- else
- o->debuglevel = 0;
+ o->debuglevel=1;
+ ast_cli(fd,"usbradio debug on.\n");
+ return RESULT_SUCCESS;
+}
- ast_cli(a->fd, "USB Radio debugging %s.\n", o->debuglevel ? "enabled" : "disabled");
+static int radio_set_debug_off(int fd, int argc, char *argv[])
+{
+ struct chan_usbradio_pvt *o = find_desc(usbradio_active);
- return CLI_SUCCESS;
+ o->debuglevel=0;
+ ast_cli(fd,"usbradio debug off.\n");
+ return RESULT_SUCCESS;
}
-static char *handle_cli_radio_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+static int radio_active(int fd, int argc, char *argv[])
{
- struct chan_usbradio_pvt *o = NULL;
+ if (argc == 2)
+ ast_cli(fd, "active (command) USB Radio device is [%s]\n", usbradio_active);
+ else if (argc != 3)
+ return RESULT_SHOWUSAGE;
+ else {
+ struct chan_usbradio_pvt *o;
+ if (strcmp(argv[2], "show") == 0) {
+ for (o = usbradio_default.next; o; o = o->next)
+ ast_cli(fd, "device [%s] exists\n", o->name);
+ return RESULT_SUCCESS;
+ }
+ o = find_desc(argv[2]);
+ if (o == NULL)
+ ast_cli(fd, "No device [%s] exists\n", argv[2]);
+ else
+ {
+ struct chan_usbradio_pvt *ao;
+ for (ao = usbradio_default.next; ao && ao->name ; ao = ao->next)ao->pmrChan->b.radioactive=0;
+ usbradio_active = o->name;
+ o->pmrChan->b.radioactive=1;
+ }
+ }
+ return RESULT_SUCCESS;
+}
+/*
+ CLI debugging on and off
+*/
+static int radio_set_xpmr_debug(int fd, int argc, char *argv[])
+{
+ struct chan_usbradio_pvt *o = find_desc(usbradio_active);
- switch (cmd) {
- case CLI_INIT:
- e->command = "radio set debug {on|off}";
- e->usage =
- "Usage: radio set debug {on|off}\n"
- " Enable/Disable radio debugging.\n";
- case CLI_GENERATE:
- return NULL;
- }
+ if (argc == 4)
+ {
+ int i;
+ i = atoi(argv[3]);
+ if ((i >= 0) && (i <= 100))
+ {
+ o->pmrChan->tracelevel=i;
+ }
+ }
+ // add ability to set it for a number of frames after which it reverts
+ ast_cli(fd,"usbradio xdebug on tracelevel %i\n",o->pmrChan->tracelevel);
- if (a->argc != e->args)
- return CLI_SHOWUSAGE;
+ return RESULT_SUCCESS;
+}
- o = find_desc(usbradio_active);
- if (!strncasecmp(a->argv[e->args - 1], "on", 2))
- o->debuglevel = 1;
- else if (!strncasecmp(a->argv[e->args - 1], "off", 3))
- o->debuglevel = 0;
- else
- return CLI_SHOWUSAGE;
+static char key_usage[] =
+ "Usage: radio key\n"
+ " Simulates COR active.\n";
- ast_cli(a->fd, "USB Radio debugging %s.\n", o->debuglevel ? "enabled" : "disabled");
+static char unkey_usage[] =
+ "Usage: radio unkey\n"
+ " Simulates COR un-active.\n";
- return CLI_SUCCESS;
-}
+static char active_usage[] =
+ "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";
+/*
+radio tune 6 3000 measured tx value
+*/
+static char radio_tune_usage[] =
+ "Usage: radio tune <function>\n"
+ " rxnoise\n"
+ " rxvoice\n"
+ " rxtone\n"
+ " rxsquelch [newsetting]\n"
+ " txvoice [newsetting]\n"
+ " txtone [newsetting]\n"
+ " auxvoice [newsetting]\n"
+ " save (settings to tuning file)\n"
+ " load (tuning settings from EEPROM)\n"
+ "\n All [newsetting]'s are values 0-999\n\n";
+
+#ifndef NEW_ASTERISK
-static struct ast_cli_entry cli_radio_set_debug_deprecated = AST_CLI_DEFINE(handle_cli_radio_set_debug_deprecated, "Enable/Disable Radio Debugging");
static struct ast_cli_entry cli_usbradio[] = {
- AST_CLI_DEFINE(handle_cli_radio_key, "Simulate Rx Signal Present"),
- AST_CLI_DEFINE(handle_cli_radio_unkey, "Simulate Rx Signal Lusb"),
- AST_CLI_DEFINE(handle_cli_radio_tune, "Radio Tune"),
- AST_CLI_DEFINE(handle_cli_radio_set_debug, "Enable/Disable Radio Debugging", .deprecate_cmd = &cli_radio_set_debug_deprecated),
+ { { "radio", "key", NULL },
+ console_key, "Simulate Rx Signal Present",
+ key_usage, NULL, NULL},
+
+ { { "radio", "unkey", NULL },
+ console_unkey, "Simulate Rx Signal Lusb",
+ unkey_usage, NULL, NULL },
+
+ { { "radio", "tune", NULL },
+ radio_tune, "Radio Tune",
+ radio_tune_usage, NULL, NULL },
+
+ { { "radio", "set", "debug", NULL },
+ radio_set_debug, "Radio Debug",
+ radio_tune_usage, NULL, NULL },
+
+ { { "radio", "set", "debug", "off", NULL },
+ radio_set_debug_off, "Radio Debug",
+ radio_tune_usage, NULL, NULL },
+
+ { { "radio", "active", NULL },
+ radio_active, "Change commanded device",
+ active_usage, NULL, NULL },
+
+ { { "radio", "set", "xdebug", NULL },
+ radio_set_xpmr_debug, "Radio set xpmr debug level",
+ active_usage, NULL, NULL },
+
};
+#endif
/*
* store the callerid components
*/
#if 0
-static void store_callerid(struct chan_usbradio_pvt *o, const char *s)
+static void store_callerid(struct chan_usbradio_pvt *o, char *s)
{
ast_callerid_split(s, o->cid_name, sizeof(o->cid_name), o->cid_num, sizeof(o->cid_num));
}
#endif
-static void store_rxdemod(struct chan_usbradio_pvt *o, const char *s)
+static void store_rxdemod(struct chan_usbradio_pvt *o, char *s)
{
- if (!strcasecmp(s, "no")) {
+ if (!strcasecmp(s,"no")){
o->rxdemod = RX_AUDIO_NONE;
- } else if (!strcasecmp(s, "speaker")) {
+ }
+ else if (!strcasecmp(s,"speaker")){
o->rxdemod = RX_AUDIO_SPEAKER;
- } else if (!strcasecmp(s, "flat")) {
+ }
+ else if (!strcasecmp(s,"flat")){
o->rxdemod = RX_AUDIO_FLAT;
- } else {
- ast_log(LOG_WARNING, "Unrecognized rxdemod parameter: %s\n", s);
+ }
+ else {
+ ast_log(LOG_WARNING,"Unrecognized rxdemod parameter: %s\n",s);
}
- ast_debug(4, "set rxdemod = %s\n", s);
+ //ast_log(LOG_WARNING, "set rxdemod = %s\n", s);
}
-static void store_txmixa(struct chan_usbradio_pvt *o, const char *s)
+static void store_txmixa(struct chan_usbradio_pvt *o, char *s)
{
- if (!strcasecmp(s, "no"))
+ if (!strcasecmp(s,"no")){
o->txmixa = TX_OUT_OFF;
-
- else if (!strcasecmp(s, "voice"))
+ }
+ else if (!strcasecmp(s,"voice")){
o->txmixa = TX_OUT_VOICE;
- else if (!strcasecmp(s, "tone"))
+ }
+ else if (!strcasecmp(s,"tone")){
o->txmixa = TX_OUT_LSD;
- else if (!strcasecmp(s, "composite"))
+ }
+ else if (!strcasecmp(s,"composite")){
o->txmixa = TX_OUT_COMPOSITE;
- else if (!strcasecmp(s, "auxvoice"))
- o->txmixb = TX_OUT_AUX;
- else
- ast_log(LOG_WARNING, "Unrecognized txmixa parameter: %s\n", s);
+ }
+ else if (!strcasecmp(s,"auxvoice")){
+ o->txmixa = TX_OUT_AUX;
+ }
+ else {
+ ast_log(LOG_WARNING,"Unrecognized txmixa parameter: %s\n",s);
+ }
- ast_debug(4, "set txmixa = %s\n", s);
+ //ast_log(LOG_WARNING, "set txmixa = %s\n", s);
}
-static void store_txmixb(struct chan_usbradio_pvt *o, const char *s)
+static void store_txmixb(struct chan_usbradio_pvt *o, char *s)
{
- if (!strcasecmp(s, "no"))
+ if (!strcasecmp(s,"no")){
o->txmixb = TX_OUT_OFF;
- else if (!strcasecmp(s, "voice"))
+ }
+ else if (!strcasecmp(s,"voice")){
o->txmixb = TX_OUT_VOICE;
- else if (!strcasecmp(s, "tone"))
+ }
+ else if (!strcasecmp(s,"tone")){
o->txmixb = TX_OUT_LSD;
- else if (!strcasecmp(s, "composite"))
+ }
+ else if (!strcasecmp(s,"composite")){
o->txmixb = TX_OUT_COMPOSITE;
- else if (!strcasecmp(s, "auxvoice"))
+ }
+ else if (!strcasecmp(s,"auxvoice")){
o->txmixb = TX_OUT_AUX;
- else
- ast_log(LOG_WARNING, "Unrecognized txmixb parameter: %s\n", s);
+ }
+ else {
+ ast_log(LOG_WARNING,"Unrecognized txmixb parameter: %s\n",s);
+ }
- ast_debug(4, "set txmixb = %s\n", s);
+ //ast_log(LOG_WARNING, "set txmixb = %s\n", s);
}
-
-static void store_rxcdtype(struct chan_usbradio_pvt *o, const char *s)
+/*
+*/
+static void store_rxcdtype(struct chan_usbradio_pvt *o, char *s)
{
- if (!strcasecmp(s, "no"))
+ if (!strcasecmp(s,"no")){
o->rxcdtype = CD_IGNORE;
- else if (!strcasecmp(s, "usb"))
+ }
+ else if (!strcasecmp(s,"usb")){
o->rxcdtype = CD_HID;
- else if (!strcasecmp(s, "dsp"))
+ }
+ else if (!strcasecmp(s,"dsp")){
o->rxcdtype = CD_XPMR_NOISE;
- else if (!strcasecmp(s, "vox"))
+ }
+ else if (!strcasecmp(s,"vox")){
o->rxcdtype = CD_XPMR_VOX;
- else if (!strcasecmp(s, "usbinvert"))
+ }
+ else if (!strcasecmp(s,"usbinvert")){
o->rxcdtype = CD_HID_INVERT;
- else
- ast_log(LOG_WARNING, "Unrecognized rxcdtype parameter: %s\n", s);
+ }
+ else {
+ ast_log(LOG_WARNING,"Unrecognized rxcdtype parameter: %s\n",s);
+ }
- ast_debug(4, "set rxcdtype = %s\n", s);
+ //ast_log(LOG_WARNING, "set rxcdtype = %s\n", s);
}
-
-static void store_rxsdtype(struct chan_usbradio_pvt *o, const char *s)
+/*
+*/
+static void store_rxsdtype(struct chan_usbradio_pvt *o, char *s)
{
- if (!strcasecmp(s, "no") || !strcasecmp(s, "SD_IGNORE"))
+ if (!strcasecmp(s,"no") || !strcasecmp(s,"SD_IGNORE")){
o->rxsdtype = SD_IGNORE;
- else if (!strcasecmp(s, "usb") || !strcasecmp(s, "SD_HID"))
+ }
+ else if (!strcasecmp(s,"usb") || !strcasecmp(s,"SD_HID")){
o->rxsdtype = SD_HID;
- else if (!strcasecmp(s, "usbinvert") || !strcasecmp(s, "SD_HID_INVERT"))
+ }
+ else if (!strcasecmp(s,"usbinvert") || !strcasecmp(s,"SD_HID_INVERT")){
o->rxsdtype = SD_HID_INVERT;
- else if (!strcasecmp(s, "software") || !strcasecmp(s, "SD_XPMR"))
+ }
+ else if (!strcasecmp(s,"software") || !strcasecmp(s,"SD_XPMR")){
o->rxsdtype = SD_XPMR;
- else
- ast_log(LOG_WARNING, "Unrecognized rxsdtype parameter: %s\n", s);
+ }
+ else {
+ ast_log(LOG_WARNING,"Unrecognized rxsdtype parameter: %s\n",s);
+ }
- ast_debug(4, "set rxsdtype = %s\n", s);
+ //ast_log(LOG_WARNING, "set rxsdtype = %s\n", s);
}
-
-static void store_rxgain(struct chan_usbradio_pvt *o, const char *s)
+/*
+*/
+static void store_rxgain(struct chan_usbradio_pvt *o, char *s)
{
float f;
- if (sscanf(s, "%f", &f) == 1)
- o->rxgain = f;
- ast_debug(4, "set rxgain = %f\n", f);
+ sscanf(s,"%f",&f);
+ o->rxgain = f;
+ //ast_log(LOG_WARNING, "set rxgain = %f\n", f);
}
-
-static void store_rxvoiceadj(struct chan_usbradio_pvt *o, const char *s)
+/*
+*/
+static void store_rxvoiceadj(struct chan_usbradio_pvt *o, char *s)
{
float f;
- if (sscanf(s, "%f", &f) == 1)
- o->rxvoiceadj = f;
- ast_debug(4, "set rxvoiceadj = %f\n", f);
+ sscanf(s,"%f",&f);
+ o->rxvoiceadj = f;
+ //ast_log(LOG_WARNING, "set rxvoiceadj = %f\n", f);
}
-
-static void store_rxctcssadj(struct chan_usbradio_pvt *o, const char *s)
+/*
+*/
+static void store_rxctcssadj(struct chan_usbradio_pvt *o, char *s)
{
float f;
- if (sscanf(s, "%f", &f) == 1)
- o->rxctcssadj = f;
- ast_debug(4, "set rxctcssadj = %f\n", f);
+ sscanf(s,"%f",&f);
+ o->rxctcssadj = f;
+ //ast_log(LOG_WARNING, "set rxctcssadj = %f\n", f);
}
-
-static void store_txtoctype(struct chan_usbradio_pvt *o, const char *s)
+/*
+*/
+static void store_txtoctype(struct chan_usbradio_pvt *o, char *s)
{
- if (!strcasecmp(s, "no") || !strcasecmp(s, "TOC_NONE"))
+ if (!strcasecmp(s,"no") || !strcasecmp(s,"TOC_NONE")){
o->txtoctype = TOC_NONE;
- else if (!strcasecmp(s, "phase") || !strcasecmp(s, "TOC_PHASE"))
+ }
+ else if (!strcasecmp(s,"phase") || !strcasecmp(s,"TOC_PHASE")){
o->txtoctype = TOC_PHASE;
- else if (!strcasecmp(s, "notone") || !strcasecmp(s, "TOC_NOTONE"))
+ }
+ else if (!strcasecmp(s,"notone") || !strcasecmp(s,"TOC_NOTONE")){
o->txtoctype = TOC_NOTONE;
- else
- ast_log(LOG_WARNING, "Unrecognized txtoctype parameter: %s\n", s);
-
- ast_debug(4, "set txtoctype = %s\n", s);
-}
-
-static void store_rxctcssfreq(struct chan_usbradio_pvt *o, const char *s)
-{
- float f;
- if (sscanf(s, "%f", &f) == 1)
- o->rxctcssfreq = f;
- ast_debug(4, "set rxctcss = %f\n", f);
-}
-
-static void store_txctcssfreq(struct chan_usbradio_pvt *o, const char *s)
-{
- float f;
- if (sscanf(s, "%f", &f) == 1)
- o->txctcssfreq = f;
- ast_debug(4, "set txctcss = %f\n", f);
+ }
+ else {
+ ast_log(LOG_WARNING,"Unrecognized txtoctype parameter: %s\n",s);
+ }
}
-
-static void tune_txoutput(struct chan_usbradio_pvt *o, int value)
+/*
+*/
+static void tune_txoutput(struct chan_usbradio_pvt *o, int value, int fd)
{
- o->txtestkey = 1;
- o->pmrChan->txPttIn = 1;
-
-#if 0
- /* generate 1KHz tone at 7200 peak */
- o->pmrChan->spsSigGen1->freq = 10000;
- o->pmrChan->spsSigGen1->outputGain = (float)(0.22 * M_Q8);
- o->pmrChan->b.startSpecialTone = 1;
-#endif
-
- TxTestTone(o->pmrChan, 1);
-
+ o->txtestkey=1;
+ o->pmrChan->txPttIn=1;
+ TxTestTone(o->pmrChan, 1); // generate 1KHz tone at 7200 peak
+ if (fd > 0) ast_cli(fd,"Tone output starting on channel %s...\n",o->name);
usleep(5000000);
- /* o->pmrChan->b.stopSpecialTone = 1; */
- usleep(100000);
-
TxTestTone(o->pmrChan, 0);
-
- o->pmrChan->txPttIn = 0;
- o->txtestkey = 0;
+ if (fd > 0) ast_cli(fd,"Tone output ending on channel %s...\n",o->name);
+ o->pmrChan->txPttIn=0;
+ o->txtestkey=0;
}
-
-static void tune_rxinput(struct chan_usbradio_pvt *o)
+/*
+*/
+static void tune_rxinput(int fd, struct chan_usbradio_pvt *o)
{
- const int target = 23000;
- const int tolerance = 2000;
- const int settingmin = 1;
- const int settingstart = 2;
- const int maxtries = 12;
+ const int target=23000;
+ const int tolerance=2000;
+ const int settingmin=1;
+ const int settingstart=2;
+ const int maxtries=12;
float settingmax;
- int setting = 0, tries = 0, tmpdiscfactor, meas;
- int tunetype = 0;
+ int setting=0, tries=0, tmpdiscfactor, meas;
+ int tunetype=0;
settingmax = o->micmax;
- if (o->pmrChan->rxDemod)
- tunetype = 1;
+ if(o->pmrChan->rxDemod)tunetype=1;
+ o->pmrChan->b.tuning=1;
setting = settingstart;
- while (tries < maxtries) {
- setamixer(o->devicenum, MIXER_PARAM_MIC_CAPTURE_VOL, setting, 0);
- setamixer(o->devicenum, MIXER_PARAM_MIC_BOOST, o->rxboostset, 0);
+ ast_cli(fd,"tune rxnoise maxtries=%i, target=%i, tolerance=%i\n",maxtries,target,tolerance);
+
+ while(tries<maxtries)
+ {
+ setamixer(o->devicenum,MIXER_PARAM_MIC_CAPTURE_VOL,setting,0);
+ setamixer(o->devicenum,MIXER_PARAM_MIC_BOOST,o->rxboostset,0);
+
usleep(100000);
- if (o->rxcdtype == CD_XPMR_VOX || o->rxdemod == RX_AUDIO_SPEAKER) {
- ast_debug(4, "Measure Direct Input\n");
+ if(o->rxcdtype!=CD_XPMR_NOISE || o->rxdemod==RX_AUDIO_SPEAKER)
+ {
+ // printf("Measure Direct Input\n");
o->pmrChan->spsMeasure->source = o->pmrChan->spsRx->source;
- o->pmrChan->spsMeasure->discfactor = 1000;
- o->pmrChan->spsMeasure->enabled = 1;
+ o->pmrChan->spsMeasure->discfactor=2000;
+ o->pmrChan->spsMeasure->enabled=1;
o->pmrChan->spsMeasure->amax = o->pmrChan->spsMeasure->amin = 0;
usleep(400000);
- meas = o->pmrChan->spsMeasure->apeak;
- o->pmrChan->spsMeasure->enabled = 0;
- } else {
- ast_debug(4, "Measure HF Noise\n");
- tmpdiscfactor = o->pmrChan->spsRx->discfactor;
- o->pmrChan->spsRx->discfactor = (i16)1000;
- o->pmrChan->spsRx->discounteru = o->pmrChan->spsRx->discounterl = 0;
- o->pmrChan->spsRx->amax = o->pmrChan->spsRx->amin = 0;
+ meas=o->pmrChan->spsMeasure->apeak;
+ o->pmrChan->spsMeasure->enabled=0;
+ }
+ else
+ {
+ // printf("Measure HF Noise\n");
+ tmpdiscfactor=o->pmrChan->spsRx->discfactor;
+ o->pmrChan->spsRx->discfactor=(i16)2000;
+ o->pmrChan->spsRx->discounteru=o->pmrChan->spsRx->discounterl=0;
+ o->pmrChan->spsRx->amax=o->pmrChan->spsRx->amin=0;
usleep(200000);
- meas = o->pmrChan->rxRssi;
- o->pmrChan->spsRx->discfactor = tmpdiscfactor;
- o->pmrChan->spsRx->discounteru = o->pmrChan->spsRx->discounterl = 0;
- o->pmrChan->spsRx->amax = o->pmrChan->spsRx->amin = 0;
- }
- if (!meas)
- meas++;
- ast_log(LOG_NOTICE, "tries=%d, setting=%d, meas=%i\n", tries, setting, meas);
-
- if ( meas < (target - tolerance) || meas > (target + tolerance) || tries < 3)
- setting = setting * target / meas;
- else if (tries > 4 && meas > (target - tolerance) && meas < (target + tolerance) )
+ meas=o->pmrChan->rxRssi;
+ o->pmrChan->spsRx->discfactor=tmpdiscfactor;
+ o->pmrChan->spsRx->discounteru=o->pmrChan->spsRx->discounterl=0;
+ o->pmrChan->spsRx->amax=o->pmrChan->spsRx->amin=0;
+ }
+ if(!meas)meas++;
+ ast_cli(fd,"tries=%i, setting=%i, meas=%i\n",tries,setting,meas);
+
+ if( meas<(target-tolerance) || meas>(target+tolerance) || tries<3){
+ setting=setting*target/meas;
+ }
+ else if(tries>4 && meas>(target-tolerance) && meas<(target+tolerance) )
+ {
break;
+ }
- if (setting < settingmin)
- setting = settingmin;
- else if (setting > settingmax)
- setting = settingmax;
+ if(setting<settingmin)setting=settingmin;
+ else if(setting>settingmax)setting=settingmax;
tries++;
}
- ast_log(LOG_NOTICE, "DONE tries=%d, setting=%d, meas=%i\n", tries,
- (setting * 1000) / o->micmax, meas);
- if (meas < (target - tolerance) || meas > (target + tolerance))
- ast_log(LOG_NOTICE, "ERROR: RX INPUT ADJUST FAILED.\n");
- else {
- ast_log(LOG_NOTICE, "INFO: RX INPUT ADJUST SUCCESS.\n");
- o->rxmixerset = (setting * 1000) / o->micmax;
+ ast_cli(fd,"DONE tries=%i, setting=%i, meas=%i\n",tries,
+ (setting * 1000) / o->micmax,meas);
+ if( meas<(target-tolerance) || meas>(target+tolerance) ){
+ ast_cli(fd,"ERROR: RX INPUT ADJUST FAILED.\n");
+ }else{
+ ast_cli(fd,"INFO: RX INPUT ADJUST SUCCESS.\n");
+ o->rxmixerset=(setting * 1000) / o->micmax;
}
+ o->pmrChan->b.tuning=0;
}
/*
*/
-static void tune_rxvoice(struct chan_usbradio_pvt *o)
+static void tune_rxvoice(int fd, struct chan_usbradio_pvt *o)
{
- const int target = 7200; /* peak */
- const int tolerance = 360; /* peak to peak */
- const float settingmin = 0.1;
- const float settingmax = 4;
- const float settingstart = 1;
- const int maxtries = 12;
+ const int target=7200; // peak
+ const int tolerance=360; // peak to peak
+ const float settingmin=0.1;
+ const float settingmax=4;
+ const float settingstart=1;
+ const int maxtries=12;
float setting;
- int tries = 0, meas;
-
- ast_log(LOG_NOTICE, "INFO: RX VOICE ADJUST START.\n");
- ast_log(LOG_NOTICE, "target=%d tolerance=%d\n", target, tolerance);
+ int tries=0, meas;
- if (!o->pmrChan->spsMeasure)
- ast_log(LOG_ERROR, "NO MEASURE BLOCK.\n");
+ ast_cli(fd,"INFO: RX VOICE ADJUST START.\n");
+ ast_cli(fd,"target=%i tolerance=%i \n",target,tolerance);
- if (!o->pmrChan->spsMeasure->source || !o->pmrChan->prxVoiceAdjust )
- ast_log(LOG_ERROR, "NO SOURCE OR MEASURE SETTING.\n");
+ o->pmrChan->b.tuning=1;
+ if(!o->pmrChan->spsMeasure)
+ ast_cli(fd,"ERROR: NO MEASURE BLOCK.\n");
- o->pmrChan->spsMeasure->source = o->pmrChan->spsRxOut->sink;
- o->pmrChan->spsMeasure->enabled = 1;
- o->pmrChan->spsMeasure->discfactor = 1000;
+ if(!o->pmrChan->spsMeasure->source || !o->pmrChan->prxVoiceAdjust )
+ ast_cli(fd,"ERROR: NO SOURCE OR MEASURE SETTING.\n");
+ o->pmrChan->spsMeasure->source=o->pmrChan->spsRxOut->sink;
+ o->pmrChan->spsMeasure->enabled=1;
+ o->pmrChan->spsMeasure->discfactor=1000;
+
setting=settingstart;
- ast_debug(4, "ERROR: NO MEASURE BLOCK.\n");
+ // ast_cli(fd,"ERROR: NO MEASURE BLOCK.\n");
- while (tries < maxtries) {
- *(o->pmrChan->prxVoiceAdjust) = setting * M_Q8;
+ while(tries<maxtries)
+ {
+ *(o->pmrChan->prxVoiceAdjust)=setting*M_Q8;
usleep(10000);
o->pmrChan->spsMeasure->amax = o->pmrChan->spsMeasure->amin = 0;
usleep(1000000);
meas = o->pmrChan->spsMeasure->apeak;
- ast_log(LOG_NOTICE, "tries=%d, setting=%f, meas=%i\n", tries, setting, meas);
+ ast_cli(fd,"tries=%i, setting=%f, meas=%i\n",tries,setting,meas);
- if (meas < (target - tolerance) || meas > (target + tolerance) || tries < 3)
- setting = setting * target / meas;
- else if (tries > 4 && meas > (target - tolerance) && meas < (target + tolerance))
+ if( meas<(target-tolerance) || meas>(target+tolerance) || tries<3){
+ setting=setting*target/meas;
+ }
+ else if(tries>4 && meas>(target-tolerance) && meas<(target+tolerance) )
+ {
break;
- if (setting < settingmin)
- setting = settingmin;
- else if (setting > settingmax)
- setting = settingmax;
+ }
+ if(setting<settingmin)setting=settingmin;
+ else if(setting>settingmax)setting=settingmax;
tries++;
}
- o->pmrChan->spsMeasure->enabled = 0;
+ o->pmrChan->spsMeasure->enabled=0;
- ast_log(LOG_NOTICE, "DONE tries=%d, setting=%f, meas=%f\n", tries, setting, (float)meas);
- if (meas < (target - tolerance) || meas > (target + tolerance))
- ast_log(LOG_ERROR, "RX VOICE GAIN ADJUST FAILED.\n");
- else {
- ast_log(LOG_NOTICE, "RX VOICE GAIN ADJUST SUCCESS.\n");
- o->rxvoiceadj = setting;
+ ast_cli(fd,"DONE tries=%i, setting=%f, meas=%f\n",tries,setting,(float)meas);
+ if( meas<(target-tolerance) || meas>(target+tolerance) ){
+ ast_cli(fd,"ERROR: RX VOICE GAIN ADJUST FAILED.\n");
+ }else{
+ ast_cli(fd,"INFO: RX VOICE GAIN ADJUST SUCCESS.\n");
+ o->rxvoiceadj=setting;
}
+ o->pmrChan->b.tuning=0;
}
-
-static void tune_rxctcss(struct chan_usbradio_pvt *o)
+/*
+*/
+static void tune_rxctcss(int fd, struct chan_usbradio_pvt *o)
{
- const int target = 4096;
- const int tolerance = 100;
- const float settingmin = 0.1;
- const float settingmax = 4;
- const float settingstart = 1;
- const int maxtries = 12;
+ const int target=2400; // was 4096 pre 20080205
+ const int tolerance=100;
+ const float settingmin=0.1;
+ const float settingmax=8;
+ const float settingstart=1;
+ const int maxtries=12;
float setting;
- int tries = 0, meas;
+ int tries=0, meas;
- ast_log(LOG_NOTICE, "RX CTCSS ADJUST START.\n");
- ast_log(LOG_NOTICE, "target=%d tolerance=%d \n", target, tolerance);
+ ast_cli(fd,"INFO: RX CTCSS ADJUST START.\n");
+ ast_cli(fd,"target=%i tolerance=%i \n",target,tolerance);
- o->pmrChan->spsMeasure->source = o->pmrChan->prxCtcssMeasure;
- o->pmrChan->spsMeasure->discfactor = 400;
- o->pmrChan->spsMeasure->enabled = 1;
+ o->pmrChan->b.tuning=1;
+ o->pmrChan->spsMeasure->source=o->pmrChan->prxCtcssMeasure;
+ o->pmrChan->spsMeasure->discfactor=400;
+ o->pmrChan->spsMeasure->enabled=1;
- setting = settingstart;
+ setting=settingstart;
- while (tries < maxtries) {
- *(o->pmrChan->prxCtcssAdjust) = setting * M_Q8;
+ while(tries<maxtries)
+ {
+ *(o->pmrChan->prxCtcssAdjust)=setting*M_Q8;
usleep(10000);
o->pmrChan->spsMeasure->amax = o->pmrChan->spsMeasure->amin = 0;
usleep(500000);
meas = o->pmrChan->spsMeasure->apeak;
- ast_debug(4, "tries=%d, setting=%f, meas=%i\n", tries, setting, meas);
+ ast_cli(fd,"tries=%i, setting=%f, meas=%i\n",tries,setting,meas);
- if (meas < (target - tolerance) || meas > (target + tolerance) || tries < 3)
- setting = setting * target / meas;
- else if (tries > 4 && meas > (target - tolerance) && meas < (target + tolerance))
+ if( meas<(target-tolerance) || meas>(target+tolerance) || tries<3){
+ setting=setting*target/meas;
+ }
+ else if(tries>4 && meas>(target-tolerance) && meas<(target+tolerance) )
+ {
break;
- if (setting < settingmin)
- setting = settingmin;
- else if (setting > settingmax)
- setting = settingmax;
+ }
+ if(setting<settingmin)setting=settingmin;
+ else if(setting>settingmax)setting=settingmax;
tries++;
}
- o->pmrChan->spsMeasure->enabled = 0;
- ast_debug(4, "DONE tries=%d, setting=%f, meas=%f\n", tries, setting, (float)meas);
- if (meas < (target - tolerance) || meas > (target + tolerance))
- ast_log(LOG_ERROR, "RX CTCSS GAIN ADJUST FAILED.\n");
- else {
- ast_log(LOG_NOTICE, "RX CTCSS GAIN ADJUST SUCCESS.\n");
- o->rxctcssadj = setting;
+ o->pmrChan->spsMeasure->enabled=0;
+ ast_cli(fd,"DONE tries=%i, setting=%f, meas=%f\n",tries,setting,(float)meas);
+ if( meas<(target-tolerance) || meas>(target+tolerance) ){
+ ast_cli(fd,"ERROR: RX CTCSS GAIN ADJUST FAILED.\n");
+ }else{
+ ast_cli(fd,"INFO: RX CTCSS GAIN ADJUST SUCCESS.\n");
+ o->rxctcssadj=setting;
}
+ o->pmrChan->b.tuning=0;
}
/*
- this file then is included in chan_usbradio.conf
- #include /etc/asterisk/usbradio_tune.conf
+ after radio tune is performed data is serialized here
*/
static void tune_write(struct chan_usbradio_pvt *o)
{
FILE *fp;
-
- fp = fopen("/etc/asterisk/usbradio_tune.conf", "w");
-
- if (!strcmp(o->name, "dsp"))
- fprintf(fp, "[general]\n");
- else
- fprintf(fp, "[%s]\n", o->name);
-
- fprintf(fp, "; name=%s\n", o->name);
- fprintf(fp, "; devicenum=%d\n", o->devicenum);
-
- fprintf(fp, "rxmixerset=%d\n", o->rxmixerset);
- fprintf(fp, "rxboostset=%d\n", o->rxboostset);
- fprintf(fp, "txmixaset=%d\n", o->txmixaset);
- fprintf(fp, "txmixbset=%d\n", o->txmixbset);
-
- fprintf(fp, "rxvoiceadj=%f\n", o->rxvoiceadj);
- fprintf(fp, "rxctcssadj=%f\n", o->rxctcssadj);
- fprintf(fp, "txctcssadj=%d\n", o->txctcssadj);
-
- fprintf(fp, "rxsquelchadj=%d\n", o->rxsquelchadj);
+ char fname[200];
+
+ snprintf(fname,sizeof(fname) - 1,"/etc/asterisk/usbradio_tune_%s.conf",o->name);
+ fp = fopen(fname,"w");
+
+ fprintf(fp,"[%s]\n",o->name);
+
+ fprintf(fp,"; name=%s\n",o->name);
+ fprintf(fp,"; devicenum=%i\n",o->devicenum);
+ fprintf(fp,"devstr=%s\n",o->devstr);
+ fprintf(fp,"rxmixerset=%i\n",o->rxmixerset);
+ fprintf(fp,"txmixaset=%i\n",o->txmixaset);
+ fprintf(fp,"txmixbset=%i\n",o->txmixbset);
+ fprintf(fp,"rxvoiceadj=%f\n",o->rxvoiceadj);
+ fprintf(fp,"rxctcssadj=%f\n",o->rxctcssadj);
+ fprintf(fp,"txctcssadj=%i\n",o->txctcssadj);
+ fprintf(fp,"rxsquelchadj=%i\n",o->rxsquelchadj);
fclose(fp);
-}
+ if(o->wanteeprom)
+ {
+ ast_mutex_lock(&o->eepromlock);
+ while(o->eepromctl)
+ {
+ ast_mutex_unlock(&o->eepromlock);
+ usleep(10000);
+ ast_mutex_lock(&o->eepromlock);
+ }
+ o->eeprom[EEPROM_RXMIXERSET] = o->rxmixerset;
+ o->eeprom[EEPROM_TXMIXASET] = o->txmixaset;
+ o->eeprom[EEPROM_TXMIXBSET] = o->txmixbset;
+ memcpy(&o->eeprom[EEPROM_RXVOICEADJ],&o->rxvoiceadj,sizeof(float));
+ memcpy(&o->eeprom[EEPROM_RXCTCSSADJ],&o->rxctcssadj,sizeof(float));
+ o->eeprom[EEPROM_TXCTCSSADJ] = o->txctcssadj;
+ o->eeprom[EEPROM_RXSQUELCHADJ] = o->rxsquelchadj;
+ o->eepromctl = 2; /* request a write */
+ ast_mutex_unlock(&o->eepromlock);
+ }
+}
+//
static void mixer_write(struct chan_usbradio_pvt *o)
{
- setamixer(o->devicenum, MIXER_PARAM_MIC_PLAYBACK_SW, 0, 0);
- setamixer(o->devicenum, MIXER_PARAM_MIC_PLAYBACK_VOL, 0, 0);
- setamixer(o->devicenum, MIXER_PARAM_SPKR_PLAYBACK_SW, 1, 0);
- setamixer(o->devicenum, MIXER_PARAM_SPKR_PLAYBACK_VOL,
+ setamixer(o->devicenum,MIXER_PARAM_MIC_PLAYBACK_SW,0,0);
+ setamixer(o->devicenum,MIXER_PARAM_MIC_PLAYBACK_VOL,0,0);
+ setamixer(o->devicenum,MIXER_PARAM_SPKR_PLAYBACK_SW,1,0);
+ setamixer(o->devicenum,MIXER_PARAM_SPKR_PLAYBACK_VOL,
o->txmixaset * o->spkrmax / 1000,
o->txmixbset * o->spkrmax / 1000);
- setamixer(o->devicenum, MIXER_PARAM_MIC_CAPTURE_VOL,
- o->rxmixerset * o->micmax / 1000, 0);
- setamixer(o->devicenum, MIXER_PARAM_MIC_BOOST, o->rxboostset, 0);
- setamixer(o->devicenum, MIXER_PARAM_MIC_CAPTURE_SW, 1, 0);
+ setamixer(o->devicenum,MIXER_PARAM_MIC_CAPTURE_VOL,
+ o->rxmixerset * o->micmax / 1000,0);
+ setamixer(o->devicenum,MIXER_PARAM_MIC_BOOST,o->rxboostset,0);
+ setamixer(o->devicenum,MIXER_PARAM_MIC_CAPTURE_SW,1,0);
}
/*
adjust dsp multiplier to add resolution to tx level adjustment
@@ -2096,43 +3116,121 @@ static void mixer_write(struct chan_usbradio_pvt *o)
static void mult_set(struct chan_usbradio_pvt *o)
{
- if (o->pmrChan->spsTxOutA) {
+ if(o->pmrChan->spsTxOutA) {
o->pmrChan->spsTxOutA->outputGain =
mult_calc((o->txmixaset * 152) / 1000);
}
- if (o->pmrChan->spsTxOutB) {
+ if(o->pmrChan->spsTxOutB){
o->pmrChan->spsTxOutB->outputGain =
mult_calc((o->txmixbset * 152) / 1000);
}
}
-/*
- * input 0 - 151 outputs are pot and multiplier
- */
+//
+// input 0 - 151 outputs are pot and multiplier
+//
static int mult_calc(int value)
{
- const int multx = M_Q8;
- int pot, mult;
+ const int multx=M_Q8;
+ int pot,mult;
- pot= ((int)(value / 4) * 4) + 2;
- mult = multx - ((multx * (3 - (value % 4))) / (pot + 2));
- return mult;
+ pot=((int)(value/4)*4)+2;
+ mult = multx-( ( multx * (3-(value%4)) ) / (pot+2) );
+ return(mult);
}
-#define pd(x) ast_debug(4, #x" = %d\n", x)
-#define pp(x) ast_debug(4, #x" = %p\n", x)
-#define ps(x) ast_debug(4, #x" = %s\n", x)
-#define pf(x) ast_debug(4, #x" = %f\n", x)
+#define pd(x) {printf(#x" = %d\n",x);}
+#define pp(x) {printf(#x" = %p\n",x);}
+#define ps(x) {printf(#x" = %s\n",x);}
+#define pf(x) {printf(#x" = %f\n",x);}
+
+
+#if 0
+/*
+ do hid output if only requirement is ptt out
+ this give fastest performance with least overhead
+ where gpio inputs are not required.
+*/
+
+static int usbhider(struct chan_usbradio_pvt *o, int opt)
+{
+ unsigned char buf[4];
+ char lastrx, txtmp;
+
+ if(opt)
+ {
+ struct usb_device *usb_dev;
+
+ usb_dev = hid_device_init(o->devstr);
+ if (usb_dev == NULL) {
+ ast_log(LOG_ERROR,"USB HID device not found\n");
+ return -1;
+ }
+ o->usb_handle = usb_open(usb_dev);
+ if (o->usb_handle == NULL) {
+ ast_log(LOG_ERROR,"Not able to open USB device\n");
+ return -1;
+ }
+ if (usb_claim_interface(o->usb_handle,C108_HID_INTERFACE) < 0)
+ {
+ if (usb_detach_kernel_driver_np(o->usb_handle,C108_HID_INTERFACE) < 0) {
+ ast_log(LOG_ERROR,"Not able to detach the USB device\n");
+ return -1;
+ }
+ if (usb_claim_interface(o->usb_handle,C108_HID_INTERFACE) < 0) {
+ ast_log(LOG_ERROR,"Not able to claim the USB device\n");
+ return -1;
+ }
+ }
+
+ memset(buf,0,sizeof(buf));
+ buf[2] = o->hid_gpio_ctl;
+ buf[1] = 0;
+ hid_set_outputs(o->usb_handle,buf);
+ memcpy(bufsave,buf,sizeof(buf));
+
+ buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
+ o->lasttx=0;
+ }
+
+ /* if change in tx state as controlled by xpmr */
+ txtmp=o->pmrChan->txPttOut;
+
+ if (o->lasttx != txtmp)
+ {
+ o->pmrChan->txPttHid=o->lasttx = txtmp;
+ if(o->debuglevel)printf("usbhid: tx set to %d\n",txtmp);
+ buf[o->hid_gpio_loc] = 0;
+ if (!o->invertptt)
+ {
+ if (txtmp) buf[o->hid_gpio_loc] = o->hid_io_ptt;
+ }
+ else
+ {
+ if (!txtmp) buf[o->hid_gpio_loc] = o->hid_io_ptt;
+ }
+ buf[o->hid_gpio_ctl_loc] = o->hid_gpio_ctl;
+ hid_set_outputs(o->usb_handle,buf);
+ }
+
+ return(0);
+}
+#endif
/*
*/
static void pmrdump(struct chan_usbradio_pvt *o)
{
t_pmr_chan *p;
+ int i;
- p = o->pmrChan;
+ p=o->pmrChan;
- ast_debug(4, "odump()\n");
+ printf("\nodump()\n");
pd(o->devicenum);
+ ps(o->devstr);
+
+ pd(o->micmax);
+ pd(o->spkrmax);
pd(o->rxdemod);
pd(o->rxcdtype);
@@ -2140,10 +3238,27 @@ static void pmrdump(struct chan_usbradio_pvt *o)
pd(o->txtoctype);
pd(o->rxmixerset);
+ pd(o->rxboostset);
+
pf(o->rxvoiceadj);
pf(o->rxctcssadj);
pd(o->rxsquelchadj);
-
+
+ ps(o->txctcssdefault);
+ ps(o->txctcssfreq);
+
+ pd(o->numrxctcssfreqs);
+ if(o->numrxctcssfreqs>0)
+ {
+ for(i=0;i<o->numrxctcssfreqs;i++)
+ {
+ printf(" %i = %s %s\n",i,o->rxctcss[i],o->txctcss[i]);
+ }
+ }
+
+ pd(o->b.rxpolarity);
+ pd(o->b.txpolarity);
+
pd(o->txprelim);
pd(o->txmixa);
pd(o->txmixb);
@@ -2151,17 +3266,50 @@ static void pmrdump(struct chan_usbradio_pvt *o)
pd(o->txmixaset);
pd(o->txmixbset);
- ast_debug(4, "pmrdump()\n");
+ printf("\npmrdump()\n");
- ast_debug(4, "prxSquelchAdjust=%d\n", *(o->pmrChan->prxSquelchAdjust));
+ pd(p->devicenum);
+
+ printf("prxSquelchAdjust=%i\n",*(o->pmrChan->prxSquelchAdjust));
pd(p->rxCarrierPoint);
pd(p->rxCarrierHyst);
+ pd(*p->prxVoiceAdjust);
+ pd(*p->prxCtcssAdjust);
+
+ pd(p->rxfreq);
+ pd(p->txfreq);
+
pd(p->rxCtcss->relax);
- pf(p->rxCtcssFreq);
- pd(p->rxCtcssIndex);
- pf(p->txCtcssFreq);
+ //pf(p->rxCtcssFreq);
+ pd(p->numrxcodes);
+ if(o->pmrChan->numrxcodes>0)
+ {
+ for(i=0;i<o->pmrChan->numrxcodes;i++)
+ {
+ printf(" %i = %s\n",i,o->pmrChan->pRxCode[i]);
+ }
+ }
+
+ pd(p->txTocType);
+ ps(p->pTxCodeDefault);
+ pd(p->txcodedefaultsmode);
+ pd(p->numtxcodes);
+ if(o->pmrChan->numtxcodes>0)
+ {
+ for(i=0;i<o->pmrChan->numtxcodes;i++)
+ {
+ printf(" %i = %s\n",i,o->pmrChan->pTxCode[i]);
+ }
+ }
+
+ pd(p->b.rxpolarity);
+ pd(p->b.txpolarity);
+ pd(p->b.dcsrxpolarity);
+ pd(p->b.dcstxpolarity);
+ pd(p->b.lsdrxpolarity);
+ pd(p->b.lsdtxpolarity);
pd(p->txMixA);
pd(p->txMixB);
@@ -2170,21 +3318,73 @@ static void pmrdump(struct chan_usbradio_pvt *o)
pd(p->rxCenterSlicerEnable);
pd(p->rxCtcssDecodeEnable);
pd(p->rxDcsDecodeEnable);
+ pd(p->b.ctcssRxEnable);
+ pd(p->b.dcsRxEnable);
+ pd(p->b.lmrRxEnable);
+ pd(p->b.dstRxEnable);
+ pd(p->smode);
pd(p->txHpfEnable);
pd(p->txLimiterEnable);
pd(p->txPreEmpEnable);
pd(p->txLpfEnable);
- if (p->spsTxOutA)
- pd(p->spsTxOutA->outputGain);
- if (p->spsTxOutB)
- pd(p->spsTxOutB->outputGain);
+ if(p->spsTxOutA)pd(p->spsTxOutA->outputGain);
+ if(p->spsTxOutB)pd(p->spsTxOutB->outputGain);
+ pd(p->txPttIn);
+ pd(p->txPttOut);
+
+ pd(p->tracetype);
return;
}
+/*
+ takes data from a chan_usbradio_pvt struct (e.g. o->)
+ and configures the xpmr radio layer
+*/
+static int xpmr_config(struct chan_usbradio_pvt *o)
+{
+ //ast_log(LOG_NOTICE,"xpmr_config()\n");
+
+ TRACEO(1,("xpmr_config()\n"));
+
+ if(o->pmrChan==NULL)
+ {
+ ast_log(LOG_ERROR,"pmr channel structure NULL\n");
+ return 1;
+ }
+
+ o->pmrChan->rxCtcss->relax = o->rxctcssrelax;
+ o->pmrChan->txpower=0;
+ if(o->b.remoted)
+ {
+ o->pmrChan->pTxCodeDefault = o->set_txctcssdefault;
+ o->pmrChan->pRxCodeSrc=o->set_rxctcssfreqs;
+ o->pmrChan->pTxCodeSrc=o->set_txctcssfreqs;
+ o->pmrChan->rxfreq=o->set_rxfreq;
+ o->pmrChan->txfreq=o->set_txfreq;
+ /* printf(" remoted %s %s --> %s \n",o->pmrChan->txctcssdefault,
+ o->pmrChan->txctcssfreq,o->pmrChan->rxctcssfreq); */
+ }
+ else
+ {
+ // set xpmr pointers to source strings
+
+ o->pmrChan->pTxCodeDefault = o->txctcssdefault;
+ o->pmrChan->pRxCodeSrc = o->rxctcssfreqs;
+ o->pmrChan->pTxCodeSrc = o->txctcssfreqs;
+
+ o->pmrChan->rxfreq = o->rxfreq;
+ o->pmrChan->txfreq = o->txfreq;
+ }
+
+ code_string_parse(o->pmrChan);
+ if(o->pmrChan->rxfreq) o->pmrChan->b.reprog=1;
+
+ return 0;
+}
/*
* grab fields from the config file, init the descriptor and open the device.
*/
@@ -2193,175 +3393,318 @@ static struct chan_usbradio_pvt *store_config(struct ast_config *cfg, char *ctg)
struct ast_variable *v;
struct chan_usbradio_pvt *o;
struct ast_config *cfg1;
- struct ast_flags config_flags = { 0 };
-
+ int i;
+ char fname[200];
+#ifdef NEW_ASTERISK
+ struct ast_flags zeroflag = {0};
+#endif
if (ctg == NULL) {
- traceusb1(" store_config() ctg == NULL\n");
+ traceusb1((" store_config() ctg == NULL\n"));
o = &usbradio_default;
ctg = "general";
} else {
- if (!(o = ast_calloc(1, sizeof(*o)))){
- return NULL;
- }
- *o = usbradio_default;
/* "general" is also the default thing */
if (strcmp(ctg, "general") == 0) {
- o->name = ast_strdup("dsp");
- usbradio_active = o->name;
- } else
+ o = &usbradio_default;
+ } else {
+ // ast_log(LOG_NOTICE,"ast_calloc for chan_usbradio_pvt of %s\n",ctg);
+ if (!(o = ast_calloc(1, sizeof(*o))))
+ return NULL;
+ *o = usbradio_default;
o->name = ast_strdup(ctg);
+ if (!usbradio_active)
+ usbradio_active = o->name;
+ }
}
-
+ ast_mutex_init(&o->eepromlock);
strcpy(o->mohinterpret, "default");
- o->micmax = amixer_max(o->devicenum, MIXER_PARAM_MIC_CAPTURE_VOL);
- o->spkrmax = amixer_max(o->devicenum, MIXER_PARAM_SPKR_PLAYBACK_VOL);
/* fill other fields from configuration */
for (v = ast_variable_browse(cfg, ctg); v; v = v->next) {
+ M_START((char *)v->name, (char *)v->value);
/* handle jb conf */
if (!ast_jb_read_conf(&global_jbconf, v->name, v->value))
continue;
- CV_START(v->name, v->value);
-
- CV_UINT("frags", o->frags);
- CV_UINT("queuesize", o->queuesize);
- CV_UINT("devicenum", o->devicenum);
- CV_UINT("debug", usbradio_debug);
- CV_BOOL("rxcpusaver", o->rxcpusaver);
- CV_BOOL("txcpusaver", o->txcpusaver);
- CV_BOOL("invertptt", o->invertptt);
- CV_F("rxdemod", store_rxdemod(o, v->value));
- CV_BOOL("txprelim", o->txprelim);;
- CV_F("txmixa", store_txmixa(o, v->value));
- CV_F("txmixb", store_txmixb(o, v->value));
- CV_F("carrierfrom", store_rxcdtype(o, v->value));
- CV_F("rxsdtype", store_rxsdtype(o, v->value));
- CV_F("rxctcssfreq", store_rxctcssfreq(o, v->value));
- CV_F("txctcssfreq", store_txctcssfreq(o, v->value));
- CV_F("rxgain", store_rxgain(o, v->value));
- CV_BOOL("rxboostset", o->rxboostset);
- CV_UINT("rxctcssrelax", o->rxctcssrelax);
- CV_F("txtoctype", store_txtoctype(o, v->value));
- CV_UINT("hdwtype", o->hdwtype);
- CV_UINT("duplex", o->radioduplex);
-
- CV_END;
- }
-
- cfg1 = ast_config_load(config1, config_flags);
- if (!cfg1) {
- o->rxmixerset = 500;
- o->txmixaset = 500;
- o->txmixbset = 500;
- o->rxvoiceadj = 0.5;
- o->rxctcssadj = 0.5;
- o->txctcssadj = 200;
- o->rxsquelchadj = 500;
- ast_log(LOG_WARNING, "File %s not found, using default parameters.\n", config1);
- } else {
- for (v = ast_variable_browse(cfg1, ctg); v; v = v->next) {
+
+#if 0
+ M_BOOL("autoanswer", o->autoanswer)
+ M_BOOL("autohangup", o->autohangup)
+ M_BOOL("overridecontext", o->overridecontext)
+ M_STR("context", o->ctx)
+ M_STR("language", o->language)
+ M_STR("mohinterpret", o->mohinterpret)
+ M_STR("extension", o->ext)
+ M_F("callerid", store_callerid(o, v->value))
+#endif
+ M_UINT("frags", o->frags)
+ M_UINT("queuesize",o->queuesize)
+#if 0
+ M_UINT("devicenum",o->devicenum)
+#endif
+ M_UINT("debug", usbradio_debug)
+ M_BOOL("rxcpusaver",o->rxcpusaver)
+ M_BOOL("txcpusaver",o->txcpusaver)
+ M_BOOL("invertptt",o->invertptt)
+ M_F("rxdemod",store_rxdemod(o,(char *)v->value))
+ M_BOOL("txprelim",o->txprelim);
+ M_F("txmixa",store_txmixa(o,(char *)v->value))
+ M_F("txmixb",store_txmixb(o,(char *)v->value))
+ M_F("carrierfrom",store_rxcdtype(o,(char *)v->value))
+ M_F("rxsdtype",store_rxsdtype(o,(char *)v->value))
+ M_UINT("rxsqvox",o->rxsqvoxadj)
+ M_STR("txctcssdefault",o->txctcssdefault)
+ M_STR("rxctcssfreqs",o->rxctcssfreqs)
+ M_STR("txctcssfreqs",o->txctcssfreqs)
+ M_UINT("rxfreq",o->rxfreq)
+ M_UINT("txfreq",o->txfreq)
+ M_F("rxgain",store_rxgain(o,(char *)v->value))
+ M_BOOL("rxboost",o->rxboostset)
+ M_UINT("rxctcssrelax",o->rxctcssrelax)
+ M_F("txtoctype",store_txtoctype(o,(char *)v->value))
+ M_UINT("hdwtype",o->hdwtype)
+ M_UINT("eeprom",o->wanteeprom)
+ M_UINT("duplex",o->radioduplex)
+ M_UINT("txsettletime",o->txsettletime)
+ M_BOOL("rxpolarity",o->b.rxpolarity)
+ M_BOOL("txpolarity",o->b.txpolarity)
+ M_BOOL("dcsrxpolarity",o->b.dcsrxpolarity)
+ M_BOOL("dcstxpolarity",o->b.dcstxpolarity)
+ M_BOOL("lsdrxpolarity",o->b.lsdrxpolarity)
+ M_BOOL("lsdtxpolarity",o->b.lsdtxpolarity)
+ M_BOOL("loopback",o->b.loopback)
+ M_BOOL("radioactive",o->b.radioactive)
+ M_UINT("rptnum",o->rptnum)
+ M_UINT("idleinterval",o->idleinterval)
+ M_UINT("turnoffs",o->turnoffs)
+ M_UINT("tracetype",o->tracetype)
+ M_UINT("tracelevel",o->tracelevel)
+ M_UINT("area",o->area)
+ M_STR("ukey",o->ukey)
+ M_END(;
+ );
+ }
+
+ o->debuglevel=0;
+
+ if (o == &usbradio_default) /* we are done with the default */
+ return NULL;
+
+ snprintf(fname,sizeof(fname) - 1,config1,o->name);
+#ifdef NEW_ASTERISK
+ cfg1 = ast_config_load(fname,zeroflag);
+#else
+ cfg1 = ast_config_load(fname);
+#endif
+ o->rxmixerset = 500;
+ o->txmixaset = 500;
+ o->txmixbset = 500;
+ o->rxvoiceadj = 0.5;
+ o->rxctcssadj = 0.5;
+ o->txctcssadj = 200;
+ o->rxsquelchadj = 500;
+ o->devstr[0] = 0;
+ if (cfg1) {
+ for (v = ast_variable_browse(cfg1, o->name); v; v = v->next) {
- CV_START(v->name, v->value);
- CV_UINT("rxmixerset", o->rxmixerset);
- CV_UINT("txmixaset", o->txmixaset);
- CV_UINT("txmixbset", o->txmixbset);
- CV_F("rxvoiceadj", store_rxvoiceadj(o, v->value));
- CV_F("rxctcssadj", store_rxctcssadj(o, v->value));
- CV_UINT("txctcssadj", o->txctcssadj);
- CV_UINT("rxsquelchadj", o->rxsquelchadj);
- CV_END;
+ M_START((char *)v->name, (char *)v->value);
+ M_UINT("rxmixerset", o->rxmixerset)
+ M_UINT("txmixaset", o->txmixaset)
+ M_UINT("txmixbset", o->txmixbset)
+ M_F("rxvoiceadj",store_rxvoiceadj(o,(char *)v->value))
+ M_F("rxctcssadj",store_rxctcssadj(o,(char *)v->value))
+ M_UINT("txctcssadj",o->txctcssadj);
+ M_UINT("rxsquelchadj", o->rxsquelchadj)
+ M_STR("devstr", o->devstr)
+ M_END(;
+ );
}
ast_config_destroy(cfg1);
+ } else ast_log(LOG_WARNING,"File %s not found, using default parameters.\n",fname);
+
+ if(o->wanteeprom)
+ {
+ ast_mutex_lock(&o->eepromlock);
+ while(o->eepromctl)
+ {
+ ast_mutex_unlock(&o->eepromlock);
+ usleep(10000);
+ ast_mutex_lock(&o->eepromlock);
+ }
+ o->eepromctl = 1; /* request a load */
+ ast_mutex_unlock(&o->eepromlock);
}
+ /* if our specified one exists in the list */
+ if ((!usb_list_check(o->devstr)) || find_desc_usb(o->devstr))
+ {
+ char *s;
- o->debuglevel = 0;
+ for(s = usb_device_list; *s; s += strlen(s) + 1)
+ {
+ if (!find_desc_usb(s)) break;
+ }
+ if (!*s)
+ {
+ ast_log(LOG_WARNING,"Unable to assign USB device for channel %s\n",o->name);
+ goto error;
+ }
+ ast_log(LOG_NOTICE,"Assigned USB device %s to usbradio channel %s\n",s,o->name);
+ strcpy(o->devstr,s);
+ }
- if (o == &usbradio_default) /* we are done with the default */
- return NULL;
+ i = usb_get_usbdev(o->devstr);
+ if (i < 0)
+ {
+ ast_log(LOG_ERROR,"Not able to find alsa USB device\n");
+ goto error;
+ }
+ o->devicenum = i;
+ o->micmax = amixer_max(o->devicenum,MIXER_PARAM_MIC_CAPTURE_VOL);
+ o->spkrmax = amixer_max(o->devicenum,MIXER_PARAM_SPKR_PLAYBACK_VOL);
o->lastopen = ast_tvnow(); /* don't leave it 0 or tvdiff may wrap */
o->dsp = ast_dsp_new();
- if (o->dsp) {
- ast_dsp_set_features(o->dsp, DSP_FEATURE_DIGIT_DETECT);
- ast_dsp_set_digitmode(o->dsp, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
+ if (o->dsp)
+ {
+#ifdef NEW_ASTERISK
+ ast_dsp_set_features(o->dsp,DSP_FEATURE_DIGIT_DETECT);
+ ast_dsp_set_digitmode(o->dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
+#else
+ ast_dsp_set_features(o->dsp,DSP_FEATURE_DTMF_DETECT);
+ ast_dsp_digitmode(o->dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
+#endif
}
- if (o->rxctcssfreq != 0 && o->rxdemod == RX_AUDIO_SPEAKER)
- ast_log(LOG_ERROR, "Incompatable Options o->rxctcssfreq=%f and o->rxdemod=speaker\n", o->rxctcssfreq);
-
- if (o->pmrChan == NULL) {
+ if(o->pmrChan==NULL)
+ {
t_pmr_chan tChan;
- memset(&tChan, 0, sizeof(tChan));
+ // ast_log(LOG_NOTICE,"createPmrChannel() %s\n",o->name);
+ memset(&tChan,0,sizeof(t_pmr_chan));
+
+ tChan.pTxCodeDefault = o->txctcssdefault;
+ tChan.pRxCodeSrc = o->rxctcssfreqs;
+ tChan.pTxCodeSrc = o->txctcssfreqs;
- tChan.rxDemod = o->rxdemod;
- tChan.rxCdType = o->rxcdtype;
+ tChan.rxDemod=o->rxdemod;
+ tChan.rxCdType=o->rxcdtype;
+ tChan.rxSqVoxAdj=o->rxsqvoxadj;
- tChan.txMod = o->txprelim;
+ if (o->txprelim)
+ tChan.txMod = 2;
tChan.txMixA = o->txmixa;
tChan.txMixB = o->txmixb;
- tChan.rxCpuSaver = o->rxcpusaver;
- tChan.txCpuSaver = o->txcpusaver;
+ tChan.rxCpuSaver=o->rxcpusaver;
+ tChan.txCpuSaver=o->txcpusaver;
- tChan.rxCtcssFreq = o->rxctcssfreq;
- tChan.txCtcssFreq = o->txctcssfreq;
+ tChan.b.rxpolarity=o->b.rxpolarity;
+ tChan.b.txpolarity=o->b.txpolarity;
- o->pmrChan = createPmrChannel(&tChan, FRAME_SIZE);
+ tChan.b.dcsrxpolarity=o->b.dcsrxpolarity;
+ tChan.b.dcstxpolarity=o->b.dcstxpolarity;
- o->pmrChan->radioDuplex = o->radioduplex;
+ tChan.b.lsdrxpolarity=o->b.lsdrxpolarity;
+ tChan.b.lsdtxpolarity=o->b.lsdtxpolarity;
- o->pmrChan->rxCpuSaver = o->rxcpusaver;
- o->pmrChan->txCpuSaver = o->txcpusaver;
+ tChan.tracetype=o->tracetype;
+ tChan.tracelevel=o->tracelevel;
+ tChan.rptnum=o->rptnum;
+ tChan.idleinterval=o->idleinterval;
+ tChan.turnoffs=o->turnoffs;
+ tChan.area=o->area;
+ tChan.ukey=o->ukey;
+ tChan.name=o->name;
+
+ o->pmrChan=createPmrChannel(&tChan,FRAME_SIZE);
+
+ o->pmrChan->radioDuplex=o->radioduplex;
+ o->pmrChan->b.loopback=0;
+ o->pmrChan->txsettletime=o->txsettletime;
+ o->pmrChan->rxCpuSaver=o->rxcpusaver;
+ o->pmrChan->txCpuSaver=o->txcpusaver;
*(o->pmrChan->prxSquelchAdjust) =
((999 - o->rxsquelchadj) * 32767) / 1000;
- o->pmrChan->spsRx->outputGain = o->rxvoiceadj*M_Q8;
-
+ *(o->pmrChan->prxVoiceAdjust)=o->rxvoiceadj*M_Q8;
+ *(o->pmrChan->prxCtcssAdjust)=o->rxctcssadj*M_Q8;
+ o->pmrChan->rxCtcss->relax=o->rxctcssrelax;
o->pmrChan->txTocType = o->txtoctype;
- if ((o->txmixa == TX_OUT_LSD) ||
- (o->txmixa == TX_OUT_COMPOSITE) ||
- (o->txmixb == TX_OUT_LSD) ||
- (o->txmixb == TX_OUT_COMPOSITE)) {
- *(o->pmrChan->prxCtcssAdjust) = o->rxctcssadj * M_Q8;
- set_txctcss_level(o);
+ if ( (o->txmixa == TX_OUT_LSD) ||
+ (o->txmixa == TX_OUT_COMPOSITE) ||
+ (o->txmixb == TX_OUT_LSD) ||
+ (o->txmixb == TX_OUT_COMPOSITE))
+ {
+ set_txctcss_level(o);
+ }
+
+ if( (o->txmixa!=TX_OUT_VOICE) && (o->txmixb!=TX_OUT_VOICE) &&
+ (o->txmixa!=TX_OUT_COMPOSITE) && (o->txmixb!=TX_OUT_COMPOSITE)
+ )
+ {
+ ast_log(LOG_ERROR,"No txvoice output configured.\n");
+ }
+
+ if( o->txctcssfreq[0] &&
+ o->txmixa!=TX_OUT_LSD && o->txmixa!=TX_OUT_COMPOSITE &&
+ o->txmixb!=TX_OUT_LSD && o->txmixb!=TX_OUT_COMPOSITE
+ )
+ {
+ ast_log(LOG_ERROR,"No txtone output configured.\n");
+ }
+
+ if(o->b.radioactive)
+ {
+ // 20080328 sphenke asdf maw !!!
+ // this diagnostic option was working but now appears broken
+ // it's not required for operation so I'll fix it later.
+ //struct chan_usbradio_pvt *ao;
+ //for (ao = usbradio_default.next; ao && ao->name ; ao = ao->next)ao->pmrChan->b.radioactive=0;
+ usbradio_active = o->name;
+ // o->pmrChan->b.radioactive=1;
+ //o->b.radioactive=0;
+ //o->pmrChan->b.radioactive=0;
+ ast_log(LOG_NOTICE,"radio active set to [%s]\n",o->name);
}
-
- o->pmrChan->rxCtcss->relax = o->rxctcssrelax;
-
}
- if ((o->txmixa != TX_OUT_VOICE) && (o->txmixb != TX_OUT_VOICE) &&
- (o->txmixa != TX_OUT_COMPOSITE) && (o->txmixb != TX_OUT_COMPOSITE))
- ast_log(LOG_ERROR, "No txvoice output configured.\n");
-
- if (o->txctcssfreq &&
- o->txmixa != TX_OUT_LSD && o->txmixa != TX_OUT_COMPOSITE &&
- o->txmixb != TX_OUT_LSD && o->txmixb != TX_OUT_COMPOSITE)
- ast_log(LOG_ERROR, "No txtone output configured.\n");
-
- if (o->rxctcssfreq && o->pmrChan->rxCtcssIndex < 0)
- ast_log(LOG_ERROR, "Invalid CTCSS Frequency.\n");
-
- /* RxTestIt(o); */
+ xpmr_config(o);
+ TRACEO(1,("store_config() 120\n"));
mixer_write(o);
+ TRACEO(1,("store_config() 130\n"));
mult_set(o);
+ TRACEO(1,("store_config() 140\n"));
hidhdwconfig(o);
- /* pmrdump(o); */
+ TRACEO(1,("store_config() 200\n"));
+
+#ifndef NEW_ASTERISK
+ if (pipe(o->sndcmd) != 0) {
+ ast_log(LOG_ERROR, "Unable to create pipe\n");
+ goto error;
+ }
+
+ ast_pthread_create_background(&o->sthread, NULL, sound_thread, o);
+#endif
/* link into list of devices */
if (o != &usbradio_default) {
o->next = usbradio_default.next;
usbradio_default.next = o;
}
+ TRACEO(1,("store_config() complete\n"));
return o;
+
+ error:
+ if (o != &usbradio_default)
+ free(o);
+ return NULL;
}
+
#if DEBUG_FILETEST == 1
/*
Test It on a File
@@ -2371,86 +3714,231 @@ int RxTestIt(struct chan_usbradio_pvt *o)
const int numSamples = SAMPLES_PER_BLOCK;
const int numChannels = 16;
- i16 sample, i, ii;
+ i16 sample,i,ii;
i32 txHangTime;
i16 txEnable;
- t_pmr_chan tChan;
+ t_pmr_chan tChan;
t_pmr_chan *pChan;
- FILE *hInput = NULL, *hOutput = NULL, *hOutputTx = NULL;
+ FILE *hInput=NULL, *hOutput=NULL, *hOutputTx=NULL;
- i16 iBuff[numSamples * 2 * 6], oBuff[numSamples];
-
- ast_debug(4, "RxTestIt()\n");
+ i16 iBuff[numSamples*2*6], oBuff[numSamples];
+
+ printf("RxTestIt()\n");
- pChan = o->pmrChan;
- pChan->b.txCapture = 1;
- pChan->b.rxCapture = 1;
+ pChan=o->pmrChan;
+ pChan->b.txCapture=1;
+ pChan->b.rxCapture=1;
txEnable = 0;
- hInput = fopen("/usr/src/xpmr/testdata/rx_in.pcm", "r");
- if (!hInput){
- ast_debug(4, " RxTestIt() File Not Found.\n");
+ hInput = fopen("/usr/src/xpmr/testdata/rx_in.pcm","r");
+ if(!hInput){
+ printf(" RxTestIt() File Not Found.\n");
return 0;
}
- hOutput = fopen("/usr/src/xpmr/testdata/rx_debug.pcm", "w");
+ hOutput = fopen("/usr/src/xpmr/testdata/rx_debug.pcm","w");
- ast_debug(4, " RxTestIt() Working...\n");
+ printf(" RxTestIt() Working...\n");
- while (!feof(hInput)) {
- fread((void *)iBuff, 2, numSamples * 2 * 6, hInput);
+ while(!feof(hInput))
+ {
+ fread((void *)iBuff,2,numSamples*2*6,hInput);
- if (txHangTime)
- txHangTime -= numSamples;
- if (txHangTime < 0)
- txHangTime = 0;
+ if(txHangTime)txHangTime-=numSamples;
+ if(txHangTime<0)txHangTime=0;
- if (pChan->rxCtcss->decode)
- txHangTime = (8000 / 1000 * 2000);
+ if(pChan->rxCtcss->decode)txHangTime=(8000/1000*2000);
- if (pChan->rxCtcss->decode && !txEnable) {
- txEnable = 1;
- /* pChan->inputBlanking = (8000 / 1000 * 200); */
- } else if (!pChan->rxCtcss->decode && txEnable) {
- txEnable = 0;
+ if(pChan->rxCtcss->decode && !txEnable)
+ {
+ txEnable=1;
+ //pChan->inputBlanking=(8000/1000*200);
+ }
+ else if(!pChan->rxCtcss->decode && txEnable)
+ {
+ txEnable=0;
}
- PmrRx(pChan, iBuff, oBuff);
+ PmrRx(pChan,iBuff,oBuff);
- fwrite((void *)pChan->prxDebug, 2, numSamples * numChannels, hOutput);
+ fwrite((void *)pChan->prxDebug,2,numSamples*numChannels,hOutput);
}
- pChan->b.txCapture = 0;
- pChan->b.rxCapture = 0;
+ pChan->b.txCapture=0;
+ pChan->b.rxCapture=0;
- if (hInput)
- fclose(hInput);
- if (hOutput)
- fclose(hOutput);
+ if(hInput)fclose(hInput);
+ if(hOutput)fclose(hOutput);
- ast_debug(4, " RxTestIt() Complete.\n");
+ printf(" RxTestIt() Complete.\n");
return 0;
}
#endif
+#ifdef NEW_ASTERISK
+
+static char *res2cli(int r)
+
+{
+ switch (r)
+ {
+ case RESULT_SUCCESS:
+ return(CLI_SUCCESS);
+ case RESULT_SHOWUSAGE:
+ return(CLI_SHOWUSAGE);
+ default:
+ return(CLI_FAILURE);
+ }
+}
+
+static char *handle_console_key(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio key";
+ e->usage = key_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(console_key(a->fd,a->argc,a->argv));
+}
+
+static char *handle_console_unkey(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio unkey";
+ e->usage = unkey_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(console_unkey(a->fd,a->argc,a->argv));
+}
+
+static char *handle_radio_tune(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio tune";
+ e->usage = radio_tune_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_tune(a->fd,a->argc,a->argv));
+}
+
+static char *handle_radio_debug(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio debug";
+ e->usage = radio_tune_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_set_debug(a->fd,a->argc,a->argv));
+}
+
+static char *handle_radio_debug_off(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio debug off";
+ e->usage = radio_tune_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_set_debug_off(a->fd,a->argc,a->argv));
+}
+
+static char *handle_radio_active(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio active";
+ e->usage = active_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_active(a->fd,a->argc,a->argv));
+}
+
+static char *handle_set_xdebug(struct ast_cli_entry *e,
+ int cmd, struct ast_cli_args *a)
+{
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "radio set xdebug";
+ e->usage = active_usage;
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+ return res2cli(radio_set_xpmr_debug(a->fd,a->argc,a->argv));
+}
+
+
+static struct ast_cli_entry cli_usbradio[] = {
+ AST_CLI_DEFINE(handle_console_key,"Simulate Rx Signal Present"),
+ AST_CLI_DEFINE(handle_console_unkey,"Simulate Rx Signal Loss"),
+ AST_CLI_DEFINE(handle_radio_tune,"Radio Tune"),
+ AST_CLI_DEFINE(handle_radio_debug,"Radio Debug On"),
+ AST_CLI_DEFINE(handle_radio_debug_off,"Radio Debug Off"),
+ AST_CLI_DEFINE(handle_radio_active,"Change commanded device"),
+ AST_CLI_DEFINE(handle_set_xdebug,"Radio set xpmr debug level")
+};
+
+#endif
+
#include "./xpmr/xpmr.c"
+#ifdef HAVE_XPMRX
+#include "./xpmrx/xpmrx.c"
+#endif
+
/*
*/
static int load_module(void)
{
struct ast_config *cfg = NULL;
char *ctg = NULL;
- struct ast_flags config_flags = { 0 };
+#ifdef NEW_ASTERISK
+ struct ast_flags zeroflag = {0};
+#endif
+
+ if (hid_device_mklist()) {
+ ast_log(LOG_NOTICE, "Unable to make hid list\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
+
+ usb_list_check("");
+
+ usbradio_active = NULL;
/* Copy the default jb config over global_jbconf */
memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
/* load config file */
- if (!(cfg = ast_config_load(config, config_flags))) {
+#ifdef NEW_ASTERISK
+ if (!(cfg = ast_config_load(config,zeroflag))) {
+#else
+ if (!(cfg = ast_config_load(config))) {
+#endif
ast_log(LOG_NOTICE, "Unable to load config %s\n", config);
return AST_MODULE_LOAD_DECLINE;
}
@@ -2462,7 +3950,7 @@ static int load_module(void)
ast_config_destroy(cfg);
if (find_desc(usbradio_active) == NULL) {
- ast_log(LOG_NOTICE, "Device %s not found\n", usbradio_active);
+ ast_log(LOG_NOTICE, "radio active device %s not found\n", usbradio_active);
/* XXX we could default to 'dsp' perhaps ? */
/* XXX should cleanup allocated memory etc. */
return AST_MODULE_LOAD_FAILURE;
@@ -2491,8 +3979,7 @@ static int unload_module(void)
for (o = usbradio_default.next; o; o = o->next) {
ast_log(LOG_WARNING, "destroyPmrChannel() called\n");
- if (o->pmrChan)
- destroyPmrChannel(o->pmrChan);
+ if(o->pmrChan)destroyPmrChannel(o->pmrChan);
#if DEBUG_CAPTURES == 1
if (frxcapraw) { fclose(frxcapraw); frxcapraw = NULL; }
@@ -2504,8 +3991,13 @@ static int unload_module(void)
#endif
close(o->sounddev);
- if (o->dsp)
- ast_dsp_free(o->dsp);
+#ifndef NEW_ASTERISK
+ if (o->sndcmd[0] > 0) {
+ close(o->sndcmd[0]);
+ close(o->sndcmd[1]);
+ }
+#endif
+ if (o->dsp) ast_dsp_free(o->dsp);
if (o->owner)
ast_softhangup(o->owner, AST_SOFTHANGUP_APPUNLOAD);
if (o->owner) /* XXX how ??? */
diff --git a/channels/xpmr/sinetabx.h b/channels/xpmr/sinetabx.h
index 4c4574850..14d8f9f4c 100755
--- a/channels/xpmr/sinetabx.h
+++ b/channels/xpmr/sinetabx.h
@@ -4,16 +4,26 @@
* All Rights Reserved. Copyright (C)2007, Xelatec, LLC
*
* 20070808 1235 Steven Henke, W9SH, sph@xelatec.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * This version may be optionally licenced under the GNU LGPL licence.
*
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
+ * A license has been granted to Digium (via disclaimer) for the use of
+ * this code.
*
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
*/
/*! \file
@@ -24,11 +34,11 @@
*/
#ifndef XPMR_SINETABX_H
-#define XPMR_SINETABX_H 1
+#define XPMR_SINETABX_H 1
#define SAMPLES_PER_SINE 256
-const i16 sinetablex[]={
+static const i16 sinetablex[]={
0, // 0
804, // 1
1608, // 2
diff --git a/channels/xpmr/xpmr.c b/channels/xpmr/xpmr.c
index a799ca9d3..5e1b0f59d 100755
--- a/channels/xpmr/xpmr.c
+++ b/channels/xpmr/xpmr.c
@@ -1,19 +1,30 @@
/*
* xpmr.c - Xelatec Private Mobile Radio Processes
- *
+ *
* All Rights Reserved. Copyright (C)2007, Xelatec, LLC
- *
+ *
* 20070808 1235 Steven Henke, W9SH, sph@xelatec.com
*
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * This version may be optionally licenced under the GNU LGPL licence.
+ *
+ * A license has been granted to Digium (via disclaimer) for the use of
+ * this code.
*
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
+ * 20080118 0800 sph@xelatec.com major fixes and features
*/
/*! \file
@@ -36,29 +47,419 @@
FIR = Finite Impulse Response (Filter)
IIR = Infinite Impulse Response (Filter)
*/
+
+// XPMR_FILE_VERSION(__FILE__, "$Revision$")
+
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
+#include <sys/io.h>
#include <fcntl.h>
#include <sys/time.h>
#include <stdlib.h>
#include <errno.h>
-
+
#include "xpmr.h"
#include "xpmr_coef.h"
#include "sinetabx.h"
static i16 pmrChanIndex=0; // count of created pmr instances
+//static i16 pmrSpsIndex=0;
+
+#if (DTX_PROG == 1) || XPMR_PPTP == 1
+static int ppdrvdev=0;
+#endif
+
+/*
+ Trace Routines
+*/
+void strace(i16 point, t_sdbg *sdbg, i16 index, i16 value)
+{
+ // make dbg_trace buffer in structure
+ if(!sdbg->mode || sdbg->point[point]<0){
+ return;
+ } else {
+ sdbg->buffer[(index*XPMR_DEBUG_CHANS) + sdbg->point[point]] = value;
+ }
+}
+/*
+
+*/
+void strace2(t_sdbg *sdbg)
+{
+ int i;
+ for(i=0;i<XPMR_DEBUG_CHANS;i++)
+ {
+ if(sdbg->source[i])
+ {
+ int ii;
+ for(ii=0;ii<SAMPLES_PER_BLOCK;ii++)
+ {
+ sdbg->buffer[ii*XPMR_DEBUG_CHANS + i] = sdbg->source[i][ii];
+ }
+ }
+ }
+}
+#if XPMR_PPTP == 1
+/*
+ Hardware Trace Signals via the PC Parallel Port
+*/
+void pptp_init (void)
+{
+ if (ppdrvdev == 0)
+ ppdrvdev = open("/dev/ppdrv_device", 0);
+
+ if (ppdrvdev < 0)
+ {
+ ast_log(LOG_ERROR, "open /dev/ppdrv_ppdrvdev returned %i\n",ppdrvdev);
+ exit(0);
+ }
+ ioctl(ppdrvdev, PPDRV_IOC_PINMODE_OUT, DTX_CLK | DTX_DATA | DTX_ENABLE | DTX_TXPWR | DTX_TX | DTX_TP1 | DTX_TP2);
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, DTX_CLK | DTX_DATA | DTX_ENABLE | DTX_TXPWR | DTX_TX | DTX_TP1 | DTX_TP2);
+}
+/*
+*/
+void pptp_write(i16 bit, i16 state)
+{
+ if(bit==0)
+ {
+ if(state)ioctl(ppdrvdev,PPDRV_IOC_PINSET,DTX_TP1);
+ else ioctl(ppdrvdev,PPDRV_IOC_PINCLEAR,DTX_TP1);
+ }
+ else
+ {
+ if(state)ioctl(ppdrvdev,PPDRV_IOC_PINSET,DTX_TP2);
+ else ioctl(ppdrvdev,PPDRV_IOC_PINCLEAR,DTX_TP2);
+ }
+}
+#endif
+/*
+ take source string allocate and copy
+ copy is modified, delimiters are replaced with zeros to mark
+ end of string
+ count set pointers
+ string_parse( char *src, char *dest, char **sub)
+*/
+i16 string_parse(char *src, char **dest, char ***ptrs)
+{
+ char *p,*pd;
+ char *ptstr[1000];
+ i16 i, slen, numsub;
+
+ TRACEJ(2,("string_parse(%s)\n",src));
+
+ slen=strlen(src);
+ TRACEJ(2,(" source len = %i\n",slen));
+
+ pd=*dest;
+ if(pd) free(pd);
+ pd=calloc(slen+1,1);
+ memcpy(pd,src,slen);
+ *dest=pd;
+
+ p=0;
+ numsub=0;
+ for(i=0;i<slen+1;i++)
+ {
+ TRACEJ(5,(" pd[%i] = %c\n",i,pd[i]));
+
+ if( p==0 && pd[i]!=',' && pd[i]!=' ' )
+ {
+ p=&(pd[i]);
+ }
+ else if(pd[i]==',' || pd[i]==0 )
+ {
+ ptstr[numsub]=p;
+ pd[i]=0;
+ p=0;
+ numsub++;
+ }
+ }
+
+ for(i=0;i<numsub;i++)
+ {
+ TRACEJ(5,(" ptstr[%i] = %p %s\n",i,ptstr[i],ptstr[i]));
+ }
+
+ if(*ptrs)free(*ptrs);
+ *ptrs=calloc(numsub,4);
+ for(i=0;i<numsub;i++)
+ {
+ (*ptrs)[i]=ptstr[i];
+ TRACEJ(5,(" %i = %s\n",i,(*ptrs)[i]));
+ }
+ TRACEJ(5,("string_parse()=%i\n\n",numsub));
+
+ return numsub;
+}
+/*
+ the parent program defines
+ pRxCodeSrc and pTxCodeSrc string pointers to the list of codes
+ pTxCodeDefault the default Tx Code.
+
+*/
+i16 code_string_parse(t_pmr_chan *pChan)
+{
+ i16 i, ii, hit, ti;
+ char *p;
+ float f, maxctcsstxfreq;
+
+ t_pmr_sps *pSps;
+ i16 maxctcssindex;
+
+ TRACEF(1,("code_string_parse(%i)\n",0));
+ TRACEF(1,("pChan->pRxCodeSrc %s \n",pChan->pRxCodeSrc));
+ TRACEF(1,("pChan->pTxCodeSrc %s \n",pChan->pTxCodeSrc));
+ TRACEF(1,("pChan->pTxCodeDefault %s \n",pChan->pTxCodeDefault));
+
+ //printf("code_string_parse() %s / %s / %s / %s \n",pChan->name, pChan->pTxCodeDefault,pChan->pTxCodeSrc,pChan->pRxCodeSrc);
+
+ maxctcssindex=CTCSS_NULL;
+ maxctcsstxfreq=CTCSS_NULL;
+ pChan->txctcssdefault_index=CTCSS_NULL;
+ pChan->txctcssdefault_value=CTCSS_NULL;
+
+ pChan->b.ctcssRxEnable=pChan->b.ctcssTxEnable=0;
+ pChan->b.dcsRxEnable=pChan->b.dcsTxEnable=0;
+ pChan->b.lmrRxEnable=pChan->b.lmrTxEnable=0;
+ pChan->b.mdcRxEnable=pChan->b.mdcTxEnable=0;
+ pChan->b.dstRxEnable=pChan->b.dstTxEnable=0;
+ pChan->b.p25RxEnable=pChan->b.p25TxEnable=0;
+
+ if(pChan->spsLsdGen){
+ pChan->spsLsdGen->enabled=0;
+ pChan->spsLsdGen->state=0;
+ }
+
+ TRACEF(1,("code_string_parse(%i) 05\n",0));
+
+ pChan->numrxcodes = string_parse( pChan->pRxCodeSrc, &(pChan->pRxCodeStr), &(pChan->pRxCode));
+ pChan->numtxcodes = string_parse( pChan->pTxCodeSrc, &(pChan->pTxCodeStr), &(pChan->pTxCode));
+
+ if(pChan->numrxcodes!=pChan->numtxcodes)printf("ERROR: numrxcodes != numtxcodes \n");
+
+ pChan->rxCtcss->enabled=0;
+ pChan->rxCtcss->gain=1*M_Q8;
+ pChan->rxCtcss->limit=8192;
+ pChan->rxCtcss->input=pChan->pRxLsdLimit;
+ pChan->rxCtcss->decode=CTCSS_NULL;
+
+ pChan->rxCtcss->testIndex=0;
+ if(!pChan->rxCtcss->testIndex)pChan->rxCtcss->testIndex=3;
+
+ pChan->rxctcssfreq[0]=0; // decode now CTCSS_RXONLY
+
+ for(i=0;i<CTCSS_NUM_CODES;i++)
+ {
+ pChan->rxctcss[i]=0;
+ pChan->txctcss[i]=0;
+ pChan->rxCtcssMap[i]=CTCSS_NULL;
+ }
+
+ TRACEF(1,("code_string_parse(%i) 10\n",0));
+
+ #ifdef XPMRX_H
+ xpmrx(pChan,XXO_LSDCODEPARSE);
+ #endif
+
+ // Do Receive Codes String
+ for(i=0;i<pChan->numrxcodes;i++)
+ {
+ i16 ii,ri,ti;
+ float f;
+
+ p=pChan->pStr=pChan->pRxCode[i];
+
+ #ifdef HAVE_XPMRX
+ if(!xpmrx(pChan,XXO_LSDCODEPARSE_1))
+ #endif
+ {
+ sscanf(p,"%f",&f);
+ ri=CtcssFreqIndex(f);
+ if(ri>maxctcssindex)maxctcssindex=ri;
+
+ sscanf(pChan->pTxCode[i],"%f",&f);
+ ti=CtcssFreqIndex(f);
+ if(f>maxctcsstxfreq)maxctcsstxfreq=f;
+
+ if(ri>CTCSS_NULL && ti>CTCSS_NULL)
+ {
+ pChan->b.ctcssRxEnable=pChan->b.ctcssTxEnable=1;
+ pChan->rxCtcssMap[ri]=ti;
+ pChan->numrxctcssfreqs++;
+ TRACEF(1,("pChan->rxctcss[%i]=%s pChan->rxCtcssMap[%i]=%i\n",i,pChan->rxctcss[i],ri,ti));
+ }
+ else if(ri>CTCSS_NULL && f==0)
+ {
+ pChan->b.ctcssRxEnable=1;
+ pChan->rxCtcssMap[ri]=CTCSS_RXONLY;
+ pChan->numrxctcssfreqs++;
+ TRACEF(1,("pChan->rxctcss[%i]=%s pChan->rxCtcssMap[%i]=%i RXONLY\n",i,pChan->rxctcss[i],ri,ti));
+ }
+ else
+ {
+ pChan->numrxctcssfreqs=0;
+ for(ii=0;ii<CTCSS_NUM_CODES;ii++) pChan->rxCtcssMap[ii]=CTCSS_NULL;
+ TRACEF(1,("WARNING: Invalid Channel code detected and ignored. %i %s %s \n",i,pChan->pRxCode[i],pChan->pTxCode[i]));
+ }
+ }
+ }
+
+ TRACEF(1,("code_string_parse() CTCSS Init Struct %i %i\n",pChan->b.ctcssRxEnable,pChan->b.ctcssTxEnable));
+ if(pChan->b.ctcssRxEnable)
+ {
+ pChan->rxHpfEnable=1;
+ pChan->spsRxLsdNrz->enabled=pChan->rxCenterSlicerEnable=1;
+ pChan->rxCtcssDecodeEnable=1;
+ pChan->rxCtcss->enabled=1;
+ }
+ else
+ {
+ pChan->rxHpfEnable=1;
+ pChan->spsRxLsdNrz->enabled=pChan->rxCenterSlicerEnable=0;
+ pChan->rxCtcssDecodeEnable=0;
+ pChan->rxCtcss->enabled=0;
+ }
+
+ TRACEF(1,("code_string_parse() CTCSS Init Decoders \n"));
+ for(i=0;i<CTCSS_NUM_CODES;i++)
+ {
+ t_tdet *ptdet;
+ ptdet=&(pChan->rxCtcss->tdet[i]);
+ ptdet->counterFactor=coef_ctcss_div[i];
+ ptdet->state=1;
+ ptdet->setpt=(M_Q15*0.041); // 0.069
+ ptdet->hyst =(M_Q15*0.0130);
+ ptdet->binFactor=(M_Q15*0.135); // was 0.140
+ ptdet->fudgeFactor=8;
+ }
+
+
+ // DEFAULT TX CODE
+ TRACEF(1,("code_string_parse() Default Tx Code %s \n",pChan->pTxCodeDefault));
+ pChan->txcodedefaultsmode=SMODE_NULL;
+ p=pChan->pStr=pChan->pTxCodeDefault;
+
+ #ifdef HAVE_XPMRX
+ if(!lsd_code_parse(pChan,3))
+ #endif
+ {
+ sscanf(p,"%f",&f);
+ ti=CtcssFreqIndex(f);
+ if(f>maxctcsstxfreq)maxctcsstxfreq=f;
+
+ if(ti>CTCSS_NULL)
+ {
+ pChan->b.ctcssTxEnable=1;
+ pChan->txctcssdefault_index=ti;
+ pChan->txctcssdefault_value=f;
+ pChan->spsSigGen0->freq=f*10;
+ pChan->txcodedefaultsmode=SMODE_CTCSS;
+ TRACEF(1,("code_string_parse() Tx Default CTCSS = %s %i %f\n",p,ti,f));
+ }
+ }
+
+
+ // set x for maximum length and just change pointers
+ TRACEF(1,("code_string_parse() Filter Config \n"));
+ pSps=pChan->spsTxLsdLpf;
+ if(pSps->x)free(pSps->x);
+ if(maxctcsstxfreq>203.5)
+ {
+ pSps->ncoef=taps_fir_lpf_250_9_66;
+ pSps->size_coef=2;
+ pSps->coef=(void*)coef_fir_lpf_250_9_66;
+ pSps->nx=taps_fir_lpf_250_9_66;
+ pSps->size_x=2;
+ pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
+ pSps->calcAdjust=gain_fir_lpf_250_9_66;
+ TRACEF(1,("code_string_parse() Tx Filter Freq High\n"));
+ }
+ else
+ {
+ pSps->ncoef=taps_fir_lpf_215_9_88;
+ pSps->size_coef=2;
+ pSps->coef=(void*)coef_fir_lpf_215_9_88;
+ pSps->nx=taps_fir_lpf_215_9_88;
+ pSps->size_x=2;
+ pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
+ pSps->calcAdjust=gain_fir_lpf_215_9_88;
+ TRACEF(1,("code_string_parse() Tx Filter Freq Low\n"));
+ }
+
+ // CTCSS Rx Decoder Low Pass Filter
+ hit=0;
+ ii= CtcssFreqIndex(203.5);
+ for(i=ii;i<CTCSS_NUM_CODES;i++)
+ {
+ if(pChan->rxCtcssMap[i]>CTCSS_NULL)hit=1;
+ }
+
+ pSps=pChan->spsRxLsd;
+ if(pSps->x)free(pSps->x);
+ if(hit)
+ {
+ pSps->ncoef=taps_fir_lpf_250_9_66;
+ pSps->size_coef=2;
+ pSps->coef=(void*)coef_fir_lpf_250_9_66;
+ pSps->nx=taps_fir_lpf_250_9_66;
+ pSps->size_x=2;
+ pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
+ pSps->calcAdjust=gain_fir_lpf_250_9_66;
+ TRACEF(1,("code_string_parse() Rx Filter Freq High\n"));
+ }
+ else
+ {
+ pSps->ncoef=taps_fir_lpf_215_9_88;
+ pSps->size_coef=2;
+ pSps->coef=(void*)coef_fir_lpf_215_9_88;
+ pSps->nx=taps_fir_lpf_215_9_88;
+ pSps->size_x=2;
+ pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
+ pSps->calcAdjust=gain_fir_lpf_215_9_88;
+ TRACEF(1,("code_string_parse() Rx Filter Freq Low\n"));
+ }
+
+ if(pChan->b.ctcssRxEnable || pChan->b.dcsRxEnable || pChan->b.lmrRxEnable)
+ {
+ pChan->rxCenterSlicerEnable=1;
+ pSps->enabled=1;
+ }
+ else
+ {
+ pChan->rxCenterSlicerEnable=0;
+ pSps->enabled=0;
+ }
+
+ #if XPMR_DEBUG0 == 1
+ TRACEF(2,("code_string_parse() ctcssRxEnable = %i \n",pChan->b.ctcssRxEnable));
+ TRACEF(2,(" ctcssTxEnable = %i \n",pChan->b.ctcssTxEnable));
+ TRACEF(2,(" dcsRxEnable = %i \n",pChan->b.dcsRxEnable));
+ TRACEF(2,(" lmrRxEnable = %i \n",pChan->b.lmrRxEnable));
+ TRACEF(2,(" txcodedefaultsmode = %i \n",pChan->txcodedefaultsmode));
+ for(i=0;i<CTCSS_NUM_CODES;i++)
+ {
+ TRACEF(2,("rxCtcssMap[%i] = %i \n",i,pChan->rxCtcssMap[i]));
+ }
+ #endif
+
+ #ifdef HAVE_XPMRX
+ lsd_code_parse(pChan,5);
+ #endif
+ TRACEF(1,("code_string_parse(%i) end\n",0));
+
+ return 0;
+}
/*
Convert a Frequency in Hz to a zero based CTCSS Table index
*/
i16 CtcssFreqIndex(float freq)
{
- i16 i,hit=-1;
+ i16 i,hit=CTCSS_NULL;
for(i=0;i<CTCSS_NUM_CODES;i++){
if(freq==freq_ctcss[i])hit=i;
@@ -66,15 +467,15 @@ i16 CtcssFreqIndex(float freq)
return hit;
}
/*
- pmr_rx_frontend
+ pmr_rx_frontend
Takes a block of data and low pass filters it.
Determines the amplitude of high frequency noise for carrier detect.
Decimates input data to change the rate.
*/
-i16 pmr_rx_frontend(t_pmr_sps *mySps)
+i16 pmr_rx_frontend(t_pmr_sps *mySps)
{
#define DCgainBpfNoise 65536
-
+
i16 samples,iOutput, *input, *output, *noutput;
i16 *x, *coef, *coef2;
i32 i, naccum, outputGain, calcAdjust;
@@ -83,7 +484,7 @@ i16 pmr_rx_frontend(t_pmr_sps *mySps)
i16 amax, amin, apeak, discounteru, discounterl, discfactor;
i16 decimator, decimate, doNoise;
- TRACEX(("pmr_rx_frontend()\n"));
+ TRACEJ(5,("pmr_rx_frontend()\n"));
if(!mySps->enabled)return(1);
@@ -112,12 +513,12 @@ i16 pmr_rx_frontend(t_pmr_sps *mySps)
compOut=mySps->compOut;
samples=mySps->nSamples*decimate;
- x=mySps->x;
+ x=mySps->x;
iOutput=0;
if(mySps->parentChan->rxCdType!=CD_XPMR_VOX)doNoise=1;
else doNoise=0;
-
+
for(i=0;i<samples;i++)
{
i16 n;
@@ -127,14 +528,14 @@ i16 pmr_rx_frontend(t_pmr_sps *mySps)
x[n] = x[n-1];
x[0] = input[i*2];
-
+
--decimator;
if(decimator<=0)
{
decimator=decimate;
-
- y=0;
+
+ y=0;
for(n=0; n<nx; n++)
y += coef[n] * x[n];
@@ -153,9 +554,9 @@ i16 pmr_rx_frontend(t_pmr_sps *mySps)
naccum=0;
for(n=0; n<nx; n++)
naccum += coef_fir_bpf_noise_1[n] * x[n];
-
+
naccum /= DCgainBpfNoise;
-
+
if(naccum>amax)
{
amax=naccum;
@@ -177,33 +578,33 @@ i16 pmr_rx_frontend(t_pmr_sps *mySps)
discounterl=discfactor;
amin=(i32)((amin*32700)/32768);
}
-
+
apeak=(amax-amin)/2;
-
+
} // if doNoise
}
if(doNoise)
{
((t_pmr_chan *)(mySps->parentChan))->rxRssi=apeak;
-
+
if(apeak>setpt || (compOut&&(apeak>(setpt-hyst)))) compOut=1;
else compOut=0;
mySps->compOut=compOut;
mySps->amax=amax;
- mySps->amin=amin;
+ mySps->amin=amin;
mySps->apeak=apeak;
mySps->discounteru=discounteru;
- mySps->discounterl=discounterl;
+ mySps->discounterl=discounterl;
}
return 0;
}
-/*
+/*
pmr general purpose fir
works on a block of samples
*/
-i16 pmr_gp_fir(t_pmr_sps *mySps)
+i16 pmr_gp_fir(t_pmr_sps *mySps)
{
i32 nsamples,inputGain,outputGain,calcAdjust;
i16 *input, *output;
@@ -214,7 +615,7 @@ i16 pmr_gp_fir(t_pmr_sps *mySps)
i16 decimator, decimate, interpolate;
i16 numChanOut, selChanOut, mixOut, monoOut;
- TRACEX(("pmr_gp_fir() %i\n",mySps->enabled));
+ TRACEJ(5,("pmr_gp_fir() %i %i\n",mySps->index, mySps->enabled));
if(!mySps->enabled)return(1);
@@ -227,7 +628,7 @@ i16 pmr_gp_fir(t_pmr_sps *mySps)
x = mySps->x;
nx = mySps->nx;
coef = mySps->coef;
-
+
decimator = mySps->decimator;
decimate = mySps->decimate;
interpolate = mySps->interpolate;
@@ -243,11 +644,11 @@ i16 pmr_gp_fir(t_pmr_sps *mySps)
monoOut = mySps->monoOut;
amax=mySps->amax;
- amin=mySps->amin;
+ amin=mySps->amin;
discfactor=mySps->discfactor;
- hyst=mySps->hyst;
- setpt=mySps->setpt;
+ hyst=mySps->hyst;
+ setpt=mySps->setpt;
nsamples=mySps->nSamples;
if(mySps->option==3)
@@ -270,21 +671,21 @@ i16 pmr_gp_fir(t_pmr_sps *mySps)
int ix;
int64_t y=0;
-
+
if(decimate<0)
{
- decimator=decimate;
+ decimator=decimate;
}
for(ix=0;ix<interpolate;ix++)
{
- i16 n;
+ i16 n;
y=0;
-
+
for(n=nx-1; n>0; n--)
x[n] = x[n-1];
x[0] = (input[i]*inputGain)/M_Q8;
-
+
#if 0
--decimator;
if(decimator<=0)
@@ -292,7 +693,7 @@ i16 pmr_gp_fir(t_pmr_sps *mySps)
decimator=decimate;
for(n=0; n<nx; n++)
y += coef[n] * x[n];
- y /= (outputGain*3);
+ y /= (outputGain*3);
output[ii++]=y;
}
#else
@@ -300,13 +701,13 @@ i16 pmr_gp_fir(t_pmr_sps *mySps)
y += coef[n] * x[n];
y=((y/calcAdjust)*outputGain)/M_Q8;
-
+
if(mixOut){
if(monoOut){
output[(ii*2)]=output[(ii*2)+1]+=y;
}
else{
- output[(ii*numChanOut)+selChanOut]+=y;
+ output[(ii*numChanOut)+selChanOut]+=y;
}
}
else{
@@ -336,7 +737,7 @@ i16 pmr_gp_fir(t_pmr_sps *mySps)
discounteru=discfactor;
amax=(i32)((amax*32700)/32768);
}
-
+
if(accum<amin)
{
amin=accum;
@@ -347,9 +748,9 @@ i16 pmr_gp_fir(t_pmr_sps *mySps)
discounterl=discfactor;
amin=(i32)((amin*32700)/32768);
}
-
+
apeak = (i32)(amax-amin)/2;
-
+
if(apeak>setpt)compOut=1;
else if(compOut&&(apeak<(setpt-hyst)))compOut=0;
}
@@ -358,13 +759,13 @@ i16 pmr_gp_fir(t_pmr_sps *mySps)
mySps->decimator = decimator;
mySps->amax=amax;
- mySps->amin=amin;
- mySps->apeak=apeak;
+ mySps->amin=amin;
+ mySps->apeak=apeak;
mySps->discounteru=discounteru;
- mySps->discounterl=discounterl;
-
+ mySps->discounterl=discounterl;
+
mySps->compOut=compOut;
-
+
return 0;
}
/*
@@ -382,7 +783,7 @@ i16 gp_inte_00(t_pmr_sps *mySps)
i32 state00;
i16 coeff00, coeff01;
- TRACEX(("gp_inte_00() %i\n",mySps->enabled));
+ TRACEJ(5,("gp_inte_00() %i\n",mySps->enabled));
if(!mySps->enabled)return(1);
input = mySps->source;
@@ -447,7 +848,7 @@ i16 gp_diff(t_pmr_sps *mySps)
x0=x[0];
- TRACEX(("gp_diff()\n"));
+ TRACEJ(5,("gp_diff()\n"));
for (i=0;i<npoints;i++)
{
@@ -455,7 +856,11 @@ i16 gp_diff(t_pmr_sps *mySps)
x0 = input[i];
temp1 = input[i] * a0;
y0 = (temp0 + temp1)/calcAdjust;
- output[i]=(y0*outputGain)/M_Q8;
+ y0 =(y0*outputGain)/M_Q8;
+
+ if(y0>32766)y0=32766;
+ else if(y0<-32766)y0=-32766;
+ output[i]=y0;
}
x[0]=x0;
@@ -484,10 +889,11 @@ i16 CenterSlicer(t_pmr_sps *mySps)
i32 discounterl; // amplitude detector integrator discharge counter lower
i32 discfactor; // amplitude detector integrator discharge factor
- TRACEX(("CenterSlicer() %i\n",mySps->enabled));
+ TRACEJ(5,("CenterSlicer() %i\n",mySps->enabled));
+ if(!mySps->enabled)return(1);
input = mySps->source;
- output = mySps->sink;
+ output = mySps->sink; // limited output
buff = mySps->buff;
npoints=mySps->nSamples;
@@ -532,27 +938,34 @@ i16 CenterSlicer(t_pmr_sps *mySps)
uhit=1;
}
}
-
- if(--discounteru<=0 && amax>0)
+ #if 0
+ if((discounteru-=1)<=0 && amax>amin)
{
- amax--;
+ if((amax-=10)<amin)amax=amin;
uhit=1;
}
-
- if(--discounterl<=0 && amin<0)
+
+ if((discounterl-=1)<=0 && amin<amax)
{
- amin++;
+ if((amin+=10)>amax)amin=amax;
lhit=1;
}
-
- if(uhit)discounteru=discfactor;
- if(lhit)discounterl=discfactor;
-
+ if(uhit)discounteru=discfactor;
+ if(lhit)discounterl=discfactor;
+
+ #else
+
+ if((amax-=discfactor)<amin)amax=amin;
+ if((amin+=discfactor)>amax)amin=amax;
+
+ #endif
+
apeak = (amax-amin)/2;
center = (amax+amin)/2;
accum = accum - center;
- output[i]=accum;
-
+
+ output[i]=accum; // sink output unlimited/centered.
+
// do limiter function
if(accum>inputGainB)accum=inputGainB;
else if(accum<-inputGainB)accum=-inputGainB;
@@ -560,7 +973,13 @@ i16 CenterSlicer(t_pmr_sps *mySps)
#if XPMR_DEBUG0 == 1
#if 0
- mySps->debugBuff0[i]=center;
+ mySps->parentChan->pRxLsdCen[i]=center; // trace center ref
+ #else
+ static i32 tfx=0;
+ if((tfx++/8)&1) // trace min/max levels
+ mySps->parentChan->pRxLsdCen[i]=amax;
+ else
+ mySps->parentChan->pRxLsdCen[i]=amin;
#endif
#if 0
if(mySps->parentChan->frameCountRx&0x01) mySps->parentChan->prxDebug1[i]=amax;
@@ -599,7 +1018,7 @@ i16 MeasureBlock(t_pmr_sps *mySps)
i32 discounterl; // amplitude detector integrator discharge counter lower
i32 discfactor; // amplitude detector integrator discharge factor
- TRACEX(("MeasureBlock() %i\n",mySps->enabled));
+ TRACEJ(5,("MeasureBlock() %i\n",mySps->enabled));
if(!mySps->enabled)return 1;
@@ -657,7 +1076,7 @@ i16 MeasureBlock(t_pmr_sps *mySps)
apeak = (i32)(amax-amin)/2;
if(output)output[i]=apeak;
}
-
+
mySps->amax=amax;
mySps->amin=amin;
mySps->apeak=apeak;
@@ -665,7 +1084,7 @@ i16 MeasureBlock(t_pmr_sps *mySps)
mySps->discounterl=discounterl;
if(apeak>=setpt) mySps->compOut=1;
else mySps->compOut=0;
-
+
//TRACEX((" -MeasureBlock()=%i\n",mySps->apeak));
return 0;
}
@@ -701,7 +1120,7 @@ i16 SoftLimiter(t_pmr_sps *mySps)
amax=(setpt*124)/128;
amin=-amax;
- TRACEX(("SoftLimiter() %i %i %i) \n",amin, amax,setpt));
+ TRACEJ(5,("SoftLimiter() %i %i %i) \n",amin, amax,setpt));
for(i=0;i<npoints;i++)
{
@@ -745,15 +1164,17 @@ i16 SigGen(t_pmr_sps *mySps)
i32 ph;
i16 i,outputgain,waveform,numChanOut,selChanOut;
- i32 accum;
-
- TRACEX(("SigGen(%i) \n",mySps->option));
+ i32 accum;
+
+ t_pmr_chan *pChan;
+ pChan=mySps->parentChan;
+ TRACEC(5,("SigGen(%i %i %i)\n",mySps->option,mySps->enabled,mySps->state));
if(!mySps->freq ||!mySps->enabled)return 0;
outputgain=mySps->outputGain;
waveform=0;
- numChanOut=mySps->numChanOut;
+ numChanOut=mySps->numChanOut;
selChanOut=mySps->selChanOut;
if(mySps->option==1)
@@ -762,8 +1183,8 @@ i16 SigGen(t_pmr_sps *mySps)
mySps->state=1;
mySps->discfactor=
(SAMPLES_PER_SINE*mySps->freq*PH_FRACT_FACT)/mySps->sampleRate/10;
-
- TRACEX((" SigGen() discfactor = %i\n",mySps->discfactor));
+
+ TRACEF(5,(" SigGen() discfactor = %i\n",mySps->discfactor));
if(mySps->discounterl)mySps->state=2;
}
else if(mySps->option==2)
@@ -772,7 +1193,7 @@ i16 SigGen(t_pmr_sps *mySps)
// phase shift request
mySps->option=0;
mySps->state=2;
- mySps->discounterl=CTCSS_TURN_OFF_TIME-(2*MS_PER_FRAME); //
+ mySps->discounterl=CTCSS_TURN_OFF_TIME-(2*MS_PER_FRAME); //
mySps->discounteru = \
(mySps->discounteru + (((SAMPLES_PER_SINE*shiftfactor)/360)*PH_FRACT_FACT)) % (SAMPLES_PER_SINE*PH_FRACT_FACT);
@@ -838,7 +1259,7 @@ i16 SigGen(t_pmr_sps *mySps)
/*
adder/mixer
takes existing buffer and adds source buffer to destination buffer
- sink buffer = (sink buffer * gain) + source buffer
+ sink buffer = (sink buffer * gain) + source buffer
*/
i16 pmrMixer(t_pmr_sps *mySps)
{
@@ -849,7 +1270,9 @@ i16 pmrMixer(t_pmr_sps *mySps)
i16 discounteru,discounterl,amax,amin,setpt,discfactor;
i16 npoints,uhit,lhit,apeak,measPeak;
- TRACEX(("pmrMixer()\n"));
+ t_pmr_chan *pChan;
+ pChan=mySps->parentChan;
+ TRACEF(5,("pmrMixer()\n"));
input = mySps->source;
inputB = mySps->sourceB;
@@ -858,7 +1281,7 @@ i16 pmrMixer(t_pmr_sps *mySps)
inputGain=mySps->inputGain;
inputGainB=mySps->inputGainB;
outputGain=mySps->outputGain;
-
+
amax=mySps->amax;
amin=mySps->amin;
setpt=mySps->setpt;
@@ -871,7 +1294,7 @@ i16 pmrMixer(t_pmr_sps *mySps)
for(i=0;i<npoints;i++)
{
- accum = ((input[i]*inputGain)/M_Q8) +
+ accum = ((input[i]*inputGain)/M_Q8) +
((inputB[i]*inputGainB)/M_Q8);
accum=(accum*outputGain)/M_Q8;
@@ -879,7 +1302,7 @@ i16 pmrMixer(t_pmr_sps *mySps)
if(measPeak){
lhit=uhit=0;
-
+
if(accum>amax){
amax=accum;
uhit=1;
@@ -896,20 +1319,20 @@ i16 pmrMixer(t_pmr_sps *mySps)
uhit=1;
}
}
-
+
if(--discounteru<=0 && amax>0){
amax--;
uhit=1;
}
-
+
if(--discounterl<=0 && amin<0){
amin++;
lhit=1;
}
-
- if(uhit)discounteru=discfactor;
+
+ if(uhit)discounteru=discfactor;
if(lhit)discounterl=discfactor;
- }
+ }
}
if(measPeak){
@@ -920,19 +1343,21 @@ i16 pmrMixer(t_pmr_sps *mySps)
mySps->discounteru=discounteru;
mySps->discounterl=discounterl;
}
-
+
return 0;
}
/*
- DelayLine
+ DelayLine
*/
i16 DelayLine(t_pmr_sps *mySps)
{
i16 *input, *output, *buff;
i16 i, npoints,buffsize,inindex,outindex;
- TRACEX((" DelayLine() %i\n",mySps->enabled));
-
+ t_pmr_chan *pChan;
+ pChan=mySps->parentChan;
+ TRACEF(5,(" DelayLine() %i\n",mySps->enabled));
+
input = mySps->source;
output = mySps->sink;
buff = (i16*)(mySps->buff);
@@ -946,7 +1371,7 @@ i16 DelayLine(t_pmr_sps *mySps)
{
inindex %= buffsize;
outindex %= buffsize;
-
+
buff[inindex]=input[i];
output[i]=buff[outindex];
inindex++;
@@ -959,25 +1384,27 @@ i16 DelayLine(t_pmr_sps *mySps)
/*
Continuous Tone Coded Squelch (CTCSS) Detector
*/
-i16 ctcss_detect(t_pmr_chan *pmrChan)
+i16 ctcss_detect(t_pmr_chan *pChan)
{
- i16 i,points2do, points=0, *pInput, hit, thit,relax;
- i16 tnum, tmp, indexWas=0, indexNow, gain, peakwas=0, diffpeak;
+ i16 i,points2do,*pInput,hit,thit,relax;
+ i16 tnum, tmp,indexNow,gain,diffpeak;
i16 difftrig;
- i16 lasttv0=0, lasttv1=0, lasttv2=0, tv0, tv1, tv2, indexDebug;
+ i16 tv0,tv1,tv2,tv3,indexDebug;
+ i16 points=0;
+ i16 indexWas=0;
- TRACEX(("ctcss_detect(%p) %i %i %i %i\n",pmrChan,
- pmrChan->rxCtcss->enabled,
- pmrChan->rxCtcssIndex,
- pmrChan->rxCtcss->testIndex,
- pmrChan->rxCtcss->decode));
+ TRACEF(5,("ctcss_detect(%p) %i %i %i %i\n",pChan,
+ pChan->rxCtcss->enabled,
+ 0,
+ pChan->rxCtcss->testIndex,
+ pChan->rxCtcss->decode));
- if(!pmrChan->rxCtcss->enabled)return(1);
+ if(!pChan->rxCtcss->enabled)return(1);
+
+ relax = pChan->rxCtcss->relax;
+ pInput = pChan->rxCtcss->input;
+ gain = pChan->rxCtcss->gain;
- relax = pmrChan->rxCtcss->relax;
- pInput = pmrChan->rxCtcss->input;
- gain = pmrChan->rxCtcss->gain;
-
if(relax) difftrig=(-0.1*M_Q15);
else difftrig=(-0.05*M_Q15);
@@ -992,35 +1419,32 @@ i16 ctcss_detect(t_pmr_chan *pmrChan)
i16 fudgeFactor;
i16 binFactor;
- //TRACEX((" ctcss_detect() tnum=%i %i\n",tnum,pmrChan->rxCtcssMap[tnum]));
+ TRACEF(6,(" ctcss_detect() tnum=%i %i\n",tnum,pChan->rxCtcssMap[tnum]));
+ //if(tnum==14)printf("ctcss_detect() %i %i %i\n",tnum,pChan->rxCtcssMap[tnum], pChan->rxCtcss->decode );
- if( (pmrChan->rxCtcssMap[tnum] < 0) ||
- (pmrChan->rxCtcss->decode>=0 && (tnum!= pmrChan->rxCtcss->decode)) ||
- (!pmrChan->rxCtcss->multiFreq && (tnum!= pmrChan->rxCtcssIndex))
+ if( (pChan->rxCtcssMap[tnum]==CTCSS_NULL) ||
+ (pChan->rxCtcss->decode>CTCSS_NULL && (tnum!= pChan->rxCtcss->decode))
)
continue;
- //TRACEX((" ctcss_detect() tnum=%i\n",tnum));
+ TRACEF(6,(" ctcss_detect() tnum=%i\n",tnum));
- ptdet=&(pmrChan->rxCtcss->tdet[tnum]);
+ ptdet=&(pChan->rxCtcss->tdet[tnum]);
indexDebug=0;
- points=points2do=pmrChan->nSamplesRx;
+ points=points2do=pChan->nSamplesRx;
fudgeFactor=ptdet->fudgeFactor;
binFactor=ptdet->binFactor;
while(ptdet->counter < (points2do*CTCSS_SCOUNT_MUL))
{
- //TRACEX((" ctcss_detect() - inner loop\n"));
tmp=(ptdet->counter/CTCSS_SCOUNT_MUL)+1;
ptdet->counter-=(tmp*CTCSS_SCOUNT_MUL);
points2do-=tmp;
indexNow=points-points2do;
-
- ptdet->counter += ptdet->counterFactor;
- accum = pInput[indexNow-1]; // dude's major bug fix!
+ ptdet->counter += ptdet->counterFactor;
- peakwas=ptdet->peak;
+ accum = pInput[indexNow-1]; // duuuude's major bug fix!
ptdet->z[ptdet->zIndex]+=
(((accum - ptdet->z[ptdet->zIndex])*binFactor)/M_Q15);
@@ -1037,7 +1461,7 @@ i16 ctcss_detect(t_pmr_chan *pmrChan)
static const i16 a1=-13723;
i32 temp0,temp1;
i16 x0;
-
+
//differentiate
x0=ptdet->zd;
temp0 = x0 * a1;
@@ -1053,7 +1477,7 @@ i16 ctcss_detect(t_pmr_chan *pmrChan)
else if(ptdet->dvu)ptdet->dvu--;
tmp=ptdet->setpt;
- if(pmrChan->rxCtcss->decode==tnum)
+ if(pChan->rxCtcss->decode==tnum)
{
if(relax)tmp=(tmp*55)/100;
else tmp=(tmp*80)/100;
@@ -1063,54 +1487,67 @@ i16 ctcss_detect(t_pmr_chan *pmrChan)
{
if(ptdet->decode<(fudgeFactor*32))ptdet->decode++;
}
- else if(pmrChan->rxCtcss->decode==tnum)
+ else if(pChan->rxCtcss->decode==tnum)
{
if(ptdet->peak > ptdet->hyst)ptdet->decode--;
- else if(relax) ptdet->decode--;
- else ptdet->decode-=4;
+ else if(relax) ptdet->decode--;
+ else ptdet->decode-=4;
}
else
{
ptdet->decode=0;
}
- if((pmrChan->rxCtcss->decode==tnum) && !relax && (ptdet->dvu > (0.00075*M_Q15)))
+ if((pChan->rxCtcss->decode==tnum) && !relax && (ptdet->dvu > (0.00075*M_Q15)))
{
ptdet->decode=0;
ptdet->z[0]=ptdet->z[1]=ptdet->z[2]=ptdet->z[3]=ptdet->dvu=0;
- //printf("ctcss_detect() turnoff code!\n");
+ TRACEF(4,("ctcss_detect() turnoff detected by dvdt for tnum = %i.\n",tnum));
}
- if(ptdet->decode<0 || !pmrChan->rxCarrierDetect)ptdet->decode=0;
-
- if(ptdet->decode>=fudgeFactor)thit=tnum;
+ if(ptdet->decode<0 || !pChan->rxCarrierDetect)ptdet->decode=0;
- #if XPMR_DEBUG0 == 1
- //if(thit>=0 && thit==tnum)
- // printf(" ctcss_detect() %i %i %i %i \n",tnum,ptdet->peak,ptdet->setpt,ptdet->hyst);
-
- // tv0=accum;
- tv0=ptdet->peak;
- tv1=diffpeak;
- tv2=ptdet->dvu;
-
- //tv1=ptdet->zi*100;
- while(indexDebug<indexNow)
+ if(ptdet->decode>=fudgeFactor)
{
- if(indexDebug==0)lasttv0=ptdet->pDebug0[points-1];
- if(ptdet->pDebug0)ptdet->pDebug0[indexDebug]=lasttv0;
+ thit=tnum;
+ if(pChan->rxCtcss->decode!=tnum)
+ {
+ ptdet->zd=ptdet->dvu=ptdet->dvd=0;
+ }
+ }
- if(indexDebug==0)lasttv1=ptdet->pDebug1[points-1];
- if(ptdet->pDebug1)ptdet->pDebug1[indexDebug]=lasttv1;
+ #if XPMR_DEBUG0 == 1
+ if(thit>=0 && thit==tnum)
+ TRACEF(6,(" ctcss_detect() %i %i %i %i \n",tnum,ptdet->peak,ptdet->setpt,ptdet->hyst));
- if(indexDebug==0)lasttv2=ptdet->pDebug2[points-1];
- if(ptdet->pDebug2)ptdet->pDebug2[indexDebug]=lasttv2;
+ if(ptdet->pDebug0)
+ {
+ tv0=ptdet->peak;
+ tv1=ptdet->decode;
+ tv2=tmp;
+ tv3=ptdet->dvu*32;
+
+ if(indexDebug==0)
+ {
+ ptdet->lasttv0=ptdet->pDebug0[points-1];
+ ptdet->lasttv1=ptdet->pDebug1[points-1];
+ ptdet->lasttv2=ptdet->pDebug2[points-1];
+ ptdet->lasttv3=ptdet->pDebug3[points-1];
+ }
- indexDebug++;
+ while(indexDebug<indexNow)
+ {
+ ptdet->pDebug0[indexDebug]=ptdet->lasttv0;
+ ptdet->pDebug1[indexDebug]=ptdet->lasttv1;
+ ptdet->pDebug2[indexDebug]=ptdet->lasttv2;
+ ptdet->pDebug3[indexDebug]=ptdet->lasttv3;
+ indexDebug++;
+ }
+ ptdet->lasttv0=tv0;
+ ptdet->lasttv1=tv1;
+ ptdet->lasttv2=tv2;
+ ptdet->lasttv3=tv3;
}
- lasttv0=tv0;
- lasttv1=tv1;
- lasttv2=tv2*100;
#endif
indexWas=indexNow;
ptdet->zIndex=(++ptdet->zIndex)%4;
@@ -1120,36 +1557,40 @@ i16 ctcss_detect(t_pmr_chan *pmrChan)
#if XPMR_DEBUG0 == 1
for(i=indexWas;i<points;i++)
{
- if(ptdet->pDebug0)ptdet->pDebug0[i]=lasttv0;
- if(ptdet->pDebug1)ptdet->pDebug1[i]=lasttv1;
- if(ptdet->pDebug2)ptdet->pDebug2[i]=lasttv2;
+ ptdet->pDebug0[i]=ptdet->lasttv0;
+ ptdet->pDebug1[i]=ptdet->lasttv1;
+ ptdet->pDebug2[i]=ptdet->lasttv2;
+ ptdet->pDebug3[i]=ptdet->lasttv3;
}
#endif
}
//TRACEX((" ctcss_detect() thit %i\n",thit));
- if(pmrChan->rxCtcss->BlankingTimer>0)pmrChan->rxCtcss->BlankingTimer-=points;
- if(pmrChan->rxCtcss->BlankingTimer<0)pmrChan->rxCtcss->BlankingTimer=0;
+ if(pChan->rxCtcss->BlankingTimer>0)pChan->rxCtcss->BlankingTimer-=points;
+ if(pChan->rxCtcss->BlankingTimer<0)pChan->rxCtcss->BlankingTimer=0;
- if(thit>=0 && pmrChan->rxCtcss->decode<0 && !pmrChan->rxCtcss->BlankingTimer)
+ if(thit>CTCSS_NULL && pChan->rxCtcss->decode<=CTCSS_NULL && !pChan->rxCtcss->BlankingTimer)
{
- pmrChan->rxCtcss->decode=thit;
+ pChan->rxCtcss->decode=thit;
+ sprintf(pChan->rxctcssfreq,"%.1f",freq_ctcss[thit]);
+ TRACEC(1,("ctcss decode %i %.1f\n",thit,freq_ctcss[thit]));
}
- else if(thit<0 && pmrChan->rxCtcss->decode>=0)
+ else if(thit<=CTCSS_NULL && pChan->rxCtcss->decode>CTCSS_NULL)
{
- pmrChan->rxCtcss->BlankingTimer=SAMPLE_RATE_NETWORK/5;
- pmrChan->rxCtcss->decode=-1;
-
+ pChan->rxCtcss->BlankingTimer=SAMPLE_RATE_NETWORK/5;
+ pChan->rxCtcss->decode=CTCSS_NULL;
+ strcpy(pChan->rxctcssfreq,"0");
+ TRACEC(1,("ctcss decode NULL\n"));
for(tnum=0;tnum<CTCSS_NUM_CODES;tnum++)
{
t_tdet *ptdet=NULL;
- ptdet=&(pmrChan->rxCtcss->tdet[tnum]);
+ ptdet=&(pChan->rxCtcss->tdet[tnum]);
ptdet->decode=0;
ptdet->z[0]=ptdet->z[1]=ptdet->z[2]=ptdet->z[3]=0;
}
}
- //TRACEX((" ctcss_detect() thit %i %i\n",thit,pmrChan->rxCtcss->decode));
+ //TRACEX((" ctcss_detect() thit %i %i\n",thit,pChan->rxCtcss->decode));
return(0);
}
/*
@@ -1161,6 +1602,7 @@ static i16 TxTestTone(t_pmr_chan *pChan, i16 function)
{
pChan->spsSigGen1->enabled=1;
pChan->spsSigGen1->option=1;
+ pChan->spsSigGen1->outputGain=(.23125*M_Q8); // to match *99 level
pChan->spsTx->source=pChan->spsSigGen1->sink;
}
else
@@ -1169,7 +1611,7 @@ static i16 TxTestTone(t_pmr_chan *pChan, i16 function)
}
return 0;
}
-/*
+/*
assumes:
sampling rate is 48KS/s
samples are all 16 bits
@@ -1178,36 +1620,37 @@ static i16 TxTestTone(t_pmr_chan *pChan, i16 function)
t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
{
i16 i, *inputTmp;
-
t_pmr_chan *pChan;
t_pmr_sps *pSps;
t_dec_ctcss *pDecCtcss;
- t_tdet *ptdet;
- TRACEX(("createPmrChannel(%p,%i)\n",tChan,numSamples));
+ TRACEJ(1,("createPmrChannel(%p,%i)\n",tChan,numSamples));
pChan = (t_pmr_chan *)calloc(sizeof(t_pmr_chan),1);
-
if(pChan==NULL)
{
printf("createPmrChannel() failed\n");
return(NULL);
}
-
- pChan->nSamplesRx=numSamples;
- pChan->nSamplesTx=numSamples;
+
+ #if XPMR_PPTP == 1
+ pptp_init();
+ #endif
pChan->index=pmrChanIndex++;
+ pChan->nSamplesTx=pChan->nSamplesRx=numSamples;
- for(i=0;i<CTCSS_NUM_CODES;i++)
- {
- pChan->rxCtcssMap[i]=-1;
- }
+ pDecCtcss = (t_dec_ctcss *)calloc(sizeof(t_dec_ctcss),1);
+ pChan->rxCtcss=pDecCtcss;
+ pChan->rxctcssfreq[0]=0;
- pChan->rxCtcssIndex=-1;
+ #ifdef HAVE_XPMRX
+ if(tChan->rptnum>=LSD_CHAN_MAX)tChan->rptnum=0;
+ #endif
if(tChan==NULL)
{
+ printf("createPmrChannel() WARNING: NULL tChan!\n");
pChan->rxNoiseSquelchEnable=0;
pChan->rxHpfEnable=0;
pChan->rxDeEmpEnable=0;
@@ -1218,13 +1661,10 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pChan->rxCarrierPoint = 17000;
pChan->rxCarrierHyst = 2500;
- pChan->rxCtcssFreq=103.5;
-
pChan->txHpfEnable=0;
pChan->txLimiterEnable=0;
pChan->txPreEmpEnable=0;
pChan->txLpfEnable=1;
- pChan->txCtcssFreq=103.5;
pChan->txMixA=TX_OUT_VOICE;
pChan->txMixB=TX_OUT_LSD;
}
@@ -1234,49 +1674,66 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pChan->rxCdType=tChan->rxCdType;
pChan->rxSquelchPoint = tChan->rxSquelchPoint;
pChan->rxCarrierHyst = 3000;
- pChan->rxCtcssFreq=tChan->rxCtcssFreq;
+ pChan->rxSqVoxAdj=tChan->rxSqVoxAdj;
- for(i=0;i<CTCSS_NUM_CODES;i++)
- pChan->rxCtcssMap[i]=tChan->rxCtcssMap[i];
-
pChan->txMod=tChan->txMod;
- pChan->txHpfEnable=1;
+ pChan->txHpfEnable=1;
pChan->txLpfEnable=1;
- pChan->txCtcssFreq=tChan->txCtcssFreq;
+
+ pChan->pTxCodeDefault=tChan->pTxCodeDefault;
+ pChan->pRxCodeSrc=tChan->pRxCodeSrc;
+ pChan->pTxCodeSrc=tChan->pTxCodeSrc;
+
pChan->txMixA=tChan->txMixA;
pChan->txMixB=tChan->txMixB;
pChan->radioDuplex=tChan->radioDuplex;
+ pChan->area=tChan->area;
+ pChan->rptnum=tChan->rptnum;
+ pChan->idleinterval=tChan->idleinterval;
+ pChan->turnoffs=tChan->turnoffs;
+ pChan->b.rxpolarity=tChan->b.rxpolarity;
+ pChan->b.txpolarity=tChan->b.txpolarity;
+ pChan->b.dcsrxpolarity=tChan->b.dcsrxpolarity;
+ pChan->b.dcstxpolarity=tChan->b.dcstxpolarity;
+ pChan->b.lsdrxpolarity=tChan->b.lsdrxpolarity;
+ pChan->b.lsdtxpolarity=tChan->b.lsdtxpolarity;
+
+ pChan->txsettletime=tChan->txsettletime;
+ pChan->tracelevel=tChan->tracelevel;
+ pChan->tracetype=tChan->tracetype;
+ pChan->ukey=tChan->ukey;
+ pChan->name=tChan->name;
}
- TRACEX(("misc settings \n"));
- if(pChan->rxCdType==CD_XPMR_NOISE){
- pChan->rxNoiseSquelchEnable=1;
- }
+ pChan->txHpfEnable=1;
+ pChan->txLpfEnable=1;
- if(pChan->rxDemod==RX_AUDIO_FLAT){
- pChan->rxHpfEnable=1;
- pChan->rxDeEmpEnable=1;
- }
+ if(pChan->rxCdType==CD_XPMR_NOISE) pChan->rxNoiseSquelchEnable=1;
+
+ if(pChan->rxDemod==RX_AUDIO_FLAT) pChan->rxDeEmpEnable=1;
pChan->rxCarrierPoint=(pChan->rxSquelchPoint*32767)/100;
pChan->rxCarrierHyst = 3000; //pChan->rxCarrierPoint/15;
-
+
pChan->rxDcsDecodeEnable=0;
- if(pChan->rxCtcssFreq!=0){
+ if(pChan->b.ctcssRxEnable || pChan->b.dcsRxEnable || pChan->b.lmrRxEnable)
+ {
pChan->rxHpfEnable=1;
pChan->rxCenterSlicerEnable=1;
pChan->rxCtcssDecodeEnable=1;
- pChan->rxCtcssIndex=CtcssFreqIndex(pChan->rxCtcssFreq);
}
if(pChan->txMod){
pChan->txPreEmpEnable=1;
pChan->txLimiterEnable=1;
}
-
- TRACEX(("calloc buffers \n"));
+
+ pChan->dd.option=9;
+ dedrift(pChan);
+
+ TRACEF(1,("calloc buffers \n"));
pChan->pRxDemod = calloc(numSamples,2);
pChan->pRxNoise = calloc(numSamples,2);
@@ -1287,8 +1744,8 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pChan->pRxCtcss = calloc(numSamples,2);
pChan->pRxDcTrack = calloc(numSamples,2);
pChan->pRxLsdLimit = calloc(numSamples,2);
-
-
+
+ pChan->pTxInput = calloc(numSamples,2);
pChan->pTxBase = calloc(numSamples,2);
pChan->pTxHpf = calloc(numSamples,2);
pChan->pTxPreEmp = calloc(numSamples,2);
@@ -1298,13 +1755,20 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pChan->pTxComposite = calloc(numSamples,2);
pChan->pSigGen0 = calloc(numSamples,2);
pChan->pSigGen1 = calloc(numSamples,2);
+
+ pChan->prxMeasure = calloc(numSamples,2);
- pChan->pTxCode = calloc(numSamples,2);
pChan->pTxOut = calloc(numSamples,2*2*6); // output buffer
-
+
+#ifdef HAVE_XPMRX
+ pChan->pLsdEnc = calloc(sizeof(t_encLsd),1);
+#endif
+
#if XPMR_DEBUG0 == 1
- pChan->pTxPttIn = calloc(numSamples,2);
- pChan->pTxPttOut = calloc(numSamples,2);
+ TRACEF(1,("configure tracing\n"));
+
+ pChan->pTstTxOut = calloc(numSamples,2);
+ pChan->pRxLsdCen = calloc(numSamples,2);
pChan->prxDebug0 = calloc(numSamples,2);
pChan->prxDebug1 = calloc(numSamples,2);
pChan->prxDebug2 = calloc(numSamples,2);
@@ -1314,41 +1778,175 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pChan->ptxDebug2 = calloc(numSamples,2);
pChan->ptxDebug3 = calloc(numSamples,2);
pChan->pNull = calloc(numSamples,2);
- for(i=0;i<numSamples;i++)pChan->pNull[i]=((i%(numSamples/2))*8000)-4000;
- #endif
- TRACEX(("create ctcss\n"));
+ for(i=0;i<numSamples;i++)pChan->pNull[i]=((i%(numSamples/2))*8000)-4000;
- pDecCtcss = (t_dec_ctcss *)calloc(sizeof(t_dec_ctcss),1);
-
- pChan->rxCtcss=pDecCtcss;
- pDecCtcss->enabled=1;
- pDecCtcss->gain=1*M_Q8;
- pDecCtcss->limit=8192;
- pDecCtcss->input=pChan->pRxLsdLimit;
- pDecCtcss->testIndex=pChan->rxCtcssIndex;
- if(!pDecCtcss->testIndex)pDecCtcss->testIndex=1;
- pChan->rxCtcssMap[pChan->rxCtcssIndex]=pChan->rxCtcssIndex;
- pDecCtcss->decode=-1;
+ pChan->rxCtcss->pDebug0=calloc(numSamples,2);
+ pChan->rxCtcss->pDebug1=calloc(numSamples,2);
+ pChan->rxCtcss->pDebug2=calloc(numSamples,2);
+ pChan->rxCtcss->pDebug3=calloc(numSamples,2);
for(i=0;i<CTCSS_NUM_CODES;i++)
{
- ptdet=&(pChan->rxCtcss->tdet[i]);
- ptdet->state=1;
- ptdet->setpt=(M_Q15*0.067); // 0.069
- ptdet->hyst =(M_Q15*0.020);
- ptdet->counterFactor=coef_ctcss_div[i];
- ptdet->binFactor=(M_Q15*0.135); // was 0.140
- ptdet->fudgeFactor=8;
- }
+ pChan->rxCtcss->tdet[i].pDebug0=calloc(numSamples,2);
+ pChan->rxCtcss->tdet[i].pDebug1=calloc(numSamples,2);
+ pChan->rxCtcss->tdet[i].pDebug2=calloc(numSamples,2);
+ pChan->rxCtcss->tdet[i].pDebug3=calloc(numSamples,2);
+ }
+
+ // buffer, 2 bytes per sample, and 16 channels
+ pChan->prxDebug=calloc(numSamples*16,2);
+ pChan->ptxDebug=calloc(numSamples*16,2);
+
+ // TSCOPE CONFIGURATION SETSCOPE configure debug traces and sources for each channel of the output
+ pChan->sdbg = (t_sdbg *)calloc(sizeof(t_sdbg),1);
+
+ for(i=0;i<XPMR_DEBUG_CHANS;i++)pChan->sdbg->trace[i]=-1;
+
+ TRACEF(1,("pChan->tracetype = %i\n",pChan->tracetype));
+
+ if(pChan->tracetype==1) // CTCSS DECODE
+ {
+ pChan->sdbg->source [0]=pChan->pRxDemod;
+ pChan->sdbg->source [1]=pChan->pRxBase;
+ pChan->sdbg->source [2]=pChan->pRxNoise;
+ pChan->sdbg->trace [3]=RX_NOISE_TRIG;
+ pChan->sdbg->source [4]=pChan->pRxLsd;
+ pChan->sdbg->source [5]=pChan->pRxLsdCen;
+ pChan->sdbg->source [6]=pChan->pRxLsdLimit;
+ pChan->sdbg->source [7]=pChan->rxCtcss->tdet[3].pDebug0;
+ pChan->sdbg->trace [8]=RX_CTCSS_DECODE;
+ pChan->sdbg->trace [9]=RX_SMODE;
+ }
+ if(pChan->tracetype==2) // CTCSS DECODE
+ {
+ pChan->sdbg->source [0]=pChan->pRxDemod;
+ pChan->sdbg->source [1]=pChan->pRxBase;
+ pChan->sdbg->trace [2]=RX_NOISE_TRIG;
+ pChan->sdbg->source [3]=pChan->pRxLsd;
+ pChan->sdbg->source [4]=pChan->pRxLsdCen;
+ pChan->sdbg->source [5]=pChan->pRxDcTrack;
+ pChan->sdbg->source [6]=pChan->pRxLsdLimit;
+ pChan->sdbg->source [7]=pChan->rxCtcss->tdet[3].pDebug0;
+ pChan->sdbg->source [8]=pChan->rxCtcss->tdet[3].pDebug1;
+ pChan->sdbg->source [9]=pChan->rxCtcss->tdet[3].pDebug2;
+ pChan->sdbg->source [10]=pChan->rxCtcss->tdet[3].pDebug3;
+ pChan->sdbg->trace [11]=RX_CTCSS_DECODE;
+ pChan->sdbg->trace [12]=RX_SMODE;
+ pChan->sdbg->trace [13]=TX_PTT_IN;
+ pChan->sdbg->trace [14]=TX_PTT_OUT;
+ pChan->sdbg->source [15]=pChan->pTxLsdLpf;
+ }
+ else if(pChan->tracetype==3) // DCS DECODE
+ {
+ pChan->sdbg->source [0]=pChan->pRxDemod;
+ pChan->sdbg->source [1]=pChan->pRxBase;
+ pChan->sdbg->trace [2]=RX_NOISE_TRIG;
+ pChan->sdbg->source [3]=pChan->pRxLsd;
+ pChan->sdbg->source [4]=pChan->pRxLsdCen;
+ pChan->sdbg->source [5]=pChan->pRxDcTrack;
+ pChan->sdbg->trace [6]=RX_DCS_CLK;
+ pChan->sdbg->trace [7]=RX_DCS_DIN;
+ pChan->sdbg->trace [8]=RX_DCS_DEC;
+ pChan->sdbg->trace [9]=RX_SMODE;
+ pChan->sdbg->trace [10]=TX_PTT_IN;
+ pChan->sdbg->trace [11]=TX_PTT_OUT;
+ pChan->sdbg->trace [12]=TX_LSD_CLK;
+ pChan->sdbg->trace [13]=TX_LSD_DAT;
+ pChan->sdbg->trace [14]=TX_LSD_GEN;
+ pChan->sdbg->source [14]=pChan->pTxLsd;
+ pChan->sdbg->source [15]=pChan->pTxLsdLpf;
+ }
+ else if(pChan->tracetype==4) // LSD DECODE
+ {
+ pChan->sdbg->source [0]=pChan->pRxDemod;
+ pChan->sdbg->source [1]=pChan->pRxBase;
+ pChan->sdbg->trace [2]=RX_NOISE_TRIG;
+ pChan->sdbg->source [3]=pChan->pRxLsd;
+ pChan->sdbg->source [4]=pChan->pRxLsdCen;
+ pChan->sdbg->source [5]=pChan->pRxDcTrack;
+ pChan->sdbg->trace [6]=RX_LSD_CLK;
+ pChan->sdbg->trace [7]=RX_LSD_DAT;
+ pChan->sdbg->trace [8]=RX_LSD_ERR;
+ pChan->sdbg->trace [9]=RX_LSD_SYNC;
+ pChan->sdbg->trace [10]=RX_SMODE;
+ pChan->sdbg->trace [11]=TX_PTT_IN;
+ pChan->sdbg->trace [12]=TX_PTT_OUT;
+ pChan->sdbg->trace [13]=TX_LSD_CLK;
+ pChan->sdbg->trace [14]=TX_LSD_DAT;
+ //pChan->sdbg->trace [14]=TX_LSD_GEN;
+ //pChan->sdbg->source [14]=pChan->pTxLsd;
+ pChan->sdbg->source [15]=pChan->pTxLsdLpf;
+ }
+ else if(pChan->tracetype==5) // LSD LOGIC
+ {
+ pChan->sdbg->source [0]=pChan->pRxBase;
+ pChan->sdbg->trace [1]=RX_NOISE_TRIG;
+ pChan->sdbg->source [2]=pChan->pRxDcTrack;
+ pChan->sdbg->trace [3]=RX_LSD_SYNC;
+ pChan->sdbg->trace [4]=RX_SMODE;
+ pChan->sdbg->trace [5]=TX_PTT_IN;
+ pChan->sdbg->trace [6]=TX_PTT_OUT;
+ pChan->sdbg->source [7]=pChan->pTxLsdLpf;
+ }
+ else if(pChan->tracetype==6)
+ {
+ // tx clock skew and jitter buffer
+ pChan->sdbg->source [0]=pChan->pRxDemod;
+ pChan->sdbg->source [5]=pChan->pTxBase;
+ pChan->sdbg->trace [6]=TX_DEDRIFT_LEAD;
+ pChan->sdbg->trace [7]=TX_DEDRIFT_ERR;
+ pChan->sdbg->trace [8]=TX_DEDRIFT_FACTOR;
+ pChan->sdbg->trace [9]=TX_DEDRIFT_DRIFT;
+ }
+ else if(pChan->tracetype==7)
+ {
+ // tx path
+ pChan->sdbg->source [0]=pChan->pRxBase;
+ pChan->sdbg->trace [1]=RX_NOISE_TRIG;
+ pChan->sdbg->source [2]=pChan->pRxLsd;
+ pChan->sdbg->trace [3]=RX_CTCSS_DECODE;
+ pChan->sdbg->source [4]=pChan->pRxHpf;
+
+ pChan->sdbg->trace [5]=TX_PTT_IN;
+ pChan->sdbg->trace [6]=TX_PTT_OUT;
+
+ pChan->sdbg->source [7]=pChan->pTxBase;
+ pChan->sdbg->source [8]=pChan->pTxHpf;
+ pChan->sdbg->source [9]=pChan->pTxPreEmp;
+ pChan->sdbg->source [10]=pChan->pTxLimiter;
+ pChan->sdbg->source [11]=pChan->pTxComposite;
+ pChan->sdbg->source [12]=pChan->pTxLsdLpf;
+ }
+
+ for(i=0;i<XPMR_DEBUG_CHANS;i++){
+ if(pChan->sdbg->trace[i]>=0)pChan->sdbg->point[pChan->sdbg->trace[i]]=i;
+ }
+ pChan->sdbg->mode=1;
+ #endif
+
+ #ifdef XPMRX_H
+ // LSD GENERATOR
+ pSps=pChan->spsLsdGen=createPmrSps(pChan);
+ pSps->source=NULL;
+ pSps->sink=pChan->pTxLsd;
+ pSps->numChanOut=1;
+ pSps->selChanOut=0;
+ pSps->sigProc=LsdGen;
+ pSps->nSamples=pChan->nSamplesTx;
+ pSps->outputGain=(.25*M_Q8);
+ pSps->option=0;
+ pSps->interpolate=1;
+ pSps->decimate=1;
+ pSps->enabled=0;
+ #endif
// General Purpose Function Generator
- pSps=pChan->spsSigGen1=createPmrSps();
- pSps->parentChan=pChan;
- pSps->sink=pChan->pSigGen1;
+ pSps=pChan->spsSigGen1=createPmrSps(pChan);
+ pSps->sink=pChan->pSigGen1;
pSps->numChanOut=1;
pSps->selChanOut=0;
- pSps->sigProc=SigGen;
+ pSps->sigProc=SigGen;
pSps->nSamples=pChan->nSamplesTx;
pSps->sampleRate=SAMPLE_RATE_NETWORK;
pSps->freq=10000; // in increments of 0.1 Hz
@@ -1360,26 +1958,24 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
// CTCSS ENCODER
- pSps = pChan->spsSigGen0 = createPmrSps();
- pSps->parentChan=pChan;
- pSps->sink=pChan->pTxLsd;
- pSps->sigProc=SigGen;
+ pSps = pChan->spsSigGen0 = createPmrSps(pChan);
+ pSps->sink=pChan->pTxLsd;
+ pSps->sigProc=SigGen;
pSps->numChanOut=1;
pSps->selChanOut=0;
pSps->nSamples=pChan->nSamplesTx;
pSps->sampleRate=SAMPLE_RATE_NETWORK;
- pSps->freq=pChan->txCtcssFreq*10; // in increments of 0.1 Hz
+ pSps->freq=1000; // in 0.1 Hz steps
pSps->outputGain=(0.5*M_Q8);
pSps->option=0;
pSps->interpolate=1;
pSps->decimate=1;
pSps->enabled=0;
-
// Tx LSD Low Pass Filter
- pSps=pChan->spsTxLsdLpf=pSps->nextSps=createPmrSps();
+ pSps=pChan->spsTxLsdLpf=createPmrSps(pChan);
pSps->source=pChan->pTxLsd;
- pSps->sink=pChan->pTxLsdLpf;
+ pSps->sink=pChan->pTxLsdLpf;
pSps->sigProc=pmr_gp_fir;
pSps->enabled=0;
pSps->numChanOut=1;
@@ -1389,41 +1985,30 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pSps->interpolate=1;
pSps->inputGain=(1*M_Q8);
pSps->outputGain=(1*M_Q8);
-
- if(pChan->txCtcssFreq>203.0)
- {
- pSps->ncoef=taps_fir_lpf_250_9_66;
- pSps->size_coef=2;
- pSps->coef=(void*)coef_fir_lpf_250_9_66;
- pSps->nx=taps_fir_lpf_250_9_66;
- pSps->size_x=2;
- pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
- pSps->calcAdjust=gain_fir_lpf_250_9_66;
- }
- else
- {
- pSps->ncoef=taps_fir_lpf_215_9_88;
- pSps->size_coef=2;
- pSps->coef=(void*)coef_fir_lpf_215_9_88;
- pSps->nx=taps_fir_lpf_215_9_88;
- pSps->size_x=2;
- pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
- pSps->calcAdjust=gain_fir_lpf_215_9_88;
- }
+
+ // configure the longer, lower cutoff filter by default
+ pSps->ncoef=taps_fir_lpf_215_9_88;
+ pSps->size_coef=2;
+ pSps->coef=(void*)coef_fir_lpf_215_9_88;
+ pSps->nx=taps_fir_lpf_215_9_88;
+ pSps->size_x=2;
+ pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
+ pSps->calcAdjust=gain_fir_lpf_215_9_88;
pSps->inputGain=(1*M_Q8);
pSps->outputGain=(1*M_Q8);
-
- if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
-
+ TRACEF(1,("spsTxLsdLpf = sps \n"));
+
+ if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
+
+
// RX Process
- TRACEX(("create rx\n"));
+ TRACEF(1,("create rx\n"));
pSps = NULL;
// allocate space for first sps and set pointers
- pSps=pChan->spsRx=createPmrSps();
- pSps->parentChan=pChan;
+ pSps=pChan->spsRx=createPmrSps(pChan);
pSps->source=NULL; //set when called
pSps->sink=pChan->pRxBase;
pSps->sigProc=pmr_rx_frontend;
@@ -1440,7 +2025,7 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pSps->x=(void*)(calloc(pSps->nx,pSps->size_coef));
pSps->calcAdjust=(gain_fir_lpf_3K_1*256)/0x0100;
pSps->outputGain=(1.0*M_Q8);
- pSps->discfactor=2;
+ pSps->discfactor=2;
pSps->hyst=pChan->rxCarrierHyst;
pSps->setpt=pChan->rxCarrierPoint;
pChan->prxSquelchAdjust=&pSps->setpt;
@@ -1450,11 +2035,10 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pSps->debugBuff2=pChan->prxDebug0;
#endif
-
+
// allocate space for next sps and set pointers
// Rx SubAudible Decoder Low Pass Filter
- pSps=pSps->nextSps=createPmrSps();
- pSps->parentChan=pChan;
+ pSps=pChan->spsRxLsd=pSps->nextSps=createPmrSps(pChan);
pSps->source=pChan->pRxBase;
pSps->sink=pChan->pRxLsd;
pSps->sigProc=pmr_gp_fir;
@@ -1465,59 +2049,40 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pSps->decimator=pSps->decimate=1;
pSps->interpolate=1;
- if(pChan->rxCtcssFreq>203.5)
- {
- pSps->ncoef=taps_fir_lpf_250_9_66;
- pSps->size_coef=2;
- pSps->coef=(void*)coef_fir_lpf_250_9_66;
- pSps->nx=taps_fir_lpf_250_9_66;
- pSps->size_x=2;
- pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
- pSps->calcAdjust=gain_fir_lpf_250_9_66;
- }
- else
- {
- pSps->ncoef=taps_fir_lpf_215_9_88;
- pSps->size_coef=2;
- pSps->coef=(void*)coef_fir_lpf_215_9_88;
- pSps->nx=taps_fir_lpf_215_9_88;
- pSps->size_x=2;
- pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
- pSps->calcAdjust=gain_fir_lpf_215_9_88;
- }
+ // configure the the larger, lower cutoff filter by default
+ pSps->ncoef=taps_fir_lpf_215_9_88;
+ pSps->size_coef=2;
+ pSps->coef=(void*)coef_fir_lpf_215_9_88;
+ pSps->nx=taps_fir_lpf_215_9_88;
+ pSps->size_x=2;
+ pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
+ pSps->calcAdjust=gain_fir_lpf_215_9_88;
pSps->inputGain=(1*M_Q8);
pSps->outputGain=(1*M_Q8);
pChan->prxCtcssMeasure=pSps->sink;
- pChan->prxCtcssAdjust=&(pSps->outputGain);
-
+ pChan->prxCtcssAdjust=&(pSps->outputGain);
+
+ // CTCSS CenterSlicer
+ pSps=pChan->spsRxLsdNrz=pSps->nextSps=createPmrSps(pChan);
+ pSps->source=pChan->pRxLsd;
+ pSps->sink=pChan->pRxDcTrack;
+ pSps->buff=pChan->pRxLsdLimit;
+ pSps->sigProc=CenterSlicer;
+ pSps->nSamples=pChan->nSamplesRx;
+ pSps->discfactor=LSD_DFS; // centering time constant
+ pSps->inputGain=(1*M_Q8);
+ pSps->outputGain=(1*M_Q8);
+ pSps->setpt=4900; // ptp clamp for DC centering
+ pSps->inputGainB=625; // peak output limiter clip point
+ pSps->enabled=0;
- // allocate space for next sps and set pointers
- // CenterSlicer
- if(pChan->rxCenterSlicerEnable)
- {
- pSps=pSps->nextSps=createPmrSps();
- pSps->parentChan=pChan;
- pSps->source=pChan->pRxLsd;
- pSps->sink=pChan->pRxDcTrack;
- pSps->buff=pChan->pRxLsdLimit;
- pSps->sigProc=CenterSlicer;
- pSps->enabled=1;
- pSps->nSamples=pChan->nSamplesRx;
- pSps->discfactor=800;
- pSps->inputGain=(1*M_Q8);
- pSps->outputGain=(1*M_Q8);
- pSps->setpt=3000;
- pSps->inputGainB=1000; // limiter set point
- }
- // allocate space for next sps and set pointers
// Rx HPF
- pSps=pSps->nextSps=createPmrSps();
- pSps->parentChan=pChan;
+ pSps=pSps->nextSps=createPmrSps(pChan);
pChan->spsRxHpf=pSps;
pSps->source=pChan->pRxBase;
- pSps->sink=pChan->pRxHpf;
+ pSps->sink=pChan->pRxHpf;
pSps->sigProc=pmr_gp_fir;
pSps->enabled=1;
pSps->numChanOut=1;
@@ -1531,49 +2096,49 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pSps->nx=taps_fir_hpf_300_9_66;
pSps->size_x=2;
pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
- if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
+ if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
pSps->calcAdjust=gain_fir_hpf_300_9_66;
pSps->inputGain=(1*M_Q8);
pSps->outputGain=(1*M_Q8);
+ pChan->prxVoiceAdjust=&(pSps->outputGain);
pChan->spsRxOut=pSps;
// allocate space for next sps and set pointers
// Rx DeEmp
if(pChan->rxDeEmpEnable){
- pSps=pSps->nextSps=createPmrSps();
- pSps->parentChan=pChan;
+ pSps=pSps->nextSps=createPmrSps(pChan);
pChan->spsRxDeEmp=pSps;
pSps->source=pChan->pRxHpf;
- pSps->sink=pChan->pRxSpeaker;
- pChan->spsRxOut=pSps; // OUTPUT STRUCTURE! maw
+ pSps->sink=pChan->pRxSpeaker;
+ pChan->spsRxOut=pSps; // OUTPUT STRUCTURE!
pSps->sigProc=gp_inte_00;
pSps->enabled=1;
pSps->nSamples=pChan->nSamplesRx;
-
+
pSps->ncoef=taps_int_lpf_300_1_2;
pSps->size_coef=2;
pSps->coef=(void*)coef_int_lpf_300_1_2;
-
+
pSps->nx=taps_int_lpf_300_1_2;
pSps->size_x=4;
pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
- if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
+ if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
pSps->calcAdjust=gain_int_lpf_300_1_2/2;
pSps->inputGain=(1.0*M_Q8);
pSps->outputGain=(1.0*M_Q8);
pChan->prxVoiceMeasure=pSps->sink;
- pChan->prxVoiceAdjust=&(pSps->outputGain);
+ pChan->prxVoiceAdjust=&(pSps->outputGain);
}
if(pChan->rxDelayLineEnable)
{
- TRACEX(("create delayline\n"));
- pSps=pChan->spsDelayLine=pSps->nextSps=createPmrSps();
+ TRACEF(1,("create delayline\n"));
+ pSps=pChan->spsDelayLine=pSps->nextSps=createPmrSps(pChan);
pSps->sigProc=DelayLine;
- pSps->source=pChan->pRxSpeaker;
+ pSps->source=pChan->pRxSpeaker;
pSps->sink=pChan->pRxSpeaker;
pSps->enabled=0;
- pSps->inputGain=1*M_Q8;
+ pSps->inputGain=1*M_Q8;
pSps->outputGain=1*M_Q8;
pSps->nSamples=pChan->nSamplesRx;
pSps->buffSize=4096;
@@ -1584,36 +2149,40 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
if(pChan->rxCdType==CD_XPMR_VOX)
{
- TRACEX(("create vox measureblock\n"));
- pSps=pChan->spsRxVox=pSps->nextSps=createPmrSps();
+ TRACEF(1,("create vox measureblock\n"));
+ pChan->prxVoxMeas=calloc(pChan->nSamplesRx,2);
+
+ pSps=pChan->spsRxVox=pSps->nextSps=createPmrSps(pChan);
pSps->sigProc=MeasureBlock;
pSps->parentChan=pChan;
pSps->source=pChan->pRxBase;
- pSps->sink=pChan->prxDebug1;
- pSps->inputGain=1*M_Q8;
+ pSps->sink=pChan->prxVoxMeas;
+ pSps->inputGain=1*M_Q8;
pSps->outputGain=1*M_Q8;
pSps->nSamples=pChan->nSamplesRx;
pSps->discfactor=3;
- pSps->setpt=(0.01*M_Q15);
+ if(pChan->rxSqVoxAdj==0)
+ pSps->setpt=(0.011*M_Q15);
+ else
+ pSps->setpt=(pChan->rxSqVoxAdj);
pSps->hyst=(pSps->setpt/10);
pSps->enabled=1;
}
// tuning measure block
- pSps=pChan->spsMeasure=pSps->nextSps=createPmrSps();
- pSps->parentChan=pChan;
- pSps->source=pChan->spsRx->sink;
- pSps->sink=pChan->prxDebug2;
+ pSps=pChan->spsMeasure=pSps->nextSps=createPmrSps(pChan);
+ pSps->source=pChan->spsRx->sink;
+ pSps->sink=pChan->prxMeasure;
pSps->sigProc=MeasureBlock;
pSps->enabled=0;
pSps->nSamples=pChan->nSamplesRx;
- pSps->discfactor=10;
+ pSps->discfactor=10;
pSps->nextSps=NULL; // last sps in chain RX
// CREATE TRANSMIT CHAIN
- TRACEX((" create tx\n"));
+ TRACEF(1,("create tx\n"));
inputTmp=NULL;
pSps = NULL;
@@ -1622,10 +2191,10 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
// Tx HPF SubAudible
if(pChan->txHpfEnable)
{
- pSps=createPmrSps();
+ pSps=createPmrSps(pChan);
pChan->spsTx=pSps;
pSps->source=pChan->pTxBase;
- pSps->sink=pChan->pTxHpf;
+ pSps->sink=pChan->pTxHpf;
pSps->sigProc=pmr_gp_fir;
pSps->enabled=1;
pSps->numChanOut=1;
@@ -1639,7 +2208,7 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pSps->nx=taps_fir_hpf_300_9_66;
pSps->size_x=2;
pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
- if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
+ if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
pSps->calcAdjust=gain_fir_hpf_300_9_66;
pSps->inputGain=(1*M_Q8);
pSps->outputGain=(1*M_Q8);
@@ -1649,37 +2218,36 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
// Tx PreEmphasis
if(pChan->txPreEmpEnable)
{
- if(pSps==NULL) pSps=pChan->spsTx=createPmrSps();
- else pSps=pSps->nextSps=createPmrSps();
-
- pSps->parentChan=pChan;
+ if(pSps==NULL) pSps=pChan->spsTx=createPmrSps(pChan);
+ else pSps=pSps->nextSps=createPmrSps(pChan);
+
pSps->source=inputTmp;
- pSps->sink=pChan->pTxPreEmp;
-
+ pSps->sink=pChan->pTxPreEmp;
+
pSps->sigProc=gp_diff;
pSps->enabled=1;
pSps->nSamples=pChan->nSamplesTx;
-
+
pSps->ncoef=taps_int_hpf_4000_1_2;
pSps->size_coef=2;
pSps->coef=(void*)coef_int_hpf_4000_1_2;
-
+
pSps->nx=taps_int_hpf_4000_1_2;
pSps->size_x=2;
pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
- pSps->outputGain=(1*M_Q8);
+
pSps->calcAdjust=gain_int_hpf_4000_1_2;
pSps->inputGain=(1*M_Q8);
- pSps->outputGain=(1*M_Q8);
+ pSps->outputGain=(1*M_Q8); // to match flat at 1KHz
inputTmp=pSps->sink;
}
// Tx Limiter
if(pChan->txLimiterEnable)
{
- if(pSps==NULL) pSps=pChan->spsTx=createPmrSps();
- else pSps=pSps->nextSps=createPmrSps();
+ if(pSps==NULL) pSps=pChan->spsTx=createPmrSps(pChan);
+ else pSps=pSps->nextSps=createPmrSps(pChan);
pSps->source=inputTmp;
pSps->sink=pChan->pTxLimiter;
pSps->sigProc=SoftLimiter;
@@ -1695,38 +2263,37 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
if((pChan->txMixA==TX_OUT_COMPOSITE)||(pChan->txMixB==TX_OUT_COMPOSITE))
{
if(pSps==NULL)
- pSps=pChan->spsTx=createPmrSps();
+ pSps=pChan->spsTx=createPmrSps(pChan);
else
- pSps=pSps->nextSps=createPmrSps();
+ pSps=pSps->nextSps=createPmrSps(pChan);
pSps->source=inputTmp;
pSps->sourceB=pChan->pTxLsdLpf; //asdf ??? !!! maw pTxLsdLpf
pSps->sink=pChan->pTxComposite;
pSps->sigProc=pmrMixer;
pSps->enabled=1;
pSps->nSamples=pChan->nSamplesTx;
- pSps->inputGain=2*M_Q8;
- pSps->inputGainB=1*M_Q8/8;
+ pSps->inputGain=2*M_Q8;
+ pSps->inputGainB=1*M_Q8/8;
pSps->outputGain=1*M_Q8;
pSps->setpt=0;
inputTmp=pSps->sink;
pChan->ptxCtcssAdjust=&pSps->inputGainB;
}
- // Chan A Upsampler and Filter
- if(pSps==NULL) pSps=pChan->spsTx=createPmrSps();
- else pSps=pSps->nextSps=createPmrSps();
+ // Chan A Upsampler and Filter
+ if(pSps==NULL) pSps=pChan->spsTx=createPmrSps(pChan);
+ else pSps=pSps->nextSps=createPmrSps(pChan);
pChan->spsTxOutA=pSps;
if(!pChan->spsTx)pChan->spsTx=pSps;
- pSps->parentChan=pChan;
if(pChan->txMixA==TX_OUT_COMPOSITE)
{
- pSps->source=pChan->pTxComposite;
+ pSps->source=pChan->pTxComposite;
}
else if(pChan->txMixA==TX_OUT_LSD)
{
- pSps->source=pChan->pTxLsdLpf;
+ pSps->source=pChan->pTxLsdLpf;
}
else if(pChan->txMixA==TX_OUT_VOICE)
{
@@ -1734,14 +2301,15 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
}
else if (pChan->txMixA==TX_OUT_AUX)
{
- pSps->source=inputTmp;
+ pSps->source=inputTmp;
}
else
{
- pSps->source=NULL;
+ pSps->source=NULL; // maw sph asdf !!! no blow up
+ pSps->source=inputTmp;
}
-
- pSps->sink=pChan->pTxOut;
+
+ pSps->sink=pChan->pTxOut;
pSps->sigProc=pmr_gp_fir;
pSps->enabled=1;
pSps->numChanOut=2;
@@ -1754,7 +2322,7 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pSps->nx=taps_fir_lpf_3K_1;
pSps->size_x=2;
pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
- if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
+ if(pSps==NULL)printf("Error: calloc(), createPmrChannel()\n");
pSps->calcAdjust=gain_fir_lpf_3K_1;
pSps->inputGain=(1*M_Q8);
pSps->outputGain=(1*M_Q8);
@@ -1762,17 +2330,16 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
else pSps->monoOut=0;
- // Chan B Upsampler and Filter
+ // Chan B Upsampler and Filter
if((pChan->txMixA!=pChan->txMixB)&&(pChan->txMixB!=TX_OUT_OFF))
{
- if(pSps==NULL) pSps=pChan->spsTx=createPmrSps();
- else pSps=pSps->nextSps=createPmrSps();
+ if(pSps==NULL) pSps=pChan->spsTx=createPmrSps(pChan);
+ else pSps=pSps->nextSps=createPmrSps(pChan);
pChan->spsTxOutB=pSps;
- pSps->parentChan=pChan;
if(pChan->txMixB==TX_OUT_COMPOSITE)
{
- pSps->source=pChan->pTxComposite;
+ pSps->source=pChan->pTxComposite;
}
else if(pChan->txMixB==TX_OUT_LSD)
{
@@ -1789,10 +2356,10 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
}
else
{
- pSps->source=NULL;
+ pSps->source=NULL;
}
- pSps->sink=pChan->pTxOut;
+ pSps->sink=pChan->pTxOut;
pSps->sigProc=pmr_gp_fir;
pSps->enabled=1;
pSps->numChanOut=2;
@@ -1810,46 +2377,33 @@ t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples)
pSps->calcAdjust=(gain_fir_lpf_3K_1);
pSps->inputGain=(1*M_Q8);
pSps->outputGain=(1*M_Q8);
-
}
pSps->nextSps=NULL;
- #if XPMR_DEBUG0 == 1
- {
- t_tdet *ptdet;
- TRACEX((" configure tracing\n"));
-
- pChan->rxCtcss->pDebug0=calloc(numSamples,2);
- pChan->rxCtcss->pDebug1=calloc(numSamples,2);
- pChan->rxCtcss->pDebug2=calloc(numSamples,2);
-
- for(i=0;i<CTCSS_NUM_CODES;i++){
- ptdet=&(pChan->rxCtcss->tdet[i]);
- ptdet->pDebug0=calloc(numSamples,2);
- ptdet->pDebug1=calloc(numSamples,2);
- ptdet->pDebug2=calloc(numSamples,2);
- }
+ // Configure Coded Signaling
+ code_string_parse(pChan);
- // buffer, 2 bytes per sample, and 16 channels
- pChan->prxDebug=calloc(numSamples*16,2);
- pChan->ptxDebug=calloc(numSamples*16,2);
- }
- #endif
+ pChan->smode=SMODE_NULL;
+ pChan->smodewas=SMODE_NULL;
+ pChan->smodetime=2500;
+ pChan->smodetimer=0;
+ pChan->b.smodeturnoff=0;
+
+ pChan->txsettletimer=0;
- TRACEX((" createPmrChannel() end\n"));
+ TRACEF(1,("createPmrChannel() end\n"));
return pChan;
}
-/*
+/*
*/
i16 destroyPmrChannel(t_pmr_chan *pChan)
{
t_pmr_sps *pmr_sps, *tmp_sps;
- i16 i;
-
- TRACEX(("destroyPmrChannel()\n"));
+ TRACEF(1,("destroyPmrChannel()\n"));
+
free(pChan->pRxDemod);
free(pChan->pRxNoise);
free(pChan->pRxBase);
@@ -1865,20 +2419,16 @@ i16 destroyPmrChannel(t_pmr_chan *pChan)
free(pChan->pTxLsd);
free(pChan->pTxLsdLpf);
if(pChan->pTxComposite)free(pChan->pTxComposite);
- free(pChan->pTxCode);
free(pChan->pTxOut);
+ if(pChan->prxMeasure)free(pChan->prxMeasure);
if(pChan->pSigGen0)free(pChan->pSigGen0);
if(pChan->pSigGen1)free(pChan->pSigGen1);
+
#if XPMR_DEBUG0 == 1
- free(pChan->pTxPttIn);
- free(pChan->pTxPttOut);
- if(pChan->prxDebug)free(pChan->prxDebug);
+ //if(pChan->prxDebug)free(pChan->prxDebug);
if(pChan->ptxDebug)free(pChan->ptxDebug);
- free(pChan->rxCtcss->pDebug0);
- free(pChan->rxCtcss->pDebug1);
-
free(pChan->prxDebug0);
free(pChan->prxDebug1);
free(pChan->prxDebug2);
@@ -1889,18 +2439,28 @@ i16 destroyPmrChannel(t_pmr_chan *pChan)
free(pChan->ptxDebug2);
free(pChan->ptxDebug3);
+ free(pChan->rxCtcss->pDebug0);
+ free(pChan->rxCtcss->pDebug1);
+
+ i16 i;
for(i=0;i<CTCSS_NUM_CODES;i++)
{
free(pChan->rxCtcss->tdet[i].pDebug0);
free(pChan->rxCtcss->tdet[i].pDebug1);
free(pChan->rxCtcss->tdet[i].pDebug2);
+ free(pChan->rxCtcss->tdet[i].pDebug3);
}
#endif
+ pChan->dd.option=8;
+ dedrift(pChan);
+
free(pChan->pRxCtcss);
pmr_sps=pChan->spsRx;
-
+
+ if(pChan->sdbg)free(pChan->sdbg);
+
while(pmr_sps)
{
tmp_sps = pmr_sps;
@@ -1914,16 +2474,19 @@ i16 destroyPmrChannel(t_pmr_chan *pChan)
}
/*
*/
-t_pmr_sps *createPmrSps(void)
+t_pmr_sps *createPmrSps(t_pmr_chan *pChan)
{
t_pmr_sps *pSps;
- TRACEX(("createPmrSps()\n"));
+ TRACEF(1,("createPmrSps()\n"));
pSps = (t_pmr_sps *)calloc(sizeof(t_pmr_sps),1);
if(!pSps)printf("Error: createPmrSps()\n");
+ pSps->parentChan=pChan;
+ pSps->index=pChan->spsIndex++;
+
// pSps->x=calloc(pSps->nx,pSps->size_x);
return pSps;
@@ -1932,21 +2495,63 @@ t_pmr_sps *createPmrSps(void)
*/
i16 destroyPmrSps(t_pmr_sps *pSps)
{
- TRACEX(("destroyPmrSps(%i)\n",pSps->index));
+ TRACEJ(1,("destroyPmrSps(%i)\n",pSps->index));
if(pSps->x!=NULL)free(pSps->x);
free(pSps);
return 0;
}
-/*
- PmrRx does the whole buffer
+/*
+ PmrTx - takes data from network and holds it for PmrRx
+*/
+i16 PmrTx(t_pmr_chan *pChan, i16 *input)
+{
+ pChan->frameCountTx++;
+
+ TRACEF(5,("PmrTx() start %i\n",pChan->frameCountTx));
+
+ #if XPMR_PPTP == 99
+ pptp_p2^=1;
+ if(pptp_p2)ioctl(ppdrvdev,PPDRV_IOC_PINSET,LP_PIN02);
+ else ioctl(ppdrvdev,PPDRV_IOC_PINCLEAR,LP_PIN02);
+ #endif
+
+ if(pChan==NULL){
+ printf("PmrTx() pChan == NULL\n");
+ return 1;
+ }
+
+ #if XPMR_DEBUG0 == 1
+ if(pChan->b.rxCapture && pChan->tracetype==5)
+ {
+ memcpy(pChan->pTxInput,input,pChan->nSamplesRx*2);
+ }
+ #endif
+
+ //if(pChan->b.radioactive)pChan->dd.debug=1;
+ //else pChan->dd.debug=0;
+
+ dedrift_write(pChan,input);
+
+ return 0;
+}
+/*
+ PmrRx handles a block of data from the usb audio device
*/
-i16 PmrRx(t_pmr_chan *pChan, i16 *input, i16 *output)
+i16 PmrRx(t_pmr_chan *pChan, i16 *input, i16 *outputrx, i16 *outputtx)
{
- int i,ii;
+ int i,hit;
+ float f=0;
t_pmr_sps *pmr_sps;
- TRACEX(("PmrRx() %i\n",pChan->frameCountRx));
+ TRACEC(5,("PmrRx(%p %p %p %p)\n",pChan, input, outputrx, outputtx));
+
+ #if XPMR_PPTP == 1
+ if(pChan->b.radioactive)
+ {
+ pptp_write(1,pChan->frameCountRx&0x00000001);
+ }
+ #endif
if(pChan==NULL){
printf("PmrRx() pChan == NULL\n");
@@ -1955,10 +2560,23 @@ i16 PmrRx(t_pmr_chan *pChan, i16 *input, i16 *output)
pChan->frameCountRx++;
+ #if XPMR_DEBUG0 == 1
+ if(pChan->b.rxCapture)
+ {
+ //if(pChan->prxDebug)memset((void *)pChan->prxDebug,0,pChan->nSamplesRx*XPMR_DEBUG_CHANS*2);
+ if(pChan->ptxDebug)memset((void *)pChan->ptxDebug,0,pChan->nSamplesRx*XPMR_DEBUG_CHANS*2);
+ if(pChan->sdbg->buffer)
+ {
+ memset((void *)pChan->sdbg->buffer,0,pChan->nSamplesRx*XPMR_DEBUG_CHANS*2);
+ pChan->prxDebug=pChan->sdbg->buffer;
+ }
+ }
+ #endif
+
pmr_sps=pChan->spsRx; // first sps
pmr_sps->source=input;
- if(output!=NULL)pChan->spsRxOut->sink=output; //last sps
+ if(outputrx!=NULL)pChan->spsRxOut->sink=outputrx; //last sps
#if 0
if(pChan->inputBlanking>0)
@@ -1969,30 +2587,38 @@ i16 PmrRx(t_pmr_chan *pChan, i16 *input, i16 *output)
input[i]=0;
}
#endif
-
- // || (pChan->radioDuplex && (pChan->pttIn || pChan->pttOut)))
- if(pChan->rxCpuSaver && !pChan->rxCarrierDetect)
+
+ if( pChan->rxCpuSaver && !pChan->rxCarrierDetect &&
+ pChan->smode==SMODE_NULL &&
+ !pChan->txPttIn && !pChan->txPttOut)
{
- if(pChan->spsRxHpf)pChan->spsRxHpf->enabled=0;
- if(pChan->spsRxDeEmp)pChan->spsRxDeEmp->enabled=0;
+ if(!pChan->b.rxhalted)
+ {
+ if(pChan->spsRxHpf)pChan->spsRxHpf->enabled=0;
+ if(pChan->spsRxDeEmp)pChan->spsRxDeEmp->enabled=0;
+ pChan->b.rxhalted=1;
+ TRACEC(1,("PmrRx() rx sps halted\n"));
+ }
}
- else
+ else if(pChan->b.rxhalted)
{
if(pChan->spsRxHpf)pChan->spsRxHpf->enabled=1;
if(pChan->spsRxDeEmp)pChan->spsRxDeEmp->enabled=1;
+ pChan->b.rxhalted=0;
+ TRACEC(1,("PmrRx() rx sps un-halted\n"));
}
i=0;
while(pmr_sps!=NULL && pmr_sps!=0)
{
- TRACEX(("PmrRx() sps %i\n",i++));
+ TRACEC(5,("PmrRx() sps %i\n",i++));
pmr_sps->sigProc(pmr_sps);
pmr_sps = (t_pmr_sps *)(pmr_sps->nextSps);
//pmr_sps=NULL; // sph maw
}
#define XPMR_VOX_HANGTIME 2000
-
+
if(pChan->rxCdType==CD_XPMR_VOX)
{
if(pChan->spsRxVox->compOut)
@@ -2015,242 +2641,692 @@ i16 PmrRx(t_pmr_chan *pChan, i16 *input, i16 *output)
pChan->rxCarrierDetect=!pChan->spsRx->compOut;
}
- if( !pChan->rxCpuSaver || pChan->rxCarrierDetect
- || pChan->rxCtcss->decode!=-1) ctcss_detect(pChan);
+ // stop and start these engines instead to eliminate falsing
+ if( pChan->b.ctcssRxEnable &&
+ ( (!pChan->b.rxhalted ||
+ pChan->rxCtcss->decode!=CTCSS_NULL || pChan->smode==SMODE_CTCSS) &&
+ (pChan->smode!=SMODE_DCS&&pChan->smode!=SMODE_LSD) )
+ )
+ {
+ ctcss_detect(pChan);
+ }
- #if XPMR_DEBUG0 == 1
- // TRACEX(("Write file.\n"));
- ii=0;
- if(pChan->b.rxCapture)
+ #if 1
+ if(pChan->txPttIn!=pChan->b.pttwas)
{
- for(i=0;i<pChan->nSamplesRx;i++)
- {
- pChan->prxDebug[ii++]=input[i*2*6]; // input data
- pChan->prxDebug[ii++]=output[i]; // output data
- pChan->prxDebug[ii++]=pChan->rxCarrierDetect*M_Q14; // carrier detect
- if(pChan->rxCtcss)
- pChan->prxDebug[ii++]=pChan->rxCtcss->decode*M_Q15/CTCSS_NUM_CODES; // decoded ctcss
- else
- pChan->prxDebug[ii++]=0;
-
- pChan->prxDebug[ii++]=pChan->pRxNoise[i]; // rssi
- pChan->prxDebug[ii++]=pChan->pRxBase[i]; // decimated, low pass filtered
- pChan->prxDebug[ii++]=pChan->pRxHpf[i]; // output to network
- pChan->prxDebug[ii++]=pChan->pRxSpeaker[i];
-
- pChan->prxDebug[ii++]=pChan->pRxLsd[i]; // CTCSS Filtered
- pChan->prxDebug[ii++]=pChan->pRxDcTrack[i]; // DC Restoration
- pChan->prxDebug[ii++]=pChan->pRxLsdLimit[i]; // Amplitude Limited
-
- //pChan->prxDebug[ii++]=pChan->rxCtcss->tdet[pChan->rxCtcss->testIndex+1].pDebug0[i]; // Upper Adjacent CTCSS Code
- pChan->prxDebug[ii++]=pChan->rxCtcss->tdet[pChan->rxCtcss->testIndex].pDebug0[i]; // Primary CTCSS Code
- pChan->prxDebug[ii++]=pChan->rxCtcss->tdet[pChan->rxCtcss->testIndex].pDebug1[i]; // dv/dt of decoder output
- pChan->prxDebug[ii++]=pChan->rxCtcss->tdet[pChan->rxCtcss->testIndex].pDebug2[i];
-
- //pChan->prxDebug[ii++]=pChan->rxCtcss->tdet[pChan->rxCtcss->testIndex-1].pDebug0[i]; // Lower Adjacent CTCSS Code
-
- pChan->prxDebug[ii++]=pChan->prxDebug1[i]; // Measure Output for VOX
- pChan->prxDebug[ii++]=pChan->prxDebug2[i]; // Measure Output for Tuning
- }
+ pChan->b.pttwas=pChan->txPttIn;
+ TRACEC(1,("PmrRx() txPttIn=%i\n",pChan->b.pttwas));
}
#endif
- return 0;
-}
-/*
- PmrTx does the whole buffer
-*/
-i16 PmrTx(t_pmr_chan *pChan, i16 *input, i16 *output)
-{
- int i, hit=0;
- t_pmr_sps *pmr_sps;
-
- pChan->frameCountTx++;
-
- TRACEX(("PmrTx() %i\n",pChan->frameCountTx));
+ #ifdef XPMRX_H
+ xpmrx(pChan,XXO_RXDECODE);
+ #endif
- if(pChan==NULL){
- printf("PmrTx() pChan == NULL\n");
- return 1;
+ if(pChan->smodetimer>0 && !pChan->txPttIn)
+ {
+ pChan->smodetimer-=MS_PER_FRAME;
+
+ if(pChan->smodetimer<=0)
+ {
+ pChan->smodetimer=0;
+ pChan->smodewas=pChan->smode;
+ pChan->smode=SMODE_NULL;
+ pChan->b.smodeturnoff=1;
+ TRACEC(1,("smode timeout. smode was=%i\n",pChan->smodewas));
+ }
}
- if(pChan->b.startSpecialTone)
+ if(pChan->rxCtcss->decode > CTCSS_NULL &&
+ (pChan->smode==SMODE_NULL||pChan->smode==SMODE_CTCSS) )
{
- pChan->b.startSpecialTone=0;
- pChan->spsSigGen1->option=1;
- pChan->spsSigGen1->enabled=1;
- pChan->b.doingSpecialTone=1;
- } else if(pChan->b.stopSpecialTone)
- {
- pChan->b.stopSpecialTone=0;
- pChan->spsSigGen1->option=0;
- pChan->b.doingSpecialTone=0;
- pChan->spsSigGen1->enabled=0;
- } else if(pChan->b.doingSpecialTone)
- {
- pChan->spsSigGen1->sink=output;
- pChan->spsSigGen1->sigProc(pChan->spsSigGen1);
- for(i=0;i<(pChan->nSamplesTx*2*6);i+=2)output[i+1]=output[i];
- return 0;
+ if(pChan->smode!=SMODE_CTCSS)
+ {
+ TRACEC(1,("smode set=%i code=%i\n",pChan->smode,pChan->rxCtcss->decode));
+ pChan->smode=pChan->smodewas=SMODE_CTCSS;
+ }
+ pChan->smodetimer=pChan->smodetime;
}
- // handle transmitter ptt input
+ #ifdef HAVE_XPMRX
+ xpmrx(pChan,XXO_LSDCTL);
+ #endif
+
+ //TRACEX(("PmrRx() tx portion.\n"));
+
+ // handle radio transmitter ptt input
hit=0;
- if( pChan->txPttIn && pChan->txState==0)
+ if( !(pChan->smode==SMODE_DCS||pChan->smode==SMODE_LSD) )
+ {
+
+ if( pChan->txPttIn && pChan->txState==CHAN_TXSTATE_IDLE )
{
- pChan->txState = 2;
+ TRACEC(1,("txPttIn==1 from CHAN_TXSTATE_IDLE && !SMODE_LSD. codeindex=%i %i \n",pChan->rxCtcss->decode, pChan->rxCtcssMap[pChan->rxCtcss->decode] ));
+ pChan->dd.b.doitnow=1;
+
+ if(pChan->smode==SMODE_CTCSS && !pChan->b.txCtcssInhibit)
+ {
+ if(pChan->rxCtcss->decode>CTCSS_NULL)
+ {
+ if(pChan->rxCtcssMap[pChan->rxCtcss->decode]!=CTCSS_RXONLY)
+ {
+ f=freq_ctcss[pChan->rxCtcssMap[pChan->rxCtcss->decode]];
+ }
+ }
+ else
+ {
+ f=pChan->txctcssdefault_value;
+ }
+ TRACEC(1,("txPttIn - Start CTCSSGen %f \n",f));
+ if(f)
+ {
+ t_pmr_sps *pSps;
+
+ pChan->spsSigGen0->freq=f*10;
+ pSps=pChan->spsTxLsdLpf;
+ pSps->enabled=1;
+
+ #if 0
+ if(f>203.0)
+ {
+ pSps->ncoef=taps_fir_lpf_250_9_66;
+ pSps->size_coef=2;
+ pSps->coef=(void*)coef_fir_lpf_250_9_66;
+ pSps->nx=taps_fir_lpf_250_9_66;
+ pSps->size_x=2;
+ pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
+ pSps->calcAdjust=gain_fir_lpf_250_9_66;
+ }
+ else
+ {
+ pSps->ncoef=taps_fir_lpf_215_9_88;
+ pSps->size_coef=2;
+ pSps->coef=(void*)coef_fir_lpf_215_9_88;
+ pSps->nx=taps_fir_lpf_215_9_88;
+ pSps->size_x=2;
+ pSps->x=(void*)(calloc(pSps->nx,pSps->size_x));
+ pSps->calcAdjust=gain_fir_lpf_215_9_88;
+ }
+ #endif
+
+ pChan->spsSigGen0->option=1;
+ pChan->spsSigGen0->enabled=1;
+ pChan->spsSigGen0->discounterl=0;
+ }
+ }
+ else if(pChan->smode==SMODE_NULL && pChan->txcodedefaultsmode==SMODE_CTCSS && !pChan->b.txCtcssInhibit)
+ {
+ TRACEC(1,("txPtt Encode txcodedefaultsmode==SMODE_CTCSS %f\n",pChan->txctcssdefault_value));
+ pChan->spsSigGen0->freq=pChan->txctcssdefault_value*10;
+ pChan->spsSigGen0->option=1;
+ pChan->spsSigGen0->enabled=1;
+ pChan->spsSigGen0->discounterl=0;
+ pChan->smode=SMODE_CTCSS;
+ pChan->smodetimer=pChan->smodetime;
+ }
+ else if(pChan->txcodedefaultsmode==SMODE_NULL||pChan->b.txCtcssInhibit)
+ {
+ TRACEC(1,("txPtt Encode txcodedefaultsmode==SMODE_NULL\n"));
+ }
+ else
+ {
+ printf ("ERROR: txPttIn=%i NOT HANDLED PROPERLY.\n",pChan->txPttIn);
+ TRACEC(1,("ERROR: txPttIn=%i NOT HANDLED PROPERLY.\n",pChan->txPttIn));
+ }
+
+ pChan->txState = CHAN_TXSTATE_ACTIVE;
pChan->txPttOut=1;
- pChan->spsSigGen0->freq=pChan->txCtcssFreq*10;
- pChan->spsSigGen0->option=1;
- pChan->spsSigGen0->enabled=1;
+
+ pChan->txsettletimer=pChan->txsettletime;
+
if(pChan->spsTxOutA)pChan->spsTxOutA->enabled=1;
if(pChan->spsTxOutB)pChan->spsTxOutB->enabled=1;
if(pChan->spsTxLsdLpf)pChan->spsTxLsdLpf->enabled=1;
- TRACEX((" TxOn\n"));
+ if(pChan->txfreq)pChan->b.reprog=1;
+ TRACEC(1,("PmrRx() TxOn\n"));
+ }
+ else if(pChan->txPttIn && pChan->txState==CHAN_TXSTATE_ACTIVE)
+ {
+ // pChan->smode=SMODE_CTCSS;
+ pChan->smodetimer=pChan->smodetime;
}
- else if(!pChan->txPttIn && pChan->txState==2)
+ else if(!pChan->txPttIn && pChan->txState==CHAN_TXSTATE_ACTIVE)
{
- if( pChan->txTocType==TOC_NONE || !pChan->txCtcssFreq )
+ TRACEC(1,("txPttIn==0 from CHAN_TXSTATE_ACTIVE\n"));
+ if(pChan->smode==SMODE_CTCSS && !pChan->b.txCtcssInhibit)
{
- hit=1;
- TRACEX((" Tx Off Immediate.\n"));
- }
- else if(pChan->txCtcssFreq && pChan->txTocType==TOC_NOTONE)
+ if( pChan->txTocType==TOC_NONE || !pChan->b.ctcssTxEnable )
+ {
+ TRACEC(1,("Tx Off Immediate.\n"));
+ pChan->spsSigGen0->option=3;
+ pChan->txBufferClear=3;
+ pChan->txState=CHAN_TXSTATE_FINISHING;
+ }
+ else if(pChan->txTocType==TOC_NOTONE)
+ {
+ pChan->txState=CHAN_TXSTATE_TOC;
+ pChan->txHangTime=TOC_NOTONE_TIME/MS_PER_FRAME;
+ pChan->spsSigGen0->option=3;
+ TRACEC(1,("Tx Turn Off No Tone Start.\n"));
+ }
+ else
+ {
+ pChan->txState=CHAN_TXSTATE_TOC;
+ pChan->txHangTime=0;
+ pChan->spsSigGen0->option=2;
+ TRACEC(1,("Tx Turn Off Phase Shift Start.\n"));
+ }
+ }
+ else
{
- pChan->txState=3;
- pChan->txHangTime=TOC_NOTONE_TIME/MS_PER_FRAME;
- pChan->spsSigGen0->option=3;
- TRACEX((" Tx Turn Off No Tone Start.\n"));
+ pChan->txBufferClear=3;
+ pChan->txState=CHAN_TXSTATE_FINISHING;
+ TRACEC(1,("Tx Off No SMODE to Finish.\n"));
}
- else
+ }
+ else if(pChan->txState==CHAN_TXSTATE_TOC)
+ {
+ if( pChan->txPttIn && pChan->smode==SMODE_CTCSS )
{
- pChan->txState=3;
- pChan->txHangTime=0;
- pChan->spsSigGen0->option=2;
- TRACEX((" Tx Turn Off Phase Shift Start.\n"));
+ TRACEC(1,("Tx Key During HangTime\n"));
+ pChan->txState = CHAN_TXSTATE_ACTIVE;
+ pChan->spsSigGen0->option=1;
+ pChan->spsSigGen0->enabled=1;
+ pChan->spsSigGen0->discounterl=0;
+ hit=0;
}
- }
- else if(pChan->txState==3)
- {
- if(pChan->txHangTime)
+ else if(pChan->txHangTime)
{
- if(--pChan->txHangTime==0)hit=1;
-
+ if(--pChan->txHangTime==0)pChan->txState=CHAN_TXSTATE_FINISHING;
}
else if(pChan->txHangTime<=0 && pChan->spsSigGen0->state==0)
- {
- hit=1;
- TRACEX((" Tx Off TOC.\n"));
- }
- if(pChan->txPttIn)
{
- TRACEX((" Tx Key During HangTime\n"));
- if((pChan->txTocType==TOC_PHASE)||(pChan->txTocType==TOC_NONE))
- {
- pChan->txState = 2;
- hit=0;
- }
+ pChan->txBufferClear=3;
+ pChan->txState=CHAN_TXSTATE_FINISHING;
+ TRACEC(1,("Tx Off TOC.\n"));
}
}
-
- if( pChan->txCpuSaver && !hit && !pChan->txPttIn && !pChan->txPttOut && pChan->txState==0 ) return (1);
+ else if(pChan->txState==CHAN_TXSTATE_FINISHING)
+ {
+ if(--pChan->txBufferClear<=0)
+ pChan->txState=CHAN_TXSTATE_COMPLETE;
+ }
+ else if(pChan->txState==CHAN_TXSTATE_COMPLETE)
+ {
+ hit=1;
+ }
+ } // end of if SMODE==LSD
if(hit)
{
pChan->txPttOut=0;
- pChan->txState=0;
+ pChan->spsSigGen0->option=3;
+ pChan->txState=CHAN_TXSTATE_IDLE;
if(pChan->spsTxLsdLpf)pChan->spsTxLsdLpf->option=3;
if(pChan->spsTxOutA)pChan->spsTxOutA->option=3;
if(pChan->spsTxOutB)pChan->spsTxOutB->option=3;
- TRACEX((" Tx Off hit.\n"));
+ if(pChan->rxfreq||pChan->txfreq)pChan->b.reprog=1;
+ TRACEC(1,("Tx Off hit.\n"));
+ }
+
+ if(pChan->b.reprog)
+ {
+ pChan->b.reprog=0;
+ progdtx(pChan);
}
- if(pChan->spsSigGen0)
+ if(pChan->txsettletimer && pChan->txPttHid )
{
- pChan->spsSigGen0->sigProc(pChan->spsSigGen0);
- pmr_sps=pChan->spsSigGen0->nextSps;
- i=0;
- while(pmr_sps!=NULL && pmr_sps!=0)
+ pChan->txsettletimer-=MS_PER_FRAME;
+ if(pChan->txsettletimer<0)pChan->txsettletimer=0;
+ }
+
+ // enable this after we know everything else is working
+ if( pChan->txCpuSaver &&
+ !pChan->txPttIn && !pChan->txPttOut &&
+ pChan->txState==CHAN_TXSTATE_IDLE &&
+ !pChan->dd.b.doitnow
+ )
+ {
+ if(!pChan->b.txhalted)
{
- TRACEX((" PmrTx() subaudible sps %i\n",i++));
- //printf(" CTCSS ENCODE %i %i\n",pChan->spsSigGen0->freq,pChan->spsSigGen0->outputGain);
- pmr_sps->sigProc(pmr_sps);
- pmr_sps = (t_pmr_sps *)(pmr_sps->nextSps);
+ pChan->b.txhalted=1;
+ TRACEC(1,("PmrRx() tx sps halted\n"));
}
}
+ else if(pChan->b.txhalted)
+ {
+ pChan->dd.b.doitnow=1;
+ pChan->b.txhalted=0;
+ TRACEC(1,("PmrRx() tx sps un-halted\n"));
+ }
+
+ if(pChan->b.txhalted)return(1);
+
+ if(pChan->b.startSpecialTone)
+ {
+ pChan->b.startSpecialTone=0;
+ pChan->spsSigGen1->option=1;
+ pChan->spsSigGen1->enabled=1;
+ pChan->b.doingSpecialTone=1;
+ }
+ else if(pChan->b.stopSpecialTone)
+ {
+ pChan->b.stopSpecialTone=0;
+ pChan->spsSigGen1->option=0;
+ pChan->b.doingSpecialTone=0;
+ pChan->spsSigGen1->enabled=0;
+ }
+ else if(pChan->b.doingSpecialTone)
+ {
+ pChan->spsSigGen1->sink=outputtx;
+ pChan->spsSigGen1->sigProc(pChan->spsSigGen1);
+ for(i=0;i<(pChan->nSamplesTx*2*6);i+=2)outputtx[i+1]=outputtx[i];
+ return 0;
+ }
+
+ if(pChan->spsSigGen0 && pChan->spsSigGen0->enabled )
+ {
+ pChan->spsSigGen0->sigProc(pChan->spsSigGen0);
+ }
if(pChan->spsSigGen1 && pChan->spsSigGen1->enabled)
{
pChan->spsSigGen1->sigProc(pChan->spsSigGen1);
}
+ #ifdef XPMRX_H
+ pChan->spsLsdGen->sigProc(pChan->spsLsdGen); // maw sph ???
+ #endif
+
+ // Do Low Speed Data Low Pass Filter
+ pChan->spsTxLsdLpf->sigProc(pChan->spsTxLsdLpf);
+
// Do Voice
pmr_sps=pChan->spsTx;
- if(!pChan->spsSigGen1->enabled)pmr_sps->source=input;
+
+ // get tx data from de-drift process
+ pChan->dd.option=0;
+ pChan->dd.ptr=pChan->pTxBase;
+ dedrift(pChan);
+
+ // tx process
+ if(!pChan->spsSigGen1->enabled)
+ {
+ pmr_sps->source=pChan->pTxBase;
+ }
else input=pmr_sps->source;
- if(output!=NULL)
+ if(outputtx!=NULL)
{
- if(pChan->spsTxOutA)pChan->spsTxOutA->sink=output;
- if(pChan->spsTxOutB)pChan->spsTxOutB->sink=output;
+ if(pChan->spsTxOutA)pChan->spsTxOutA->sink=outputtx;
+ if(pChan->spsTxOutB)pChan->spsTxOutB->sink=outputtx;
}
i=0;
while(pmr_sps!=NULL && pmr_sps!=0)
{
- TRACEX((" PmrTx() sps %i\n",i++));
+ //TRACEF(1,("PmrTx() sps %i\n",i++));
pmr_sps->sigProc(pmr_sps);
pmr_sps = (t_pmr_sps *)(pmr_sps->nextSps);
}
-
+ //TRACEF(1,("PmrTx() - outputs \n"));
if(pChan->txMixA==TX_OUT_OFF || !pChan->txPttOut){
- for(i=0;i<pChan->nSamplesTx*2*6;i+=2)output[i]=0;
+ for(i=0;i<pChan->nSamplesTx*2*6;i+=2)outputtx[i]=0;
}
if(pChan->txMixB==TX_OUT_OFF || !pChan->txPttOut ){
- for(i=0;i<pChan->nSamplesTx*2*6;i+=2)output[i+1]=0;
+ for(i=0;i<pChan->nSamplesTx*2*6;i+=2)outputtx[i+1]=0;
}
- #if XPMR_DEBUG0 == 1
- if(pChan->b.txCapture)
+ #if XPMR_PPTP == 1
+ if( pChan->b.radioactive && pChan->b.pptp_p1!=pChan->txPttOut)
{
- i16 ii=0;
- for(i=0;i<pChan->nSamplesTx;i++)
+ pChan->b.pptp_p1=pChan->txPttOut;
+ pptp_write(0,pChan->b.pptp_p1);
+ }
+ #endif
+
+ #if XPMR_DEBUG0 == 1
+ // TRACEF(1,("PmrRx() - debug outputs \n"));
+ if(pChan->b.rxCapture){
+ for(i=0;i<pChan->nSamplesRx;i++)
{
- pChan->ptxDebug[ii++]=input[i];
- pChan->ptxDebug[ii++]=output[i*2*6];
- pChan->ptxDebug[ii++]=output[(i*2*6)+1];
- pChan->ptxDebug[ii++]=pChan->txPttIn*8192;
-
- pChan->ptxDebug[ii++]=pChan->txPttOut*8192;
- if(pChan->txHpfEnable)pChan->ptxDebug[ii++]=pChan->pTxHpf[i];
- else pChan->ptxDebug[ii++]=0;
- if(pChan->txPreEmpEnable)pChan->ptxDebug[ii++]=pChan->pTxPreEmp[i];
- else pChan->ptxDebug[ii++]=0;
- if(pChan->txLimiterEnable)pChan->ptxDebug[ii++]=pChan->pTxLimiter[i];
- else pChan->ptxDebug[ii++]=0;
-
- pChan->ptxDebug[ii++]=pChan->pTxLsd[i];
- pChan->ptxDebug[ii++]=pChan->pTxLsdLpf[i];
- pChan->ptxDebug[ii++]=pChan->pTxComposite[i];
- pChan->ptxDebug[ii++]=pChan->pSigGen1[i];
-
- #if 1
- pChan->ptxDebug[ii++]=pChan->ptxDebug0[i];
- pChan->ptxDebug[ii++]=pChan->ptxDebug1[i];
- pChan->ptxDebug[ii++]=pChan->ptxDebug2[i];
- pChan->ptxDebug[ii++]=pChan->ptxDebug3[i];
- #else
- pChan->ptxDebug[ii++]=0;
- pChan->ptxDebug[ii++]=0;
- pChan->ptxDebug[ii++]=0;
- pChan->ptxDebug[ii++]=0;
- #endif
+ pChan->pRxDemod[i]=input[i*2*6];
+ pChan->pTstTxOut[i]=outputtx[i*2*6+0]; // txa
+ //pChan->pTstTxOut[i]=outputtx[i*2*6+1]; // txb
+ TSCOPE((RX_NOISE_TRIG, pChan->sdbg, i, (pChan->rxCarrierDetect*XPMR_TRACE_AMP)-XPMR_TRACE_AMP/2));
+ TSCOPE((RX_CTCSS_DECODE, pChan->sdbg, i, pChan->rxCtcss->decode*(M_Q14/CTCSS_NUM_CODES)));
+ TSCOPE((RX_SMODE, pChan->sdbg, i, pChan->smode*(XPMR_TRACE_AMP/4)));
+ TSCOPE((TX_PTT_IN, pChan->sdbg, i, (pChan->txPttIn*XPMR_TRACE_AMP)-XPMR_TRACE_AMP/2));
+ TSCOPE((TX_PTT_OUT, pChan->sdbg, i, (pChan->txPttOut*XPMR_TRACE_AMP)-XPMR_TRACE_AMP/2));
+ TSCOPE((TX_DEDRIFT_LEAD, pChan->sdbg, i, pChan->dd.lead*8));
+ TSCOPE((TX_DEDRIFT_ERR, pChan->sdbg, i, pChan->dd.err*16));
+ TSCOPE((TX_DEDRIFT_FACTOR, pChan->sdbg, i, pChan->dd.factor*16));
+ TSCOPE((TX_DEDRIFT_DRIFT, pChan->sdbg, i, pChan->dd.drift*16));
}
- }
+ }
#endif
+ strace2(pChan->sdbg);
+ TRACEC(5,("PmrRx() return cd=%i smode=%i txPttIn=%i txPttOut=%i \n",pChan->rxCarrierDetect,pChan->smode,pChan->txPttIn,pChan->txPttOut));
return 0;
}
+/*
+ parallel binary programming of an RF Transceiver*/
+
+void ppbinout (u8 chan)
+{
+#if(DTX_PROG == 1)
+ i32 i;
+
+ if (ppdrvdev == 0)
+ ppdrvdev = open("/dev/ppdrv_device", 0);
+
+ if (ppdrvdev < 0)
+ {
+ ast_log(LOG_ERROR, "open /dev/ppdrv_ppdrvdev returned %i\n",ppdrvdev);
+ return;
+ }
+
+ i=0;
+ if(chan&0x01)i|=BIN_PROG_0;
+ if(chan&0x02)i|=BIN_PROG_1;
+ if(chan&0x04)i|=BIN_PROG_2;
+ if(chan&0x08)i|=BIN_PROG_3;
+
+ ioctl(ppdrvdev, PPDRV_IOC_PINMODE_OUT, BIN_PROG_3|BIN_PROG_2|BIN_PROG_1|BIN_PROG_0);
+ //ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, BIN_PROG_3|BIN_PROG_2|BIN_PROG_1|BIN_PROG_0);
+ //ioctl(ppdrvdev, PPDRV_IOC_PINSET, i );
+ ioctl(ppdrvdev, PPDRV_IOC_PINSET, BIN_PROG_3|BIN_PROG_2|BIN_PROG_1|BIN_PROG_0);
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, i );
+
+ // ioctl(ppdrvdev, PPDRV_IOC_PINSET, BIN_PROG_3|BIN_PROG_2|BIN_PROG_1|BIN_PROG_0 );
+ ast_log(LOG_NOTICE, "mask=%i 0x%x\n",i,i);
+#endif
+}
+/*
+ SPI Programming of an RF Transceiver
+ need to add permissions check and mutex
+*/
+/*
+ need to add permissions check and mutex
+*/
+void ppspiout (u32 spidata)
+{
+#if(DTX_PROG == 1)
+ static char firstrun=0;
+ i32 i,ii;
+ u32 bitselect;
+
+ if (ppdrvdev < 0)
+ {
+ ast_log(LOG_ERROR, "no parallel port permission ppdrvdev %i\n",ppdrvdev);
+ exit(0);
+ }
+
+ ioctl(ppdrvdev, PPDRV_IOC_PINMODE_OUT, DTX_CLK | DTX_DATA | DTX_ENABLE | DTX_TXPWR | DTX_TX );
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, DTX_CLK | DTX_DATA | DTX_ENABLE | DTX_TXPWR | DTX_TX );
+
+ if(firstrun==0)
+ {
+ firstrun=1;
+ for(ii=0;ii<PP_BIT_TIME*200;ii++);
+ }
+ else
+ {
+ for(ii=0;ii<PP_BIT_TIME*4;ii++);
+ }
+
+ bitselect=0x00080000;
+
+ for(i=0;i<(PP_REG_LEN-12);i++)
+ {
+ if((bitselect&spidata))
+ ioctl(ppdrvdev, PPDRV_IOC_PINSET, DTX_DATA );
+ else
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, DTX_DATA );
+
+ for(ii=0;ii<PP_BIT_TIME;ii++);
+
+ ioctl(ppdrvdev, PPDRV_IOC_PINSET, DTX_CLK );
+ for(ii=0;ii<PP_BIT_TIME;ii++);
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, DTX_CLK );
+ for(ii=0;ii<PP_BIT_TIME;ii++);
+
+ bitselect=(bitselect>>1);
+ }
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, DTX_CLK | DTX_DATA );
+ ioctl(ppdrvdev, PPDRV_IOC_PINSET, DTX_ENABLE );
+ for(ii=0;ii<PP_BIT_TIME;ii++);
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, DTX_ENABLE );
+#endif
+}
+/*
+ mutex needed
+ now assumes calling thread secures permissions
+ could set up a separate thread to program the radio? yuck!
+
+*/
+void progdtx(t_pmr_chan *pChan)
+{
+#if(DTX_PROG == 1)
+ //static u32 progcount=0;
+
+ u32 reffreq;
+ u32 stepfreq;
+ u32 rxiffreq;
+ u32 synthfreq;
+ u32 shiftreg;
+ u32 tmp;
+
+ TRACEC(1,("\nprogdtx() %i %i %i\n",pChan->rxfreq,pChan->txfreq,0));
+
+ if (ppdrvdev == 0)
+ ppdrvdev = open("/dev/ppdrv_device", 0);
+
+ if (ppdrvdev < 0)
+ {
+ ast_log(LOG_ERROR, "open /dev/ppdrv_ppdrvdev returned %i\n",ppdrvdev);
+ exit(0);
+ }
+
+ if(pChan->rxfreq>200000000)
+ {
+ reffreq=16012500;
+ stepfreq=12500;
+ rxiffreq=21400000;
+ }
+ else
+ {
+ reffreq=16000000;
+ stepfreq=5000;
+ rxiffreq=10700000;
+ }
+
+ shiftreg=(reffreq/stepfreq)<<1;
+ shiftreg=shiftreg|0x00000001;
+
+ ppspiout(shiftreg);
+
+ if(pChan->txPttOut)
+ synthfreq=pChan->txfreq;
+ else
+ synthfreq=pChan->rxfreq-rxiffreq;
+
+ shiftreg=(synthfreq/stepfreq)<<1;
+ tmp=(shiftreg&0xFFFFFF80)<<1;
+ shiftreg=tmp+(shiftreg&0x0000007F);
+
+ ppspiout(shiftreg);
+
+ ioctl(ppdrvdev, PPDRV_IOC_PINMODE_OUT, DTX_CLK | DTX_DATA | DTX_ENABLE | DTX_TXPWR | DTX_TX );
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, DTX_CLK | DTX_DATA | DTX_ENABLE );
+
+ if(pChan->txPttOut)
+ {
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, DTX_TXPWR );
+ ioctl(ppdrvdev, PPDRV_IOC_PINSET, DTX_TX );
+ if(pChan->txpower && 0) ioctl(ppdrvdev, PPDRV_IOC_PINSET, DTX_TXPWR );
+ }
+ else
+ {
+ ioctl(ppdrvdev, PPDRV_IOC_PINCLEAR, DTX_TX | DTX_TXPWR );
+ }
+#endif
+}
+
+/* dedrift
+ reconciles clock differences between the usb adapter and
+ asterisk's frame rate clock
+ take out all accumulated drift error on these events:
+ before transmitter on
+ when ptt release from mobile units detected
+*/
+void dedrift(t_pmr_chan *pChan)
+{
+ TRACEC(5,("dedrift()\n"));
+
+ if(pChan->dd.option==9)
+ {
+ TRACEF(1,("dedrift(9)\n"));
+ pChan->dd.framesize=DDB_FRAME_SIZE;
+ pChan->dd.frames=DDB_FRAMES_IN_BUFF;
+ pChan->dd.buffersize = pChan->dd.frames * pChan->dd.framesize;
+ pChan->dd.buff=calloc(DDB_FRAME_SIZE*DDB_FRAMES_IN_BUFF,2);
+ pChan->dd.modulus=DDB_ERR_MODULUS;
+ pChan->dd.inputindex=0;
+ pChan->dd.outputindex=0;
+ pChan->dd.skew = pChan->dd.lead=0;
+ pChan->dd.z1=0;
+ pChan->dd.debug=0;
+ pChan->dd.debugcnt=0;
+ pChan->dd.lock=pChan->dd.b.txlock=pChan->dd.b.rxlock=0;
+ pChan->dd.initcnt=2;
+ pChan->dd.timer=10000/20;
+ pChan->dd.drift=0;
+ pChan->dd.factor=pChan->dd.x1 = pChan->dd.x0 = pChan->dd.y1 = pChan->dd.y0 = 0;
+ pChan->dd.txframecnt=pChan->dd.rxframecnt=0;
+ // clear the buffer too!
+ return;
+ }
+ else if(pChan->dd.option==8)
+ {
+ free(pChan->dd.buff);
+ pChan->dd.lock=0;
+ pChan->dd.b.txlock=pChan->dd.b.rxlock=0;
+ return;
+ }
+ else if(pChan->dd.initcnt==0)
+ {
+ void *vptr;
+ i16 inputindex;
+ i16 indextweak;
+ i32 accum;
+
+ inputindex = pChan->dd.inputindex;
+ pChan->dd.skew = pChan->dd.txframecnt-pChan->dd.rxframecnt;
+ pChan->dd.rxframecnt++;
+
+ // pull data from buffer
+ if( (pChan->dd.outputindex + pChan->dd.framesize) > pChan->dd.buffersize )
+ {
+ i16 dofirst,donext;
+
+ dofirst = pChan->dd.buffersize - pChan->dd.outputindex;
+ donext = pChan->dd.framesize - dofirst;
+ vptr = (void*)(pChan->dd.ptr);
+ memcpy(vptr,(void*)(pChan->dd.buff + pChan->dd.outputindex),dofirst*2);
+ vptr=(void*)(pChan->dd.ptr + dofirst);
+ memcpy(vptr,(void*)(pChan->dd.buff),donext*2);
+ }
+ else
+ {
+ memcpy(pChan->dd.ptr,(void*)(pChan->dd.buff + pChan->dd.outputindex),pChan->dd.framesize*2);
+ }
+
+ // compute clock error and correction factor
+ if(pChan->dd.outputindex > inputindex)
+ {
+ pChan->dd.lead = (inputindex + pChan->dd.buffersize) - pChan->dd.outputindex;
+ }
+ else
+ {
+ pChan->dd.lead = inputindex - pChan->dd.outputindex;
+ }
+ pChan->dd.err = pChan->dd.lead - (pChan->dd.buffersize/2);
+
+ // WinFilter, IIR Fs=50, Fc=0.1
+ const i32 a0 = 26231;
+ const i32 a1 = 26231;
+ const i32 b0 = 32768;
+ const i32 b1 = -32358;
+ const i32 dg = 128;
+ pChan->dd.x1 = pChan->dd.x0;
+ pChan->dd.y1 = pChan->dd.y0;
+ pChan->dd.x0 = pChan->dd.err;
+ pChan->dd.y0 = a0 * pChan->dd.x0;
+ pChan->dd.y0 += (a1 * pChan->dd.x1 - (b1 * pChan->dd.y1));
+ pChan->dd.y0 /= b0;
+ accum = pChan->dd.y0/dg;
+
+ pChan->dd.factor=accum;
+ indextweak=0;
+
+ #if 1
+ // event sync'd correction
+ if(pChan->dd.b.doitnow)
+ {
+ pChan->dd.b.doitnow=0;
+ indextweak=pChan->dd.factor;
+ pChan->dd.factor = pChan->dd.x1 = pChan->dd.x0 = pChan->dd.y1 = pChan->dd.y0 = 0;
+ pChan->dd.timer=20000/MS_PER_FRAME;
+ }
+ // coarse lead adjustment if really far out of range
+ else if( pChan->dd.lead >= pChan->dd.framesize*(DDB_FRAMES_IN_BUFF-2) )
+ {
+ pChan->dd.factor = pChan->dd.x1 = pChan->dd.x0 = pChan->dd.y1 = pChan->dd.y0 = 0;
+ indextweak += (pChan->dd.framesize*5/4);
+ }
+ else if(pChan->dd.lead <= pChan->dd.framesize*2 )
+ {
+ pChan->dd.factor = pChan->dd.x1 = pChan->dd.x0 = pChan->dd.y1 = pChan->dd.y0 = 0;
+ indextweak -= (pChan->dd.framesize*5/4);
+ }
+ #endif
+
+ #if 1
+ if(pChan->dd.timer>0)pChan->dd.timer--;
+ if(pChan->dd.timer==0 && abs(pChan->dd.factor)>=16)
+ {
+ indextweak=pChan->dd.factor;
+ pChan->dd.factor = pChan->dd.x1 = pChan->dd.x0 = pChan->dd.y1 = pChan->dd.y0 = 0;
+ pChan->dd.timer=20000/MS_PER_FRAME;
+ }
+ #endif
+
+ #if XPMR_DEBUG0 == 1
+ if(indextweak!=0)TRACEF(4,("%08i indextweak %+4i %+4i %+5i %5i %5i %5i %+4i\n",pChan->dd.rxframecnt, indextweak, pChan->dd.err, accum, inputindex, pChan->dd.outputindex, pChan->dd.lead, pChan->dd.skew));
+ #endif
+
+ // set the output index based on lead and clock offset
+ pChan->dd.outputindex = (pChan->dd.outputindex + pChan->dd.framesize + indextweak)%pChan->dd.buffersize;
+ }
+}
+/*
+*/
+void dedrift_write(t_pmr_chan *pChan, i16 *src )
+{
+ void *vptr;
+
+ TRACEF(5,("dedrift_write()\n"));
+ vptr = pChan->dd.buff + pChan->dd.inputindex;
+ memcpy(vptr, src, pChan->dd.framesize*2);
+ pChan->dd.inputindex = (pChan->dd.inputindex + pChan->dd.framesize) % pChan->dd.buffersize;
+ pChan->dd.txframecnt++;
+ if(pChan->dd.initcnt!=0)pChan->dd.initcnt--;
+ pChan->dd.accum+=pChan->dd.framesize;
+}
+
/* end of file */
diff --git a/channels/xpmr/xpmr.h b/channels/xpmr/xpmr.h
index b39ce23d6..49f5148fa 100755
--- a/channels/xpmr/xpmr.h
+++ b/channels/xpmr/xpmr.h
@@ -5,15 +5,25 @@
*
* 20070808 1235 Steven Henke, W9SH, sph@xelatec.com
*
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * This version may be optionally licenced under the GNU LGPL licence.
+ *
+ * A license has been granted to Digium (via disclaimer) for the use of
+ * this code.
*
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
*/
/*! \file
@@ -23,25 +33,73 @@
* \author Steven Henke, W9SH <sph@xelatec.com> Xelatec, LLC
*/
-#ifndef XPMR_H
-#define XPMR_H 1
+#ifndef XPMR_H
+#define XPMR_H 1
+
+#define XPMR_DEV 0 // when running in test mode
+
+#define XPMR_TRACE_LEVEL 0
+
+#ifdef RADIO_RTX
+#define DTX_PROG 1 // rf transceiver module
+#define XPMR_PPTP 0 // parallel port test probe
+#else
+#define DTX_PROG 0
+#define XPMR_PPTP 0
+#endif
+
+#if (DTX_PROG == 1) || XPMR_PPTP == 1
+#include <parapindriver.h>
+#endif
#ifdef CHAN_USBRADIO
#define XPMR_DEBUG0 1
-#define XPMR_TRACE 0
+#define XPMR_TRACE 1
+#define TRACEO(level,a) { if ( o->tracelevel >= level ) {printf a;} }
#else
#define XPMR_DEBUG0 1
#define XPMR_TRACE 1
+#define TRACEO(level,a)
#endif
+
+#define LSD_DFS 5
+#define LSD_DFD 1
+
+#if(XPMR_DEBUG0 == 1)
+#define XPMR_DEBUG_CHANS 16
+#define TSCOPE(a) {strace a;}
+#else
+#define XPMR_DEBUG_CHANS 0
+#define TSCOPE(a)
+#endif
+
+#define XPMR_TRACE_AMP 8192
+
+// TRACEM(3,TSYS_LSD,("pmr_lsdctl_exec() RX FRAME UNPROCESSED.\n"));
#if(XPMR_TRACE == 1)
#define TRACEX(a) {printf a;}
#define TRACEXL(a) {printf("%s @ %u : ",__FILE__ ,__LINE__); printf a; }
-#define TRACEXT(a) { struct timeval hack; gettimeofday(&hack,NULL); printf("%ld.",hack.tv_sec%100000); printf("%i : ",(int)hack.tv_usec); printf a; }
+#define TRACEXT(a) {struct timeval hack; gettimeofday(&hack,NULL); printf("%ld.",hack.tv_sec%100000); printf("%i : ",(int)hack.tv_usec); printf a; }
+#define TRACEXR(a) {printf a;}
+#define TRACEC(level,a) {if(pChan->tracelevel>=level){printf("%08i ",pChan->frameCountRx);printf a;} }
+#define TRACEF(level,a) {if(pChan->tracelevel>=level){printf a;} }
+#define TRACEJ(level,a) {if(XPMR_TRACE_LEVEL>=level){printf a;} }
+#define TRACES(level,a) {if(mySps->parentChan->tracelevel >= level){printf a;} }
+#define TRACET(level,a) {if(pChan->tracelevel>=level){printf("%08i %02i",pChan->frameCountRx,pChan->rptnum);printf a;} }
+#define TRACEXR(a) {printf a;}
+#define TRACEM(level,sys,a) {if(pChan->tracelevel>=level || (pChan->tracesys[sys])){printf a;} }
#else
#define TRACEX(a)
#define TRACEXL(a)
#define TRACEXT(a)
+#define TRACEC(level,a)
+#define TRACEF(level,a)
+#define TRACEJ(level,a)
+#define TRACES(level,a)
+#define TRACET(level,a)
+#define TRACEXR(a)
+#define TRACEM(level,sys,a)
#endif
#define i8 int8_t
@@ -52,11 +110,18 @@
#define u32 u_int32_t
#define i64 int64_t
#define u64 u_int64_t
-
+
+#define M_Q31 0x80000000 //
+#define M_Q30 0x40000000 //
+#define M_Q29 0x20000000 //
+#define M_Q28 0x10000000 //
+#define M_Q27 0x08000000 //
+#define M_Q26 0x04000000 //
+#define M_Q25 0x02000000 //
#define M_Q24 0x01000000 //
#define M_Q23 0x00800000 //
#define M_Q22 0x00400000 //
-#define M_Q21 0x00200000 //
+#define M_Q21 0x00200000 // undsoweiter
#define M_Q20 0x00100000 // 1048576
#define M_Q19 0x00080000 // 524288
#define M_Q18 0x00040000 // 262144
@@ -86,8 +151,11 @@
#define SAMPLES_PER_BLOCK 160
#define MS_PER_FRAME 20
+#define SAMPLES_PER_MS 8
-#define CTCSS_NUM_CODES 38
+#define CTCSS_NULL -1
+#define CTCSS_RXONLY -2
+#define CTCSS_NUM_CODES 38 // 0 - 37
#define CTCSS_SCOUNT_MUL 100
#define CTCSS_INTEGRATE 3932 // 32767*.120 // 120/1000 // 0.120
#define CTCSS_INPUT_LIMIT 1000
@@ -98,6 +166,61 @@
#define CTCSS_TURN_OFF_SHIFT 240 // degrees
#define TOC_NOTONE_TIME 600 // ms
+#define DDB_FRAME_SIZE 160 // clock de-drift defaults
+#define DDB_FRAMES_IN_BUFF 8
+#define DDB_ERR_MODULUS 10000
+
+#define DCS_TURN_OFF_TIME 180
+
+#define NUM_TXLSD_FRAMEBUFFERS 4
+
+#define CHAN_TXSTATE_IDLE 0
+#define CHAN_TXSTATE_ACTIVE 1
+#define CHAN_TXSTATE_TOC 2
+#define CHAN_TXSTATE_HANGING 3
+#define CHAN_TXSTATE_FINISHING 4
+#define CHAN_TXSTATE_COMPLETE 5
+#define CHAN_TXSTATE_USURPED 9
+
+#define SMODE_NULL 0
+#define SMODE_CARRIER 1
+#define SMODE_CTCSS 2
+#define SMODE_DCS 3
+#define SMODE_LSD 4
+#define SMODE_MPT 5
+#define SMODE_DST 6
+#define SMODE_P25 7
+#define SMODE_MDC 8
+
+
+#define SPS_OPT_START 1
+#define SPS_OPT_STOP 2
+#define SPS_OPT_TURNOFF 3
+#define SPS_OPT_STOPNOW 4
+
+#define SPS_STAT_STOPPED 0
+#define SPS_STAT_STARTING 1
+#define SPS_STAT_RUNNING 2
+#define SPS_STAT_HALTING 3
+
+
+#define PP_BIT_TEST 6
+#define PP_REG_LEN 32
+#define PP_BIT_TIME 100000
+
+#define DTX_CLK LP_PIN02
+#define DTX_DATA LP_PIN03
+#define DTX_ENABLE LP_PIN04
+#define DTX_TX LP_PIN05 // only used on older mods
+#define DTX_TXPWR LP_PIN06 // not used
+#define DTX_TP1 LP_PIN07 // not used
+#define DTX_TP2 LP_PIN08 // not used
+
+#define BIN_PROG_0 LP_PIN06
+#define BIN_PROG_1 LP_PIN07
+#define BIN_PROG_2 LP_PIN08
+#define BIN_PROG_3 LP_PIN09
+
#ifndef CHAN_USBRADIO
enum {RX_AUDIO_NONE,RX_AUDIO_SPEAKER,RX_AUDIO_FLAT};
enum {TX_AUDIO_NONE,TX_AUDIO_FLAT,TX_AUDIO_FILTERED,TX_AUDIO_PROC};
@@ -108,6 +231,130 @@ enum {TX_OUT_OFF,TX_OUT_VOICE,TX_OUT_LSD,TX_OUT_COMPOSITE,TX_OUT_AUX};
enum {TOC_NONE,TOC_PHASE,TOC_NOTONE};
#endif
+enum dbg_pts {
+
+RX_INPUT,
+RX_NOISE_AMP,
+RX_NOISE_TRIG,
+
+RX_CTCSS_LPF,
+RX_CTCSS_CENTER,
+RX_CTCSS_NRZ,
+RX_CTCSS_CLK,
+RX_CTCSS_P0,
+RX_CTCSS_P1,
+RX_CTCSS_ACCUM,
+RX_CTCSS_DVDT,
+RX_CTCSS_DECODE,
+
+RX_DCS_CENTER,
+RX_DCS_DEC,
+RX_DCS_DIN,
+RX_DCS_CLK,
+RX_DCS_DAT,
+
+RX_LSD_LPF,
+RX_LSD_CLK,
+RX_LSD_DAT,
+RX_LSD_DEC,
+
+RX_LSD_CENTER,
+RX_LSD_SYNC,
+RX_LSD_STATE,
+RX_LSD_ERR,
+RX_LSD_INTE,
+
+RX_SMODE,
+
+TX_PTT_IN,
+TX_PTT_OUT,
+
+TX_DEDRIFT_LEAD,
+TX_DEDRIFT_ERR,
+TX_DEDRIFT_FACTOR,
+TX_DEDRIFT_DRIFT,
+TX_DEDRIFT_TWIDDLE,
+
+TX_CTCSS_GEN,
+
+TX_SIGGEN_0,
+
+TX_DCS_CLK,
+TX_DCS_DAT,
+TX_DCS_LPF,
+
+TX_LSD_CLK,
+TX_LSD_DAT,
+TX_LSD_GEN,
+TX_LSD_LPF,
+
+TX_NET_INT,
+TX_VOX_HPF,
+TX_VOX_LIM,
+
+TX_VOX_LPF,
+
+TX_OUT_A,
+TX_OUT_B,
+
+NUM_DEBUG_PTS
+};
+
+typedef struct
+{
+ i16 mode;
+ i16 point[NUM_DEBUG_PTS];
+ i16 trace[16];
+ i16 scale[16];
+ i16 offset[16];
+ i16 buffer[16 * SAMPLES_PER_BLOCK]; // allocate for rx and tx
+ i16 *source[16];
+} t_sdbg;
+
+typedef struct
+{
+ i16 lock;
+ i16 option; // 1 = data in, 0 = data out
+ i16 debug;
+ i16 debugcnt;
+ i32 rxframecnt;
+ i32 txframecnt;
+
+ i32 skew;
+
+ i16 frames;
+ i16 framesize;
+ i16 buffersize;
+
+ i32 timer;
+
+ i32 x0,x1,y0,y1;
+
+ i16 inputindex;
+ i16 outputindex;
+ i16 lead;
+ i16 err;
+ i16 accum;
+
+ i16 *ptr; // source or destination
+ i16 *buff;
+
+ i16 inputcnt;
+ i16 initcnt;
+
+ i32 factor;
+ i32 drift;
+ i32 modulus;
+ i32 z1;
+ struct {
+ unsigned rxlock:1;
+ unsigned txlock:1;
+ unsigned twiddle:1;
+ unsigned doitnow:1;
+ }b;
+}
+t_dedrift;
+
/*
one structure for each ctcss tone to decode
*/
@@ -121,7 +368,7 @@ typedef struct
i16 enabled;
i16 state; // dead, running, error
i16 zIndex; // z bucket index
- i16 z[4]; // maw sph today
+ i16 z[4];
i16 zi;
i16 dvu;
i16 dvd;
@@ -130,78 +377,62 @@ typedef struct
i16 hyst;
i16 decode;
i16 diffpeak;
- i16 debug; // value held from last pass
+ i16 debug;
+
+ #if XPMR_DEBUG0 == 1
+ i16 lasttv0;
+ i16 lasttv1;
+ i16 lasttv2;
+ i16 lasttv3;
+
i16 *pDebug0; // pointer to debug output
i16 *pDebug1; // pointer to debug output
i16 *pDebug2; // pointer to debug output
+ i16 *pDebug3; // pointer to debug output
+ #endif
} t_tdet;
typedef struct
{
i16 enabled; // if 0 none, 0xFFFF all tones, or single tone
- i16 *input;
+ i16 *input; // source data
i16 clamplitude;
i16 center;
i16 decode; // current ctcss decode index
i32 BlankingTimer;
u32 TurnOffTimer;
- t_tdet tdet[CTCSS_NUM_CODES];
i16 gain;
i16 limit;
+ i16 debugIndex;
i16 *pDebug0;
i16 *pDebug1;
i16 *pDebug2;
+ i16 *pDebug3;
i16 testIndex;
i16 multiFreq;
i8 relax;
+ t_tdet tdet[CTCSS_NUM_CODES];
-} t_dec_ctcss;
+ i8 numrxcodes;
+ i16 rxCtcssMap[CTCSS_NUM_CODES];
+ char *rxctcss[CTCSS_NUM_CODES]; // pointers to each tone in string above
+ char *txctcss[CTCSS_NUM_CODES];
-typedef struct
-{
- i16 enabled; // if 0 none, 0xFFFF all tones, or single tone
- i16 clamplitude;
- i16 center;
- i16 decode; // current ctcss decode value
- i32 BlankingTimer;
- u32 TurnOffTimer;
- i16 gain;
- i16 limit;
- i16 *pDebug0;
- i16 *pDebug1;
- i16 rxPolarity;
-} t_dec_dcs;
+ i32 txctcssdefault_index;
+ float txctcssdefault_value;
+
+ struct{
+ unsigned valid:1;
+ }b;
+} t_dec_ctcss;
/*
- Low Speed Data decoding both polarities
+ Low Speed Data
+*/
+/*
+ general purpose pmr signal processing element
*/
-typedef struct
-{
- i16 counter; // counter to next sample
- i16 synced;
- u32 syncCorr[2];
- u32 data[2];
- i16 state; // disabled, enabled,
- i16 decode;
- i16 debug;
-
- i16 polarity;
- u32 frameNum;
-
- u16 area;
- u16 chan;
- u16 home;
- u16 id;
- u16 free;
-
- u16 crc;
- i16 rssi;
-
-} t_decLsd;
-
-
-/* general purpose pmr signal processing element */
struct t_pmr_chan;
@@ -211,6 +442,7 @@ typedef struct t_pmr_sps
i16 enabled; // enabled/disabled
+
struct t_pmr_chan *parentChan;
i16 *source; // source buffer
@@ -220,7 +452,9 @@ typedef struct t_pmr_sps
i16 numChanOut; // allows output direct to interleaved buffer
i16 selChanOut;
- u32 ticks;
+ i32 ticks;
+ i32 timer;
+ i32 count;
void *buff; // this structure's internal buffer
@@ -258,6 +492,29 @@ typedef struct t_pmr_sps
i16 err; // error condition
i16 option; // option / request zero
i16 state; // stopped, start, stopped assumes zero'd
+
+ i16 pending;
+
+ struct {
+ unsigned hit:1;
+ unsigned hitlast:1;
+ unsigned hita:1;
+ unsigned hitb:1;
+ unsigned bithit:1;
+ unsigned now:1;
+ unsigned next:1;
+ unsigned prev:1;
+ unsigned clock:1;
+ unsigned hold:1;
+ unsigned opt1:1;
+ unsigned opt2:1;
+ unsigned polarity:1;
+ unsigned dotting:1;
+ unsigned lastbitpending:1;
+ unsigned outzero:1;
+ unsigned settling:1;
+ unsigned syncing:1;
+ }b;
i16 cleared; // output buffer cleared
@@ -288,14 +545,28 @@ typedef struct t_pmr_sps
} t_pmr_sps;
+
+struct t_dec_dcs;
+struct t_lsd_control;
+struct t_decLsd;;
+struct t_encLsd;
+
/*
pmr channel
*/
typedef struct t_pmr_chan
{
i16 index; // which one
+ i16 devicenum; // belongs to
+
+ char *name;
+
i16 enabled; // enabled/disabled
i16 status; // ok, error, busy, idle, initializing
+
+ i16 tracelevel;
+ i16 tracetype;
+ u32 tracemask;
i16 nSamplesRx; // max frame size
i16 nSamplesTx;
@@ -306,11 +577,23 @@ typedef struct t_pmr_chan
i16 inputGain;
i16 inputOffset;
+ i32 ticks; // time ticks
u32 frameCountRx; // number processed
u32 frameCountTx;
+ i8 txframelock;
+
i32 txHangTime;
+ i32 txHangTimer;
i32 txTurnOff;
+ i16 txBufferClear;
+
+ u32 txfreq;
+ u32 rxfreq;
+ i8 txpower;
+
+ i32 txsettletime; // in samples
+ i32 txsettletimer;
i16 rxDC; // average DC value of input
i16 rxSqSet; // carrier squelch threshold
@@ -319,6 +602,7 @@ typedef struct t_pmr_chan
i16 rxQuality; // signal quality metric
i16 rxCarrierDetect; // carrier detect
i16 rxCdType;
+ i16 rxSqVoxAdj;
i16 rxExtCarrierDetect;
i32 inputBlanking; // Tx pulse eliminator
@@ -340,20 +624,54 @@ typedef struct t_pmr_chan
char radioDuplex;
- struct {
- unsigned pmrNoiseSquelch:1;
- unsigned rxHpf:1;
- unsigned txHpf:1;
- unsigned txLpf:1;
- unsigned rxDeEmphasis:1;
- unsigned txPreEmphasis:1;
- unsigned startSpecialTone:1;
- unsigned stopSpecialTone:1;
- unsigned doingSpecialTone:1;
- unsigned extCarrierDetect:1;
- unsigned txCapture:1;
- unsigned rxCapture:1;
- }b;
+ char *pStr;
+
+ // start channel signaling codes source
+ char *pRxCodeSrc; // source
+ char *pTxCodeSrc; // source
+ char *pTxCodeDefault; // source
+ // end channel signaling codes source
+
+ // start signaling code info derived from source
+ i16 numrxcodes;
+ i16 numtxcodes;
+ char *pRxCodeStr; // copied and cut up
+ char **pRxCode; // pointers to subs
+ char *pTxCodeStr;
+ char **pTxCode;
+
+ char txctcssdefault[16]; // codes from higher level
+
+ char *rxctcssfreqs; // rest are derived from this
+ char *txctcssfreqs;
+
+ char numrxctcssfreqs;
+ char numtxctcssfreqs;
+
+ char *rxctcss[CTCSS_NUM_CODES]; // pointers to each tone in string above
+ char *txctcss[CTCSS_NUM_CODES];
+
+ i16 rxCtcssMap[CTCSS_NUM_CODES];
+
+ i8 txcodedefaultsmode;
+ i16 txctcssdefault_index;
+ float txctcssdefault_value;
+
+ char txctcssfreq[32]; // encode now
+ char rxctcssfreq[32]; // decode now
+ // end most of signaling code info derived from source
+
+ struct t_lsd_control *pLsdCtl;
+
+ i16 rptnum;
+ i16 area;
+ char *ukey;
+ u32 idleinterval;
+ char turnoffs;
+
+ char pplock;
+
+ t_dedrift dd;
i16 dummy;
@@ -379,21 +697,34 @@ typedef struct t_pmr_chan
i16 rxCarrierPoint;
i16 rxCarrierHyst;
-
- i16 rxCtcssMap[CTCSS_NUM_CODES];
i16 txCtcssTocShift;
i16 txCtcssTocTime;
i8 txTocType;
- float txCtcssFreq;
- float rxCtcssFreq;
- float rxInputGain;
-
- i16 rxCtcssIndex;
+ i16 smode; // ctcss, dcs, lsd
+ i16 smodecode;
+ i16 smodewas; // ctcss, dcs, lsd
+ i32 smodetimer; // in ms
+ i32 smodetime; // to set in ms
+
+ t_dec_ctcss *rxCtcss;
+ struct t_dec_dcs *decDcs;
+ struct t_decLsd *decLsd;
+ struct t_encLsd *pLsdEnc;
+
+ i16 clamplitudeDcs;
+ i16 centerDcs;
+ u32 dcsBlankingTimer;
+ i16 dcsDecode; // current dcs decode value
+
+ i16 clamplitudeLsd;
+ i16 centerLsd;
+
i16 txPttIn; // from external request
i16 txPttOut; // to radio hardware
+ i16 txPttHid;
i16 bandwidth; // wide/narrow
i16 txCompand; // type
@@ -410,12 +741,15 @@ typedef struct t_pmr_chan
i16 function;
- i16 txState; // off,settling,on,hangtime,turnoff
+ i16 txState; // off,settling,on,hangtime,turnoff
+
+ i16 spsIndex;
- t_pmr_sps *spsMeasure; // measurement block
+ t_pmr_sps *spsMeasure; // measurement block
t_pmr_sps *spsRx; // 1st signal processing struct
t_pmr_sps *spsRxLsd;
+ t_pmr_sps *spsRxLsdNrz;
t_pmr_sps *spsRxDeEmp;
t_pmr_sps *spsRxHpf;
t_pmr_sps *spsRxVox;
@@ -423,14 +757,14 @@ typedef struct t_pmr_chan
t_pmr_sps *spsRxOut; // Last signal processing struct
t_pmr_sps *spsTx; // 1st signal processing struct
-
- t_pmr_sps *spsTxLsdLpf;
+
t_pmr_sps *spsTxOutA; // Last signal processing struct
-
t_pmr_sps *spsTxOutB; // Last signal processing struct
t_pmr_sps *spsSigGen0; // ctcss
t_pmr_sps *spsSigGen1; // test and other tones
+ t_pmr_sps *spsLsdGen;
+ t_pmr_sps *spsTxLsdLpf;
// tune tweaks
@@ -452,6 +786,58 @@ typedef struct t_pmr_chan
i32 *ptxLimiterAdjust; // from calling application
+ struct {
+ unsigned pmrNoiseSquelch:1;
+ unsigned rxHpf:1;
+ unsigned txHpf:1;
+ unsigned txLpf:1;
+ unsigned rxDeEmphasis:1;
+ unsigned txPreEmphasis:1;
+ unsigned startSpecialTone:1;
+ unsigned stopSpecialTone:1;
+ unsigned doingSpecialTone:1;
+ unsigned extCarrierDetect:1;
+ unsigned txCapture:1;
+ unsigned rxCapture:1;
+ unsigned reprog:1;
+ unsigned radioactive:1;
+ unsigned rxplmon:1;
+ unsigned remoted:1;
+ unsigned loopback:1;
+ unsigned rxpolarity:1;
+ unsigned txpolarity:1;
+ unsigned dcsrxpolarity:1;
+ unsigned dcstxpolarity:1;
+ unsigned lsdrxpolarity:1;
+ unsigned lsdtxpolarity:1;
+ unsigned txsettling:1;
+ unsigned smodeturnoff:1;
+
+ unsigned ctcssRxEnable:1;
+ unsigned ctcssTxEnable:1;
+ unsigned dcsRxEnable:1;
+ unsigned dcsTxEnable:1;
+ unsigned lmrRxEnable:1;
+ unsigned lmrTxEnable:1;
+ unsigned mdcRxEnable:1;
+ unsigned mdcTxEnable:1;
+ unsigned dstRxEnable:1;
+ unsigned dstTxEnable:1;
+ unsigned p25RxEnable:1;
+ unsigned p25TxEnable:1;
+ unsigned ax25Enable:1;
+
+ unsigned txCtcssInhibit:1;
+
+ unsigned rxkeyed:1;
+ unsigned rxhalted:1;
+ unsigned txhalted:1;
+ unsigned pptp_p1:1;
+ unsigned pptp_p2:1;
+ unsigned tuning:1;
+ unsigned pttwas:1;
+ }b;
+
i16 *pRxDemod; // buffers
i16 *pRxBase; // decimated lpf input
i16 *pRxNoise;
@@ -463,7 +849,10 @@ typedef struct t_pmr_chan
i16 *pRxLsdLimit; // LSD Limited
i16 *pRxCtcss; //
i16 *pRxSquelch;
+ i16 *prxVoxMeas;
+ i16 *prxMeasure;
+ i16 *pTxInput; // input data
i16 *pTxBase; // input data
i16 *pTxHpf;
i16 *pTxPreEmp;
@@ -474,11 +863,6 @@ typedef struct t_pmr_chan
i16 *pTxMod; // upsampled, low pass filtered
i16 *pTxOut; //
-
- i16 *pTxPttIn;
- i16 *pTxPttOut;
- i16 *pTxHang;
- i16 *pTxCode;
i16 *pSigGen0;
i16 *pSigGen1;
@@ -488,6 +872,12 @@ typedef struct t_pmr_chan
i16 *pNull;
+ #if XPMR_DEBUG0 == 1
+
+ i16 *pRxLsdCen;
+
+ i16 *pTstTxOut;
+
i16 *prxDebug; // consolidated debug buffer
i16 *ptxDebug; // consolidated debug buffer
@@ -501,23 +891,23 @@ typedef struct t_pmr_chan
i16 *ptxDebug2;
i16 *ptxDebug3;
- t_dec_ctcss *rxCtcss;
-
- i16 clamplitudeDcs;
- i16 centerDcs;
- u32 dcsBlankingTimer;
- i16 dcsDecode; // current dcs decode value
+ #endif
- i16 clamplitudeLsd;
- i16 centerLsd;
- t_decLsd decLsd[2]; // for both polarities
+ i16 numDebugChannels;
+
+ t_sdbg *sdbg;
} t_pmr_chan;
-static i16 TxTestTone(t_pmr_chan *pChan, i16 function);
+/*
+ function prototype declarations
+*/
+void strace(i16 point, t_sdbg *sdbg, i16 index, i16 value);
+void strace2(t_sdbg *sdbg);
+static i16 TxTestTone(t_pmr_chan *pChan, i16 function);
t_pmr_chan *createPmrChannel(t_pmr_chan *tChan, i16 numSamples);
-t_pmr_sps *createPmrSps(void);
+t_pmr_sps *createPmrSps(t_pmr_chan *pChan);
i16 destroyPmrChannel(t_pmr_chan *pChan);
i16 destroyPmrSps(t_pmr_sps *pSps);
i16 pmr_rx_frontend(t_pmr_sps *mySps);
@@ -531,10 +921,28 @@ i16 SoftLimiter(t_pmr_sps *mySps);
i16 SigGen(t_pmr_sps *mySps);
i16 pmrMixer(t_pmr_sps *mySps);
i16 DelayLine(t_pmr_sps *mySps);
-i16 PmrRx(t_pmr_chan *PmrChan, i16 *input, i16 *output);
-i16 PmrTx(t_pmr_chan *PmrChan, i16 *input, i16 *output);
+
+i16 PmrRx(t_pmr_chan *PmrChan, i16 *input, i16 *outputrx, i16 *outputtx );
+i16 PmrTx(t_pmr_chan *PmrChan, i16 *input);
+
+i16 string_parse(char *src, char **dest, char ***ptrs);
+i16 code_string_parse(t_pmr_chan *pChan);
+
i16 CtcssFreqIndex(float freq);
i16 MeasureBlock(t_pmr_sps *mySps);
+
+void dedrift (t_pmr_chan *pChan);
+void dedrift_write (t_pmr_chan *pChan, i16 *src);
+
+void ppspiout (u32 spidata);
+void progdtx (t_pmr_chan *pChan);
+void ppbinout (u8 chan);
+
+#if XPMR_PPTP == 1
+void pptp_init (void);
+void pptp_write (i16 bit, i16 state);
+#endif
+
#endif /* ! XPMR_H */
/* end of file */
diff --git a/channels/xpmr/xpmr_coef.h b/channels/xpmr/xpmr_coef.h
index fda6762da..84254e884 100755
--- a/channels/xpmr/xpmr_coef.h
+++ b/channels/xpmr/xpmr_coef.h
@@ -4,16 +4,28 @@
* All Rights Reserved. Copyright (C)2007, Xelatec, LLC
*
* 20070808 1235 Steven Henke, W9SH, sph@xelatec.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * This version may be optionally licenced under the GNU LGPL licence.
+ *
+ * A license has been granted to Digium (via disclaimer) for the use of
+ * this code.
*
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
+ * Some filter coeficients via 'WinFilter' http://www.winfilter.20m.com.
*
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
*/
/*! \file
@@ -24,30 +36,25 @@
*/
#ifndef XPMR_COEF_H
-#define XMPR_COEF_H 1
+#define XMPR_COEF_H 1
// frequencies in 0.1 Hz
-const u32 dtmf_row[] =
+static const u32 dtmf_row[] =
{
6970, 7700, 8520, 9410
};
-const u32 dtmf_col[] =
+static const u32 dtmf_col[] =
{
12090, 13360, 14770, 16330
};
-const i16 coef_dcs_rx = 1488; // dcs rx data divisor for oversampling 8000/134.4
-const i16 coef_dcs_tx = 5952; // dcs tx data divisor
-
-const i16 coef_lsd_div = 672; // low speed data divisor
-const u32 coef_lsd_sync = 0x158; // 000101011000
-const u32 coef_lsd_sync_pattern[] = {0x0000000F, 0x0F0FF000};
#define CTCSS_COEF_INT 120
#define CTCSS_SAMPLE_RATE 8000
#define TDIV(x) ((CTCSS_SAMPLE_RATE*1000/x)+5)/10
-i32 coef_ctcss[4][5]=
+#if 0
+static i32 coef_ctcss[4][5]=
{
// freq, divisor, integrator, filter
{770,TDIV(770),CTCSS_COEF_INT,0,0},
@@ -55,9 +62,9 @@ i32 coef_ctcss[4][5]=
{1035,TDIV(1035),CTCSS_COEF_INT,0,0},
{0,0,0,0}
};
+#endif
-
-i16 coef_ctcss_div[]=
+static i16 coef_ctcss_div[]=
{
2985, // 00 067.0
2782, // 01 071.9
@@ -99,7 +106,7 @@ i16 coef_ctcss_div[]=
799 // 37 250.3
};
-float freq_ctcss[]=
+static float freq_ctcss[]=
{
067.0, // 00
071.9, // 01
@@ -378,7 +385,8 @@ static const int16_t coef_int_lpf_300_1_2[]={
// pre-emphasis differentiator 4000 Hz with 8KS/s
// a0,a1,b0,
static const int16_t taps_int_hpf_4000_1_2 = 2;
-static const int32_t gain_int_hpf_4000_1_2 = 16384;
+//static const int32_t gain_int_hpf_4000_1_2 = 16384; // per calculations
+static const int32_t gain_int_hpf_4000_1_2 = 13404; // hand tweaked for unity gain at 1KHz
static const int16_t coef_int_hpf_4000_1_2[]={
17610,
-17610,
@@ -386,298 +394,6 @@ static const int16_t coef_int_hpf_4000_1_2[]={
};
-/*
- ltr crc table
- from http://www.radioreference.com/forums/showthread.php?t=24126
-*/
-
-static const u8 ltr_table[]=
-{
-0x38, // 00 Area 0111000
-0x1c, // 01 Channel 4 0011100
-0x0e, // 02 Channel 3 0001110
-0x46, // 03 Channel 2 1000110
-0x23, // 04 Channel 1 0100011
-0x51, // 05 Channel 0 1010001
-0x68, // 06 Home 4 1101000
-0x75, // 07 Home 3 1110101
-0x7a, // 08 Home 2 1111010
-0x3d, // 09 Home 1 0111101
-0x1f, // 10 Home 0 0011111
-0x4f, // 11 Group 7 1001111
-0x26, // 12 Group 6 0100110
-0x52, // 13 Group 5 1010010
-0x29, // 14 Group 4 0101001
-0x15, // 15 Group 3 0010101
-0x0d, // 16 Group 2 0001101
-0x45, // 17 Group 1 1000101
-0x62, // 18 Group 0 1100010
-0x31, // 19 Free 4 0110001
-0x19, // 20 Free 3 0011001
-0x0d, // 21 Free 2 0001101
-0x07, // 22 Free 1 0000111
-0x43 // 23 Free 0 1000011
-};
-
-static const i16 bitWeight[]=
-{
-0, // 0
-1, // 1
-1, // 2
-2, // 3
-1, // 4
-2, // 5
-2, // 6
-3, // 7
-1, // 8
-2, // 9
-2, // 10
-3, // 11
-2, // 12
-3, // 13
-3, // 14
-4, // 15
-1, // 16
-2, // 17
-2, // 18
-3, // 19
-2, // 20
-3, // 21
-3, // 22
-4, // 23
-2, // 24
-3, // 25
-3, // 26
-4, // 27
-3, // 28
-4, // 29
-4, // 30
-5, // 31
-1, // 32
-2, // 33
-2, // 34
-3, // 35
-2, // 36
-3, // 37
-3, // 38
-4, // 39
-2, // 40
-3, // 41
-3, // 42
-4, // 43
-3, // 44
-4, // 45
-4, // 46
-5, // 47
-2, // 48
-3, // 49
-3, // 50
-4, // 51
-3, // 52
-4, // 53
-4, // 54
-5, // 55
-3, // 56
-4, // 57
-4, // 58
-5, // 59
-4, // 60
-5, // 61
-5, // 62
-6, // 63
-1, // 64
-2, // 65
-2, // 66
-3, // 67
-2, // 68
-3, // 69
-3, // 70
-4, // 71
-2, // 72
-3, // 73
-3, // 74
-4, // 75
-3, // 76
-4, // 77
-4, // 78
-5, // 79
-2, // 80
-3, // 81
-3, // 82
-4, // 83
-3, // 84
-4, // 85
-4, // 86
-5, // 87
-3, // 88
-4, // 89
-4, // 90
-5, // 91
-4, // 92
-5, // 93
-5, // 94
-6, // 95
-2, // 96
-3, // 97
-3, // 98
-4, // 99
-3, // 100
-4, // 101
-4, // 102
-5, // 103
-3, // 104
-4, // 105
-4, // 106
-5, // 107
-4, // 108
-5, // 109
-5, // 110
-6, // 111
-3, // 112
-4, // 113
-4, // 114
-5, // 115
-4, // 116
-5, // 117
-5, // 118
-6, // 119
-4, // 120
-5, // 121
-5, // 122
-6, // 123
-5, // 124
-6, // 125
-6, // 126
-7, // 127
-1, // 128
-2, // 129
-2, // 130
-3, // 131
-2, // 132
-3, // 133
-3, // 134
-4, // 135
-2, // 136
-3, // 137
-3, // 138
-4, // 139
-3, // 140
-4, // 141
-4, // 142
-5, // 143
-2, // 144
-3, // 145
-3, // 146
-4, // 147
-3, // 148
-4, // 149
-4, // 150
-5, // 151
-3, // 152
-4, // 153
-4, // 154
-5, // 155
-4, // 156
-5, // 157
-5, // 158
-6, // 159
-2, // 160
-3, // 161
-3, // 162
-4, // 163
-3, // 164
-4, // 165
-4, // 166
-5, // 167
-3, // 168
-4, // 169
-4, // 170
-5, // 171
-4, // 172
-5, // 173
-5, // 174
-6, // 175
-3, // 176
-4, // 177
-4, // 178
-5, // 179
-4, // 180
-5, // 181
-5, // 182
-6, // 183
-4, // 184
-5, // 185
-5, // 186
-6, // 187
-5, // 188
-6, // 189
-6, // 190
-7, // 191
-2, // 192
-3, // 193
-3, // 194
-4, // 195
-3, // 196
-4, // 197
-4, // 198
-5, // 199
-3, // 200
-4, // 201
-4, // 202
-5, // 203
-4, // 204
-5, // 205
-5, // 206
-6, // 207
-3, // 208
-4, // 209
-4, // 210
-5, // 211
-4, // 212
-5, // 213
-5, // 214
-6, // 215
-4, // 216
-5, // 217
-5, // 218
-6, // 219
-5, // 220
-6, // 221
-6, // 222
-7, // 223
-3, // 224
-4, // 225
-4, // 226
-5, // 227
-4, // 228
-5, // 229
-5, // 230
-6, // 231
-4, // 232
-5, // 233
-5, // 234
-6, // 235
-5, // 236
-6, // 237
-6, // 238
-7, // 239
-4, // 240
-5, // 241
-5, // 242
-6, // 243
-5, // 244
-6, // 245
-6, // 246
-7, // 247
-5, // 248
-6, // 249
-6, // 250
-7, // 251
-6, // 252
-7, // 253
-7, // 254
-8 // 255
-};
/*