📄 at_cgdcont.java
字号:
package com.jzl.sirius.at.command;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import com.jzl.sirius.at.ATConstants;
/**
* @author xujian
* @version 2.0
* @see com.jzl.sirius.at.ATCommand
* @see com.jzl.sirius.at.command.ATCommandBase
*/
public class AT_CGDCONT extends ATCommandBase {
private int commandType;
private StringBuffer command = new StringBuffer();
private String[] PDPContexts = new String[0];
private String[] supportedPDPContexts = new String[0];
/**
* 构造函数 提供"AT+CGDCONT?"的AT命令
*/
public AT_CGDCONT() {
this(false);
}
/**
* 构造函数 提供"AT+CGDCONT=?"的AT命令或"AT+CGDCONT?"的AT命令
*
* @param tested
* 当为true时提供"AT+CGDCONT=?"的AT命令,当为false时提供"AT+CGDCONT?"的AT命令。
*/
public AT_CGDCONT(boolean tested) {
commandType = tested ? COMMAND_TYPE_TEST : COMMAND_TYPE_READ;
command.append(tested ? "AT+CGDCONT=?" : "AT+CGDCONT?");
command.append(ATConstants.CR);
}
/**
* 构造函数 提供"AT+CGDCONT=int"的AT命令
*
* @param cid
* PDP context identifier,range: 1-4
*/
public AT_CGDCONT(int cid) {
command.append("AT+CGDCONT=");
command.append(cid);
command.append(ATConstants.CR);
}
/**
* 构造函数 提供"AT+CGDCONT=int,str"的AT命令
*
* @param cid
* PDP context identifier,range: 1-4
* @param pdpType
* type of packet data protocol,"IP" Internet Protocol (IETF STD
* 5),"PPP" Point to Point Protocol (IETF STD 51)
*/
public AT_CGDCONT(int cid, String pdpType) {
command.append("AT+CGDCONT=");
command.append(cid);
command.append(",\"");
command.append(pdpType);
command.append("\"");
command.append(ATConstants.CR);
}
/**
* 构造函数 提供"AT+CGDCONT=int,str,str"的AT命令
*
* @param cid
* PDP context identifier,range: 1-4
* @param pdpType
* type of packet data protocol,"IP" Internet Protocol (IETF STD
* 5),"PPP" Point to Point Protocol (IETF STD 51)
* @param apn
* access point name: logical name that is used to select the
* GGSN or the external packet data network.
*/
public AT_CGDCONT(int cid, String pdpType, String apn) {
command.append("AT+CGDCONT=");
command.append(cid);
command.append(",\"");
command.append(pdpType);
command.append("\",\"");
command.append(apn);
command.append("\"");
command.append(ATConstants.CR);
}
/**
* 构造函数 提供"AT+CGDCONT=int,str,str,str"的AT命令
*
* @param cid
* PDP context identifier,range: 1-4
* @param pdpType
* type of packet data protocol,"IP" Internet Protocol (IETF STD
* 5),"PPP" Point to Point Protocol (IETF STD 51)
* @param apn
* access point name: logical name that is used to select the
* GGSN or the external packet data network.
* @param pdpAddr
* PDP address: identifies the MT in the address space applicable
* to the PDP
*/
public AT_CGDCONT(int cid, String pdpType, String apn, String pdpAddr) {
command.append("AT+CGDCONT=");
command.append(cid);
command.append(",\"");
command.append(pdpType);
command.append("\",\"");
command.append(apn);
command.append("\",\"");
command.append(pdpAddr);
command.append("\"");
command.append(ATConstants.CR);
}
/**
* 构造函数 提供"AT+CGDCONT=int,str,str,str,int"的AT命令
*
* @param cid
* PDP context identifier,range: 1-4
* @param pdpType
* type of packet data protocol,"IP" Internet Protocol (IETF STD
* 5),"PPP" Point to Point Protocol (IETF STD 51)
* @param apn
* access point name: logical name that is used to select the
* GGSN or the external packet data network.
* @param pdpAddr
* PDP address: identifies the MT in the address space applicable
* to the PDP
* @param dcomp
* PDP data compression mode,0 OFF (default value),1 ON
*/
public AT_CGDCONT(int cid, String pdpType, String apn, String pdpAddr, int dcomp) {
command.append("AT+CGDCONT=");
command.append(cid);
command.append(",\"");
command.append(pdpType);
command.append("\",\"");
command.append(apn);
command.append("\",\"");
command.append(pdpAddr);
command.append("\",");
command.append(dcomp);
command.append(ATConstants.CR);
}
/**
* 构造函数 提供"AT+CGDCONT=int,str,str,str,int,int"的AT命令
*
* @param cid
* PDP context identifier,range: 1-4
* @param pdpType
* type of packet data protocol,"IP" Internet Protocol (IETF STD
* 5),"PPP" Point to Point Protocol (IETF STD 51)
* @param apn
* access point name: logical name that is used to select the
* GGSN or the external packet data network.
* @param pdpAddr
* PDP address: identifies the MT in the address space applicable
* to the PDP
* @param dcomp
* PDP data compression mode,0 OFF (default value),1 ON
* @param hcomp
* PDP header compression mode,0 OFF (default value),1 ON
*/
public AT_CGDCONT(int cid, String pdpType, String apn, String pdpAddr, int dcomp, int hcomp) {
command.append("AT+CGDCONT=");
command.append(cid);
command.append(",\"");
command.append(pdpType);
command.append("\",\"");
command.append(apn);
command.append("\",\"");
command.append(pdpAddr);
command.append("\",");
command.append(dcomp);
command.append(",");
command.append(hcomp);
command.append(ATConstants.CR);
}
public String buildCommand() {
return command.toString();
}
private List<String> decodeCGDCONT(String str) {
String startToken = ATConstants.CRLF + "+CGDCONT:";
ArrayList<String> results = new ArrayList<String>();
while(true) {
int pos = str.indexOf(startToken);
if (pos == -1)
break;
str = str.substring(pos + startToken.length());
pos = str.indexOf(ATConstants.CRLF);
if (pos == -1)
break;
String result = str.substring(0, pos).trim();
results.add(result);
str = str.substring(pos);
}
return results;
}
protected void decodeOkResponse(CharBuffer response) {
String str = response.toString();
try {
if (commandType == COMMAND_TYPE_READ) {
// format:<CR><LF>+CGDCONT:
// <cid>,<PDP_type>,<APN>,<PDP_addr>,<d_comp>,<h_comp><CR><LF><CR><LF>
// [+CGDCONT:
// <cid>,<PDP_type>,<APN>,<PDP_addr>,<d_comp>,<h_comp>
// […]]
// <CR><LF><CR><LF>OK<CR><LF>
PDPContexts = (String[])decodeCGDCONT(str).toArray(new String[0]);
} else if (commandType == COMMAND_TYPE_TEST) {
// format:<CR><LF>+CGDCONT: (list of supported
// <cid>s),<PDP_type>,,,(list of
// supported <d_comp>s),(list of supported <h_comp>s)
// [+CGDCONT: (list of supported <cid>s),<PDP_type>,,,(list of
// supported <d_comp>s),(list of supported <h_comp>s)
// […]]
// <CR><LF><CR><LF>OK<CR><LF>
supportedPDPContexts = (String[])decodeCGDCONT(str).toArray(new String[0]);;
}
}
catch(Exception ex) {
}
}
/**
* 取得设备的当前的“PDP Context”值,返回值的类型为String[],其中每一个元素的值的格式为:<br>
* cid,PDP_type,APN,PDP_addr,d_comp,h_comp
*
* @return 取得设备的当前的“PDP Context”值
*/
public String[] getPDPContexts() {
return PDPContexts;
}
/**
* 取得设备所支持的“PDP Context”值,返回值的类型为String[],其中每一个元素的值的格式为:<br>
* supported cids,supported PDP_types,supported APNs,supported
* PDP_addrs,supported d_comp,h_comps
*
* @return 取得设备所支持的“PDP Context”值
*/
public String[] getSupportedPDPContexts() {
return supportedPDPContexts;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -