Skip to content

Commit

Permalink
Switch the zpro encoder/decoder to using BufBound project-chip#2073
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhaskar-Sarma committed Aug 21, 2020
1 parent 6ed0fc4 commit cda51db
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 190 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)
14 changes: 14 additions & 0 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 Down Expand Up @@ -120,3 +132,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 cda51db

Please sign in to comment.