Skip to content

Commit

Permalink
Run codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Jun 15, 2021
1 parent e7ba0c8 commit be29ca2
Show file tree
Hide file tree
Showing 13 changed files with 7,357 additions and 974 deletions.
61 changes: 47 additions & 14 deletions examples/chip-tool/commands/clusters/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "gen/CHIPClientCallbacks.h"
#include "gen/CHIPClusters.h"
#include <lib/core/CHIPSafeCasts.h>
#include <lib/support/SafeInt.h>

static void OnDefaultSuccessResponse(void * context)
{
Expand All @@ -50,65 +51,97 @@ static void OnBooleanAttributeResponse(void * context, bool value)
command->SetCommandExitStatus(true);
}

static void OnInt8uAttributeResponse(void * context, uint8_t value)
static void OnInt8uAttributeResponse(void * context, uint64_t value)
{
ChipLogProgress(chipTool, "Int8u attribute Response: %" PRIu8, value);
if (!chip::CanCastTo<uint8_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into uint8", value);
}
ChipLogProgress(chipTool, "Int8u attribute Response: %" PRIu8, static_cast<uint8_t>(value));

ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
command->SetCommandExitStatus(true);
}

static void OnInt16uAttributeResponse(void * context, uint16_t value)
static void OnInt16uAttributeResponse(void * context, uint64_t value)
{
ChipLogProgress(chipTool, "Int16u attribute Response: %" PRIu16, value);
if (!chip::CanCastTo<uint16_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into uint16", value);
}
ChipLogProgress(chipTool, "Int16u attribute Response: %" PRIu16, static_cast<uint16_t>(value));

ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
command->SetCommandExitStatus(true);
}

static void OnInt32uAttributeResponse(void * context, uint32_t value)
static void OnInt32uAttributeResponse(void * context, uint64_t value)
{
ChipLogProgress(chipTool, "Int32u attribute Response: %" PRIu32, value);
if (!chip::CanCastTo<uint32_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into uint32", value);
}
ChipLogProgress(chipTool, "Int32u attribute Response: %" PRIu32, static_cast<uint32_t>(value));

ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
command->SetCommandExitStatus(true);
}

static void OnInt64uAttributeResponse(void * context, uint64_t value)
{
ChipLogProgress(chipTool, "Int64u attribute Response: %" PRIu64, value);
if (!chip::CanCastTo<uint64_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into uint64", value);
}
ChipLogProgress(chipTool, "Int64u attribute Response: %" PRIu64, static_cast<uint64_t>(value));

ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
command->SetCommandExitStatus(true);
}

static void OnInt8sAttributeResponse(void * context, int8_t value)
static void OnInt8sAttributeResponse(void * context, int64_t value)
{
ChipLogProgress(chipTool, "Int8s attribute Response: %" PRId8, value);
if (!chip::CanCastTo<int8_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into int8", value);
}
ChipLogProgress(chipTool, "Int8s attribute Response: %" PRId8, static_cast<int8_t>(value));

ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
command->SetCommandExitStatus(true);
}

static void OnInt16sAttributeResponse(void * context, int16_t value)
static void OnInt16sAttributeResponse(void * context, int64_t value)
{
ChipLogProgress(chipTool, "Int16s attribute Response: %" PRId16, value);
if (!chip::CanCastTo<int16_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into int16", value);
}
ChipLogProgress(chipTool, "Int16s attribute Response: %" PRId16, static_cast<int16_t>(value));

ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
command->SetCommandExitStatus(true);
}

static void OnInt32sAttributeResponse(void * context, int32_t value)
static void OnInt32sAttributeResponse(void * context, int64_t value)
{
ChipLogProgress(chipTool, "Int32s attribute Response: %" PRId32, value);
if (!chip::CanCastTo<int32_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into int32", value);
}
ChipLogProgress(chipTool, "Int32s attribute Response: %" PRId32, static_cast<int32_t>(value));

ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
command->SetCommandExitStatus(true);
}

static void OnInt64sAttributeResponse(void * context, int64_t value)
{
ChipLogProgress(chipTool, "Int64s attribute Response: %" PRId64, value);
if (!chip::CanCastTo<int64_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into int64", value);
}
ChipLogProgress(chipTool, "Int64s attribute Response: %" PRId64, static_cast<int64_t>(value));

ModelCommand * command = reinterpret_cast<ModelCommand *>(context);
command->SetCommandExitStatus(true);
Expand Down
24 changes: 18 additions & 6 deletions examples/chip-tool/commands/reporting/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,31 @@ class Listen : public ReportingCommand
ChipLogProgress(chipTool, "Boolean attribute Response: %d", value);
}

static void OnInt8uAttributeResponse(void * context, uint8_t value)
static void OnInt8uAttributeResponse(void * context, uint64_t value)
{
ChipLogProgress(chipTool, "Int8u attribute Response: %" PRIu8, value);
if (!chip::CanCastTo<uint8_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into uint8", value);
}
ChipLogProgress(chipTool, "Int8u attribute Response: %" PRIu8, static_cast<uint8_t>(value));
}

static void OnInt16uAttributeResponse(void * context, uint16_t value)
static void OnInt16uAttributeResponse(void * context, uint64_t value)
{
ChipLogProgress(chipTool, "Int16u attribute Response: %" PRIu16, value);
if (!chip::CanCastTo<uint16_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into uint16", value);
}
ChipLogProgress(chipTool, "Int16u attribute Response: %" PRIu16, static_cast<uint16_t>(value));
}

static void OnInt16sAttributeResponse(void * context, int16_t value)
static void OnInt16sAttributeResponse(void * context, int64_t value)
{
ChipLogProgress(chipTool, "Int16s attribute Response: %" PRId16, value);
if (!chip::CanCastTo<int16_t>(value))
{
ChipLogError(chipTool, "WARN: value read (%" PRIx64 ") does not fits into int16", value);
}
ChipLogProgress(chipTool, "Int16s attribute Response: %" PRId16, static_cast<int16_t>(value));
}

private:
Expand Down
113 changes: 113 additions & 0 deletions examples/pump-app/pump-common/gen/CHIPClientCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,119 @@ bool IMDefaultResponseCallback(const chip::app::Command * commandObj, EmberAfSta
return true;
}

bool IMReadReportAttributesResponseCallback(const app::ReadClient * apReadClient, const app::ClusterInfo & aPath,
TLV::TLVReader * apData, uint8_t status)
{
ChipLogProgress(Zcl, "ReadAttributesResponse:");
ChipLogProgress(Zcl, " ClusterId: 0x%04x", aPath.mClusterId);

Callback::Cancelable * onSuccessCallback = nullptr;
Callback::Cancelable * onFailureCallback = nullptr;
NodeId sourceId = aPath.mNodeId;
// In CHIPClusters.cpp, we are using sequenceNumber as application identifier.
uint8_t sequenceNumber = static_cast<uint8_t>(apReadClient->GetAppIdentifier());
CHIP_ERROR err = gCallbacks.GetResponseCallback(sourceId, sequenceNumber, &onSuccessCallback, &onFailureCallback);

if (CHIP_NO_ERROR != err)
{
if (onSuccessCallback == nullptr)
{
ChipLogDetail(Zcl, "%s: Missing success callback", __FUNCTION__);
}

if (onFailureCallback == nullptr)
{
ChipLogDetail(Zcl, "%s: Missing failure callback", __FUNCTION__);
}

return true;
}

// struct readAttributeResponseRecord[]
uint16_t attributeId = aPath.mFieldId; // attribId
ChipLogProgress(Zcl, " attributeId: 0x%04x", attributeId);
LogStatus(status);

if (status == EMBER_ZCL_STATUS_SUCCESS && apData != nullptr)
{
chip::TLV::TLVType attributeType = apData->GetType();
ChipLogProgress(Zcl, " attributeType: 0x%02x", attributeType);

switch (attributeType)
{
case chip::TLV::kTLVType_SignedInteger: {
int64_t value;
apData->Get(value);
ChipLogProgress(Zcl, " value: %" PRId64, value);

Callback::Callback<Int64sAttributeCallback> * cb =
Callback::Callback<Int64sAttributeCallback>::FromCancelable(onSuccessCallback);
cb->mCall(cb->mContext, value);
break;
}
case chip::TLV::kTLVType_UnsignedInteger: {
uint64_t value;
apData->Get(value);
ChipLogProgress(Zcl, " value: %" PRIu64, value);

Callback::Callback<Int64uAttributeCallback> * cb =
Callback::Callback<Int64uAttributeCallback>::FromCancelable(onSuccessCallback);
cb->mCall(cb->mContext, value);
break;
}
case chip::TLV::kTLVType_Boolean: {
bool value;
apData->Get(value);
ChipLogProgress(Zcl, " value: %s", value ? "True" : "False");

Callback::Callback<Int64uAttributeCallback> * cb =
Callback::Callback<Int64uAttributeCallback>::FromCancelable(onSuccessCallback);
cb->mCall(cb->mContext, value);
break;
}

case chip::TLV::kTLVType_UTF8String:
case chip::TLV::kTLVType_ByteString: {
uint8_t length = apData->GetLength();
const uint8_t * data;
apData->GetDataPtr(data);
LogStringAttribute(data, length, attributeType == chip::TLV::kTLVType_UTF8String);
Callback::Callback<StringAttributeCallback> * cb =
Callback::Callback<StringAttributeCallback>::FromCancelable(onSuccessCallback);
cb->mCall(cb->mContext, chip::ByteSpan(data, length));
break;
}
case chip::TLV::kTLVType_Array:
case chip::TLV::kTLVType_List: {
// TODO: Support for complex types (arrays / structures).
switch (aPath.mClusterId)
{
}
break;
}
case chip::TLV::kTLVType_FloatingPointNumber:
case chip::TLV::kTLVType_Null:
case chip::TLV::kTLVType_Structure:
case chip::TLV::kTLVType_UnknownContainer:
case chip::TLV::kTLVType_NotSpecified: {
ChipLogError(Zcl, "attributeType 0x%02x is not yet supported", attributeType);
Callback::Callback<DefaultFailureCallback> * cb =
Callback::Callback<DefaultFailureCallback>::FromCancelable(onFailureCallback);
cb->mCall(cb->mContext, EMBER_ZCL_STATUS_INVALID_VALUE);
return true;
}
}
}
else
{
Callback::Callback<DefaultFailureCallback> * cb =
Callback::Callback<DefaultFailureCallback>::FromCancelable(onFailureCallback);
cb->mCall(cb->mContext, status);
}

return true;
}

bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * message, uint16_t messageLen)
{
ChipLogProgress(Zcl, "ReadAttributesResponse:");
Expand Down
15 changes: 9 additions & 6 deletions examples/pump-app/pump-common/gen/CHIPClientCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#pragma once

#include <app/Command.h>
#include <app/InteractionModelEngine.h>
#include <app/common/gen/af-structs.h>
#include <app/util/af-enums.h>
#include <inttypes.h>
Expand All @@ -29,17 +30,19 @@
// instead of IM status code.
// #6308 should handle IM error code on the application side, either modify this function or remove this.
bool IMDefaultResponseCallback(const chip::app::Command * commandObj, EmberAfStatus status);
bool IMReadReportAttributesResponseCallback(const chip::app::ReadClient * apReadClient, const chip::app::ClusterInfo & aPath,
chip::TLV::TLVReader * apData, uint8_t status);

// Global Response Callbacks
typedef void (*DefaultSuccessCallback)(void * context);
typedef void (*DefaultFailureCallback)(void * context, uint8_t status);
typedef void (*BooleanAttributeCallback)(void * context, bool value);
typedef void (*Int8uAttributeCallback)(void * context, uint8_t value);
typedef void (*Int8sAttributeCallback)(void * context, int8_t value);
typedef void (*Int16uAttributeCallback)(void * context, uint16_t value);
typedef void (*Int16sAttributeCallback)(void * context, int16_t value);
typedef void (*Int32uAttributeCallback)(void * context, uint32_t value);
typedef void (*Int32sAttributeCallback)(void * context, int32_t value);
typedef void (*Int8uAttributeCallback)(void * context, uint64_t value);
typedef void (*Int8sAttributeCallback)(void * context, int64_t value);
typedef void (*Int16uAttributeCallback)(void * context, uint64_t value);
typedef void (*Int16sAttributeCallback)(void * context, int64_t value);
typedef void (*Int32uAttributeCallback)(void * context, uint64_t value);
typedef void (*Int32sAttributeCallback)(void * context, int64_t value);
typedef void (*Int64uAttributeCallback)(void * context, uint64_t value);
typedef void (*Int64sAttributeCallback)(void * context, int64_t value);
typedef void (*StringAttributeCallback)(void * context, const chip::ByteSpan value);
Expand Down
Loading

0 comments on commit be29ca2

Please sign in to comment.