lizhanwei
2020-02-14 4e307b0d89c9a84916bbbc2119e41d34c6badc13
app/src/main/java/safeluck/drive/evaluation/bean/RegisterMessage.java
@@ -1,5 +1,12 @@
package safeluck.drive.evaluation.bean;
import android.text.TextUtils;
import com.anyun.im_lib.util.ByteUtil;
import static com.anyun.im_lib.util.ByteUtil.shortGetBytes;
/**
 * 注册消息
 * MyApplication2
@@ -9,7 +16,42 @@
 */
public class RegisterMessage extends DriveExamProtocol {
    private static final int BODY_LENGTH = 2;
    /**
     * 1.1.1   终端注册
     * 消息ID:0x0100。
     * 起始字节
     * 字段
     * 数据类型
     * 描述及要求
     * 0
     * 省域ID
     * WORD
     * 终端所在地省ID
     * 2
     * 市县域ID
     * WORD
     * 终端所在地市ID
     * 4
     * 终端型号
     * BYTE[20]
     * 20个字节,此终端型号由制造商自行定义,位数不足20位的,后补“0X00”
     * 24
     * 终端出厂序列号
     * BYTE[8]
     * 8个字节,由大写字母和数字组成,此终端ID由制造商自行定义,位数不足时,后补“0X00”
     * 32
     * IMEI
     * BYTE[15]
     * 国际移动设备标识,ASCII码
     */
    private static final int BODY_LENGTH = 55;
    private short proviceId;
    private short cityid;
    private String model;//终端型号
    private String sn;//出厂序列号
    private String imei;//
    /**
     * 构造函数
     *
@@ -17,6 +59,50 @@
     */
    public RegisterMessage(short msg_id) {
        super(msg_id);
    }
    public static int getBodyLength() {
        return BODY_LENGTH;
    }
    public short getProviceId() {
        return proviceId;
    }
    public void setProviceId(short proviceId) {
        this.proviceId = proviceId;
    }
    public short getCityid() {
        return cityid;
    }
    public void setCityid(short cityid) {
        this.cityid = cityid;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
    public String getSn() {
        return sn;
    }
    public void setSn(String sn) {
        this.sn = sn;
    }
    public String getImei() {
        return imei;
    }
    public void setImei(String imei) {
        this.imei = imei;
    }
    @Override
@@ -27,9 +113,30 @@
    @Override
    protected byte[] createMessageBody() {
        int pos = 0;
        byte[] messageBody = new byte[BODY_LENGTH];
        messageBody[0] = 0x65;
        messageBody[1] = 0x67;
        //省域ID
        byte[] provinceIdBytes = ByteUtil.shortGetBytes(proviceId);
        System.arraycopy(provinceIdBytes,0,messageBody,pos,provinceIdBytes.length);
        pos += provinceIdBytes.length;
        //市域ID
        byte[] cityIdBytes = ByteUtil.shortGetBytes(cityid);
        System.arraycopy(cityIdBytes,0,messageBody,pos,cityIdBytes.length);
        pos += cityIdBytes.length;
        //model
        byte[] modelBytes = !TextUtils.isEmpty(model)?model.getBytes():"".getBytes();
        System.arraycopy(modelBytes,0,messageBody,pos,modelBytes.length);
        pos += 20;
        //sn
        byte[] snBytes = !TextUtils.isEmpty(sn)?sn.getBytes():"".getBytes();
        System.arraycopy(snBytes,0,messageBody,pos,snBytes.length);
        pos += 16;
        //IMEI
        byte[] imeiBytes = !TextUtils.isEmpty(imei)?imei.getBytes():"".getBytes();
        System.arraycopy(imeiBytes,0,messageBody,pos,imeiBytes.length);
        return messageBody;
    }
}