aboutsummaryrefslogtreecommitdiff
path: root/apps/sm-get-value.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/sm-get-value.h')
-rw-r--r--apps/sm-get-value.h39
1 files changed, 18 insertions, 21 deletions
diff --git a/apps/sm-get-value.h b/apps/sm-get-value.h
index c98d1d4..5893d23 100644
--- a/apps/sm-get-value.h
+++ b/apps/sm-get-value.h
@@ -21,7 +21,6 @@ using namespace trygvis::sensor;
using namespace trygvis::sensor::io;
class sm_get_value : public app {
-
public:
sm_get_value() : app("sm-get-value") {
}
@@ -35,25 +34,24 @@ public:
vector<pair<unsigned int, string>> sensors;
KeyDictionary dict;
- SampleKey* hostname_key = dict.indexOf("hostname");
- SampleKey* device_key = dict.indexOf("device");
- SampleKey* timestamp_key = dict.indexOf("timestamp_ms");
+ SampleKey *hostname_key = dict.indexOf("hostname");
+ SampleKey *device_key = dict.indexOf("device");
+ SampleKey *timestamp_key = dict.indexOf("timestamp_ms");
void add_options(po::options_description_easy_init &options) override {
auto default_sleep = po::value<>(&sleepTime)->default_value(0);
auto default_format = po::value<sample_format_type>(&format)->default_value(sample_format_type::KEY_VALUE);
- options
- ("device", po::value<string>()->required(), "MAC of device to poll")
- ("sensor", po::value<vector<unsigned int>>(&sensorIndexes)->multitoken(), "Sensor to poll, defaults to all")
- ("sleep", default_sleep,
- "How long to sleep in seconds between each poll. If not given, it will exit after first poll")
- ("format", default_format, "Output format");
+ options("device", po::value<string>()->required(), "MAC of device to poll");
+ options("sensor", po::value<vector<unsigned int>>(&sensorIndexes)->multitoken(),
+ "Sensor to poll, defaults to all");
+ options("sleep", default_sleep,
+ "How long to sleep in seconds between each poll. If not given, it will exit after first poll");
+ options("format", default_format, "Output format");
}
int main(app_execution &execution) override {
- __attribute__((unused))
- BluetoothSystem bluetoothSystem;
+ __attribute__((unused)) BluetoothSystem bluetoothSystem;
auto desc = execution.desc;
auto vm = execution.vm;
@@ -86,7 +84,8 @@ public:
}
if (loop) {
- LOG4CPLUS_DEBUG(execution.logger, "Sleeping for " + std::to_string(sleepTime) + " seconds after failure.");
+ LOG4CPLUS_DEBUG(execution.logger,
+ "Sleeping for " + std::to_string(sleepTime) + " seconds after failure.");
auto targetTime = system_clock::now() + seconds(sleepTime);
this_thread::sleep_until(targetTime);
@@ -106,8 +105,7 @@ public:
void read_sensors(SoilMoisture &soilMoisture, string mac) {
auto epoch = system_clock::now().time_since_epoch();
auto timestamp = duration_cast<seconds>(epoch).count();
- auto unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter),
- dict, format);
+ auto unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter), dict, format);
shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)};
int i = 0;
@@ -121,11 +119,11 @@ public:
auto sensor_name_key = dict.indexOf("sensor_name" + std::to_string(i));
auto sample = SampleRecord(dict)
- .set(hostname_key, get_hostname())
- .set(device_key, mac)
- .set(timestamp_key, std::to_string(timestamp))
- .set(sensor_key, std::to_string(value))
- .set(sensor_name_key, name);
+ .set(hostname_key, get_hostname())
+ .set(device_key, mac)
+ .set(timestamp_key, std::to_string(timestamp))
+ .set(sensor_key, std::to_string(value))
+ .set(sensor_name_key, name);
output_stream->write(sample);
@@ -178,6 +176,5 @@ public:
}
}
};
-
}
}