| | |
| | | private void initFakeThread(){ |
| | | ThreadHandler thread = new FakeNyShuttleThread(redisUtil, gatewayPort, enableFake, enableFakeDeviceThread); |
| | | new Thread(thread).start(); |
| | | SlaveConnection.put(SlaveType.FakeThread, 1, thread); |
| | | |
| | | ThreadHandler thread2 = new FakeZyForkLiftThread(redisUtil); |
| | | new Thread(thread2).start(); |
| | | SlaveConnection.put(SlaveType.FakeThread, 2, thread2); |
| | | } |
| | | |
| | | |
| | |
| | | import com.zy.core.model.param.AddFakeDeviceParam; |
| | | import com.zy.core.model.param.DeleteDeviceParam; |
| | | import com.zy.core.properties.DeviceConfig; |
| | | import com.zy.core.thread.FakeThread; |
| | | import com.zy.core.thread.ForkLiftThread; |
| | | import com.zy.core.thread.ShuttleThread; |
| | | import com.zy.core.utils.DeviceMsgUtils; |
| | |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | @GetMapping("/getFakeThreadList") |
| | | public R getFakeThreadList() { |
| | | FakeThread fakeThread1 = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 1); |
| | | FakeThread fakeThread2 = (FakeThread) SlaveConnection.get(SlaveType.FakeThread, 2); |
| | | |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("fakeNyShuttleStatusMap", fakeThread1.getFakeStatusMap()); |
| | | map.put("fakeZyForkLiftStatusMap", fakeThread2.getFakeStatusMap()); |
| | | return R.ok().add(map); |
| | | } |
| | | |
| | | @GetMapping("/getDeviceList") |
| | | public R getDeviceList() { |
| | | List<DeviceConfig> deviceList = new ArrayList<>(); |
| | |
| | | Lift, |
| | | ForkLift, |
| | | ForkLiftMaster, |
| | | FakeThread, |
| | | ; |
| | | |
| | | public static SlaveType findInstance(String s){ |
| New file |
| | |
| | | package com.zy.core.thread; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.zy.core.ThreadHandler; |
| | | |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | public interface FakeThread extends ThreadHandler { |
| | | |
| | | ConcurrentHashMap<String, Thread> getFakeThreadMap(); |
| | | |
| | | ConcurrentHashMap<String, JSONObject> getFakeStatusMap(); |
| | | |
| | | ConcurrentHashMap<String, JSONObject> getFakeCommandMap(); |
| | | |
| | | } |
| | |
| | | import com.zy.common.SpringUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.properties.DeviceConfig; |
| | | import com.zy.core.thread.FakeThread; |
| | | import com.zy.core.thread.impl.NyShuttleThread; |
| | | import com.zy.core.utils.FakeDeviceUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | |
| | | @Slf4j |
| | | @SuppressWarnings("all") |
| | | public class FakeNyShuttleThread implements ThreadHandler { |
| | | public class FakeNyShuttleThread implements FakeThread { |
| | | |
| | | private RedisUtil redisUtil; |
| | | private JSONObject fakeStatusDemo = JSONObject.parseObject("{\"mode\":1,\"extend\":{\"countQuantity\":400,\"suspendState\":0,\"minCellVoltage\":3279,\"chargeCycleTimes\":0,\"maxCellVoltage\":3281,\"surplusQuantity\":204,\"voltage\":5248},\"hasLift\":false,\"hasPallet\":false,\"batteryVoltage\":5248,\"runDirection\":\"2\",\"currentCode\":\"{\\\"x\\\":19,\\\"y\\\":11,\\\"z\\\":2}\",\"errorCode\":\"0\",\"hasCharge\":false,\"batteryPower\":\"51\",\"speed\":0,\"deviceStatus\":1}"); |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public ConcurrentHashMap<String, Thread> getFakeThreadMap() { |
| | | return this.fakeThreadMap; |
| | | } |
| | | |
| | | @Override |
| | | public ConcurrentHashMap<String, JSONObject> getFakeStatusMap() { |
| | | return this.fakeStatusMap; |
| | | } |
| | | |
| | | @Override |
| | | public ConcurrentHashMap<String, JSONObject> getFakeCommandMap() { |
| | | return this.fakeCommandMap; |
| | | } |
| | | } |
| | |
| | | import com.zy.common.SpringUtils; |
| | | import com.zy.common.utils.RedisUtil; |
| | | import com.zy.core.News; |
| | | import com.zy.core.ThreadHandler; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.RedisKeyType; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.zy.core.model.DeviceCommandMsgModel; |
| | | import com.zy.core.model.DeviceMsgModel; |
| | | import com.zy.core.properties.DeviceConfig; |
| | | import com.zy.core.thread.FakeThread; |
| | | import com.zy.core.thread.impl.ZyForkLiftThread; |
| | | import com.zy.core.utils.DeviceMsgUtils; |
| | | import com.zy.core.utils.FakeDeviceUtils; |
| | |
| | | |
| | | @Slf4j |
| | | @SuppressWarnings("all") |
| | | public class FakeZyForkLiftThread implements ThreadHandler { |
| | | public class FakeZyForkLiftThread implements FakeThread { |
| | | |
| | | private RedisUtil redisUtil; |
| | | private JSONObject fakeStatusDemo = JSONObject.parseObject("{\"model\":2,\"wrkNo\":0,\"lev\":1,\"protocolStatus\":0,\"taskMode\":0,\"pick\":0,\"put\":0,\"iOMode\":0,\"errorCode\":0,\"trayList\":[0,0,0,0],\"carList\":[0,0,0,0]}"); |
| | |
| | | |
| | | |
| | | // init |
| | | ThreadHandler thread = new ZyForkLiftThread(device, redisUtil);; |
| | | ZyForkLiftThread thread = new ZyForkLiftThread(device, redisUtil);; |
| | | new Thread(thread).start(); |
| | | SlaveConnection.put(SlaveType.ForkLift, device.getDeviceNo(), thread); |
| | | } |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public ConcurrentHashMap<String, Thread> getFakeThreadMap() { |
| | | return this.fakeThreadMap; |
| | | } |
| | | |
| | | @Override |
| | | public ConcurrentHashMap<String, JSONObject> getFakeStatusMap() { |
| | | return this.fakeStatusMap; |
| | | } |
| | | |
| | | @Override |
| | | public ConcurrentHashMap<String, JSONObject> getFakeCommandMap() { |
| | | return this.fakeCommandMap; |
| | | } |
| | | } |
| | |
| | | private Socket socket; |
| | | private boolean stopThread = false; |
| | | private HashMap<Integer, String> resultKeyMap = new HashMap<Integer, String>(); |
| | | private long lastConnectTime = System.currentTimeMillis(); |
| | | |
| | | public NyShuttleThread(DeviceConfig deviceConfig, RedisUtil redisUtil) { |
| | | this.deviceConfig = deviceConfig; |
| | |
| | | return true; |
| | | } |
| | | |
| | | if(System.currentTimeMillis() - lastConnectTime < 1000 * 10) { |
| | | return false; |
| | | } |
| | | |
| | | if(this.deviceConfig.getFake()) { |
| | | return fakeConnect(); |
| | | }else { |
| | |
| | | deviceSocket.setSoTimeout(10000); |
| | | deviceSocket.setKeepAlive(true); |
| | | this.socket = deviceSocket; |
| | | this.lastConnectTime = System.currentTimeMillis(); |
| | | log.info(MessageFormat.format("【{0}】四向穿梭车Socket链接成功 ===>> [id:{1}] [ip:{2}] [port:{3}]", DateUtils.convert(new Date()), deviceConfig.getDeviceNo(), deviceConfig.getIp(), deviceConfig.getPort())); |
| | | } |
| | | } |