From b3f0598b1ad6cbea12b7184e6a4e4ef5200feb3e Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 15 Jan 2018 16:17:09 +0700 Subject: [PATCH] move createHapResponse() --- .../BLEHomekit/src/HAPCharacteristic.cpp | 21 ------------------- libraries/BLEHomekit/src/HAPCharacteristic.h | 2 -- libraries/BLEHomekit/src/HAPProcedure.cpp | 21 +++++++++++++++++++ libraries/BLEHomekit/src/HAPProcedure.h | 2 ++ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libraries/BLEHomekit/src/HAPCharacteristic.cpp b/libraries/BLEHomekit/src/HAPCharacteristic.cpp index 49e37db8..970bb96c 100644 --- a/libraries/BLEHomekit/src/HAPCharacteristic.cpp +++ b/libraries/BLEHomekit/src/HAPCharacteristic.cpp @@ -182,27 +182,6 @@ uint16_t HAPCharacteristic::writeHapValue(uint32_t num) return writeHapValue(&num, len); } -HAPResponse_t* HAPCharacteristic::createHapResponse(uint8_t tid, uint8_t status, TLV8_t tlv_para[], uint8_t count) -{ - // Determine body len, does not to include 2 byte length itself - uint16_t body_len = tlv8_calculate_encode_len(tlv_para, count); - HAPResponse_t* hap_resp = (HAPResponse_t*) rtos_malloc(sizeof(HAPResponseHeader_t) + 2 + body_len); - VERIFY( hap_resp != NULL, NULL ); - - /*------------- Header -------------*/ - varclr(&hap_resp->header.control); - hap_resp->header.control.fragment = 0; - hap_resp->header.control.type = HAP_PDU_RESPONSE; - hap_resp->header.tid = tid; - hap_resp->header.status = status; - hap_resp->body_len = body_len; - - /*------------- Serialize Data -------------*/ - tlv8_encode_n(hap_resp->body_data, body_len, tlv_para, count); - - return hap_resp; -} - HAPResponse_t* HAPCharacteristic::processChrSignatureRead(HAPRequest_t* hap_req) { uint16_t svc_id = ((HAPService*)_service)->getSvcId(); diff --git a/libraries/BLEHomekit/src/HAPCharacteristic.h b/libraries/BLEHomekit/src/HAPCharacteristic.h index cab4bb2d..3f87b19b 100644 --- a/libraries/BLEHomekit/src/HAPCharacteristic.h +++ b/libraries/BLEHomekit/src/HAPCharacteristic.h @@ -71,8 +71,6 @@ class HAPCharacteristic : public BLECharacteristic // Callbacks void setHapWriteCallback(hap_write_cb_t fp); - HAPResponse_t* createHapResponse(uint8_t tid, uint8_t status, TLV8_t tlv_para[] = NULL, uint8_t count = 0); - /*------------- Internal Functions -------------*/ virtual void _eventHandler(ble_evt_t* event); diff --git a/libraries/BLEHomekit/src/HAPProcedure.cpp b/libraries/BLEHomekit/src/HAPProcedure.cpp index 366d5cd3..64a2eeb4 100644 --- a/libraries/BLEHomekit/src/HAPProcedure.cpp +++ b/libraries/BLEHomekit/src/HAPProcedure.cpp @@ -143,3 +143,24 @@ uint16_t tlv8_encode_n(uint8_t* buf, uint16_t bufsize, TLV8_t tlv[], uint8_t cou return len - bufsize; } + +HAPResponse_t* createHapResponse(uint8_t tid, uint8_t status, TLV8_t tlv_para[], uint8_t count) +{ + // Determine body len, does not to include 2 byte length itself + uint16_t body_len = tlv8_calculate_encode_len(tlv_para, count); + HAPResponse_t* hap_resp = (HAPResponse_t*) rtos_malloc(sizeof(HAPResponseHeader_t) + 2 + body_len); + VERIFY( hap_resp != NULL, NULL ); + + /*------------- Header -------------*/ + varclr(&hap_resp->header.control); + hap_resp->header.control.fragment = 0; + hap_resp->header.control.type = HAP_PDU_RESPONSE; + hap_resp->header.tid = tid; + hap_resp->header.status = status; + hap_resp->body_len = body_len; + + /*------------- Serialize Data -------------*/ + tlv8_encode_n(hap_resp->body_data, body_len, tlv_para, count); + + return hap_resp; +} diff --git a/libraries/BLEHomekit/src/HAPProcedure.h b/libraries/BLEHomekit/src/HAPProcedure.h index 6d2e4cff..62b73c61 100644 --- a/libraries/BLEHomekit/src/HAPProcedure.h +++ b/libraries/BLEHomekit/src/HAPProcedure.h @@ -154,4 +154,6 @@ bool tlv8_encode_next(uint8_t** pp_buf, uint16_t* p_buflen, TLV8_t tlv); uint16_t tlv8_encode_n(uint8_t* buf, uint16_t bufsize, TLV8_t tlv[], uint8_t count); uint16_t tlv8_calculate_encode_len(TLV8_t tlv_para[], uint8_t count); +HAPResponse_t* createHapResponse(uint8_t tid, uint8_t status, TLV8_t tlv_para[] = NULL, uint8_t count = 0); + #endif /* HAPPROCEDURE_H_ */