1. 修改心跳协议以及控制器状态回复协议

This commit is contained in:
黄昕 2023-08-21 14:55:09 +08:00
parent 28c904076a
commit 1faa9ff0ca
17 changed files with 223 additions and 377 deletions

View File

@ -1,20 +1,12 @@
package com.zjyr.beidouservice.adapter.impl.netty.decode; package com.zjyr.beidouservice.adapter.impl.netty.decode;
import com.zjyr.beidouservice.common.CommonEnumHandler; 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.ControlCommandName;
import com.zjyr.beidouservice.common.impl.SendStatusName; import com.zjyr.beidouservice.common.impl.SendStatusName;
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName; 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.misc.HelperUtils;
import com.zjyr.beidouservice.pojo.vo.binary.BaseBinaryProtocol; import com.zjyr.beidouservice.pojo.vo.binary.*;
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 io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil; import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
@ -50,16 +42,24 @@ public class YuanRongProtocolDecode extends ByteToMessageDecoder {
if (cmd != null) { if (cmd != null) {
switch (cmd) { switch (cmd) {
case COMMAND_REPORT_HEART -> { 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]; byte[] beidouSignal = new byte[10];
buf.readBytes(beidouSignal, 0, 10); buf.readBytes(beidouSignal, 0, 10);
SensorStatusName wireStatus = CommonEnumHandler.codeOf(SensorStatusName.class, buf.readByte()); ControlChannelStatus wireStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class, buf.readByte());
SensorStatusName phoneStatus = CommonEnumHandler.codeOf(SensorStatusName.class, buf.readByte()); ControlChannelStatus phoneStatus = CommonEnumHandler.codeOf(ControlChannelStatus.class, buf.readByte());
ControllerStatus status = ControllerStatus.builder() ControllerStatus status = ControllerStatus.builder()
.sendStatus(sendStatus)
.beidouStatus(beidouStatus)
.beidouFreq(beidouCommFreq)
.beidouSignalStrength(beidouSignal) .beidouSignalStrength(beidouSignal)
.wirelessStatus(wireStatus) .wirelessStatus(wireStatus)
.telphoneStatus(phoneStatus) .telphoneStatus(phoneStatus)
.build(); .build();
MessageContent<ControllerStatus> msgCtx = MessageContent.<ControllerStatus>builder().msgType( MessageContent<ControllerStatus> msgCtx = MessageContent.<ControllerStatus>builder().msgType(
msgType).msgSize(msgSize).msgBody(status).build(); msgType).msgSize(msgSize).msgBody(status).build();
@ -74,35 +74,35 @@ public class YuanRongProtocolDecode extends ByteToMessageDecoder {
.build()); .build());
} }
case COMMAND_REPORT_SENSOR -> { case COMMAND_REPORT_SENSOR -> {
SendStatusName sendStatus = CommonEnumHandler.codeOf(SendStatusName.class, buf.readByte()); // SendStatusName sendStatus = CommonEnumHandler.codeOf(SendStatusName.class, buf.readByte());
BeidouStatusName beidouStatus = CommonEnumHandler.codeOf(BeidouStatusName.class, // BeidouStatusName beidouStatus = CommonEnumHandler.codeOf(BeidouStatusName.class,
buf.readByte()); // buf.readByte());
WirelessStatusName wireStatus = CommonEnumHandler.codeOf(WirelessStatusName.class, // WirelessStatusName wireStatus = CommonEnumHandler.codeOf(WirelessStatusName.class,
buf.readByte()); // buf.readByte());
TelphoneStatusName phoneStatus = CommonEnumHandler.codeOf(TelphoneStatusName.class, // TelphoneStatusName phoneStatus = CommonEnumHandler.codeOf(TelphoneStatusName.class,
buf.readByte()); // buf.readByte());
byte[] beidouSignle = new byte[3]; // byte[] beidouSignle = new byte[3];
buf.readBytes(beidouSignle, 0, 3); // buf.readBytes(beidouSignle, 0, 3);
//
SensorCotrolAck ack = SensorCotrolAck.builder() // SensorCotrolAck ack = SensorCotrolAck.builder()
.sendStatus(sendStatus) // .sendStatus(sendStatus)
.beidouStatus(beidouStatus) // .beidouStatus(beidouStatus)
.wirelessStatus(wireStatus) // .wirelessStatus(wireStatus)
.telphoneStatus(phoneStatus) // .telphoneStatus(phoneStatus)
.beidouFreq(beidouSignle) // .beidouFreq(beidouSignle)
.build(); // .build();
//
MessageContent<SensorCotrolAck> msgCtx = MessageContent.<SensorCotrolAck>builder().msgType( // MessageContent<SensorCotrolAck> msgCtx = MessageContent.<SensorCotrolAck>builder().msgType(
msgType).msgSize(msgSize).msgBody(ack).build(); // msgType).msgSize(msgSize).msgBody(ack).build();
list.add(BaseBinaryProtocol.<SensorCotrolAck>builder() // list.add(BaseBinaryProtocol.<SensorCotrolAck>builder()
.msgLength(msgLength) // .msgLength(msgLength)
.version(version) // .version(version)
.commandId(commandId) // .commandId(commandId)
.cryptoType(cryptCytp) // .cryptoType(cryptCytp)
.timeStamp(timeStamp) // .timeStamp(timeStamp)
.statusCode(statusCode) // .statusCode(statusCode)
.msgContent(msgCtx) // .msgContent(msgCtx)
.build()); // .build());
} }
case COMMAND_REPORT_QUERY_SENSOR -> { case COMMAND_REPORT_QUERY_SENSOR -> {
int nItems = buf.readByte(); int nItems = buf.readByte();

View File

@ -62,7 +62,7 @@ public class YuanRongProtocolEncode<T> extends MessageToByteEncoder<BaseBinaryPr
byteBuf.writeByte(msg.getNControlInfo()); byteBuf.writeByte(msg.getNControlInfo());
for (var c : msg.getControllContents()) { for (var c : msg.getControllContents()) {
byteBuf.writeByte(c.getDistrictsCode()); byteBuf.writeByte(c.getDistrictsCode());
byteBuf.writeByte(c.getControlAction().getValue().byteValue()); //byteBuf.writeByte(c.getControlAction().getValue().byteValue());
byteBuf.writeShort(c.getSensorId()); byteBuf.writeShort(c.getSensorId());
} }
} }
@ -76,7 +76,7 @@ public class YuanRongProtocolEncode<T> extends MessageToByteEncoder<BaseBinaryPr
byteBuf.writeByte(msg.getNControlInfo()); byteBuf.writeByte(msg.getNControlInfo());
for (var c : msg.getControllContents()) { for (var c : msg.getControllContents()) {
byteBuf.writeByte(c.getDistrictsCode()); byteBuf.writeByte(c.getDistrictsCode());
byteBuf.writeByte(c.getControlAction().getValue().byteValue()); //byteBuf.writeByte(c.getControlAction().getValue().byteValue());
byteBuf.writeShort(c.getSensorId()); byteBuf.writeShort(c.getSensorId());
} }
} }

View File

@ -2,10 +2,12 @@ package com.zjyr.beidouservice.common.impl;
import com.zjyr.beidouservice.common.EnumerationBase; import com.zjyr.beidouservice.common.EnumerationBase;
public enum BeidouStatusName implements EnumerationBase { public enum ControlChannelStatus implements EnumerationBase {
BEIDOU_NORMAL(0, "BEIDOU_NORMAL"), CHANNEL_NORMAL(0, "CHANNEL_NORMAL"),
BEIDOU_MODULE_EXCEPTION(1, "BEIDOU_MODULE_EXCEPTION"), CHANNEL_MODULE_UNEXISTS(1, "CHANNEL_MODULE_UNEXISTS"),
BEIDOU_SATELLITE_EXCEPTION(2, "BEIDOU_SATELLITE_EXCEPTION"), 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 val the val
* @param desc the desc * @param desc the desc
*/ */
BeidouStatusName(int val, String desc) { ControlChannelStatus(int val, String desc) {
this.code = val; this.code = val;
this.desc = desc; this.desc = desc;
} }

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -1,6 +1,5 @@
package com.zjyr.beidouservice.controller; 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.SensorControlModeName;
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName; import com.zjyr.beidouservice.common.impl.SensorControlTunnelName;
import com.zjyr.beidouservice.pojo.dto.BaseProtocolDTO; import com.zjyr.beidouservice.pojo.dto.BaseProtocolDTO;
@ -62,11 +61,11 @@ public class AuthUser {
List<BeidouAdapterControlContent> adapterInfo = new ArrayList<>(); List<BeidouAdapterControlContent> adapterInfo = new ArrayList<>();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
adapterInfo.add(BeidouAdapterControlContent.builder() // adapterInfo.add(BeidouAdapterControlContent.builder()
.districtsCode(0x10 + i) // .districtsCode(0x10 + i)
.sensorId(0x3f00 + i) // .sensorId(0x3f00 + i)
.controlAction(SensorControlActionName.ACTION_DISTRICTS_BASED) // .controlAction(SensorControlActionName.ACTION_DISTRICTS_BASED)
.build()); // .build());
} }
SensorControlProtocol sp = SensorControlProtocol sp =

View File

@ -41,6 +41,12 @@ public class ControlDevice {
*/ */
private String deviceAddr; private String deviceAddr;
private Integer sendEnabled;
private Integer beidouStatus;
private String beidouChannelStatus;
/** /**
* The Beidou signal strength. * The Beidou signal strength.
*/ */

View File

@ -1,6 +1,5 @@
package com.zjyr.beidouservice.pojo.po; package com.zjyr.beidouservice.pojo.po;
import com.zjyr.beidouservice.common.impl.SensorControlActionName;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -14,7 +13,7 @@ public class BeidouAdapterControlContent {
/** /**
* The Control action. * The Control action.
*/ */
private SensorControlActionName controlAction; //private SensorControlActionName controlAction;
/** /**
* The Sensor id. * The Sensor id.
*/ */

View File

@ -13,7 +13,7 @@ public class BeidouAdapterDevice {
/** /**
* The Id. * The Id.
*/ */
private Long id; private long id;
/** /**
* The Adapter type. * The Adapter type.
*/ */
@ -22,6 +22,9 @@ public class BeidouAdapterDevice {
* The Adapter addr. * The Adapter addr.
*/ */
private String adapterAddr; private String adapterAddr;
private int sendEnabled;
private int beidouStatus;
private String beidouChannelStatus;
/** /**
* The Beidou signal strength. * The Beidou signal strength.
*/ */
@ -29,9 +32,9 @@ public class BeidouAdapterDevice {
/** /**
* The Wireless status. * The Wireless status.
*/ */
private Integer wirelessStatus; private int wirelessStatus;
/** /**
* The Telphone status. * The Telphone status.
*/ */
private Integer telphoneStatus; private int telphoneStatus;
} }

View File

@ -1,6 +1,6 @@
package com.zjyr.beidouservice.pojo.vo.binary; 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.Builder;
import lombok.Data; import lombok.Data;
@ -10,16 +10,14 @@ import lombok.Data;
@Data @Data
@Builder @Builder
public class ControllerStatus { public class ControllerStatus {
private byte[] beidouFreq;
/** /**
* The Beidou signal strength. * The Beidou signal strength.
*/ */
private byte[] beidouSignalStrength; private byte[] beidouSignalStrength;
/** private SendStatusName sendStatus;
* The Wireless status. private ControlChannelStatus beidouStatus;
*/ private ControlChannelStatus wirelessStatus;
private SensorStatusName wirelessStatus; private ControlChannelStatus telphoneStatus;
/**
* The Telphone status.
*/
private SensorStatusName telphoneStatus;
} }

View File

@ -1,6 +1,6 @@
package com.zjyr.beidouservice.pojo.vo.binary; 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.Builder;
import lombok.Data; import lombok.Data;
@ -17,7 +17,7 @@ public class SensorControllContent {
/** /**
* The Control action. * The Control action.
*/ */
private SensorControlActionName controlAction; //private SensorControlActionName controlAction;
/** /**
* The Sensor id. * The Sensor id.
*/ */

View File

@ -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;
}

View File

@ -9,7 +9,6 @@ import com.zjyr.beidouservice.pojo.entry.ControlDevice;
import com.zjyr.beidouservice.pojo.po.BeidouAdapterDevice; import com.zjyr.beidouservice.pojo.po.BeidouAdapterDevice;
import com.zjyr.beidouservice.pojo.vo.ControlAdapterSocketCtx; import com.zjyr.beidouservice.pojo.vo.ControlAdapterSocketCtx;
import com.zjyr.beidouservice.pojo.vo.binary.ControllerStatus; 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.pojo.vo.binary.SensorStatusAck;
import com.zjyr.beidouservice.service.AdapterProtocolService; import com.zjyr.beidouservice.service.AdapterProtocolService;
import com.zjyr.beidouservice.service.BaidouAdapterService; import com.zjyr.beidouservice.service.BaidouAdapterService;
@ -74,11 +73,10 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
if (evtContent instanceof SocketNotifyEvent event) { if (evtContent instanceof SocketNotifyEvent event) {
InetSocketAddress sa = (InetSocketAddress) event.getCtxChannel().remoteAddress(); InetSocketAddress sa = (InetSocketAddress) event.getCtxChannel().remoteAddress();
switch (event.getSocketEvent()) { switch (event.getSocketEvent()) {
case SOCKET_EVT_CONNECT, SOCKET_EVT_IDLE_TIMEOUT -> { case SOCKET_EVT_CONNECT -> {
sendCommond(event.getCtxChannel(), adapterProtocolService.createHeartProtocol()); sendCommond(event.getCtxChannel(), adapterProtocolService.createHeartProtocol());
if (event.getSocketEvent() == SOCKET_EVT_CONNECT) { if (event.getSocketEvent() == SOCKET_EVT_CONNECT) {
BeidouAdapterDevice a = BeidouAdapterDevice.builder() BeidouAdapterDevice a = BeidouAdapterDevice.builder()
.adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP) .adapterType(BeidouAdapterTypeName.ADAPTER_SOCKET_TCP)
.adapterAddr(sa.getAddress().getHostAddress()) .adapterAddr(sa.getAddress().getHostAddress())
@ -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 -> { case SOCKET_EVT_DISCONNECT -> {
for (ConcurrentHashMap.Entry<Long, ControlAdapterSocketCtx> entry : ctxMap.entrySet()) { for (ConcurrentHashMap.Entry<Long, ControlAdapterSocketCtx> entry : ctxMap.entrySet()) {
if (entry.getValue().getChannel().id() == event.getCtxChannel().id()) { if (entry.getValue().getChannel().id() == event.getCtxChannel().id()) {
@ -104,14 +106,25 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
status.getWirelessStatus(), status.getWirelessStatus(),
status.getTelphoneStatus(), status.getTelphoneStatus(),
HelperUtils.bytesToHexString(status.getBeidouSignalStrength())); HelperUtils.bytesToHexString(status.getBeidouSignalStrength()));
} else if (event.getEvtMessage() instanceof SensorCotrolAck ack) { 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("+++{}, {}, {}, {}, {}", log.info("+++{}, {}, {}, {}, {}",
ack.getSendStatus(), ack.getSendStatus(),
ack.getBeidouStatus(), ack.getBeidouStatus(),
ack.getWirelessStatus(), ack.getWirelessStatus(),
ack.getTelphoneStatus(), ack.getTelphoneStatus(),
HelperUtils.bytesToHexString(ack.getBeidouFreq())); 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()); log.info("+++Total Sensors: {}", ack.getSensorStatus().size());
sensorDataService.addNewSensor(ack.getSensorStatus()); sensorDataService.addNewSensor(ack.getSensorStatus());
} }
@ -150,6 +163,9 @@ public class BaidouSocketAdapterServiceImpl<T extends ApplicationEvent> implemen
.id(adapter.getId()) .id(adapter.getId())
.deviceType(adapter.getAdapterType()) .deviceType(adapter.getAdapterType())
.deviceAddr(adapter.getAdapterAddr()) .deviceAddr(adapter.getAdapterAddr())
.beidouStatus(adapter.getBeidouStatus())
.sendEnabled(adapter.getSendEnabled())
.beidouChannelStatus(adapter.getBeidouChannelStatus())
.beidouSignalStrength(adapter.getBeidouSignalStrength()) .beidouSignalStrength(adapter.getBeidouSignalStrength())
.wirelessStatus(adapter.getWirelessStatus()) .wirelessStatus(adapter.getWirelessStatus())
.telphoneStatus(adapter.getTelphoneStatus()) .telphoneStatus(adapter.getTelphoneStatus())

View File

@ -31,7 +31,7 @@ public class BeidouSocketProtocolServiceImpl implements AdapterProtocolService {
for (BeidouAdapterControlContent v : ctxList) { for (BeidouAdapterControlContent v : ctxList) {
list.add(SensorControllContent.builder() list.add(SensorControllContent.builder()
.districtsCode(v.getDistrictsCode().byteValue()) .districtsCode(v.getDistrictsCode().byteValue())
.controlAction(v.getControlAction()) //.controlAction(v.getControlAction())
.sensorId(v.getSensorId().shortValue()) .sensorId(v.getSensorId().shortValue())
.build()); .build());
} }

View File

@ -5,29 +5,59 @@
<id column="id" property="id"/> <id column="id" property="id"/>
<result column="deviceType" property="deviceType"/> <result column="deviceType" property="deviceType"/>
<result column="deviceAddr" property="deviceAddr"/> <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="beidouSignalStrength" property="beidouSignalStrength"/>
<result column="wirelessStatus" property="wirelessStatus"/> <result column="wirelessStatus" property="wirelessStatus"/>
<result column="telphoneStatus" property="telphoneStatus"/> <result column="telphoneStatus" property="telphoneStatus"/>
</resultMap> </resultMap>
<select id="selectAll" resultMap="control_device"> <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 FROM control_device
</select> </select>
<update id="upgradeControlDevice" parameterType="com.zjyr.beidouservice.pojo.entry.ControlDevice"> <update id="upgradeControlDevice" parameterType="com.zjyr.beidouservice.pojo.entry.ControlDevice">
UPDATE control_device INSERT IGNORE INTO control_device(deviceAddr, deviceType, sendEnabled, beidouStatus, beidouChannelStatus,
SET beidouSignalStrength = #{dev.beidouSignalStrength}, beidouSignalStrength, wirelessStatus, telphoneStatus)
wirelessStatus = #{dev.wirelessStatus}, SELECT #{device.deviceAddr},
telphoneStatus = #{dev.telphoneStatus} #{device.deviceType},
WHERE deviceAddr = #{dev.deviceAddr} #{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> </update>
<insert id="addControlDevice" useGeneratedKeys="true" keyProperty="id" <insert id="addControlDevice" useGeneratedKeys="true" keyProperty="id"
parameterType="com.zjyr.beidouservice.pojo.entry.ControlDevice"> parameterType="com.zjyr.beidouservice.pojo.entry.ControlDevice">
INSERT IGNORE INTO control_device(deviceAddr, deviceType, beidouSignalStrength, wirelessStatus, telphoneStatus) INSERT IGNORE INTO control_device(deviceAddr, deviceType, sendEnabled, beidouStatus, beidouChannelStatus,
SELECT #{device.deviceAddr}, #{device.deviceType}, #{device.beidouSignalStrength}, #{device.wirelessStatus}, beidouSignalStrength, wirelessStatus, telphoneStatus)
#{device.telphoneStatus} FROM DUAL WHERE NOT EXISTS (SELECT deviceAddr FROM control_device 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}) WHERE deviceAddr = #{device.deviceAddr})
</insert> </insert>
</mapper> </mapper>