Skip to content

Commit

Permalink
make chipZclBuffer_t opaque
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Walker committed Jun 2, 2020
1 parent 362a8e8 commit c8a2dd0
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 106 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ third_party/nlio/
third_party/nlunit-test/
third_party/mbedtls/
examples/common/m5stack-tft/
examples/common/QRCode/repo
examples/common/QRCode/repo/

# Example specific rules
examples/**/sdkconfig
Expand All @@ -40,7 +40,7 @@ src/test_driver/esp32/build
# Temporary Directories
.tmp/

# Xcode
# Xcode, other development environment stuff
*.pbxuser
*.mode1v3
*.mode2v3
Expand All @@ -50,3 +50,4 @@ project.xcworkspace/
xcuserdata/
*.xcodeproj/*
*.xcworkspace/*
TAGS
2 changes: 1 addition & 1 deletion examples/wifi-echo/server/esp32/main/DataModelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void InitDataModelHandler()

void HandleDataModelMessage(System::PacketBuffer * buffer)
{
ChipZclStatus_t zclStatus = chipZclProcessIncoming(buffer->Start(), buffer->DataLength());
ChipZclStatus_t zclStatus = chipZclProcessIncoming((ChipZclBuffer_t *) buffer);
if (zclStatus == CHIP_ZCL_STATUS_SUCCESS)
{
ESP_LOGI(TAG, "Data model processing success!");
Expand Down
4 changes: 2 additions & 2 deletions scripts/examples/esp_echo_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

make -f Makefile-bootstrap repos
source examples/wifi-echo/server/esp32/idf.sh
idf make -C examples/wifi-echo/server/esp32 defconfig
idf make -C examples/wifi-echo/server/esp32
idf make V=1 -C examples/wifi-echo/server/esp32 defconfig
idf make V=1 -C examples/wifi-echo/server/esp32
2 changes: 1 addition & 1 deletion src/app/DataModel.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ CHIP_BUILD_DATA_MODEL_SOURCE_FILES
@top_builddir@/src/app/gen/gen-command-handler.c \
@top_builddir@/src/app/gen/gen-global-command-handler.c \
@top_builddir@/src/app/gen/gen-specs.c \
@top_builddir@/src/app/plugin/binding-mock/mock.c \
@top_builddir@/src/app/plugin/binding-chip/chip.cpp \
@top_builddir@/src/app/plugin/cluster-server-basic/basic-server.c \
@top_builddir@/src/app/plugin/cluster-server-identify/identify-server.c \
@top_builddir@/src/app/plugin/cluster-server-level-control/level-control-server.c \
Expand Down
2 changes: 2 additions & 0 deletions src/app/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ lib_LIBRARIES = libCHIPDataModel.a
libCHIPDataModel_a_CPPFLAGS = \
-I$(top_srcdir)/src/app/chip-zcl \
-I$(top_srcdir)/src/app/gen \
-I$(top_srcdir)/src \
-I$(top_srcdir)/src/lib \
$(NULL)

libCHIPDataModel_a_SOURCES = $(CHIP_BUILD_DATA_MODEL_SOURCE_FILES)
Expand Down
34 changes: 8 additions & 26 deletions src/app/chip-zcl/chip-zcl-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif /* #ifdef __cplusplus */

/**
* Structure that describes the buffers passed between the CHIP layers and
* the Zap layer.
Expand All @@ -37,24 +41,7 @@
* from, currentPosition represents the current read position and dataLength is
* the total length of the data that can be read.
*/
typedef struct
{
/**
* The data storage for our buffer.
*/
uint8_t * buffer;

/**
* The size of our buffer above.
*/
uint16_t bufferLength;

/**
* The length of the data that can be read from this buffer; nonzero only
* when it's ready to be read from.
*/
uint16_t dataLength;
} ChipZclBuffer_t;
typedef struct ChipZclBuffer_t ChipZclBuffer_t;

/**
* Function that allocates a buffer.
Expand Down Expand Up @@ -82,14 +69,6 @@ uint8_t * chipZclBufferPointer(ChipZclBuffer_t * buffer);
*/
void chipZclBufferFree(ChipZclBuffer_t * buffer);

/**
* Function that resets a buffer to have its entire allocated length
* available for writing.
*
* @param[in] buffer the buffer to reset.
*/
void chipZclBufferReset(ChipZclBuffer_t * buffer);

/**
* Function that returns the size of the used portion of the buffer, in octets,
* when the buffer is ready for reading. Always returns 0 for buffers that are
Expand Down Expand Up @@ -117,4 +96,7 @@ void chipZclBufferSetDataLength(ChipZclBuffer_t * buffer, uint16_t newLength);
*/
uint16_t chipZclBufferAvailableLength(ChipZclBuffer_t * buffer);

#ifdef __cplusplus
}
#endif /* #ifdef __cplusplus */
#endif // CHIP_ZCL_BUFFER
8 changes: 8 additions & 0 deletions src/app/chip-zcl/chip-zcl-codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif /* #ifdef __cplusplus */

/**
* Codec keeps track of an ongoing encode/decode session of a Buffer
*/
Expand Down Expand Up @@ -84,4 +88,8 @@ ChipZclStatus_t chipZclCodecDecode(ChipZclCodec_t * codec, ChipZclType_t type, v
*/
ChipZclStatus_t chipZclCodecDecodeEnd(ChipZclCodec_t * me);

#ifdef __cplusplus
}
#endif /* #ifdef __cplusplus */

#endif // CHIP_ZCL_CODEC
7 changes: 7 additions & 0 deletions src/app/chip-zcl/chip-zcl-struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif /* #ifdef __cplusplus */

/**
* Base types for the codec. This is a smaller subset than the actual ZCL types, and the
* generated layer for a specific code is responsible for mapping ZCL types onto these
Expand Down Expand Up @@ -250,4 +254,7 @@ void chipZclStoreInt32uValue(uint8_t * valueLoc, uint32_t value, uint8_t valueSi

/** @} end addtogroup */

#ifdef __cplusplus
}
#endif /* #ifdef __cplusplus */
#endif // CHIP_ZCL_STRUCT
21 changes: 10 additions & 11 deletions src/app/chip-zcl/chip-zcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
#ifndef CHIP_ZCL_MASTER_HEADER
#define CHIP_ZCL_MASTER_HEADER

#include "chip-zcl-buffer.h"

#include <memory.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>

#include "chip-zcl-buffer.h"
#ifdef __cplusplus
extern "C" {
#endif /* #ifdef __cplusplus */

typedef uint64_t bitmap64_t;
typedef uint8_t enum8_t;
Expand Down Expand Up @@ -833,6 +837,7 @@ typedef struct
void chipZclEventSetDelayMs(Event * event, uint32_t delay);

void chEventControlSetDelayMS(ChipZclEventControl * event, uint32_t delay);

/** @brief Sets this ::EmberEventControl to run "delay" milliseconds in the future.
* NOTE: To avoid rollover errors in event calculation, the delay must be
* less than ::EMBER_MAX_EVENT_CONTROL_DELAY_MS.
Expand Down Expand Up @@ -976,15 +981,6 @@ void chipZclEventSetDelayMs(Event * event, uint32_t delay);
// Endpoint Management
ChipZclEndpointId_t chipZclEndpointIndexToId(ChipZclEndpointIndex_t index, const ChipZclClusterSpec_t * clusterSpec);

// Some platform CHIP_ZCL_STATUS_INSUFFICIENT_SPACE
#define MEMSET(d, v, l) memset(d, v, l)
#define MEMCOPY(d, s, l) memcpy(d, s, l)
#define MEMMOVE(d, s, l) memmove(d, s, l)
#define MEMCOMPARE(s0, s1, l) memcmp(s0, s1, l)
#define MEMPGMCOMPARE(s0, s1, l) memcmp(s0, s1, l)
#define LOW_BYTE(n) ((uint8_t)((n) &0xFF))
#define HIGH_BYTE(n) ((uint8_t)(LOW_BYTE((n) >> 8)))
#define IS_BIG_ENDIAN() false
/**
* @brief Returns the value built from the two \c uint8_t
* values \c high and \c low.
Expand Down Expand Up @@ -1113,6 +1109,9 @@ void chipZclEncodeZclHeader(ChipZclBuffer_t * buffer, ChipZclCommandContext_t *
*/
void chipZclDecodeZclHeader(ChipZclBuffer_t * buffer, ChipZclCommandContext_t * context);

ChipZclStatus_t chipZclProcessIncoming(uint8_t * buffer, uint16_t bufferLength);
ChipZclStatus_t chipZclProcessIncoming(ChipZclBuffer_t * buffer);

#ifdef __cplusplus
}
#endif /* #ifdef __cplusplus */
#endif // CHIP_ZCL_MASTER_HEADER
150 changes: 150 additions & 0 deletions src/app/plugin/binding-chip/chip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/**
*
* Copyright (c) 2020 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* @file
* This file provides the CHIP implementation of functions required
* by the CHIP ZCL Application Layer
*
*/

#include "chip-zcl.h"

#include <support/logging/CHIPLogging.h>
#include <system/SystemPacketBuffer.h>

#include <stdarg.h>

void chipZclCorePrintln(const char * formatString, ...)
{
va_list args;
va_start(args, formatString);
chip::Logging::LogV(chip::Logging::kLogModule_Zcl, chip::Logging::kLogCategory_Detail, formatString, args);
va_end(args);
}

// Default Response Stubs
ChipZclStatus_t chipZclSendDefaultResponse(const ChipZclCommandContext_t * context, ChipZclStatus_t status)
{
return CHIP_ZCL_STATUS_SUCCESS;
}

// Reporting Configuration Stubs
void chipZclReportingConfigurationsFactoryReset(ChipZclEndpointId_t endpointId)
{
return;
}

// Endpoint Management Stubs
ChipZclEndpointId_t chipZclEndpointIndexToId(ChipZclEndpointIndex_t index, const ChipZclClusterSpec_t * clusterSpec)
{
return CHIP_ZCL_ENDPOINT_NULL;
}

// Attribute Management Stubs
void chipZclResetAttributes(ChipZclEndpointId_t endpointId)
{
return;
}

// Event Management Stubs
EventQueue emAppEventQueue;

Event * chipZclEventFind(EventQueue * queue, EventActions * actions, EventPredicate predicate, void * data, bool all)
{
return 0;
}

void chEventControlSetDelayMS(ChipZclEventControl * event, uint32_t delay)
{
return;
}

void chipZclEventSetDelayMs(Event * event, uint32_t delay)
{
return;
}

int32_t chipZclCompareClusterSpec(const ChipZclClusterSpec_t * s1, const ChipZclClusterSpec_t * s2)
{
return 0;
}

bool chipZclAreClusterSpecsEqual(const ChipZclClusterSpec_t * s1, const ChipZclClusterSpec_t * s2)
{
return 0;
}

void chipZclReverseClusterSpec(const ChipZclClusterSpec_t * s1, ChipZclClusterSpec_t * s2)
{
return;
}

/**
* ChipZclBuffer_t is merely a type alias
*/
struct ChipZclBuffer_t : public chip::System::PacketBuffer
{
};

/**
* Function that allocates a buffer.
*/
ChipZclBuffer_t * chipZclBufferAlloc(uint16_t allocatedLength)
{
return static_cast<ChipZclBuffer_t *>(chip::System::PacketBuffer::NewWithAvailableSize(allocatedLength));
}

/**
* Function that frees a buffer and its storage.
*/
void chipZclBufferFree(ChipZclBuffer_t * buffer)
{
chip::System::PacketBuffer::Free(buffer);
}

/**
* Function that returns a pointer to the raw buffer.
*/
uint8_t * chipZclBufferPointer(ChipZclBuffer_t * buffer)
{
return buffer->Start();
}

/**
* Function that returns the size of the used portion of the buffer.
*/
uint16_t chipZclBufferDataLength(ChipZclBuffer_t * buffer)
{
return buffer->DataLength();
}

/**
* returns space available for writing after any data already in the buffer
*/
uint16_t chipZclBufferAvailableLength(ChipZclBuffer_t * buffer)
{
return buffer->AvailableDataLength();
}

/**
* sets data length for a buffer that's being written to
*/
void chipZclBufferSetDataLength(ChipZclBuffer_t * buffer, uint16_t newLength)
{
buffer->SetDataLength(newLength);
}
Loading

0 comments on commit c8a2dd0

Please sign in to comment.