|
|
|
@ -36,10 +36,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
import java.util.concurrent.CountDownLatch;
|
|
|
|
|
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static cc.iotkit.plugins.emqx.conf.BCDClockGenerator.formatBCDToHex;
|
|
|
|
import static cc.iotkit.plugins.emqx.conf.BCDClockGenerator.formatBCDToHex;
|
|
|
|
import static cc.iotkit.plugins.emqx.conf.BCDClockGenerator.generateBCDTime;
|
|
|
|
import static cc.iotkit.plugins.emqx.conf.BCDClockGenerator.generateBCDTime;
|
|
|
|
@ -89,6 +86,18 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
|
|
|
|
|
|
|
|
public static final Map<String, Set<String>> CLIENT_DEVICE_MAP = new HashMap<>();
|
|
|
|
public static final Map<String, Set<String>> CLIENT_DEVICE_MAP = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//定义一个线程池,线程池大小时cpu的2倍
|
|
|
|
|
|
|
|
// 创建线程池,大小为CPU核心数的2倍
|
|
|
|
|
|
|
|
private static ExecutorService statusThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
|
|
|
|
// 创建线程池,大小为CPU核心数的2倍
|
|
|
|
|
|
|
|
private static ExecutorService threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建线程池,大小为CPU核心数的2倍
|
|
|
|
|
|
|
|
private static ExecutorService sxsbThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 创建线程池,大小为CPU核心数的2倍
|
|
|
|
|
|
|
|
private static ExecutorService onlineThreadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
|
|
|
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
|
|
@PostConstruct
|
|
|
|
public void init() {
|
|
|
|
public void init() {
|
|
|
|
vertx = Vertx.vertx();
|
|
|
|
vertx = Vertx.vertx();
|
|
|
|
@ -175,6 +184,12 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
log.error("client connect fail: ", s.cause());
|
|
|
|
log.error("client connect fail: ", s.cause());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).publishHandler(msg -> {
|
|
|
|
}).publishHandler(msg -> {
|
|
|
|
|
|
|
|
// 获取当前线程对象
|
|
|
|
|
|
|
|
Thread currentThread = Thread.currentThread();
|
|
|
|
|
|
|
|
// 获取当前线程的 ID
|
|
|
|
|
|
|
|
long threadId = currentThread.getId();
|
|
|
|
|
|
|
|
long start = System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=189{}",threadId+":"+start);
|
|
|
|
String topic = msg.topicName();
|
|
|
|
String topic = msg.topicName();
|
|
|
|
log.info("topic={}",topic);
|
|
|
|
log.info("topic={}",topic);
|
|
|
|
if (topic.contains("/request/")) {
|
|
|
|
if (topic.contains("/request/")) {
|
|
|
|
@ -203,7 +218,8 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
if (device == null) {
|
|
|
|
if (device == null) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long start0 = System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=222{}",threadId+":"+start0);
|
|
|
|
//有消息上报-设备上线
|
|
|
|
//有消息上报-设备上线
|
|
|
|
online("*", device.getDeviceName());
|
|
|
|
online("*", device.getDeviceName());
|
|
|
|
|
|
|
|
|
|
|
|
@ -213,7 +229,8 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
if(StringUtils.isBlank(method)){
|
|
|
|
if(StringUtils.isBlank(method)){
|
|
|
|
method = "thing.event.property.post";
|
|
|
|
method = "thing.event.property.post";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long start1 = System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=229{}",threadId+":"+start1);
|
|
|
|
if (StringUtils.isBlank(method)) {
|
|
|
|
if (StringUtils.isBlank(method)) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -231,6 +248,8 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
mapRaw.put("rawHex", rawHex);
|
|
|
|
mapRaw.put("rawHex", rawHex);
|
|
|
|
mapRaw.put("replyHex", replyHex);
|
|
|
|
mapRaw.put("replyHex", replyHex);
|
|
|
|
Map<String, Object> result = new HashMap<>(mapRaw);
|
|
|
|
Map<String, Object> result = new HashMap<>(mapRaw);
|
|
|
|
|
|
|
|
long start2 = System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=248{}",threadId+":"+start2);
|
|
|
|
if(ObjectUtils.isNotEmpty(cmd)&& ObjectUtils.isNotEmpty(data)){
|
|
|
|
if(ObjectUtils.isNotEmpty(cmd)&& ObjectUtils.isNotEmpty(data)){
|
|
|
|
if(cmd.equals("0x11")){
|
|
|
|
if(cmd.equals("0x11")){
|
|
|
|
|
|
|
|
|
|
|
|
@ -272,25 +291,38 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
.params(result)
|
|
|
|
.params(result)
|
|
|
|
.time(System.currentTimeMillis())
|
|
|
|
.time(System.currentTimeMillis())
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
long start3= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=291{}",threadId+":"+start3);
|
|
|
|
|
|
|
|
statusThreadPool.submit(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
thingService.post(pluginInfo.getPluginId(), action1);
|
|
|
|
thingService.post(pluginInfo.getPluginId(), action1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
long start4= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=299{}",threadId+":"+start4);
|
|
|
|
}else if(cmd.equals("0x12")){
|
|
|
|
}else if(cmd.equals("0x12")){
|
|
|
|
//4.2 燃气报警器物联网模块数据上报(0x12)
|
|
|
|
//4.2 燃气报警器物联网模块数据上报(0x12)
|
|
|
|
GasAlarmDataParser.parseHexDataToList(data).forEach(
|
|
|
|
GasAlarmDataParser.parseHexDataToList(data).forEach(
|
|
|
|
(key, value) -> result.merge(key, value, (v1, v2) -> v2));
|
|
|
|
(key, value) -> result.merge(key, value, (v1, v2) -> v2));
|
|
|
|
payload.put("params",result);
|
|
|
|
payload.put("params",result);
|
|
|
|
|
|
|
|
long start5= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=306{}",threadId+":"+start5);
|
|
|
|
// GasAlarmDataParser.parseHexDataToList(data);
|
|
|
|
// GasAlarmDataParser.parseHexDataToList(data);
|
|
|
|
}else if(cmd.equals("0x14")){
|
|
|
|
}else if(cmd.equals("0x14")){
|
|
|
|
//动火离人数据上报与事件上报
|
|
|
|
//动火离人数据上报与事件上报
|
|
|
|
FireSafetyDataReceiver.handleHexData(data).forEach(
|
|
|
|
FireSafetyDataReceiver.handleHexData(data).forEach(
|
|
|
|
(key, value) -> result.merge(key, value, (v1, v2) -> v2));
|
|
|
|
(key, value) -> result.merge(key, value, (v1, v2) -> v2));
|
|
|
|
payload.put("params",result);
|
|
|
|
payload.put("params",result);
|
|
|
|
|
|
|
|
long start6= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=314{}",threadId+":"+start6);
|
|
|
|
}else if(cmd.equals("0x15")){
|
|
|
|
}else if(cmd.equals("0x15")){
|
|
|
|
//联动控制箱设备状态及参数数据上报
|
|
|
|
//联动控制箱设备状态及参数数据上报
|
|
|
|
LinkageControlDataParser.parseHexDataToList(data).forEach(
|
|
|
|
LinkageControlDataParser.parseHexDataToList(data).forEach(
|
|
|
|
(key, value) -> result.merge(key, value, (v1, v2) -> v2));
|
|
|
|
(key, value) -> result.merge(key, value, (v1, v2) -> v2));
|
|
|
|
payload.put("params",result);
|
|
|
|
payload.put("params",result);
|
|
|
|
|
|
|
|
long start7= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=321{}",threadId+":"+start7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(cmd.equals("0x23")){
|
|
|
|
else if(cmd.equals("0x23")){
|
|
|
|
flag=false;
|
|
|
|
flag=false;
|
|
|
|
@ -307,14 +339,26 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
.time(System.currentTimeMillis())
|
|
|
|
.time(System.currentTimeMillis())
|
|
|
|
.config(payload.getJsonObject("params", defParams).getMap())
|
|
|
|
.config(payload.getJsonObject("params", defParams).getMap())
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
long start8= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=339{}",threadId+":"+start8);
|
|
|
|
|
|
|
|
threadPool.submit(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
thingService.post(pluginInfo.getPluginId(), config);
|
|
|
|
thingService.post(pluginInfo.getPluginId(), config);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
long start9= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=347{}",threadId+":"+start9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(cmd.equals("0x24")){
|
|
|
|
else if(cmd.equals("0x24")){
|
|
|
|
flag=false;
|
|
|
|
flag=false;
|
|
|
|
//下发配置数据的回复
|
|
|
|
//下发配置数据的回复
|
|
|
|
// payload.put("params", FireSafetyDataReceiver.handleHexData(data));
|
|
|
|
// Map<String, Object> mapConfig = FireSafetyDataReceiver.handleHexConfigData(data);
|
|
|
|
|
|
|
|
// if(!mapConfig.isEmpty()) {
|
|
|
|
|
|
|
|
// payload.put("params", mapConfig);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// long start10= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
// log.info("threadId=357{}",threadId+":"+start10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -334,10 +378,9 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
String subPk = params.getString("productKey");
|
|
|
|
String subPk = params.getString("productKey");
|
|
|
|
String subDn = params.getString("deviceName");
|
|
|
|
String subDn = params.getString("deviceName");
|
|
|
|
String subModel = params.getString("model");
|
|
|
|
String subModel = params.getString("model");
|
|
|
|
|
|
|
|
long start11= System.currentTimeMillis() ;
|
|
|
|
ActionResult regResult = thingService.post(
|
|
|
|
log.info("threadId=378{}",threadId+":"+start11);
|
|
|
|
pluginInfo.getPluginId(),
|
|
|
|
ActionResult regResult = thingService.post(pluginInfo.getPluginId(),fillAction(
|
|
|
|
fillAction(
|
|
|
|
|
|
|
|
SubDeviceRegister.builder()
|
|
|
|
SubDeviceRegister.builder()
|
|
|
|
.productKey(device.getProductKey())
|
|
|
|
.productKey(device.getProductKey())
|
|
|
|
.deviceName(device.getDeviceName())
|
|
|
|
.deviceName(device.getDeviceName())
|
|
|
|
@ -352,6 +395,8 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
.build()
|
|
|
|
.build()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
long start12= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=395{}",threadId+":"+start12);
|
|
|
|
if (regResult.getCode() == 0) {
|
|
|
|
if (regResult.getCode() == 0) {
|
|
|
|
//注册成功
|
|
|
|
//注册成功
|
|
|
|
reply(topic, payload, 0);
|
|
|
|
reply(topic, payload, 0);
|
|
|
|
@ -379,7 +424,8 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
.params(params.getMap())
|
|
|
|
.params(params.getMap())
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
long start13= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=424{}",threadId+":"+start13);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if(flag) {
|
|
|
|
if(flag) {
|
|
|
|
reply1(replyHex,device.getDeviceName(), payload);
|
|
|
|
reply1(replyHex,device.getDeviceName(), payload);
|
|
|
|
@ -395,8 +441,17 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
action.setProductKey(device.getProductKey());
|
|
|
|
action.setProductKey(device.getProductKey());
|
|
|
|
action.setDeviceName(device.getDeviceName());
|
|
|
|
action.setDeviceName(device.getDeviceName());
|
|
|
|
action.setTime(System.currentTimeMillis());
|
|
|
|
action.setTime(System.currentTimeMillis());
|
|
|
|
thingService.post(pluginInfo.getPluginId(), action);
|
|
|
|
long start14= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=441{}",threadId+":"+start14);
|
|
|
|
|
|
|
|
IDeviceAction finalAction = action;
|
|
|
|
|
|
|
|
sxsbThreadPool.submit(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
|
|
|
|
thingService.post(pluginInfo.getPluginId(), finalAction);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
long start15= System.currentTimeMillis() ;
|
|
|
|
|
|
|
|
log.info("threadId=450{}",threadId+":"+start15);
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("message is illegal.", e);
|
|
|
|
log.error("message is illegal.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -429,6 +484,9 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onlineThreadPool.submit(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
//上线
|
|
|
|
//上线
|
|
|
|
thingService.post(
|
|
|
|
thingService.post(
|
|
|
|
pluginInfo.getPluginId(),
|
|
|
|
pluginInfo.getPluginId(),
|
|
|
|
@ -441,6 +499,8 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
DEVICE_ONLINE.put(dn, true);
|
|
|
|
DEVICE_ONLINE.put(dn, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void offline(String clientId) {
|
|
|
|
public void offline(String clientId) {
|
|
|
|
String[] parts = clientId.split("_");
|
|
|
|
String[] parts = clientId.split("_");
|
|
|
|
@ -678,3 +738,4 @@ public class EmqxPlugin implements PluginCloseListener, IPlugin, Runnable {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|