1. 修改心跳协议以及控制器状态回复协议
This commit is contained in:
parent
28c904076a
commit
1faa9ff0ca
|
@ -1,20 +1,12 @@
|
|||
package com.zjyr.beidouservice.adapter.impl.netty.decode;
|
||||
|
||||
import com.zjyr.beidouservice.common.CommonEnumHandler;
|
||||
import com.zjyr.beidouservice.common.impl.BeidouStatusName;
|
||||
import com.zjyr.beidouservice.common.impl.ControlChannelStatus;
|
||||
import com.zjyr.beidouservice.common.impl.ControlCommandName;
|
||||
import com.zjyr.beidouservice.common.impl.SendStatusName;
|
||||
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName;
|
||||
import com.zjyr.beidouservice.common.impl.SensorStatusName;
|
||||
import com.zjyr.beidouservice.common.impl.TelphoneStatusName;
|
||||
import com.zjyr.beidouservice.common.impl.WirelessStatusName;
|
||||
import com.zjyr.beidouservice.misc.HelperUtils;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.BaseBinaryProtocol;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.ControllerStatus;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.MessageContent;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.SensorCotrolAck;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.SensorStatusAck;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.SensorStatusInfo;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.*;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
@ -37,75 +29,83 @@ public class YuanRongProtocolDecode extends ByteToMessageDecoder {
|
|||
protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf buf, List<Object> list) {
|
||||
log.info("\n{}", ByteBufUtil.prettyHexDump(buf));
|
||||
try {
|
||||
short msgLength = buf.readShort();
|
||||
int commandId = buf.readInt();
|
||||
byte version = buf.readByte();
|
||||
byte cryptCytp = buf.readByte();
|
||||
int timeStamp = buf.readInt();
|
||||
int statusCode = buf.readInt();
|
||||
byte msgType = buf.readByte();
|
||||
short msgSize = buf.readShort();
|
||||
short msgLength = buf.readShort();
|
||||
int commandId = buf.readInt();
|
||||
byte version = buf.readByte();
|
||||
byte cryptCytp = buf.readByte();
|
||||
int timeStamp = buf.readInt();
|
||||
int statusCode = buf.readInt();
|
||||
byte msgType = buf.readByte();
|
||||
short msgSize = buf.readShort();
|
||||
|
||||
ControlCommandName cmd = CommonEnumHandler.codeOf(ControlCommandName.class, msgType);
|
||||
if (cmd != null) {
|
||||
switch (cmd) {
|
||||
case COMMAND_REPORT_HEART -> {
|
||||
SendStatusName sendStatus = CommonEnumHandler.codeOf(SendStatusName.class, buf.readByte());
|
||||
ControlChannelStatus beidouStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class, buf.readByte());
|
||||
byte[] beidouCommFreq = new byte[3];
|
||||
buf.readBytes(beidouCommFreq, 0, 3);
|
||||
byte[] beidouSignal = new byte[10];
|
||||
buf.readBytes(beidouSignal, 0, 10);
|
||||
SensorStatusName wireStatus = CommonEnumHandler.codeOf(SensorStatusName.class, buf.readByte());
|
||||
SensorStatusName phoneStatus = CommonEnumHandler.codeOf(SensorStatusName.class, buf.readByte());
|
||||
ControlChannelStatus wireStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class, buf.readByte());
|
||||
ControlChannelStatus phoneStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class, buf.readByte());
|
||||
|
||||
ControllerStatus status = ControllerStatus.builder()
|
||||
.beidouSignalStrength(beidouSignal)
|
||||
.wirelessStatus(wireStatus)
|
||||
.telphoneStatus(phoneStatus)
|
||||
.build();
|
||||
.sendStatus(sendStatus)
|
||||
.beidouStatus(beidouStatus)
|
||||
.beidouFreq(beidouCommFreq)
|
||||
.beidouSignalStrength(beidouSignal)
|
||||
.wirelessStatus(wireStatus)
|
||||
.telphoneStatus(phoneStatus)
|
||||
.build();
|
||||
|
||||
MessageContent<ControllerStatus> msgCtx = MessageContent.<ControllerStatus>builder().msgType(
|
||||
msgType).msgSize(msgSize).msgBody(status).build();
|
||||
|
||||
list.add(BaseBinaryProtocol.<ControllerStatus>builder()
|
||||
.msgLength(msgLength)
|
||||
.version(version)
|
||||
.commandId(commandId)
|
||||
.cryptoType(cryptCytp)
|
||||
.timeStamp(timeStamp)
|
||||
.statusCode(statusCode)
|
||||
.msgContent(msgCtx)
|
||||
.build());
|
||||
.msgLength(msgLength)
|
||||
.version(version)
|
||||
.commandId(commandId)
|
||||
.cryptoType(cryptCytp)
|
||||
.timeStamp(timeStamp)
|
||||
.statusCode(statusCode)
|
||||
.msgContent(msgCtx)
|
||||
.build());
|
||||
}
|
||||
case COMMAND_REPORT_SENSOR -> {
|
||||
SendStatusName sendStatus = CommonEnumHandler.codeOf(SendStatusName.class, buf.readByte());
|
||||
BeidouStatusName beidouStatus = CommonEnumHandler.codeOf(BeidouStatusName.class,
|
||||
buf.readByte());
|
||||
WirelessStatusName wireStatus = CommonEnumHandler.codeOf(WirelessStatusName.class,
|
||||
buf.readByte());
|
||||
TelphoneStatusName phoneStatus = CommonEnumHandler.codeOf(TelphoneStatusName.class,
|
||||
buf.readByte());
|
||||
byte[] beidouSignle = new byte[3];
|
||||
buf.readBytes(beidouSignle, 0, 3);
|
||||
|
||||
SensorCotrolAck ack = SensorCotrolAck.builder()
|
||||
.sendStatus(sendStatus)
|
||||
.beidouStatus(beidouStatus)
|
||||
.wirelessStatus(wireStatus)
|
||||
.telphoneStatus(phoneStatus)
|
||||
.beidouFreq(beidouSignle)
|
||||
.build();
|
||||
|
||||
MessageContent<SensorCotrolAck> msgCtx = MessageContent.<SensorCotrolAck>builder().msgType(
|
||||
msgType).msgSize(msgSize).msgBody(ack).build();
|
||||
list.add(BaseBinaryProtocol.<SensorCotrolAck>builder()
|
||||
.msgLength(msgLength)
|
||||
.version(version)
|
||||
.commandId(commandId)
|
||||
.cryptoType(cryptCytp)
|
||||
.timeStamp(timeStamp)
|
||||
.statusCode(statusCode)
|
||||
.msgContent(msgCtx)
|
||||
.build());
|
||||
// SendStatusName sendStatus = CommonEnumHandler.codeOf(SendStatusName.class, buf.readByte());
|
||||
// BeidouStatusName beidouStatus = CommonEnumHandler.codeOf(BeidouStatusName.class,
|
||||
// buf.readByte());
|
||||
// WirelessStatusName wireStatus = CommonEnumHandler.codeOf(WirelessStatusName.class,
|
||||
// buf.readByte());
|
||||
// TelphoneStatusName phoneStatus = CommonEnumHandler.codeOf(TelphoneStatusName.class,
|
||||
// buf.readByte());
|
||||
// byte[] beidouSignle = new byte[3];
|
||||
// buf.readBytes(beidouSignle, 0, 3);
|
||||
//
|
||||
// SensorCotrolAck ack = SensorCotrolAck.builder()
|
||||
// .sendStatus(sendStatus)
|
||||
// .beidouStatus(beidouStatus)
|
||||
// .wirelessStatus(wireStatus)
|
||||
// .telphoneStatus(phoneStatus)
|
||||
// .beidouFreq(beidouSignle)
|
||||
// .build();
|
||||
//
|
||||
// MessageContent<SensorCotrolAck> msgCtx = MessageContent.<SensorCotrolAck>builder().msgType(
|
||||
// msgType).msgSize(msgSize).msgBody(ack).build();
|
||||
// list.add(BaseBinaryProtocol.<SensorCotrolAck>builder()
|
||||
// .msgLength(msgLength)
|
||||
// .version(version)
|
||||
// .commandId(commandId)
|
||||
// .cryptoType(cryptCytp)
|
||||
// .timeStamp(timeStamp)
|
||||
// .statusCode(statusCode)
|
||||
// .msgContent(msgCtx)
|
||||
// .build());
|
||||
}
|
||||
case COMMAND_REPORT_QUERY_SENSOR -> {
|
||||
int nItems = buf.readByte();
|
||||
int nItems = buf.readByte();
|
||||
SensorStatusAck sensorAck = SensorStatusAck.builder().sensorStatus(new ArrayList<>()).build();
|
||||
|
||||
MessageContent<SensorStatusAck> msgCtx = MessageContent.<SensorStatusAck>builder().msgType(
|
||||
|
@ -114,53 +114,53 @@ public class YuanRongProtocolDecode extends ByteToMessageDecoder {
|
|||
for (int i = 0; i < nItems; i++) {
|
||||
short tmInfo = buf.readShort();
|
||||
SensorControlTunnelName tn = CommonEnumHandler.codeOf(SensorControlTunnelName.class,
|
||||
buf.readByte());
|
||||
int cmdType = buf.readByte();
|
||||
short sa = buf.readShort();
|
||||
short sid = buf.readShort();
|
||||
int warrStatus = buf.readByte();
|
||||
int emg0 = buf.readByte();
|
||||
int emg1 = buf.readByte();
|
||||
int emg2 = buf.readByte();
|
||||
int spk0 = buf.readByte();
|
||||
int spk1 = buf.readByte();
|
||||
int spk2 = buf.readByte();
|
||||
int runStatus = buf.readByte();
|
||||
byte[] signale = new byte[5];
|
||||
buf.readByte());
|
||||
int cmdType = buf.readByte();
|
||||
short sa = buf.readShort();
|
||||
short sid = buf.readShort();
|
||||
int warrStatus = buf.readByte();
|
||||
int emg0 = buf.readByte();
|
||||
int emg1 = buf.readByte();
|
||||
int emg2 = buf.readByte();
|
||||
int spk0 = buf.readByte();
|
||||
int spk1 = buf.readByte();
|
||||
int spk2 = buf.readByte();
|
||||
int runStatus = buf.readByte();
|
||||
byte[] signale = new byte[5];
|
||||
buf.readBytes(signale, 0, 5);
|
||||
byte[] id = new byte[3];
|
||||
buf.readBytes(id, 0, 3);
|
||||
|
||||
SensorStatusInfo si = SensorStatusInfo.builder()
|
||||
.dtInfo(tmInfo)
|
||||
.tunnelName(tn)
|
||||
.command(cmdType)
|
||||
.startAddr(sa)
|
||||
.sensorId(sid)
|
||||
.warrningStatus(warrStatus)
|
||||
.emergenStatus0(emg0)
|
||||
.emergenStatus1(emg1)
|
||||
.emergenStatus2(emg2)
|
||||
.speakerStatus0(spk0)
|
||||
.speakerStatus1(spk1)
|
||||
.speakerStatus2(spk2)
|
||||
.runStatus(runStatus)
|
||||
.signalStrength(HelperUtils.bytesToHexString(signale))
|
||||
.beidouId(HelperUtils.bytesToHexString(id))
|
||||
.build();
|
||||
.dtInfo(tmInfo)
|
||||
.tunnelName(tn)
|
||||
.command(cmdType)
|
||||
.startAddr(sa)
|
||||
.sensorId(sid)
|
||||
.warrningStatus(warrStatus)
|
||||
.emergenStatus0(emg0)
|
||||
.emergenStatus1(emg1)
|
||||
.emergenStatus2(emg2)
|
||||
.speakerStatus0(spk0)
|
||||
.speakerStatus1(spk1)
|
||||
.speakerStatus2(spk2)
|
||||
.runStatus(runStatus)
|
||||
.signalStrength(HelperUtils.bytesToHexString(signale))
|
||||
.beidouId(HelperUtils.bytesToHexString(id))
|
||||
.build();
|
||||
|
||||
sensorAck.getSensorStatus().add(si);
|
||||
}
|
||||
|
||||
list.add(BaseBinaryProtocol.<SensorStatusAck>builder()
|
||||
.msgLength(msgLength)
|
||||
.version(version)
|
||||
.commandId(commandId)
|
||||
.cryptoType(cryptCytp)
|
||||
.timeStamp(timeStamp)
|
||||
.statusCode(statusCode)
|
||||
.msgContent(msgCtx)
|
||||
.build());
|
||||
.msgLength(msgLength)
|
||||
.version(version)
|
||||
.commandId(commandId)
|
||||
.cryptoType(cryptCytp)
|
||||
.timeStamp(timeStamp)
|
||||
.statusCode(statusCode)
|
||||
.msgContent(msgCtx)
|
||||
.build());
|
||||
}
|
||||
default -> log.error("Unsupport Command: {}({})", cmd, msgType);
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ public class YuanRongProtocolEncode<T> extends MessageToByteEncoder<BaseBinaryPr
|
|||
byteBuf.writeByte(msg.getNControlInfo());
|
||||
for (var c : msg.getControllContents()) {
|
||||
byteBuf.writeByte(c.getDistrictsCode());
|
||||
byteBuf.writeByte(c.getControlAction().getValue().byteValue());
|
||||
//byteBuf.writeByte(c.getControlAction().getValue().byteValue());
|
||||
byteBuf.writeShort(c.getSensorId());
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ public class YuanRongProtocolEncode<T> extends MessageToByteEncoder<BaseBinaryPr
|
|||
byteBuf.writeByte(msg.getNControlInfo());
|
||||
for (var c : msg.getControllContents()) {
|
||||
byteBuf.writeByte(c.getDistrictsCode());
|
||||
byteBuf.writeByte(c.getControlAction().getValue().byteValue());
|
||||
//byteBuf.writeByte(c.getControlAction().getValue().byteValue());
|
||||
byteBuf.writeShort(c.getSensorId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package com.zjyr.beidouservice.common.impl;
|
|||
|
||||
import com.zjyr.beidouservice.common.EnumerationBase;
|
||||
|
||||
public enum BeidouStatusName implements EnumerationBase {
|
||||
BEIDOU_NORMAL(0, "BEIDOU_NORMAL"),
|
||||
BEIDOU_MODULE_EXCEPTION(1, "BEIDOU_MODULE_EXCEPTION"),
|
||||
BEIDOU_SATELLITE_EXCEPTION(2, "BEIDOU_SATELLITE_EXCEPTION"),
|
||||
public enum ControlChannelStatus implements EnumerationBase {
|
||||
CHANNEL_NORMAL(0, "CHANNEL_NORMAL"),
|
||||
CHANNEL_MODULE_UNEXISTS(1, "CHANNEL_MODULE_UNEXISTS"),
|
||||
CHANNEL_MODULE_EXCEPTION(2, "CHANNEL_MODULE_EXCEPTION"),
|
||||
BEIDOU_MODULE_EXCEPTION(3, "BEIDOU_MODULE_EXCEPTION"),
|
||||
BEIDOU_SATELLITE_EXCEPTION(4, "BEIDOU_SATELLITE_EXCEPTION"),
|
||||
;
|
||||
|
||||
/**
|
||||
|
@ -23,7 +25,7 @@ public enum BeidouStatusName implements EnumerationBase {
|
|||
* @param val the val
|
||||
* @param desc the desc
|
||||
*/
|
||||
BeidouStatusName(int val, String desc) {
|
||||
ControlChannelStatus(int val, String desc) {
|
||||
this.code = val;
|
||||
this.desc = desc;
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package com.zjyr.beidouservice.common.impl;
|
||||
|
||||
import com.zjyr.beidouservice.common.EnumerationBase;
|
||||
|
||||
/**
|
||||
* The enum Sensor control action name.
|
||||
*/
|
||||
public enum SensorControlActionName implements EnumerationBase {
|
||||
/**
|
||||
* Action single point sensor control action name.
|
||||
*/
|
||||
ACTION_SINGLE_POINT(0, "ACTION_SINGLE_POINT"),
|
||||
|
||||
/**
|
||||
* Action city based sensor control action name.
|
||||
*/
|
||||
ACTION_CITY_BASED(1, "ACTION_CITY_BASED"),
|
||||
|
||||
/**
|
||||
* Action districts based sensor control action name.
|
||||
*/
|
||||
ACTION_DISTRICTS_BASED(2, "ACTION_DISTRICTS_BASED"),
|
||||
;
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final Integer code;
|
||||
/**
|
||||
* The Desc.
|
||||
*/
|
||||
private final String desc;
|
||||
|
||||
/**
|
||||
* Instantiates a new Sensor control action name.
|
||||
*
|
||||
* @param val the val
|
||||
* @param desc the desc
|
||||
*/
|
||||
SensorControlActionName(int val, String desc) {
|
||||
this.code = val;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return this.desc;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package com.zjyr.beidouservice.common.impl;
|
||||
|
||||
import com.zjyr.beidouservice.common.EnumerationBase;
|
||||
|
||||
/**
|
||||
* The enum Sensor status name.
|
||||
*/
|
||||
public enum SensorStatusName implements EnumerationBase {
|
||||
/**
|
||||
* Wireless noexists sensor status name.
|
||||
*/
|
||||
WIRELESS_NOEXISTS(0, "WIRELESS_NOEXISTS"),
|
||||
|
||||
/**
|
||||
* Wireless normal sensor status name.
|
||||
*/
|
||||
WIRELESS_NORMAL(1, "WIRELESS_NORMAL"),
|
||||
|
||||
/**
|
||||
* Wireless exception sensor status name.
|
||||
*/
|
||||
WIRELESS_EXCEPTION(2, "WIRELESS_EXCEPTION"),
|
||||
;
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final Integer code;
|
||||
/**
|
||||
* The Desc.
|
||||
*/
|
||||
private final String desc;
|
||||
|
||||
/**
|
||||
* Instantiates a new Sensor status name.
|
||||
*
|
||||
* @param val the val
|
||||
* @param desc the desc
|
||||
*/
|
||||
SensorStatusName(int val, String desc) {
|
||||
this.code = val;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return this.desc;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.zjyr.beidouservice.common.impl;
|
||||
|
||||
import com.zjyr.beidouservice.common.EnumerationBase;
|
||||
|
||||
public enum TelphoneStatusName implements EnumerationBase {
|
||||
TELPHONE_NORMAL(0, "TELPHONE_NORMAL"),
|
||||
TELPHONE_NOT_DETECTION(1, "TELPHONE_NOT_DETECTION"),
|
||||
TELPHONE_BREAKDOWN(2, "TELPHONE_BREAKDOWN"),
|
||||
;
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final Integer code;
|
||||
/**
|
||||
* The Desc.
|
||||
*/
|
||||
private final String desc;
|
||||
|
||||
/**
|
||||
* Instantiates a new Beidou adapter type name.
|
||||
*
|
||||
* @param val the val
|
||||
* @param desc the desc
|
||||
*/
|
||||
TelphoneStatusName(int val, String desc) {
|
||||
this.code = val;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return this.desc;
|
||||
}
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
package com.zjyr.beidouservice.common.impl;
|
||||
|
||||
import com.zjyr.beidouservice.common.EnumerationBase;
|
||||
|
||||
public enum WirelessStatusName implements EnumerationBase {
|
||||
|
||||
WIRELESS_NORMAL(0, "WIRELESS_NORMAL"),
|
||||
WIRELESS_BREAKDOWN(0, "WIRELESS_BREAKDOWN"),
|
||||
;
|
||||
|
||||
/**
|
||||
* The Code.
|
||||
*/
|
||||
private final Integer code;
|
||||
/**
|
||||
* The Desc.
|
||||
*/
|
||||
private final String desc;
|
||||
|
||||
/**
|
||||
* Instantiates a new Beidou adapter type name.
|
||||
*
|
||||
* @param val the val
|
||||
* @param desc the desc
|
||||
*/
|
||||
WirelessStatusName(int val, String desc) {
|
||||
this.code = val;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return this.desc;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package com.zjyr.beidouservice.controller;
|
||||
|
||||
import com.zjyr.beidouservice.common.impl.SensorControlActionName;
|
||||
import com.zjyr.beidouservice.common.impl.SensorControlModeName;
|
||||
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName;
|
||||
import com.zjyr.beidouservice.pojo.dto.BaseProtocolDTO;
|
||||
|
@ -62,11 +61,11 @@ public class AuthUser {
|
|||
List<BeidouAdapterControlContent> adapterInfo = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
adapterInfo.add(BeidouAdapterControlContent.builder()
|
||||
.districtsCode(0x10 + i)
|
||||
.sensorId(0x3f00 + i)
|
||||
.controlAction(SensorControlActionName.ACTION_DISTRICTS_BASED)
|
||||
.build());
|
||||
// adapterInfo.add(BeidouAdapterControlContent.builder()
|
||||
// .districtsCode(0x10 + i)
|
||||
// .sensorId(0x3f00 + i)
|
||||
// .controlAction(SensorControlActionName.ACTION_DISTRICTS_BASED)
|
||||
// .build());
|
||||
}
|
||||
|
||||
SensorControlProtocol sp =
|
||||
|
|
|
@ -31,7 +31,7 @@ public class ControlDevice {
|
|||
*/
|
||||
@Id
|
||||
@KeySql(useGeneratedKeys = true)
|
||||
private Long id;
|
||||
private Long id;
|
||||
/**
|
||||
* The Device type.
|
||||
*/
|
||||
|
@ -39,12 +39,18 @@ public class ControlDevice {
|
|||
/**
|
||||
* The Device addr.
|
||||
*/
|
||||
private String deviceAddr;
|
||||
private String deviceAddr;
|
||||
|
||||
private Integer sendEnabled;
|
||||
|
||||
private Integer beidouStatus;
|
||||
|
||||
private String beidouChannelStatus;
|
||||
|
||||
/**
|
||||
* The Beidou signal strength.
|
||||
*/
|
||||
private String beidouSignalStrength;
|
||||
private String beidouSignalStrength;
|
||||
/**
|
||||
* The Wireless status.
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.zjyr.beidouservice.pojo.po;
|
||||
|
||||
import com.zjyr.beidouservice.common.impl.SensorControlActionName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -14,7 +13,7 @@ public class BeidouAdapterControlContent {
|
|||
/**
|
||||
* The Control action.
|
||||
*/
|
||||
private SensorControlActionName controlAction;
|
||||
//private SensorControlActionName controlAction;
|
||||
/**
|
||||
* The Sensor id.
|
||||
*/
|
||||
|
|
|
@ -13,7 +13,7 @@ public class BeidouAdapterDevice {
|
|||
/**
|
||||
* The Id.
|
||||
*/
|
||||
private Long id;
|
||||
private long id;
|
||||
/**
|
||||
* The Adapter type.
|
||||
*/
|
||||
|
@ -21,17 +21,20 @@ public class BeidouAdapterDevice {
|
|||
/**
|
||||
* The Adapter addr.
|
||||
*/
|
||||
private String adapterAddr;
|
||||
private String adapterAddr;
|
||||
private int sendEnabled;
|
||||
private int beidouStatus;
|
||||
private String beidouChannelStatus;
|
||||
/**
|
||||
* The Beidou signal strength.
|
||||
*/
|
||||
private String beidouSignalStrength;
|
||||
private String beidouSignalStrength;
|
||||
/**
|
||||
* The Wireless status.
|
||||
*/
|
||||
private Integer wirelessStatus;
|
||||
private int wirelessStatus;
|
||||
/**
|
||||
* The Telphone status.
|
||||
*/
|
||||
private Integer telphoneStatus;
|
||||
private int telphoneStatus;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.zjyr.beidouservice.pojo.vo.binary;
|
||||
|
||||
import com.zjyr.beidouservice.common.impl.SensorStatusName;
|
||||
import com.zjyr.beidouservice.common.impl.*;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -10,16 +10,14 @@ import lombok.Data;
|
|||
@Data
|
||||
@Builder
|
||||
public class ControllerStatus {
|
||||
private byte[] beidouFreq;
|
||||
/**
|
||||
* The Beidou signal strength.
|
||||
*/
|
||||
private byte[] beidouSignalStrength;
|
||||
/**
|
||||
* The Wireless status.
|
||||
*/
|
||||
private SensorStatusName wirelessStatus;
|
||||
/**
|
||||
* The Telphone status.
|
||||
*/
|
||||
private SensorStatusName telphoneStatus;
|
||||
private SendStatusName sendStatus;
|
||||
private ControlChannelStatus beidouStatus;
|
||||
private ControlChannelStatus wirelessStatus;
|
||||
private ControlChannelStatus telphoneStatus;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.zjyr.beidouservice.pojo.vo.binary;
|
||||
|
||||
import com.zjyr.beidouservice.common.impl.SensorControlActionName;
|
||||
//import com.zjyr.beidouservice.common.impl.SensorControlActionName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -17,7 +17,7 @@ public class SensorControllContent {
|
|||
/**
|
||||
* The Control action.
|
||||
*/
|
||||
private SensorControlActionName controlAction;
|
||||
//private SensorControlActionName controlAction;
|
||||
/**
|
||||
* The Sensor id.
|
||||
*/
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package com.zjyr.beidouservice.pojo.vo.binary;
|
||||
|
||||
import com.zjyr.beidouservice.common.impl.BeidouStatusName;
|
||||
import com.zjyr.beidouservice.common.impl.SendStatusName;
|
||||
import com.zjyr.beidouservice.common.impl.TelphoneStatusName;
|
||||
import com.zjyr.beidouservice.common.impl.WirelessStatusName;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
public class SensorCotrolAck {
|
||||
private byte[] beidouFreq;
|
||||
|
||||
private SendStatusName sendStatus;
|
||||
private BeidouStatusName beidouStatus;
|
||||
private WirelessStatusName wirelessStatus;
|
||||
private TelphoneStatusName telphoneStatus;
|
||||
}
|
|
@ -9,7 +9,6 @@ import com.zjyr.beidouservice.pojo.entry.ControlDevice;
|
|||
import com.zjyr.beidouservice.pojo.po.BeidouAdapterDevice;
|
||||
import com.zjyr.beidouservice.pojo.vo.ControlAdapterSocketCtx;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.ControllerStatus;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.SensorCotrolAck;
|
||||
import com.zjyr.beidouservice.pojo.vo.binary.SensorStatusAck;
|
||||
import com.zjyr.beidouservice.service.AdapterProtocolService;
|
||||
import com.zjyr.beidouservice.service.BaidouAdapterService;
|
||||
|
@ -33,7 +32,7 @@ import static com.zjyr.beidouservice.common.impl.SocketEventName.SOCKET_EVT_CONN
|
|||
@Slf4j
|
||||
|
||||
public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implements BaidouAdapterService,
|
||||
ApplicationListener<T> {
|
||||
ApplicationListener<T> {
|
||||
|
||||
private final ConcurrentHashMap<Long, ControlAdapterSocketCtx> ctxMap = new ConcurrentHashMap<>();
|
||||
@Resource
|
||||
|
@ -74,15 +73,14 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
|||
if (evtContent instanceof SocketNotifyEvent event) {
|
||||
InetSocketAddress sa = (InetSocketAddress) event.getCtxChannel().remoteAddress();
|
||||
switch (event.getSocketEvent()) {
|
||||
case SOCKET_EVT_CONNECT, SOCKET_EVT_IDLE_TIMEOUT -> {
|
||||
case SOCKET_EVT_CONNECT -> {
|
||||
sendCommond(event.getCtxChannel(), adapterProtocolService.createHeartProtocol());
|
||||
|
||||
if (event.getSocketEvent() == SOCKET_EVT_CONNECT) {
|
||||
|
||||
BeidouAdapterDevice a = BeidouAdapterDevice.builder()
|
||||
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
|
||||
.adapterAddr(sa.getAddress().getHostAddress())
|
||||
.build();
|
||||
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
|
||||
.adapterAddr(sa.getAddress().getHostAddress())
|
||||
.build();
|
||||
addNewBeidouAdapter(a);
|
||||
|
||||
ControlAdapterSocketCtx sockCtx = new ControlAdapterSocketCtx(a.getId(), event.getCtxChannel());
|
||||
|
@ -90,6 +88,10 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
|||
}
|
||||
}
|
||||
|
||||
case SOCKET_EVT_IDLE_TIMEOUT -> {
|
||||
sendCommond(event.getCtxChannel(), adapterProtocolService.createHeartProtocol());
|
||||
}
|
||||
|
||||
case SOCKET_EVT_DISCONNECT -> {
|
||||
for (ConcurrentHashMap.Entry<Long, ControlAdapterSocketCtx> entry : ctxMap.entrySet()) {
|
||||
if (entry.getValue().getChannel().id() == event.getCtxChannel().id()) {
|
||||
|
@ -101,17 +103,28 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
|||
case SOCKET_EVT_RECV -> {
|
||||
if (event.getEvtMessage() instanceof ControllerStatus status) {
|
||||
log.info("+++{}, {}, {}",
|
||||
status.getWirelessStatus(),
|
||||
status.getTelphoneStatus(),
|
||||
HelperUtils.bytesToHexString(status.getBeidouSignalStrength()));
|
||||
} else if (event.getEvtMessage() instanceof SensorCotrolAck ack) {
|
||||
status.getWirelessStatus(),
|
||||
status.getTelphoneStatus(),
|
||||
HelperUtils.bytesToHexString(status.getBeidouSignalStrength()));
|
||||
BeidouAdapterDevice a = BeidouAdapterDevice.builder()
|
||||
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
|
||||
.adapterAddr(sa.getAddress().getHostAddress())
|
||||
.sendEnabled(status.getSendStatus().getValue())
|
||||
.beidouStatus(status.getBeidouStatus().getValue())
|
||||
.beidouChannelStatus(HelperUtils.bytesToHexString(status.getBeidouFreq()))
|
||||
.beidouSignalStrength(HelperUtils.bytesToHexString(status.getBeidouSignalStrength()))
|
||||
.wirelessStatus(status.getWirelessStatus().getValue())
|
||||
.telphoneStatus(status.getTelphoneStatus().getValue())
|
||||
.build();
|
||||
addNewBeidouAdapter(a);
|
||||
} /*else if (event.getEvtMessage() instanceof SensorCotrolAck ack) {
|
||||
log.info("+++{}, {}, {}, {}, {}",
|
||||
ack.getSendStatus(),
|
||||
ack.getBeidouStatus(),
|
||||
ack.getWirelessStatus(),
|
||||
ack.getTelphoneStatus(),
|
||||
HelperUtils.bytesToHexString(ack.getBeidouFreq()));
|
||||
} else if (event.getEvtMessage() instanceof SensorStatusAck ack) {
|
||||
}*/ else if (event.getEvtMessage() instanceof SensorStatusAck ack) {
|
||||
log.info("+++Total Sensors: {}", ack.getSensorStatus().size());
|
||||
sensorDataService.addNewSensor(ack.getSensorStatus());
|
||||
}
|
||||
|
@ -129,13 +142,13 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
|||
|
||||
for (ControlDevice c : controlDevices) {
|
||||
adapterDevices.add(BeidouAdapterDevice.builder()
|
||||
.id(c.getId())
|
||||
.adapterType(c.getDeviceType())
|
||||
.adapterAddr(c.getDeviceAddr())
|
||||
.beidouSignalStrength(c.getBeidouSignalStrength())
|
||||
.wirelessStatus(c.getWirelessStatus())
|
||||
.telphoneStatus(c.getTelphoneStatus())
|
||||
.build());
|
||||
.id(c.getId())
|
||||
.adapterType(c.getDeviceType())
|
||||
.adapterAddr(c.getDeviceAddr())
|
||||
.beidouSignalStrength(c.getBeidouSignalStrength())
|
||||
.wirelessStatus(c.getWirelessStatus())
|
||||
.telphoneStatus(c.getTelphoneStatus())
|
||||
.build());
|
||||
}
|
||||
|
||||
return adapterDevices;
|
||||
|
@ -147,13 +160,16 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
|
|||
@Override
|
||||
public void addNewBeidouAdapter(BeidouAdapterDevice adapter) {
|
||||
ControlDevice device = ControlDevice.builder()
|
||||
.id(adapter.getId())
|
||||
.deviceType(adapter.getAdapterType())
|
||||
.deviceAddr(adapter.getAdapterAddr())
|
||||
.beidouSignalStrength(adapter.getBeidouSignalStrength())
|
||||
.wirelessStatus(adapter.getWirelessStatus())
|
||||
.telphoneStatus(adapter.getTelphoneStatus())
|
||||
.build();
|
||||
.id(adapter.getId())
|
||||
.deviceType(adapter.getAdapterType())
|
||||
.deviceAddr(adapter.getAdapterAddr())
|
||||
.beidouStatus(adapter.getBeidouStatus())
|
||||
.sendEnabled(adapter.getSendEnabled())
|
||||
.beidouChannelStatus(adapter.getBeidouChannelStatus())
|
||||
.beidouSignalStrength(adapter.getBeidouSignalStrength())
|
||||
.wirelessStatus(adapter.getWirelessStatus())
|
||||
.telphoneStatus(adapter.getTelphoneStatus())
|
||||
.build();
|
||||
BeidouAdapterDevice dev = getAdapterByAddr(adapter.getAdapterAddr());
|
||||
if (dev == null) {
|
||||
controlDeviceMapper.addControlDevice(device);
|
||||
|
|
|
@ -31,7 +31,7 @@ public class BeidouSocketProtocolServiceImpl implements AdapterProtocolService {
|
|||
for (BeidouAdapterControlContent v : ctxList) {
|
||||
list.add(SensorControllContent.builder()
|
||||
.districtsCode(v.getDistrictsCode().byteValue())
|
||||
.controlAction(v.getControlAction())
|
||||
//.controlAction(v.getControlAction())
|
||||
.sensorId(v.getSensorId().shortValue())
|
||||
.build());
|
||||
}
|
||||
|
|
|
@ -5,29 +5,59 @@
|
|||
<id column="id" property="id"/>
|
||||
<result column="deviceType" property="deviceType"/>
|
||||
<result column="deviceAddr" property="deviceAddr"/>
|
||||
<result column="sendEnabled" property="sendEnabled"/>
|
||||
<result column="beidouStatus" property="beidouStatus"/>
|
||||
<result column="beidouChannelStatus" property="beidouChannelStatus"/>
|
||||
<result column="beidouSignalStrength" property="beidouSignalStrength"/>
|
||||
<result column="wirelessStatus" property="wirelessStatus"/>
|
||||
<result column="telphoneStatus" property="telphoneStatus"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectAll" resultMap="control_device">
|
||||
SELECT id, deviceAddr, deviceType, beidouSignalStrength, wirelessStatus, telphoneStatus
|
||||
SELECT id,
|
||||
deviceAddr,
|
||||
deviceType,
|
||||
sendEnabled,
|
||||
beidouStatus,
|
||||
beidouChannelStatus,
|
||||
beidouSignalStrength,
|
||||
wirelessStatus,
|
||||
telphoneStatus
|
||||
FROM control_device
|
||||
</select>
|
||||
|
||||
<update id="upgradeControlDevice" parameterType="com.zjyr.beidouservice.pojo.entry.ControlDevice">
|
||||
UPDATE control_device
|
||||
SET beidouSignalStrength = #{dev.beidouSignalStrength},
|
||||
wirelessStatus = #{dev.wirelessStatus},
|
||||
telphoneStatus = #{dev.telphoneStatus}
|
||||
WHERE deviceAddr = #{dev.deviceAddr}
|
||||
INSERT IGNORE INTO control_device(deviceAddr, deviceType, sendEnabled, beidouStatus, beidouChannelStatus,
|
||||
beidouSignalStrength, wirelessStatus, telphoneStatus)
|
||||
SELECT #{device.deviceAddr},
|
||||
#{device.deviceType},
|
||||
#{device.sendEnabled},
|
||||
#{device.beidouStatus},
|
||||
#{device.beidouChannelStatus},
|
||||
#{device.beidouSignalStrength},
|
||||
#{device.wirelessStatus},
|
||||
#{device.telphoneStatus}
|
||||
FROM DUAL
|
||||
WHERE NOT EXISTS (SELECT deviceAddr
|
||||
FROM control_device
|
||||
WHERE deviceAddr = #{device.deviceAddr})
|
||||
</update>
|
||||
|
||||
<insert id="addControlDevice" useGeneratedKeys="true" keyProperty="id"
|
||||
parameterType="com.zjyr.beidouservice.pojo.entry.ControlDevice">
|
||||
INSERT IGNORE INTO control_device(deviceAddr, deviceType, beidouSignalStrength, wirelessStatus, telphoneStatus)
|
||||
SELECT #{device.deviceAddr}, #{device.deviceType}, #{device.beidouSignalStrength}, #{device.wirelessStatus},
|
||||
#{device.telphoneStatus} FROM DUAL WHERE NOT EXISTS (SELECT deviceAddr FROM control_device
|
||||
WHERE deviceAddr = #{device.deviceAddr})
|
||||
INSERT IGNORE INTO control_device(deviceAddr, deviceType, sendEnabled, beidouStatus, beidouChannelStatus,
|
||||
beidouSignalStrength, wirelessStatus, telphoneStatus)
|
||||
SELECT #{device.deviceAddr},
|
||||
#{device.deviceType},
|
||||
#{device.sendEnabled},
|
||||
#{device.beidouStatus},
|
||||
#{device.beidouChannelStatus},
|
||||
#{device.beidouSignalStrength},
|
||||
#{device.wirelessStatus},
|
||||
#{device.telphoneStatus}
|
||||
FROM DUAL
|
||||
WHERE NOT EXISTS (SELECT deviceAddr
|
||||
FROM control_device
|
||||
WHERE deviceAddr = #{device.deviceAddr})
|
||||
</insert>
|
||||
</mapper>
|
Loading…
Reference in New Issue