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

📄 at_cnmi.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;

/**
 * @author xujian
 * @version 2.0
 * @see com.jzl.sirius.at.ATCommand
 * @see com.jzl.sirius.at.command.ATCommandBase
 */
public class AT_CNMI extends ATCommandBase {

	private int commandType;
	private StringBuffer command = new StringBuffer();

	private int mode = -1;
	private int mt   = -1;
	private int bm   = -1;
	private int ds   = -1;
	private int bfr  = -1;

	private String supportedModes;

    /**
     * 构造函数 提供"AT+CNMI?"的AT命令
     */
    public AT_CNMI() {
        this(false);
    }

    /**
     * 构造函数 提供"AT+CNMI=?"的AT命令或"AT+CNMI?"的AT命令
     * 
     * @param tested
     *            当为true时提供"AT+CNMI=?"的AT命令,当为false时提供"AT+CNMI?"的AT命令。
     */
    public AT_CNMI(boolean tested) {
        super(new StringMatch(ATConstants.CRLF + "+CNMI:"));
        commandType = tested ? COMMAND_TYPE_TEST : COMMAND_TYPE_READ;
        command.append(tested ? "AT+CNMI=?" : "AT+CNMI?");
        command.append(ATConstants.CR);
    }

    /**
     * 构造函数 提供"AT+CNMI=int,int,int,int,int"的AT命令
     * @param mode processing of unsolicited result codes (see note below),值可能为以下的一种:<br>
     * 1. 0 same processing as mode=2<br>
     * 2. 1 same processing as mode=2<br>
     * 3. 2 Buffer unsolicited result codes in the TA when TA-TE link is reserved and flush them to the TE after reservation.Otherwise forward them directly to the TE.<br>
     * 4. 3 same processing as mode=2<br>
     * @param mt result code indication routing for SMS-DELIVER indications
     * 1. 0 no SMS-DELIVER indications are routed<br>
     * 2. 1 SMS-DELIVERs are routed using unsolicited code +CMTI (default value)<br>
     * 3. 2 SMS-DELIVERs (except class 2 messages) are routed using unsolicited code +CMT<br>
     * 4. 3 Class 3 SMS-DELIVERS are routed directly using code in mt=2 .Other classes messages result in indication mt=1.<br>
     * @param bm rules for storing the received CBMs (Cell Broadcast Message) types,值可能是:<br>
     * 1. 0 no CBM indications are routed to the TE (default value).The CBMs are stored.<br>
     * 2. 1 The CBM is stored and an indication of the memory location is routed to the customer application using unsolicited result code +CBMI.<br>
     * 3. 2 New CBMs are routed directly to the TE using unsolicited result code +CBM.<br>
     * 4. 3 Class 3 CBMs: as bm=2.Other classes CBMs: as bm=1.<br>
     * @param ds SMS-STATUS-REPORTs routing,值可能是:<br>
     * 1. 0 no SMS-STATUS-REPORTs are routed (default value)<br>
     * 2. 1 SMS-STATUS-REPORTs are routed using unsolicited code +CDS.<br>
     * 3. 2 SMS-STATUS-REPORTs are stored<br>
     * @param bfr TA buffer of unsolicited result codes mode,值可能是:<br>
     * 1. 0 TA buffer defined within this command is flushed to the TE when <mode> = 1 to 3 is entered (OK response shall be given before flushing the codes).Default value.<br>
     * 2. 1 TA buffer of unsolicited result codes defined within this command is cleared when <mode> 1…3 is entered.<br>
     */
    public AT_CNMI(int mode, int mt, int bm, int ds, int bfr) {
        commandType = COMMAND_TYPE_ACTION;
        command.append("AT+CNMI=");
        command.append(mode);
        command.append(",");
        command.append(mt);
        command.append(",");
        command.append(bm);
        command.append(",");
        command.append(ds);
        command.append(",");
        command.append(bfr);
        
        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>+CNMI: <mode>,<mt>,<bm>,<ds>,<bfr><CR><LF><CR><LF>OK<CR><LF>
                str = StringUtils.substring(str, "+CNMI:", ATConstants.CRLF).trim();
                
                String[] arry = str.split(",");
                mode = Integer.parseInt(arry[0].trim());
                mt   = Integer.parseInt(arry[1].trim());
                bm   = Integer.parseInt(arry[2].trim());
                ds   = Integer.parseInt(arry[3].trim());
                bfr  = Integer.parseInt(arry[4].trim());
            } else if (commandType == COMMAND_TYPE_TEST) {
                // format:<CR><LF>+CNMI: (list of supported <mode>s),(list of supported <mt>s),(list of supported <bm>s),(list of supported <ds>s),(list of supported <bfr>s)<CR><LF><CR><LF>OK<CR><LF>
                supportedModes = StringUtils.substring(str, "+CNMI:", ATConstants.CRLF).trim();
            }
        }
        catch(Exception ex) {
            
        }
    }
    
    
	/**
	 * 取得设备的processing of unsolicited result codes (see note below),值可能为以下的一种:<br>
	 * 1. 0 same processing as mode=2<br>
	 * 2. 1 same processing as mode=2<br>
	 * 3. 2 Buffer unsolicited result codes in the TA when TA-TE link is reserved and flush them to the TE after reservation.Otherwise forward them directly to the TE.<br>
	 * 4. 3 same processing as mode=2<br>
	 * @return 返回设备的processing of unsolicited result codes (see note below)
	 */
	public int getMode() {
		return mode;
	}

	/**
	 * 取得设备的result code indication routing for SMS-DELIVER indications,值可能为以下的一种:<br>
	 * 1. 0 no SMS-DELIVER indications are routed<br>
	 * 2. 1 SMS-DELIVERs are routed using unsolicited code +CMTI (default value)<br>
	 * 3. 2 SMS-DELIVERs (except class 2 messages) are routed using unsolicited code +CMT<br>
	 * 4. 3 Class 3 SMS-DELIVERS are routed directly using code in mt=2 .Other classes messages result in indication mt=1.<br>
	 * @return 返回设备的result code indication routing for SMS-DELIVER indications<br>
	 */
	public int getMt() {
		return mt;
	}

	/**
	 * 取得设备的rules for storing the received CBMs (Cell Broadcast Message) types,值可能是:<br>
	 * 1. 0 no CBM indications are routed to the TE (default value).The CBMs are stored.<br>
	 * 2. 1 The CBM is stored and an indication of the memory location is routed to the customer application using unsolicited result code +CBMI.<br>
	 * 3. 2 New CBMs are routed directly to the TE using unsolicited result code +CBM.<br>
	 * 4. 3 Class 3 CBMs: as bm=2.Other classes CBMs: as bm=1.<br>
	 * @return 返回设备的rules for storing the received CBMs (Cell Broadcast Message) types
	 */
	public int getBm() {
		return bm;
	}

	/**
	 * 取得设备的SMS-STATUS-REPORTs routing,值可能是:<br>
	 * 1. 0 no SMS-STATUS-REPORTs are routed (default value)<br>
	 * 2. 1 SMS-STATUS-REPORTs are routed using unsolicited code +CDS.<br>
	 * 3. 2 SMS-STATUS-REPORTs are stored<br>
	 * @return 返回设备的SMS-STATUS-REPORTs routing
	 */
	public int getDs() {
		return ds;
	}

	/**
	 * 取得设备的TA buffer of unsolicited result codes mode,值可能是:<br>
	 * 1. 0 TA buffer defined within this command is flushed to the TE when <mode> = 1 to 3 is entered (OK response shall be given before flushing the codes).Default value.<br>
	 * 2. 1 TA buffer of unsolicited result codes defined within this command is cleared when <mode> 1…3 is entered.<br>
	 * @return 返回设备的TA buffer of unsolicited result codes mode
	 */
	public int getBfr() {
		return bfr;
	}
	
	/**
	 * 取得设备支持的processing of unsolicited result codes (see note below)
	 * @return 返回设备支持的processing of unsolicited result codes (see note below)
	 */
	public String getSupportedModes(){
		return supportedModes;
	}
	

}

⌨️ 快捷键说明

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