Skip to content

Commit 684bf22

Browse files
author
MatthewColvin
committed
Tweak handling of json file paths to be consistent across the various spots where they are defined.
1 parent 80ef949 commit 684bf22

7 files changed

Lines changed: 14 additions & 14 deletions

File tree

Platformio/lib/Device/ActiveDeviceConfig.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ std::vector<IDevice::Ptr> ActiveDeviceConfig::loadDevices() {
4848

4949
// #TODO OMOTE-Community/OMOTE-Firmware-object-oriented#72
5050
// HardwareFactory::getAbstract().debugPrint("Loaded JSON %s", content.c_str());
51-
auto configPath = std::filesystem::path(ACTIVE_DEVICES_CONFIG_FILE);
51+
std::filesystem::path configPath(ACTIVE_DEVICES_CONFIG_FILE);
5252
rapidjson::Document doc = OMOTE::JSON::GetDocument(configPath);
5353

5454
if (!doc.IsArray())

Platformio/lib/HAL/Hardware/LoggingInterface.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
#include <fstream>
55
#include <rapidjson/document.h>
66

7-
#define LOG_SETTINGS_FILE "logSettings.json"
8-
97
void LoggingInterface::restoreSettings() {
108
// Default to warning for all modules before loading from file
119
// so new modules default to warning
1210
std::fill(mCurrentLogLevels.begin(), mCurrentLogLevels.end(), LogLevel::Warning);
1311

14-
std::filesystem::path settingsPath(FS_PATH LOG_SETTINGS_FILE);
12+
std::filesystem::path settingsPath(LOG_SETTINGS_FILE);
1513
rapidjson::Document d = OMOTE::JSON::GetDocument(settingsPath);
1614

1715
if (!d.HasParseError() && d.IsObject()) {
@@ -41,7 +39,7 @@ void LoggingInterface::saveSettings() {
4139
d.AddMember(key, val, d.GetAllocator());
4240
}
4341

44-
std::filesystem::path settingsPath(FS_PATH LOG_SETTINGS_FILE);
42+
std::filesystem::path settingsPath(LOG_SETTINGS_FILE);
4543
OMOTE::JSON::WriteDocumentToFile(d, settingsPath);
4644
}
4745

Platformio/lib/HAL/Hardware/LoggingInterface.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class LoggingInterface {
101101
// Check level and module to see if we want to print the log
102102
static bool isPrintWanted(LogModule aModule, LogLevel aLevelToCheck);
103103
static inline std::array<LogLevel, NumLogModules> mCurrentLogLevels{};
104+
static constexpr auto LOG_SETTINGS_FILE = FS_PATH "logSettings.json";
104105
};
105106

106107
inline void LoggingInterface::setLogModule(LogModule aModule) {

Platformio/lib/HAL/Hardware/wifiHandlerInterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,7 @@ class wifiHandlerInterface {
104104
std::make_shared<ScanNotificationTy>();
105105
std::shared_ptr<Notification<wifiStatus>> mStatusUpdate =
106106
std::make_shared<Notification<wifiStatus>>();
107+
108+
static constexpr auto MQTT_CONFIG_FILE = FS_PATH "mqtt.json";
109+
static constexpr auto NTP_CONFIG_FILE = FS_PATH "ntp.json";
107110
};

Platformio/lib/SimulatorHalImpl/wifiHandlerSim/wifiHandlerSim.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,16 @@ void wifiHandlerSim::mqttSaveCredentials() {
209209
d.AddMember("password", mMqttPassword, d.GetAllocator());
210210
d.AddMember("client", mMqttClientName, d.GetAllocator());
211211

212-
std::filesystem::path mqttJsonConfigPath(FS_PATH "mqtt.json");
212+
std::filesystem::path mqttJsonConfigPath(MQTT_CONFIG_FILE);
213213
OMOTE::JSON::WriteDocumentToFile(d, mqttJsonConfigPath);
214214

215215
mMqttSaveOnConnect = false;
216216
}
217217
}
218218

219219
void wifiHandlerSim::restoreCredentials() {
220-
std::filesystem::path mqttJson(FS_PATH "mqtt.json");
221-
rapidjson::Document d = OMOTE::JSON::GetDocument(mqttJson);
220+
std::filesystem::path mqttJsonConfigPath(MQTT_CONFIG_FILE);
221+
rapidjson::Document d = OMOTE::JSON::GetDocument(mqttJsonConfigPath);
222222
if (d.HasParseError() || d.IsNull()) {
223223
return;
224224
}

Platformio/lib/esp32HalImpl/wifiHandler/wifihandler.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ void wifiHandler::enableMqtt(bool enabled) {
316316

317317
void wifiHandler::mqttRestoreCredentials() {
318318
// restore from disk
319-
std::filesystem::path aMqttPath(MQTT_CONFIG_FILE);
320-
rapidjson::Document d = OMOTE::JSON::GetDocument(aMqttPath);
319+
std::filesystem::path mqttConfigPath(MQTT_CONFIG_FILE);
320+
rapidjson::Document d = OMOTE::JSON::GetDocument(mqttConfigPath);
321321
if (d.HasParseError() || d.IsNull()) {
322322
mLogger->error("Could not load MQTT credentials.");
323323
return;
@@ -369,8 +369,8 @@ void wifiHandler::ntpRestoreCredentials() {
369369
mNtpDisplayMode = ntpDisplayMode::constant;
370370

371371
// restore from disk
372-
std::filesystem::path ntpJsonConfig(NTP_CONFIG_FILE);
373-
rapidjson::Document d = OMOTE::JSON::GetDocument(ntpJsonConfig);
372+
std::filesystem::path ntpConfigPath(NTP_CONFIG_FILE);
373+
rapidjson::Document d = OMOTE::JSON::GetDocument(ntpConfigPath);
374374

375375
if (d.HasParseError() || d.IsNull()) {
376376
mLogger->error("Could not load NTP credentials.");

Platformio/lib/esp32HalImpl/wifiHandler/wifihandler.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ class wifiHandler : public wifiHandlerInterface {
116116
/**
117117
* @brief MQTT variables
118118
*/
119-
static constexpr auto MQTT_CONFIG_FILE = FS_PATH "mqtt.json";
120119
std::string mMqttBroker = "broker";
121120
std::string mMqttPort = "port";
122121
std::string mMqttUser = "user";
@@ -132,7 +131,6 @@ class wifiHandler : public wifiHandlerInterface {
132131
/**
133132
* @brief NTP variables
134133
*/
135-
static constexpr auto NTP_CONFIG_FILE = FS_PATH "ntp.json";
136134
bool mNtpEnabled = false;
137135
bool mNtpInitialised = false;
138136
std::string mNtpServer = "pool.ntp.org";

0 commit comments

Comments
 (0)