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.

96 lines
2.2 KiB

#include "zi_module.hpp"
#include <stdint.h>
#include <functional>
using namespace iflytop;
int32_t ZIModule::getid() {
int32_t id = 0;
getid(&id);
return id;
};
int32_t ZIModule::module_ping() { return 0; };
int32_t ZIModule::module_set_reg(int32_t param_id, int32_t param_value) { return _module_xxx_reg(param_id, false, param_value); }
int32_t ZIModule::module_get_reg(int32_t param_id, int32_t *param_value) { return _module_xxx_reg(param_id, true, *param_value); }
int32_t ZIModule::_module_xxx_reg(int32_t param_id, bool read, int32_t &val) {
if (param_id == kreg_module_version) {
if (read) {
module_get_version(&val);
return 0;
} else {
return 0;
}
}
else if (param_id == kreg_module_type) {
if (read) {
module_get_type(&val);
return 0;
} else {
return 0;
}
}
else if (param_id == kreg_module_status) {
if (read) {
module_get_status(&val);
return 0;
} else {
return 0;
}
}
else if (param_id == kreg_module_errorcode) {
if (read) {
val = creg.module_errorcode;
return 0;
} else {
return 0;
}
}
return module_xxx_reg(param_id, read, val);
}
int32_t ZIModule::_module_set_reg(int32_t regoff, int32_t *regval, int32_t val, int32_t min, int32_t max) {
if (val < min || val > max) {
return err::kparam_out_of_range;
}
*regval = val;
return 0;
}
int32_t ZIModule::_module_get_reg(int32_t regoff, int32_t regval, int32_t &val) {
val = regval;
return 0;
}
int32_t ZIModule::_module_set_reg_float(int32_t regoff, float *regval, int32_t val, float precision, int32_t min, int32_t max) {
if (val < min || val > max) {
return err::kparam_out_of_range;
}
*regval = val * precision;
return 0;
}
int32_t ZIModule::_module_get_reg_float(int32_t regoff, float regval, int32_t &val, float precision) {
val = regval / precision;
return 0;
}
int32_t ZIModule::module_get_error(int32_t *iserror) {
*iserror = creg.module_errorcode;
return 0;
}
int32_t ZIModule::module_clear_error() {
creg.module_errorcode = 0;
creg.m_module_status = 0;
return 0;
}
int32_t ZIModule::module_get_status(int32_t *status) {
*status = creg.m_module_status;
return 0;
}