TemperatureMould.hpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 DeviceTemperatureMould
  9. class DeviceTemperatureMould : public FloatMouldWithWarn
  10. {
  11. typedef enum ECOM_Templerature_state
  12. {
  13. ECOM_TEM_STATE_TOO_LOW = 0,
  14. ECOM_TEM_STATE_LOW,
  15. ECOM_TEM_STAE_NORMAL,
  16. ECOM_TEM_STATE_HIGH,
  17. ECOM_TEM_STATE_TOO_HIGH
  18. }ECOM_TEMPERATURE_STATE;
  19. float 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 = FloatMouldWithWarn;
  25. DeviceTemperatureMould(const char* strkey, float initialvalue, float min, float WarnMin, float WarnMax, float max, float 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.0f;
  31. }
  32. ~DeviceTemperatureMould() {}
  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 JSGetCurrentTemperatureValue(std::string & out)
  46. {
  47. char szFDinfo[MAX_STRING] = { 0 };
  48. sprintf_s(szFDinfo, "%f", m_CurrentValue);
  49. out = szFDinfo;
  50. return RET_STATUS::RET_SUCCEED;
  51. }
  52. bool SetTemperature(float nValue, int & nState)
  53. {
  54. if (nValue != m_CurrentValue)
  55. {
  56. m_CurrentValue = nValue;
  57. if (m_CurrentValue > m_LimitMax)
  58. {
  59. nState = ECOM_TEM_STATE_TOO_HIGH;
  60. }
  61. else if (m_CurrentValue <= m_LimitMax && m_CurrentValue > m_WarningMax)
  62. {
  63. nState = ECOM_TEM_STATE_HIGH;
  64. }
  65. else if (m_CurrentValue <= m_WarningMax && m_CurrentValue >= m_WarningMin)
  66. {
  67. nState = ECOM_TEM_STAE_NORMAL;
  68. }
  69. else if (m_CurrentValue < m_WarningMin && m_CurrentValue >= m_LimitMin)
  70. {
  71. nState = ECOM_TEM_STATE_LOW;
  72. }
  73. else if (m_CurrentValue < m_LimitMin)
  74. {
  75. nState = ECOM_TEM_STATE_TOO_LOW;
  76. }
  77. char szFDinfo[MAX_STRING] = { 0 };
  78. sprintf_s(szFDinfo, "%f", nValue);
  79. //std::string str = szFDinfo;
  80. m_EventCenter->OnNotify((int)ATTRACTION_SET,"Temperature_Value", szFDinfo);
  81. }
  82. return true;
  83. };
  84. };
  85. #pragma endregion DeviceTemperatureMould
  86. }