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

📄 at_cmgr.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.StringUtils;

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

	private StringBuffer command = new StringBuffer();
	
    private int mode = ATConstants.SMS_FORMAT_PDU;
    private int smsType;
    
    private int stat;
    private int alpha;
    private int length;
	private String pdu = "";
    
    private String data = "";
    
    
    /**
     * 构造函数 提供"AT+CMGR=int"的AT命令,读取索引处的SMS
     * @param intIndex 要读取的SMS的存储地址的索引值
     */
    public AT_CMGR(int index) {
        command.append("AT+CMGR=");
        command.append(index);
        command.append(ATConstants.CR);
        
    }
    
    public AT_CMGR(int smsType ,int index) {
        this.smsType = smsType;
        mode = ATConstants.SMS_FORMAT_TEXT;
        command.append("AT+CMGR=");
        command.append(index);
        command.append(ATConstants.CR);
        
    }

    public String buildCommand() {
        return command.toString();
    }
    
    protected void decodeOkResponse(CharBuffer response) {
        String str = response.toString();
        if (mode == ATConstants.SMS_FORMAT_PDU){
            decodePdu(str);
        }
        else {
            if (smsType == ATConstants.SMS_TYPE_DELIVER) {
                
            }
            else if (smsType == ATConstants.SMS_TYPE_SUBMIT) {
                
            }
            else if (smsType == ATConstants.SMS_TYPE_STATUS_REPORT) {
                
            }
        }
    }
    
    private void decodePdu(String str) {
        str = StringUtils.substring(str, "+CMGR:", ATConstants.CRLF).trim();
        String[] arry = str.split(",");
        try {
            stat   = Integer.parseInt(arry[0].trim());
        }
        catch(Exception ex) {
        }
        
        try {
            alpha  = Integer.parseInt(arry[1].trim());
        }
        catch(Exception ex) {
        }
        
        try {
            length = Integer.parseInt(arry[2].trim());
        }
        catch(Exception ex) {
        }
        
        pdu = StringUtils.substring(str, ATConstants.CRLF + ATConstants.CRLF, ATConstants.CRLF).trim().trim();
    }

    public int getAlpha() {
        return alpha;
    }

    public String getData() {
        return data;
    }

    public int getLength() {
        return length;
    }

    public String getPdu() {
        return pdu;
    }

    public int getStat() {
        return stat;
    }
	
	

	

}

⌨️ 快捷键说明

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