1078-解析104...
This commit is contained in:
@@ -318,4 +318,38 @@ public class JTDeviceConfig {
|
||||
public void setReportingIntervalEmergencyAlarm(Long reportingIntervalEmergencyAlarm) {
|
||||
this.reportingIntervalEmergencyAlarm = reportingIntervalEmergencyAlarm;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JTDeviceConfig{" +
|
||||
"keepaliveInterval=" + keepaliveInterval +
|
||||
", tcpResponseTimeout=" + tcpResponseTimeout +
|
||||
", tcpRetransmissionCount=" + tcpRetransmissionCount +
|
||||
", udpResponseTimeout=" + udpResponseTimeout +
|
||||
", udpRetransmissionCount=" + udpRetransmissionCount +
|
||||
", smsResponseTimeout=" + smsResponseTimeout +
|
||||
", smsRetransmissionCount=" + smsRetransmissionCount +
|
||||
", apnMaster='" + apnMaster + '\'' +
|
||||
", dialingUsernameMaster='" + dialingUsernameMaster + '\'' +
|
||||
", dialingPasswordMaster='" + dialingPasswordMaster + '\'' +
|
||||
", addressMaster='" + addressMaster + '\'' +
|
||||
", apnBackup='" + apnBackup + '\'' +
|
||||
", dialingUsernameBackup='" + dialingUsernameBackup + '\'' +
|
||||
", dialingPasswordBackup='" + dialingPasswordBackup + '\'' +
|
||||
", addressBackup='" + addressBackup + '\'' +
|
||||
", addressIcMaster='" + addressIcMaster + '\'' +
|
||||
", tcpPortIcMaster=" + tcpPortIcMaster +
|
||||
", udpPortIcMaster=" + udpPortIcMaster +
|
||||
", addressIcBackup='" + addressIcBackup + '\'' +
|
||||
", locationReportingStrategy=" + locationReportingStrategy +
|
||||
", locationReportingPlan=" + locationReportingPlan +
|
||||
", reportingIntervalOffline=" + reportingIntervalOffline +
|
||||
", apnSlave='" + apnSlave + '\'' +
|
||||
", dialingUsernameSlave='" + dialingUsernameSlave + '\'' +
|
||||
", dialingPasswordSlave='" + dialingPasswordSlave + '\'' +
|
||||
", addressSlave='" + addressSlave + '\'' +
|
||||
", reportingIntervalDormancy=" + reportingIntervalDormancy +
|
||||
", reportingIntervalEmergencyAlarm=" + reportingIntervalEmergencyAlarm +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface ConfigAttribute {
|
||||
|
||||
byte id();
|
||||
long id();
|
||||
|
||||
String description();
|
||||
}
|
||||
|
||||
@@ -30,13 +30,14 @@ public class J0104 extends Re {
|
||||
@Override
|
||||
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
||||
respNo = buf.readUnsignedShort();
|
||||
paramLength = (int)buf.readUnsignedByte();
|
||||
|
||||
paramLength = (int) buf.readUnsignedByte();
|
||||
if (paramLength <= 0) {
|
||||
return null;
|
||||
}
|
||||
JTDeviceConfig deviceConfig = new JTDeviceConfig();
|
||||
Field[] fields = deviceConfig.getClass().getFields();
|
||||
Map<Byte, Field> allFieldMap = new HashMap<>();
|
||||
Field[] fields = deviceConfig.getClass().getDeclaredFields();
|
||||
Map<Long, Field> allFieldMap = new HashMap<>();
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
ConfigAttribute configAttribute = field.getAnnotation(ConfigAttribute.class);
|
||||
@@ -44,9 +45,37 @@ public class J0104 extends Re {
|
||||
allFieldMap.put(configAttribute.id(), field);
|
||||
}
|
||||
}
|
||||
System.out.println("========");
|
||||
for (int i = 0; i < paramLength; i++) {
|
||||
long id = buf.readUnsignedInt();
|
||||
System.out.println(id);
|
||||
short length = buf.readUnsignedByte();
|
||||
if (allFieldMap.containsKey(id)) {
|
||||
Field field = allFieldMap.get(id);
|
||||
field.setAccessible(true);
|
||||
System.out.println(field.getGenericType());
|
||||
try {
|
||||
switch (field.getGenericType().toString()) {
|
||||
case "class java.lang.Long":
|
||||
field.set(deviceConfig, buf.readUnsignedInt());
|
||||
continue;
|
||||
case "class java.lang.String":
|
||||
String val = buf.readCharSequence(length, Charset.forName("GBK")).toString().trim();
|
||||
field.set(deviceConfig, val);
|
||||
continue;
|
||||
default:
|
||||
System.err.println(field.getGenericType());
|
||||
continue;
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(respNo);
|
||||
System.out.println(paramLength);
|
||||
System.out.println(deviceConfig.toString());
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -13,23 +13,23 @@ import java.util.Arrays;
|
||||
@MsgId(id = "8106")
|
||||
public class J8106 extends Rs {
|
||||
|
||||
private byte[] params;
|
||||
private long[] params;
|
||||
|
||||
@Override
|
||||
public ByteBuf encode() {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
buffer.writeByte(params.length);
|
||||
for (int param : params) {
|
||||
buffer.writeByte(param);
|
||||
for (long param : params) {
|
||||
buffer.writeInt((int) param);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public byte[] getParams() {
|
||||
public long[] getParams() {
|
||||
return params;
|
||||
}
|
||||
|
||||
public void setParams(byte[] params) {
|
||||
public void setParams(long[] params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
|
||||
@@ -504,13 +504,13 @@ public class jt1078ServiceImpl implements Ijt1078Service {
|
||||
J8104 j8104 = new J8104();
|
||||
jt1078Template.getDeviceConfig(deviceId, j8104, 6);
|
||||
}else {
|
||||
byte[] paramBytes = new byte[params.length];
|
||||
long[] paramBytes = new long[params.length];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
try {
|
||||
Field field = JTDeviceConfig.class.getDeclaredField(params[i]);
|
||||
if (field.isAnnotationPresent(ConfigAttribute.class) ) {
|
||||
ConfigAttribute configAttribute = field.getAnnotation(ConfigAttribute.class);
|
||||
byte id = configAttribute.id();
|
||||
long id = configAttribute.id();
|
||||
String description = configAttribute.description();
|
||||
System.out.println(description + ": " + id);
|
||||
paramBytes[i] = configAttribute.id();
|
||||
|
||||
Reference in New Issue
Block a user