⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 at_cgclass.java

📁 自己实现的基于串口通讯发送短消息的低层协议JAVA代码
💻 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;

/**
 * 
 * <p>用途:设置移动终端的类别</p>
 * <p>用法:</p>
 * <p>参照:<br />
 * GPRS Mobile Station Class +CGCLASS
 * 	<ul>
 * 		<li>Description</li>
 * 			<ul>
 * 				<li>This command is used to set the MT to operate according to the specified GPRS mobile class.</li>
 * 			</ul>
 * 		<li>Syntax</li>
 * 			<ul>
 * 				<li>Action command</li>
 * 					<ul>
 * 						<li>AT+CGCLASS=&lt;class&gt;</li>
 * 						<li>OK</li>
 * 					</ul>
 * 				<li>Read command</li>
 * 					<ul>
 * 						<li>AT+CGCLASS?</li>
 * 						<li>+CGCLASS: &lt;class&gt;</li>
 * 						<li>OK</li>
 * 					</ul>
 * 				<li>Test command</li>
 * 					<ul>
 * 						<li>AT+CGCLASS=?</li>
 * 						<li>+CGCLASS: (list of supported &lt;class&gt;s)</li>
 * 						<li>OK</li>
 * 					</ul>
 * 			</ul>
 * 		<li>Parameters and Defined Values</li>
 * 			<ul>
 * 				<li>&lt;class&gt;: GPRS mobile class (in descending order of functionality)</li>
 * 					<ul>
 * 						<li>"B" class B</li>
 * 						<li>"CG" class C in GPRS only mode</li>
 * 						<li>"CC" class C in circuit switched only mode (lowest)</li>
 * </p>
 * 
 * @author xujian
 * @version 2.0
 * @see com.jzl.sirius.at.ATCommand
 * @see com.jzl.sirius.at.command.ATCommandBase
 * 
 */
public class AT_CGCLASS extends ATCommandBase {

	private int commandType;
	private StringBuffer command = new StringBuffer();
	private String clazz;
	private String supportedClasses;

	public AT_CGCLASS() {
		this(false);
	}

	public AT_CGCLASS(boolean tested) {
        super(new StringMatch(ATConstants.CRLF + "+CGCLASS:"));
		commandType = tested ? COMMAND_TYPE_TEST : COMMAND_TYPE_READ;
		command.append(tested ? "AT+CGCLASS=?" : "AT+CGCLASS?");
		command.append(ATConstants.CR);
	}

	public AT_CGCLASS(String clazz) {
		commandType = COMMAND_TYPE_ACTION;
		command.append("AT+CGCLASS=\"");
        command.append(clazz);
        command.append("\"");
		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>+CGCLASS: <class><CR><LF><CR><LF>OK<CR><LF>
                clazz = StringUtils.substring(str, "+CGCLASS:", ATConstants.CRLF).trim();
                
            } else if (commandType == COMMAND_TYPE_TEST) {
                // format:<CR><LF>+CGCLASS: (list of supported <class>s)<CR><LF><CR><LF>OK<CR><LF>
                supportedClasses = StringUtils.substring(str, "+CGCLASS:", ATConstants.CRLF).trim();
            }
        }
        catch(Exception ex) {
            
        }
    }

	public String getClazz() {
		return clazz;
	}

	public String getSupportedClasses() {
		return supportedClasses;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -