|
@@ -1,122 +0,0 @@
|
|
|
-package com.warewms.hailiang.controller;
|
|
|
-
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
-import cn.hutool.json.JSONUtil;
|
|
|
-import com.warewms.common.annotation.Anonymous;
|
|
|
-import com.warewms.common.core.domain.R;
|
|
|
-import com.warewms.hailiang.config.DeviceMessageSocket;
|
|
|
-import com.warewms.hailiang.domain.DeviceLog;
|
|
|
-import com.warewms.hailiang.init.PlcConnectServiceRunner;
|
|
|
-import com.warewms.hailiang.init.TcpServiceRunner;
|
|
|
-import com.warewms.hailiang.util.InkjetPrintersSetUpTools;
|
|
|
-import com.warewms.hailiang.util.ParseMsgTools;
|
|
|
-import io.netty.buffer.Unpooled;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-
|
|
|
-/**
|
|
|
- * Created with IntelliJ IDEA.
|
|
|
- *
|
|
|
- * @author: liuzhifei
|
|
|
- * Date: 2023/8/7
|
|
|
- * Time: 16:41
|
|
|
- * To change this template use File | Settings | File Templates.
|
|
|
- * Description:
|
|
|
- **/
|
|
|
-@RestController
|
|
|
-@RequestMapping("/test")
|
|
|
-@Slf4j
|
|
|
-public class TestContoller {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- PlcConnectServiceRunner plcConnectServiceRunner;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- DeviceMessageSocket deviceMessageSocket;
|
|
|
-
|
|
|
- @GetMapping("/pclTest")
|
|
|
- public Object testPlc(String plcName, String db, String type, String value) {
|
|
|
- if (type.equals("1")) {
|
|
|
- db = "V" + db;
|
|
|
- return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
|
|
|
- }
|
|
|
- if (type.equals("2")) {
|
|
|
- db = "Q" + db;
|
|
|
- return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
|
|
|
- }
|
|
|
- if (type.equals("3")) {
|
|
|
- db = "I" + db;
|
|
|
- return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
|
|
|
- }
|
|
|
- if (type.equals("4")) {
|
|
|
- db = "DB" + db;
|
|
|
- return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
|
|
|
- }
|
|
|
- if (type.equals("5")) {
|
|
|
- db = "DB" + db;
|
|
|
- plcConnectServiceRunner.getPlcServer(plcName).writeBoolean(db, Boolean.parseBoolean(value));
|
|
|
- return "yes";
|
|
|
- }
|
|
|
- if (type.equals("6")) {
|
|
|
- db = "Q" + db;
|
|
|
- plcConnectServiceRunner.getPlcServer(plcName).writeBoolean(db, Boolean.parseBoolean(value));
|
|
|
- return "yes";
|
|
|
- }
|
|
|
- if (type.equals("7")) {
|
|
|
- db = "I" + db;
|
|
|
- plcConnectServiceRunner.getPlcServer(plcName).writeBoolean(db, Boolean.parseBoolean(value));
|
|
|
- return "yes";
|
|
|
- }
|
|
|
- if (type.equals("8")) {
|
|
|
- db = "M" + db;
|
|
|
- return plcConnectServiceRunner.getPlcServer(plcName).readBoolean(db);
|
|
|
- }
|
|
|
- if (type.equals("9")) {
|
|
|
- db = "M" + db;
|
|
|
- plcConnectServiceRunner.getPlcServer(plcName).writeBoolean(db, Boolean.parseBoolean(value));
|
|
|
- return "yes";
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/getStatus")
|
|
|
- public Object getStatus(String plcName) {
|
|
|
- return plcConnectServiceRunner.getPlcServer(plcName).checkConnected();
|
|
|
- }
|
|
|
-
|
|
|
- @GetMapping("/testNotify")
|
|
|
- @Anonymous
|
|
|
- public R testNotify(String content, String status) throws InterruptedException {
|
|
|
- Thread.sleep(3000);
|
|
|
- DeviceLog deviceLog = new DeviceLog("1", "倒角读码器", content, status);
|
|
|
- deviceLog.setCreateBy("system");
|
|
|
- deviceLog.setUpdateBy("system");
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.set("type", "notify");
|
|
|
- jsonObject.set("content", JSONUtil.parse(deviceLog));
|
|
|
- //推送消息
|
|
|
- deviceMessageSocket.sendAllMessage(jsonObject.toString());
|
|
|
- return R.ok();
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- TcpServiceRunner tcpServiceRunner;
|
|
|
-
|
|
|
- @GetMapping("/testCode")
|
|
|
- @Anonymous
|
|
|
- public R testCode(String code) {
|
|
|
- String updateCode = InkjetPrintersSetUpTools.updateCode(code);
|
|
|
- log.info(code);
|
|
|
- tcpServiceRunner.getTCPInstanceList("InkjetPrinters").getChannel().writeAndFlush(Unpooled.copiedBuffer(ParseMsgTools.hexString2Bytes(updateCode)));
|
|
|
- return R.ok();
|
|
|
- }
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- System.out.println(InkjetPrintersSetUpTools.updateCode("237191409000"));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|