-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add log-source-app for diagnostic log cluster example (#12316)
- Loading branch information
Showing
25 changed files
with
5,456 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# | ||
# 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. | ||
|
||
import("//build_overrides/build.gni") | ||
|
||
# The location of the build configuration file. | ||
buildconfig = "${build_root}/config/BUILDCONFIG.gn" | ||
|
||
# CHIP uses angle bracket includes. | ||
check_system_includes = true | ||
|
||
default_args = { | ||
import("//args.gni") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# | ||
# 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. | ||
|
||
import("//build_overrides/build.gni") | ||
import("//build_overrides/chip.gni") | ||
|
||
executable("chip-log-source-app") { | ||
sources = [ "main.cpp" ] | ||
|
||
deps = [ | ||
"${chip_root}/examples/log-source-app/log-source-common", | ||
"${chip_root}/examples/platform/linux:app-main", | ||
"${chip_root}/src/app/server", | ||
"${chip_root}/src/lib", | ||
"${chip_root}/src/protocols/bdx", | ||
] | ||
|
||
cflags = [ "-Wconversion" ] | ||
|
||
output_dir = root_out_dir | ||
} | ||
|
||
group("linux") { | ||
deps = [ ":chip-log-source-app" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# log-source-app | ||
|
||
This is a reference application that implements an example of an diagnostic log | ||
cluster server. | ||
|
||
## Building | ||
|
||
Suggest doing the following: | ||
`scripts/examples/gn_build_example.sh examples/log-source-app/linux out/debug chip_config_network_layer_ble=false` | ||
|
||
## Usage | ||
|
||
`./log-source-app` | ||
|
||
## Current Features/Limitations | ||
|
||
### Features | ||
|
||
- Redirect logs into the internal buffer, send logs using diagnostic logs | ||
cluster. | ||
|
||
### Limitations: | ||
|
||
- BDX transfer is not implemented yet (TODO) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) 2020 Project CHIP Authors | ||
# | ||
# 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. | ||
|
||
import("//build_overrides/chip.gni") | ||
|
||
import("${chip_root}/config/standalone/args.gni") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../build_overrides |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* Copyright (c) 2021 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. | ||
*/ | ||
|
||
#include <platform/CHIPDeviceLayer.h> | ||
#include <platform/PlatformManager.h> | ||
|
||
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h> | ||
#include <app/server/Server.h> | ||
#include <app/util/util.h> | ||
#include <credentials/DeviceAttestationCredsProvider.h> | ||
#include <credentials/examples/DeviceAttestationCredsExample.h> | ||
#include <lib/core/CHIPError.h> | ||
#include <lib/support/CHIPArgParser.hpp> | ||
#include <lib/support/CHIPMem.h> | ||
#include <lib/support/logging/CHIPLogging.h> | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <unistd.h> | ||
|
||
using chip::BitFlags; | ||
using chip::ArgParser::HelpOptions; | ||
using chip::ArgParser::OptionDef; | ||
using chip::ArgParser::OptionSet; | ||
using chip::ArgParser::PrintArgError; | ||
using chip::Messaging::ExchangeManager; | ||
|
||
bool HandleOptions(const char * aProgram, OptionSet * aOptions, int aIdentifier, const char * aName, const char * aValue) | ||
{ | ||
// No option yet | ||
return true; | ||
} | ||
|
||
OptionDef cmdLineOptionsDef[] = { | ||
{}, | ||
}; | ||
|
||
OptionSet cmdLineOptions = { HandleOptions, cmdLineOptionsDef, "PROGRAM OPTIONS" }; | ||
|
||
HelpOptions helpOptions("log-source-app", "Usage: log-source-app [options]", "1.0"); | ||
|
||
OptionSet * allOptions[] = { &cmdLineOptions, &helpOptions, nullptr }; | ||
|
||
static constexpr size_t kMaxLogMessageLength = 512; | ||
|
||
DiagnosticLogsCommandHandler & GetLogProvider() | ||
{ | ||
static DiagnosticLogsCommandHandler LogProvider; | ||
return LogProvider; | ||
} | ||
|
||
void LoggingCallback(const char * module, uint8_t category, const char * msg, va_list args) | ||
{ | ||
// Print the log on console for debug | ||
va_list argsCopy; | ||
va_copy(argsCopy, args); | ||
chip::Logging::Platform::LogV(module, category, msg, argsCopy); | ||
|
||
// Feed the log entry into the internal circular buffer | ||
char buffer1[kMaxLogMessageLength]; | ||
char buffer2[kMaxLogMessageLength]; | ||
int s1 = vsnprintf(buffer1, sizeof(buffer1), msg, args); | ||
int s2 = snprintf(buffer2, sizeof(buffer2), "%s:%.*s", module, s1, buffer1); | ||
GetLogProvider().PushLog(chip::ByteSpan(reinterpret_cast<uint8_t *>(buffer2), s2)); | ||
} | ||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
if (chip::Platform::MemoryInit() != CHIP_NO_ERROR) | ||
{ | ||
fprintf(stderr, "FAILED to initialize memory\n"); | ||
return 1; | ||
} | ||
|
||
chip::Logging::SetLogRedirectCallback(&LoggingCallback); | ||
|
||
if (chip::DeviceLayer::PlatformMgr().InitChipStack() != CHIP_NO_ERROR) | ||
{ | ||
fprintf(stderr, "FAILED to initialize chip stack\n"); | ||
return 1; | ||
} | ||
|
||
if (!chip::ArgParser::ParseArgs(argv[0], argc, argv, allOptions)) | ||
{ | ||
return 1; | ||
} | ||
|
||
chip::DeviceLayer::ConfigurationMgr().LogDeviceConfig(); | ||
chip::Server::GetInstance().Init(); | ||
|
||
// Initialize device attestation config | ||
SetDeviceAttestationCredentialsProvider(chip::Credentials::Examples::GetExampleDACProvider()); | ||
|
||
chip::app::InteractionModelEngine::GetInstance()->RegisterCommandHandler(&GetLogProvider()); | ||
|
||
chip::DeviceLayer::PlatformMgr().RunEventLoop(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) 2021 Project CHIP Authors | ||
# | ||
# 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. | ||
|
||
import("//build_overrides/chip.gni") | ||
|
||
import("${chip_root}/src/app/chip_data_model.gni") | ||
|
||
config("config") { | ||
include_dirs = [ ".." ] | ||
} | ||
|
||
chip_data_model("log-source-common") { | ||
zap_file = "log-source-app.zap" | ||
|
||
zap_pregenerated_dir = | ||
"${chip_root}/zzz_generated/log-source-app/zap-generated" | ||
|
||
deps = [ "${chip_root}/src/protocols/bdx" ] | ||
|
||
is_server = true | ||
|
||
public_configs = [ ":config" ] | ||
} |
Oops, something went wrong.