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.

68 lines
1.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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. //
  2. // Created by zwsd
  3. //
  4. #pragma once
  5. #include <functional>
  6. #include "config_index.hpp"
  7. #include "errorcode.hpp"
  8. #include "packet_interface.hpp"
  9. #include "protocol_constant.hpp"
  10. namespace iflytop {
  11. using namespace zcr;
  12. class ICmdParserACK {
  13. public:
  14. typedef enum {
  15. kAckType_none,
  16. kAckType_int32,
  17. kAckType_buf,
  18. kAckType_str,
  19. } ICmdParserACKType_t;
  20. public:
  21. int32_t ecode;
  22. ICmdParserACKType_t acktype;
  23. uint8_t rawdata[ZCANCMD_READ_BUF_MAX_SIZE + 100];
  24. int32_t rawlen;
  25. public:
  26. void setInt32Ack(int32_t ecode, int32_t val) {
  27. this->ecode = ecode;
  28. acktype = kAckType_int32;
  29. rawlen = sizeof(int32_t);
  30. *((int32_t *)rawdata) = val;
  31. }
  32. void setNoneAck(int32_t ecode) {
  33. this->ecode = ecode;
  34. acktype = kAckType_none;
  35. rawlen = 0;
  36. rawdata[0] = 0;
  37. }
  38. int32_t *getAck(int index) {
  39. if (index < 0 || index >= (int32_t)(sizeof(rawdata) / 4)) {
  40. return nullptr;
  41. }
  42. return (int32_t *)rawdata + index;
  43. }
  44. int32_t getAckInt32Val(int index) {
  45. if (index < 0 || index >= rawlen / (int)sizeof(int32_t)) {
  46. return 0;
  47. }
  48. return *((int32_t *)rawdata + index);
  49. }
  50. int32_t getAckInt32Num() { return rawlen / (int)sizeof(int32_t); }
  51. };
  52. typedef function<void(int32_t paramN, const char **paraV, ICmdParserACK *ack)> ICmdFunction_t;
  53. class ICmdParser {
  54. public:
  55. virtual void regCMD(const char *cmdname, const char *helpinfo, int paraNum, ICmdFunction_t cmdimpl) = 0;
  56. };
  57. } // namespace iflytop