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

📄 at_cced.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_CCED extends ATCommandBase {
    
    private StringBuffer command = new StringBuffer();
    
    
    private int mode = 0;
    private int requestedDump = -1;
    
    private int rssi;
    private int ber;
    private String cced;
    
    public AT_CCED() {
        super(new StringMatch(ATConstants.CRLF + "+CSQ:"));
        command.append("AT+CCED=");
        command.append(mode);
        command.append(ATConstants.CR);
    }
    
    public  AT_CCED(int requestedDump) {
        super((requestedDump >= 8 && requestedDump < 16) ? new StringMatch(ATConstants.CRLF + "+CSQ:") : new StringMatch(ATConstants.CRLF + "+CCED:"));

        this.requestedDump = requestedDump;
        command.append("AT+CCED=");
        command.append(mode);
        command.append(",");
        command.append(requestedDump);
        command.append(ATConstants.CR);
    }
    
    public String buildCommand() {
        return command.toString();
    }

    protected void decodeOkResponse(CharBuffer response) {
        String str = response.toString();
        if (requestedDump == -1 || (requestedDump >= 8 && requestedDump < 16)) {
            decodeCSQ(str);
        }
        
        if (requestedDump != 8)
            decodeCCED(str);
    }
    
    private void decodeCSQ(String result) {
        String csqStr = StringUtils.substring(result, "+CSQ:", ATConstants.CRLF);
        if (csqStr == null || csqStr.trim().length() == 0)
            return;
        
        int index =  csqStr.indexOf(',');
        if (index != -1) {
            rssi = Integer.parseInt(csqStr.substring(0, index).trim());
            ber  = Integer.parseInt(csqStr.substring(index + 1).trim());
        }
    }
    
    private void decodeCCED(String result) {
        cced = StringUtils.substring(result, "+CCED:", ATConstants.CRLF).trim();
    }

    public int getBer() {
        return ber;
    }

    public String getCced() {
        return cced;
    }

    public int getRssi() {
        return rssi;
    }
}

⌨️ 快捷键说明

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