支持从数据库查询注册的设备是否合法
This commit is contained in:
@@ -0,0 +1,98 @@
|
|||||||
|
package com.genersoft.iot.vmp.jt1078.bean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JT 设备
|
||||||
|
*/
|
||||||
|
public class JTDevice {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 省域ID
|
||||||
|
*/
|
||||||
|
private int provinceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 市县域ID
|
||||||
|
*/
|
||||||
|
private int cityId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 制造商ID
|
||||||
|
*/
|
||||||
|
private String makerId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 终端型号
|
||||||
|
*/
|
||||||
|
private String deviceModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 终端ID
|
||||||
|
*/
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车牌颜色
|
||||||
|
*/
|
||||||
|
private int plateColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车牌
|
||||||
|
*/
|
||||||
|
private String plateNo;
|
||||||
|
|
||||||
|
public int getProvinceId() {
|
||||||
|
return provinceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProvinceId(int provinceId) {
|
||||||
|
this.provinceId = provinceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCityId() {
|
||||||
|
return cityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCityId(int cityId) {
|
||||||
|
this.cityId = cityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMakerId() {
|
||||||
|
return makerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMakerId(String makerId) {
|
||||||
|
this.makerId = makerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceModel() {
|
||||||
|
return deviceModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceModel(String deviceModel) {
|
||||||
|
this.deviceModel = deviceModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceId(String deviceId) {
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPlateColor() {
|
||||||
|
return plateColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlateColor(int plateColor) {
|
||||||
|
this.plateColor = plateColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlateNo() {
|
||||||
|
return plateNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlateNo(String plateNo) {
|
||||||
|
this.plateNo = plateNo;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.jt1078.proc.Header;
|
|||||||
import com.genersoft.iot.vmp.jt1078.proc.factory.CodecFactory;
|
import com.genersoft.iot.vmp.jt1078.proc.factory.CodecFactory;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.request.Re;
|
import com.genersoft.iot.vmp.jt1078.proc.request.Re;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
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 com.genersoft.iot.vmp.jt1078.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.ByteBufUtil;
|
import io.netty.buffer.ByteBufUtil;
|
||||||
@@ -28,9 +29,11 @@ public class Jt808Decoder extends ByteToMessageDecoder {
|
|||||||
private final static Logger log = LoggerFactory.getLogger(Jt808Decoder.class);
|
private final static Logger log = LoggerFactory.getLogger(Jt808Decoder.class);
|
||||||
|
|
||||||
private ApplicationEventPublisher applicationEventPublisher = null;
|
private ApplicationEventPublisher applicationEventPublisher = null;
|
||||||
|
private Ijt1078Service service = null;
|
||||||
|
|
||||||
public Jt808Decoder(ApplicationEventPublisher applicationEventPublisher) {
|
public Jt808Decoder(ApplicationEventPublisher applicationEventPublisher, Ijt1078Service service ) {
|
||||||
this.applicationEventPublisher = applicationEventPublisher;
|
this.applicationEventPublisher = applicationEventPublisher;
|
||||||
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -58,7 +61,7 @@ public class Jt808Decoder extends ByteToMessageDecoder {
|
|||||||
log.error("get msgId is null {}", header.getMsgId());
|
log.error("get msgId is null {}", header.getMsgId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Rs decode = handler.decode(buf, header, session);
|
Rs decode = handler.decode(buf, header, session, service);
|
||||||
ApplicationEvent applicationEvent = handler.getEvent();
|
ApplicationEvent applicationEvent = handler.getEvent();
|
||||||
if (applicationEvent != null) {
|
if (applicationEvent != null) {
|
||||||
applicationEventPublisher.publishEvent(applicationEvent);
|
applicationEventPublisher.publishEvent(applicationEvent);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.jt1078.codec.decode.Jt808Decoder;
|
|||||||
import com.genersoft.iot.vmp.jt1078.codec.encode.Jt808Encoder;
|
import com.genersoft.iot.vmp.jt1078.codec.encode.Jt808Encoder;
|
||||||
import com.genersoft.iot.vmp.jt1078.codec.encode.Jt808EncoderCmd;
|
import com.genersoft.iot.vmp.jt1078.codec.encode.Jt808EncoderCmd;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.factory.CodecFactory;
|
import com.genersoft.iot.vmp.jt1078.proc.factory.CodecFactory;
|
||||||
|
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
@@ -37,12 +38,14 @@ public class TcpServer {
|
|||||||
private EventLoopGroup bossGroup = null;
|
private EventLoopGroup bossGroup = null;
|
||||||
private EventLoopGroup workerGroup = null;
|
private EventLoopGroup workerGroup = null;
|
||||||
private ApplicationEventPublisher applicationEventPublisher = null;
|
private ApplicationEventPublisher applicationEventPublisher = null;
|
||||||
|
private Ijt1078Service service = null;
|
||||||
|
|
||||||
private final ByteBuf DECODER_JT808 = Unpooled.wrappedBuffer(new byte[]{0x7e});
|
private final ByteBuf DECODER_JT808 = Unpooled.wrappedBuffer(new byte[]{0x7e});
|
||||||
|
|
||||||
public TcpServer(Integer port, ApplicationEventPublisher applicationEventPublisher) {
|
public TcpServer(Integer port, ApplicationEventPublisher applicationEventPublisher, Ijt1078Service service) {
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.applicationEventPublisher = applicationEventPublisher;
|
this.applicationEventPublisher = applicationEventPublisher;
|
||||||
|
this.service = service;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startTcpServer() {
|
private void startTcpServer() {
|
||||||
@@ -63,7 +66,7 @@ public class TcpServer {
|
|||||||
channel.pipeline()
|
channel.pipeline()
|
||||||
.addLast(new IdleStateHandler(10, 0, 0, TimeUnit.MINUTES))
|
.addLast(new IdleStateHandler(10, 0, 0, TimeUnit.MINUTES))
|
||||||
.addLast(new DelimiterBasedFrameDecoder(1024 * 2, DECODER_JT808))
|
.addLast(new DelimiterBasedFrameDecoder(1024 * 2, DECODER_JT808))
|
||||||
.addLast(new Jt808Decoder(applicationEventPublisher))
|
.addLast(new Jt808Decoder(applicationEventPublisher, service))
|
||||||
.addLast(new Jt808Encoder())
|
.addLast(new Jt808Encoder())
|
||||||
.addLast(new Jt808EncoderCmd())
|
.addLast(new Jt808EncoderCmd())
|
||||||
.addLast(new Jt808Handler());
|
.addLast(new Jt808Handler());
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.jt1078.config;
|
|||||||
|
|
||||||
import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template;
|
import com.genersoft.iot.vmp.jt1078.cmd.JT1078Template;
|
||||||
import com.genersoft.iot.vmp.jt1078.codec.netty.TcpServer;
|
import com.genersoft.iot.vmp.jt1078.codec.netty.TcpServer;
|
||||||
|
import com.genersoft.iot.vmp.jt1078.service.Ijt1078Service;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
@@ -23,9 +24,12 @@ public class JT1078AutoConfiguration {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ApplicationEventPublisher applicationEventPublisher;
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private Ijt1078Service service;
|
||||||
|
|
||||||
@Bean(initMethod = "start", destroyMethod = "stop")
|
@Bean(initMethod = "start", destroyMethod = "stop")
|
||||||
public TcpServer jt1078Server(@Value("${jt1078.port}") Integer port) {
|
public TcpServer jt1078Server(@Value("${jt1078.port}") Integer port) {
|
||||||
return new TcpServer(port, applicationEventPublisher);
|
return new TcpServer(port, applicationEventPublisher, service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.genersoft.iot.vmp.jt1078.event;
|
package com.genersoft.iot.vmp.jt1078.event;
|
||||||
|
|
||||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
|
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
|
||||||
|
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,74 +19,13 @@ public class RegisterEvent extends ApplicationEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private int provinceId;
|
private JTDevice device;
|
||||||
|
|
||||||
private int cityId;
|
public JTDevice getDevice() {
|
||||||
|
return device;
|
||||||
private String makerId;
|
|
||||||
|
|
||||||
private String deviceModel;
|
|
||||||
|
|
||||||
private String deviceId;
|
|
||||||
|
|
||||||
private int plateColor;
|
|
||||||
|
|
||||||
private String plateNo;
|
|
||||||
|
|
||||||
|
|
||||||
public int getProvinceId() {
|
|
||||||
return provinceId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProvinceId(int provinceId) {
|
public void setDevice(JTDevice device) {
|
||||||
this.provinceId = provinceId;
|
this.device = device;
|
||||||
}
|
|
||||||
|
|
||||||
public int getCityId() {
|
|
||||||
return cityId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCityId(int cityId) {
|
|
||||||
this.cityId = cityId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getMakerId() {
|
|
||||||
return makerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMakerId(String makerId) {
|
|
||||||
this.makerId = makerId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceModel() {
|
|
||||||
return deviceModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceModel(String deviceModel) {
|
|
||||||
this.deviceModel = deviceModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDeviceId() {
|
|
||||||
return deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDeviceId(String deviceId) {
|
|
||||||
this.deviceId = deviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlateColor() {
|
|
||||||
return plateColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlateColor(int plateColor) {
|
|
||||||
this.plateColor = plateColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPlateNo() {
|
|
||||||
return plateNo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPlateNo(String plateNo) {
|
|
||||||
this.plateNo = plateNo;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON;
|
|||||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
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 com.genersoft.iot.vmp.jt1078.session.Session;
|
||||||
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
|
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
@@ -32,7 +33,7 @@ public class J0001 extends Re {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rs handler(Header header, Session session) {
|
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||||
SessionManager.INSTANCE.response(header.getDevId(), "0001", (long) respNo, JSON.toJSONString(this));
|
SessionManager.INSTANCE.response(header.getDevId(), "0001", (long) respNo, JSON.toJSONString(this));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
|||||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
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.J8001;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
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 com.genersoft.iot.vmp.jt1078.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
@@ -23,7 +24,7 @@ public class J0002 extends Re {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rs handler(Header header, Session session) {
|
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||||
J8001 j8001 = new J8001();
|
J8001 j8001 = new J8001();
|
||||||
j8001.setRespNo(header.getSn());
|
j8001.setRespNo(header.getSn());
|
||||||
j8001.setRespId(header.getMsgId());
|
j8001.setRespId(header.getMsgId());
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.jt1078.proc.request;
|
|||||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
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 com.genersoft.iot.vmp.jt1078.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
@@ -22,7 +23,7 @@ public class J0004 extends Re {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rs handler(Header header, Session session) {
|
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package com.genersoft.iot.vmp.jt1078.proc.request;
|
package com.genersoft.iot.vmp.jt1078.proc.request;
|
||||||
|
|
||||||
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
||||||
|
import com.genersoft.iot.vmp.jt1078.bean.JTDevice;
|
||||||
import com.genersoft.iot.vmp.jt1078.event.RegisterEvent;
|
import com.genersoft.iot.vmp.jt1078.event.RegisterEvent;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.J8100;
|
import com.genersoft.iot.vmp.jt1078.proc.response.J8100;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
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 com.genersoft.iot.vmp.jt1078.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
@@ -21,67 +23,56 @@ import java.io.UnsupportedEncodingException;
|
|||||||
@MsgId(id = "0100")
|
@MsgId(id = "0100")
|
||||||
public class J0100 extends Re {
|
public class J0100 extends Re {
|
||||||
|
|
||||||
private int provinceId;
|
private JTDevice device;
|
||||||
|
|
||||||
private int cityId;
|
|
||||||
|
|
||||||
private String makerId;
|
|
||||||
|
|
||||||
private String deviceModel;
|
|
||||||
|
|
||||||
private String deviceId;
|
|
||||||
|
|
||||||
private int plateColor;
|
|
||||||
|
|
||||||
private String plateNo;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
protected Rs decode0(ByteBuf buf, Header header, Session session) {
|
||||||
Short version = header.getVersion();
|
Short version = header.getVersion();
|
||||||
provinceId = buf.readUnsignedShort();
|
device = new JTDevice();
|
||||||
|
device.setProvinceId(buf.readUnsignedShort());
|
||||||
if (version >= 1) {
|
if (version >= 1) {
|
||||||
cityId = buf.readUnsignedShort();
|
device.setCityId(buf.readUnsignedShort());
|
||||||
// decode as 2019
|
// decode as 2019
|
||||||
byte[] bytes11 = new byte[11];
|
byte[] bytes11 = new byte[11];
|
||||||
buf.readBytes(bytes11);
|
buf.readBytes(bytes11);
|
||||||
makerId = new String(bytes11).trim();
|
device.setMakerId(new String(bytes11).trim());
|
||||||
|
|
||||||
byte[] bytes30 = new byte[30];
|
byte[] bytes30 = new byte[30];
|
||||||
buf.readBytes(bytes30);
|
buf.readBytes(bytes30);
|
||||||
deviceModel = new String(bytes30).trim();
|
device.setDeviceModel(new String(bytes30).trim());
|
||||||
|
|
||||||
buf.readBytes(bytes30);
|
buf.readBytes(bytes30);
|
||||||
deviceId = new String(bytes30).trim();
|
device.setDeviceId(new String(bytes30).trim());
|
||||||
|
|
||||||
plateColor = buf.readByte();
|
device.setPlateColor(buf.readByte());
|
||||||
byte[] plateColorBytes = new byte[buf.readableBytes()];
|
byte[] plateColorBytes = new byte[buf.readableBytes()];
|
||||||
buf.readBytes(plateColorBytes);
|
buf.readBytes(plateColorBytes);
|
||||||
try {
|
try {
|
||||||
plateNo = new String(plateColorBytes, "GBK").trim();
|
device.setPlateNo(new String(plateColorBytes, "GBK").trim());
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// decode as 2013
|
// decode as 2013
|
||||||
cityId = buf.readUnsignedShort();
|
device.setCityId(buf.readUnsignedShort());
|
||||||
// decode as 2019
|
// decode as 2019
|
||||||
byte[] bytes5 = new byte[5];
|
byte[] bytes5 = new byte[5];
|
||||||
buf.readBytes(bytes5);
|
buf.readBytes(bytes5);
|
||||||
makerId = new String(bytes5).trim();
|
device.setMakerId(new String(bytes5).trim());
|
||||||
|
|
||||||
byte[] bytes20 = new byte[20];
|
byte[] bytes20 = new byte[20];
|
||||||
buf.readBytes(bytes20);
|
buf.readBytes(bytes20);
|
||||||
deviceModel = new String(bytes20).trim();
|
device.setDeviceModel(new String(bytes20).trim());
|
||||||
|
|
||||||
byte[] bytes7 = new byte[7];
|
byte[] bytes7 = new byte[7];
|
||||||
buf.readBytes(bytes7);
|
buf.readBytes(bytes7);
|
||||||
deviceId = new String(bytes7).trim();
|
device.setDeviceId(new String(bytes7).trim());
|
||||||
|
|
||||||
plateColor = buf.readByte();
|
device.setPlateColor(buf.readByte());
|
||||||
byte[] plateColorBytes = new byte[buf.readableBytes()];
|
byte[] plateColorBytes = new byte[buf.readableBytes()];
|
||||||
buf.readBytes(plateColorBytes);
|
buf.readBytes(plateColorBytes);
|
||||||
try {
|
try {
|
||||||
plateNo = new String(plateColorBytes, "GBK").trim();
|
device.setPlateNo(new String(plateColorBytes, "GBK").trim());
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -90,7 +81,8 @@ public class J0100 extends Re {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rs handler(Header header, Session session) {
|
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||||
|
// TODO 从数据库判断这个设备是否合法
|
||||||
J8100 j8100 = new J8100();
|
J8100 j8100 = new J8100();
|
||||||
j8100.setRespNo(header.getSn());
|
j8100.setRespNo(header.getSn());
|
||||||
j8100.setResult(J8100.SUCCESS);
|
j8100.setResult(J8100.SUCCESS);
|
||||||
@@ -101,13 +93,7 @@ public class J0100 extends Re {
|
|||||||
@Override
|
@Override
|
||||||
public ApplicationEvent getEvent() {
|
public ApplicationEvent getEvent() {
|
||||||
RegisterEvent registerEvent = new RegisterEvent(this);
|
RegisterEvent registerEvent = new RegisterEvent(this);
|
||||||
registerEvent.setProvinceId(provinceId);
|
registerEvent.setDevice(device);
|
||||||
registerEvent.setCityId(cityId);
|
|
||||||
registerEvent.setDeviceId(deviceId);
|
|
||||||
registerEvent.setDeviceModel(deviceModel);
|
|
||||||
registerEvent.setMakerId(makerId);
|
|
||||||
registerEvent.setPlateColor(plateColor);
|
|
||||||
registerEvent.setPlateNo(plateNo);
|
|
||||||
return registerEvent;
|
return registerEvent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
|||||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
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.J8001;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
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 com.genersoft.iot.vmp.jt1078.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
@@ -26,7 +27,7 @@ public class J0102 extends Re {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rs handler(Header header, Session session) {
|
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||||
J8001 j8001 = new J8001();
|
J8001 j8001 = new J8001();
|
||||||
j8001.setRespNo(header.getSn());
|
j8001.setRespNo(header.getSn());
|
||||||
j8001.setRespId(header.getMsgId());
|
j8001.setRespId(header.getMsgId());
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
|||||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
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.J8001;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
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 com.genersoft.iot.vmp.jt1078.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.springframework.context.ApplicationEvent;
|
import org.springframework.context.ApplicationEvent;
|
||||||
@@ -23,7 +24,7 @@ public class J0200 extends Re {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rs handler(Header header, Session session) {
|
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||||
J8001 j8001 = new J8001();
|
J8001 j8001 = new J8001();
|
||||||
j8001.setRespNo(header.getSn());
|
j8001.setRespNo(header.getSn());
|
||||||
j8001.setRespId(header.getMsgId());
|
j8001.setRespId(header.getMsgId());
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.jt1078.annotation.MsgId;
|
|||||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
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.J8001;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
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 com.genersoft.iot.vmp.jt1078.session.Session;
|
||||||
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
|
import com.genersoft.iot.vmp.jt1078.session.SessionManager;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
@@ -49,7 +50,7 @@ public class J1205 extends Re {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Rs handler(Header header, Session session) {
|
protected Rs handler(Header header, Session session, Ijt1078Service service) {
|
||||||
SessionManager.INSTANCE.response(header.getDevId(), "1205", (long) respNo, JSON.toJSONString(this));
|
SessionManager.INSTANCE.response(header.getDevId(), "1205", (long) respNo, JSON.toJSONString(this));
|
||||||
|
|
||||||
J8001 j8001 = new J8001();
|
J8001 j8001 = new J8001();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.jt1078.proc.request;
|
|||||||
|
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
import com.genersoft.iot.vmp.jt1078.proc.Header;
|
||||||
import com.genersoft.iot.vmp.jt1078.proc.response.Rs;
|
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 com.genersoft.iot.vmp.jt1078.session.Session;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -19,14 +20,14 @@ public abstract class Re {
|
|||||||
|
|
||||||
protected abstract Rs decode0(ByteBuf buf, Header header, Session session);
|
protected abstract Rs decode0(ByteBuf buf, Header header, Session session);
|
||||||
|
|
||||||
protected abstract Rs handler(Header header, Session session);
|
protected abstract Rs handler(Header header, Session session, Ijt1078Service service);
|
||||||
|
|
||||||
public Rs decode(ByteBuf buf, Header header, Session session) {
|
public Rs decode(ByteBuf buf, Header header, Session session, Ijt1078Service service) {
|
||||||
if (session != null && !StringUtils.hasLength(session.getDevId())) {
|
if (session != null && !StringUtils.hasLength(session.getDevId())) {
|
||||||
session.register(header.getDevId(), (int) header.getVersion(), header);
|
session.register(header.getDevId(), (int) header.getVersion(), header);
|
||||||
}
|
}
|
||||||
Rs rs = decode0(buf, header, session);
|
Rs rs = decode0(buf, header, session);
|
||||||
Rs rsHand = handler(header, session);
|
Rs rsHand = handler(header, session, service);
|
||||||
if (rs == null && rsHand != null) {
|
if (rs == null && rsHand != null) {
|
||||||
rs = rsHand;
|
rs = rsHand;
|
||||||
} else if (rs != null && rsHand != null) {
|
} else if (rs != null && rsHand != null) {
|
||||||
|
|||||||
@@ -12,6 +12,13 @@ import io.netty.util.CharsetUtil;
|
|||||||
*/
|
*/
|
||||||
@MsgId(id = "8100")
|
@MsgId(id = "8100")
|
||||||
public class J8100 extends Rs {
|
public class J8100 extends Rs {
|
||||||
|
/**
|
||||||
|
* 0 成功
|
||||||
|
* 1 车辆已被注册
|
||||||
|
* 2 数据库中无该车辆
|
||||||
|
* 2 终端已被注册
|
||||||
|
* 2 数据库中无该终端
|
||||||
|
*/
|
||||||
public static final Integer SUCCESS = 0;
|
public static final Integer SUCCESS = 0;
|
||||||
|
|
||||||
Integer respNo;
|
Integer respNo;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class JT1078ServerTest {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Starting jt1078 server...");
|
System.out.println("Starting jt1078 server...");
|
||||||
TcpServer tcpServer = new TcpServer(21078, null);
|
TcpServer tcpServer = new TcpServer(21078, null, null);
|
||||||
tcpServer.start();
|
tcpServer.start();
|
||||||
System.out.println("Start jt1078 server success!");
|
System.out.println("Start jt1078 server success!");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user