package com.dy.testClient.httpCl;
|
|
import com.dy.common.mw.protocol.pMeterV1_0_1.ProtocolConstantV1_0_1;
|
import com.dy.common.util.ByteUtil;
|
import com.dy.common.util.ByteUtilUnsigned;
|
import com.dy.common.util.CreateRadom;
|
import com.dy.common.util.DateTime;
|
|
public class RtuData4MeterV1_0 {
|
public byte[] create(String imei) throws Exception{
|
/*
|
* 68
|
* 0051
|
* 01
|
* 0300000000000001
|
* 12233445566778
|
* 01
|
* 221128152107
|
* 0001E240
|
* 000004D2
|
* 24
|
* 0129
|
* 11
|
* 002D
|
* 0035
|
* 003D
|
* 006E
|
* 0038
|
* 00C3
|
* 00AC
|
* 004C
|
* 0028
|
* 0081
|
* 001B
|
* 005E
|
* 003D
|
* 0063
|
* 00AB
|
* 0071
|
* 00BB
|
* 0046
|
* 004A
|
* 009B
|
* 0087
|
* 00BE
|
* 0022
|
* 00B0
|
* DA
|
* 16
|
*/
|
int len = 89 ;
|
byte[] bs = new byte[len] ;
|
bs[0] = ProtocolConstantV1_0_1.P_Head_Byte ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, len, 1);//长度
|
bs[3] = (byte)101 ;//协议版本号
|
while(true){
|
if(imei.length() >= 16){
|
break ;
|
}else{
|
imei = "0" + imei ;
|
}
|
}
|
ByteUtil.string2BCD_BE(bs, imei, 4) ;//IMEI号
|
|
String meterNo = "" + (Long.valueOf(imei) + 1);
|
while(true){
|
if(meterNo.length() >= 16){
|
break ;
|
}else{
|
meterNo = "0" + meterNo ;
|
}
|
}
|
ByteUtil.string2BCD_BE(bs, meterNo, 12) ;//水表号
|
|
bs[20] = 1 ;//功能码
|
|
ByteUtil.string2BCD_BE(bs, DateTime.yyMMddhhmmss(), 21) ;//时间
|
|
ByteUtilUnsigned.int2Bytes_BE(bs, 123456, 27);//实时累计水量
|
|
ByteUtilUnsigned.int2Bytes_BE(bs, 54321, 31);//日累计水量
|
|
bs[35] = (byte)36;//电池电压
|
|
ByteUtilUnsigned.short2Bytes_BE(bs, 297, 36);//信号强度
|
|
byte sta = 0 ;
|
int num = CreateRadom.radom_4() ;
|
if(num%2 == 0){
|
sta += 1 ;//阀门状态
|
}
|
num = CreateRadom.radom_4() ;
|
if(num%2 == 0){
|
sta += 4 ;//阀门故障
|
}
|
num = CreateRadom.radom_4() ;
|
if(num%2 == 0){
|
sta += 8 ;//强磁
|
}
|
num = CreateRadom.radom_4() ;
|
if(num%2 == 0){
|
sta += 16 ;//电池欠压
|
}
|
bs[38] = sta;//表状态
|
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 39);//1点小时用水量
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 41);//2点小时用水量
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 43);//3
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 45);//4
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 47);//5
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 49);//6
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 51);//7
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 53);//8
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 55);//9
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 57);//10
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 59);//11
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 61);//12
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 63);//13
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 65);//14
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 67);//15
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 69);//16
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 71);//17
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 73);//18
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 75);//19
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 77);//20
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 79);//21
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 81);//22
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 83);//23
|
num = CreateRadom.radom(200, 10) ;
|
ByteUtilUnsigned.short2Bytes_BE(bs, num, 85);//24
|
|
byte he = 0 ;
|
for(byte i = 0 ; i <= 86; i++){
|
he = (byte)(he + bs[i]) ;
|
}
|
ByteUtilUnsigned.byte2Byte(bs, he, 87) ;
|
bs[88] = ProtocolConstantV1_0_1.P_Tail_Byte ;
|
|
return bs ;
|
}
|
|
}
|