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.

75 lines
3.1 KiB

2 years ago
1 year 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 year ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include <stdint.h>
  3. #include <functional>
  4. #include "apibasic/basic.hpp"
  5. namespace iflytop {
  6. using namespace std;
  7. #define REG_SET(reg, ...) _module_set_reg(param_id, &reg, val, ##__VA_ARGS__)
  8. #define REG_GET(reg) _module_get_reg(param_id, reg, val)
  9. #define REG_SET_FLOAT(reg, precision, ...) _module_set_reg_float(param_id, &reg, val, precision, ##__VA_ARGS__)
  10. #define REG_GET_FLOAT(reg, precision) _module_get_reg_float(param_id, reg, val, precision)
  11. #define ACTION_NONE 0
  12. #define PROCESS_REG(param_id, readaction, writeacton) \
  13. case param_id: { \
  14. if (read) { \
  15. return readaction; \
  16. } else { \
  17. return writeacton; \
  18. } \
  19. } break;
  20. #define ENABLE_MODULE(name, type, version) \
  21. const char *module_name = #name; \
  22. int32_t module_version = version; \
  23. int32_t module_type = type;
  24. #define MODULE_COMMON_PROCESS_REG_CB() \
  25. PROCESS_REG(kreg_module_version, /* */ REG_GET(module_version), ACTION_NONE); \
  26. PROCESS_REG(kreg_module_type, /* */ REG_GET(module_type), ACTION_NONE); \
  27. PROCESS_REG(kreg_module_status, /* */ module_get_status(&val), ACTION_NONE); \
  28. PROCESS_REG(kreg_module_errorcode, /* */ REG_GET(creg.module_errorcode), ACTION_NONE);
  29. typedef struct {
  30. int32_t module_errorcode;
  31. int32_t module_errorbitflag0;
  32. } module_common_reg_t;
  33. class ZIModule {
  34. int32_t m_inited_flag = 0;
  35. protected:
  36. module_common_reg_t creg;
  37. public:
  38. virtual ~ZIModule() {}
  39. public:
  40. virtual int32_t getid();
  41. virtual int32_t module_ping();
  42. virtual int32_t module_get_error(int32_t *iserror);
  43. virtual int32_t module_clear_error();
  44. virtual int32_t module_set_reg(int32_t param_id, int32_t param_value);
  45. virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value);
  46. /***********************************************************************************************************************
  47. * ûʵ *
  48. ***********************************************************************************************************************/
  49. virtual int32_t getid(int32_t *id) = 0;
  50. virtual int32_t module_get_status(int32_t *status) = 0;
  51. virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t &val) = 0;
  52. protected:
  53. virtual int32_t _module_set_reg(int32_t regoff, int32_t *regval, int32_t val, int32_t min = INT32_MIN, int32_t max = INT32_MAX);
  54. virtual int32_t _module_get_reg(int32_t regoff, int32_t regval, int32_t &val);
  55. virtual int32_t _module_set_reg_float(int32_t regoff, float *regval, int32_t val, float precision, int32_t min = INT32_MIN, int32_t max = INT32_MAX);
  56. virtual int32_t _module_get_reg_float(int32_t regoff, float regval, int32_t &val, float precision);
  57. public:
  58. public:
  59. };
  60. } // namespace iflytop