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.

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