13 changed files with 29 additions and 310 deletions
-
5README.md
-
9app_protocols/app_protocols.h
-
53app_protocols/appecode/errorcode.c
-
55app_protocols/appecode/errorcode.h
-
0app_protocols/bean/hand_acid_mode.c
-
6app_protocols/bean/hand_acid_mode.h
-
7app_protocols/bean/hand_acid_remoter_key_event.h
-
93app_protocols/ble_through/ble_proto.h
-
55app_protocols/ble_through/ble_proto_utils.c
-
31app_protocols/ble_through/ble_proto_utils.h
-
0app_protocols/hand_acid_val_protocol/hand_acid_val_protocol.h
-
1app_protocols/zscanprotocol
-
24ui/ui.h
@ -1,9 +0,0 @@ |
|||
#pragma once |
|||
#include "bean/hand_acid_mode.h" |
|||
#include "bean/hand_acid_remoter_key_event.h" |
|||
#include "appecode/errorcode.h" |
|||
// |
|||
#include "zscanprotocol/zscanprotocol.h" |
|||
#include "hand_acid_val_protocol/hand_acid_val_protocol.h" |
|||
#include "ble_through/ble_proto.h" |
|||
#include "ble_through/ble_proto_utils.h" |
@ -1,53 +0,0 @@ |
|||
#include "errorcode.h" |
|||
|
|||
#define ERR2STR(code) \ |
|||
case code: \ |
|||
return #code; |
|||
|
|||
|
|||
#define ERR_ITERM(enum) \ |
|||
{ enum, #enum } |
|||
|
|||
static ecode_table_item_t table[] = { |
|||
|
|||
ERR_ITERM(ksucc), |
|||
ERR_ITERM(kfail), |
|||
ERR_ITERM(kparam_out_of_range), |
|||
ERR_ITERM(kcmd_not_support), |
|||
ERR_ITERM(kdevice_is_busy), |
|||
ERR_ITERM(kdevice_is_offline), |
|||
ERR_ITERM(kovertime), |
|||
ERR_ITERM(knoack), |
|||
ERR_ITERM(kerrorack), |
|||
ERR_ITERM(kdevice_offline), |
|||
ERR_ITERM(ksubdevice_overtime), |
|||
ERR_ITERM(kbuffer_not_enough), |
|||
ERR_ITERM(kcmd_param_num_error), |
|||
ERR_ITERM(kcheckcode_is_error), |
|||
ERR_ITERM(killegal_operation), |
|||
|
|||
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]); } |
|||
|
@ -1,55 +0,0 @@ |
|||
#pragma once |
|||
#include <stdint.h> |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
#define ERROR_CODE(errortype, suberrorcode) (errortype + suberrorcode) |
|||
|
|||
typedef enum { |
|||
|
|||
ksucc = 0, |
|||
kfail = 1, |
|||
|
|||
kparam_out_of_range = 102, |
|||
kcmd_not_support = 103, |
|||
kdevice_is_busy = 104, |
|||
kdevice_is_offline = 105, |
|||
kovertime = 106, |
|||
knoack = 107, |
|||
kerrorack = 108, |
|||
kdevice_offline = 109, |
|||
ksubdevice_overtime = 111, |
|||
kbuffer_not_enough = 112, |
|||
kcmd_param_num_error = 114, |
|||
kcheckcode_is_error = 115, |
|||
killegal_operation = 116, |
|||
|
|||
kstep_motor_not_found_zero_point = 600, |
|||
kstep_motor_not_go_zero = 601, |
|||
kstep_motor_over_temperature = 602, |
|||
kstep_motor_over_voltage = 603, |
|||
kstep_motor_run_overtime = 604, |
|||
kstep_motor_not_enable = 605, |
|||
kstep_motor_ioindex_out_of_range = 606, |
|||
kstep_motor_subic_reset = 607, |
|||
kstep_motor_drv_err = 608, |
|||
kstep_motor_uv_cp = 609, |
|||
kstep_motor_not_found_point_edge = 610, |
|||
|
|||
} 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(); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -1,6 +0,0 @@ |
|||
#pragma once |
|||
typedef enum { |
|||
khand_acid_m_unset_mode = 0, // unset_mode |
|||
khand_acid_m_jog_mode = 1, // jog_mode |
|||
khand_acid_m_continuous_mode = 2, // continuous_mode |
|||
} hand_acid_mode_t; |
@ -1,7 +0,0 @@ |
|||
#pragma once |
|||
typedef enum { |
|||
hand_acid_remoter_kevent_add_liquid = 0, // |
|||
hand_acid_remoter_kevent_change_next_mode = 1, // |
|||
hand_acid_remoter_kevent_reflux = 2, // |
|||
hand_acid_remoter_kevent_preFilling = 3, // |
|||
} hand_acid_remoter_key_event_t; |
@ -1,93 +0,0 @@ |
|||
#pragma once |
|||
#include <stdbool.h> |
|||
#include <stdint.h> |
|||
// |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
#define PACKET_H1 (0xAA) |
|||
#define PACKET_H2 (0xBB) |
|||
#define PACKET_TAIL (0xCC) |
|||
typedef enum { |
|||
kzble_proto_cmd = 1, |
|||
kzble_proto_cmd_receipt = 2, |
|||
kzble_proto_report = 3, |
|||
kzble_proto_error_receipt = 4, |
|||
} zble_proto_packet_type_t; |
|||
|
|||
typedef enum { |
|||
kzble_upper = 1, |
|||
kzble_master = 2, |
|||
kzble_slave = 3, |
|||
} zble_proto_role_t; |
|||
|
|||
/*********************************************************************************************************************** |
|||
* ENUM * |
|||
***********************************************************************************************************************/ |
|||
|
|||
#pragma pack(1) |
|||
typedef struct { |
|||
uint8_t h1; |
|||
uint8_t h2; |
|||
uint8_t packetlen; |
|||
uint8_t frameType; |
|||
uint8_t frameIndex; |
|||
uint16_t cmd; |
|||
uint8_t from; |
|||
uint8_t to; |
|||
uint8_t data[]; |
|||
} zble_proto_packet_t; |
|||
|
|||
typedef enum { |
|||
|
|||
kzble_cmd_reset = 100, // |
|||
kzble_cmd_read_version = 101, // param:{} receipt:ble_master_read_version_t |
|||
kzble_cmd_start_scan = 102, // param:zble_start_scan_t receipt:{} |
|||
kzble_cmd_stop_scan = 103, // param:{} receipt:{} |
|||
kzble_cmd_set_in_dfu_mode = 104, // param:{} receipt:{} |
|||
kzble_cmd_clear_reset_flag = 105, // |
|||
|
|||
kzble_report_connected_event = 150, // zble_connected_event_t |
|||
kzble_report_scan_result = 151, // zble_scan_result_t |
|||
kzble_report_power_on = 152, // |
|||
kzble_report_heart = 153, // zble_heart_t |
|||
|
|||
kzble_app_cmd_set_state = 200, // params:workmode(hand_acid_mode_t),pumpworkstate(0:notwork,1:work) |
|||
kzble_app_report_key_event = 250, // params:hand_acid_remoter_key_event_t |
|||
|
|||
} ble_app_proto_cmd_t; |
|||
|
|||
typedef struct { |
|||
uint8_t auto_connect; |
|||
uint8_t auto_connect_client_name[20]; |
|||
} zble_start_scan_t; |
|||
|
|||
typedef struct { |
|||
uint8_t connected; |
|||
char blename[20]; |
|||
char bleid[20]; |
|||
} zble_connected_event_t; |
|||
|
|||
typedef struct { |
|||
char blename[20]; |
|||
char bleid[20]; |
|||
uint8_t rssi; |
|||
} zble_scan_result_t; |
|||
|
|||
typedef struct { |
|||
int32_t firmware_version; |
|||
int32_t blestack_version; |
|||
int32_t bootloader_version; |
|||
int32_t hardware_version; |
|||
} zble_read_version_t; |
|||
|
|||
typedef struct { |
|||
uint8_t reset_flag; |
|||
uint8_t connected_flag; |
|||
} zble_heart_t; |
|||
#pragma pack() |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -1,55 +0,0 @@ |
|||
#include "ble_proto_utils.h" |
|||
|
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
|
|||
bool ble_through_proto_check_packet(zble_proto_packet_t *packet) { |
|||
uint8_t *pu8 = (uint8_t *)packet; |
|||
|
|||
if (packet->packetlen < (BLE_THROUGH_PACKET_BASE_SIZE())) { |
|||
return false; |
|||
} |
|||
if (packet->h1 != PACKET_H1 || packet->h2 != PACKET_H2) { |
|||
return false; |
|||
} |
|||
if (pu8[packet->packetlen - 1] != PACKET_TAIL) { |
|||
return false; |
|||
} |
|||
|
|||
uint8_t checksum = 0; |
|||
for (int i = 0; i < packet->packetlen - 2; i++) { |
|||
checksum += pu8[i]; |
|||
} |
|||
if (checksum != pu8[packet->packetlen - 2]) { |
|||
return false; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
uint8_t ble_through_proto_sum(zble_proto_packet_t *packet) { |
|||
uint8_t *_packet = (uint8_t *)packet; |
|||
uint8_t sum = 0; |
|||
for (int i = 0; i < packet->packetlen - 2; i++) { |
|||
sum += _packet[i]; |
|||
} |
|||
return sum; |
|||
} |
|||
|
|||
void zble_proto_utils_create_cmd_packet(zble_proto_packet_t *packet, uint16_t cmd, uint8_t index, uint8_t *data, int32_t datalen) { |
|||
int32_t packetlen = BLE_THROUGH_PACKET_BASE_SIZE() + datalen; |
|||
|
|||
packet->h1 = PACKET_H1; |
|||
packet->h2 = PACKET_H2; |
|||
packet->packetlen = packetlen; |
|||
packet->frameType = kzble_proto_cmd; |
|||
packet->frameIndex = index; |
|||
packet->cmd = cmd; |
|||
packet->from = kzble_upper; |
|||
packet->to = kzble_slave; |
|||
memcpy((void *)packet->data, data, datalen); |
|||
BLE_THROUGH_PACKET_SET_CHECKSUM(packet); |
|||
BLE_THROUGH_PACKET_SET_TAIL(packet); |
|||
} |
|||
|
|||
void zble_proto_utils_create_cmd_packet_int32(zble_proto_packet_t *packet, uint16_t cmd, uint8_t index, int32_t *data, int32_t ndata) { zble_proto_utils_create_cmd_packet(packet, cmd, index, (uint8_t *)data, ndata * 4); } |
@ -1,31 +0,0 @@ |
|||
#pragma once |
|||
|
|||
#include "ble_proto.h" |
|||
|
|||
#ifdef __cplusplus |
|||
extern "C" { |
|||
#endif |
|||
|
|||
#define BLE_THROUGH_PACKET_SET_TAIL(packet) \ |
|||
{ \ |
|||
uint8_t *__data = (uint8_t *)packet; \ |
|||
__data[packet->packetlen - 1] = PACKET_TAIL; \ |
|||
} |
|||
|
|||
#define BLE_THROUGH_PACKET_SET_CHECKSUM(packet) \ |
|||
{ \ |
|||
uint8_t *__data = (uint8_t *)packet; \ |
|||
__data[packet->packetlen - 2] = ble_through_proto_sum(packet); \ |
|||
} |
|||
|
|||
#define BLE_THROUGH_PACKET_BASE_SIZE() (sizeof(zble_proto_packet_t) + 1) |
|||
|
|||
bool ble_through_proto_check_packet(zble_proto_packet_t *packet); |
|||
uint8_t ble_through_proto_sum(zble_proto_packet_t *packet); |
|||
|
|||
void zble_proto_utils_create_cmd_packet(zble_proto_packet_t *packet, uint16_t cmd, uint8_t index, uint8_t *data, int32_t datalen); |
|||
void zble_proto_utils_create_cmd_packet_int32(zble_proto_packet_t *packet, uint16_t cmd, uint8_t index, int32_t *data, int32_t ndata); |
|||
|
|||
#ifdef __cplusplus |
|||
} |
|||
#endif |
@ -1 +0,0 @@ |
|||
Subproject commit 81529a15c57000f73cc5bd4b7276f567099b9988 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue