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.
88 lines
3.4 KiB
88 lines
3.4 KiB
#pragma once
|
|
#include <stdint.h>
|
|
|
|
#include <functional>
|
|
|
|
#include "apibasic/basic.hpp"
|
|
|
|
namespace iflytop {
|
|
using namespace std;
|
|
|
|
#define REG_SET(reg, ...) _module_set_reg(param_id, ®, val, ##__VA_ARGS__)
|
|
#define REG_GET(reg) _module_get_reg(param_id, reg, val)
|
|
|
|
#define REG_SET_FLOAT(reg, precision, ...) _module_set_reg_float(param_id, ®, val, precision, ##__VA_ARGS__)
|
|
#define REG_GET_FLOAT(reg, precision) _module_get_reg_float(param_id, reg, val, precision)
|
|
|
|
#define ACTION_NONE 0
|
|
#define PROCESS_REG(param_id, readaction, writeacton) \
|
|
case param_id: { \
|
|
if (read) { \
|
|
return readaction; \
|
|
} else { \
|
|
return writeacton; \
|
|
} \
|
|
} break;
|
|
|
|
#define ENABLE_MODULE(name, type, version) \
|
|
public: \
|
|
virtual int32_t module_get_version(int32_t *val) { \
|
|
*val = version; \
|
|
return 0; \
|
|
} \
|
|
virtual int32_t module_get_type(int32_t *val) { \
|
|
*val = type; \
|
|
return 0; \
|
|
}
|
|
|
|
#define MODULE_COMMON_PROCESS_REG_CB()
|
|
|
|
typedef struct {
|
|
int32_t module_errorcode;
|
|
int32_t module_status;
|
|
} module_common_reg_t;
|
|
|
|
class ZIModule {
|
|
int32_t m_inited_flag = 0;
|
|
|
|
protected:
|
|
module_common_reg_t creg;
|
|
|
|
public:
|
|
virtual ~ZIModule() {}
|
|
|
|
public:
|
|
virtual int32_t getid();
|
|
virtual int32_t module_ping();
|
|
virtual int32_t module_get_error(int32_t *iserror);
|
|
virtual int32_t module_clear_error();
|
|
virtual int32_t module_set_reg(int32_t param_id, int32_t param_value);
|
|
virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value);
|
|
virtual int32_t module_get_status(int32_t *status);
|
|
virtual int32_t module_get_version(int32_t *val) = 0;
|
|
virtual int32_t module_get_type(int32_t *val) = 0;
|
|
virtual int32_t module_stop() { return 0; }
|
|
virtual int32_t module_active_cfg() { return 0; }
|
|
|
|
/***********************************************************************************************************************
|
|
* 用户实现 *
|
|
***********************************************************************************************************************/
|
|
virtual int32_t getid(int32_t *id) = 0;
|
|
virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t &val) = 0;
|
|
|
|
public:
|
|
// slice
|
|
virtual int32_t bfcall(int32_t cmdid, uint8_t *param, int32_t len) { return 0; };
|
|
virtual void aftercall(int32_t val) {};
|
|
|
|
protected:
|
|
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);
|
|
virtual int32_t _module_get_reg(int32_t regoff, int32_t regval, int32_t &val);
|
|
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);
|
|
virtual int32_t _module_get_reg_float(int32_t regoff, float regval, int32_t &val, float precision);
|
|
virtual int32_t _module_xxx_reg(int32_t param_id, bool read, int32_t &val);
|
|
|
|
public:
|
|
public:
|
|
};
|
|
} // namespace iflytop
|