123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #pragma once
- #include <memory>
- #include "ResDataObject.h"
- #include "CCOS.Dev.IODevice.hpp"
- #include "CCOS.Dev.MouldDefine.hpp"
- namespace CCOS::Dev::Detail
- {
- class DeviceWifiMould : public IntMouldWithWarn
- {
- typedef enum ECOM_Wifi_state
- {
- ECOM_WIFI_STATE_TOO_LOW = 0,
- ECOM_WIFI_STATE_LOW,
- ECOM_WIFI_STAE_NORMAL,
- ECOM_WIFI_STATE_GOOD,
- ECOM_WIFI_STATE_FULL
- }ECOM_WIFI_STATE;
- int m_CurrentValue;
- std::shared_ptr <CCOS::Dev::IOEventCenter> m_EventCenter;
- std::string m_Key;
- public:
- using super = IntMouldWithWarn;
- DeviceWifiMould(const char* strkey, int initialvalue, int min, int WarnMin, int WarnMax,
- int CalibWarnMin, int CalibWarnMax, int max, int accuracy,
- std::shared_ptr <CCOS::Dev::IOEventCenter> EventCenter)
- :super(strkey, initialvalue, min, WarnMin, WarnMax, CalibWarnMin, CalibWarnMax, max, accuracy)
- {
- m_Key = strkey;
- m_EventCenter = EventCenter;
- m_CurrentValue = 0;
- }
- ~DeviceWifiMould() {}
- std::string GetDescription()
- {
- ResDataObject temp, result;
- temp.add(ValKey::UPPERLIMIT, m_LimitMax);
- temp.add(ValKey::LOWERLIMIT, m_LimitMin);
- temp.add(ValKey::WARNUPPERLIMIT, m_WarningMax);
- temp.add(ValKey::WARNLOWERLIMIT, m_WarningMin);
- temp.add(ValKey::ACCURACY, m_Accuracy);
- temp.add(ValKey::UNIT, m_Key.c_str());
- result.add(Key.c_str(), temp);
- return result.encode();
- }
- RET_STATUS JSGetCurrentSignalValue(std::string& out)
- {
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf(szFDinfo, "%d", m_CurrentValue);
- out = szFDinfo;
- return RET_STATUS::RET_SUCCEED;
- }
- bool SetSignalValue(int nValue, int & nStatus)
- {
- m_CurrentValue = nValue;
- if (m_WarningMin <= nValue)
- {
- nStatus = ECOM_WIFI_STAE_NORMAL;
- }
- else if (m_LimitMin <= nValue && nValue < m_WarningMin)
- {
- nStatus = ECOM_WIFI_STATE_LOW;
- }
- else if (nValue < m_LimitMin)
- {
- nStatus = ECOM_WIFI_STATE_TOO_LOW;
- }
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf(szFDinfo, "%d", nValue);
- m_EventCenter->OnNotify((int)ATTRACTION_SET, "Wifi_Strength_Value", szFDinfo);
- return true;
- };
- RET_STATUS JSGetSignalErrorMin(std::string& out)
- {
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf(szFDinfo, "%d", m_LimitMin);
- out = szFDinfo;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS SetSignalErrorMin(string nValue)
- {
- int temp = atoi(nValue.c_str());
- if (m_LimitMin == temp)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- m_LimitMin = temp;
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf(szFDinfo, "%d", m_LimitMin);
- m_EventCenter->OnNotify((int)ATTRACTION_SET, "WifiMiniLimit", szFDinfo);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS JSGetSignalWarningMin(std::string& out)
- {
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf(szFDinfo, "%d", m_WarningMin);
- out = szFDinfo;
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS SetSignalWarningMin(string nValue)
- {
- int temp = atoi(nValue.c_str());
- if (m_WarningMin == temp)
- {
- return RET_STATUS::RET_SUCCEED;
- }
- m_WarningMin = temp;
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf(szFDinfo, "%d", m_WarningMin);
- m_EventCenter->OnNotify((int)ATTRACTION_SET, "WifiLowerLimit", szFDinfo);
- return RET_STATUS::RET_SUCCEED;
- }
- RET_STATUS JSUpdateSignalWarningMin(string in, string& out)
- {
- out = in;
- return SetSignalWarningMin(in);
- }
- RET_STATUS JSUpdateSignalErrorMin(string in, string& out)
- {
- out = in;
- return SetSignalErrorMin(in);
- }
- };//DeviceWifiMould
- }
|