1 #pragma once
2
3 #include "conf.hpp"
4 #include "failsafeloggers/failsafe_logger.hpp"
5
6 #include <memory>
7 #include <string>
8 #include <unordered_map>
9 #include <vector>
10
11 /** Map of the zone ID to its failsafe logger.
12 */
13 extern std::unordered_map<int64_t, std::shared_ptr<pid_control::FailsafeLogger>>
14 zoneIdToFailsafeLogger;
15
16 /** Map of the sensor name/ID to its corresponding zone IDs.
17 */
18 extern std::unordered_map<std::string, std::vector<int64_t>> sensorNameToZoneId;
19
20 namespace pid_control
21 {
22
23 /** Given a sensor name, attempt to output entering/leaving-failsafe-mode
24 * logs for its corresponding zones.
25 */
outputFailsafeLogWithSensor(const std::string sensorName,const bool newFailsafeState,const std::string location,const std::string reason)26 inline void outputFailsafeLogWithSensor(
27 const std::string sensorName, const bool newFailsafeState,
28 const std::string location, const std::string reason)
29 {
30 for (const int64_t zoneId : sensorNameToZoneId[sensorName])
31 {
32 if (zoneIdToFailsafeLogger.count(zoneId))
33 {
34 zoneIdToFailsafeLogger[zoneId]->outputFailsafeLog(
35 zoneId, newFailsafeState, location, reason);
36 }
37 }
38 }
39
40 /** Given a zone ID, attempt to output entering/leaving-failsafe-mode
41 * logs for its corresponding zones.
42 */
outputFailsafeLogWithZone(const int64_t zoneId,const bool newFailsafeState,const std::string location,const std::string reason)43 inline void outputFailsafeLogWithZone(
44 const int64_t zoneId, const bool newFailsafeState,
45 const std::string location, const std::string reason)
46 {
47 if (zoneIdToFailsafeLogger.count(zoneId))
48 {
49 zoneIdToFailsafeLogger[zoneId]->outputFailsafeLog(
50 zoneId, newFailsafeState, location, reason);
51 }
52 }
53 } // namespace pid_control
54