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.

141 lines
3.6 KiB

3 months ago
  1. #include "gstate_mgr.hpp"
  2. #include "app_event_bus.hpp"
  3. using namespace std;
  4. using namespace iflytop;
  5. #define TAG "GSM"
  6. #define GSM GStateMgr::ins()
  7. void GStateMgr::initialize() { m_mutex.init(); }
  8. /***********************************************************************************************************************
  9. * USER *
  10. ***********************************************************************************************************************/
  11. void GStateMgr::setLogin(int loginUsrId, const char* usrName, user_role_t role) {
  12. zlock_guard l(m_mutex);
  13. m_loginUsrType = role;
  14. m_isLogin = true;
  15. strncpy(this->m_loginUsr, usrName, MAX_USR_NAME_SIZE);
  16. m_loginUsrId = loginUsrId;
  17. }
  18. void GStateMgr::setUnLogin() {
  19. zlock_guard l(m_mutex);
  20. m_isLogin = false;
  21. m_loginUsrType = kuser;
  22. memset(m_loginUsr, 0, sizeof(m_loginUsr));
  23. }
  24. bool GStateMgr::isLogin() {
  25. zlock_guard l(m_mutex);
  26. return m_isLogin;
  27. }
  28. user_role_t GStateMgr::getLoginUsrType() {
  29. zlock_guard l(m_mutex);
  30. return m_loginUsrType;
  31. }
  32. const char* GStateMgr::getLoginUsr() {
  33. zlock_guard l(m_mutex);
  34. return m_loginUsr;
  35. }
  36. int GStateMgr::getUserId() {
  37. zlock_guard l(m_mutex);
  38. return m_loginUsrId;
  39. }
  40. void GStateMgr::setRemoterHeart(int32_t state, uint8_t* heart_data) {
  41. zlock_guard l(m_mutex);
  42. AppEvent appevent;
  43. m_RemoterS = state;
  44. appevent.type = kAE_RemoterHeartEvent;
  45. appevent.setHeartInfo(heart_data);
  46. AppEventBus::ins()->pushEvent(appevent);
  47. }
  48. //
  49. void GStateMgr::setRemoterS(int32_t state, const char* name) {
  50. zlock_guard l(m_mutex);
  51. AppEvent appevent;
  52. m_RemoterS = state;
  53. if (state) {
  54. ZLOGI(TAG, "on ble connect -> client name:%s", name);
  55. strncpy(m_RemoterName, name, sizeof(m_RemoterName));
  56. // strncpy(appevent.d.bleName, name, sizeof(appevent.d.bleName));
  57. appevent.type = kAE_RemoterConnectedEvent;
  58. } else {
  59. ZLOGI(TAG, "on ble disconnect");
  60. appevent.type = kAE_RemoterDisConnectedEvent;
  61. }
  62. AppEventBus::ins()->pushEvent(appevent);
  63. }
  64. const char* GStateMgr::getRemoterName() {
  65. zlock_guard l(m_mutex);
  66. return m_RemoterName;
  67. }
  68. void GStateMgr::setRunMode(hand_acid_mode_t mode) {
  69. zlock_guard l(m_mutex);
  70. if (m_RunMode != mode) {
  71. m_RunMode = mode;
  72. AppEventBus::ins()->pushSimpleEvent(kAE_RunModeChangeEvent);
  73. }
  74. }
  75. void GStateMgr::changeToNextRunMode() {
  76. zlock_guard l(m_mutex);
  77. if (m_RunMode == khand_acid_m_jog_mode) {
  78. setRunMode(khand_acid_m_continuous_mode);
  79. } else {
  80. setRunMode(khand_acid_m_jog_mode);
  81. }
  82. }
  83. int32_t GStateMgr::getRemoterS() {
  84. zlock_guard l(m_mutex);
  85. return m_RemoterS;
  86. }
  87. hand_acid_mode_t GStateMgr::getRunMode() {
  88. zlock_guard l(m_mutex);
  89. return m_RunMode;
  90. }
  91. void GStateMgr::setPumpSelectState(int32_t index, bool state) {
  92. zlock_guard l(m_mutex);
  93. m_pumpSelectState[index] = state;
  94. }
  95. bool GStateMgr::getPumpSelectState(int32_t index) {
  96. zlock_guard l(m_mutex);
  97. return m_pumpSelectState[index];
  98. }
  99. float GStateMgr::getAcidRemain(int32_t index) {
  100. zlock_guard l(m_mutex);
  101. return acidRemain[index]; // add 0.5 for force change to int
  102. }
  103. float GStateMgr::getAcidUsed(int32_t index) {
  104. zlock_guard l(m_mutex);
  105. return acidUsed[index]; // add 0.5 for force change to int
  106. }
  107. bool GStateMgr::isHasPumpSelect() {
  108. zlock_guard l(m_mutex);
  109. for (int i = 0; i < 4; i++) {
  110. if (m_pumpSelectState[i]) {
  111. return true;
  112. }
  113. }
  114. return false;
  115. }
  116. void GStateMgr::setAcidRemain(int32_t index, float val) {
  117. zlock_guard l(m_mutex);
  118. acidRemain[index] = val;
  119. }
  120. void GStateMgr::setAcidUsed(int32_t index, float val) {
  121. zlock_guard l(m_mutex);
  122. acidUsed[index] = val;
  123. }