Browse Source

add some utils

master
zhaohe 11 months ago
parent
commit
1be600cfcc
  1. 1
      ble_through/ble_proto.h
  2. 53
      ble_through/ble_proto_utils.c
  3. 4
      ble_through/ble_proto_utils.h

1
ble_through/ble_proto.h

@ -85,6 +85,7 @@ typedef struct {
typedef struct {
uint8_t reset_flag;
uint8_t connected_flag;
uint8_t power;
} zble_heart_t;
#pragma pack()

53
ble_through/ble_proto_utils.c

@ -53,3 +53,56 @@ void zble_proto_utils_create_cmd_packet(zble_proto_packet_t *packet, uint16_t cm
}
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); }
void zble_proto_utils_create_error_receipt(zble_proto_packet_t* packet, zble_proto_packet_t* rxpacket, int32_t errorcode) {
int32_t packetlen = BLE_THROUGH_PACKET_BASE_SIZE() + sizeof(errorcode);
packet->h1 = PACKET_H1;
packet->h2 = PACKET_H2;
packet->packetlen = packetlen;
packet->frameType = kzble_proto_error_receipt;
packet->frameIndex = rxpacket->frameIndex;
packet->cmd = rxpacket->cmd;
packet->from = kzble_slave;
packet->to = kzble_upper;
memcpy((void*)packet->data, (void*)&errorcode, 4);
BLE_THROUGH_PACKET_SET_CHECKSUM(packet);
BLE_THROUGH_PACKET_SET_TAIL(packet);
//
}
void zble_proto_utils_create_receipt(zble_proto_packet_t* packet, zble_proto_packet_t* rxpacket, uint8_t* data, int32_t len) {
int32_t packetlen = BLE_THROUGH_PACKET_BASE_SIZE() + len;
packet->h1 = PACKET_H1;
packet->h2 = PACKET_H2;
packet->packetlen = packetlen;
packet->frameType = kzble_proto_cmd_receipt;
packet->frameIndex = rxpacket->frameIndex;
packet->cmd = rxpacket->cmd;
packet->from = kzble_slave;
packet->to = kzble_upper;
// memcpy((void*)packet->data, (void*)&errorcode, 4);
memcpy((void*)packet->data, (void*)data, len);
BLE_THROUGH_PACKET_SET_CHECKSUM(packet);
BLE_THROUGH_PACKET_SET_TAIL(packet);
//
}
void zble_proto_utils_create_report(zble_proto_packet_t* packet, uint16_t index, uint16_t cmd, uint8_t* data, int32_t len) {
int32_t packetlen = BLE_THROUGH_PACKET_BASE_SIZE() + len;
packet->h1 = PACKET_H1;
packet->h2 = PACKET_H2;
packet->packetlen = packetlen;
packet->frameType = kzble_proto_report;
packet->frameIndex = index;
packet->cmd = cmd;
packet->from = kzble_slave;
packet->to = kzble_upper;
// memcpy((void*)packet->data, (void*)&errorcode, 4);
memcpy((void*)packet->data, (void*)data, len);
BLE_THROUGH_PACKET_SET_CHECKSUM(packet);
BLE_THROUGH_PACKET_SET_TAIL(packet);
//
}

4
ble_through/ble_proto_utils.h

@ -26,6 +26,10 @@ 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);
void zble_proto_utils_create_error_receipt(zble_proto_packet_t *packet, zble_proto_packet_t *rxpacket, int32_t errorcode);
void zble_proto_utils_create_receipt(zble_proto_packet_t *packet, zble_proto_packet_t *rxpacket, uint8_t *data, int32_t len);
void zble_proto_utils_create_report(zble_proto_packet_t *packet, uint16_t index, uint16_t cmd, uint8_t *data, int32_t len);
#ifdef __cplusplus
}
#endif
Loading…
Cancel
Save