📄 at_creg.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_CREG extends ATCommandBase {
private int commandType;
private StringBuffer command = new StringBuffer();
private int mode = -1;
private int stat;
private String lac;
private String cid;
private String rejectCause;
private String supportedModes = "";
public AT_CREG() {
this(false);
}
public AT_CREG(boolean tested) {
super(new StringMatch(ATConstants.CRLF + "+CREG:"));
commandType = tested ? COMMAND_TYPE_TEST : COMMAND_TYPE_READ;
command.append(tested ? "AT+CREG=?" : "AT+CREG?");
command.append(ATConstants.CR);
}
public AT_CREG(int mode) {
commandType = COMMAND_TYPE_ACTION;
command.append("AT+CREG=");
command.append(mode);
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>+CREG: <mode>,<stat>[,<lac>,<cid>]<CR><LF><CR><LF>OK<CR><LF>
str = StringUtils.substring(str, "+CREG:", ATConstants.CRLF);
if (str == null || str.trim().length() == 0)
return;
String[] arry = str.split(",");
mode = Integer.parseInt(arry[0].trim());
stat = Integer.parseInt(arry[1].trim());
if (mode == 3) {
if (arry.length == 3)
rejectCause = arry[2];
} else {
if (arry.length == 4) {
lac = arry[2];
cid = arry[3];
}
}
} else if (commandType == COMMAND_TYPE_TEST) {
supportedModes = StringUtils.substring(str, "+CREG:", ATConstants.CRLF);
}
}
catch(Exception ex) {
ex.printStackTrace();
}
}
public String getSupportedModes() {
return supportedModes;
}
public String getCid() {
return cid;
}
public String getLac() {
return lac;
}
public int getMode() {
return mode;
}
public String getRejectCause() {
return rejectCause;
}
public int getStat() {
return stat;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -