📄 voice.java
字号:
}
/** Read # of digits in queue */
public synchronized int digits() {
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Get buffered digits()");
return Dialogic.ATDX_BUFDIGS(device);
}
/** Get a digit from channel */
public synchronized String getdig(TPT tpt) {
if (tpt == null)
throw new RuntimeException("Bad parameter value");
byte buf[] = new byte[64]; // Should be >= 2 * (DG_MAXDIGS+1) = 64
EVT evt;
try {
channel.beginService();
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice getdig (" + device + ")");
Dialogic.dx_getdig(this, tpt, Dialogic.EV_ASYNC);
do {
evt = channel.serviceWaitEvent();
} while (evt.type != EVT.TDX_GETDIG);
int i = Dialogic.dx_getdig(this, buf);
// returns number of digits
if (i < 1)
return "";
else
return new String(buf, 0, i);
} finally {
channel.endService();
}
}
protected int callpStatus() {
int result = Dialogic.ATDX_CPTERM(device);
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice CPTERM (" + device + "): " + result);
return result;
}
/** Clear "memory" of voice resource when clearing channel */
public synchronized void clear() {
cleardig();
digitEvents(false);
}
/** Clear digit buffer */
public synchronized void cleardig() {
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice cleardig (" + device + ")");
Dialogic.dx_clrdigbuf(device);
}
/** Enable digit events */
public synchronized void digitEvents(boolean doEvents) {
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice digitEvents (" + device + "," + doEvents + ")");
if (doEvents)
Dialogic.dx_setevtmsk(device, Dialogic.DM_DIGITS);
else
Dialogic.dx_setevtmsk(device, Dialogic.DM_DIGOFF);
}
/** Get ANI (analog caller-ID) from channel */
public synchronized String getAni() {
byte buf[] = new byte[81]; // Should be able to get away with 21...
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice getAni (" + device + ")");
buf[0] = 0;
int len = Dialogic.dx_gtcallid(device, buf);
// figure out what we got
if (len < 0) {
// Map Caller-ID errors back to strings
switch (-len) {
case Dialogic.EDX_CLIDINFO: // Info/sub-msg not available
return "";
case Dialogic.EDX_CLIDBLK: // Private / blocked
return "P";
case Dialogic.EDX_CLIDOOA: // Out of area
return "O";
case Dialogic.EDX_CLIDPUB: // Public phone
return "C";
case Dialogic.EDX_CLIDPLAN: // Unknown plan
return "S";
default:
return "";
}
} else {
// Return a string
return new String(buf, 0, len);
}
}
/** Get ANI details from channel */
public synchronized String getCallerIdExtended(int infoType) {
if (infoType == Dialogic.CLIDINFO_FRAMETYPE) {
throw new IllegalArgumentException("Use getCallerIdFrameType");
}
byte buf[] = new byte[259]; // Dialogic specifies max buffer is 258 data bytes.
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice getCallerIdExtended (" + device + "," + infoType + ")");
buf[0] = 0;
int len = Dialogic.dx_gtextcallid(device, infoType, buf);
// figure out what we got
if (len < 0) {
if (len == -Dialogic.EDX_CLIDINFO) { // Info/sub-msg not available
return "";
}
if (infoType == Dialogic.CLIDINFO_CALLID) {
// Map Caller-ID errors back to strings
switch (-len) {
case Dialogic.EDX_CLIDBLK: // Private / blocked
return "P";
case Dialogic.EDX_CLIDOOA: // Out of area
return "O";
case Dialogic.EDX_CLIDPUB: // Public phone
return "C";
case Dialogic.EDX_CLIDPLAN: // Unknown plan
return "S";
}
}
throw new RuntimeException("getCallerIdExtended(" + infoType + ") returned " + -len + " for " + this);
} else {
// Return a string
return new String(buf, 0, len);
}
}
/** Get caller-ID frame type */
public synchronized int getCallerIdFrameType() {
byte buf[] = new byte[259];
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice getCallerIdFrameType (" + device + ")");
buf[0] = 0;
int len = Dialogic.dx_gtextcallid(device, Dialogic.CLIDINFO_FRAMETYPE, buf);
if (len == 1) {
return ((int) buf[0]) & 0x0FF; // Force unsigned conversion to integer.
} else {
throw new RuntimeException("getCallerIdFrameType returned len=" + len + " for " + this);
}
}
/** Enable perfect call */
public synchronized void initPerfectCall() {
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Init perfect call (" + device + ")");
Dialogic.dx_initcallp(device);
}
public void dial(String number, DXCAP cap) {
dial(number, cap, false);
}
public void dial(String number, DXCAP cap, boolean perfect) {
waitIdle();
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice dial (" + device + ")");
int linest = Dialogic.ATDX_LINEST(device);
if ((linest & Dialogic.RLS_HOOK) != 0) {
channel.beginService();
try {
Dialogic.dx_sethook(device, Dialogic.DX_OFFHOOK, Dialogic.EV_ASYNC);
channel.serviceWaitEvent();
} finally {
channel.endService();
}
}
int ret = Dialogic.dx_dial(device, number, cap, (perfect?Dialogic.DX_CALLP:0)|Dialogic.EV_ASYNC);
}
// Make a single GTD tone
int GTDid = 1;
public synchronized int buildStGTD(int freq, int dev) {
waitIdle();
synchronized(toneLock) {
Dialogic.dx_bldst(GTDid, freq, dev,Dialogic.TN_LEADING);
int ok = Dialogic.dx_addtone(device, 0, 0);
if (ok != 0)
throw new RuntimeException("Addtone failed for " + this);
Dialogic.dx_distone(device, GTDid, Dialogic.DM_TONEON|Dialogic.DM_TONEOFF);
}
return GTDid++;
}
// Make a dual GTD tone
public synchronized int buildDtGTD(int freq1, int freq2, int dev) {
waitIdle();
synchronized(toneLock) {
Dialogic.dx_blddt(GTDid, freq1, dev, freq2, dev, Dialogic.TN_LEADING);
int ok = Dialogic.dx_addtone(device, 0, 0);
if (ok != 0)
throw new RuntimeException("Addtone failed for " + this);
Dialogic.dx_distone(device, GTDid, Dialogic.DM_TONEON|Dialogic.DM_TONEOFF);
}
return GTDid++;
}
// enable/disable GTD tones
public synchronized void setGTD(int id, boolean toneOn, boolean toneOff) {
waitIdle();
int mask = 0;
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"GTD " + id + " (" + device + ") " + (toneOn ? "On/":"Off/") + (toneOff ? "On":"Off"));
if (toneOn) mask |= Dialogic.DM_TONEON;
if (toneOff) mask |= Dialogic.DM_TONEOFF;
if ((Dialogic.dx_distone(device, id,
(Dialogic.DM_TONEON|Dialogic.DM_TONEOFF) & ~mask) != 0) ||
(Dialogic.dx_enbtone(device, id, mask) != 0))
throw new RuntimeException("setGTD failed for " + this);
}
// stop channel
public synchronized void stop() {
try {
channel.beginService();
while (Dialogic.ATDX_STATE(device) != Dialogic.CS_IDLE) {
if ((Dialogic.debug & Dialogic.DEBUG_VFNS) != 0)
System.out.println(new java.util.Date().toString().substring(11,20) +
"Voice stop (" + device + ")");
Dialogic.dx_stopch(device, Dialogic.EV_ASYNC);
channel.serviceWaitEvent(200);
}
channel.flush();
} finally {
channel.endService();
}
}
// SC routing fns
public int getTs() {
return Dialogic.dx_getxmitslot(device);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -