手机 AT 命令集模拟器:响应代码的正确语法

发布于 2024-09-27 14:36:04 字数 3562 浏览 2 评论 0原文

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

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();
}

we've got some legacy hardware which connects to cell phones over Bluetooth using the DUN profile. It then issues AT commands to read SMS for monitoring purposes.

Android phones do not support AT over DUN. That's why I'm writing this application. The problem is: while the legacy hardware will connect to the phone, it will not accept my responses to its commands. Specifically, it seems not to accept my answer to the AT+CGMI command. I assume there is something wrong with my usage of the CR and LF control characters, but I can't figure out what's going on.

Here's an example chat log:

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)

The exception happens as the device resets the connection.

Here's some code:

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();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

り繁华旳梦境 2024-10-04 14:36:04

如何扭转局面,使用 Android 设备模拟传统硬件设备,连接到传统蓝牙手机,并对手机给出的响应进行十六进制转储?

或者您甚至可以使用 Android 手机制作一种中间人代理并记录和十六进制转储整个交换?

How about turning things around and using the android device to emulate the legacy hardware device, connect to a legacy bluetooth phone, and do a hexdump of exactly what that phone gives in response?

Or maybe you could even use the android phone to make a sort of man-in-the-middle proxy and record and hexdump the whole exchange?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文