| | |
| | | import com.example.agvcontroller.utils.SnowflakeIdWorker; |
| | | |
| | | import java.net.Socket; |
| | | import java.sql.Time; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.TimeoutException; |
| | | |
| | | |
| | | public class MainActivity extends AppCompatActivity { |
| | | |
| | | public static final Map<String, Object> map = new ConcurrentHashMap(); |
| | | |
| | | private RecyclerView recyclerView; |
| | | private ItemAdapter itemAdapter; |
| | |
| | | private boolean isDowm = false; |
| | | private boolean isOpen = false; |
| | | |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | |
| | | |
| | | |
| | | private Handler handler = new Handler(new Handler.Callback() { |
| | | @Override |
| | | public boolean handleMessage(Message msg) { |
| | | if (isDowm) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(ForceSwitchAction.class) |
| | | .setAgvNo("1") |
| | | .setSerialNo(substring) |
| | | .setVal(1) |
| | | .bodySync((action) -> action.setPwd((short) 21)); |
| | | |
| | | nettyServerHandler.sendMessageToClient(clientId, agvAction); // 发送消息到客户端 |
| | | handler.sendEmptyMessageDelayed(0, 100); |
| | | |
| | | boolean result = false; |
| | | long timestamp = System.currentTimeMillis(); |
| | | |
| | | while (System.currentTimeMillis() - timestamp < 5000) { |
| | | |
| | | Object o = map.get(substring); |
| | | |
| | | if (null != o) { |
| | | result = true; |
| | | map.remove(o); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (result) { |
| | | // alert ok |
| | | } else { |
| | | throw new TimeoutException("超时"); |
| | | } |
| | | |
| | | } |
| | | if (isOpen) { |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(ForceSwitchAction.class) |
| | | .setAgvNo("12") |
| | | .setSerialNo(substring) |
| | |
| | | if (vibrator != null && vibrator.hasVibrator()) { |
| | | vibrator.vibrate(500); |
| | | } |
| | | |
| | | String substring = String.valueOf(new SnowflakeIdWorker().nextId()).substring(0,16); |
| | | AgvAction agvAction = new AgvAction<>(HandOutAction.class) |
| | | .setAgvNo("12") |
| | | .setSerialNo(substring) |