22 changed files with 1141 additions and 1355 deletions
-
7api/api.hpp
-
12api/apibasic/basic.hpp
-
18api/apibasic/module_type_index.hpp
-
49api/apibasic/packet_interface.hpp
-
96api/zi_module.cpp
-
88api/zi_module.hpp
-
7protocol.hpp
-
0protocol/cmdid.cpp
-
0protocol/cmdid.hpp
-
0protocol/errorcode.cpp
-
0protocol/errorcode.hpp
-
53protocol/packet.hpp
-
0protocol/reg_index.cpp
-
0protocol/reg_index.hpp
-
2protocol/zmotor_struct.hpp
@ -1,7 +0,0 @@ |
|||
#pragma once
|
|||
#include "apibasic/basic.hpp"
|
|||
//
|
|||
#include "zi_module.hpp"
|
|||
//
|
|||
#include "zi_motor.hpp"
|
|||
//
|
@ -1,12 +0,0 @@ |
|||
#pragma once
|
|||
|
|||
#include "cmdid.hpp"
|
|||
//
|
|||
#include "errorcode.hpp"
|
|||
//
|
|||
#include "packet_interface.hpp"
|
|||
//
|
|||
#include "module_type_index.hpp"
|
|||
//
|
|||
#include "reg_index.hpp"
|
|||
//
|
@ -1,18 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
namespace iflytop { |
|||
typedef enum { |
|||
khbot_module = 1, // hbot模块
|
|||
ktemperature_ctrl_module = 3, // 温度控制
|
|||
kfan_ctrl_module = 5, // 风扇控制
|
|||
kcode_scaner = 6, // 扫码器
|
|||
kpipette_ctrl_module = 7, // 移液体枪控制
|
|||
ka8000_optical_module = 8, // a8000光学模组
|
|||
ktmc_step_motor = 10, // 步进电机
|
|||
kmini_servo_motor_module = 11, // 舵机
|
|||
kboard = 12, // 板子
|
|||
ka8000_idcard_reader = 13, // id卡读卡器
|
|||
ka8000_plate_code_scaner = 14, // 反应板条扫码器
|
|||
} module_type_t; |
|||
} |
@ -1,49 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
#define ZCANCMD_PACKET_MAX_LEN 64
|
|||
|
|||
namespace iflytop { |
|||
namespace zcr { |
|||
#pragma pack(push, 1)
|
|||
typedef struct { |
|||
uint8_t packetType; |
|||
uint16_t cmdid; |
|||
uint8_t moduleId; |
|||
uint8_t index; |
|||
uint8_t datalen; |
|||
uint8_t data[]; |
|||
/* int8_t checksum;*/ |
|||
} zcr_cmd_header_t; |
|||
|
|||
#pragma pack(pop)
|
|||
|
|||
typedef enum { |
|||
kptv2_cmd = 0xA0, |
|||
kptv2_ack = 0xA1, |
|||
kptv2_error_ack = 0xA2, |
|||
kptv2_event = 0xA3, |
|||
} zcan_cmd_packet_type_t; |
|||
|
|||
static inline bool zcr_cmd_checkpacket(const zcr_cmd_header_t* header, int len) { |
|||
if (len < sizeof(zcr_cmd_header_t)) { |
|||
return false; |
|||
} |
|||
if ((header->datalen + sizeof(zcr_cmd_header_t) + 1) != len) { |
|||
return false; |
|||
} |
|||
|
|||
uint8_t* rawpacket = (uint8_t*)header; |
|||
uint8_t checksum = 0; |
|||
for (int i = 0; i < len - 1; i++) { |
|||
checksum += rawpacket[i]; |
|||
} |
|||
|
|||
if (checksum != rawpacket[len - 1]) { |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
@ -1,96 +0,0 @@ |
|||
|
|||
#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.module_status = 0; |
|||
return 0; |
|||
} |
|||
|
|||
int32_t ZIModule::module_get_status(int32_t *status) { |
|||
*status = creg.module_status; |
|||
return 0; |
|||
} |
@ -1,88 +0,0 @@ |
|||
#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 cmdid, uint8_t *param, int32_t len, uint8_t *ack, int32_t acklen, int32_t ret) {}; |
|||
|
|||
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
|
@ -1,2 +1,7 @@ |
|||
#pragma once
|
|||
#include "api/api.hpp"
|
|||
#include "protocol\cmdid.hpp"
|
|||
#include "protocol\errorcode.hpp"
|
|||
#include "protocol\packet.hpp"
|
|||
#include "protocol\reg_index.hpp"
|
|||
//
|
|||
#include "protocol\zmotor_struct.hpp"
|
@ -0,0 +1,53 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
#define ZCANCMD_PACKET_MAX_LEN 64
|
|||
|
|||
namespace iflytop { |
|||
|
|||
typedef enum { |
|||
khbot_module = 1, // hbot模块
|
|||
ktemperature_ctrl_module = 3, // 温度控制
|
|||
kfan_ctrl_module = 5, // 风扇控制
|
|||
kcode_scaner = 6, // 扫码器
|
|||
kpipette_ctrl_module = 7, // 移液体枪控制
|
|||
ka8000_optical_module = 8, // a8000光学模组
|
|||
ktmc_step_motor = 10, // 步进电机
|
|||
kmini_servo_motor_module = 11, // 舵机
|
|||
kboard = 12, // 板子
|
|||
ka8000_idcard_reader = 13, // id卡读卡器
|
|||
ka8000_plate_code_scaner = 14, // 反应板条扫码器
|
|||
} module_type_t; |
|||
|
|||
namespace zcr { |
|||
#pragma pack(push, 1)
|
|||
typedef struct { |
|||
uint8_t packetType; |
|||
uint16_t cmdid; |
|||
uint8_t moduleId; |
|||
uint8_t index; |
|||
uint8_t datalen; |
|||
uint8_t data[]; |
|||
/* int8_t checksum;*/ |
|||
} zcr_cmd_header_t; |
|||
|
|||
#pragma pack(pop)
|
|||
|
|||
typedef enum { |
|||
kptv2_cmd = 0xA0, |
|||
kptv2_ack = 0xA1, |
|||
kptv2_error_ack = 0xA2, |
|||
kptv2_event = 0xA3, |
|||
} zcan_cmd_packet_type_t; |
|||
|
|||
static inline bool zcr_cmd_checkpacket(const zcr_cmd_header_t* header, int len) { |
|||
if (len < sizeof(zcr_cmd_header_t)) return false; |
|||
if ((header->datalen + sizeof(zcr_cmd_header_t) + 1) != len) return false; |
|||
|
|||
uint8_t checksum = 0; |
|||
for (int i = 0; i < len - 1; i++) checksum += ((uint8_t*)header)[i]; |
|||
|
|||
return checksum == ((uint8_t*)header)[len - 1]; |
|||
} |
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue