提交 b23a8ae4 authored 作者: Anthony Minessale's avatar Anthony Minessale

update1

git-svn-id: http://svn.openzap.org/svn/openzap/trunk@216 a93c3328-9c30-0410-af19-c9cd2b2d52af
上级 6bf627a3
......@@ -38,8 +38,8 @@ $(SRC)/zap_isdn.o \
$(SRC)/zap_analog.o \
$(SRC)/zap_config.o \
$(SRC)/zap_callerid.o \
$(SRC)/dsp/fsk.o \
$(SRC)/dsp/uart.o \
$(SRC)/fsk.o \
$(SRC)/uart.o \
$(SRC)/g711.o \
$(SRC)/libteletone_detect.o \
$(SRC)/libteletone_generate.o \
......@@ -58,20 +58,23 @@ $(SRC)/isdn/Q931StateTE.o \
$(SRC)/isdn/nationalmes.o \
$(SRC)/isdn/nationalStateNT.o \
$(SRC)/isdn/nationalStateTE.o \
$(SRC)/isdn/Q932mes.o
$(SRC)/isdn/Q932mes.o \
$(SRC)/zap_zt.o \
$(SRC)/zap_wanpipe.o
HEADERS=$(SRC)/isdn/include/Q931.h \
$(SRC)/include/openzap.h
PWD=$(shell pwd)
INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include -I$(PWD)/src/dsp
INCS=-I$(PWD)/$(SRC)//include -I$(PWD)/$(SRC)//isdn/include
CFLAGS=$(ZAP_CFLAGS) $(INCS)
MYLIB=libopenzap.a
LIBPRIA=libpri.a
LIBPRI=./libpri
TMP=-I$(LIBPRI) -I$(SRC)/include -I./src -w
include general.makefile $(ZAP_MODS)
include general.makefile
all: $(MYLIB)
......@@ -106,12 +109,6 @@ priserver: $(MYLIB) $(SRC)/priserver.o $(SRC)/sangoma_pri.o $(LIBPRI)/$(LIBPRIA)
$(SRC)/zap_io.o: $(SRC)/zap_io.c
$(CC) $(MOD_CFLAGS) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@
$(SRC)/zap_wanpipe.o: $(SRC)/zap_wanpipe.c
$(CC) $(CFLAGS) $(ZAP_CFLAGS) $(WP_CFLAGS) -c $< -o $@
$(SRC)/zap_zt.o: $(SRC)/zap_zt.c
$(CC) $(CFLAGS) $(ZAP_CFLAGS) $(ZT_CFLAGS) -c $< -o $@
%.o: %.c
$(CC) $(CC_CFLAGS) $(CFLAGS) -c $< -o $@
......
I have only tested the library with samples at 8kHz. It *should* work with arbitrary sample rates; the "optr" variable in the code samples below is the sampling rate in Hz.
The first thing you need to do is initialize a context structure:
dsp_fsk_attr_t fsk1200_attr; // attributes structure for FSK 1200 baud modem
dsp_fsk_handle_t *fsk1200_handle; // context structure for FSK 1200 baud modem
// initialize:
dsp_fsk_attr_init (&fsk1200_attr); // clear attributes structure
dsp_fsk_attr_set_samplerate (&fsk1200_attr, optr); // set sample rate
dsp_fsk_attr_set_bytehandler (&fsk1200_attr, clid_byte_handler, ch); // bind byte handler
// create context:
fsk1200_handle = dsp_fsk_create (&fsk1200_attr);
// error check:
if (fsk1200_handle == NULL) {
fprintf (stderr, "%s: can't dsp_fsk_create, errno %d (%s)\n", progname, errno, strerror (errno));
exit (EXIT_FAILURE);
}
If you are decoding multiple channels, you will need multiple context structures; one per channel.
The attributes ("dsp_fsk_attr_t") do not have to be persistent, but the handle does.
There's even a "dsp_fsk_destroy()" function call to remove the context structure; I don't believe I've ever used it, my stuff hangs around forever.
Then, you need to feed samples into the software modem:
dsp_fsk_sample (fsk1200_handle, (double) sample / 32767.);
It assumes the samples are between -1 and 1 as a double.
It will outcall to your provided "clid_byte_handler()" function, which needs to have a prototype as follows:
void clid_byte_handler (void *x, int data);
The "x" is a context "void *" that you can associate in the fsk1200_handle (great for multiple channels).
This will dribble bytes out to you at 1200 baud.
From there, you are on your own. Canadian caller ID streams are different format than US caller ID streams IIRC. Both are trivial to figure out, as they have lots of ASCII data. I can supply some more code later on the Canadian one if you need it.
Here's a sample of a Canadian caller ID stream from when you called:
00000000: 55 55 55 55 55 55 55 55-55 55 55 55 55 55 55 55 UUUUUUUUUUUUUUUU
00000010: 55 55 D5 80 1D 01 08 30-36 30 31 31 36 31 36 08 UU.....06011616.
00000020: 01 4F 03 0B 31 32 34 38-35 35 35 31 32 31 32 06 .O..12485551212.
00000030: 01 4C D1 85 00 02 54 00-02 C5 60 28 10 0A 80 30 .L....T...`(...0
The "UUUUU" is an alternating series of ones and zeros (which, when combined with the start and stop bits, creates the 0x55 character "U") used to train analog modems.
06011616 is the date and time (JUN 01 16:16), the "O" at 0x21 is an "Out of area"
qualifier for why your name didn't appear, and "1248..." is your DN. The "L" at 0x31 is a long distance qualifier.
......@@ -87,124 +87,6 @@ struct iphdr {
#define FNAME_LEN 50
/* what should the returns from this function be?? */
/* I dont think they are currently consistant between windows and *nix */
#ifdef __WINDOWS__
static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd)
{
/* can we make the structure passed for this on nix and windows the same */
/* so we don't have to do the extra 2 memcpy's on windows for this ? */
wan_udp_hdr_t wan_udp;
DWORD ln;
unsigned char id = 0;
wan_udp.wan_udphdr_request_reply = 0x01;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL;
wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t);
memcpy( wan_udp.wan_udphdr_data, (void*)tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t));
if (DeviceIoControl(
fd,
IoctlManagementCommand,
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
return 1;
}
if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK){
return 2;
}
memcpy( (void*)tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t));
return 0;
}
#else
static __inline__ int tdmv_api_ioctl(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api_cmd)
{
return ioctl(fd, SIOC_WANPIPE_TDM_API, tdm_api_cmd);
}
#endif
void __inline__ tdmv_api_close_socket(sng_fd_t *sp)
{
if ( *sp != WP_INVALID_SOCKET){
#if defined(__WINDOWS__)
CloseHandle(*sp);
#else
close(*sp);
#endif
*sp = WP_INVALID_SOCKET;
}
}
static __inline__ sng_fd_t tdmv_api_open_span_chan(int span, int chan)
{
char fname[FNAME_LEN];
sng_fd_t fd = WP_INVALID_SOCKET;
#if defined(__WINDOWS__)
DWORD ln;
wan_udp_hdr_t wan_udp;
/* NOTE: under Windows Interfaces are zero based but 'chan' is 1 based. */
/* Subtract 1 from 'chan'. */
_snprintf(fname , FNAME_LEN, "\\\\.\\WANPIPE%d_IF%d", span, chan - 1);
fd = CreateFile( fname,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
(LPSECURITY_ATTRIBUTES)NULL,
OPEN_EXISTING,
FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,
(HANDLE)NULL
);
/* make sure that we are the only ones who have this chan open */
/* is this a threadsafe way to make sure that we are ok and will */
/* never return a valid handle to more than one thread for the same channel? */
wan_udp.wan_udphdr_command = GET_OPEN_HANDLES_COUNTER;
wan_udp.wan_udphdr_data_len = 0;
DeviceIoControl(
fd,
IoctlManagementCommand,
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
);
if ((wan_udp.wan_udphdr_return_code) || (*(int*)&wan_udp.wan_udphdr_data[0] != 1)){
/* somone already has this channel, or somthing else is not right. */
tdmv_api_close_socket(&fd);
}
#else
/* Does this fail if another thread already has this chan open? */
/* if not, we need to add some code to make sure it does */
snprintf(fname, FNAME_LEN, "/dev/wptdm_s%dc%d",span,chan);
fd = open(fname, O_RDWR);
if (fd < 0) {
fd = WP_INVALID_SOCKET;
}
#endif
return fd;
}
#if defined(__WINDOWS__)
/* This might be broken on windows, as POLL_EVENT_TELEPHONY seems to be commented out in sang_api.h.. it should be added to POLLPRI */
......
......@@ -31,6 +31,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#define ZAP_ZT_SUPPORT
#define ZAP_WANPIPE_SUPPORT
#include "openzap.h"
#include "zap_isdn.h"
#include <stdarg.h>
......
......@@ -49,7 +49,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
{
unsigned configured = 0, x;
char path[128] = "";
zt_params_t ztp = {0};
zt_params_t ztp;
memset(&ztp, 0, sizeof(ztp));
for(x = start; x < end; x++) {
zap_channel_t *chan;
......@@ -236,9 +238,11 @@ static ZIO_CLOSE_FUNCTION(zt_close)
static ZIO_COMMAND_FUNCTION(zt_command)
{
zt_params_t ztp = {0};
zt_params_t ztp;
int err = 0;
memset(&ztp, 0, sizeof(ztp));
switch(command) {
case ZAP_COMMAND_OFFHOOK:
{
......@@ -385,7 +389,8 @@ static ZIO_WAIT_FUNCTION(zt_wait)
ZIO_SPAN_POLL_EVENT_FUNCTION(zt_poll_event)
{
struct pollfd pfds[ZAP_MAX_CHANNELS_SPAN];
int i, j = 0, k = 0, r, e;
uint32_t i, j = 0, k = 0;
int r;
for(i = 1; i <= span->chan_count; i++) {
memset(&pfds[j], 0, sizeof(pfds[j]));
......@@ -474,7 +479,6 @@ ZIO_SPAN_NEXT_EVENT_FUNCTION(zt_next_event)
break;
}
event:
span->channels[i].last_event_time = 0;
span->event_header.e_type = ZAP_EVENT_OOB;
span->event_header.enum_id = event_id;
......
MOD_CFLAGS +=-DZAP_WANPIPE_SUPPORT
OBJS += $(SRC)/zap_wanpipe.o
WANPIPE_INCLUDE=/usr/include/wanpipe
WP_CFLAGS =-Wall -Werror -I$(WANPIPE_INCLUDE) -I/usr/local/include -I/usr/src/linux/include -I. -I/usr/include
WP_CFLAGS +=-D__LINUX__ -D_REENTRANT -D_GNU_SOURCE -DAFT_A104 -DWANPIPE_TDM_API -D_GNUC_ -DWANPIPE_TDM_API
MOD_CFLAGS +=-DZAP_ZT_SUPPORT
OBJS += $(SRC)/zap_zt.o
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论