TCLCommand.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. void UpdateRtnCode()
  27. {
  28. if (!_tcsicmp(_T("AA"), head.c_str())) { // 调试用命令代码引导码;
  29. _rtnCode = 0xAB;
  30. }
  31. else if (!_tcsicmp(_T("AC"), head.c_str())) { // 软件配屏参数调整命令代码引导码;
  32. _rtnCode = 0xAD;
  33. }
  34. else if (!_tcsicmp(_T("AE"), head.c_str())) { // 保留命令发送类型引导码;
  35. _rtnCode = 0xAF;
  36. }
  37. }
  38. void Clean()
  39. {
  40. //_rtnCode = 0;
  41. _rtnStatus = 0;
  42. #if _MSC_VER >= 1200 && _MSC_VER < 1500
  43. _rtnData = "";
  44. _rtnError = "";
  45. #elif _MSC_VER >= 1500
  46. _rtnData.clear();
  47. _rtnError.clear();
  48. #endif
  49. }
  50. __CMDPARAM__() {
  51. _rtnCode = 0;
  52. _rtnStatus = 0;
  53. nOption = 0;
  54. bMulticode = false;
  55. cmd_wait_time = 100;
  56. read_wait_time = 100;
  57. }
  58. } CommandParam, * pCommandParam;
  59. class TCLCommand :public CBaseSerial
  60. {
  61. public:
  62. TCLCommand(bool bSync = true);
  63. ~TCLCommand(void);
  64. public:
  65. int pares_time_value(std::string strTime);
  66. bool parse_pair_key(std::string& RetValue, std::string strLine, TCHAR* lpszText);
  67. int parse_cmd_param_from_file(TCHAR* file_name, std::vector<CommandParam>& vtCommandParams);
  68. bool TheFirstPart(CommandParam& cmdPara, std::string data);
  69. bool TheSecondPart(CommandParam& cmdPara, std::string data);
  70. std::string PackingCommand(CommandParam& cmdPara, std::string data, const int& dataLen);
  71. void ParseResultString(CommandParam& cmdPara, std::string data, const int& dataLen);
  72. };