修改地磅称重等待间隔时间控制
parent
5dda71bd90
commit
b8cfd0453b
|
|
@ -8,6 +8,7 @@ import com.cowr.local.ssjygl.devicectrl.controllers.InController;
|
|||
import com.cowr.local.ssjygl.devicectrl.controllers.OutController;
|
||||
import com.cowr.local.ssjygl.devicectrl.device.*;
|
||||
import com.cowr.local.ssjygl.main.CliCacheData;
|
||||
import com.cowr.local.ssjygl.main.Config;
|
||||
import com.jfinal.kit.StrKit;
|
||||
import com.jfinal.log.Log;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
|
|
@ -61,6 +62,7 @@ public class DeviceThread extends Thread {
|
|||
"plc": { "ip": "192.168.0.220", "port": 502 },
|
||||
"scale": { "ip": "192.168.0.189", "port": 10003 },
|
||||
"which": "R01",
|
||||
"scale_wait_time":5000,
|
||||
"camera": { "ip": "192.168.0.100" }
|
||||
}, {
|
||||
"led": { "ip": "192.168.0.197", "port": 5005 },
|
||||
|
|
@ -153,6 +155,7 @@ public class DeviceThread extends Thread {
|
|||
JSONObject device = flow.getJSONObject(i);
|
||||
|
||||
String which = device.getString("which");
|
||||
Integer scale_wait_time = device.getInteger("scale_wait_time");
|
||||
JSONObject cameraconf = device.getJSONObject("camera");
|
||||
JSONObject scaleconf = device.getJSONObject("scale");
|
||||
JSONObject ledconf = device.getJSONObject("led");
|
||||
|
|
@ -191,14 +194,19 @@ public class DeviceThread extends Thread {
|
|||
}
|
||||
|
||||
Controller controller = null;
|
||||
if (scale_wait_time == null) {
|
||||
scale_wait_time = Config.configprop.getInt("default_scale_wait_time");
|
||||
}
|
||||
|
||||
if (scale_wait_time < 1000) {
|
||||
log.error("scale_wait_time 值设置错误 %s ", config);
|
||||
return;
|
||||
}
|
||||
|
||||
if (which.startsWith(Enums.CtrlFlowEnum.R.name())) {
|
||||
InController incontroller = new InController(which, camera, scale, led, plc);
|
||||
incontroller.setSupermarket_id(supermarket_id);
|
||||
|
||||
controller = incontroller;
|
||||
controller = new InController(which, camera, scale, led, plc, scale_wait_time);
|
||||
} else if (which.startsWith(Enums.CtrlFlowEnum.C.name())) {
|
||||
controller = new OutController(which, camera, scale, led, plc);
|
||||
controller = new OutController(which, camera, scale, led, plc, scale_wait_time);
|
||||
} else {
|
||||
log.error("which 值设置错误 %s ", config);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public abstract class Controller implements Runnable {
|
|||
private AbsScale scale; // 入场称重
|
||||
private LEDThread led; // 称重结果显示
|
||||
private PLC plc; // 道闸控制
|
||||
private int scaleWaitTime; // 落杆后,上榜等待时间
|
||||
|
||||
private String currentLicense; // 当前流程车牌
|
||||
private BlockingQueue<LicenseJPGPair> licenseQueue = new LinkedBlockingQueue<>(); // 车识识别结果队列
|
||||
|
|
@ -40,12 +41,15 @@ public abstract class Controller implements Runnable {
|
|||
|
||||
private boolean running = true;
|
||||
|
||||
public Controller(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc) {
|
||||
public Controller(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc, int scaleWaitTime) {
|
||||
log.info("%s 流程上磅等待时间 %s", which, scaleWaitTime);
|
||||
|
||||
this.which = which;
|
||||
this.camera = camera;
|
||||
this.scale = scale;
|
||||
this.led = led;
|
||||
this.plc = plc;
|
||||
this.scaleWaitTime = scaleWaitTime;
|
||||
}
|
||||
|
||||
public void onLicenseResult(String license, File file, boolean head, boolean delete) {
|
||||
|
|
@ -91,7 +95,7 @@ public abstract class Controller implements Runnable {
|
|||
}
|
||||
|
||||
postLicenseQueue(this.which, licenseQueue);
|
||||
}finally {
|
||||
} finally {
|
||||
licenseResultLock.unlock();
|
||||
log.debug("licenseResultLock time: %s", System.currentTimeMillis() - st);
|
||||
}
|
||||
|
|
@ -126,7 +130,7 @@ public abstract class Controller implements Runnable {
|
|||
List<String> strings = licenseQueue.stream().map(licenseJPGPair -> licenseJPGPair.license).collect(Collectors.toList());
|
||||
|
||||
TransportDeviceService.me.postLicenseQueue(strings, which);
|
||||
}finally {
|
||||
} finally {
|
||||
postLicenseQueueLock.unlock();
|
||||
log.debug("postLicenseQueueLock time: %s", System.currentTimeMillis() - st);
|
||||
}
|
||||
|
|
@ -248,6 +252,14 @@ public abstract class Controller implements Runnable {
|
|||
|
||||
public abstract String plcSensor1(); // 读地感 1
|
||||
|
||||
public int getScaleWaitTime() {
|
||||
return scaleWaitTime;
|
||||
}
|
||||
|
||||
public void setScaleWaitTime(int scaleWaitTime) {
|
||||
this.scaleWaitTime = scaleWaitTime;
|
||||
}
|
||||
|
||||
public void deviceInit() {
|
||||
// 后续加入摄像头连不上的时候,可以手动加入
|
||||
// 摄像头没有连上 getLicenseQueue() 不为空,表示有手动加入车牌
|
||||
|
|
@ -268,7 +280,7 @@ public abstract class Controller implements Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
if(!isRunning()){
|
||||
if (!isRunning()) {
|
||||
log.debug("流程已终止");
|
||||
return;
|
||||
}
|
||||
|
|
@ -288,7 +300,7 @@ public abstract class Controller implements Runnable {
|
|||
}
|
||||
|
||||
try {
|
||||
if(!getPlc().isConnected()){
|
||||
if (!getPlc().isConnected()) {
|
||||
getPlc().connect();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.cowr.local.ssjygl.devicectrl.controllers;
|
|||
import com.cowr.local.ssjygl.devicectrl.device.*;
|
||||
import com.cowr.local.ssjygl.devicectrl.utils.LicenseJPGPair;
|
||||
import com.cowr.local.ssjygl.main.CliCacheData;
|
||||
import com.cowr.local.ssjygl.main.Config;
|
||||
import com.cowr.model.PostLicenseResult;
|
||||
import com.jfinal.log.Log;
|
||||
|
||||
|
|
@ -11,18 +12,8 @@ import java.io.IOException;
|
|||
public class InController extends Controller implements Runnable {
|
||||
private static Log log = Log.getLog(InController.class);
|
||||
|
||||
private int supermarket_id;
|
||||
|
||||
public InController(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc) {
|
||||
super(which, camera, scale, led, plc);
|
||||
}
|
||||
|
||||
public int getSupermarket_id() {
|
||||
return supermarket_id;
|
||||
}
|
||||
|
||||
public void setSupermarket_id(int supermarket_id) {
|
||||
this.supermarket_id = supermarket_id;
|
||||
public InController(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc, int scaleWaitTime) {
|
||||
super(which, camera, scale, led, plc, scaleWaitTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -41,7 +32,7 @@ public class InController extends Controller implements Runnable {
|
|||
}
|
||||
|
||||
public void run() {
|
||||
log.debug("开始 %s 流程 %s", getWhich(), supermarket_id);
|
||||
log.debug("开始 %s 流程", getWhich());
|
||||
deviceInit();
|
||||
|
||||
while (isRunning()) {
|
||||
|
|
@ -108,7 +99,7 @@ public class InController extends Controller implements Runnable {
|
|||
continue;
|
||||
}
|
||||
|
||||
log.debug("%s 【%s】开始流程 %s", getWhich(), pair.license, supermarket_id);
|
||||
log.debug("%s 【%s】开始流程 %s", getWhich(), pair.license);
|
||||
|
||||
setCurrentLicense(pair.license); // 设定当前流程中的车辆
|
||||
|
||||
|
|
@ -169,13 +160,7 @@ public class InController extends Controller implements Runnable {
|
|||
}
|
||||
|
||||
// 盐港的雷达离地磅比较远,要多等一会儿
|
||||
// TODO:这里的等待时间应该改成从配置文件获取
|
||||
if(supermarket_id == 6){
|
||||
Thread.sleep(10000);
|
||||
}else{
|
||||
// 获取到地感线圈状态后,等待 5 秒后开始称重
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
Thread.sleep(getScaleWaitTime());
|
||||
|
||||
double weight = 0;
|
||||
int tryCount = 0;
|
||||
|
|
@ -192,7 +177,7 @@ public class InController extends Controller implements Runnable {
|
|||
if (weight > 0) {
|
||||
log.debug("%s 【%s】称重结果【%s】", getWhich(), pair.license, weight);
|
||||
break;
|
||||
}else{
|
||||
} else {
|
||||
// 读数错误,断开连接,下次读取时重连
|
||||
getScale().disconnect();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import java.io.IOException;
|
|||
public class OutController extends Controller implements Runnable {
|
||||
private static Log log = Log.getLog(InController.class);
|
||||
|
||||
public OutController(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc) {
|
||||
super(which, camera, scale, led, plc);
|
||||
public OutController(String which, Camera camera, AbsScale scale, LEDThread led, PLC plc, int scaleWaitTime) {
|
||||
super(which, camera, scale, led, plc, scaleWaitTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -159,7 +159,7 @@ public class OutController extends Controller implements Runnable {
|
|||
}
|
||||
|
||||
// 获取到地感线圈状态后,等待 5 秒后开始称重
|
||||
Thread.sleep(5000);
|
||||
Thread.sleep(getScaleWaitTime());
|
||||
|
||||
double weight = 0;
|
||||
int tryCount = 0;
|
||||
|
|
|
|||
|
|
@ -252,6 +252,8 @@ public class LEDThread extends Device implements Runnable {
|
|||
} catch (Exception e) {
|
||||
if (e.getMessage().contains("connect timed out")) {
|
||||
log.error("LED %s %s 连接超时", getId(), getIp());
|
||||
} else if (e.getMessage().contains("Host unreachable")) {
|
||||
log.error("LED %s %s 无法连接", getId(), getIp());
|
||||
} else {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ public class Config extends JFinalConfig {
|
|||
public static DeviceThread deviceThread = new DeviceThread();
|
||||
public static SocketIOService socketio = null;
|
||||
private static boolean client_run = true;
|
||||
public static final String CLINET_VERSION = "20201016";
|
||||
public static final String CLINET_VERSION = "20201017";
|
||||
|
||||
public static String getRootPath() {
|
||||
return PathKit.getWebRootPath()
|
||||
|
|
@ -327,8 +327,8 @@ public class Config extends JFinalConfig {
|
|||
CliCacheData.SUP = Supermarket.dao.findById(configprop.getInt("current.supermarket_id"));
|
||||
|
||||
if (CliCacheData.SUP == null) {
|
||||
System.out.println("没有获取到有效的砂站信息,检查配置是否正确");
|
||||
log.error("没有获取到有效的砂站信息,检查配置是否正确");
|
||||
System.out.println("没有获取到有效的砂站信息,检查配置是否正确。退出系统");
|
||||
log.error("没有获取到有效的砂站信息,检查配置是否正确。退出系统");
|
||||
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
|
|
@ -337,6 +337,10 @@ public class Config extends JFinalConfig {
|
|||
}
|
||||
|
||||
System.exit(0);
|
||||
} else {
|
||||
log.info("====================================================");
|
||||
log.info("============= 启动 %s %s 服务 =================", CliCacheData.SUP.getId(), CliCacheData.SUP.getName());
|
||||
log.info("====================================================");
|
||||
}
|
||||
|
||||
StockSyncService.me.initSupermarketStock();
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ socketio.port=12002
|
|||
|
||||
#当前部署本地程序的砂站id
|
||||
current.supermarket_id=6
|
||||
#落杆后,等待上磅的时间
|
||||
default_scale_wait_time=5000
|
||||
|
||||
#打印用到的配置信息
|
||||
print.vendor=浠水县长投环保有限公司
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ socketio.port=12002
|
|||
|
||||
#当前部署本地程序的砂站id
|
||||
current.supermarket_id=6
|
||||
#落杆后,等待上磅的时间
|
||||
default_scale_wait_time=5000
|
||||
|
||||
#打印用到的配置信息
|
||||
print.vendor=浠水县长投环保有限公司
|
||||
|
|
|
|||
Loading…
Reference in New Issue