You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
926 B

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include <map>
  3. #include <string>
  4. #include "sdk/os/zos.hpp"
  5. #include "sdk\components\zprotocols\errorcode\errorcode.hpp"
  6. namespace iflytop {
  7. using namespace std;
  8. class CmdScheduler {
  9. public:
  10. class CmdProcessContext {
  11. public:
  12. bool breakflag = false;
  13. };
  14. typedef function<void(int, char**, CmdProcessContext*)> call_cmd_t;
  15. private:
  16. map<string, call_cmd_t> m_cmdMap;
  17. ZUART* m_uart;
  18. char* rxbuf;
  19. int32_t m_rxsize = 0;
  20. uint32_t m_rxbufsize;
  21. bool m_dataisready = false;
  22. char cmdcache[1024] = {0};
  23. public:
  24. void initialize(UART_HandleTypeDef* huart, uint32_t rxbufsize);
  25. void registerCmd(std::string cmd, call_cmd_t call_cmd);
  26. void tx(const char* data, int len);
  27. void schedule();
  28. private:
  29. void regbasiccmd();
  30. void callcmd(const char* cmd, CmdProcessContext& context);
  31. void prase_cmd(char* input, int inputlen, int& argc, char* argv[]);
  32. };
  33. } // namespace iflytop