AtCommandResultpublic class AtCommandResult extends Object The result of execution of an single AT command.
This class can represent the final response to an AT command line, and also
intermediate responses to a single command within a chained AT command
line.
The actual responses that are intended to be send in reply to the AT command
line are stored in a string array. The final response is stored as an
int enum, converted to a string when toString() is called. Only a single
final response is sent from multiple commands chained into a single command
line. |
Fields Summary |
---|
public static final int | OK | public static final int | ERROR | public static final int | UNSOLICITED | private static final String | OK_STRING | private static final String | ERROR_STRING | private int | mResultCode | private StringBuilder | mResponse |
Constructors Summary |
---|
public AtCommandResult(int resultCode)Construct a new AtCommandResult with given result code, and an empty
response array. // Response with CRLF line breaks
mResultCode = resultCode;
mResponse = new StringBuilder();
| public AtCommandResult(String response)Construct a new AtCommandResult with result code OK, and the specified
single line response.
this(OK);
addResponse(response);
|
Methods Summary |
---|
public void | addResponse(java.lang.String response)Add another line to the response.
appendWithCrlf(mResponse, response);
| public void | addResult(android.bluetooth.AtCommandResult result)Add the given result into this AtCommandResult object.
Used to combine results from multiple commands in a single command line
(command chaining).
if (result != null) {
appendWithCrlf(mResponse, result.mResponse.toString());
mResultCode = result.mResultCode;
}
| public static void | appendWithCrlf(java.lang.StringBuilder str1, java.lang.String str2)Append a string to a string builder, joining with a double
CRLF. Used to create multi-line AT command replies
if (str1.length() > 0 && str2.length() > 0) {
str1.append("\r\n\r\n");
}
str1.append(str2);
| public int | getResultCode()
return mResultCode;
| public java.lang.String | toString()Generate the string response ready to send
StringBuilder result = new StringBuilder(mResponse.toString());
switch (mResultCode) {
case OK:
appendWithCrlf(result, OK_STRING);
break;
case ERROR:
appendWithCrlf(result, ERROR_STRING);
break;
}
return result.toString();
|
|