📄 at_cgatt.java
字号:
package com.jzl.sirius.at.command;
import java.nio.CharBuffer;
import com.jzl.sirius.at.ATConstants;
import com.jzl.sirius.at.util.StringMatch;
import com.jzl.sirius.at.util.StringUtils;
/**
* @author xujian
* @version 2.0
* @see com.jzl.sirius.at.ATCommand
* @see com.jzl.sirius.at.command.ATCommandBase
*/
public class AT_CGATT extends ATCommandBase {
private int commandType;
private StringBuffer command = new StringBuffer();
private int state = -1;
private String supportedStates = "";
/**
* 构造函数 提供"AT+CGATT?"的AT命令
*/
public AT_CGATT() {
this(false);
}
/**
* 构造函数 提供"AT+CGATT=?"的AT命令或"AT+CGATT?"的AT命令
*
* @param tested
* 当为true时提供"AT+CGATT=?"的AT命令,当为false时提供"AT+CGATT?"的AT命令。
*/
public AT_CGATT(boolean tested) {
super(new StringMatch(ATConstants.CRLF + "+CGATT:"));
commandType = tested ? COMMAND_TYPE_TEST : COMMAND_TYPE_READ;
command.append(tested ? "AT+CGATT=?" : "AT+CGATT?");
command.append(ATConstants.CR);
}
/**
* 构造函数 提供"AT+CGATT=int"的AT命令
*
* @param state
* state of GPRS attachment ,0 detached ,1 attached ,2 combined
* detach (GPRS and GSM detach in the same network request)
*/
public AT_CGATT(int state) {
commandType = COMMAND_TYPE_ACTION;
command.append("AT+CGATT=");
command.append(state);
command.append(ATConstants.CR);
}
public String buildCommand() {
return command.toString();
}
protected void decodeOkResponse(CharBuffer response) {
String str = response.toString();
try {
if (commandType == COMMAND_TYPE_READ) {
// format:<CR><LF>+CGATT: <state><CR><LF><CR><LF>OK<CR><LF>
str = StringUtils.substring(str, "+CGATT:", ATConstants.CRLF).trim();
state = Integer.parseInt(str);
} else if (commandType == COMMAND_TYPE_TEST) {
// format:<CR><LF>+CGATT: (list of supported <state>s)<CR><LF><CR><LF>OK<CR><LF>
supportedStates = StringUtils.substring(str, "+CGATT:", ATConstants.CRLF).trim();
}
}
catch(Exception ex) {
}
}
/**
* 取得设备的state of GPRS attachment
*
* @return 返回设备的state of GPRS attachment
*/
public int getState() {
return state;
}
/**
* 取得设备支持的state of GPRS attachment
*
* @return 返回设备支持的state of GPRS attachment
*/
public String getSupportedStates() {
return supportedStates;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -