[VOL-4069] Measure and read Rx optical power for an ONU
Reading Rx optical power requires triggering an RSSI measurement and tracking the RSSI Measurement Completed indication.
The raw value is converted to mW, and a dBm value is returned back.
A small test application (~40K) is bundled within the Debian package to help with debugging the optical power levels.
Change-Id: I20f304a9de0c47b94dfd7b1d8fdd52c56d6a2983
diff --git a/agent/src/core_utils.cc b/agent/src/core_utils.cc
index 0153078..e8060aa 100644
--- a/agent/src/core_utils.cc
+++ b/agent/src/core_utils.cc
@@ -1723,3 +1723,25 @@
return {buffer.str(), in_file.good()};
}
+
+bool save_to_txt_file(const std::string& file_name, const std::string& content) {
+ std::ofstream out_file;
+ out_file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
+
+ try {
+ out_file.open(file_name, std::ios::out | std::ios::trunc);
+
+ if (!out_file.is_open()) {
+ std::cerr << "error while opening file '" << file_name << "'\n";
+ return false;
+ }
+
+ out_file << content;
+ out_file.close();
+
+ return true;
+ } catch (const std::ofstream::failure& e) {
+ std::cerr << "exception while writing to file '" << file_name << "' | err: " << e.what() << '\n';
+ return false;
+ }
+}