📄 at_cfun.java
字号:
package com.jzl.sirius.at.command;
import java.nio.CharBuffer;
import com.jzl.sirius.at.ATConstants;
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_CFUN extends ATCommandBase {
private int commandType;
private StringBuffer command = new StringBuffer();
private int fun = -1;
private String supportedFuns = "";
/**
* 构造函数 提供"AT+CFUN?"的AT命令
*/
public AT_CFUN() {
this(false);
}
/**
* 构造函数 提供"AT+CFUN=?"的AT命令或"AT+CFUN?"的AT命令
*
* @param tested
* 当为true时提供"AT+CFUN=?"的AT命令,当为false时提供"AT+CFUN?"的AT命令。
*/
public AT_CFUN(boolean tested) {
commandType = tested ? COMMAND_TYPE_TEST : COMMAND_TYPE_READ;
command.append(tested ? "AT+CFUN=?" : "AT+CFUN?");
command.append(ATConstants.CR);
}
/**
* 构造函数 提供"AT+CFUN=intFun"的AT命令
* @param intFun functionality level,详细说明请见类说明。
*/
public AT_CFUN(int fun) {
commandType = COMMAND_TYPE_ACTION;
command.append("AT+CFUN=");
command.append(fun);
command.append(ATConstants.CR);
}
public String buildCommand() {
return command.toString();
}
protected void decodeOkResponse(CharBuffer response) {
if (commandType == COMMAND_TYPE_READ) {
// format:<CR><LF>+CFUN: <fun><CR><LF><CR><LF>OK<CR><LF>
String str = StringUtils.substring(response.toString(), "+CFUN:", ATConstants.CRLF).trim();
try {
fun = Integer.parseInt(str.trim());
}
catch(Exception ex) {
}
} else if (commandType == COMMAND_TYPE_TEST) {
// format:<CR><LF>+CFUN: (list of supported <fun>s),(list of supported <rst>s)<CR><LF><CR><LF>OK<CR><LF>
supportedFuns = StringUtils.substring(response.toString(), "+CFUN:", ATConstants.CRLF).trim();
}
}
/**
* 取得functionality level
* @return 返回functionality level,如果返回值是-1,则说明没有取到当前的functionality level值。
*/
public int getFun() {
return fun;
}
/**
* 取得支持的functionality level
* @return 返回支持的functionality level,如果返回值是的数组长度为0,则说明没有取到支持的functionality level值。
*/
public String getSupportedFuns() {
return supportedFuns;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -