Skip to content

Commit 3a1ba37

Browse files
committed
Add support for diagnostic logs server cluster and add the log provider delegate to all-clusters-app
- Add darwin code to download logs of differnt types and get the logs transferred via BDX
1 parent 836ceec commit 3a1ba37

28 files changed

+2189
-124
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.matter

+58
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,51 @@ server cluster NetworkCommissioning = 49 {
15221522
command access(invoke: administer) ReorderNetwork(ReorderNetworkRequest): NetworkConfigResponse = 8;
15231523
}
15241524

1525+
/** The cluster provides commands for retrieving unstructured diagnostic logs from a Node that may be used to aid in diagnostics. */
1526+
client cluster DiagnosticLogs = 50 {
1527+
enum IntentEnum : ENUM8 {
1528+
kEndUserSupport = 0;
1529+
kNetworkDiag = 1;
1530+
kCrashLogs = 2;
1531+
}
1532+
1533+
enum StatusEnum : ENUM8 {
1534+
kSuccess = 0;
1535+
kExhausted = 1;
1536+
kNoLogs = 2;
1537+
kBusy = 3;
1538+
kDenied = 4;
1539+
}
1540+
1541+
enum TransferProtocolEnum : ENUM8 {
1542+
kResponsePayload = 0;
1543+
kBDX = 1;
1544+
}
1545+
1546+
readonly attribute command_id generatedCommandList[] = 65528;
1547+
readonly attribute command_id acceptedCommandList[] = 65529;
1548+
readonly attribute event_id eventList[] = 65530;
1549+
readonly attribute attrib_id attributeList[] = 65531;
1550+
readonly attribute bitmap32 featureMap = 65532;
1551+
readonly attribute int16u clusterRevision = 65533;
1552+
1553+
request struct RetrieveLogsRequestRequest {
1554+
IntentEnum intent = 0;
1555+
TransferProtocolEnum requestedProtocol = 1;
1556+
optional char_string<32> transferFileDesignator = 2;
1557+
}
1558+
1559+
response struct RetrieveLogsResponse = 1 {
1560+
StatusEnum status = 0;
1561+
LONG_OCTET_STRING logContent = 1;
1562+
optional epoch_us UTCTimeStamp = 2;
1563+
optional systime_us timeSinceBoot = 3;
1564+
}
1565+
1566+
/** Retrieving diagnostic logs from a Node */
1567+
command RetrieveLogsRequest(RetrieveLogsRequestRequest): RetrieveLogsResponse = 0;
1568+
}
1569+
15251570
/** The cluster provides commands for retrieving unstructured diagnostic logs from a Node that may be used to aid in diagnostics. */
15261571
server cluster DiagnosticLogs = 50 {
15271572
enum IntentEnum : ENUM8 {
@@ -1556,6 +1601,13 @@ server cluster DiagnosticLogs = 50 {
15561601
optional char_string<32> transferFileDesignator = 2;
15571602
}
15581603

1604+
response struct RetrieveLogsResponse = 1 {
1605+
StatusEnum status = 0;
1606+
LONG_OCTET_STRING logContent = 1;
1607+
optional epoch_us UTCTimeStamp = 2;
1608+
optional systime_us timeSinceBoot = 3;
1609+
}
1610+
15591611
command RetrieveLogsRequest(RetrieveLogsRequestRequest): RetrieveLogsResponse = 0;
15601612
}
15611613

@@ -5671,6 +5723,7 @@ endpoint 0 {
56715723
device type ma_powersource = 17, version 1;
56725724

56735725
binding cluster OtaSoftwareUpdateProvider;
5726+
binding cluster DiagnosticLogs;
56745727

56755728
server cluster Identify {
56765729
ram attribute identifyTime default = 0x0000;
@@ -5885,10 +5938,15 @@ endpoint 0 {
58855938
}
58865939

58875940
server cluster DiagnosticLogs {
5941+
callback attribute generatedCommandList;
5942+
callback attribute acceptedCommandList;
5943+
callback attribute eventList;
5944+
callback attribute attributeList;
58885945
ram attribute featureMap default = 0;
58895946
ram attribute clusterRevision default = 1;
58905947

58915948
handle command RetrieveLogsRequest;
5949+
handle command RetrieveLogsResponse;
58925950
}
58935951

58945952
server cluster GeneralDiagnostics {

examples/all-clusters-app/all-clusters-common/all-clusters-app.zap

+144-6
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
}
1818
],
1919
"package": [
20-
{
21-
"pathRelativity": "relativeToZap",
22-
"path": "../../../src/app/zap-templates/app-templates.json",
23-
"type": "gen-templates-json",
24-
"version": "chip-v1"
25-
},
2620
{
2721
"pathRelativity": "relativeToZap",
2822
"path": "../../../src/app/zap-templates/zcl/zcl-with-test-extensions.json",
2923
"type": "zcl-properties",
3024
"category": "matter",
3125
"version": 1,
3226
"description": "Matter SDK ZCL data with some extensions"
27+
},
28+
{
29+
"pathRelativity": "relativeToZap",
30+
"path": "../../../src/app/zap-templates/app-templates.json",
31+
"type": "gen-templates-json",
32+
"version": "chip-v1"
3333
}
3434
],
3535
"endpointTypes": [
@@ -2628,6 +2628,66 @@
26282628
}
26292629
]
26302630
},
2631+
{
2632+
"name": "Diagnostic Logs",
2633+
"code": 50,
2634+
"mfgCode": null,
2635+
"define": "DIAGNOSTIC_LOGS_CLUSTER",
2636+
"side": "client",
2637+
"enabled": 1,
2638+
"commands": [
2639+
{
2640+
"name": "RetrieveLogsRequest",
2641+
"code": 0,
2642+
"mfgCode": null,
2643+
"source": "client",
2644+
"isIncoming": 0,
2645+
"isEnabled": 1
2646+
},
2647+
{
2648+
"name": "RetrieveLogsResponse",
2649+
"code": 1,
2650+
"mfgCode": null,
2651+
"source": "server",
2652+
"isIncoming": 1,
2653+
"isEnabled": 1
2654+
}
2655+
],
2656+
"attributes": [
2657+
{
2658+
"name": "FeatureMap",
2659+
"code": 65532,
2660+
"mfgCode": null,
2661+
"side": "client",
2662+
"type": "bitmap32",
2663+
"included": 1,
2664+
"storageOption": "RAM",
2665+
"singleton": 0,
2666+
"bounded": 0,
2667+
"defaultValue": "0",
2668+
"reportable": 1,
2669+
"minInterval": 1,
2670+
"maxInterval": 65534,
2671+
"reportableChange": 0
2672+
},
2673+
{
2674+
"name": "ClusterRevision",
2675+
"code": 65533,
2676+
"mfgCode": null,
2677+
"side": "client",
2678+
"type": "int16u",
2679+
"included": 1,
2680+
"storageOption": "RAM",
2681+
"singleton": 0,
2682+
"bounded": 0,
2683+
"defaultValue": "1",
2684+
"reportable": 1,
2685+
"minInterval": 1,
2686+
"maxInterval": 65534,
2687+
"reportableChange": 0
2688+
}
2689+
]
2690+
},
26312691
{
26322692
"name": "Diagnostic Logs",
26332693
"code": 50,
@@ -2643,9 +2703,81 @@
26432703
"source": "client",
26442704
"isIncoming": 1,
26452705
"isEnabled": 1
2706+
},
2707+
{
2708+
"name": "RetrieveLogsResponse",
2709+
"code": 1,
2710+
"mfgCode": null,
2711+
"source": "server",
2712+
"isIncoming": 0,
2713+
"isEnabled": 1
26462714
}
26472715
],
26482716
"attributes": [
2717+
{
2718+
"name": "GeneratedCommandList",
2719+
"code": 65528,
2720+
"mfgCode": null,
2721+
"side": "server",
2722+
"type": "array",
2723+
"included": 1,
2724+
"storageOption": "External",
2725+
"singleton": 0,
2726+
"bounded": 0,
2727+
"defaultValue": "",
2728+
"reportable": 1,
2729+
"minInterval": 1,
2730+
"maxInterval": 65534,
2731+
"reportableChange": 0
2732+
},
2733+
{
2734+
"name": "AcceptedCommandList",
2735+
"code": 65529,
2736+
"mfgCode": null,
2737+
"side": "server",
2738+
"type": "array",
2739+
"included": 1,
2740+
"storageOption": "External",
2741+
"singleton": 0,
2742+
"bounded": 0,
2743+
"defaultValue": "",
2744+
"reportable": 1,
2745+
"minInterval": 1,
2746+
"maxInterval": 65534,
2747+
"reportableChange": 0
2748+
},
2749+
{
2750+
"name": "EventList",
2751+
"code": 65530,
2752+
"mfgCode": null,
2753+
"side": "server",
2754+
"type": "array",
2755+
"included": 1,
2756+
"storageOption": "External",
2757+
"singleton": 0,
2758+
"bounded": 0,
2759+
"defaultValue": "",
2760+
"reportable": 1,
2761+
"minInterval": 1,
2762+
"maxInterval": 65534,
2763+
"reportableChange": 0
2764+
},
2765+
{
2766+
"name": "AttributeList",
2767+
"code": 65531,
2768+
"mfgCode": null,
2769+
"side": "server",
2770+
"type": "array",
2771+
"included": 1,
2772+
"storageOption": "External",
2773+
"singleton": 0,
2774+
"bounded": 0,
2775+
"defaultValue": "",
2776+
"reportable": 1,
2777+
"minInterval": 1,
2778+
"maxInterval": 65534,
2779+
"reportableChange": 0
2780+
},
26492781
{
26502782
"name": "FeatureMap",
26512783
"code": 65532,
@@ -6136,6 +6268,7 @@
61366268
"define": "FAULT_INJECTION_CLUSTER",
61376269
"side": "server",
61386270
"enabled": 1,
6271+
"apiMaturity": "internal",
61396272
"commands": [
61406273
{
61416274
"name": "FailAtFault",
@@ -6641,6 +6774,7 @@
66416774
"define": "SCENES_CLUSTER",
66426775
"side": "server",
66436776
"enabled": 1,
6777+
"apiMaturity": "provisional",
66446778
"commands": [
66456779
{
66466780
"name": "AddScene",
@@ -13698,6 +13832,7 @@
1369813832
"define": "FAN_CONTROL_CLUSTER",
1369913833
"side": "server",
1370013834
"enabled": 1,
13835+
"apiMaturity": "provisional",
1370113836
"commands": [
1370213837
{
1370313838
"name": "Step",
@@ -15060,6 +15195,7 @@
1506015195
"define": "BALLAST_CONFIGURATION_CLUSTER",
1506115196
"side": "server",
1506215197
"enabled": 1,
15198+
"apiMaturity": "provisional",
1506315199
"attributes": [
1506415200
{
1506515201
"name": "PhysicalMinLevel",
@@ -18982,6 +19118,7 @@
1898219118
"define": "UNIT_TESTING_CLUSTER",
1898319119
"side": "server",
1898419120
"enabled": 1,
19121+
"apiMaturity": "internal",
1898519122
"commands": [
1898619123
{
1898719124
"name": "Test",
@@ -20943,6 +21080,7 @@
2094321080
"define": "SCENES_CLUSTER",
2094421081
"side": "server",
2094521082
"enabled": 1,
21083+
"apiMaturity": "provisional",
2094621084
"commands": [
2094721085
{
2094821086
"name": "AddScene",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h>
22+
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>
23+
24+
#include <fstream>
25+
26+
namespace chip {
27+
namespace app {
28+
namespace Clusters {
29+
namespace DiagnosticLogs {
30+
31+
/**
32+
* The application delegate to statically define the options.
33+
*/
34+
35+
class LogProvider : public LogProviderDelegate
36+
{
37+
static LogSessionHandle sLogSessionHandle;
38+
static LogProvider sInstance;
39+
40+
public:
41+
42+
LogSessionHandle StartLogCollection(IntentEnum logType);
43+
44+
uint64_t GetNextChunk(LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF);
45+
46+
void EndLogCollection(LogSessionHandle logSessionHandle);
47+
48+
uint64_t GetTotalNumberOfBytesConsumed(LogSessionHandle logSessionHandle);
49+
50+
void SetEndUserSupportLogFileDesignator(const char * logFileName);
51+
52+
void SetNetworkDiagnosticsLogFileDesignator(const char * logFileName);
53+
54+
void SetCrashLogFileDesignator(const char * logFileName);
55+
56+
LogProvider() = default;
57+
58+
~LogProvider() = default;
59+
60+
static inline LogProvider & getLogProvider() { return sInstance; }
61+
62+
private:
63+
64+
const char * GetLogFilePath(IntentEnum logType);
65+
66+
char mEndUserSupportLogFileDesignator[kLogFileDesignatorMaxLen];
67+
char mNetworkDiagnosticsLogFileDesignator[kLogFileDesignatorMaxLen];
68+
char mCrashLogFileDesignator[kLogFileDesignatorMaxLen];
69+
70+
//std::ifstream mFileStream;
71+
72+
LogSessionHandle mLogSessionHandle;
73+
74+
uint64_t mTotalNumberOfBytesConsumed;
75+
};
76+
77+
} // namespace DiagnosticLogs
78+
} // namespace Clusters
79+
} // namespace app
80+
} // namespace chip

0 commit comments

Comments
 (0)