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.
 
 

131 lines
4.2 KiB

  1. using HBLConsole.Service;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace HBLDevice.ICChip
  8. {
  9. public class ChipStatus : Singleton<ChipStatus>
  10. {
  11. private DateTime lastRefreshTime = DateTime.MinValue;
  12. /// <summary>
  13. /// 是否在线
  14. /// </summary>
  15. public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } }
  16. /// <summary>
  17. /// 取冰淇淋杯完成
  18. /// </summary>
  19. public bool CompletedTake_CPU_CUP_ICECREAM { get; set; }
  20. /// <summary>
  21. /// 取咖啡杯完成
  22. /// </summary>
  23. public bool CompletedTake_CPU_CUP_COFFEE { get; set; }
  24. /// <summary>
  25. /// 1号舵机打开完成
  26. /// </summary>
  27. public bool CompletedOpen_SE_1 { get; set; }
  28. /// <summary>
  29. /// 2号舵机打开完成
  30. /// </summary>
  31. public bool CompletedOpen_SE_2 { get; set; }
  32. /// <summary>
  33. /// 3号舵机打开完成
  34. /// </summary>
  35. public bool CompletedOpen_SE_3 { get; set; }
  36. /// <summary>
  37. /// 1号舵机关闭完成
  38. /// </summary>
  39. public bool CompletedClose_SE_1 { get; set; }
  40. /// <summary>
  41. /// 2号舵机关闭完成
  42. /// </summary>
  43. public bool CompletedClose_SE_2 { get; set; }
  44. /// <summary>
  45. /// 3号舵机关闭完成
  46. /// </summary>
  47. public bool CompletedClose_SE_3 { get; set; }
  48. /// <summary>
  49. /// 是否存在物品
  50. /// </summary>
  51. public bool ArticleExits { get; set; }
  52. /// <summary>
  53. /// 物品距离
  54. /// </summary>
  55. public byte ArticleDist { get; set; }
  56. public bool CanDo
  57. {
  58. get
  59. {
  60. if (!OnLine)
  61. return false;
  62. return true;
  63. }
  64. }
  65. public void ProcessMsg(ICChipPackage data)
  66. {
  67. try
  68. {
  69. switch (data.Cmd)
  70. {
  71. case IC_CMD.HEART_BEAT:
  72. lastRefreshTime = DateTime.Now;
  73. break;
  74. case IC_CMD.TAKE_CUP:
  75. switch ((IC_CUP)data.Value)
  76. {
  77. case IC_CUP.CUP_COFFEE:
  78. CompletedTake_CPU_CUP_COFFEE = true;
  79. break;
  80. case IC_CUP.CUP_ICECREAM:
  81. CompletedTake_CPU_CUP_ICECREAM = true;
  82. break;
  83. }
  84. break;
  85. case IC_CMD.OPEN_SE:
  86. switch ((IC_SE)data.Value)
  87. {
  88. case IC_SE.SE_1:
  89. CompletedOpen_SE_1 = true;
  90. break;
  91. case IC_SE.SE_2:
  92. CompletedOpen_SE_2 = true;
  93. break;
  94. case IC_SE.SE_3:
  95. CompletedOpen_SE_3 = true;
  96. break;
  97. }
  98. break;
  99. case IC_CMD.CLOSE_SE:
  100. switch ((IC_SE)data.Value)
  101. {
  102. case IC_SE.SE_1:
  103. CompletedClose_SE_1 = true;
  104. break;
  105. case IC_SE.SE_2:
  106. CompletedClose_SE_2 = true;
  107. break;
  108. case IC_SE.SE_3:
  109. CompletedClose_SE_3 = true;
  110. break;
  111. }
  112. break;
  113. case IC_CMD.ARTICLE_EXITS:
  114. ArticleExits = data.Value > 0;
  115. break;
  116. case IC_CMD.ARTICLE_DIST:
  117. ArticleDist = data.Value;
  118. break;
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. }
  124. }
  125. }
  126. }