zcancmder_v2
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.

56 lines
1.1 KiB

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. namespace iflytop {
  10. using namespace zcr;
  11. class ICmdParserACK {
  12. public:
  13. typedef enum {
  14. kAckType_none,
  15. kAckType_int32,
  16. kAckType_buf,
  17. } ICmdParserACKType_t;
  18. public:
  19. int32_t ecode;
  20. ICmdParserACKType_t acktype;
  21. uint8_t rawdata[512];
  22. int32_t rawlen;
  23. int32_t *getAck(int index) {
  24. if (index < 0 || index >= rawlen / sizeof(int32_t)) {
  25. return nullptr;
  26. }
  27. return (int32_t *)rawdata + index;
  28. }
  29. int32_t getAckInt32Val(int index) {
  30. if (index < 0 || index >= rawlen / sizeof(int32_t)) {
  31. return 0;
  32. }
  33. return *((int32_t *)rawdata + index);
  34. }
  35. int32_t getAckInt32Num() {
  36. if (rawlen != sizeof(int32_t)) {
  37. return 0;
  38. }
  39. return *((int32_t *)rawdata);
  40. }
  41. };
  42. typedef function<void(int32_t paramN, const char **paraV, ICmdParserACK *ack)> ICmdFunction_t;
  43. class ICmdParser {
  44. public:
  45. virtual void regCMD(const char *cmdname, const char *helpinfo, int paraNum, ICmdFunction_t cmdimpl) = 0;
  46. };
  47. } // namespace iflytop