TCLCommand.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #include "serial.h"
  3. enum CMDOPT
  4. {
  5. CMDOPT_None = 0,
  6. CMDOPT_Get = 1,
  7. CMDOPT_Set = 2
  8. };
  9. typedef struct __CMDPARAM__ {
  10. std::string name; // 命令描述;
  11. std::string head; // 命令头;
  12. std::string code; // 命令码;
  13. std::string param; // 命令码参数;
  14. // 命令属性类型:
  15. // 0=None,只返回一段数据包;
  16. // 1=Get,返回一段或两段数据包(成功时返回2段,失败时返回1段);
  17. // 2=Set,返回一段或两段数据包(成功时返回1段,失败时返回1段);
  18. int nOption;
  19. bool bMulticode; // 命令码是否多参数;
  20. int cmd_wait_time; // 两条串口指令间隔时间;
  21. int read_wait_time; // 写完串口后,等待多久读;
  22. byte _rtnCode;
  23. byte _rtnStatus;
  24. std::string _rtnData;
  25. std::string _rtnError;
  26. std::string _rtnContext;
  27. std::string _cmdContext;
  28. void UpdateRtnCode()
  29. {
  30. if (!_tcsicmp(_T("AA"), head.c_str())) { // 调试用命令代码引导码;
  31. _rtnCode = 0xAB;
  32. }
  33. else if (!_tcsicmp(_T("AC"), head.c_str())) { // 软件配屏参数调整命令代码引导码;
  34. _rtnCode = 0xAD;
  35. }
  36. else if (!_tcsicmp(_T("AE"), head.c_str())) { // 保留命令发送类型引导码;
  37. _rtnCode = 0xAF;
  38. }
  39. }
  40. void Clean()
  41. {
  42. //_rtnCode = 0;
  43. _rtnStatus = 0;
  44. #if _MSC_VER >= 1200 && _MSC_VER < 1500
  45. _rtnData = "";
  46. _rtnError = "";
  47. #elif _MSC_VER >= 1500
  48. _rtnData.clear();
  49. _rtnError.clear();
  50. #endif
  51. }
  52. __CMDPARAM__() {
  53. _rtnCode = 0;
  54. _rtnStatus = 0;
  55. nOption = 0;
  56. bMulticode = false;
  57. cmd_wait_time = 100;
  58. read_wait_time = 100;
  59. }
  60. } CommandParam, * pCommandParam;
  61. class TCLCommand :public CBaseSerial
  62. {
  63. // 内部-低优先查找;
  64. std::vector<CommandParam> m_vtInternalCMDParams;
  65. // 外部-高优先查找;
  66. std::vector<CommandParam> m_vtExternalCMDParams;
  67. public:
  68. TCLCommand(bool bSync = true);
  69. ~TCLCommand(void);
  70. public:
  71. int pares_time_value(std::string strTime);
  72. bool parse_pair_key(std::string& RetValue, std::string strLine, TCHAR* lpszText);
  73. int parse_cmd_param_from_file(TCHAR* file_name, std::vector<CommandParam>& vtCommandParams);
  74. int parse_cmd_from_string(std::string str, std::vector<CommandParam>& vtCommandParams);
  75. bool TheFirstPart(CommandParam& cmdPara, std::string data);
  76. bool TheSecondPart(CommandParam& cmdPara, std::string data);
  77. std::string PackingCommand(CommandParam& cmdPara, std::string data, const int& dataLen);
  78. void ParseResultString(CommandParam& cmdPara, std::string data, const int& dataLen);
  79. public:
  80. };