Hi,<div><br></div><div>I am trying to send custom data over zap channel. for that i have to kill asterisk so the channels arent busy anymore.</div><div><br></div><div>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. </div>
<div><br></div><div>I am using two asterisk ready systems to achieve this.... </div><div><br></div><div>Any help would be appreciated :)</div><div>BR.</div><div>Ali</div><div><br></div><div><br></div><div>Code follows:</div>
<div><br></div><div>======================</div><div>FOR WRITING TO A CHANNEL</div><div>======================</div><div><div>int main()</div><div>{</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int fd ; <span class="Apple-tab-span" style="white-space:pre">                </span>//file descriptor for channel</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int chan = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int res = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>ZT_BUFFERINFO bi;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>unsigned char *buffer = "A";//my name is muhammad Ali fff";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>unsigned char *tbuf;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int size = 0;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>fd = open("/dev/zap/channel",O_RDWR | O_NONBLOCK,0600);</div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(fd<0)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>perror("failed to open interface");</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>tbuf = (unsigned char*)malloc(NUM_BUF);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("Using Number: %d \n",fd);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>chan = 1;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>res = ioctl(fd,ZT_SPECIFY,&chan);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(res < 0)</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>perror("could not specify channel");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>res = ioctl(fd, ZT_GET_BUFINFO, &bi);</div><div><br></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>bi.txbufpolicy = ZT_POLICY_IMMEDIATE;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bi.numbufs = 4;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>bi.bufsize = 1024;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>res = ioctl(fd, ZT_SET_BUFINFO, &bi);</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>if (res < 0) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>perror("unable to set buffer info");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>size = NUM_BUF;<span class="Apple-tab-span" style="white-space:pre">        </span>///NUM_BUF;//sizeof(buffer);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("writing %d bytes /n",size);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>g_buffer.left = 27;</div>
<div>for(;;)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//create_chunk(tbuf,buffer,8,27);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>res = write(fd,buffer,size);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (res != size)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>printf("didnr write complete buffer : %d \n", res);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>res = ioctl(fd,ZT_SYNC,&chan);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>if(res < 0)</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>printf("WHAT THE EFF \n");</div><div>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("written bytes: %d \n",res);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>close(fd);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("Hello world");</div><div><br></div><div><br></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>return 0;</div><div>}</div><div><br></div><div>===========================</div><div>FOR READING FROM A CHANNEL</div><div>===========================</div><div>
int main()</div><div>{</div><div><div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int fd ; <span class="Apple-tab-span" style="white-space:pre">                </span>//file descriptor for channel</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int chan = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int res = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int bs = 0;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>ZT_BUFFERINFO bi;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//unsigned char *buffer = "2";</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>unsigned char buffer[256];</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>int size = 0;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>int i= 0;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>fd = open("/dev/zap/channel",O_RDWR | O_NONBLOCK,0600); // </div>
<div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(fd<0)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>perror("failed to open interface");</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("Using Number: %d \n",fd);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>chan = 1;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>res = ioctl(fd,ZT_SPECIFY,&chan);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if(res < 0)</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>perror("could not specify channel");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>close(fd);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("Channel Specified \n");</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>/*bs = 169;//READ_SIZE;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>if (ioctl(fd, ZT_SET_BLOCKSIZE, &bs) == -1) {</div><div>
<span class="Apple-tab-span" style="white-space:pre">                </span>perror("Unable to set blocksize ");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>close(fd);</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>return -1;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>}*/</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>res = ioctl(fd, ZT_GET_BUFINFO, &bi);</div><div><br></div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>bi.txbufpolicy = ZT_POLICY_IMMEDIATE;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bi.rxbufpolicy = ZT_POLICY_IMMEDIATE;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>bi.numbufs = 4;</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>bi.bufsize = 1024;</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>res = ioctl(fd, ZT_SET_BUFINFO, &bi);</div><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>if (res < 0) {</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>perror("unable to set buffer info");</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>close(fd);</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>exit(-1);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("Buffers Policy Set \n");</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>size = 256;///sizeof(buffer);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("Reading %d bytes \n",size);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span></div><div>for(;;)</div><div>{</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>//res = write(fd,buffer,size);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>res = read(fd,buffer,size);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>if (!(res < 0))</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                </span>for(i=0;i<256;i++)</div>
<div><span class="Apple-tab-span" style="white-space:pre">                </span>{</div><div><span class="Apple-tab-span" style="white-space:pre">                        </span>if(buffer[i] !=255)</div><div><span class="Apple-tab-span" style="white-space:pre">                                </span>printf("Read data: %d \n",(unsigned char)buffer[i]); </div>
<div><span class="Apple-tab-span" style="white-space:pre">                        </span></div><div><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>}</div>
<div>}</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("written bytes: %d \n",res);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>close(fd);</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>printf("Hello world");</div>
<div><br></div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>return 0;</div><div>}</div></div><br>-- <br>ALi...<br>(علی)<br><a href="http://m-ali.deviantart.com">http://m-ali.deviantart.com</a><br>
<br>
</div>