FileDocCategorySizeDatePackage
AtCommandResult.javaAPI DocAndroid 1.5 API3672Wed May 06 22:41:54 BST 2009android.bluetooth

AtCommandResult

public 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.

hide

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.

param
resultCode One of OK, ERROR or UNSOLICITED.

 // 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.

param
response The single line response.

        this(OK);
        addResponse(response);
    
Methods Summary
public voidaddResponse(java.lang.String response)
Add another line to the response.

        appendWithCrlf(mResponse, response);
    
public voidaddResult(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).

param
result The AtCommandResult to add to this result.

        if (result != null) {
            appendWithCrlf(mResponse, result.mResponse.toString());
            mResultCode = result.mResultCode;
        }
    
public static voidappendWithCrlf(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 intgetResultCode()

        return mResultCode;
    
public java.lang.StringtoString()
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();