Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add darwin test for general diagnostics cluster, and fix incorrect reinterpret_cast that got added #6804

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ typedef struct _NeighborTable
// Struct for NetworkInterfaceType
typedef struct _NetworkInterfaceType
{
uint8_t * Name;
chip::ByteSpan Name;
uint8_t FabricConnected;
uint8_t OffPremiseServicesReachableIPv4;
uint8_t OffPremiseServicesReachableIPv6;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
entryOffset = static_cast<uint16_t>(entryOffset + ((index - 1) * entryLength));
// Struct _NetworkInterfaceType
_NetworkInterfaceType * entry = reinterpret_cast<_NetworkInterfaceType *>(write ? src : dest);
chip::ByteSpan * NameSpan = reinterpret_cast<chip::ByteSpan *>(&entry->Name); // CHAR_STRING
chip::ByteSpan * NameSpan = &entry->Name; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, NameSpan) : ReadByteSpan(src + entryOffset, 34, NameSpan)))
{
Expand Down Expand Up @@ -219,8 +219,8 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->GroupKeyIndex, write ? (uint8_t *) &entry->GroupKeyIndex : src, write,
&entryOffset, sizeof(entry->GroupKeyIndex)); // INT16U
chip::ByteSpan * GroupKeyRootSpan = reinterpret_cast<chip::ByteSpan *>(&entry->GroupKeyRoot); // OCTET_STRING
&entryOffset, sizeof(entry->GroupKeyIndex)); // INT16U
chip::ByteSpan * GroupKeyRootSpan = &entry->GroupKeyRoot; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 18, GroupKeyRootSpan)
: ReadByteSpan(src + entryOffset, 18, GroupKeyRootSpan)))
Expand Down Expand Up @@ -318,8 +318,8 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
// Struct _TestListStructOctet
_TestListStructOctet * entry = reinterpret_cast<_TestListStructOctet *>(write ? src : dest);
copyListMember(write ? dest : (uint8_t *) &entry->fabricIndex, write ? (uint8_t *) &entry->fabricIndex : src, write,
&entryOffset, sizeof(entry->fabricIndex)); // INT64U
chip::ByteSpan * operationalCertSpan = reinterpret_cast<chip::ByteSpan *>(&entry->operationalCert); // OCTET_STRING
&entryOffset, sizeof(entry->fabricIndex)); // INT64U
chip::ByteSpan * operationalCertSpan = &entry->operationalCert; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, operationalCertSpan)
: ReadByteSpan(src + entryOffset, 34, operationalCertSpan)))
Expand Down
2 changes: 1 addition & 1 deletion examples/bridge-app/bridge-common/gen/af-structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ typedef struct _NeighborTable
// Struct for NetworkInterfaceType
typedef struct _NetworkInterfaceType
{
uint8_t * Name;
chip::ByteSpan Name;
uint8_t FabricConnected;
uint8_t OffPremiseServicesReachableIPv4;
uint8_t OffPremiseServicesReachableIPv6;
Expand Down
2 changes: 1 addition & 1 deletion examples/bridge-app/bridge-common/gen/attribute-size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
entryOffset = static_cast<uint16_t>(entryOffset + ((index - 1) * entryLength));
// Struct _NetworkInterfaceType
_NetworkInterfaceType * entry = reinterpret_cast<_NetworkInterfaceType *>(write ? src : dest);
chip::ByteSpan * NameSpan = reinterpret_cast<chip::ByteSpan *>(&entry->Name); // CHAR_STRING
chip::ByteSpan * NameSpan = &entry->Name; // OCTET_STRING
if (CHIP_NO_ERROR !=
(write ? WriteByteSpan(dest + entryOffset, 34, NameSpan) : ReadByteSpan(src + entryOffset, 34, NameSpan)))
{
Expand Down
82 changes: 82 additions & 0 deletions examples/chip-tool/chip-tool.zap
Original file line number Diff line number Diff line change
Expand Up @@ -2462,6 +2462,88 @@
}
]
},
{
"name": "General Diagnostics",
"code": 51,
"mfgCode": null,
"define": "GENERAL_DIAGNOSTICS_CLUSTER",
"side": "client",
"enabled": 1,
"commands": [],
"attributes": [
{
"name": "cluster revision",
"code": 65533,
"mfgCode": null,
"side": "client",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0001",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
}
]
},
{
"name": "General Diagnostics",
"code": 51,
"mfgCode": null,
"define": "GENERAL_DIAGNOSTICS_CLUSTER",
"side": "server",
"enabled": 0,
"commands": [],
"attributes": [
{
"name": "NetworkInterfaces",
"code": 0,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "RebootCount",
"code": 1,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0000",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "cluster revision",
"code": 65533,
"mfgCode": null,
"side": "server",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0001",
"reportable": 0,
"minInterval": 0,
"maxInterval": 65344,
"reportableChange": 0
}
]
},
{
"name": "Switch",
"code": 59,
Expand Down
180 changes: 180 additions & 0 deletions examples/chip-tool/commands/clusters/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,26 @@ static void OnDescriptorPartsListListAttributeResponse(void * context, uint16_t
command->SetCommandExitStatus(true);
}

static void OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse(void * context, uint16_t count,
_NetworkInterfaceType * entries)
{
ChipLogProgress(chipTool, "OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse: %lu entries", count);

for (uint16_t i = 0; i < count; i++)
{
ChipLogProgress(chipTool, "NetworkInterfaceType[%lu]:", i);
ChipLogProgress(chipTool, " Name: %s", entries[i].Name);
ChipLogProgress(chipTool, " FabricConnected: %" PRIu8 "", entries[i].FabricConnected);
ChipLogProgress(chipTool, " OffPremiseServicesReachableIPv4: %" PRIu8 "", entries[i].OffPremiseServicesReachableIPv4);
ChipLogProgress(chipTool, " OffPremiseServicesReachableIPv6: %" PRIu8 "", entries[i].OffPremiseServicesReachableIPv6);
ChipLogProgress(chipTool, " HardwareAddress: %" PRIu64 "", entries[i].HardwareAddress);
ChipLogProgress(chipTool, " Type: %" PRIu8 "", entries[i].Type);
}

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

static void OnGroupKeyManagementGroupsListAttributeResponse(void * context, uint16_t count, _GroupState * entries)
{
ChipLogProgress(chipTool, "OnGroupKeyManagementGroupsListAttributeResponse: %lu entries", count);
Expand Down Expand Up @@ -820,6 +840,7 @@ static void OnTestClusterListStructOctetStringListAttributeResponse(void * conte
| Descriptor | 0x001D |
| DoorLock | 0x0101 |
| GeneralCommissioning | 0x0030 |
| GeneralDiagnostics | 0x0033 |
| GroupKeyManagement | 0xF004 |
| Groups | 0x0004 |
| Identify | 0x0003 |
Expand Down Expand Up @@ -854,6 +875,7 @@ constexpr chip::ClusterId kContentLaunchClusterId = 0x050A;
constexpr chip::ClusterId kDescriptorClusterId = 0x001D;
constexpr chip::ClusterId kDoorLockClusterId = 0x0101;
constexpr chip::ClusterId kGeneralCommissioningClusterId = 0x0030;
constexpr chip::ClusterId kGeneralDiagnosticsClusterId = 0x0033;
constexpr chip::ClusterId kGroupKeyManagementClusterId = 0xF004;
constexpr chip::ClusterId kGroupsClusterId = 0x0004;
constexpr chip::ClusterId kIdentifyClusterId = 0x0003;
Expand Down Expand Up @@ -7815,6 +7837,150 @@ class ReadGeneralCommissioningClusterRevision : public ModelCommand
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

/*----------------------------------------------------------------------------*\
| Cluster GeneralDiagnostics | 0x0033 |
|------------------------------------------------------------------------------|
| Commands: | |
|------------------------------------------------------------------------------|
| Attributes: | |
| * NetworkInterfaces | 0x0000 |
| * RebootCount | 0x0001 |
| * ClusterRevision | 0xFFFD |
\*----------------------------------------------------------------------------*/

/*
* Discover Attributes
*/
class DiscoverGeneralDiagnosticsAttributes : public ModelCommand
{
public:
DiscoverGeneralDiagnosticsAttributes() : ModelCommand("discover") { ModelCommand::AddArguments(); }

~DiscoverGeneralDiagnosticsAttributes()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster (0x0000) command (0x0C) on endpoint %" PRIu16, endpointId);

chip::Controller::GeneralDiagnosticsCluster cluster;
cluster.Associate(device, endpointId);
return cluster.DiscoverAttributes(onSuccessCallback->Cancel(), onFailureCallback->Cancel());
}

private:
chip::Callback::Callback<DefaultSuccessCallback> * onSuccessCallback =
new chip::Callback::Callback<DefaultSuccessCallback>(OnDefaultSuccessResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

/*
* Attribute NetworkInterfaces
*/
class ReadGeneralDiagnosticsNetworkInterfaces : public ModelCommand
{
public:
ReadGeneralDiagnosticsNetworkInterfaces() : ModelCommand("read")
{
AddArgument("attr-name", "network-interfaces");
ModelCommand::AddArguments();
}

~ReadGeneralDiagnosticsNetworkInterfaces()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster (0x0033) command (0x00) on endpoint %" PRIu16, endpointId);

chip::Controller::GeneralDiagnosticsCluster cluster;
cluster.Associate(device, endpointId);
return cluster.ReadAttributeNetworkInterfaces(onSuccessCallback->Cancel(), onFailureCallback->Cancel());
}

private:
chip::Callback::Callback<GeneralDiagnosticsNetworkInterfacesListAttributeCallback> * onSuccessCallback =
new chip::Callback::Callback<GeneralDiagnosticsNetworkInterfacesListAttributeCallback>(
OnGeneralDiagnosticsNetworkInterfacesListAttributeResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

/*
* Attribute RebootCount
*/
class ReadGeneralDiagnosticsRebootCount : public ModelCommand
{
public:
ReadGeneralDiagnosticsRebootCount() : ModelCommand("read")
{
AddArgument("attr-name", "reboot-count");
ModelCommand::AddArguments();
}

~ReadGeneralDiagnosticsRebootCount()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster (0x0033) command (0x00) on endpoint %" PRIu16, endpointId);

chip::Controller::GeneralDiagnosticsCluster cluster;
cluster.Associate(device, endpointId);
return cluster.ReadAttributeRebootCount(onSuccessCallback->Cancel(), onFailureCallback->Cancel());
}

private:
chip::Callback::Callback<Int16uAttributeCallback> * onSuccessCallback =
new chip::Callback::Callback<Int16uAttributeCallback>(OnInt16uAttributeResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

/*
* Attribute ClusterRevision
*/
class ReadGeneralDiagnosticsClusterRevision : public ModelCommand
{
public:
ReadGeneralDiagnosticsClusterRevision() : ModelCommand("read")
{
AddArgument("attr-name", "cluster-revision");
ModelCommand::AddArguments();
}

~ReadGeneralDiagnosticsClusterRevision()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
{
ChipLogProgress(chipTool, "Sending cluster (0x0033) command (0x00) on endpoint %" PRIu16, endpointId);

chip::Controller::GeneralDiagnosticsCluster cluster;
cluster.Associate(device, endpointId);
return cluster.ReadAttributeClusterRevision(onSuccessCallback->Cancel(), onFailureCallback->Cancel());
}

private:
chip::Callback::Callback<Int16uAttributeCallback> * onSuccessCallback =
new chip::Callback::Callback<Int16uAttributeCallback>(OnInt16uAttributeResponse, this);
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback =
new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
};

/*----------------------------------------------------------------------------*\
| Cluster GroupKeyManagement | 0xF004 |
|------------------------------------------------------------------------------|
Expand Down Expand Up @@ -14895,6 +15061,19 @@ void registerClusterGeneralCommissioning(Commands & commands)

commands.Register(clusterName, clusterCommands);
}
void registerClusterGeneralDiagnostics(Commands & commands)
{
const char * clusterName = "GeneralDiagnostics";

commands_list clusterCommands = {
make_unique<DiscoverGeneralDiagnosticsAttributes>(),
make_unique<ReadGeneralDiagnosticsNetworkInterfaces>(),
make_unique<ReadGeneralDiagnosticsRebootCount>(),
make_unique<ReadGeneralDiagnosticsClusterRevision>(),
};

commands.Register(clusterName, clusterCommands);
}
void registerClusterGroupKeyManagement(Commands & commands)
{
const char * clusterName = "GroupKeyManagement";
Expand Down Expand Up @@ -15247,6 +15426,7 @@ void registerClusters(Commands & commands)
registerClusterDescriptor(commands);
registerClusterDoorLock(commands);
registerClusterGeneralCommissioning(commands);
registerClusterGeneralDiagnostics(commands);
registerClusterGroupKeyManagement(commands);
registerClusterGroups(commands);
registerClusterIdentify(commands);
Expand Down
Loading