0

这个真的让我很头疼。我正在通过 BluetoothChatService 从 Android 应用程序向连接到无线电收发器串行输入的串行蓝牙适配器发送字母数字数据。

一切正常,除非我尝试使用其 AT 命令即时配置无线电。AT+++(进入命令模式)接收正常,但问题在于接下来两个命令中的扩展 ascii 字符:更改无线电目标地址(这是我正在尝试做的)需要 CCh 10h(加 3 hex无线电地址字节),退出命令模式需要 CCh ATO。

我知道收音机可以配置好,因为我已经在早期的原型上使用 PIC basic 的串行命令完成了它,也可以通过直接从 hyperterm 输入命令来配置它。这两种方法都以某种方式将讨厌的 CCh 转换为无线电可以理解的形式。

我已经尝试了 Android noob 可能想出的所有方法来解决编码问题,例如:

private void command_address() {
    byte[] addrArray = {(byte) 0xCC, 16, 36, 65, 21, 13};                   
    CharSequence addrvalues = EncodingUtils.getString(addrArray, "UTF-8");  
    sendMessage((String) addrvalues);
}

但无论如何,我似乎无法让那个高位字节(CCh/204/-52)发挥应有的作用。所有其他 (< 127) 字节、命令或数据都可以毫无问题地传输。在这里的任何帮助将不胜感激。

-戴夫

4

1 回答 1

0

Welll ... turns out the BluetoothChat code re-creates the byte array with message.getBytes() before sending to the service. (after all, being chat code it would normally source only regular ascii strings) As others on this site have pointed out, getBytes() can create encoding issues in some cases. So, for purposes of sending these extended-ascii commands, I don't mess with strings and just send the byte array to the service with

private void sendCommand(byte[] cmd) {
    mChatService.write(cmd);
}

The so-called command array is first initialized with placeholders for the hex radio address elements

byte[] addrArray = {(byte) 0xCC, 16, 0, 0, 0, 13};

and then filled in with the help of the conversion method

radioArray = HexStringToByteArray(radioAddr1);

which can be found here: HexStringToByteArray@stackoverflow

于 2011-01-11T15:41:08.260 回答