北斗定位
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

107 行
3.9KB

  1. package com.telpo.dipperposition.service.impl;
  2. import com.telpo.dipperposition.common.HexConvert;
  3. import com.telpo.dipperposition.common.SocketClient;
  4. import com.telpo.dipperposition.service.IDipperAstTimeAsyncTaskService;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.scheduling.annotation.Async;
  8. import org.springframework.stereotype.Service;
  9. import java.time.LocalDateTime;
  10. /**
  11. * @program: DipperDataAsyncTaskServiceImpl
  12. * @description: 发送SDBP-AST-TIME获取时间信息
  13. * @author: king
  14. * @create: 2021-01-10 14:01
  15. */
  16. @Service
  17. @Slf4j
  18. public class DipperAstTimeAsyncTaskServiceImpl implements IDipperAstTimeAsyncTaskService {
  19. @Override
  20. @Async("asyncServiceExecutor")
  21. public String pushAstTime() {
  22. // (1) 发送SDBP-AST-TIME
  23. // String sendResult = pushTimeToDipper();
  24. //if (sendResult == null) {
  25. // log.error("取不到时间。");
  26. // return null;
  27. //}
  28. // (2) 获取时间信息
  29. return pushTimeToDipper();
  30. //return sendResult;
  31. }
  32. private String pushTimeToDipper() {
  33. // 创建Socket客户端实例;
  34. // SocketClient client = new SocketClient(astServer, timeAstPort, astTimeout);
  35. // 时间和位置不是从服务器获取,而是本地生成(其中时间误差不超过3s)
  36. // 23 3E 04 02 10 00 20 E1 07 09 14 0C 22 38 00 00 00 00 00 28 6B EE 22 98
  37. // 23 3E 为同步头
  38. // 04 02 为识别码
  39. // 10 00 表示长度为 16
  40. // --日期--
  41. // 20 E1 表示闰秒改正数为
  42. // E1 07 表示年为 2017 年(十六进制 07E1 转为十进制)
  43. // 09 表示 9 月
  44. // 14 表示 20 日
  45. // 0C 22 38 00 00 00 00 00 表示 UTC时间,为12时34分56.0秒(小数秒建议固定为 0)
  46. // 00 28 6B EE 表示 4 秒的时间精度(十六进制 EE6B2800 转为十进制为 4000000000,乘以比 例因子 10-9就是 4 秒)
  47. // 00 2F 为校验和
  48. // TODO astTimeCmd 组装
  49. String astTimeCmd = "233E0402";
  50. astTimeCmd += "1000";
  51. astTimeCmd += "20E1";
  52. LocalDateTime now = LocalDateTime.now();
  53. int year = now.getYear();
  54. int month = now.getMonthValue();
  55. int day = now.getDayOfMonth();
  56. String hexYearString = Integer.toHexString(year);
  57. hexYearString = "0" + hexYearString;
  58. astTimeCmd += hexYearString.substring(2,2) + hexYearString.substring(0,2);
  59. String hexMonthString = Integer.toHexString(month);
  60. hexMonthString = "0" + hexMonthString;
  61. astTimeCmd += hexMonthString;
  62. String hexDayString = Integer.toHexString(day);
  63. if (day < 16) {
  64. hexDayString = "0" + hexDayString;
  65. }
  66. astTimeCmd += hexDayString;
  67. int hour = now.getHour();
  68. int minitor = now.getMinute();
  69. int second = now.getSecond();
  70. String hexHourString = Integer.toHexString(hour);
  71. if (hour < 16) {
  72. hexHourString = "0" + hexHourString;
  73. }
  74. astTimeCmd += hexHourString;
  75. String hexMinitorString = Integer.toHexString(minitor);
  76. if (minitor < 16) {
  77. hexMinitorString = "0" + hexMinitorString;
  78. }
  79. astTimeCmd += hexMinitorString;
  80. String hexSecondString = Integer.toHexString(second);
  81. if (second < 16) {
  82. hexSecondString = "0" + hexSecondString;
  83. }
  84. astTimeCmd += hexSecondString;
  85. astTimeCmd += "0000000000";
  86. astTimeCmd += "00286BEE";
  87. //String hexIn = HexConvert.convertStringToHex(astTimeCmd) + HexConvert.makeChecksum(astTimeCmd);
  88. String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd);
  89. //String ackAckCheckRef = "233E0101020004020A1D";
  90. //String sendResult = client.sendCmd(hexIn, ackAckCheckRef);
  91. //client.closeConnection();
  92. return hexIn;
  93. }
  94. }