[asterisk-dev] data over zap channel

Muhammad Ali enigma.ali at gmail.com
Sat Jul 3 07:01:28 CDT 2010


Hi,

I am trying to send custom data over zap channel. for that i have to kill
asterisk so the channels arent busy anymore.

I am using /dev/zap/channel interface to access channels for reading and
writing. The problem i am experiencing is that the number of bytes
transmitted is not equal to number of received bytes. i am unable to
identify whether it is a problem at transmission end or the reception end.

I am using two asterisk ready systems to achieve this....

Any help would be appreciated :)
BR.
Ali


Code follows:

======================
FOR WRITING TO A CHANNEL
======================
int main()
{

int fd ; //file descriptor for channel
int chan = 0;
int res = 0;
ZT_BUFFERINFO bi;
unsigned char *buffer = "A";//my name is muhammad Ali fff";
unsigned char *tbuf;
int size = 0;

 fd = open("/dev/zap/channel",O_RDWR | O_NONBLOCK,0600);

if(fd<0)
{
perror("failed to open interface");
exit(-1);

}
 tbuf = (unsigned char*)malloc(NUM_BUF);
 printf("Using Number: %d \n",fd);
chan = 1;
res = ioctl(fd,ZT_SPECIFY,&chan);
if(res < 0)
{
perror("could not specify channel");
exit(-1);
}

res = ioctl(fd, ZT_GET_BUFINFO, &bi);

bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
bi.numbufs = 4;
bi.bufsize = 1024;

res = ioctl(fd, ZT_SET_BUFINFO, &bi);
if (res < 0) {
perror("unable to set buffer info");
exit(-1);
}


size = NUM_BUF; ///NUM_BUF;//sizeof(buffer);
printf("writing %d bytes /n",size);
 g_buffer.left = 27;
for(;;)
{
//create_chunk(tbuf,buffer,8,27);
res = write(fd,buffer,size);
 if (res != size)
{
printf("didnr write complete buffer : %d \n", res);
}
res = ioctl(fd,ZT_SYNC,&chan);
if(res < 0)
printf("WHAT THE EFF \n");
}
printf("written bytes: %d \n",res);
close(fd);
printf("Hello world");


return 0;
}

===========================
FOR READING FROM A CHANNEL
===========================
int main()
{


int fd ; //file descriptor for channel
int chan = 0;
int res = 0;
int bs = 0;
ZT_BUFFERINFO bi;
//unsigned char *buffer = "2";
unsigned char buffer[256];
int size = 0;
int i= 0;

fd = open("/dev/zap/channel",O_RDWR | O_NONBLOCK,0600); //

if(fd<0)
{
perror("failed to open interface");
exit(-1);

}

printf("Using Number: %d \n",fd);
chan = 1;
res = ioctl(fd,ZT_SPECIFY,&chan);
if(res < 0)
{
perror("could not specify channel");
close(fd);
exit(-1);
}

printf("Channel Specified \n");
/*bs = 169;//READ_SIZE;
if (ioctl(fd, ZT_SET_BLOCKSIZE, &bs) == -1) {
perror("Unable to set blocksize ");
close(fd);
return -1;
}*/

res = ioctl(fd, ZT_GET_BUFINFO, &bi);

bi.txbufpolicy = ZT_POLICY_IMMEDIATE;
bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;
bi.numbufs = 4;
bi.bufsize = 1024;

res = ioctl(fd, ZT_SET_BUFINFO, &bi);
if (res < 0) {
perror("unable to set buffer info");
close(fd);
exit(-1);
}
printf("Buffers Policy Set \n");
 size = 256;///sizeof(buffer);
printf("Reading %d bytes \n",size);
for(;;)
{
//res = write(fd,buffer,size);
res = read(fd,buffer,size);
if (!(res < 0))
{
for(i=0;i<256;i++)
{
if(buffer[i] !=255)
printf("Read data: %d \n",(unsigned char)buffer[i]);
 }
}
}
printf("written bytes: %d \n",res);
close(fd);
printf("Hello world");


return 0;
}

-- 
ALi...
(علی)
http://m-ali.deviantart.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-dev/attachments/20100703/bbc0636a/attachment-0001.htm 


More information about the asterisk-dev mailing list