Skip to content

Commit

Permalink
Add support for diagnostic logs server cluster and add the log provid…
Browse files Browse the repository at this point in the history
…er delegate to all-clusters-app

- Add darwin code to download logs of differnt types and get the logs transferred via BDX
  • Loading branch information
nivi-apple committed Oct 25, 2023
1 parent 836ceec commit 6faf371
Show file tree
Hide file tree
Showing 28 changed files with 2,194 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1522,6 +1522,51 @@ server cluster NetworkCommissioning = 49 {
command access(invoke: administer) ReorderNetwork(ReorderNetworkRequest): NetworkConfigResponse = 8;
}

/** The cluster provides commands for retrieving unstructured diagnostic logs from a Node that may be used to aid in diagnostics. */
client cluster DiagnosticLogs = 50 {
enum IntentEnum : ENUM8 {
kEndUserSupport = 0;
kNetworkDiag = 1;
kCrashLogs = 2;
}

enum StatusEnum : ENUM8 {
kSuccess = 0;
kExhausted = 1;
kNoLogs = 2;
kBusy = 3;
kDenied = 4;
}

enum TransferProtocolEnum : ENUM8 {
kResponsePayload = 0;
kBDX = 1;
}

readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct RetrieveLogsRequestRequest {
IntentEnum intent = 0;
TransferProtocolEnum requestedProtocol = 1;
optional char_string<32> transferFileDesignator = 2;
}

response struct RetrieveLogsResponse = 1 {
StatusEnum status = 0;
LONG_OCTET_STRING logContent = 1;
optional epoch_us UTCTimeStamp = 2;
optional systime_us timeSinceBoot = 3;
}

/** Retrieving diagnostic logs from a Node */
command RetrieveLogsRequest(RetrieveLogsRequestRequest): RetrieveLogsResponse = 0;
}

/** The cluster provides commands for retrieving unstructured diagnostic logs from a Node that may be used to aid in diagnostics. */
server cluster DiagnosticLogs = 50 {
enum IntentEnum : ENUM8 {
Expand Down Expand Up @@ -1556,6 +1601,13 @@ server cluster DiagnosticLogs = 50 {
optional char_string<32> transferFileDesignator = 2;
}

response struct RetrieveLogsResponse = 1 {
StatusEnum status = 0;
LONG_OCTET_STRING logContent = 1;
optional epoch_us UTCTimeStamp = 2;
optional systime_us timeSinceBoot = 3;
}

command RetrieveLogsRequest(RetrieveLogsRequestRequest): RetrieveLogsResponse = 0;
}

Expand Down Expand Up @@ -5671,6 +5723,7 @@ endpoint 0 {
device type ma_powersource = 17, version 1;

binding cluster OtaSoftwareUpdateProvider;
binding cluster DiagnosticLogs;

server cluster Identify {
ram attribute identifyTime default = 0x0000;
Expand Down Expand Up @@ -5885,10 +5938,15 @@ endpoint 0 {
}

server cluster DiagnosticLogs {
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0;
ram attribute clusterRevision default = 1;

handle command RetrieveLogsRequest;
handle command RetrieveLogsResponse;
}

server cluster GeneralDiagnostics {
Expand Down
150 changes: 144 additions & 6 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
}
],
"package": [
{
"pathRelativity": "relativeToZap",
"path": "../../../src/app/zap-templates/app-templates.json",
"type": "gen-templates-json",
"version": "chip-v1"
},
{
"pathRelativity": "relativeToZap",
"path": "../../../src/app/zap-templates/zcl/zcl-with-test-extensions.json",
"type": "zcl-properties",
"category": "matter",
"version": 1,
"description": "Matter SDK ZCL data with some extensions"
},
{
"pathRelativity": "relativeToZap",
"path": "../../../src/app/zap-templates/app-templates.json",
"type": "gen-templates-json",
"version": "chip-v1"
}
],
"endpointTypes": [
Expand Down Expand Up @@ -2628,6 +2628,66 @@
}
]
},
{
"name": "Diagnostic Logs",
"code": 50,
"mfgCode": null,
"define": "DIAGNOSTIC_LOGS_CLUSTER",
"side": "client",
"enabled": 1,
"commands": [
{
"name": "RetrieveLogsRequest",
"code": 0,
"mfgCode": null,
"source": "client",
"isIncoming": 0,
"isEnabled": 1
},
{
"name": "RetrieveLogsResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"isIncoming": 1,
"isEnabled": 1
}
],
"attributes": [
{
"name": "FeatureMap",
"code": 65532,
"mfgCode": null,
"side": "client",
"type": "bitmap32",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "client",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
}
]
},
{
"name": "Diagnostic Logs",
"code": 50,
Expand All @@ -2643,9 +2703,81 @@
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "RetrieveLogsResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
}
],
"attributes": [
{
"name": "GeneratedCommandList",
"code": 65528,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AcceptedCommandList",
"code": 65529,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "EventList",
"code": 65530,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AttributeList",
"code": 65531,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "FeatureMap",
"code": 65532,
Expand Down Expand Up @@ -6136,6 +6268,7 @@
"define": "FAULT_INJECTION_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "internal",
"commands": [
{
"name": "FailAtFault",
Expand Down Expand Up @@ -6641,6 +6774,7 @@
"define": "SCENES_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "provisional",
"commands": [
{
"name": "AddScene",
Expand Down Expand Up @@ -13698,6 +13832,7 @@
"define": "FAN_CONTROL_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "provisional",
"commands": [
{
"name": "Step",
Expand Down Expand Up @@ -15060,6 +15195,7 @@
"define": "BALLAST_CONFIGURATION_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "provisional",
"attributes": [
{
"name": "PhysicalMinLevel",
Expand Down Expand Up @@ -18982,6 +19118,7 @@
"define": "UNIT_TESTING_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "internal",
"commands": [
{
"name": "Test",
Expand Down Expand Up @@ -20943,6 +21080,7 @@
"define": "SCENES_CLUSTER",
"side": "server",
"enabled": 1,
"apiMaturity": "provisional",
"commands": [
{
"name": "AddScene",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* 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.
*/

#pragma once

#include <app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h>
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>

#include <fstream>

namespace chip {
namespace app {
namespace Clusters {
namespace DiagnosticLogs {

/**
* The application delegate to statically define the options.
*/

class LogProvider : public LogProviderDelegate
{
static LogSessionHandle sLogSessionHandle;
static LogProvider sInstance;

public:
LogSessionHandle StartLogCollection(IntentEnum logType);

uint64_t GetNextChunk(LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF);

void EndLogCollection(LogSessionHandle logSessionHandle);

uint64_t GetTotalNumberOfBytesConsumed(LogSessionHandle logSessionHandle);

void SetEndUserSupportLogFileDesignator(const char * logFileName);

void SetNetworkDiagnosticsLogFileDesignator(const char * logFileName);

void SetCrashLogFileDesignator(const char * logFileName);

LogProvider() = default;

~LogProvider() = default;

static inline LogProvider & getLogProvider() { return sInstance; }

private:
const char * GetLogFilePath(IntentEnum logType);

char mEndUserSupportLogFileDesignator[kLogFileDesignatorMaxLen];
char mNetworkDiagnosticsLogFileDesignator[kLogFileDesignatorMaxLen];
char mCrashLogFileDesignator[kLogFileDesignatorMaxLen];

// std::ifstream mFileStream;

LogSessionHandle mLogSessionHandle;

uint64_t mTotalNumberOfBytesConsumed;
};

} // namespace DiagnosticLogs
} // namespace Clusters
} // namespace app
} // namespace chip
Loading

0 comments on commit 6faf371

Please sign in to comment.