123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- #pragma once
- #include "serial.h"
- enum CMDOPT
- {
- CMDOPT_None = 0,
- CMDOPT_Get = 1,
- CMDOPT_Set = 2
- };
- typedef struct __CMDPARAM__ {
- std::string name; // 命令描述;
- std::string head; // 命令头;
- std::string code; // 命令码;
- std::string param; // 命令码参数;
- // 命令属性类型:
- // 0=None,只返回一段数据包;
- // 1=Get,返回一段或两段数据包(成功时返回2段,失败时返回1段);
- // 2=Set,返回一段或两段数据包(成功时返回1段,失败时返回1段);
- int nOption;
- bool bMulticode; // 命令码是否多参数;
- int cmd_wait_time; // 两条串口指令间隔时间;
- int read_wait_time; // 写完串口后,等待多久读;
- byte _rtnCode;
- byte _rtnStatus;
- std::string _rtnData;
- std::string _rtnError;
- std::string _rtnContext;
- std::string _cmdContext;
- void UpdateRtnCode()
- {
- if (!_tcsicmp(_T("AA"), head.c_str())) { // 调试用命令代码引导码;
- _rtnCode = 0xAB;
- }
- else if (!_tcsicmp(_T("AC"), head.c_str())) { // 软件配屏参数调整命令代码引导码;
- _rtnCode = 0xAD;
- }
- else if (!_tcsicmp(_T("AE"), head.c_str())) { // 保留命令发送类型引导码;
- _rtnCode = 0xAF;
- }
- }
- __CMDPARAM__& operator=(const __CMDPARAM__& cls)
- {
- if (this != &cls)
- {
- name = cls.name;
- head = cls.head;
- code = cls.code;
- param = cls.param;
- nOption = cls.nOption;
- bMulticode = cls.bMulticode;
- cmd_wait_time = cls.cmd_wait_time;
- read_wait_time = cls.read_wait_time;
- _rtnCode = cls._rtnCode;
- _rtnStatus = cls._rtnStatus;
- _rtnData = cls._rtnData;
- _rtnError = cls._rtnError;
- _rtnContext = cls._rtnContext;
- _cmdContext = cls._cmdContext;
- }
-
- return *this;
- }
- void Clean()
- {
- //_rtnCode = 0;
- _rtnStatus = 0;
- #if _MSC_VER >= 1200 && _MSC_VER < 1500
- _rtnData = "";
- _rtnError = "";
- _rtnContext = "";
- _cmdContext = "";
- #elif _MSC_VER >= 1500
- _rtnData.clear();
- _rtnError.clear();
- _rtnContext.clear();
- _cmdContext.clear();
- #endif
- }
- __CMDPARAM__() {
- _rtnCode = 0;
- _rtnStatus = 0;
- nOption = 0;
- bMulticode = false;
- cmd_wait_time = 100;
- read_wait_time = 100;
- }
- } CommandParam, * pCommandParam;
- class TCLCommand :public CBaseSerial
- {
- // 内部-低优先查找;
- std::vector<CommandParam> m_vtInternalCMDParams;
- // 外部-高优先查找;
- std::vector<CommandParam> m_vtExternalCMDParams;
- public:
- TCLCommand(bool bSync = true);
- ~TCLCommand(void);
- public:
- int pares_time_value(std::string strTime);
- bool parse_pair_key(std::string& RetValue, std::string strLine, TCHAR* lpszText);
- int parse_cmds_from_file(TCHAR* file_name, std::vector<CommandParam>& vtCommandParams);
- void parse_cmds_from_string(std::string str, std::vector<CommandParam>& vtCommandParams);
- bool GetCommandParams(std::string name, CommandParam& cmdPara);
- bool TheFirstPart(CommandParam& cmdPara, std::string data);
- bool TheSecondPart(CommandParam& cmdPara, std::string data);
- std::string PackingCommand(CommandParam& cmdPara, std::string data, const int& dataLen);
- void ParseResultString(CommandParam& cmdPara, std::string data, const int& dataLen);
- public:
- };
|