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

adding option for output file instead of console #8410

Merged
merged 2 commits into from
Feb 23, 2021
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
1 change: 1 addition & 0 deletions tools/fw-logger/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ In order to run this, ensure that your camera is streaming. This can be done usi
|`-l <xml-path>`|xml file ful path, used to parse the logs||
|`-p <polling-interval-in-ms>`|logs polling interval (in milliseconds)| 100 | 25-300|
|`-f`|collect flash logs instead of firmware logs||
|`-o <file-path>`|output file path||

## Usage
After installing `librealsense` run `rs-fw-logger` to launch the tool.
Expand Down
17 changes: 12 additions & 5 deletions tools/fw-logger/rs-fw-logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,28 @@ int main(int argc, char* argv[])
int default_polling_interval_ms = 100;
CmdLine cmd("librealsense rs-fw-logger example tool", ' ', RS2_API_VERSION_STR);
ValueArg<string> xml_arg("l", "load", "Full file path of HW Logger Events XML file", false, "", "Load HW Logger Events XML file");
ValueArg<string> out_arg("o", "out", "Full file path of output file", false, "", "Print Fw logs to output file");
ValueArg<int> polling_interval_arg("p", "polling_interval", "Time Interval between each log messages polling (in milliseconds)", false, default_polling_interval_ms, "");
SwitchArg flash_logs_arg("f", "flash", "Flash Logs Request", false);
cmd.add(xml_arg);
cmd.add(xml_arg);
cmd.add(out_arg);
cmd.add(polling_interval_arg);
cmd.add(flash_logs_arg);
cmd.parse(argc, argv);

log_to_file(RS2_LOG_SEVERITY_WARN, "librealsense.log");

auto use_xml_file = false;
auto output_file_path = out_arg.getValue();
std::ofstream output_file(output_file_path);
// write to file if it is open, else write to console
std::ostream& out = (!output_file.is_open() ? std::cout : output_file);

auto xml_full_file_path = xml_arg.getValue();
auto polling_interval_ms = polling_interval_arg.getValue();
if (polling_interval_ms < 25 || polling_interval_ms > 300)
{
std::cout << "Polling interval time provided: " << polling_interval_ms << "ms, is not in the valid range [25,300]. Default value " << default_polling_interval_ms << "ms is used." << std::endl;
out << "Polling interval time provided: " << polling_interval_ms << "ms, is not in the valid range [25,300]. Default value " << default_polling_interval_ms << "ms is used." << std::endl;
polling_interval_ms = default_polling_interval_ms;
}

Expand All @@ -78,9 +85,9 @@ int main(int argc, char* argv[])
{
try
{
cout << "\nWaiting for RealSense device to connect...\n";
out << "\nWaiting for RealSense device to connect...\n";
auto dev = hub.wait_for_device();
cout << "RealSense device was connected...\n";
out << "RealSense device was connected...\n";

setvbuf(stdout, NULL, _IONBF, 0); // unbuffering stdout

Expand Down Expand Up @@ -147,7 +154,7 @@ int main(int argc, char* argv[])
fw_log_lines.push_back(sstr.str());
}
for (auto& line : fw_log_lines)
cout << line << endl;
out << line << endl;
}
else
{
Expand Down