北斗定位
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.2KB

  1. package com.telpo.dipperposition.service.impl;
  2. import com.telpo.dipperposition.common.HexConvert;
  3. import com.telpo.dipperposition.common.RedisUtil;
  4. import com.telpo.dipperposition.common.SocketClient;
  5. import com.telpo.dipperposition.config.SchedulingExecutorConfig;
  6. import com.telpo.dipperposition.service.IDipperDataAsyncTaskService;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.scheduling.annotation.Async;
  10. import org.springframework.stereotype.Service;
  11. /**
  12. * @program: DipperDataAsyncTaskServiceImpl
  13. * @description: 获取星历数据。
  14. * @author: king
  15. * @create: 2021-01-10 14:01
  16. */
  17. @Service
  18. @Slf4j
  19. public class DipperDataAsyncTaskServiceImpl implements IDipperDataAsyncTaskService {
  20. private static String DIPPER_DATA_KEY = "TaidouDipperData";
  21. private static String DIPPER_ALL_DATA_REQ = "616C6C";
  22. @Autowired
  23. private RedisUtil redisUtil;
  24. @Autowired
  25. private SchedulingExecutorConfig schedulingExecutorConfig;
  26. @Override
  27. @Async("asyncServiceExecutor")
  28. public void pullAstEPH() {
  29. // (1) 发送bds获取星历数据
  30. String dipperData = pullEPHFromDipper();
  31. // (2) 获取星历数据
  32. if (dipperData == null) {
  33. log.error("获取星历数据错误,取不到星历数据。");
  34. } else {
  35. // 保存到DB或者缓存
  36. log.info("保存到DB或者缓存");
  37. redisUtil.set(DIPPER_DATA_KEY,dipperData);
  38. }
  39. }
  40. private String pullEPHFromDipper() {
  41. // 创建Socket客户端实例;
  42. SocketClient client = new SocketClient(schedulingExecutorConfig.getAstServer(), schedulingExecutorConfig.getEphAstHexPort(),schedulingExecutorConfig.getAstTimeout());
  43. // astTimeCmd 组装
  44. String astTimeCmd = DIPPER_ALL_DATA_REQ;
  45. String hexIn = astTimeCmd + HexConvert.makeChecksum(astTimeCmd);
  46. String ackAckCheckRef = "233E010102000421293C";
  47. String sendResult = client.sendCmd(hexIn, ackAckCheckRef);
  48. client.closeConnection();
  49. return sendResult;
  50. }
  51. @Override
  52. public String getAstEPH(){
  53. return (String)redisUtil.get(DIPPER_DATA_KEY);
  54. }
  55. }