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 BPA.Utility;
  2. using HBLConsole.Service;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace HBLDevice.ICChip
  9. {
  10. public class ChipStatus : Singleton<ChipStatus>
  11. {
  12. private DateTime lastRefreshTime = DateTime.MinValue;
  13. /// <summary>
  14. /// 是否在线
  15. /// </summary>
  16. public bool OnLine { get { return DateTime.Now.Subtract(lastRefreshTime).TotalSeconds <= 3; } }
  17. /// <summary>
  18. /// 取冰淇淋杯完成
  19. /// </summary>
  20. public bool CompletedTake_CPU_CUP_ICECREAM { get; set; }
  21. /// <summary>
  22. /// 取咖啡杯完成
  23. /// </summary>
  24. public bool CompletedTake_CPU_CUP_COFFEE { get; set; }
  25. /// <summary>
  26. /// 1号舵机打开完成
  27. /// </summary>
  28. public bool CompletedOpen_SE_1 { get; set; }
  29. /// <summary>
  30. /// 2号舵机打开完成
  31. /// </summary>
  32. public bool CompletedOpen_SE_2 { get; set; }
  33. /// <summary>
  34. /// 3号舵机打开完成
  35. /// </summary>
  36. public bool CompletedOpen_SE_3 { get; set; }
  37. /// <summary>
  38. /// 1号舵机关闭完成
  39. /// </summary>
  40. public bool CompletedClose_SE_1 { get; set; }
  41. /// <summary>
  42. /// 2号舵机关闭完成
  43. /// </summary>
  44. public bool CompletedClose_SE_2 { get; set; }
  45. /// <summary>
  46. /// 3号舵机关闭完成
  47. /// </summary>
  48. public bool CompletedClose_SE_3 { get; set; }
  49. /// <summary>
  50. /// 是否存在物品
  51. /// </summary>
  52. public bool ArticleExits { get; set; }
  53. /// <summary>
  54. /// 物品距离
  55. /// </summary>
  56. public byte ArticleDist { get; set; }
  57. public bool CanDo
  58. {
  59. get
  60. {
  61. if (!OnLine)
  62. return false;
  63. return true;
  64. }
  65. }
  66. public void ProcessMsg(ICChipPackage data)
  67. {
  68. try
  69. {
  70. switch (data.Cmd)
  71. {
  72. case IC_CMD.HEART_BEAT:
  73. lastRefreshTime = DateTime.Now;
  74. break;
  75. case IC_CMD.TAKE_CUP:
  76. switch ((IC_CUP)data.Value) {
  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. }