优化打印机配置加载

dev
lisai17@sina.com 2020-08-10 21:58:20 +08:00
parent b370f20bc6
commit 773b695576
3 changed files with 36 additions and 23 deletions

View File

@ -85,5 +85,6 @@ public interface Enums {
enum PrinterIdEnum {
printer1,
printer2,
printer3,
}
}

View File

@ -54,25 +54,28 @@ public class DeviceThread extends Thread {
/*
{
"printer1": { "ip": "127.0.0.1", "port": 5005 },
"printer2": { "ip": "127.0.0.1", "port": 5005 },
"flow": [
{
"flow": [{
"led": { "ip": "192.168.0.198", "port": 5005 },
"plc": { "ip": "192.168.0.220", "port": 502 },
"scale": { "ip": "192.168.0.189", "port": 10003 },
"which": "R01",
"camera": { "ip": "192.168.1.201" },
"scale": { "ip": "127.0.0.1", "port": 5005 },
"led": { "ip": "127.0.0.1", "port": 5005 },
"plc": { "ip": "127.0.0.1", "port": 5005 }
},
{
"camera": { "ip": "192.168.0.100" }
}, {
"led": { "ip": "192.168.0.197", "port": 5005 },
"plc": { "ip": "192.168.0.220", "port": 502 },
"scale": { "ip": "192.168.0.189", "port": 10001 },
"which": "C01",
"camera": { "ip": "192.168.1.201" },
"scale": { "ip": "127.0.0.1", "port": 5005 },
"led": { "ip": "127.0.0.1", "port": 5005 },
"plc": { "ip": "127.0.0.1", "port": 5005 }
"camera": { "ip": "192.168.0.102" }
}
],
"printer": [{
"id": "printer1", "ip": "192.168.0.5", "port": 9527
}, {
"id": "printer2", "ip": "192.168.0.5", "port": 9527
}
]
}
*/
/**
@ -119,13 +122,21 @@ public class DeviceThread extends Thread {
config = JSONObject.parseObject(record.getStr("content"));
JSONObject printer1conf = config.getJSONObject("printer1");
JSONObject printer2conf = config.getJSONObject("printer2");
JSONArray flow = config.getJSONArray("flow");
JSONArray flow = config.getJSONArray("flow");
JSONArray printer = config.getJSONArray("printer");
printerMap.put(Enums.PrinterIdEnum.printer1.name(), new Printer(printer1conf.getString("ip"), printer1conf.getIntValue("port")));
printerMap.put(Enums.PrinterIdEnum.printer2.name(), new Printer(printer2conf.getString("ip"), printer2conf.getIntValue("port")));
if (printer.isEmpty()) {
log.error("没有配置打印机 %s ", config);
return;
}
// 加载打印机配置
for (int i = 0; i < printer.size(); i++) {
JSONObject printerconf = printer.getJSONObject(i);
printerMap.put(printerconf.getString("id"), new Printer(printerconf.getString("ip"), printerconf.getIntValue("port")));
}
// 加载称重流程控制相关硬件配置
for (int i = 0; i < flow.size(); i++) {
//TODO debug 只连一个摄像头测试
// if (i != 0) {
@ -298,7 +309,7 @@ public class DeviceThread extends Thread {
return false;
}
public Controller getController(String which){
public Controller getController(String which) {
for (Controller controller : controllers) {
if (controller.getWhich().equals(which)) {
return controller;
@ -310,10 +321,11 @@ public class DeviceThread extends Thread {
/**
*
*
* @param which
* @return
*/
public String getCtrlCurrentLicense(String which){
public String getCtrlCurrentLicense(String which) {
for (Controller controller : controllers) {
if (controller.getWhich().equals(which)) {
return controller.getCurrentLicense();

View File

@ -327,9 +327,9 @@ public class Config extends JFinalConfig {
// BocommXMLKit.me.init(); // 初始化银行 sdk
// 最后启动 deviceThread
if ("prod".equals(ENV)) {
// if ("prod".equals(ENV)) {
deviceThread.start();
}
// }
} catch (Exception e) {
log.error(e.getMessage(), e);
}