WifiMould.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #pragma once
  2. #include <memory>
  3. #include "ResDataObject.h"
  4. #include "CCOS.Dev.IODevice.hpp"
  5. #include "CCOS.Dev.MouldDefine.hpp"
  6. namespace CCOS::Dev::Detail
  7. {
  8. class DeviceWifiMould : public IntMouldWithWarn
  9. {
  10. typedef enum ECOM_Wifi_state
  11. {
  12. ECOM_WIFI_STATE_TOO_LOW = 0,
  13. ECOM_WIFI_STATE_LOW,
  14. ECOM_WIFI_STAE_NORMAL,
  15. ECOM_WIFI_STATE_GOOD,
  16. ECOM_WIFI_STATE_FULL
  17. }ECOM_WIFI_STATE;
  18. int m_CurrentValue;
  19. std::shared_ptr <CCOS::Dev::IOEventCenter> m_EventCenter;
  20. std::string m_Key;
  21. public:
  22. using super = IntMouldWithWarn;
  23. DeviceWifiMould(const char* strkey, int initialvalue, int min, int WarnMin, int WarnMax,
  24. int CalibWarnMin, int CalibWarnMax, int max, int accuracy,
  25. std::shared_ptr <CCOS::Dev::IOEventCenter> EventCenter)
  26. :super(strkey, initialvalue, min, WarnMin, WarnMax, CalibWarnMin, CalibWarnMax, max, accuracy)
  27. {
  28. m_Key = strkey;
  29. m_EventCenter = EventCenter;
  30. m_CurrentValue = 0;
  31. }
  32. ~DeviceWifiMould() {}
  33. std::string GetDescription()
  34. {
  35. ResDataObject temp, result;
  36. temp.add(ValKey::UPPERLIMIT, m_LimitMax);
  37. temp.add(ValKey::LOWERLIMIT, m_LimitMin);
  38. temp.add(ValKey::WARNUPPERLIMIT, m_WarningMax);
  39. temp.add(ValKey::WARNLOWERLIMIT, m_WarningMin);
  40. temp.add(ValKey::ACCURACY, m_Accuracy);
  41. temp.add(ValKey::UNIT, m_Key.c_str());
  42. result.add(Key.c_str(), temp);
  43. return result.encode();
  44. }
  45. RET_STATUS JSGetCurrentSignalValue(std::string& out)
  46. {
  47. char szFDinfo[MAX_STRING] = { 0 };
  48. sprintf(szFDinfo, "%d", m_CurrentValue);
  49. out = szFDinfo;
  50. return RET_STATUS::RET_SUCCEED;
  51. }
  52. bool SetSignalValue(int nValue, int & nStatus)
  53. {
  54. m_CurrentValue = nValue;
  55. if (m_WarningMin <= nValue)
  56. {
  57. nStatus = ECOM_WIFI_STAE_NORMAL;
  58. }
  59. else if (m_LimitMin <= nValue && nValue < m_WarningMin)
  60. {
  61. nStatus = ECOM_WIFI_STATE_LOW;
  62. }
  63. else if (nValue < m_LimitMin)
  64. {
  65. nStatus = ECOM_WIFI_STATE_TOO_LOW;
  66. }
  67. char szFDinfo[MAX_STRING] = { 0 };
  68. sprintf(szFDinfo, "%d", nValue);
  69. m_EventCenter->OnNotify((int)ATTRACTION_SET, "Wifi_Strength_Value", szFDinfo);
  70. return true;
  71. };
  72. RET_STATUS JSGetSignalErrorMin(std::string& out)
  73. {
  74. char szFDinfo[MAX_STRING] = { 0 };
  75. sprintf(szFDinfo, "%d", m_LimitMin);
  76. out = szFDinfo;
  77. return RET_STATUS::RET_SUCCEED;
  78. }
  79. RET_STATUS SetSignalErrorMin(string nValue)
  80. {
  81. int temp = atoi(nValue.c_str());
  82. if (m_LimitMin == temp)
  83. {
  84. return RET_STATUS::RET_SUCCEED;
  85. }
  86. m_LimitMin = temp;
  87. char szFDinfo[MAX_STRING] = { 0 };
  88. sprintf(szFDinfo, "%d", m_LimitMin);
  89. m_EventCenter->OnNotify((int)ATTRACTION_SET, "WifiMiniLimit", szFDinfo);
  90. return RET_STATUS::RET_SUCCEED;
  91. }
  92. RET_STATUS JSGetSignalWarningMin(std::string& out)
  93. {
  94. char szFDinfo[MAX_STRING] = { 0 };
  95. sprintf(szFDinfo, "%d", m_WarningMin);
  96. out = szFDinfo;
  97. return RET_STATUS::RET_SUCCEED;
  98. }
  99. RET_STATUS SetSignalWarningMin(string nValue)
  100. {
  101. int temp = atoi(nValue.c_str());
  102. if (m_WarningMin == temp)
  103. {
  104. return RET_STATUS::RET_SUCCEED;
  105. }
  106. m_WarningMin = temp;
  107. char szFDinfo[MAX_STRING] = { 0 };
  108. sprintf(szFDinfo, "%d", m_WarningMin);
  109. m_EventCenter->OnNotify((int)ATTRACTION_SET, "WifiLowerLimit", szFDinfo);
  110. return RET_STATUS::RET_SUCCEED;
  111. }
  112. RET_STATUS JSUpdateSignalWarningMin(string in, string& out)
  113. {
  114. out = in;
  115. return SetSignalWarningMin(in);
  116. }
  117. RET_STATUS JSUpdateSignalErrorMin(string in, string& out)
  118. {
  119. out = in;
  120. return SetSignalErrorMin(in);
  121. }
  122. };//DeviceWifiMould
  123. }