Browse Source

udpate protocol

master
zhaohe 1 year ago
parent
commit
4f2d39e078
  1. 44
      errorcode.cpp
  2. 40
      errorcode.hpp
  3. 269
      heart_rate_sensor_protocol.h
  4. 3
      protocol.hpp

44
errorcode.cpp

@ -0,0 +1,44 @@
#include "errorcode.hpp"
#define ERR2STR(code) \
case code: \
return #code;
namespace iflytop {
namespace err {
#define ERR_ITERM(enum) \
{ enum, #enum }
static ecode_table_item_t table[] = {
ERR_ITERM(ksucc),
ERR_ITERM(kfail),
ERR_ITERM(kstep_motor_not_found_zero_point),
ERR_ITERM(kstep_motor_not_go_zero),
ERR_ITERM(kstep_motor_over_temperature),
ERR_ITERM(kstep_motor_over_voltage),
ERR_ITERM(kstep_motor_run_overtime),
ERR_ITERM(kstep_motor_not_enable),
ERR_ITERM(kstep_motor_ioindex_out_of_range),
ERR_ITERM(kstep_motor_subic_reset),
ERR_ITERM(kstep_motor_drv_err),
ERR_ITERM(kstep_motor_uv_cp),
ERR_ITERM(kstep_motor_not_found_point_edge),
};
const char* error2str(int32_t code) {
for (int i = 0; i < sizeof(table) / sizeof(table[0]); i++) {
if (table[i].index == code) {
return table[i].info;
}
}
return "unknown error";
}
ecode_table_item_t* error_get_table() { return table; }
int error_get_table_size() { return sizeof(table) / sizeof(table[0]); }
} // namespace err
} // namespace iflytop

40
errorcode.hpp

@ -0,0 +1,40 @@
#pragma once
#include <stdint.h>
namespace iflytop {
namespace err {
using namespace std;
#define ERROR_CODE(errortype, suberrorcode) (errortype + suberrorcode)
typedef enum {
ksucc = ERROR_CODE(0, 0),
kfail = ERROR_CODE(0, 1),
kstep_motor_not_found_zero_point = ERROR_CODE(600, 0), // 未找到零点
kstep_motor_not_go_zero = ERROR_CODE(600, 1), // 设备未归零
kstep_motor_over_temperature = ERROR_CODE(600, 2), // 过温
kstep_motor_over_voltage = ERROR_CODE(600, 3), // 过压
kstep_motor_run_overtime = ERROR_CODE(600, 4), // 运行超时
kstep_motor_not_enable = ERROR_CODE(600, 5), // 电机未使能
kstep_motor_ioindex_out_of_range = ERROR_CODE(600, 6), // IO超出范围
kstep_motor_subic_reset = ERROR_CODE(600, 7), // 子IC复位
kstep_motor_drv_err = ERROR_CODE(600, 8), // 驱动器异常
kstep_motor_uv_cp = ERROR_CODE(600, 9), // 驱动器异常
kstep_motor_not_found_point_edge = ERROR_CODE(600, 10), // 未找到零点
} error_t;
typedef struct {
int index;
const char* info;
} ecode_table_item_t;
const char* error2str(int32_t code);
ecode_table_item_t* error_get_table();
int error_get_table_size();
} // namespace err
} // namespace iflytop

269
heart_rate_sensor_protocol.h

@ -1,269 +0,0 @@
#pragma once
#include <stdint.h>
#pragma pack(push, 1)
typedef struct {
uint8_t frame_type;
uint8_t frame_index;
uint8_t cmd;
uint8_t data[];
} ify_hrs_packet_t;
typedef enum {
kifyhrs_ecode_success = 0,
kifyhrs_ecode_unkown_error = 1,
kifyhrs_ecode_cmd_not_support = 2,
kifyhrs_ecode_illegal_parameter = 3,
kifyhrs_ecode_device_busy = 4,
kifyhrs_ecode_hardware_error = 5,
kifyhrs_ecode_sensor_drop = 6,
kifyhrs_ecode_no_record_find = 7,
kifyhrs_ecode_parameter_error = 8,
kifyhrs_ecode_electrode_is_not_inserted = 9,
kifyhrs_ecode_device_exception = 10,
kifyhrs_ecode_invalid_state = 11,
kifyhrs_ecode_overtime = 200,
kifyhrs_ecode_channel_is_close = 201,
kifyhrs_ecode_upper_exception = 202,
} ify_hrs_error_code_t;
static inline const char *ify_hrs_error_code_to_string(ify_hrs_error_code_t code) {
switch (code) {
case kifyhrs_ecode_success:
return "success";
case kifyhrs_ecode_unkown_error:
return "unkown error";
case kifyhrs_ecode_cmd_not_support:
return "cmd not support";
case kifyhrs_ecode_illegal_parameter:
return "illegal parameter";
case kifyhrs_ecode_device_busy:
return "device busy";
case kifyhrs_ecode_hardware_error:
return "hardware error";
case kifyhrs_ecode_sensor_drop:
return "sensor drop";
case kifyhrs_ecode_no_record_find:
return "no record find";
case kifyhrs_ecode_parameter_error:
return "parameter error";
case kifyhrs_ecode_electrode_is_not_inserted:
return "electrode is not inserted";
case kifyhrs_ecode_device_exception:
return "device exception";
case kifyhrs_ecode_invalid_state:
return "invalid state";
case kifyhrs_ecode_overtime:
return "overtime";
case kifyhrs_ecode_channel_is_close:
return "channel is close";
case kifyhrs_ecode_upper_exception:
return "upper exception";
default:
return "unkown error";
}
}
typedef enum {
kifyhrs_pt_cmd = 1,
kifyhrs_pt_cmd_receipt = 2,
kifyhrs_pt_report = 3,
kifyhrs_pt_error_receipt = 4,
} ify_hrs_packet_type_t;
typedef enum {
kifyhrs_sensor_pos_none = 0, //
kifyhrs_sensor_pos_I = 1, // I
kifyhrs_sensor_pos_II = 2, // II
kifyhrs_sensor_pos_III = 3, // III
kifyhrs_sensor_pos_V1 = 4, // V1
kifyhrs_sensor_pos_V2 = 5, // V2
kifyhrs_sensor_pos_V3 = 6, // V3
kifyhrs_sensor_pos_V4 = 7, // V4
kifyhrs_sensor_pos_V5 = 8, // V5
kifyhrs_sensor_pos_V6 = 9, // V6
kifyhrs_sensor_pos_aVR = 10, //
kifyhrs_sensor_pos_aVL = 11, //
kifyhrs_sensor_pos_aVF = 12, //
} ify_hrs_sensor_pos_t;
typedef enum {
ify_hrs_cmd_read_device_version = 1,
ify_hrs_cmd_read_sensor_info = 2,
ify_hrs_cmd_read_device_state = 3,
ify_hrs_cmd_read_time = 4,
ify_hrs_cmd_sync_time = 5,
ify_hrs_cmd_start_realtime_preview = 8,
ify_hrs_cmd_stop_realtime_preview = 9,
ify_hrs_cmd_read_records_info = 10,
ify_hrs_cmd_del_record = 11,
ify_hrs_cmd_start_upload_record = 12,
ify_hrs_cmd_enter_ota = 13,
ify_hrs_cmd_read_sn = 14,
ify_hrs_cmd_reset = 15,
ify_hrs_cmd_stop_upload_record = 16,
ify_hrs_cmd_ads1293_error_detail_info = 19, // 使
ify_hrs_cmd_change_sn = 20, // 使
ify_hrs_cmd_read_device_exception_state = 21, //
ify_hrs_cmd_read_ads1293_cfg_type = 22, // ads1293使用的配置类型
ify_hrs_cmd_start_storage = 23, //
ify_hrs_cmd_stop_storage = 24, //
ify_hrs_report_heartrate_data = 101,
ify_hrs_report_battery_level = 102,
ify_hrs_report_low_battey_level = 103,
ify_hrs_report_sample_finish_end = 104,
ify_hrs_report_sensor_drop_detect = 105,
ify_hrs_report_record_upload_end = 106,
ify_hrs_cmd_set_ecg_in_test_mode = 150,
ify_hrs_cmd_set_ecg_report_data_in_raw_mode = 151, // ECG上报数据为原始数据
ify_hrs_cmd_ecg_subic_read_reg = 152,
ify_hrs_cmd_ecg_subic_write_reg = 153,
} ify_hrs_cmd_t;
/*******************************************************************************
* packet_struct *
*******************************************************************************/
typedef struct {
uint16_t placeholder;
uint16_t blestack_version;
uint16_t bootloader_version;
uint16_t firmware_version;
uint16_t hardware_version;
} device_version_info_receipt_t;
typedef struct {
uint8_t sensor_num; //
uint8_t sensor_precision; //
uint8_t sensor_sample_rate; //
uint8_t sensor0_pos; //
uint8_t sensor1_pos; //
uint8_t sensor2_pos; //
} sensor_info_receipt_t;
typedef struct {
uint8_t drop_state0;
uint8_t drop_state1;
struct {
uint8_t sampling_state : 1; //
uint8_t report_state : 1; //
uint8_t low_battery : 1; //
uint8_t full_storge : 1; //
// uint8_t is_storaging : 1; //
uint8_t holder : 4; //
} device_state0;
uint8_t device_state1; //
uint8_t powerlevel; //
uint8_t storage_item_num; //
// uint32_t storage_setting_time_s;
// uint32_t storage_has_storaged_time_s;
} device_state_receipt_t;
typedef struct {
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} read_time_receipt_t;
typedef struct {
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} sync_time_cmd_t;
typedef struct {
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
} start_capture_cmd_t;
typedef struct {
uint8_t record_index; //
} read_record_info_cmd_t;
typedef struct {
uint8_t record_id[6];
uint32_t frameNum;
uint32_t dataSize;
uint8_t sensorNum;
uint8_t captureRate; // N*10HZ
uint8_t capturePrecision;
uint8_t compressAlgorithm; //
uint32_t checksum; //
} read_record_info_receipt_t;
typedef struct {
uint8_t record_id[6];
} del_record_cmd_t;
typedef struct {
uint8_t record_id[6];
} start_upload_record_cmd_t;
typedef struct {
uint8_t sn[14];
} read_sn_receipt_t;
typedef struct {
uint8_t errorcode;
} error_receipt_t;
/*******************************************************************************
* *
*******************************************************************************/
typedef struct {
uint8_t frame_type;
uint8_t frame_index;
uint8_t cmd;
uint32_t sample_data_index;
uint8_t data[]; //
} heartrate_report_packet_t;
typedef struct {
uint8_t frame_type;
uint8_t frame_index;
uint8_t cmd;
uint32_t sample_data_index;
uint16_t leadoff_state;
uint16_t sample_data_num;
int32_t frame[]; //
} m1003_heartrate_report_packet_t;
typedef struct {
uint8_t frame_type;
uint8_t frame_index;
uint8_t cmd;
uint32_t sample_data_index;
uint32_t reportdata[50];
} ads1291_report_packet_t;
typedef struct {
uint8_t frame_type;
uint8_t frame_index;
uint8_t cmd;
uint8_t drop_state0;
uint8_t drop_state1;
} sensor_drop_event_report_packet_t;
#pragma pack(pop)

3
protocol.hpp

@ -0,0 +1,3 @@
#pragma once
#include "errorcode.hpp"
Loading…
Cancel
Save