123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #pragma once
- #include <memory>
- #include "ResDataObject.h"
- #include "DIOS.Dev.IODevice.hpp"
- #include "DIOS.Dev.MouldDefine.hpp"
- namespace DIOS::Dev::Detail
- {
- #pragma region DeviceTemperatureMould
- class DeviceTemperatureMould : public FloatMouldWithWarn
- {
- typedef enum ECOM_Templerature_state
- {
- ECOM_TEM_STATE_TOO_LOW = 0,
- ECOM_TEM_STATE_LOW,
- ECOM_TEM_STAE_NORMAL,
- ECOM_TEM_STATE_HIGH,
- ECOM_TEM_STATE_TOO_HIGH
- }ECOM_TEMPERATURE_STATE;
- float m_CurrentValue;
- //ResDataObject m_Cache;
- std::shared_ptr <DIOS::Dev::IOEventCenter> m_EventCenter;
- std::string m_Key;
- public:
- using super = FloatMouldWithWarn;
- DeviceTemperatureMould(const char* strkey, float initialvalue, float min, float WarnMin, float WarnMax, float max, float accuracy, std::shared_ptr <DIOS::Dev::IOEventCenter> EventCenter)
- : super(strkey, initialvalue, min, WarnMin, WarnMax, max, accuracy)
- {
- m_Key = strkey;
- m_EventCenter = EventCenter;
- m_CurrentValue = 0.0f;
- }
- ~DeviceTemperatureMould() {}
- 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 JSGetCurrentTemperatureValue(std::string & out)
- {
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf_s(szFDinfo, "%f", m_CurrentValue);
- out = szFDinfo;
- return RET_STATUS::RET_SUCCEED;
- }
- bool SetTemperature(float nValue, int & nState)
- {
- if (nValue != m_CurrentValue)
- {
- m_CurrentValue = nValue;
- if (m_CurrentValue > m_LimitMax)
- {
- nState = ECOM_TEM_STATE_TOO_HIGH;
- }
- else if (m_CurrentValue <= m_LimitMax && m_CurrentValue > m_WarningMax)
- {
- nState = ECOM_TEM_STATE_HIGH;
- }
- else if (m_CurrentValue <= m_WarningMax && m_CurrentValue >= m_WarningMin)
- {
- nState = ECOM_TEM_STAE_NORMAL;
- }
- else if (m_CurrentValue < m_WarningMin && m_CurrentValue >= m_LimitMin)
- {
- nState = ECOM_TEM_STATE_LOW;
- }
- else if (m_CurrentValue < m_LimitMin)
- {
- nState = ECOM_TEM_STATE_TOO_LOW;
- }
- char szFDinfo[MAX_STRING] = { 0 };
- sprintf_s(szFDinfo, "%f", nValue);
- //std::string str = szFDinfo;
- m_EventCenter->OnNotify((int)ATTRACTION_SET,"Temperature_Value", szFDinfo);
- }
- return true;
- };
- };
- #pragma endregion DeviceTemperatureMould
-
- }
|