#pragma once #include #include #include #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 class ValueDef : public BaseJsonDataObject { public: BaseJsonDataObject m_value;//实际值 BaseJsonDataObject m_UpThreshold;//上阀值 BaseJsonDataObject m_DownThreshold;//下阀值 BaseJsonDataObject 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::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 // { // public: // // BaseJsonDataObject DevID; // BaseJsonDataObject DevType; // BaseJsonDataObject UnitID; // BaseJsonDataObject 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 // { // public: // BaseJsonDataObject CodeID; // BaseJsonDataObject Level; // BaseJsonDataObject Resouceinfo; // BaseJsonDataObject 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()); // // }; //};