0

This one really has me banging my head. I'm sending alphanumeric data from an Android app, through the BluetoothChatService, to a serial bluetooth adaptor connected to the serial input of a radio transceiver.

Everything works fine except when I try to configure the radio on-the-fly with its AT-commands. The AT+++ (enter command mode) is received OK, but the problem comes with the extended-ascii characters in the next two commands: Changing the radio destination address (which is what I'm trying to do) requires CCh 10h (plus 3 hex radio address bytes), and exiting the command mode requires CCh ATO.

I know the radio can be configured OK because I've done it on an earlier prototype with the serial commands from PIC basic, and it also can be configured by entering the commands directly from hyperterm. Both these methods somehow convert that pesky CCh into a form the radio understands.

I've have tried just about everything an Android noob could possibly come up with to finagle the encoding such as:

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

but no matter what, I can't seem to get that high-order byte (CCh/204/-52) to behave as it should. All other (< 127) bytes, command or data, transmit with no problem. Any help here would be greatly appreciated.

-Dave

dsolimano
  • 8,870
  • 3
  • 48
  • 63
softex
  • 11
  • 1
  • 5

1 Answers1

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

Community
  • 1
  • 1
softex
  • 11
  • 1
  • 5