main.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package com.fdkk.sxz;
  2. import cn.hutool.core.lang.Console;
  3. import cn.hutool.core.util.StrUtil;
  4. import cn.hutool.socket.aio.AioClient;
  5. import cn.hutool.socket.aio.AioSession;
  6. import cn.hutool.socket.aio.SimpleIoAction;
  7. import com.alibaba.fastjson.JSON;
  8. import java.net.InetSocketAddress;
  9. import java.nio.ByteBuffer;
  10. public class main {
  11. //public static void main(String[] args) {
  12. // String json = "{\n" +
  13. // " \"sweepLocations\": [\n" +
  14. // " {\n" +
  15. // " \"subgroup\": 0,\n" +
  16. // " \"pose\": {\n" +
  17. // " \"rotation\": {\n" +
  18. // " \"w\": 0.95928264,\n" +
  19. // " \"x\": -0.0017092235,\n" +
  20. // " \"y\": -0.0016763769,\n" +
  21. // " \"z\": -0.28243768\n" +
  22. // " },\n" +
  23. // " \"translation\": {\n" +
  24. // " \"x\": 3.6112025,\n" +
  25. // " \"y\": 0.12166519,\n" +
  26. // " \"z\": 0.07516695\n" +
  27. // " }\n" +
  28. // " },\n" +
  29. // " \"visibles3\": [\n" +
  30. // " 1,\n" +
  31. // " 2,\n" +
  32. // " 3\n" +
  33. // " ],\n" +
  34. // " \"visibles2\": [\n" +
  35. // " 1,\n" +
  36. // " 2,\n" +
  37. // " 3\n" +
  38. // " ],\n" +
  39. // " \"puck\": {\n" +
  40. // " \"x\": 3.6112025,\n" +
  41. // " \"y\": 0.12166519,\n" +
  42. // " \"z\": -1.39718955\n" +
  43. // " },\n" +
  44. // " \"uuid\": \"0\",\n" +
  45. // " \"visibles\": [\n" +
  46. // " 1,\n" +
  47. // " 2,\n" +
  48. // " 3\n" +
  49. // " ],\n" +
  50. // " \"group\": 1\n" +
  51. // " },\n" +
  52. // " {\n" +
  53. // " \"subgroup\": 0,\n" +
  54. // " \"pose\": {\n" +
  55. // " \"rotation\": {\n" +
  56. // " \"w\": 0.97998166,\n" +
  57. // " \"x\": -0.00051350286,\n" +
  58. // " \"y\": -0.00007887775,\n" +
  59. // " \"z\": -0.19908713\n" +
  60. // " },\n" +
  61. // " \"translation\": {\n" +
  62. // " \"x\": 1.6813623,\n" +
  63. // " \"y\": 0.20879818,\n" +
  64. // " \"z\": 0.07516695\n" +
  65. // " }\n" +
  66. // " },\n" +
  67. // " \"visibles3\": [\n" +
  68. // " 0,\n" +
  69. // " 2,\n" +
  70. // " 3\n" +
  71. // " ],\n" +
  72. // " \"visibles2\": [\n" +
  73. // " 0,\n" +
  74. // " 2,\n" +
  75. // " 3\n" +
  76. // " ],\n" +
  77. // " \"puck\": {\n" +
  78. // " \"x\": 1.6813623,\n" +
  79. // " \"y\": 0.20879818,\n" +
  80. // " \"z\": -1.39718955\n" +
  81. // " },\n" +
  82. // " \"uuid\": \"2\",\n" +
  83. // " \"visibles\": [\n" +
  84. // " 0,\n" +
  85. // " 2,\n" +
  86. // " 3\n" +
  87. // " ],\n" +
  88. // " \"group\": 1\n" +
  89. // " },\n" +
  90. // " {\n" +
  91. // " \"subgroup\": 0,\n" +
  92. // " \"pose\": {\n" +
  93. // " \"rotation\": {\n" +
  94. // " \"w\": 0.7688388,\n" +
  95. // " \"x\": -0.0022818057,\n" +
  96. // " \"y\": 0.0016657045,\n" +
  97. // " \"z\": -0.6394364\n" +
  98. // " },\n" +
  99. // " \"translation\": {\n" +
  100. // " \"x\": -1.0941758,\n" +
  101. // " \"y\": -0.15828772,\n" +
  102. // " \"z\": 0.07516695\n" +
  103. // " }\n" +
  104. // " },\n" +
  105. // " \"visibles3\": [\n" +
  106. // " 0,\n" +
  107. // " 1,\n" +
  108. // " 3\n" +
  109. // " ],\n" +
  110. // " \"visibles2\": [\n" +
  111. // " 0,\n" +
  112. // " 1,\n" +
  113. // " 3\n" +
  114. // " ],\n" +
  115. // " \"puck\": {\n" +
  116. // " \"x\": -1.0941758,\n" +
  117. // " \"y\": -0.15828772,\n" +
  118. // " \"z\": -1.39718955\n" +
  119. // " },\n" +
  120. // " \"uuid\": \"4\",\n" +
  121. // " \"visibles\": [\n" +
  122. // " 0,\n" +
  123. // " 1,\n" +
  124. // " 3\n" +
  125. // " ],\n" +
  126. // " \"group\": 1\n" +
  127. // " },\n" +
  128. // " {\n" +
  129. // " \"subgroup\": 1,\n" +
  130. // " \"pose\": {\n" +
  131. // " \"rotation\": {\n" +
  132. // " \"w\": 0.75378096,\n" +
  133. // " \"x\": -0.00085483055,\n" +
  134. // " \"y\": 0.0011985971,\n" +
  135. // " \"z\": -0.6571241\n" +
  136. // " },\n" +
  137. // " \"translation\": {\n" +
  138. // " \"x\": -4.213454,\n" +
  139. // " \"y\": -0.17369196,\n" +
  140. // " \"z\": 0.07516695\n" +
  141. // " }\n" +
  142. // " },\n" +
  143. // " \"visibles3\": [\n" +
  144. // " 0,\n" +
  145. // " 1,\n" +
  146. // " 2\n" +
  147. // " ],\n" +
  148. // " \"visibles2\": [\n" +
  149. // " 0,\n" +
  150. // " 1,\n" +
  151. // " 2\n" +
  152. // " ],\n" +
  153. // " \"puck\": {\n" +
  154. // " \"x\": -4.213454,\n" +
  155. // " \"y\": -0.17369196,\n" +
  156. // " \"z\": -1.39718955\n" +
  157. // " },\n" +
  158. // " \"uuid\": \"6\",\n" +
  159. // " \"visibles\": [\n" +
  160. // " 0,\n" +
  161. // " 1,\n" +
  162. // " 2\n" +
  163. // " ],\n" +
  164. // " \"group\": 1\n" +
  165. // " }\n" +
  166. // " ]\n" +
  167. // "}";
  168. // JSONObject visionJson = JSON.parseObject(json);
  169. // JSONArray sweepArray = visionJson.getJSONArray("sweepLocations");
  170. // List<JSONObject> roamingPoint = new ArrayList();
  171. // for (int i = 0; i < sweepArray.size(); i++) {
  172. // JSONObject objectJson = sweepArray.getJSONObject(i);
  173. // JSONObject newJson = new JSONObject();
  174. // newJson.put("uuid", objectJson.getString("uuid"));
  175. // JSONObject puck = objectJson.getJSONObject("puck");
  176. // puck.put("y", puck.getDoubleValue("y") * -1);
  177. // puck.remove("z");
  178. // newJson.put("puck", puck);
  179. // newJson.put("subgroup", objectJson.getInteger("subgroup"));
  180. // roamingPoint.add(newJson);
  181. // }
  182. // Map<String, List<JSONObject>> subgroup = roamingPoint.stream().collect(
  183. // Collectors.groupingBy(x -> x.getString("subgroup"))).entrySet().stream()
  184. // .collect(Collectors.toMap(e -> "floor" + e.getKey(), Map.Entry::getValue));
  185. //
  186. // System.out.println(JSON.toJSONString(subgroup));
  187. //}
  188. public static void main(String[] args) {
  189. AioClient client = new AioClient(new InetSocketAddress("192.168.0.75", 8233), new SimpleIoAction() {
  190. @Override
  191. public void doAction(AioSession session, ByteBuffer data) {
  192. if (data.hasRemaining()) {
  193. Console.log(StrUtil.utf8Str(data));
  194. session.read();
  195. }
  196. Console.log("OK");
  197. }
  198. });
  199. String json = JSON.toJSONString("{\"uuid\":\"111222333\",\"max\":\"111222333.max\",\"flag\":\"false\"}");
  200. client.write(ByteBuffer.wrap(json.getBytes()));
  201. client.read();
  202. client.close();
  203. }
  204. }