AgipCommServerApplicationTests.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. package com.its.app;
  2. import com.its.app.utils.ItsUtils;
  3. import com.its.app.utils.SysUtils;
  4. import com.its.bis.AgipCommServerApplication;
  5. import com.its.bis.dto.Location;
  6. import lombok.extern.slf4j.Slf4j;
  7. import org.apache.commons.lang.StringUtils;
  8. import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
  9. import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig;
  10. import org.jasypt.salt.StringFixedSaltGenerator;
  11. import org.junit.jupiter.api.Test;
  12. import org.springframework.boot.test.context.SpringBootTest;
  13. import java.io.UnsupportedEncodingException;
  14. @Slf4j
  15. @SpringBootTest(classes = AgipCommServerApplication.class)
  16. public class AgipCommServerApplicationTests {
  17. public static double getDistance(double lat1, double lon1, double lat2, double lon2) {
  18. int EARTH_RADIUS = 6371;
  19. double dLat = Math.toRadians(lat2 - lat1);
  20. double dLon = Math.toRadians(lon2 - lon1);
  21. double a = Math.sin(dLat/2)* Math.sin(dLat/2)+ Math.cos(Math.toRadians(lat1))* Math.cos(Math.toRadians(lat2))* Math.sin(dLon/2)* Math.sin(dLon/2);
  22. double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  23. double d = EARTH_RADIUS* c * 1000; // Distance in m
  24. return d;
  25. }
  26. @Test
  27. void getNearNode() {
  28. // NodeLinkService nodeLinkService = (NodeLinkService)AppUtils.getBean(NodeLinkService.class);
  29. // Location from = Location.builder()
  30. // .mLatitude(128.74352336)
  31. // .mLongitude(36.56392018)
  32. // .build();
  33. // log.error("{}", nodeLinkService.getNearNode(from));
  34. }
  35. @Test
  36. void dist() {
  37. // private double mLatitude = 0.0; // 위도, 37.48543554333333
  38. // private double mLongitude = 0.0; // 경도, 126.89448518666667
  39. Location from = Location.builder()
  40. .mLatitude(128.74352336)
  41. .mLongitude(36.56392018)
  42. .build();
  43. Location to = Location.builder()
  44. .mLatitude(128.73881251)
  45. .mLongitude(36.56128759)
  46. .build();
  47. log.error("{}", from.distanceTo(to));
  48. log.error("{}", getDistance(from.getMLatitude(), from.getMLongitude(), to.getMLatitude(), to.getMLongitude()));
  49. }
  50. @Test
  51. void jasypt() {
  52. String encKey = "asdkjfaslkjflkajslfjkajlkf";
  53. PooledPBEStringEncryptor encryptor = new PooledPBEStringEncryptor();
  54. SimpleStringPBEConfig config = new SimpleStringPBEConfig();
  55. // ==> SimpleStringPBEConfig 사용시 아래 3개 반드시 설정해야함
  56. config.setPassword(encKey); // 암호화에 사용할 키
  57. config.setPoolSize(1); // Pool Size
  58. config.setSaltGenerator(new StringFixedSaltGenerator("fixedSalt")); // 고정으로 암호화(Default: Random)
  59. //config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
  60. //config.setAlgorithm("PBEWithMD5AndTripleDES");
  61. config.setAlgorithm("PBEWithMD5AndDES"); // Jasypt 를 이용한 암호화 알고리즘
  62. config.setProviderName("SunJCE");
  63. config.setKeyObtentionIterations("10000");
  64. config.setStringOutputType("base64");
  65. /*private Boolean proxyPropertySources = false;
  66. private String bean = "jasyptStringEncryptor";
  67. private String password;
  68. private String algorithm = "PBEWithMD5AndDES";
  69. private String keyObtentionIterations = "1000";
  70. private String poolSize = "1";
  71. private String providerName = null;
  72. //config.setSaltGeneratorClassName("org.jasypt.salt.RandomSaltGenerator");
  73. private String saltGeneratorClassname = "org.jasypt.salt.RandomSaltGenerator";
  74. private String stringOutputType = "base64";*/
  75. encryptor.setConfig(config);
  76. String yiits = encryptor.encrypt("adits");
  77. String rutis = encryptor.encrypt("ryxhdITS@#");
  78. log.info("{}", yiits);
  79. log.info("{}", rutis);
  80. }
  81. @Test
  82. void test1() {
  83. // 0123 45 67 89 0123
  84. String testData = "20230102034000";
  85. log.info("{}", testData.length());
  86. String sFrom = testData.substring(4,6) + "월" + testData.substring(6,8) + "일 " + testData.substring(8,10) + "시";
  87. log.info("{}", sFrom);
  88. }
  89. @Test
  90. void test2() {
  91. String testData = " ";
  92. log.info("{}", StringUtils.isEmpty(StringUtils.trim(testData)));
  93. }
  94. @Test
  95. void test3() {
  96. // byte b = (byte)0xFF;
  97. // eVmsOpCode opCode = eVmsOpCode.getValue(b);
  98. // log.info("{}, {}", b, opCode);
  99. }
  100. @Test
  101. void crc() {
  102. //byte[] data = {(byte)0x05, (byte)0x9A, (byte)0x01, (byte)0x01, (byte)0x1A, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x23, (byte)0x28, (byte)0x00, (byte)0x01, (byte)0x23, (byte)0x28, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x00, (byte)0x07, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x20, (byte)0x00, (byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x0B};
  103. byte[] data = {(byte)0x10, (byte)0x02,
  104. (byte)0x00, (byte)0x05, (byte)0x9A, (byte)0x01, (byte)0x01, (byte)0x1A, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x23,
  105. (byte)0x28, (byte)0x00, (byte)0x01, (byte)0x23, (byte)0x28, (byte)0x01, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x02,
  106. (byte)0x00, (byte)0x07, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x20,
  107. (byte)0x00, (byte)0xA0, (byte)0x00, (byte)0x00, (byte)0x0B,
  108. (byte)0x10, (byte)0x03, (byte)0x00, (byte)0x04};
  109. // int arc = Crc16.ARC(data, 2, data.length - 6);
  110. // log.info("ARC: {}, {}", arc, String.format("%X", arc));
  111. // int arc1 = VmsDleFramePacket.getCRC16ARC(data, 2, data.length - 6);
  112. // log.info("ARC: {}, {}", arc1, String.format("%X", arc1));
  113. }
  114. @Test
  115. void hangul() {
  116. String str = "30km 이하 서행!";
  117. //default charset 으로 인코딩된 바이트 배열
  118. byte[] bytes = str.getBytes();
  119. //인코딩된 바이트 출력
  120. System.out.print("Default charset encoding: ");
  121. for(int i=0;i<bytes.length;i++)
  122. System.out.print(bytes[i]+" ");
  123. System.out.println();
  124. //default charset 으로 디코딩된 문자열 출력
  125. String decoded = new String(bytes);
  126. System.out.println(decoded);
  127. System.out.println();
  128. try {
  129. //UTF-8로 인코딩된 바이트 배열
  130. bytes = str.getBytes("UTF-8");
  131. System.out.print("UTF-8 charset encoding: ");
  132. for(int i=0;i<bytes.length;i++)
  133. System.out.print(bytes[i]+" ");
  134. System.out.println();
  135. //이 바이트 배열을 default charset 으로 디코딩된 문자열 출력 : charset 이 다르므로 한글이 깨짐.
  136. decoded = new String(bytes);
  137. System.out.println(decoded);
  138. //인코딩된 UTF-8로 디코딩되어 한글이 깨지지 않음.
  139. decoded = new String(bytes,"UTF-8");
  140. System.out.println(decoded);
  141. } catch (UnsupportedEncodingException e) {
  142. // TODO Auto-generated catch block
  143. e.printStackTrace();
  144. }
  145. }
  146. @Test
  147. void hangul2() {
  148. String str = "30km 이하 서행!";
  149. byte[] arr1 = str.getBytes();
  150. byte[] arr2 = SysUtils.stringToByteArr(str);
  151. log.error("{}, {}, {}", str.length(), arr1.length, arr2.length);
  152. }
  153. @Test
  154. void getDnldNmbr() {
  155. // log.info("{}", VmsSymbService.getDnldSymbNmbr("60100"));
  156. // log.info("{}", VmsSymbService.getDnldSymbNmbr("80061"));
  157. // log.info("{}", VmsSymbService.getDnldSymbNmbr("80060"));
  158. // log.info("{}", VmsSymbService.getDnldSymbNmbr("80021"));
  159. // log.info("{}", VmsSymbService.getDnldSymbNmbr("8002"));
  160. //
  161. // log.info("{}", VmsFormService.getDnldFormNo(10013));
  162. // log.info("{}", VmsFormService.getDnldFormNo(10054));
  163. // log.info("{}", VmsFormService.getDnldFormNo(10186));
  164. // log.info("{}", VmsFormService.getDnldFormNo(13));
  165. }
  166. String shortToBinaryString(String binary) {
  167. String result = binary;
  168. if (result.length() > 16) {
  169. return result.substring(16, 32);
  170. }
  171. if (binary.length() < 16) {
  172. int cnt = 16 - binary.length();
  173. String tmp = "";
  174. for (int ii = 0; ii < cnt; ii++) {
  175. tmp += "0";
  176. }
  177. return tmp + binary;
  178. }
  179. return binary;
  180. }
  181. @Test
  182. void crcTest() {
  183. // 2의 보수(2s complement)
  184. short n = 10;
  185. short result = ItsUtils.orgToTwoComplement(n);
  186. String binary = ItsUtils.shortToBinaryString(Integer.toBinaryString(result));
  187. log.info("{}, {}, {}", binary, n, (int)result);
  188. short result1 = (short) ~n;
  189. log.info("{}, {}", result1, (result1 + 1));
  190. // 2s complement 를 원래의 값으로...
  191. short o = ItsUtils.twoComplementToOrg(result);
  192. String binary5 = shortToBinaryString(Integer.toBinaryString(o));
  193. log.info("{}, {}", binary5, o);
  194. }
  195. @Test
  196. void arrayCopy() {
  197. byte[] facilityIds = new byte[5];
  198. int facilityIdSize = 15;
  199. byte[] newFacilityIds = new byte[facilityIdSize];
  200. if (facilityIds.length < facilityIdSize) {
  201. facilityIdSize = facilityIds.length;
  202. }
  203. System.arraycopy(facilityIds, 0, newFacilityIds, 0, facilityIdSize);
  204. log.info("{}", facilityIds);
  205. }
  206. @Test
  207. void esbPacket() {
  208. // EsbReqVmsShortMsg vmsShortMsg = new EsbReqVmsShortMsg("ADTRVMS00100001", 1, 2, 24, "가나다123AB CD");
  209. // ByteBuffer byteBuffer = vmsShortMsg.getByteBuffer();
  210. // byte[] packet = byteBuffer.array();
  211. // log.info("{}", SysUtils.byteArrayToHexAscii(packet));
  212. }
  213. @Test
  214. void esbCrcTest() {
  215. // byte[] bbCrc = EsbFrameTail.hexToByteArray("00 20".replace(" ", ""));
  216. // byte[] bb = EsbFrameTail.hexToByteArray("54 52 53 44 46 30 30 39 30 30 36 30 30 56 4d 53 30 30 30 31 32 30 31 36 30 38 32 35 32 30 34 37 30 32 00 00 00 11 02 00 50 00 00 00 0f 30 30 30 36".replace(" ", ""));
  217. // short crc = EsbFrameTail.getCrc(bb);
  218. // log.info("{}", crc);
  219. }
  220. //[
  221. // {
  222. // "tenant": {
  223. // "entityStatus": null,
  224. // "regUser": null,
  225. // "regDate": null,
  226. // "modUser": null,
  227. // "modDate": null,
  228. // "entityId": null,
  229. // "name": "test2",
  230. // "alias": "test2",
  231. // "description": null,
  232. // "logoType": null,
  233. // "logo1Token": null,
  234. // "logo1ImageUrl": null,
  235. // "logo2Token": null,
  236. // "logo2ImageUrl": null
  237. // },
  238. // "deviceName": "LOADER-VOD-36687",
  239. // "productName": null,
  240. // "modelName": null,
  241. // "deviceIdType": null,
  242. // "deviceId": "6D-45-C4-08-AA-B6",
  243. // "deviceToken": "a738fcf994e14d8cbb99e4db244a687c",
  244. // "deviceStatus": "ACTIVE",
  245. // "deviceType": "ROVER",
  246. // "deviceClassification": "A05_ETC",
  247. // "lastConnectionStatus": "CONNECTED",
  248. // "lastConnectionDatetime": 1619505455498,
  249. // "gnssInfo": {
  250. // "deviceId": "6D-45-C4-08-AA-B6",
  251. // "deviceTime": 1619505737630,
  252. // "type": "nmea",
  253. // "raw": "$GPGGA,064217.63,3729.1261326,N,12653.6691112,E,1,00,1.0,19.203,M,0.000,M,0.0,*4C\r\n$GNRMC,064217.63,A,3729.1261326,N,12653.6691112,E,1.34,250.29,270421,0.0,E,A,V*5F\r\n$GNVTG,250.29,T,,M,1.339,N,2.480,K,D*2C\r\n$GNGST,064217.63,10,1.000,1.000,1.000,0.700,5.960,8.770*61\r",
  254. // "hertz": 0,
  255. // "latitude": 37.48543554333333,
  256. // "longitude": 126.89448518666667,
  257. // "height": 19.203,
  258. // "speed": 2.48,
  259. // "angle": 250.29,
  260. // "pdop": 0,
  261. // "fixStatus": "NORMAL",
  262. // "baseStation": "UNKNOWN",
  263. // "rmsX": 5.96,
  264. // "rmsY": 0.7,
  265. // "rmsZ": 8.77,
  266. // "ecefX": -3042181.7143300786,
  267. // "ecefY": 4052617.9642652427,
  268. // "ecefZ": 3860293.232899369,
  269. // "satellites": []
  270. // },
  271. // "healthInfo": {
  272. // "deviceId": "6D-45-C4-08-AA-B6",
  273. // "osFamily": "Raspbian GNU/Linux",
  274. // "osVersion": "10",
  275. // "cpuUsage": 14.85,
  276. // "freeMemory": 697125639,
  277. // "totalMemory": 970825728,
  278. // "freeStorage": {
  279. // "/": 61164593113
  280. // },
  281. // "totalStorage": {
  282. // "/": 62738714624
  283. // },
  284. // "temperature": 50.7,
  285. // "bettery": 72,
  286. // "networkType": "ETHERNET",
  287. // "collectedDate": null
  288. // },
  289. // "satelliteCount": 0,
  290. // "carId": null,
  291. // "carNumber": null,
  292. // "routeId": null,
  293. // "runStatus": null
  294. // }
  295. //]
  296. }