| | |
| | | try { |
| | | JSONObject fakeStatus = fakeStatusMap.get(key); |
| | | String commandType = command.getString("commandType"); |
| | | if (commandType == null) { |
| | | return; |
| | | } |
| | | |
| | | if (commandType.equals("liftUp")) { |
| | | fakeStatus.put("deviceStatus", 0);//设备忙碌 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | |
| | | //delay |
| | | Thread.sleep(2000); |
| | | fakeStatus.put("hasCharge", true); |
| | | |
| | | Integer batteryPower = Integer.parseInt(fakeStatus.getString("batteryPower")); |
| | | while (true) { |
| | | Thread.sleep(10000); |
| | | batteryPower = batteryPower + 1; |
| | | fakeStatus.put("batteryPower", batteryPower); |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | if(batteryPower >= 100) { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | fakeStatus.put("deviceStatus", 1);//设备空闲 |
| | | fakeStatusMap.put(key, fakeStatus); |
| | | }else if (commandType.equals("stopCharge")) { |
| | |
| | | private void handleClient(DeviceConfig device) throws IOException { |
| | | try { |
| | | Socket socket = fakeServerMap.get(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo()); |
| | | if (socket == null) { |
| | | removeFake(device); |
| | | return; |
| | | } |
| | | InputStream inputStream = socket.getInputStream(); |
| | | if(inputStream == null){ |
| | | removeFake(device); |
| | | return; |
| | | } |
| | | |
| | | // 获取输入流 |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); |
| | | // 读取服务器的响应 |
| | | StringBuffer sb = new StringBuffer(); |
| | | char[] chars = new char[2048];//缓冲区 |
| | |
| | | } |
| | | } |
| | | |
| | | private void removeFake(DeviceConfig device) { |
| | | fakeServerMap.remove(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo()); |
| | | fakeStatusMap.remove(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo()); |
| | | fakeCommandMap.remove(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo()); |
| | | } |
| | | |
| | | public void processCommand(JSONObject result, DeviceConfig device) throws IOException { |
| | | String response = null; |
| | | JSONObject fakeStatus = fakeStatusMap.get(String.valueOf(SlaveType.Shuttle) + device.getDeviceNo()); |