This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
sdk:scripts:voice-dispatcher-audio [2020/03/18 09:47] fachet |
sdk:scripts:voice-dispatcher-audio [2022/08/30 15:29] cakir |
||
---|---|---|---|
Line 15: | Line 15: | ||
*/ | */ | ||
- | INTERVAL = 1; /* polling status change every x seconds */ | + | INTERVAL = 1; // polling status change every x seconds |
- | NUMBER = "+123456789"; /* number to call when DI1 = on */ | + | NUMBER = "+123456789"; // number to call when DI1 = on |
template dispatcher { | template dispatcher { | ||
Line 36: | Line 36: | ||
nb_syslog("%d: endpoint %d is in state %s (%s)", i, id, state, desc); | nb_syslog("%d: endpoint %d is in state %s (%s)", i, id, state, desc); | ||
- | /* record first audio endpoint */ | + | // record first audio endpoint |
if (is_void(aud) && left(desc, 6) == "aud://") { | if (is_void(aud) && left(desc, 6) == "aud://") { | ||
this.audio = ep; | this.audio = ep; | ||
Line 56: | Line 56: | ||
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("updating dio state"); | nb_syslog("updating dio state"); | ||
this.in1 = in1; | this.in1 = in1; | ||
Line 68: | Line 68: | ||
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(this.audio.id); |
if (!is_struct(au)) { | if (!is_struct(au)) { | ||
nb_syslog("updating audio endpoint failed"); | nb_syslog("updating audio endpoint failed"); | ||
Line 77: | Line 77: | ||
austate = struct_get(au, "state"); | austate = struct_get(au, "state"); | ||
- | /* 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 84: | ||
if (austate == "available") { | if (austate == "available") { | ||
- | /* initiate new call */ | + | // initiate new call |
call = mkstruct("calling", audesc, | call = mkstruct("calling", audesc, | ||
"called", NUMBER); | "called", NUMBER); | ||
Line 93: | Line 93: | ||
nb_syslog("unable to initate call to %s", NUMBER); | nb_syslog("unable to initate call to %s", NUMBER); | ||
} | } | ||
- | nb_dio_set("out2", 1); /* call is active */ | + | nb_dio_set("out2", 1); // call is active |
} else { | } else { | ||
nb_syslog("not calling %s as endpoint %s is not available", NUMBER, audesc); | nb_syslog("not calling %s as endpoint %s is not available", NUMBER, audesc); | ||
Line 101: | Line 101: | ||
nb_syslog("DI1 has been opened"); | nb_syslog("DI1 has been opened"); | ||
- | /* terminate any active calls */ | + | // terminate any active calls |
for (i = 0; i < length(calls); i++) { | for (i = 0; i < length(calls); i++) { | ||
call = calls[i]; | call = calls[i]; | ||
Line 110: | Line 110: | ||
} | } | ||
} | } | ||
- | nb_dio_set("out2", 0); /* no active call */ | + | nb_dio_set("out2", 0); // no active call |
} | } | ||
Line 124: | Line 124: | ||
nb_syslog("received voice event '%s' on call %d\n", type, id); | nb_syslog("received voice event '%s' on call %d\n", type, id); | ||
- | /* update endpoint */ | + | // update endpoint |
- | au = nb_voice_endpoint_get(d.audio); | + | au = nb_voice_endpoint_get(this.audio.id); |
if (!is_struct(au)) { | if (!is_struct(au)) { | ||
nb_syslog("updating audio endpoint failed"); | nb_syslog("updating audio endpoint failed"); | ||
Line 135: | Line 135: | ||
switch (type) { | switch (type) { | ||
case "outgoing": | case "outgoing": | ||
- | /* don't touch any locally initiated calls */ | + | // don't touch any locally initiated calls |
break; | break; | ||
case "incoming": | case "incoming": | ||
Line 141: | Line 141: | ||
id, struct_get(call, "calling"), struct_get(call, "called")); | id, struct_get(call, "calling"), struct_get(call, "called")); | ||
- | /* route any incoming calls to audio device */ | + | // route any incoming calls to audio device |
if (nb_voice_call_route(call, audesc) == 0) { | if (nb_voice_call_route(call, audesc) == 0) { | ||
nb_syslog("routing call %d to %s", id, audesc); | nb_syslog("routing call %d to %s", id, audesc); | ||
- | nb_dio_set("out2", 1); /* ring, incomming call */ | + | nb_dio_set("out2", 1); // ring, incomming call |
} else { | } else { | ||
nb_syslog("unable to route call %d to %s", id, audesc); | nb_syslog("unable to route call %d to %s", id, audesc); | ||
nb_voice_call_hangup(call); | nb_voice_call_hangup(call); | ||
- | nb_dio_set("out2", 0); /* error, no active call */ | + | // no signaling |
} | } | ||
break; | break; | ||
case "dispatched": | case "dispatched": | ||
- | /* accept calls if DI1 closes */ | + | // accept calls if DI1 closes |
nb_syslog("call %s: %s to %s got dispatched", | nb_syslog("call %s: %s to %s got dispatched", | ||
Line 161: | Line 161: | ||
nb_syslog("hanging up call %d as audio is busy", id); | nb_syslog("hanging up call %d as audio is busy", id); | ||
} else { | } else { | ||
- | /* wait until IN1 has been closed */ | + | // wait until IN1 has been closed |
nb_syslog("waiting 10s until IN1 is closed"); | nb_syslog("waiting 10s until IN1 is closed"); | ||
for (i = 0; i < 10; i++) { | for (i = 0; i < 10; i++) { | ||
Line 170: | Line 170: | ||
if (nb_voice_call_accept(call) == 0) { | if (nb_voice_call_accept(call) == 0) { | ||
nb_syslog("accepted call %d", id); | nb_syslog("accepted call %d", id); | ||
- | /* nb_voice_call_volume(call, 7); increase volume level to max */ | + | // nb_voice_call_volume(call, 7); increase volume level to max // |
- | return; /* call established */ | + | return; // call established |
} else { | } else { | ||
nb_syslog("unable to accept call %d", id); | nb_syslog("unable to accept call %d", id); | ||
Line 180: | Line 180: | ||
} | } | ||
} | } | ||
- | /* otherwise hangup */ | + | // otherwise hangup |
nb_syslog("hanging up call %d", id); | nb_syslog("hanging up call %d", id); | ||
nb_voice_call_hangup(call); | nb_voice_call_hangup(call); | ||
- | nb_dio_set("out2", 0); /* error, no active call */ | + | nb_dio_set("out2", 0); // error, no active call |
} | } | ||
break; | break; | ||
Line 193: | Line 193: | ||
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 209: | ||
d = new dispatcher(); | d = new dispatcher(); | ||
- | nb_dio_set("out1", 0); /* clear signaling */ | + | nb_dio_set("out1", 0); // clear signaling |
dump(d); | dump(d); | ||
d.run(); | d.run(); |