配置
This commit is contained in:
@@ -50,10 +50,12 @@ public class ServerController {
|
||||
}
|
||||
|
||||
//手动触发抬杆
|
||||
@PostMapping("/openFloodgate")
|
||||
public boolean openFloodgate(@RequestBody JSONObject js) {
|
||||
@PostMapping("/gpio_out")
|
||||
public boolean gpio_out(@RequestBody JSONObject js) {
|
||||
String sn = js.getString("sn");
|
||||
return service.openFloodgate(sn);
|
||||
Integer io = js.getInteger("io");
|
||||
Integer value = js.getInteger("value");
|
||||
return service.gpio_out(sn, io, value);
|
||||
}
|
||||
|
||||
@PostMapping("/set_io_lock_status")
|
||||
@@ -61,7 +63,7 @@ public class ServerController {
|
||||
String sn = js.getString("sn");
|
||||
Integer status = js.getInteger("status");
|
||||
Integer ioout = js.getInteger("ioout");
|
||||
boolean publish = service.locked(sn, status,ioout);
|
||||
boolean publish = service.set_io_lock_status(sn, status,ioout);
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
if (publish) {
|
||||
jsonObject.put("code", 200);
|
||||
@@ -71,7 +73,7 @@ public class ServerController {
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
//常开
|
||||
//开闸
|
||||
@PostMapping("/set_io_lock_open")
|
||||
public JSONObject lockOpen(@RequestBody JSONObject js) {
|
||||
String sn = js.getString("sn");
|
||||
@@ -85,7 +87,7 @@ public class ServerController {
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
//常关
|
||||
//关闸
|
||||
@PostMapping("/set_io_lock_close")
|
||||
public JSONObject lockClose(@RequestBody JSONObject js) {
|
||||
String sn = js.getString("sn");
|
||||
|
||||
@@ -313,6 +313,19 @@ public class CarMessageListener {
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布获取IO状态监听
|
||||
*
|
||||
* @param topic
|
||||
* @param message
|
||||
*/
|
||||
@MqttServerFunction("device/${sn}/message/down/get_io_status/reply")
|
||||
public void get_io_status(String topic, byte[] message) {
|
||||
log.info("发布获取IO状态监听消息 -> Topic: {}, message: {}", topic, new String(message));
|
||||
String data = new String(message, StandardCharsets.UTF_8);
|
||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订阅离线数据数量
|
||||
|
||||
@@ -62,8 +62,7 @@ public class ServerService {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public boolean openFloodgate(String sn) {
|
||||
public boolean gpio_out(String sn, Integer io, Integer value) {
|
||||
String operUrl = "device/%s/message/down/gpio_out";
|
||||
String topic = String.format(operUrl, sn);
|
||||
OpenFloodgatePO openFloodgatePO = new OpenFloodgatePO();
|
||||
@@ -71,16 +70,26 @@ public class ServerService {
|
||||
openFloodgatePO.setId(uuid);
|
||||
openFloodgatePO.setSn(sn);
|
||||
openFloodgatePO.setName("gpio_out");
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
long timestamp = now.atZone(ZoneId.systemDefault()).toEpochSecond();
|
||||
openFloodgatePO.setTimestamp(timestamp);
|
||||
openFloodgatePO.setPayload(this.buildPayloadOpen());
|
||||
openFloodgatePO.setTimestamp(System.currentTimeMillis() / 1000);
|
||||
openFloodgatePO.setPayload(this.buildGpioOut(io, value));
|
||||
boolean result = server.publish(sn,topic, JSON.toJSONString(openFloodgatePO).getBytes(StandardCharsets.UTF_8));
|
||||
log.info("抬杠设备编码:{},result:{},请求体{}", sn,result,openFloodgatePO);
|
||||
log.info("gpio_out设备编码:{},result:{},请求体{}", sn,result,openFloodgatePO);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean locked(String sn, Integer status, Integer ioout) {
|
||||
|
||||
private JSONObject buildGpioOut(Integer io, Integer value) {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("delay", 500);
|
||||
body.put("io", io);
|
||||
body.put("value", value);
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put("type", "gpio_out");
|
||||
payload.put("body", body);
|
||||
return payload;
|
||||
}
|
||||
|
||||
public boolean set_io_lock_status(String sn, Integer status, Integer ioout) {
|
||||
String operUrl = "device/%s/message/down/set_io_lock_status";
|
||||
String topic = String.format(operUrl, sn);
|
||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
||||
@@ -89,19 +98,7 @@ public class ServerService {
|
||||
deviceIOLockRequestPO.setSn(sn);
|
||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(status, ioout));
|
||||
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
||||
return result;
|
||||
}
|
||||
|
||||
private JSONObject buildPayloadOpen() {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("delay", 10000);
|
||||
body.put("io", 0);
|
||||
body.put("value",2);
|
||||
JSONObject payload = new JSONObject();
|
||||
payload.put("type", "gpio_out");
|
||||
payload.put("body", body);
|
||||
return payload;
|
||||
return server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private JSONObject buildPayloadLocked(Integer status, Integer ioout) {
|
||||
@@ -117,52 +114,28 @@ public class ServerService {
|
||||
}
|
||||
|
||||
public boolean lockOpen(String sn) {
|
||||
String operUrl = "device/%s/message/down/set_io_lock_status";
|
||||
String operUrl = "device/%s/message/down/gpio_out";
|
||||
String topic = String.format(operUrl, sn);
|
||||
|
||||
//通道1解锁
|
||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
||||
String uuid = "lockOpen_" + UuidUtil.getUuid();
|
||||
deviceIOLockRequestPO.setId(uuid);
|
||||
deviceIOLockRequestPO.setSn(sn);
|
||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(0, 1));
|
||||
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
//通道0 锁定
|
||||
|
||||
DeviceIOLockRequestPO po = new DeviceIOLockRequestPO();
|
||||
po.setId("lockOpen_" + UuidUtil.getUuid());
|
||||
po.setSn(sn);
|
||||
po.setName("set_io_lock_status");
|
||||
po.setPayload(this.buildPayloadLocked(1, 0));
|
||||
boolean result2 = server.publish(sn,topic, JSON.toJSONString(po).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
return (result && result2);
|
||||
OpenFloodgatePO openFloodgatePO = new OpenFloodgatePO();
|
||||
String uuid = "open_" + UuidUtil.getUuid();
|
||||
openFloodgatePO.setId(uuid);
|
||||
openFloodgatePO.setSn(sn);
|
||||
openFloodgatePO.setName("gpio_out");
|
||||
openFloodgatePO.setTimestamp(System.currentTimeMillis() / 1000);
|
||||
openFloodgatePO.setPayload(this.buildGpioOut(0, 2));
|
||||
return server.publish(sn,topic, JSON.toJSONString(openFloodgatePO).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public boolean lockClose(String sn) {
|
||||
String operUrl = "device/%s/message/down/set_io_lock_status";
|
||||
String operUrl = "device/%s/message/down/gpio_out";
|
||||
String topic = String.format(operUrl, sn);
|
||||
|
||||
//通道0解锁
|
||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
||||
String uuid = "lockOpen_" + UuidUtil.getUuid();
|
||||
deviceIOLockRequestPO.setId(uuid);
|
||||
deviceIOLockRequestPO.setSn(sn);
|
||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(0, 0));
|
||||
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
//通道1 锁定
|
||||
|
||||
DeviceIOLockRequestPO po = new DeviceIOLockRequestPO();
|
||||
po.setId("lockOpen_" + UuidUtil.getUuid());
|
||||
po.setSn(sn);
|
||||
po.setName("set_io_lock_status");
|
||||
po.setPayload(this.buildPayloadLocked(1, 1));
|
||||
boolean result2 = server.publish(sn,topic, JSON.toJSONString(po).getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
return (result && result2);
|
||||
OpenFloodgatePO openFloodgatePO = new OpenFloodgatePO();
|
||||
String uuid = "open_" + UuidUtil.getUuid();
|
||||
openFloodgatePO.setId(uuid);
|
||||
openFloodgatePO.setSn(sn);
|
||||
openFloodgatePO.setName("gpio_out");
|
||||
openFloodgatePO.setTimestamp(System.currentTimeMillis() / 1000);
|
||||
openFloodgatePO.setPayload(this.buildGpioOut(1, 2));
|
||||
return server.publish(sn,topic, JSON.toJSONString(openFloodgatePO).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user