add tlv8_calculate_encode_len
This commit is contained in:
1 parent
8b76590659
commit
37219b5bc0
3 files changed
+18
-8
No files matched your search
@@ -186,12 +186,7 @@ HAPResponse_t* HAPCharacteristic::createHapResponse(uint8_t tid, uint8_t status,
|
||||
{
|
||||
// Determine body len, does not to include 2 byte length itself
|
||||
// FIXME multiple fragment len
|
||||
uint16_t body_len = 0;
|
||||
for(uint8_t i=0; i <count ; i++)
|
||||
{
|
||||
body_len += tlv_para[i].len + 2;
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
@@ -96,6 +96,19 @@ TLV8_t tlv8_decode_next(uint8_t const** pp_data, uint16_t* p_len, void* buf, uin
|
||||
return tlv;
|
||||
}
|
||||
|
||||
uint16_t tlv8_calculate_encode_len(TLV8_t tlv_para[], uint8_t count)
|
||||
{
|
||||
uint16_t total_len = 0;
|
||||
for(uint8_t i=0; i <count ; i++)
|
||||
{
|
||||
total_len += tlv_para[i].len + 2 + (tlv_para[i].len/255)*2;
|
||||
|
||||
if ( tlv_para[i].len % 255 == 0 ) total_len -= 2;
|
||||
}
|
||||
|
||||
return total_len;
|
||||
}
|
||||
|
||||
bool tlv8_encode_next(uint8_t** pp_buf, uint16_t* p_buflen, TLV8_t tlv)
|
||||
{
|
||||
while ( tlv.len )
|
||||
|
||||
@@ -148,7 +148,9 @@ typedef struct ATTR_PACKED
|
||||
|
||||
|
||||
|
||||
TLV8_t tlv8_decode_next(uint8_t const** pp_data, uint16_t* p_len, void* buf = NULL, uint16_t bufsize = 0);
|
||||
bool tlv8_encode_next(uint8_t** pp_buf, uint16_t* p_buflen, TLV8_t tlv);
|
||||
TLV8_t tlv8_decode_next(uint8_t const** pp_data, uint16_t* p_len, void* buf = NULL, uint16_t bufsize = 0);
|
||||
bool tlv8_encode_next(uint8_t** pp_buf, uint16_t* p_buflen, TLV8_t tlv);
|
||||
|
||||
uint16_t tlv8_calculate_encode_len(TLV8_t tlv_para[], uint8_t count);
|
||||
|
||||
#endif /* HAPPROCEDURE_H_ */
|
||||
Reference in new issue
Block a user