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.

71 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
  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. public:
  24. void setInt32Ack(int32_t ecode, int32_t val) {
  25. this->ecode = ecode;
  26. acktype = kAckType_int32;
  27. rawlen = sizeof(int32_t);
  28. *((int32_t *)rawdata) = val;
  29. }
  30. void setNoneAck(int32_t ecode) {
  31. this->ecode = ecode;
  32. acktype = kAckType_none;
  33. rawlen = 0;
  34. rawdata[0] = 0;
  35. }
  36. int32_t *getAck(int index) {
  37. if (index < 0 || index >= rawlen / (int)sizeof(int32_t)) {
  38. return nullptr;
  39. }
  40. return (int32_t *)rawdata + index;
  41. }
  42. int32_t getAckInt32Val(int index) {
  43. if (index < 0 || index >= rawlen / (int)sizeof(int32_t)) {
  44. return 0;
  45. }
  46. return *((int32_t *)rawdata + index);
  47. }
  48. int32_t getAckInt32Num() {
  49. if (rawlen != sizeof(int32_t)) {
  50. return 0;
  51. }
  52. return *((int32_t *)rawdata);
  53. }
  54. };
  55. typedef function<void(int32_t paramN, const char **paraV, ICmdParserACK *ack)> ICmdFunction_t;
  56. class ICmdParser {
  57. public:
  58. virtual void regCMD(const char *cmdname, const char *helpinfo, int paraNum, ICmdFunction_t cmdimpl) = 0;
  59. };
  60. } // namespace iflytop