123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392 |
- #pragma once
- #include <string>
- #include <sstream>
- #include <map>
- #include "ResDataObject.h"
- using namespace std;
- #define SYSTEM_CALL
- #define OEM_IF
- #define DEVICE_ACTION
- #define DATA_ACTION DEVICE_ACTION
- #define HW_ACTION
- #define DEVICE_SUPPORT
- #define PARAM_IN
- #define PARAM_OUT
- #define TIMEOUT_REQ (10000)
- #define THREAD_PRIORITY_NONE (0xFFFF0000)
- //64M as max Buff
- #define SCF_MAX_LIMITED_BUFF_SIZE (1024*1024*32*2)
- /*
- 返回值的状态解释
- 简单解释的话,一条命令的目的是让设备从【状态A】 -> 【状态B】.
- 1.设备处于【状态A】.
- 2.发送命令给设备 -> 【设备进入PENDING状态】,PENDING期间,设备端不再接收命令,或没有反馈.
- 3.设备执行完命令且有反馈 -> 【设备执行命令SUCCEED】
- 4.再次发送相同命令给设备 -> 【设备进入PENDING状态】
- 5.设备执行完命令且有反馈 -> 【设备进入ONGOING状态】
- 6.设备自行从【状态A】切换到【状态B】 -> 【设备进入FINISHED状态】
- 一次状态变迁一般有如下流程.(PENDING状态是暂时的,所以大部分情况不予考虑,除非命令Send后TIMEOUT了)
- 【状态A】-----接收---------再次------无反馈-------处理-----执行完成-------开始变迁-----再次---------反馈---------------->【状态B】----再次------反馈
- ↑ ↑ ↓ ↓ ↑ ↓ ↓ ↑ ↓
- CMDA2B ------>CMDA2B----->PENDING ------------> SUCCEED ------------------>CMDA2B----->ONGOING ------------> FINISHED-->CMDA2B----->FINISHED.
- */
- typedef enum _Ret_Status {
- RET_THREAD_INVALID = -4,//the calling thread is not owner
- RET_INVALID = -3,//the handle is invalid
- RET_NOSUPPORT = -2,//device not support
- RET_TIMEOUT = -1,//超时(无接收命令)
- RET_FAILED = 0,//执行命令失败
- RET_PENDING,//设备有接收命令,但无反馈(在一定时间内无反馈情况)
- RET_SUCCEED,//设备执行命令成功
- RET_ONGOING,//设备执行命令已经完成,但是没有达成目标.
- RET_FINISHED,//设备执行命令已经完成,且有达成目标.
- RET_WARNING,
- RET_MAX
- }RET_STATUS;
- //namespace ECOM::Utility::String
- //{
- // template <> inline std::string ToString(const RET_STATUS& _val)
- // {
- // return std::to_string (_val);
- // }
- //}
- typedef enum _Dios_Proc_Type {
- //DIOS_PROC_SLAVE,//not used
- DIOS_PROC_MASTER = 1,//Driver proc
- DIOS_PROC_CHANNEL,//local channel proc
- //DIOS_PROC_CLIENT,//not used
- DIOS_PROC_MAX
- }DIOS_PROC_TYPE;
- template<typename T> class ValueDef : public BaseJsonDataObject<T>
- {
- public:
- BaseJsonDataObject<T> m_value;//实际值
- BaseJsonDataObject<T> m_UpThreshold;//上阀值
- BaseJsonDataObject<T> m_DownThreshold;//下阀值
- BaseJsonDataObject<T> m_Precision;//精度
- //度量单位保留缺省单位
- //距离:mm
- //温度:度
- //角度:度
- ValueDef(void)
- {
- }
- virtual ~ValueDef(void)
- {
- }
- virtual const char *GetVal()
- {
-
- ResDataObject obj;
- obj.add(m_value.GetKey(),m_value.GetVal());
- obj.add(m_UpThreshold.GetKey(),m_UpThreshold.GetVal());
- obj.add(m_DownThreshold.GetKey(),m_DownThreshold.GetVal());
- obj.add(m_Precision.GetKey(),m_Precision.GetVal());
- std::string strValString;
- strValString = obj.encode();
- return strValString.c_str();
- };
-
- virtual bool SetVal(const char* pValString)
- {
- ResDataObject obj;
- if(obj.decode(pValString))
- {
- int idx;
- idx = obj.GetFirstOf(m_value.GetKey());
- if(idx >= 0)
- {
- m_value.SetVal(obj[idx]);
- }
- idx = obj.GetFirstOf(m_UpThreshold.GetKey());
- if(idx >= 0)
- {
- m_UpThreshold.SetVal(obj[idx]);
- }
- idx = obj.GetFirstOf(m_DownThreshold.GetKey());
- if(idx >= 0)
- {
- m_DownThreshold.SetVal(obj[idx]);
- }
- idx = obj.GetFirstOf(m_Precision.GetKey());
- if(idx >= 0)
- {
- m_Precision.SetVal(obj[idx]);
- }
- return true;
- }
- return false;
- };
- virtual void SetKey(const char* pKeyString)
- {
- std::string temp = pKeyString;
- std::string keystring;
- BaseJsonDataObject<T>::SetKey(pKeyString);
- //make key
- keystring = temp + "_value";
- m_UpThreshold.SetKey(keystring.c_str());
- m_value.SetKey(pKeyString);
- //make UpThreshold
- keystring = temp + "_UpThreshold";
- m_UpThreshold.SetKey(keystring.c_str());
- //make DownThreshold
- keystring = temp + "_DownThreshold";
- m_DownThreshold.SetKey(keystring.c_str());
- //make Precision
- keystring = temp + "_Precision";
- m_Precision.SetKey(keystring.c_str());
- };
- };
- //class MessageAddress : public BaseJsonDataObject<int>
- // {
- // public:
- //
- // BaseJsonDataObject<int> DevID;
- // BaseJsonDataObject<string> DevType;
- // BaseJsonDataObject<int> UnitID;
- // BaseJsonDataObject<string> UnitType;
- // MessageAddress(void)
- // {
- // SetKey("MessageAddress");
- //
- // DevType.SetKey("DevType");
- // DevID.SetKey("DevID");
- // UnitType.SetKey("UnitType");
- // UnitID.SetKey("UnitID");
- // }
- // virtual ~MessageAddress(void)
- // {
- //
- // }
- // virtual bool SetResDataObject(ResDataObject &obj)
- // {
- // bool ret = true;
- // try {
- // DevType = (string)obj[DevType.GetKey()];
- // DevID = obj[DevID.GetKey()];
- // UnitType = (string)obj[UnitType.GetKey()];
- // UnitID = obj[UnitID.GetKey()];
- // }
- // catch (...)
- // {
- // ret = false;
- // }
- // return ret;
- // };
- // virtual void GetResDataObject(ResDataObject &obj)
- // {
- // obj.add(DevID.GetKey(), DevID);
- // obj.add(DevType.GetKey(), ((string)DevType).c_str());
- // obj.add(UnitType.GetKey(), ((string)UnitType).c_str());
- // obj.add(UnitID.GetKey(), UnitID);
- // };
- // virtual const char *GetVal()
- // {
- //
- // ResDataObject obj;
- // obj.add(DevID.GetKey(), DevID.GetVal());
- // obj.add(DevType.GetKey(), DevType.GetVal());
- // obj.add(UnitType.GetKey(), UnitType.GetVal());
- // obj.add(UnitID.GetKey(), UnitID.GetVal());
- // (m_ValString) = obj.encode();
- //
- // return m_ValString.c_str();
- // };
- //
- // virtual bool SetVal(const char* pValString)
- // {
- //
- // ResDataObject obj;
- // if (obj.decode(pValString))
- // {
- // int idx;
- // idx = obj.GetFirstOf(DevID.GetKey());
- // if (idx >= 0)
- // {
- // DevID.SetVal(obj[idx]);
- // }
- // idx = obj.GetFirstOf(DevType.GetKey());
- // if (idx >= 0)
- // {
- // DevType.SetVal(obj[idx]);
- // }
- // idx = obj.GetFirstOf(UnitType.GetKey());
- // if (idx >= 0)
- // {
- // UnitType.SetVal(obj[idx]);
- // }
- // idx = obj.GetFirstOf(UnitID.GetKey());
- // if (idx >= 0)
- // {
- // UnitID.SetVal(obj[idx]);
- // }
- // return true;
- // }
- // return false;
- // }
- //
- // };
- //class MessageInfo : public BaseJsonDataObject<int>
- // {
- // public:
- // BaseJsonDataObject<int> CodeID;
- // BaseJsonDataObject<int> Level;
- // BaseJsonDataObject<string> Resouceinfo;
- // BaseJsonDataObject<string> Description;
- // MessageInfo(void)
- // {
- // SetKey("MessageInfo");
- // CodeID.SetKey("CodeID");
- // Level.SetKey("Level");
- // Resouceinfo.SetKey("Resouceinfo");
- // Description.SetKey("Description");
- // }
- // virtual ~MessageInfo(void)
- // {
- //
- // }
- // virtual bool SetResDataObject(ResDataObject &obj)
- // {
- // bool ret = true;
- // try {
- // CodeID = obj[CodeID.GetKey()];
- // Level = obj[Level.GetKey()];
- // Resouceinfo = (string)obj[Resouceinfo.GetKey()];
- // Description = (string)obj[Description.GetKey()];
- // }
- // catch (...)
- // {
- // ret = false;
- // }
- // return ret;
- // };
- // virtual void GetResDataObject(ResDataObject &obj)
- // {
- // obj.add(CodeID.GetKey(), CodeID);
- // obj.add(Level.GetKey(), Level);
- // obj.add(Resouceinfo.GetKey(), ((string)Resouceinfo).c_str());
- // obj.add(Description.GetKey(), ((string)Description).c_str());
- //
- // };
- // virtual const char *GetVal()
- // {
- //
- // ResDataObject obj;
- // obj.add(CodeID.GetKey(), CodeID.GetVal());
- // obj.add(Level.GetKey(), Level.GetVal());
- // obj.add(Resouceinfo.GetKey(), Resouceinfo.GetVal());
- // obj.add(Description.GetKey(), Description.GetVal());
- //
- // (m_ValString) = obj.encode();
- //
- // return m_ValString.c_str();
- // };
- //
- // virtual bool SetVal(const char* pValString)
- // {
- //
- // ResDataObject obj;
- // if (obj.decode(pValString))
- // {
- // int idx;
- // idx = obj.GetFirstOf(CodeID.GetKey());
- // if (idx >= 0)
- // {
- // CodeID.SetVal(obj[idx]);
- // }
- // idx = obj.GetFirstOf(Level.GetKey());
- // if (idx >= 0)
- // {
- // Level.SetVal(obj[idx]);
- // }
- // idx = obj.GetFirstOf(Resouceinfo.GetKey());
- // if (idx >= 0)
- // {
- // Resouceinfo.SetVal(obj[idx]);
- // }
- // idx = obj.GetFirstOf(Description.GetKey());
- // if (idx >= 0)
- // {
- // Description.SetVal(obj[idx]);
- // }
- // return true;
- // }
- // return false;
- // }
- //
- // };
- //
- //struct Message
- //{
- // MessageAddress Address;
- // MessageInfo Info;
- // virtual void GetResDataObject(ResDataObject &obj)
- // {
- // obj.add(Address.DevID.GetKey(), Address.DevID);
- // obj.add(Address.DevType.GetKey(), ((string)Address.DevType).c_str());
- // obj.add(Address.UnitType.GetKey(), ((string)Address.UnitType).c_str());
- // obj.add(Address.UnitID.GetKey(), Address.UnitID);
- // obj.add(Info.CodeID.GetKey(), Info.CodeID);
- // obj.add(Info.Level.GetKey(), Info.Level);
- // obj.add(Info.Resouceinfo.GetKey(), ((string)Info.Resouceinfo).c_str());
- // obj.add(Info.Description.GetKey(), ((string)Info.Description).c_str());
- //
- // };
- //};
|