Skip to content

Commit

Permalink
#2073 Switch the zpro encoder/decoder to using BufBound (#2103)
Browse files Browse the repository at this point in the history
* Switch the zpro encoder/decoder to using BufBound #2073

* Replace extraneous printf

* Fix build

* PR Feedback

* Fix the measure case for encodeAPSFrame

* PR Feedback round 2

* PR feedback round 3

Co-authored-by: Bhaskar Sarma <[email protected]>
  • Loading branch information
bhaskar-apple and Bhaskar-Sarma authored Aug 25, 2020
1 parent 2054146 commit 14263d9
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 195 deletions.
1 change: 1 addition & 0 deletions examples/chip-tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ void DoOnOff(DeviceController::ChipDeviceController * controller, Command comman
fprintf(stderr, "Unknown command: %d\n", int(command));
return;
}
ChipLogProgress(Zcl, "Encoded data of length %d", dataLength);
buffer->SetDataLength(dataLength);

#ifdef DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void EchoDeviceCallbacks::PostAttributeChangeCallback(uint8_t endpoint, EmberAfC
ESP_LOGI(TAG, "Unknown attribute ID: %d", attributeId);
return;
}
ESP_LOGI(TAG, "Got the post attribute callback");
ESP_LOGI(TAG, "Got the post attribute callback with value %d", *value);
// At this point we can assume that value points to a bool value.
statusLED.Set(*value);
ESP_LOGI(TAG, "Current free heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
Expand Down
4 changes: 2 additions & 2 deletions src/app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ static_library("app") {
output_name = "libCHIPDataModel"

sources = [
"decoder.c",
"encoder.c",
"decoder.cpp",
"encoder.cpp",
]

public_deps = [
Expand Down
4 changes: 2 additions & 2 deletions src/app/DataModel.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
#

CHIP_BUILD_DATA_MODEL_SOURCE_FILES = \
@top_builddir@/src/app/encoder.c \
@top_builddir@/src/app/decoder.c \
@top_builddir@/src/app/encoder.cpp \
@top_builddir@/src/app/decoder.cpp \
$(NULL)
2 changes: 1 addition & 1 deletion src/app/chip-zcl-zpro-codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void printApsFrame(EmberApsFrame * frame);
* - If buffer is null, the number of bytes needed to encode.
* - If buffer is non-null but buf_length is not enough to hold the
* EmberApsFrame, 0.
* - If buffer us non-null and buf_length is large enough, the number of bytes
* - If buffer is non-null and buf_length is large enough, the number of bytes
* placed in buffer.
*/
uint16_t encodeApsFrame(uint8_t * buffer, uint16_t buf_length, EmberApsFrame * apsFrame);
Expand Down
24 changes: 20 additions & 4 deletions src/app/decoder.c → src/app/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,68 +25,80 @@
#include <app/chip-zcl-zpro-codec.h>
#include <stdio.h>
#include <string.h>
#include <support/logging/CHIPLogging.h>

extern "C" {

uint16_t extractApsFrame(uint8_t * buffer, uint32_t buf_length, EmberApsFrame * outApsFrame)
{

if (buffer == NULL || buf_length == 0 || outApsFrame == NULL)
{
ChipLogError(Zcl, "Error extracting APS frame. invalid inputs");
return 0;
}
// Skip first byte, because that's the always-0 frame control.
uint8_t nextByteToRead = 1;

if (nextByteToRead >= buf_length)
{
ChipLogError(Zcl, "Error extracting APS frame after reading first byte");
return 0;
}
memcpy(&outApsFrame->profileId, buffer + nextByteToRead, sizeof(outApsFrame->profileId));
nextByteToRead += sizeof(outApsFrame->profileId);

if (nextByteToRead >= buf_length)
{
ChipLogError(Zcl, "Error extracting APS frame after reading profileId");
return 0;
}
memcpy(&outApsFrame->clusterId, buffer + nextByteToRead, sizeof(outApsFrame->clusterId));
nextByteToRead += sizeof(outApsFrame->clusterId);

if (nextByteToRead >= buf_length)
{
ChipLogError(Zcl, "Error extracting APS frame after reading clusterId");
return 0;
}
memcpy(&outApsFrame->sourceEndpoint, buffer + nextByteToRead, sizeof(outApsFrame->sourceEndpoint));
nextByteToRead += sizeof(outApsFrame->sourceEndpoint);

if (nextByteToRead >= buf_length)
{
ChipLogError(Zcl, "Error extracting APS frame after reading sourceEndpoint");
return 0;
}
memcpy(&outApsFrame->destinationEndpoint, buffer + nextByteToRead, sizeof(outApsFrame->destinationEndpoint));
nextByteToRead += sizeof(outApsFrame->destinationEndpoint);

if (nextByteToRead >= buf_length)
{
ChipLogError(Zcl, "Error extracting APS frame after reading destinationEndpoint");
return 0;
}
memcpy(&outApsFrame->options, buffer + nextByteToRead, sizeof(outApsFrame->options));
nextByteToRead += sizeof(outApsFrame->options);

if (nextByteToRead >= buf_length)
{
ChipLogError(Zcl, "Error extracting APS frame after reading options");
return 0;
}
memcpy(&outApsFrame->groupId, buffer + nextByteToRead, sizeof(outApsFrame->groupId));
nextByteToRead += sizeof(outApsFrame->groupId);

if (nextByteToRead >= buf_length)
{
ChipLogError(Zcl, "Error extracting APS frame after reading groupId");
return 0;
}
memcpy(&outApsFrame->sequence, buffer + nextByteToRead, sizeof(outApsFrame->sequence));
nextByteToRead += sizeof(outApsFrame->sequence);

if (nextByteToRead >= buf_length)
{
ChipLogError(Zcl, "Error extracting APS frame after reading sequence");
return 0;
}
memcpy(&outApsFrame->radius, buffer + nextByteToRead, sizeof(outApsFrame->radius));
Expand All @@ -97,10 +109,12 @@ uint16_t extractApsFrame(uint8_t * buffer, uint32_t buf_length, EmberApsFrame *

void printApsFrame(EmberApsFrame * frame)
{
printf("\n<EmberApsFrame %p> profileID %d, clusterID %d, sourceEndpoint %d, destinationEndPoint %d, options %d, groupID %d, "
"sequence %d, radius %d\n",
frame, frame->profileId, frame->clusterId, frame->sourceEndpoint, frame->destinationEndpoint, frame->options,
frame->groupId, frame->sequence, frame->radius);
ChipLogProgress(
Zcl,
"\n<EmberApsFrame %p> profileID %d, clusterID %d, sourceEndpoint %d, destinationEndPoint %d, options %d, groupID %d, "
"sequence %d, radius %d\n",
frame, frame->profileId, frame->clusterId, frame->sourceEndpoint, frame->destinationEndpoint, frame->options,
frame->groupId, frame->sequence, frame->radius);
}

uint16_t extractMessage(uint8_t * buffer, uint16_t buffer_length, uint8_t ** msg)
Expand All @@ -120,3 +134,5 @@ uint16_t extractMessage(uint8_t * buffer, uint16_t buffer_length, uint8_t ** msg
}
return result;
}

} // extern C
185 changes: 0 additions & 185 deletions src/app/encoder.c

This file was deleted.

Loading

0 comments on commit 14263d9

Please sign in to comment.