at_cmgf.java
来自「自己实现的基于串口通讯发送短消息的低层协议JAVA代码」· Java 代码 · 共 74 行
JAVA
74 行
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_CMGF extends ATCommandBase {
private int commandType;
private StringBuffer command = new StringBuffer();
private int mode = ATConstants.SMS_FORMAT_TEXT;
private String supportedModes = "";
public AT_CMGF() {
this(false);
}
public AT_CMGF(boolean tested) {
commandType = tested ? COMMAND_TYPE_TEST : COMMAND_TYPE_READ;
command.append(tested ? "AT+CMGF=?" : "AT+CMGF?");
command.append(ATConstants.CR);
}
public AT_CMGF(int mode) {
commandType = COMMAND_TYPE_ACTION;
command.append("AT+CMGF=");
command.append(mode);
command.append(ATConstants.CR);
}
public String buildCommand() {
return command.toString();
}
protected void decodeOkResponse(CharBuffer response) {
if (commandType == COMMAND_TYPE_READ) {
// format:<CR><LF>+CMGF: <mode><CR><LF><CR><LF>OK<CR><LF>
String str = StringUtils.substring(response.toString(), "+CMGF:", ATConstants.CRLF).trim();
try {
mode = Integer.parseInt(str.trim());
}
catch(Exception ex) {
}
} else if (commandType == COMMAND_TYPE_TEST) {
supportedModes = StringUtils.substring(response.toString(), "+CMGF:", ATConstants.CRLF).trim();
}
}
public int getMode() {
return mode;
}
public String getSupportedModes() {
return supportedModes;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?