配置
This commit is contained in:
@@ -50,10 +50,12 @@ public class ServerController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//手动触发抬杆
|
//手动触发抬杆
|
||||||
@PostMapping("/openFloodgate")
|
@PostMapping("/gpio_out")
|
||||||
public boolean openFloodgate(@RequestBody JSONObject js) {
|
public boolean gpio_out(@RequestBody JSONObject js) {
|
||||||
String sn = js.getString("sn");
|
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")
|
@PostMapping("/set_io_lock_status")
|
||||||
@@ -61,7 +63,7 @@ public class ServerController {
|
|||||||
String sn = js.getString("sn");
|
String sn = js.getString("sn");
|
||||||
Integer status = js.getInteger("status");
|
Integer status = js.getInteger("status");
|
||||||
Integer ioout = js.getInteger("ioout");
|
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();
|
JSONObject jsonObject = new JSONObject();
|
||||||
if (publish) {
|
if (publish) {
|
||||||
jsonObject.put("code", 200);
|
jsonObject.put("code", 200);
|
||||||
@@ -71,7 +73,7 @@ public class ServerController {
|
|||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
//常开
|
//开闸
|
||||||
@PostMapping("/set_io_lock_open")
|
@PostMapping("/set_io_lock_open")
|
||||||
public JSONObject lockOpen(@RequestBody JSONObject js) {
|
public JSONObject lockOpen(@RequestBody JSONObject js) {
|
||||||
String sn = js.getString("sn");
|
String sn = js.getString("sn");
|
||||||
@@ -85,7 +87,7 @@ public class ServerController {
|
|||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
//常关
|
//关闸
|
||||||
@PostMapping("/set_io_lock_close")
|
@PostMapping("/set_io_lock_close")
|
||||||
public JSONObject lockClose(@RequestBody JSONObject js) {
|
public JSONObject lockClose(@RequestBody JSONObject js) {
|
||||||
String sn = js.getString("sn");
|
String sn = js.getString("sn");
|
||||||
|
|||||||
@@ -313,6 +313,19 @@ public class CarMessageListener {
|
|||||||
JSONObject jsonObject = JSONObject.parseObject(data);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean gpio_out(String sn, Integer io, Integer value) {
|
||||||
public boolean openFloodgate(String sn) {
|
|
||||||
String operUrl = "device/%s/message/down/gpio_out";
|
String operUrl = "device/%s/message/down/gpio_out";
|
||||||
String topic = String.format(operUrl, sn);
|
String topic = String.format(operUrl, sn);
|
||||||
OpenFloodgatePO openFloodgatePO = new OpenFloodgatePO();
|
OpenFloodgatePO openFloodgatePO = new OpenFloodgatePO();
|
||||||
@@ -71,16 +70,26 @@ public class ServerService {
|
|||||||
openFloodgatePO.setId(uuid);
|
openFloodgatePO.setId(uuid);
|
||||||
openFloodgatePO.setSn(sn);
|
openFloodgatePO.setSn(sn);
|
||||||
openFloodgatePO.setName("gpio_out");
|
openFloodgatePO.setName("gpio_out");
|
||||||
LocalDateTime now = LocalDateTime.now();
|
openFloodgatePO.setTimestamp(System.currentTimeMillis() / 1000);
|
||||||
long timestamp = now.atZone(ZoneId.systemDefault()).toEpochSecond();
|
openFloodgatePO.setPayload(this.buildGpioOut(io, value));
|
||||||
openFloodgatePO.setTimestamp(timestamp);
|
|
||||||
openFloodgatePO.setPayload(this.buildPayloadOpen());
|
|
||||||
boolean result = server.publish(sn,topic, JSON.toJSONString(openFloodgatePO).getBytes(StandardCharsets.UTF_8));
|
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;
|
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 operUrl = "device/%s/message/down/set_io_lock_status";
|
||||||
String topic = String.format(operUrl, sn);
|
String topic = String.format(operUrl, sn);
|
||||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
||||||
@@ -89,19 +98,7 @@ public class ServerService {
|
|||||||
deviceIOLockRequestPO.setSn(sn);
|
deviceIOLockRequestPO.setSn(sn);
|
||||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
deviceIOLockRequestPO.setName("set_io_lock_status");
|
||||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(status, ioout));
|
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(status, ioout));
|
||||||
boolean result = server.publish(sn,topic, JSON.toJSONString(deviceIOLockRequestPO).getBytes(StandardCharsets.UTF_8));
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject buildPayloadLocked(Integer status, Integer ioout) {
|
private JSONObject buildPayloadLocked(Integer status, Integer ioout) {
|
||||||
@@ -117,52 +114,28 @@ public class ServerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean lockOpen(String sn) {
|
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);
|
String topic = String.format(operUrl, sn);
|
||||||
|
OpenFloodgatePO openFloodgatePO = new OpenFloodgatePO();
|
||||||
//通道1解锁
|
String uuid = "open_" + UuidUtil.getUuid();
|
||||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
openFloodgatePO.setId(uuid);
|
||||||
String uuid = "lockOpen_" + UuidUtil.getUuid();
|
openFloodgatePO.setSn(sn);
|
||||||
deviceIOLockRequestPO.setId(uuid);
|
openFloodgatePO.setName("gpio_out");
|
||||||
deviceIOLockRequestPO.setSn(sn);
|
openFloodgatePO.setTimestamp(System.currentTimeMillis() / 1000);
|
||||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
openFloodgatePO.setPayload(this.buildGpioOut(0, 2));
|
||||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(0, 1));
|
return server.publish(sn,topic, JSON.toJSONString(openFloodgatePO).getBytes(StandardCharsets.UTF_8));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean lockClose(String sn) {
|
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);
|
String topic = String.format(operUrl, sn);
|
||||||
|
OpenFloodgatePO openFloodgatePO = new OpenFloodgatePO();
|
||||||
//通道0解锁
|
String uuid = "open_" + UuidUtil.getUuid();
|
||||||
DeviceIOLockRequestPO deviceIOLockRequestPO = new DeviceIOLockRequestPO();
|
openFloodgatePO.setId(uuid);
|
||||||
String uuid = "lockOpen_" + UuidUtil.getUuid();
|
openFloodgatePO.setSn(sn);
|
||||||
deviceIOLockRequestPO.setId(uuid);
|
openFloodgatePO.setName("gpio_out");
|
||||||
deviceIOLockRequestPO.setSn(sn);
|
openFloodgatePO.setTimestamp(System.currentTimeMillis() / 1000);
|
||||||
deviceIOLockRequestPO.setName("set_io_lock_status");
|
openFloodgatePO.setPayload(this.buildGpioOut(1, 2));
|
||||||
deviceIOLockRequestPO.setPayload(this.buildPayloadLocked(0, 0));
|
return server.publish(sn,topic, JSON.toJSONString(openFloodgatePO).getBytes(StandardCharsets.UTF_8));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user