📄 simplevm.java
字号:
if (code == this.code)
return true;
play(home+"badcode.vox", tptNone);
}
return false;
}
/**
* tellmessages() : play back recorded messages
*/
private void tellmessages() {
PLFolder messages = new PLFolder(folder);
int total = messages.size();
for (int i = 0; i < total; ) {
play(folder + messages.fileAt(i), tptNone);
play(home+"menu.vox", tptDigit);
String op = vdev.getdig(tptDigit);
vdev.waitIdle();
if (op.length() == 0)
// No input ?? assume repeat
continue;
switch(op.charAt(0)) {
case '1':
// repeat
break;
case '2':
// Erase
File messFile = new File(folder+messages.fileAt(i));
messFile.delete();
case '3':
// Keep:
i++;
break;
default:
// Bad input, should tell him...
break;
}
}
play(home+"nomore.vox", tptNone);
}
/**
* newFile(directory)
* Make a new file in a directory. Take care of name clashes...
*/
private File newFile(String directory) throws IOException {
Date now = new Date();
RandomAccessFile raf;
File temp, f;
temp = new File(directory, "newfile.tmp");
StringBuffer basename = new StringBuffer("@");
int d = now.getMonth() * 31 + now.getDate();
if (d < 10) basename.append("0");
if (d < 100) basename.append("0");
basename.append(d);
d = now.getHours();
if (d < 10) basename.append("0");
basename.append(d);
d = now.getMinutes();
if (d < 10) basename.append("0");
basename.append(d);
basename.append(".");
d = now.getSeconds();
if (d < 10) basename.append("0");
basename.append(d);
basename.append(" ");
for (d = 0; d < 36; d++) {
// Create a unique file
// Lots of trouble because of lack of create() sys call.
if (d < 10)
basename.setCharAt(11, (char)('0' + d));
else
basename.setCharAt(11, (char)('a' - 10 + d));
f = new File(directory, basename.toString());
if (f.exists()) continue;
do {
try {
raf = new RandomAccessFile(temp, "rw");
raf.close();
// Rename to f, if succeeds, then its ok
if (temp.renameTo(f))
return f;
} catch (IOException ioe) {
// Somebody is using it now ?
try { Thread.currentThread().sleep(100);
} catch (InterruptedException ie) {
throw new RuntimeException("newFile interrupted");
}
continue;
}
} while (!temp.exists()); // May be some one used ours ?
}
temp.delete();
throw new IOException("newFile: too many new files");
}
/**
* getNumber(dx, min length, max length, do beep)
* ask for a numeric input with standard sintaxis (i.e. * clears, # ends)
*/
public static long getNumber(Voice v, int min, int max, boolean bip) {
// Input of digits:
// end if * or # at once, first digit at 4 secs max, next at 2
TPT fdigTpt = new TPT(TPT.DIGMASK, 0xffff, TPT.LEVEL, 0);
fdigTpt.add(TPT.MAXTIME, 40, 0, 0);
TPT ndigTpt = new TPT(TPT.DIGMASK, TPT.DM_P|TPT.DM_S, TPT.LEVEL, 0);
ndigTpt.add(TPT.MAXIDDTIME, 10, 0, 0);
ndigTpt.add(TPT.MAXDTMF, max-1, TPT.LEVEL|TPT.USE, 0);
if (bip) {
v.playtone(new TNGEN(1000, -10, 20), new TPT());
v.cleardig();
}
String dig = v.getdig(fdigTpt);
if (dig.length() == 0) {
// No input ?
throw new NumberFormatException("No input");
}
if (dig.charAt(0) == '#') {
// ??
return 0;
}
if (dig.charAt(0) == '*') {
// clear ?
v.cleardig();
dig = "";
}
for (int i = 0; i < 3; i++) {
dig += v.getdig(ndigTpt);
int len = dig.length();
if (len == 0) {
continue;
}
switch(dig.charAt(len-1)) {
case '*':
v.cleardig();
dig = "";
continue;
case '#':
if (len == 1)
return 0;
return Long.parseLong(dig.substring(0, len-1));
default:
if (len < min)
continue;
return Long.parseLong(dig.substring(0, len));
}
}
throw new NumberFormatException("Bad input");
}
private void play(String file, TPT tpt) {
try {
IOTT iott = new IOTT(file);
vdev.play(iott, tpt, Dialogic.SR_8);
vdev.waitIdle();
iott.close();
} catch (IOException e) {
System.out.println("Play error");
return;
}
}
/**
* PLFolder: small class to deal with messages in a folder
*/
class PLFolder extends Object implements FilenameFilter {
File directory;
String files[] = null;
public PLFolder(String dirName) {
directory = new File(dirName);
if (!directory.isDirectory())
throw new RuntimeException("Invalid directory name");
}
public int size() {
if (files == null) init();
return files.length;
}
public String fileAt(int n) {
if (files == null) init();
if (n >= size())
throw new IndexOutOfBoundsException("PLFolder: not so many files");
return files[n];
}
private void init() {
files = directory.list(this);
}
public boolean accept(File dir, String name) {
return name.charAt(0) == '@';
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -