WifiMould.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include <memory>
  3. #include "ResDataObject.h"
  4. #include "DIOS.Dev.IODevice.hpp"
  5. #include "DIOS.Dev.MouldDefine.hpp"
  6. namespace DIOS::Dev::Detail
  7. {
  8. #pragma region DeviceWifiMould
  9. class DeviceWifiMould : public IntMouldWithWarn
  10. {
  11. typedef enum ECOM_Wifi_state
  12. {
  13. ECOM_WIFI_STATE_TOO_LOW = 0,
  14. ECOM_WIFI_STATE_LOW,
  15. ECOM_WIFI_STAE_NORMAL,
  16. ECOM_WIFI_STATE_GOOD,
  17. ECOM_WIFI_STATE_FULL
  18. }ECOM_WIFI_STATE;
  19. int m_CurrentValue;
  20. //ResDataObject m_Cache;
  21. std::shared_ptr <DIOS::Dev::IOEventCenter> m_EventCenter;
  22. std::string m_Key;
  23. public:
  24. using super = IntMouldWithWarn;
  25. DeviceWifiMould(const char* strkey, int initialvalue, int min, int WarnMin, int WarnMax, int max, int accuracy, std::shared_ptr <DIOS::Dev::IOEventCenter> EventCenter)
  26. :super(strkey, initialvalue, min, WarnMin, WarnMax, 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_s(szFDinfo, "%d", m_CurrentValue);
  49. out = szFDinfo;
  50. return RET_STATUS::RET_SUCCEED;
  51. }
  52. bool SetSignalValue(int nValue, int & nStatus)
  53. {
  54. if (nValue != m_CurrentValue)
  55. {
  56. m_CurrentValue = nValue;
  57. if (m_WarningMin <= nValue)
  58. {
  59. nStatus = ECOM_WIFI_STAE_NORMAL;
  60. }
  61. else if (m_LimitMin <= nValue && nValue < m_WarningMin)
  62. {
  63. nStatus = ECOM_WIFI_STATE_LOW;
  64. }
  65. else if (nValue < m_LimitMin)
  66. {
  67. nStatus = ECOM_WIFI_STATE_TOO_LOW;
  68. }
  69. char szFDinfo[MAX_STRING] = { 0 };
  70. sprintf_s(szFDinfo, "%d", nValue);
  71. //std::string str = szFDinfo;
  72. m_EventCenter->OnNotify((int)ATTRACTION_SET, "Wifi_Strength_Value", szFDinfo);
  73. }
  74. return true;
  75. };
  76. };
  77. #pragma endregion DeviceWifiMould
  78. }