image.png
image.png
抽取方法
抽取这个方法可以处理所有指令AT + (指令名)+(状态)+(名称描述)+ (CS)+ (YZ)
private byte[] EnCodeData(String cmd,String Data){
byte [] buffer;
try {
byte [] bdata = Data.getBytes("gbk");
byte [] bcmd =cmd.getBytes();
int size =bcmd.length+bdata.length+6;
buffer =new byte [size];
int i=0;
int sum=0;
buffer[i]='A';
buffer[++i]='T';
for(int m=0;m<bcmd.length;m++){
buffer[++i]=bcmd[m];
}
for(byte b :bdata){
buffer[++i]=b;
}
for(int m=2;m<=i;m++){
sum =sum +(buffer[m]&0xFF);
}
byte[] Cs =getCS(sum);
buffer[++i]=Cs[0];
buffer[++i]=Cs[1];
buffer[++i]='Y';
buffer[++i]='Z';
return buffer;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return new byte[0];
}
比如要发送第二条指令
void second(String name,double balance) {
String nameAndBalance = "h1"+name+"+"+balance;
addLastAnsTask(new picTask(EnCodeData("h","1"+nameAndBalance)));
}
网友评论