1078-简化设备注册取值写法
This commit is contained in:
@@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -40,25 +41,18 @@ public class J0100 extends Re {
|
||||
if (version >= 1) {
|
||||
device.setCityId(buf.readUnsignedShort() + "");
|
||||
// decode as 2019
|
||||
byte[] bytes11 = new byte[11];
|
||||
buf.readBytes(bytes11);
|
||||
device.setMakerId(new String(bytes11).trim());
|
||||
device.setMakerId(buf.readCharSequence(11, Charset.forName("GBK"))
|
||||
.toString().trim());
|
||||
|
||||
byte[] bytes30 = new byte[30];
|
||||
buf.readBytes(bytes30);
|
||||
device.setDeviceModel(new String(bytes30).trim());
|
||||
device.setDeviceModel(buf.readCharSequence(30, Charset.forName("GBK"))
|
||||
.toString().trim());
|
||||
|
||||
buf.readBytes(bytes30);
|
||||
device.setDeviceId(new String(bytes30).trim());
|
||||
device.setDeviceId(buf.readCharSequence(30, Charset.forName("GBK"))
|
||||
.toString().trim());
|
||||
|
||||
device.setPlateColor(buf.readByte());
|
||||
byte[] plateColorBytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(plateColorBytes);
|
||||
try {
|
||||
device.setPlateNo(new String(plateColorBytes, "GBK").trim());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
device.setPlateNo(buf.readCharSequence(buf.readableBytes(), Charset.forName("GBK"))
|
||||
.toString().trim());
|
||||
} else {
|
||||
// decode as 2013
|
||||
device.setCityId(buf.readUnsignedShort() + "");
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package com.genersoft.iot.vmp.jt1078.proc.request;
|
||||
|
||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.response.J8001;
|
||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
||||
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
|
||||
import com.genersoft.iot.vmp.jt1078.session.Session;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.util.CharsetUtil;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
/**
|
||||
* 终端鉴权
|
||||
*
|
||||
@@ -18,20 +22,31 @@ import org.springframework.context.ApplicationEvent;
|
||||
*/
|
||||
@MsgId(id = "0102")
|
||||
public class J0102 extends Re {
|
||||
|
||||
private String authenticationCode;
|
||||
|
||||
@Override
|
||||
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
||||
int lenCode = buf.readUnsignedByte();
|
||||
// String code = buf.readCharSequence(lenCode, CharsetUtil.UTF_8).toString();
|
||||
byte[] authenticationCodeBytes = new byte[lenCode];
|
||||
// ByteBuf byteBuf = buf.readBytes(authenticationCodeBytes);
|
||||
authenticationCode = buf.readCharSequence(lenCode, Charset.forName("GBK")).toString();
|
||||
System.out.println("设备鉴权: authenticationCode: " + authenticationCode);
|
||||
// if 2019 to decode next
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||
JTDevice device = service.getDevice(header.getTerminalId());
|
||||
J8001 j8001 = new J8001();
|
||||
j8001.setRespNo(header.getSn());
|
||||
j8001.setRespId(header.getMsgId());
|
||||
j8001.setResult(J8001.SUCCESS);
|
||||
if (device == null || !device.getAuthenticationCode().equals(authenticationCode)) {
|
||||
j8001.setResult(J8001.FAIL);
|
||||
}else {
|
||||
j8001.setResult(J8001.SUCCESS);
|
||||
}
|
||||
return j8001;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.springframework.context.ApplicationEvent;
|
||||
public class J0200 extends Re {
|
||||
@Override
|
||||
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,15 @@ import io.netty.buffer.Unpooled;
|
||||
*/
|
||||
@MsgId(id = "8001")
|
||||
public class J8001 extends Rs {
|
||||
|
||||
public static final Integer SUCCESS = 0;
|
||||
|
||||
public static final Integer FAIL = 1;
|
||||
|
||||
public static final Integer ERROR = 2;
|
||||
public static final Integer NOT_SUPPORTED = 3;
|
||||
public static final Integer ALARM_ACK = 3;
|
||||
|
||||
Integer respNo;
|
||||
String respId;
|
||||
Integer result;
|
||||
|
||||
Reference in New Issue
Block a user