移动电话AT命令集模拟器:响应代码的正确语法

时间:2010-10-14 12:21:41

标签: android bluetooth gsm

我们有一些传统硬件使用DUN配置文件通过蓝牙连接到手机。然后它发出AT命令来读取SMS以进行监控。

Android手机不支持AT over DUN。这就是我写这个应用程序的原因。问题是:虽然传统硬件将连接到手机,但它不会接受我对其命令的响应。具体来说,似乎不接受我对AT + CGMI命令的回答。我假设我使用CR和LF控制字符有问题,但我无法弄清楚发生了什么。

以下是聊天记录的示例:

10-14 14:14:49.674: DEBUG/PROG(2663): Server started, object is android.bluetooth.BluetoothServerSocket@44f102f8
10-14 14:17:07.264: DEBUG/PROG(2663): From Device:ATE0
10-14 14:17:07.264: DEBUG/PROG(2663): To Device: 
10-14 14:17:07.264: DEBUG/PROG(2663): OK
10-14 14:17:07.868: DEBUG/PROG(2663): From Device:ATE0
10-14 14:17:07.868: DEBUG/PROG(2663): To Device: 
10-14 14:17:07.868: DEBUG/PROG(2663): OK
10-14 14:17:10.774: DEBUG/PROG(2663): From Device:AT+CGMI
10-14 14:17:10.774: DEBUG/PROG(2663): To Device: 
10-14 14:17:10.774: DEBUG/PROG(2663): "Sony Ericsson"
10-14 14:17:10.774: DEBUG/PROG(2663): 
10-14 14:17:10.774: DEBUG/PROG(2663): OK
10-14 14:17:11.434: DEBUG/PROG(2663): From Device:ATE0
10-14 14:17:11.434: DEBUG/PROG(2663): To Device: 
10-14 14:17:11.434: DEBUG/PROG(2663): OK
10-14 14:17:12.025: DEBUG/PROG(2663): From Device:ATE0
10-14 14:17:12.025: DEBUG/PROG(2663): To Device: 
10-14 14:17:12.025: DEBUG/PROG(2663): OK
10-14 14:17:14.827: DEBUG/PROG(2663): From Device:AT+CGMI
10-14 14:17:14.827: DEBUG/PROG(2663): To Device: 
10-14 14:17:14.827: DEBUG/PROG(2663): "Sony Ericsson"
10-14 14:17:14.827: DEBUG/PROG(2663): 
10-14 14:17:14.827: DEBUG/PROG(2663): OK
10-14 14:17:15.454: DEBUG/PROG(2663): From Device:ATE0
10-14 14:17:15.454: DEBUG/PROG(2663): To Device: 
10-14 14:17:15.454: DEBUG/PROG(2663): OK
10-14 14:17:16.084: DEBUG/PROG(2663): From Device:ATE0
10-14 14:17:16.084: DEBUG/PROG(2663): To Device: 
10-14 14:17:16.084: DEBUG/PROG(2663): OK
10-14 14:17:18.444: DEBUG/PROG(2663): IOException: all aboard the failboat!
10-14 14:17:18.444: DEBUG/PROG(2663): java.io.IOException: Connection reset by peer
10-14 14:17:18.444: DEBUG/PROG(2663):     at android.bluetooth.BluetoothSocket.readNative(Native Method)
10-14 14:17:18.444: DEBUG/PROG(2663):     at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:307)
10-14 14:17:18.444: DEBUG/PROG(2663):     at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
10-14 14:17:18.444: DEBUG/PROG(2663):     at java.io.InputStreamReader.read(InputStreamReader.java:275)
10-14 14:17:18.444: DEBUG/PROG(2663):     at java.io.BufferedReader.fillBuf(BufferedReader.java:155)
10-14 14:17:18.444: DEBUG/PROG(2663):     at java.io.BufferedReader.readLine(BufferedReader.java:404)

当设备重置连接时会发生异常。

以下是一些代码:

private static final String REPLY_OK = "\r\nOK\r\n";
private static final String REPLY_MANUFACTURER = "\r\n\"Sony Ericsson\"\r\n\r\nOK\r\n";
private static final String ECHO_OFF = "ATE0";
private static final String GET_MANUFACTURER = "AT+CGMI";
public static String handleCommand(String command) {

if (command.equals(ECHO_OFF)) {
   return REPLY_OK;
} else if (command.equals(GET_MANUFACTURER)) {
   return REPLY_MANUFACTURER;
}
// base case
return REPLY_OK;
}
// bts is a BluetoothSocket instance
OutputStream out = this.bts.getOutputStream();
InputStream is = this.bts.getInputStream();
InputStreamReader isr  = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String currentLine = null;
while ((currentLine = br.readLine()) != null) {
    Log.d(LOGTAG, "From Device:" +  currentLine);
    String response = handleCommand(currentLine);
    Log.d(LOGTAG, "To Device: " + response);
    out.write(response.getBytes("ASCII"));
    //out.flush();
}

1 个答案:

答案 0 :(得分:0)

如何扭转局面并使用Android设备模拟传统的硬件设备,连接到传统的蓝牙手机,并做一个完全由手机提供的内容的hexdump?

或许你甚至可以使用Android手机制作一种中间人代理并记录和整合交换?