Definitions.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. #pragma once
  2. #include <string>
  3. #include <sstream>
  4. #include <map>
  5. #include "ResDataObject.h"
  6. using namespace std;
  7. #define SYSTEM_CALL
  8. #define OEM_IF
  9. #define DEVICE_ACTION
  10. #define DATA_ACTION DEVICE_ACTION
  11. #define HW_ACTION
  12. #define DEVICE_SUPPORT
  13. #define PARAM_IN
  14. #define PARAM_OUT
  15. #define TIMEOUT_REQ (10000)
  16. #define THREAD_PRIORITY_NONE (0xFFFF0000)
  17. //64M as max Buff
  18. #define SCF_MAX_LIMITED_BUFF_SIZE (1024*1024*32*2)
  19. /*
  20. 返回值的状态解释
  21. 简单解释的话,一条命令的目的是让设备从【状态A】 -> 【状态B】.
  22. 1.设备处于【状态A】.
  23. 2.发送命令给设备 -> 【设备进入PENDING状态】,PENDING期间,设备端不再接收命令,或没有反馈.
  24. 3.设备执行完命令且有反馈 -> 【设备执行命令SUCCEED】
  25. 4.再次发送相同命令给设备 -> 【设备进入PENDING状态】
  26. 5.设备执行完命令且有反馈 -> 【设备进入ONGOING状态】
  27. 6.设备自行从【状态A】切换到【状态B】 -> 【设备进入FINISHED状态】
  28. 一次状态变迁一般有如下流程.(PENDING状态是暂时的,所以大部分情况不予考虑,除非命令Send后TIMEOUT了)
  29. 【状态A】-----接收---------再次------无反馈-------处理-----执行完成-------开始变迁-----再次---------反馈---------------->【状态B】----再次------反馈
  30. ↑ ↑ ↓ ↓ ↑ ↓ ↓ ↑ ↓
  31. CMDA2B ------>CMDA2B----->PENDING ------------> SUCCEED ------------------>CMDA2B----->ONGOING ------------> FINISHED-->CMDA2B----->FINISHED.
  32. */
  33. typedef enum _Ret_Status {
  34. RET_THREAD_INVALID = -4,//the calling thread is not owner
  35. RET_INVALID = -3,//the handle is invalid
  36. RET_NOSUPPORT = -2,//device not support
  37. RET_TIMEOUT = -1,//超时(无接收命令)
  38. RET_FAILED = 0,//执行命令失败
  39. RET_PENDING,//设备有接收命令,但无反馈(在一定时间内无反馈情况)
  40. RET_SUCCEED,//设备执行命令成功
  41. RET_ONGOING,//设备执行命令已经完成,但是没有达成目标.
  42. RET_FINISHED,//设备执行命令已经完成,且有达成目标.
  43. RET_WARNING,
  44. RET_MAX
  45. }RET_STATUS;
  46. //namespace ECOM::Utility::String
  47. //{
  48. // template <> inline std::string ToString(const RET_STATUS& _val)
  49. // {
  50. // return std::to_string (_val);
  51. // }
  52. //}
  53. typedef enum _Dios_Proc_Type {
  54. //DIOS_PROC_SLAVE,//not used
  55. DIOS_PROC_MASTER = 1,//Driver proc
  56. DIOS_PROC_CHANNEL,//local channel proc
  57. //DIOS_PROC_CLIENT,//not used
  58. DIOS_PROC_MAX
  59. }DIOS_PROC_TYPE;
  60. template<typename T> class ValueDef : public BaseJsonDataObject<T>
  61. {
  62. public:
  63. BaseJsonDataObject<T> m_value;//实际值
  64. BaseJsonDataObject<T> m_UpThreshold;//上阀值
  65. BaseJsonDataObject<T> m_DownThreshold;//下阀值
  66. BaseJsonDataObject<T> m_Precision;//精度
  67. //度量单位保留缺省单位
  68. //距离:mm
  69. //温度:度
  70. //角度:度
  71. ValueDef(void)
  72. {
  73. }
  74. virtual ~ValueDef(void)
  75. {
  76. }
  77. virtual const char *GetVal()
  78. {
  79. ResDataObject obj;
  80. obj.add(m_value.GetKey(),m_value.GetVal());
  81. obj.add(m_UpThreshold.GetKey(),m_UpThreshold.GetVal());
  82. obj.add(m_DownThreshold.GetKey(),m_DownThreshold.GetVal());
  83. obj.add(m_Precision.GetKey(),m_Precision.GetVal());
  84. std::string strValString;
  85. strValString = obj.encode();
  86. return strValString.c_str();
  87. };
  88. virtual bool SetVal(const char* pValString)
  89. {
  90. ResDataObject obj;
  91. if(obj.decode(pValString))
  92. {
  93. int idx;
  94. idx = obj.GetFirstOf(m_value.GetKey());
  95. if(idx >= 0)
  96. {
  97. m_value.SetVal(obj[idx]);
  98. }
  99. idx = obj.GetFirstOf(m_UpThreshold.GetKey());
  100. if(idx >= 0)
  101. {
  102. m_UpThreshold.SetVal(obj[idx]);
  103. }
  104. idx = obj.GetFirstOf(m_DownThreshold.GetKey());
  105. if(idx >= 0)
  106. {
  107. m_DownThreshold.SetVal(obj[idx]);
  108. }
  109. idx = obj.GetFirstOf(m_Precision.GetKey());
  110. if(idx >= 0)
  111. {
  112. m_Precision.SetVal(obj[idx]);
  113. }
  114. return true;
  115. }
  116. return false;
  117. };
  118. virtual void SetKey(const char* pKeyString)
  119. {
  120. std::string temp = pKeyString;
  121. std::string keystring;
  122. BaseJsonDataObject<T>::SetKey(pKeyString);
  123. //make key
  124. keystring = temp + "_value";
  125. m_UpThreshold.SetKey(keystring.c_str());
  126. m_value.SetKey(pKeyString);
  127. //make UpThreshold
  128. keystring = temp + "_UpThreshold";
  129. m_UpThreshold.SetKey(keystring.c_str());
  130. //make DownThreshold
  131. keystring = temp + "_DownThreshold";
  132. m_DownThreshold.SetKey(keystring.c_str());
  133. //make Precision
  134. keystring = temp + "_Precision";
  135. m_Precision.SetKey(keystring.c_str());
  136. };
  137. };
  138. //class MessageAddress : public BaseJsonDataObject<int>
  139. // {
  140. // public:
  141. //
  142. // BaseJsonDataObject<int> DevID;
  143. // BaseJsonDataObject<string> DevType;
  144. // BaseJsonDataObject<int> UnitID;
  145. // BaseJsonDataObject<string> UnitType;
  146. // MessageAddress(void)
  147. // {
  148. // SetKey("MessageAddress");
  149. //
  150. // DevType.SetKey("DevType");
  151. // DevID.SetKey("DevID");
  152. // UnitType.SetKey("UnitType");
  153. // UnitID.SetKey("UnitID");
  154. // }
  155. // virtual ~MessageAddress(void)
  156. // {
  157. //
  158. // }
  159. // virtual bool SetResDataObject(ResDataObject &obj)
  160. // {
  161. // bool ret = true;
  162. // try {
  163. // DevType = (string)obj[DevType.GetKey()];
  164. // DevID = obj[DevID.GetKey()];
  165. // UnitType = (string)obj[UnitType.GetKey()];
  166. // UnitID = obj[UnitID.GetKey()];
  167. // }
  168. // catch (...)
  169. // {
  170. // ret = false;
  171. // }
  172. // return ret;
  173. // };
  174. // virtual void GetResDataObject(ResDataObject &obj)
  175. // {
  176. // obj.add(DevID.GetKey(), DevID);
  177. // obj.add(DevType.GetKey(), ((string)DevType).c_str());
  178. // obj.add(UnitType.GetKey(), ((string)UnitType).c_str());
  179. // obj.add(UnitID.GetKey(), UnitID);
  180. // };
  181. // virtual const char *GetVal()
  182. // {
  183. //
  184. // ResDataObject obj;
  185. // obj.add(DevID.GetKey(), DevID.GetVal());
  186. // obj.add(DevType.GetKey(), DevType.GetVal());
  187. // obj.add(UnitType.GetKey(), UnitType.GetVal());
  188. // obj.add(UnitID.GetKey(), UnitID.GetVal());
  189. // (m_ValString) = obj.encode();
  190. //
  191. // return m_ValString.c_str();
  192. // };
  193. //
  194. // virtual bool SetVal(const char* pValString)
  195. // {
  196. //
  197. // ResDataObject obj;
  198. // if (obj.decode(pValString))
  199. // {
  200. // int idx;
  201. // idx = obj.GetFirstOf(DevID.GetKey());
  202. // if (idx >= 0)
  203. // {
  204. // DevID.SetVal(obj[idx]);
  205. // }
  206. // idx = obj.GetFirstOf(DevType.GetKey());
  207. // if (idx >= 0)
  208. // {
  209. // DevType.SetVal(obj[idx]);
  210. // }
  211. // idx = obj.GetFirstOf(UnitType.GetKey());
  212. // if (idx >= 0)
  213. // {
  214. // UnitType.SetVal(obj[idx]);
  215. // }
  216. // idx = obj.GetFirstOf(UnitID.GetKey());
  217. // if (idx >= 0)
  218. // {
  219. // UnitID.SetVal(obj[idx]);
  220. // }
  221. // return true;
  222. // }
  223. // return false;
  224. // }
  225. //
  226. // };
  227. //class MessageInfo : public BaseJsonDataObject<int>
  228. // {
  229. // public:
  230. // BaseJsonDataObject<int> CodeID;
  231. // BaseJsonDataObject<int> Level;
  232. // BaseJsonDataObject<string> Resouceinfo;
  233. // BaseJsonDataObject<string> Description;
  234. // MessageInfo(void)
  235. // {
  236. // SetKey("MessageInfo");
  237. // CodeID.SetKey("CodeID");
  238. // Level.SetKey("Level");
  239. // Resouceinfo.SetKey("Resouceinfo");
  240. // Description.SetKey("Description");
  241. // }
  242. // virtual ~MessageInfo(void)
  243. // {
  244. //
  245. // }
  246. // virtual bool SetResDataObject(ResDataObject &obj)
  247. // {
  248. // bool ret = true;
  249. // try {
  250. // CodeID = obj[CodeID.GetKey()];
  251. // Level = obj[Level.GetKey()];
  252. // Resouceinfo = (string)obj[Resouceinfo.GetKey()];
  253. // Description = (string)obj[Description.GetKey()];
  254. // }
  255. // catch (...)
  256. // {
  257. // ret = false;
  258. // }
  259. // return ret;
  260. // };
  261. // virtual void GetResDataObject(ResDataObject &obj)
  262. // {
  263. // obj.add(CodeID.GetKey(), CodeID);
  264. // obj.add(Level.GetKey(), Level);
  265. // obj.add(Resouceinfo.GetKey(), ((string)Resouceinfo).c_str());
  266. // obj.add(Description.GetKey(), ((string)Description).c_str());
  267. //
  268. // };
  269. // virtual const char *GetVal()
  270. // {
  271. //
  272. // ResDataObject obj;
  273. // obj.add(CodeID.GetKey(), CodeID.GetVal());
  274. // obj.add(Level.GetKey(), Level.GetVal());
  275. // obj.add(Resouceinfo.GetKey(), Resouceinfo.GetVal());
  276. // obj.add(Description.GetKey(), Description.GetVal());
  277. //
  278. // (m_ValString) = obj.encode();
  279. //
  280. // return m_ValString.c_str();
  281. // };
  282. //
  283. // virtual bool SetVal(const char* pValString)
  284. // {
  285. //
  286. // ResDataObject obj;
  287. // if (obj.decode(pValString))
  288. // {
  289. // int idx;
  290. // idx = obj.GetFirstOf(CodeID.GetKey());
  291. // if (idx >= 0)
  292. // {
  293. // CodeID.SetVal(obj[idx]);
  294. // }
  295. // idx = obj.GetFirstOf(Level.GetKey());
  296. // if (idx >= 0)
  297. // {
  298. // Level.SetVal(obj[idx]);
  299. // }
  300. // idx = obj.GetFirstOf(Resouceinfo.GetKey());
  301. // if (idx >= 0)
  302. // {
  303. // Resouceinfo.SetVal(obj[idx]);
  304. // }
  305. // idx = obj.GetFirstOf(Description.GetKey());
  306. // if (idx >= 0)
  307. // {
  308. // Description.SetVal(obj[idx]);
  309. // }
  310. // return true;
  311. // }
  312. // return false;
  313. // }
  314. //
  315. // };
  316. //
  317. //struct Message
  318. //{
  319. // MessageAddress Address;
  320. // MessageInfo Info;
  321. // virtual void GetResDataObject(ResDataObject &obj)
  322. // {
  323. // obj.add(Address.DevID.GetKey(), Address.DevID);
  324. // obj.add(Address.DevType.GetKey(), ((string)Address.DevType).c_str());
  325. // obj.add(Address.UnitType.GetKey(), ((string)Address.UnitType).c_str());
  326. // obj.add(Address.UnitID.GetKey(), Address.UnitID);
  327. // obj.add(Info.CodeID.GetKey(), Info.CodeID);
  328. // obj.add(Info.Level.GetKey(), Info.Level);
  329. // obj.add(Info.Resouceinfo.GetKey(), ((string)Info.Resouceinfo).c_str());
  330. // obj.add(Info.Description.GetKey(), ((string)Info.Description).c_str());
  331. //
  332. // };
  333. //};