GroundDIsplayCommuncator.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using Message;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace Communication
  8. {
  9. class GroundDIsplayCommuncator : Communication.Communicator
  10. {
  11. protected GroundDIsplayCommuncator():base()
  12. {
  13. }
  14. /// <summary>
  15. /// 单例访问
  16. /// </summary>
  17. public new static Communicator GetInstance()
  18. {
  19. if (instance == null)
  20. {
  21. lock (lockObj)
  22. {
  23. if (instance == null)
  24. {
  25. instance = new GroundDIsplayCommuncator();
  26. }
  27. }
  28. }
  29. return instance;
  30. }
  31. /// <summary>
  32. /// 检查消息
  33. /// </summary>
  34. /// <param name="header"></param>
  35. /// <returns></returns>
  36. public override bool CheckMsg(Base_info header)
  37. {
  38. if (header.HasMsgType && header.HasSender && header.HasTimeoutMs
  39. && header.MsgType == Message_type.EGroundStatusMsg && header.Sender == Message.Communicator.EGroundMeasurer)
  40. return true;
  41. else
  42. return false;
  43. }
  44. /// <summary>
  45. /// 检查执行器状态
  46. /// </summary>
  47. /// <param name="header"></param>
  48. /// <param name="receiveTime"></param>
  49. /// <returns></returns>
  50. public override CheckExecuterReturn CheckExecuter(Base_info header, DateTime receiveTime)
  51. {
  52. if ((DateTime.Now - receiveTime).Milliseconds > header.TimeoutMs)
  53. return CheckExecuterReturn.MSG_TIMEOUT;
  54. else
  55. return CheckExecuterReturn.EXECUTER_READY;
  56. }
  57. /// <summary>
  58. /// 执行消息
  59. /// </summary>
  60. /// <param name="msgStamped"></param>
  61. /// <returns></returns>
  62. public override bool ExecuteMsg(MsgStamped msgStamped)
  63. {
  64. Ground_status_msg msg = Ground_status_msg.Parser.ParseFrom(msgStamped.msg);
  65. Console.WriteLine(Ground_status_msg.Parser.ParseJson(msg.ToString()));
  66. return true;
  67. }
  68. }
  69. }