Skip to content

Commit 4079370

Browse files
kghostpull[bot]
authored andcommitted
Add log-source-app for diagnostic log cluster example (#12316)
1 parent 7a5ec79 commit 4079370

25 files changed

+5456
-5
lines changed

examples/log-source-app/linux/.gn

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright (c) 2020 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
17+
# The location of the build configuration file.
18+
buildconfig = "${build_root}/config/BUILDCONFIG.gn"
19+
20+
# CHIP uses angle bracket includes.
21+
check_system_includes = true
22+
23+
default_args = {
24+
import("//args.gni")
25+
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) 2020 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/build.gni")
16+
import("//build_overrides/chip.gni")
17+
18+
executable("chip-log-source-app") {
19+
sources = [ "main.cpp" ]
20+
21+
deps = [
22+
"${chip_root}/examples/log-source-app/log-source-common",
23+
"${chip_root}/examples/platform/linux:app-main",
24+
"${chip_root}/src/app/server",
25+
"${chip_root}/src/lib",
26+
"${chip_root}/src/protocols/bdx",
27+
]
28+
29+
cflags = [ "-Wconversion" ]
30+
31+
output_dir = root_out_dir
32+
}
33+
34+
group("linux") {
35+
deps = [ ":chip-log-source-app" ]
36+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# log-source-app
2+
3+
This is a reference application that implements an example of an diagnostic log
4+
cluster server.
5+
6+
## Building
7+
8+
Suggest doing the following:
9+
`scripts/examples/gn_build_example.sh examples/log-source-app/linux out/debug chip_config_network_layer_ble=false`
10+
11+
## Usage
12+
13+
`./log-source-app`
14+
15+
## Current Features/Limitations
16+
17+
### Features
18+
19+
- Redirect logs into the internal buffer, send logs using diagnostic logs
20+
cluster.
21+
22+
### Limitations:
23+
24+
- BDX transfer is not implemented yet (TODO)
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright (c) 2020 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
17+
import("${chip_root}/config/standalone/args.gni")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../build_overrides
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright (c) 2021 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <platform/CHIPDeviceLayer.h>
19+
#include <platform/PlatformManager.h>
20+
21+
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>
22+
#include <app/server/Server.h>
23+
#include <app/util/util.h>
24+
#include <credentials/DeviceAttestationCredsProvider.h>
25+
#include <credentials/examples/DeviceAttestationCredsExample.h>
26+
#include <lib/core/CHIPError.h>
27+
#include <lib/support/CHIPArgParser.hpp>
28+
#include <lib/support/CHIPMem.h>
29+
#include <lib/support/logging/CHIPLogging.h>
30+
31+
#include <fstream>
32+
#include <iostream>
33+
#include <unistd.h>
34+
35+
using chip::BitFlags;
36+
using chip::ArgParser::HelpOptions;
37+
using chip::ArgParser::OptionDef;
38+
using chip::ArgParser::OptionSet;
39+
using chip::ArgParser::PrintArgError;
40+
using chip::Messaging::ExchangeManager;
41+
42+
bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue)
43+
{
44+
// No option yet
45+
return true;
46+
}
47+
48+
OptionDef cmdLineOptionsDef[] = {
49+
{},
50+
};
51+
52+
OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" };
53+
54+
HelpOptions helpOptions("log-source-app", "Usage: log-source-app [options]", "1.0");
55+
56+
OptionSet * allOptions[] = { &cmdLineOptions, &helpOptions, nullptr };
57+
58+
static constexpr size_t kMaxLogMessageLength = 512;
59+
60+
DiagnosticLogsCommandHandler & GetLogProvider()
61+
{
62+
static DiagnosticLogsCommandHandler LogProvider;
63+
return LogProvider;
64+
}
65+
66+
void LoggingCallback(const char * module, uint8_t category, const char * msg, va_list args)
67+
{
68+
// Print the log on console for debug
69+
va_list argsCopy;
70+
va_copy(argsCopy, args);
71+
chip::Logging::Platform::LogV(module, category, msg, argsCopy);
72+
73+
// Feed the log entry into the internal circular buffer
74+
char buffer1[kMaxLogMessageLength];
75+
char buffer2[kMaxLogMessageLength];
76+
int s1 = vsnprintf(buffer1, sizeof(buffer1), msg, args);
77+
int s2 = snprintf(buffer2, sizeof(buffer2), "%s:%.*s", module, s1, buffer1);
78+
GetLogProvider().PushLog(chip::ByteSpan(reinterpret_cast<uint8_t *>(buffer2), s2));
79+
}
80+
81+
int main(int argc, char * argv[])
82+
{
83+
if (chip::Platform::MemoryInit() != CHIP_NO_ERROR)
84+
{
85+
fprintf(stderr, "FAILED to initialize memory\n");
86+
return 1;
87+
}
88+
89+
chip::Logging::SetLogRedirectCallback(&LoggingCallback);
90+
91+
if (chip::DeviceLayer::PlatformMgr().InitChipStack() != CHIP_NO_ERROR)
92+
{
93+
fprintf(stderr, "FAILED to initialize chip stack\n");
94+
return 1;
95+
}
96+
97+
if (!chip::ArgParser::ParseArgs(argv[0], argc, argv, allOptions))
98+
{
99+
return 1;
100+
}
101+
102+
chip::DeviceLayer::ConfigurationMgr().LogDeviceConfig();
103+
chip::Server::GetInstance().Init();
104+
105+
// Initialize device attestation config
106+
SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider());
107+
108+
chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(&GetLogProvider());
109+
110+
chip::DeviceLayer::PlatformMgr().RunEventLoop();
111+
112+
return 0;
113+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright (c) 2021 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import("//build_overrides/chip.gni")
16+
17+
import("${chip_root}/src/app/chip_data_model.gni")
18+
19+
config("config") {
20+
include_dirs = [ ".." ]
21+
}
22+
23+
chip_data_model("log-source-common") {
24+
zap_file = "log-source-app.zap"
25+
26+
zap_pregenerated_dir =
27+
"${chip_root}/zzz_generated/log-source-app/zap-generated"
28+
29+
deps = [ "${chip_root}/src/protocols/bdx" ]
30+
31+
is_server = true
32+
33+
public_configs = [ ":config" ]
34+
}

0 commit comments

Comments
 (0)