From 67566612731fc164b04ac40dab542edb9c41be8d Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 29 Aug 2024 14:48:07 +0800 Subject: [PATCH] =?UTF-8?q?zble=5Fproto=5Futils=E6=B7=BB=E5=8A=A0=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ble_through/ble_proto_utils.c | 31 +++++++++++++++++++------------ ble_through/ble_proto_utils.h | 2 ++ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/ble_through/ble_proto_utils.c b/ble_through/ble_proto_utils.c index 234e67d..aa00872 100644 --- a/ble_through/ble_proto_utils.c +++ b/ble_through/ble_proto_utils.c @@ -3,6 +3,12 @@ #include #include +static zble_proto_role_t m_from; + +void zble_proto_utils_init(zble_proto_role_t from) { // + m_from = from; +} + bool ble_through_proto_check_packet(zble_proto_packet_t *packet) { uint8_t *pu8 = (uint8_t *)packet; @@ -45,17 +51,18 @@ void zble_proto_utils_create_cmd_packet(zble_proto_packet_t *packet, uint16_t cm packet->frameType = kzble_proto_cmd; packet->frameIndex = index; packet->cmd = cmd; - packet->from = kzble_upper; + packet->from = m_from; 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); } - +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) { +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; @@ -63,15 +70,15 @@ void zble_proto_utils_create_error_receipt(zble_proto_packet_t* packet, zble_pro packet->frameType = kzble_proto_error_receipt; packet->frameIndex = rxpacket->frameIndex; packet->cmd = rxpacket->cmd; - packet->from = kzble_slave; + packet->from = m_from; packet->to = kzble_upper; - memcpy((void*)packet->data, (void*)&errorcode, 4); + 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) { +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; @@ -79,17 +86,17 @@ void zble_proto_utils_create_receipt(zble_proto_packet_t* packet, zble_proto_pac packet->frameType = kzble_proto_cmd_receipt; packet->frameIndex = rxpacket->frameIndex; packet->cmd = rxpacket->cmd; - packet->from = kzble_slave; + packet->from = m_from; packet->to = kzble_upper; // memcpy((void*)packet->data, (void*)&errorcode, 4); - memcpy((void*)packet->data, (void*)data, len); + 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) { +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; @@ -97,11 +104,11 @@ void zble_proto_utils_create_report(zble_proto_packet_t* packet, uint16_t index, packet->frameType = kzble_proto_report; packet->frameIndex = index; packet->cmd = cmd; - packet->from = kzble_slave; + packet->from = m_from; packet->to = kzble_upper; // memcpy((void*)packet->data, (void*)&errorcode, 4); - memcpy((void*)packet->data, (void*)data, len); + memcpy((void *)packet->data, (void *)data, len); BLE_THROUGH_PACKET_SET_CHECKSUM(packet); BLE_THROUGH_PACKET_SET_TAIL(packet); // diff --git a/ble_through/ble_proto_utils.h b/ble_through/ble_proto_utils.h index fe14eac..6a33904 100644 --- a/ble_through/ble_proto_utils.h +++ b/ble_through/ble_proto_utils.h @@ -23,6 +23,8 @@ extern "C" { 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_init(zble_proto_role_t from); + 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);