This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
sdk:scripts:voice-dispatcher-audio [2022/08/23 13:33] – juraschek | sdk:scripts:voice-dispatcher-audio [2022/09/05 12:27] (current) – schmitt | ||
---|---|---|---|
Line 2: | Line 2: | ||
<code c voice-dispatcher-audio.are> | <code c voice-dispatcher-audio.are> | ||
/* DESC: This script implements an audio voice dispatcher | /* DESC: This script implements an audio voice dispatcher | ||
- | * The first audio Interface (line-in/ | ||
- | * - Dialing os controlled via digital in 1 (in1) | ||
- | | ||
- | | ||
- | | ||
- | * - Incomming calls are signaled at digital out 1 (out1). | ||
- | | ||
- | | ||
- | * | ||
* Copyright (C) 2012 NetModule AG, Switzerland | * Copyright (C) 2012 NetModule AG, Switzerland | ||
- | | ||
*/ | */ | ||
- | INTERVAL = 1; // polling status change every x seconds | + | INTERVAL = 3; /* 3 seconds |
- | NUMBER = " | + | NUMBER = " |
template dispatcher { | template dispatcher { | ||
Line 36: | Line 26: | ||
nb_syslog(" | nb_syslog(" | ||
- | // record first audio endpoint | + | /* record first audio endpoint |
if (is_void(aud) && left(desc, 6) == " | if (is_void(aud) && left(desc, 6) == " | ||
this.audio = ep; | this.audio = ep; | ||
Line 56: | Line 46: | ||
if (in1 == this.in1) { | if (in1 == this.in1) { | ||
- | // no state change | + | /* no state change |
return -1; | return -1; | ||
} else { | } else { | ||
- | // update state | + | /* update state */ |
nb_syslog(" | nb_syslog(" | ||
this.in1 = in1; | this.in1 = in1; | ||
Line 68: | Line 58: | ||
int handle_dio_event (int ev) | int handle_dio_event (int ev) | ||
{ | { | ||
- | // update endpoint first | + | /* update endpoint first */ |
au = nb_voice_endpoint_get(d.audio); | au = nb_voice_endpoint_get(d.audio); | ||
if (!is_struct(au)) { | if (!is_struct(au)) { | ||
Line 77: | Line 67: | ||
austate = struct_get(au, | austate = struct_get(au, | ||
- | // get list of currently active calls | + | /* get list of currently active calls */ |
calls = nb_voice_call_list(); | calls = nb_voice_call_list(); | ||
Line 84: | Line 74: | ||
if (austate == " | if (austate == " | ||
- | // initiate new call | + | /* initiate new call */ |
call = mkstruct(" | call = mkstruct(" | ||
" | " | ||
Line 93: | Line 83: | ||
nb_syslog(" | nb_syslog(" | ||
} | } | ||
- | nb_dio_set(" | ||
} else { | } else { | ||
nb_syslog(" | nb_syslog(" | ||
Line 101: | Line 90: | ||
nb_syslog(" | nb_syslog(" | ||
- | // terminate any active calls | + | /* terminate any active calls */ |
for (i = 0; i < length(calls); | for (i = 0; i < length(calls); | ||
call = calls[i]; | call = calls[i]; | ||
Line 110: | Line 99: | ||
} | } | ||
} | } | ||
- | nb_dio_set(" | ||
} | } | ||
Line 124: | Line 112: | ||
nb_syslog(" | nb_syslog(" | ||
- | // update endpoint | + | /* update endpoint |
au = nb_voice_endpoint_get(d.audio); | au = nb_voice_endpoint_get(d.audio); | ||
if (!is_struct(au)) { | if (!is_struct(au)) { | ||
Line 135: | Line 123: | ||
switch (type) { | switch (type) { | ||
case " | case " | ||
- | // don't touch any locally initiated calls | + | /* don't touch any locally initiated calls */ |
break; | break; | ||
case " | case " | ||
Line 141: | Line 129: | ||
id, struct_get(call, | id, struct_get(call, | ||
- | // route any incoming calls to audio device | + | /* route any incoming calls to audio device |
if (nb_voice_call_route(call, | if (nb_voice_call_route(call, | ||
nb_syslog(" | nb_syslog(" | ||
- | nb_dio_set(" | ||
} else { | } else { | ||
nb_syslog(" | nb_syslog(" | ||
nb_voice_call_hangup(call); | nb_voice_call_hangup(call); | ||
- | // no signaling | ||
} | } | ||
break; | break; | ||
case " | case " | ||
- | // accept calls if DI1 closes | + | /* accept calls if DI1 closes |
nb_syslog(" | nb_syslog(" | ||
Line 160: | Line 146: | ||
if (austate == " | if (austate == " | ||
nb_syslog(" | nb_syslog(" | ||
+ | nb_voice_call_hangup(call); | ||
} else { | } else { | ||
- | // wait until IN1 has been closed | + | /* wait until IN1 has been closed |
nb_syslog(" | nb_syslog(" | ||
for (i = 0; i < 10; i++) { | for (i = 0; i < 10; i++) { | ||
Line 170: | Line 157: | ||
if (nb_voice_call_accept(call) == 0) { | if (nb_voice_call_accept(call) == 0) { | ||
nb_syslog(" | nb_syslog(" | ||
- | | + | |
- | return; | + | if (1) { |
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | return; | ||
} else { | } else { | ||
nb_syslog(" | nb_syslog(" | ||
Line 180: | Line 172: | ||
} | } | ||
} | } | ||
- | // otherwise hangup | + | /* otherwise hangup |
nb_syslog(" | nb_syslog(" | ||
nb_voice_call_hangup(call); | nb_voice_call_hangup(call); | ||
- | nb_dio_set(" | ||
} | } | ||
break; | break; | ||
Line 193: | Line 184: | ||
void run () | void run () | ||
{ | { | ||
- | // wait for calls | + | /* wait for calls */ |
while (1) { | while (1) { | ||
event = nb_voice_event(INTERVAL); | event = nb_voice_event(INTERVAL); | ||
Line 209: | Line 200: | ||
d = new dispatcher(); | d = new dispatcher(); | ||
- | nb_dio_set(" | ||
dump(d); | dump(d); | ||
d.run(); | d.run(); | ||
exit(0); | exit(0); | ||
- | |||
</ | </ | ||