diff options
author | Roger Fang <rogerfang@google.com> | 2022-11-23 15:09:40 +0800 |
---|---|---|
committer | Roger Fang <rogerfang@google.com> | 2022-11-23 17:34:24 +0800 |
commit | 2ce0374629eb517f27f67a3b925717cd880758d3 (patch) | |
tree | 32f4f31b97cec451e4d7f15df54d8b5394d3f3f0 | |
parent | 09c465d696b21c6885be12053ee3721d28919e20 (diff) |
pixelstats: support variant speaker numbers up to 4.
Some products have the speaker numbers more than two.
To cover atom report stats of VendorSpeakerStatsReported.
Bug: 248451580
Test: manually tested passed and logcat verified
Change-Id: Ia12b873663bd000db276e4a047e6e0538db45725
Signed-off-by: Roger Fang <rogerfang@google.com>
-rw-r--r-- | pixelstats/SysfsCollector.cpp | 93 |
1 files changed, 43 insertions, 50 deletions
diff --git a/pixelstats/SysfsCollector.cpp b/pixelstats/SysfsCollector.cpp index c2453cb..8e5c709 100644 --- a/pixelstats/SysfsCollector.cpp +++ b/pixelstats/SysfsCollector.cpp @@ -293,85 +293,78 @@ void SysfsCollector::logSpeakerImpedance(const std::shared_ptr<IStats> &stats_cl * Report the last-detected impedance, temperature and heartbeats of left & right speakers. */ void SysfsCollector::logSpeakerHealthStats(const std::shared_ptr<IStats> &stats_client) { - std::string file_contents; + std::string file_contents_impedance; + std::string file_contents_temperature; + std::string file_contents_excursion; + std::string file_contents_heartbeat; + int count, i; + float impedance_ohm[4]; + float temperature_C[4]; + float excursion_mm[4]; + float heartbeat[4]; if (kImpedancePath == nullptr || strlen(kImpedancePath) == 0) { ALOGD("Audio impedance path not specified"); return; + } else if (!ReadFileToString(kImpedancePath, &file_contents_impedance)) { + ALOGD("Unable to read speaker impedance path %s", kImpedancePath); + return; } if (kSpeakerTemperaturePath == nullptr || strlen(kSpeakerTemperaturePath) == 0) { ALOGD("Audio speaker temperature path not specified"); return; - } - - if (kSpeakerHeartbeatPath == nullptr || strlen(kSpeakerHeartbeatPath) == 0) { - ALOGD("Audio speaker heartbeat path not specified"); + } else if (!ReadFileToString(kSpeakerTemperaturePath, &file_contents_temperature)) { + ALOGD("Unable to read speaker temperature path %s", kSpeakerTemperaturePath); return; } if (kSpeakerExcursionPath == nullptr || strlen(kSpeakerExcursionPath) == 0) { ALOGD("Audio speaker excursion path not specified"); return; - } - - float left_impedance_ohm, right_impedance_ohm; - - if (!ReadFileToString(kImpedancePath, &file_contents)) { - ALOGE("Unable to read speaker impedance path %s", kImpedancePath); - return; - } - if (sscanf(file_contents.c_str(), "%g,%g", &left_impedance_ohm, &right_impedance_ohm) != 2) { - ALOGE("Unable to parse speaker impedance %s", file_contents.c_str()); + } else if (!ReadFileToString(kSpeakerExcursionPath, &file_contents_excursion)) { + ALOGD("Unable to read speaker excursion path %s", kSpeakerExcursionPath); return; } - float left_temperature_C, right_temperature_C; - if (!ReadFileToString(kSpeakerTemperaturePath, &file_contents)) { - ALOGE("Unable to read speaker temperature path %s", kSpeakerTemperaturePath); + if (kSpeakerHeartbeatPath == nullptr || strlen(kSpeakerHeartbeatPath) == 0) { + ALOGD("Audio speaker heartbeat path not specified"); return; - } - if (sscanf(file_contents.c_str(), "%g,%g", &left_temperature_C, &right_temperature_C) != 2) { - ALOGE("Unable to parse speaker temperature %s", file_contents.c_str()); + } else if (!ReadFileToString(kSpeakerHeartbeatPath, &file_contents_heartbeat)) { + ALOGD("Unable to read speaker heartbeat path %s", kSpeakerHeartbeatPath); return; } - float left_excursion_mm, right_excursion_mm; - if (!ReadFileToString(kSpeakerExcursionPath, &file_contents)) { - ALOGE("Unable to read speaker excursion path %s", kSpeakerExcursionPath); + count = sscanf(file_contents_impedance.c_str(), "%g,%g,%g,%g", &impedance_ohm[0], + &impedance_ohm[1], &impedance_ohm[2], &impedance_ohm[3]); + if (count <= 0) return; - } - if (sscanf(file_contents.c_str(), "%g,%g", &left_excursion_mm, &right_excursion_mm) != 2) { - ALOGE("Unable to parse speaker excursion %s", file_contents.c_str()); - return; - } - float left_heartbeat, right_heartbeat; - if (!ReadFileToString(kSpeakerHeartbeatPath, &file_contents)) { - ALOGE("Unable to read speaker heartbeat path %s", kSpeakerHeartbeatPath); + count = sscanf(file_contents_temperature.c_str(), "%g,%g,%g,%g", &temperature_C[0], + &temperature_C[1], &temperature_C[2], &temperature_C[3]); + if (count <= 0) return; - } - if (sscanf(file_contents.c_str(), "%g,%g", &left_heartbeat, &right_heartbeat) != 2) { - ALOGE("Unable to parse speaker heartbeat %s", file_contents.c_str()); + + count = sscanf(file_contents_excursion.c_str(), "%g,%g,%g,%g", &excursion_mm[0], + &excursion_mm[1], &excursion_mm[2], &excursion_mm[3]); + if (count <= 0) return; - } - VendorSpeakerStatsReported left_obj; - left_obj.set_speaker_location(0); - left_obj.set_impedance(static_cast<int32_t>(left_impedance_ohm * 1000)); - left_obj.set_max_temperature(static_cast<int32_t>(left_temperature_C * 1000)); - left_obj.set_excursion(static_cast<int32_t>(left_excursion_mm * 1000)); - left_obj.set_heartbeat(static_cast<int32_t>(left_heartbeat)); + count = sscanf(file_contents_heartbeat.c_str(), "%g,%g,%g,%g", &heartbeat[0], &heartbeat[1], + &heartbeat[2], &heartbeat[3]); + if (count <= 0) + return; - VendorSpeakerStatsReported right_obj; - right_obj.set_speaker_location(1); - right_obj.set_impedance(static_cast<int32_t>(right_impedance_ohm * 1000)); - right_obj.set_max_temperature(static_cast<int32_t>(right_temperature_C * 1000)); - right_obj.set_excursion(static_cast<int32_t>(right_excursion_mm * 1000)); - right_obj.set_heartbeat(static_cast<int32_t>(right_heartbeat)); + VendorSpeakerStatsReported obj[4]; + for (i = 0; i < count && i < 4; i++) { + obj[i].set_speaker_location(i); + obj[i].set_impedance(static_cast<int32_t>(impedance_ohm[i] * 1000)); + obj[i].set_max_temperature(static_cast<int32_t>(temperature_C[i] * 1000)); + obj[i].set_excursion(static_cast<int32_t>(excursion_mm[i] * 1000)); + obj[i].set_heartbeat(static_cast<int32_t>(heartbeat[i])); - reportSpeakerHealthStat(stats_client, left_obj); - reportSpeakerHealthStat(stats_client, right_obj); + reportSpeakerHealthStat(stats_client, obj[i]); + } } void SysfsCollector::logThermalStats(const std::shared_ptr<IStats> &stats_client) { |