1078-解析104...

This commit is contained in:
648540858 2024-04-19 00:01:20 +08:00
parent 16143a3fff
commit a6236a2c13
5 changed files with 74 additions and 11 deletions

View File

@ -318,4 +318,38 @@ public class JTDeviceConfig {
public void setReportingIntervalEmergencyAlarm(Long reportingIntervalEmergencyAlarm) { public void setReportingIntervalEmergencyAlarm(Long reportingIntervalEmergencyAlarm) {
this.reportingIntervalEmergencyAlarm = 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 +
'}';
}
} }

View File

@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface ConfigAttribute { public @interface ConfigAttribute {
byte id(); long id();
String description(); String description();
} }

View File

@ -30,13 +30,14 @@ public class J0104 extends Re {
@Override @Override
protected Rs decode0(ByteBuf buf, Header header, Session session) { protected Rs decode0(ByteBuf buf, Header header, Session session) {
respNo = buf.readUnsignedShort(); respNo = buf.readUnsignedShort();
paramLength = (int)buf.readUnsignedByte();
paramLength = (int) buf.readUnsignedByte();
if (paramLength <= 0) { if (paramLength <= 0) {
return null; return null;
} }
JTDeviceConfig deviceConfig = new JTDeviceConfig(); JTDeviceConfig deviceConfig = new JTDeviceConfig();
Field[] fields = deviceConfig.getClass().getFields(); Field[] fields = deviceConfig.getClass().getDeclaredFields();
Map<Byte, Field> allFieldMap = new HashMap<>(); Map<Long, Field> allFieldMap = new HashMap<>();
for (Field field : fields) { for (Field field : fields) {
field.setAccessible(true); field.setAccessible(true);
ConfigAttribute configAttribute = field.getAnnotation(ConfigAttribute.class); ConfigAttribute configAttribute = field.getAnnotation(ConfigAttribute.class);
@ -44,9 +45,37 @@ public class J0104 extends Re {
allFieldMap.put(configAttribute.id(), field); 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(respNo);
System.out.println(paramLength); System.out.println(paramLength);
System.out.println(deviceConfig.toString());
return null; return null;
} }

View File

@ -13,23 +13,23 @@ import java.util.Arrays;
@MsgId(id = "8106") @MsgId(id = "8106")
public class J8106 extends Rs { public class J8106 extends Rs {
private byte[] params; private long[] params;
@Override @Override
public ByteBuf encode() { public ByteBuf encode() {
ByteBuf buffer = Unpooled.buffer(); ByteBuf buffer = Unpooled.buffer();
buffer.writeByte(params.length); buffer.writeByte(params.length);
for (int param : params) { for (long param : params) {
buffer.writeByte(param); buffer.writeInt((int) param);
} }
return buffer; return buffer;
} }
public byte[] getParams() { public long[] getParams() {
return params; return params;
} }
public void setParams(byte[] params) { public void setParams(long[] params) {
this.params = params; this.params = params;
} }

View File

@ -504,13 +504,13 @@ public class jt1078ServiceImpl implements Ijt1078Service {
J8104 j8104 = new J8104(); J8104 j8104 = new J8104();
jt1078Template.getDeviceConfig(deviceId, j8104, 6); jt1078Template.getDeviceConfig(deviceId, j8104, 6);
}else { }else {
byte[] paramBytes = new byte[params.length]; long[] paramBytes = new long[params.length];
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
try { try {
Field field = JTDeviceConfig.class.getDeclaredField(params[i]); Field field = JTDeviceConfig.class.getDeclaredField(params[i]);
if (field.isAnnotationPresent(ConfigAttribute.class) ) { if (field.isAnnotationPresent(ConfigAttribute.class) ) {
ConfigAttribute configAttribute = field.getAnnotation(ConfigAttribute.class); ConfigAttribute configAttribute = field.getAnnotation(ConfigAttribute.class);
byte id = configAttribute.id(); long id = configAttribute.id();
String description = configAttribute.description(); String description = configAttribute.description();
System.out.println(description + ": " + id); System.out.println(description + ": " + id);
paramBytes[i] = configAttribute.id(); paramBytes[i] = configAttribute.id();