| | |
| | | //标识位 |
| | | private byte MESSAGE_TAIL = 0x7e; |
| | | //校验码 先暂时写死 |
| | | private int checkCode = 0x78; |
| | | private byte checkCode = 0x78; |
| | | |
| | | |
| | | /***===========以下是消息头=============***/ |
| | |
| | | //消息体属性 |
| | | private int msg_property; |
| | | |
| | | //终端手机号 |
| | | private String phoneOnTerminal; |
| | | //终端手机号 字符串长度必须为16 |
| | | private String phoneOnTerminal = "0008618513021245"; |
| | | //13 消息流水号 WORD 按发送顺序从0开始循环累加 |
| | | public static short msg_serial_num=0; |
| | | |
| | |
| | | //标识位 |
| | | desBytes[pos] = MESSAGE_HEAD; |
| | | pos++; |
| | | |
| | | |
| | | //协议版本号 |
| | | byte[] protoVersion = ByteUtil.shortGetByte(protocol_version); |
| | | System.arraycopy(protoVersion,0,desBytes,pos,protoVersion.length); |
| | | pos +=protoVersion.length; |
| | | |
| | | //消息ID |
| | | //消息ID |
| | | byte[] msgIdBytes = ByteUtil.shortGetBytes(msg_id); |
| | | System.arraycopy(msgIdBytes,0,desBytes,pos,msgIdBytes.length); |
| | | pos+=msgIdBytes.length; |
| | | |
| | | //消息体属性 |
| | | //消息体属性 |
| | | byte[] msg_pro_bytes = ByteUtil.shortGetBytes((short)2); |
| | | System.arraycopy(msg_pro_bytes,0,desBytes,pos,msg_pro_bytes.length); |
| | | pos+=msg_pro_bytes.length; |
| | | //终端手机号 |
| | | byte[] phoneBytes = ByteUtil.str2Bcd("1234567890121518"); |
| | | byte[] phoneBytes = ByteUtil.str2Bcd(phoneOnTerminal); |
| | | System.arraycopy(phoneBytes,0,desBytes,pos,phoneBytes.length); |
| | | pos+=phoneBytes.length; |
| | | //消息流水号 |
| | | //消息流水号 |
| | | byte[] msg_serialNum = ByteUtil.shortGetBytes(msg_serial_num++); |
| | | System.arraycopy(msg_serialNum,0,desBytes,pos,msg_serialNum.length); |
| | | pos+=msg_serialNum.length; |
| | | //保留 |
| | | //保留 |
| | | desBytes[pos] = 0; |
| | | pos++; |
| | | |
| | |
| | | pos+=messageBodyBytes.length; |
| | | |
| | | //校验码 |
| | | desBytes[pos] = 0x01; |
| | | // TODO: 2019/12/18 校验码需要计算 还有转义需要处理 |
| | | desBytes[pos] = checkCode; |
| | | pos++; |
| | | //末尾结束标识位 |
| | | desBytes[pos] = MESSAGE_TAIL; |
| | | |
| | | Log.i(TAG, "包长度="+(pos+1)); |
| | | Log.i(TAG, "包内容: "+ByteUtil.byte2HexStr(desBytes)); |
| | | |
| | | return desBytes; |
| | | } |
| | | |