mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-13 13:53:16 +00:00
improved monitor-cli.c to auto-dial a peer and pump audio in.
This commit is contained in:
parent
c6968c430a
commit
4fa63e61bc
113
monitor-cli.c
113
monitor-cli.c
@ -6,9 +6,14 @@
|
||||
#include <poll.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int fd;
|
||||
int writeLine(char *msg)
|
||||
{
|
||||
write(fd,msg,strlen(msg));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
struct sockaddr_un addr;
|
||||
int fd;
|
||||
|
||||
if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
|
||||
perror("socket error");
|
||||
@ -43,20 +48,122 @@ int main(int argc, char *argv[]) {
|
||||
fds[fdcount].events=POLLIN;
|
||||
fdcount++;
|
||||
|
||||
writeLine("monitor vomp\n");
|
||||
writeLine("monitor rhizome\n");
|
||||
|
||||
if (argc>1)
|
||||
writeLine("call * 5551 5552\n");
|
||||
|
||||
while(1) {
|
||||
poll(fds,fdcount,1000);
|
||||
|
||||
char line[1024];
|
||||
int bytes;
|
||||
int i;
|
||||
bytes=read(fd,line,1024);
|
||||
if (bytes>0)
|
||||
write(STDOUT_FILENO,line,bytes);
|
||||
for(i=0;i<bytes;i++) processChar(line[i]);
|
||||
bytes=read(STDIN_FILENO,line,1024);
|
||||
if (bytes>0) {
|
||||
write(STDOUT_FILENO,line,bytes);
|
||||
line[bytes]=0;
|
||||
printf("< %s",line);
|
||||
write(fd,line,bytes);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int callState=0;
|
||||
int processLine(char *cmd,unsigned char *data,int dataLen)
|
||||
{
|
||||
int l_id,r_id,l_state,r_state;
|
||||
printf("> %s\n",cmd);
|
||||
if (data) {
|
||||
int i,j;
|
||||
for(i=0;i<dataLen;i+=16) {
|
||||
printf(" %04x :",i);
|
||||
for(j=0;j<16;j++)
|
||||
if (i+j<dataLen) printf(" %02x",data[i+j]); else printf(" ");
|
||||
printf(" ");
|
||||
for(j=0;j<16;j++)
|
||||
if (i+j<dataLen) {
|
||||
if (data[i+j]>=0x20&&data[i+j]<0x7e)
|
||||
printf("%c",data[i+j]); else printf(".");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
if (sscanf(cmd,"CALLSTATUS:%x:%x:%d:%d",
|
||||
&l_id,&r_id,&l_state,&r_state)==4)
|
||||
{
|
||||
if (l_state==4) {
|
||||
// We are ringing, so pickup
|
||||
char msg[1024];
|
||||
sprintf(msg,"pickup %x\n",l_id);
|
||||
writeLine(msg);
|
||||
}
|
||||
callState=l_state;
|
||||
}
|
||||
if (sscanf(cmd,"KEEPALIVE:%x",&l_id)==1) {
|
||||
if (callState==5) {
|
||||
/* Send synthetic audio packet */
|
||||
char buffer[1024];
|
||||
sprintf(buffer,"*320:AUDIO:%x:8\n"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456"
|
||||
"qwertyuiopasdfghjklzxcvbnm123456",l_id);
|
||||
writeLine(buffer);
|
||||
printf("< *320:AUDIO:%x:8\\n<320 bytes>\n",l_id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
char cmd[1024];
|
||||
int cmdLen=0;
|
||||
int cmdOfs=0;
|
||||
int dataBytesExpected=0;
|
||||
unsigned char data[65536];
|
||||
int dataBytes=0;
|
||||
|
||||
#define STATE_CMD 1
|
||||
#define STATE_DATA 2
|
||||
int state=STATE_CMD;
|
||||
int processChar(int c)
|
||||
{
|
||||
switch(state) {
|
||||
case STATE_CMD:
|
||||
if (c!='\n') {
|
||||
if (cmdLen<1000) {
|
||||
cmd[cmdLen++]=c;
|
||||
}
|
||||
} else {
|
||||
if (!cmdLen) return 0;
|
||||
cmd[cmdLen]=0;
|
||||
if (sscanf(cmd,"*%d:%n",&dataBytesExpected,&cmdOfs)==1) {
|
||||
if (dataBytesExpected<0) dataBytesExpected=0;
|
||||
if (dataBytesExpected>65535) dataBytesExpected=65535;
|
||||
state=STATE_DATA;
|
||||
} else {
|
||||
processLine(cmd,NULL,0);
|
||||
cmdLen=0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case STATE_DATA:
|
||||
if (dataBytes<dataBytesExpected)
|
||||
data[dataBytes++]=c;
|
||||
if (dataBytes>=dataBytesExpected) {
|
||||
processLine(&cmd[cmdOfs],data,dataBytes);
|
||||
cmdLen=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
monitor.c
13
monitor.c
@ -369,6 +369,19 @@ int monitor_process_command(int index,char *cmd)
|
||||
else if (!strcasecmp(cmd,"ignore rhizome"))
|
||||
c->flags&=~MONITOR_RHIZOME;
|
||||
else if (sscanf(cmd,"call %s %s %s",sid,localDid,remoteDid)==3) {
|
||||
if (sid[0]=='*') {
|
||||
/* For testing, pick a peer and call them */
|
||||
int bin,slot;
|
||||
for(bin=0;bin<overlay_bin_count;bin++)
|
||||
for(slot=0;slot<overlay_bin_size;slot++)
|
||||
{
|
||||
if (!overlay_nodes[bin][slot].sid[0])
|
||||
{
|
||||
continue; }
|
||||
strcpy(sid,overlay_render_sid(overlay_nodes[bin][slot].sid));
|
||||
break;
|
||||
}
|
||||
}
|
||||
mdp.vompevent.flags=VOMPEVENT_DIAL;
|
||||
int cn=0,in=0,kp=0;
|
||||
if(!keyring_next_identity(keyring,&cn,&in,&kp))
|
||||
|
Loading…
x
Reference in New Issue
Block a user