diff options
author | Scott Murray <scott.murray@konsulko.com> | 2019-04-22 21:38:18 -0400 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2019-04-22 22:42:06 -0400 |
commit | b523b0c8cc37a989bfb84a5ebefe1ec1f2b0cbfb (patch) | |
tree | 482f3fee892fc0a0a327d256bd25134fb6996e15 /app/configuration.cpp |
Initial code check-inicefish_8.99.5icefish_8.99.4icefish_8.99.3icefish_8.99.2icefish_8.99.1icefish/8.99.5icefish/8.99.4icefish/8.99.3icefish/8.99.2icefish/8.99.1halibut_8.0.6halibut_8.0.5halibut_8.0.4halibut_8.0.3halibut_8.0.2halibut_8.0.1halibut_8.0.0halibut_7.99.3halibut_7.99.2halibut_7.99.1halibut/8.0.6halibut/8.0.5halibut/8.0.4halibut/8.0.3halibut/8.0.2halibut/8.0.1halibut/8.0.0halibut/7.99.3halibut/7.99.2halibut/7.99.18.99.58.99.48.99.38.99.28.99.18.0.68.0.58.0.48.0.38.0.28.0.18.0.07.99.37.99.27.99.1halibut
A simple telematics demo application for AGL. It reads vehicle and
engine speed from the CAN low-level binding and publishes them via
MQTT.
Change-Id: Ib85904e87919053cad1215b3f53cee81db25c94a
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
Diffstat (limited to 'app/configuration.cpp')
-rw-r--r-- | app/configuration.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/app/configuration.cpp b/app/configuration.cpp new file mode 100644 index 0000000..0762a4a --- /dev/null +++ b/app/configuration.cpp @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2019 Konsulko Group + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "configuration.h" +#include <glib.h> +#include <strings.h> + +Configuration::Configuration(const std::string &filename, const std::string &device_uuid): + m_filename(filename), + m_device_uuid(device_uuid) +{ + read(); +} + +void Configuration::read(void) +{ + GKeyFile* conf_file; + GError *error = NULL; + char *value_str; + int n; + + // Load settings from configuration file if it exists + conf_file = g_key_file_new(); + if(!conf_file) { + return; + } + + if(g_key_file_load_from_dirs(conf_file, + m_filename.c_str(), + (const gchar**) g_get_system_config_dirs(), + NULL, + G_KEY_FILE_KEEP_COMMENTS, + NULL) != TRUE) { + g_key_file_free(conf_file); + return; + } + + // + // General + // + + // Set log level if it is specified + error = NULL; + n = g_key_file_get_integer(conf_file, "General", "log_level", &error); + if(!error && n > 0) { + m_log_level = n; + } + + value_str = g_key_file_get_string(conf_file, "General", "cellular_enabled", NULL); + if(value_str) { + if(!strcasecmp(value_str, "true")) { + m_cellular_enabled = true; + } else if(!strcasecmp(value_str, "false")) { + m_cellular_enabled = false; + } + } + + value_str = g_key_file_get_string(conf_file, "General", "gps_enabled", NULL); + if(value_str) { + if(!strcasecmp(value_str, "true")) { + m_gps_enabled = true; + } else if(!strcasecmp(value_str, "false")) { + m_gps_enabled = false; + } + } + + value_str = g_key_file_get_string(conf_file, "General", "check_online", NULL); + if(value_str) { + if(!strcasecmp(value_str, "true")) { + m_check_online = true; + } else if(!strcasecmp(value_str, "false")) { + m_check_online = false; + } + } + + value_str = g_key_file_get_string(conf_file, "General", "device_uuid", NULL); + if(value_str) { + m_device_uuid = value_str; + } + + // + // MQTT + // + + value_str = g_key_file_get_string(conf_file, "MQTT", "broker", NULL); + if(value_str) { + m_mqtt_broker = value_str; + } + + error = NULL; + n = g_key_file_get_integer(conf_file, "MQTT", "port", &error); + if(!error && n > 0) { + m_mqtt_port = n; + } + + error = NULL; + n = g_key_file_get_integer(conf_file, "MQTT", "keepalive", &error); + if(!error && n >= 0) { + m_mqtt_keepalive = n; + } + + error = NULL; + n = g_key_file_get_integer(conf_file, "MQTT", "qos", &error); + if(!error && n >= 0 && n < 3) { + m_mqtt_qos = n; + } + + value_str = g_key_file_get_string(conf_file, "MQTT", "retain", NULL); + if(value_str) { + if(!strcasecmp(value_str, "true")) { + m_mqtt_retain = true; + } else if(!strcasecmp(value_str, "false")) { + m_mqtt_retain = false; + } + } + + value_str = g_key_file_get_string(conf_file, "MQTT", "username", NULL); + if(value_str) { + m_mqtt_username = value_str; + } + + value_str = g_key_file_get_string(conf_file, "MQTT", "password", NULL); + if(value_str) { + m_mqtt_password = value_str; + } + + // + // Event + // + + error = NULL; + n = g_key_file_get_integer(conf_file, "Event", "update_period", &error); + if(!error && n >= 0) { + m_update_period = n; + } + + g_key_file_free(conf_file); +} |