aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-format66
-rw-r--r--apps/SoilMoisture.cpp64
-rw-r--r--apps/SoilMoisture.h1
-rw-r--r--apps/apps.cpp3
-rw-r--r--apps/apps.h14
-rw-r--r--apps/ble-inspect-device.h19
-rw-r--r--apps/ble-scan.h14
-rw-r--r--apps/generate.cpp9
-rw-r--r--apps/launcher.cpp2
-rw-r--r--apps/sample-add-timestamp.h21
-rw-r--r--apps/sample-convert.h20
-rw-r--r--apps/sample-select.h11
-rw-r--r--apps/sm-db-insert.h22
-rw-r--r--apps/sm-db-select.h15
-rw-r--r--apps/sm-get-value.h39
-rw-r--r--apps/sm-serial-read-all.h21
-rw-r--r--apps/sm-serial-read.h13
17 files changed, 187 insertions, 167 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..e480c65
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,66 @@
+---
+Language: Cpp
+# BasedOnStyle: Google
+AccessModifierOffset: -4
+AlignAfterOpenBracket: true
+AlignEscapedNewlinesLeft: true
+AlignOperands: true
+AlignTrailingComments: false
+AlignConsecutiveAssignments: false
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: false
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: None
+AlwaysBreakAfterDefinitionReturnType: false
+AlwaysBreakTemplateDeclarations: true
+AlwaysBreakBeforeMultilineStrings: true
+BreakBeforeBinaryOperators: None
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BinPackParameters: true
+BinPackArguments: true
+ColumnLimit: 120
+ConstructorInitializerAllOnOneLineOrOnePerLine: true
+ConstructorInitializerIndentWidth: 4
+DerivePointerAlignment: true
+ExperimentalAutoDetectBinPacking: false
+IndentCaseLabels: true
+IndentWrappedFunctionNames: false
+IndentFunctionDeclarationAfterType: false
+MaxEmptyLinesToKeep: 2
+KeepEmptyLinesAtTheStartOfBlocks: false
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: false
+PenaltyBreakBeforeFirstCallParameter: 1
+PenaltyBreakComment: 300
+PenaltyBreakString: 1000
+PenaltyBreakFirstLessLess: 120
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Left
+SpacesBeforeTrailingComments: 1
+Cpp11BracedListStyle: true
+Standard: Auto
+IndentWidth: 4
+TabWidth: 8
+UseTab: Never
+BreakBeforeBraces: Attach
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpacesInAngles: false
+SpaceInEmptyParentheses: false
+SpacesInCStyleCastParentheses: false
+SpaceAfterCStyleCast: true
+SpacesInContainerLiterals: true
+SpaceBeforeAssignmentOperators: true
+ContinuationIndentWidth: 4
+CommentPragmas: '^ IWYU pragma:'
+ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
+SpaceBeforeParens: ControlStatements
+DisableFormat: false
+...
+
diff --git a/apps/SoilMoisture.cpp b/apps/SoilMoisture.cpp
index fea1ef9..044ba21 100644
--- a/apps/SoilMoisture.cpp
+++ b/apps/SoilMoisture.cpp
@@ -4,20 +4,10 @@ namespace trygvis {
namespace sensor {
#define BLUETOOTH_UUID_INITIALIZER \
- { \
- 0x00, 0x00, 0x00, 0x00, \
- 0x00, 0x00, \
- 0x10, 0x00, \
- 0x80, 0x00, \
- 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb \
- };
-
-auto trygvis_io_base_uuid = boost::uuids::uuid {
- 0x32, 0xd0, 0x00, 0x00,
- 0x03, 0x5d,
- 0x59, 0xc5,
- 0x70, 0xd3,
- 0xbc, 0x8e, 0x4a, 0x1f, 0xd8, 0x3f};
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb };
+
+auto trygvis_io_base_uuid =
+ boost::uuids::uuid{0x32, 0xd0, 0x00, 0x00, 0x03, 0x5d, 0x59, 0xc5, 0x70, 0xd3, 0xbc, 0x8e, 0x4a, 0x1f, 0xd8, 0x3f};
const boost::uuids::uuid soil_moisture_service = makeUuid(trygvis_io_base_uuid, 0x00, 0x10);
const boost::uuids::uuid soil_moisture_characteristic = makeUuid(trygvis_io_base_uuid, 0x00, 0x11);
@@ -25,41 +15,39 @@ const boost::uuids::uuid soil_moisture_characteristic = makeUuid(trygvis_io_base
using namespace trygvis::bluetooth;
ByteBuffer createGetSensorCount() {
- return ByteBuffer::alloc(100).
- write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_GET_SENSOR_COUNT));
+ return ByteBuffer::alloc(100) //
+ .write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_GET_SENSOR_COUNT));
}
ByteBuffer createGetValue(uint8_t sensor) {
- return ByteBuffer::alloc(100).
- write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_GET_VALUE)).
- write16le(sensor);
+ return ByteBuffer::alloc(100) //
+ .write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_GET_VALUE)) //
+ .write16le(sensor);
}
ByteBuffer createSetWarningValue(uint8_t sensor, uint16_t warning_value) {
- return ByteBuffer::alloc(100).
- write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_SET_WARNING_VALUE)).
- write8(sensor).
- write16le(warning_value);
+ return ByteBuffer::alloc(100)
+ .write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_SET_WARNING_VALUE))
+ .write8(sensor)
+ .write16le(warning_value);
}
ByteBuffer createSetSensorName(uint8_t sensor, string name) {
- return ByteBuffer::alloc(100).
- write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_SET_SENSOR_NAME)).
- write8(sensor).
- write(reinterpret_cast<const uint8_t *>(name.c_str()), name.length());
+ return ByteBuffer::alloc(100)
+ .write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_SET_SENSOR_NAME))
+ .write8(sensor)
+ .write(reinterpret_cast<const uint8_t *>(name.c_str()), name.length());
}
ByteBuffer createGetSensorName(uint8_t sensor) {
- return ByteBuffer::alloc(100).
- write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_GET_SENSOR_NAME)).
- write8(sensor);
+ return ByteBuffer::alloc(100).write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_GET_SENSOR_NAME)).write8(sensor);
}
ByteBuffer createSetUpdateInterval(uint8_t sensor, uint8_t interval_in_seconds) {
- return ByteBuffer::alloc(100).
- write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_SET_UPDATE_INTERVAL)).
- write8(sensor).
- write8(interval_in_seconds);
+ return ByteBuffer::alloc(100)
+ .write8(static_cast<uint8_t>(sm_cmd_code::SM_CMD_SET_UPDATE_INTERVAL))
+ .write8(sensor)
+ .write8(interval_in_seconds);
}
SoilMoisture SoilMoisture::create(shared_ptr<BluetoothGatt> gatt) {
@@ -80,8 +68,8 @@ SoilMoisture SoilMoisture::create(shared_ptr<BluetoothGatt> gatt) {
return SoilMoisture(gatt, *service, *c);
}
-SoilMoisture::SoilMoisture(shared_ptr<BluetoothGatt> gatt, BluetoothGattService &s, BluetoothGattCharacteristic &c) :
- gatt(std::move(gatt)), s(s), c(c) {
+SoilMoisture::SoilMoisture(shared_ptr<BluetoothGatt> gatt, BluetoothGattService &s, BluetoothGattCharacteristic &c)
+ : gatt(std::move(gatt)), s(s), c(c) {
}
ByteBuffer SoilMoisture::writeAndRead(ByteBuffer &requestBytes) {
@@ -99,7 +87,8 @@ ByteBuffer SoilMoisture::writeAndRead(ByteBuffer &requestBytes) {
uint8_t actualCode = responseBytes.read8();
if (actualCode != expectedCode) {
- throw runtime_error("Unexpected response code: " + to_string(actualCode) + ", expected " + to_string(expectedCode));
+ throw runtime_error("Unexpected response code: " + to_string(actualCode) + ", expected " +
+ to_string(expectedCode));
}
return responseBytes;
@@ -128,6 +117,5 @@ string SoilMoisture::getName(uint8_t sensor) {
return string((char *) bytes, (unsigned long) bytesLeft);
}
-
}
}
diff --git a/apps/SoilMoisture.h b/apps/SoilMoisture.h
index 79e393f..b5a8749 100644
--- a/apps/SoilMoisture.h
+++ b/apps/SoilMoisture.h
@@ -41,6 +41,5 @@ private:
BluetoothGattService &s;
BluetoothGattCharacteristic &c;
};
-
}
}
diff --git a/apps/apps.cpp b/apps/apps.cpp
index e0bb631..b353e85 100644
--- a/apps/apps.cpp
+++ b/apps/apps.cpp
@@ -16,7 +16,7 @@ std::string get_hostname() {
}
struct addrinfo hints, *info, *p;
-// int gai_result;
+ // int gai_result;
char hostname[1024];
hostname[1023] = '\0';
@@ -43,6 +43,5 @@ std::string get_hostname() {
void app_execution::usage() {
cerr << desc << endl;
}
-
}
}
diff --git a/apps/apps.h b/apps/apps.h
index 7569a9f..4a69b05 100644
--- a/apps/apps.h
+++ b/apps/apps.h
@@ -22,7 +22,7 @@ public:
const json::string_t key;
};
-template<typename T>
+template <typename T>
T get(json j, std::string key) {
auto ref = j[key];
@@ -35,7 +35,8 @@ T get(json j, std::string key) {
class app_execution {
public:
- app_execution(po::options_description desc, po::variables_map vm, Logger logger) : desc(desc), vm(vm), logger(logger) {
+ app_execution(po::options_description desc, po::variables_map vm, Logger logger)
+ : desc(desc), vm(vm), logger(logger) {
}
const po::options_description desc;
@@ -52,11 +53,9 @@ public:
virtual ~app() = default;
- virtual void add_options(po::options_description_easy_init &options) {
- };
+ virtual void add_options(po::options_description_easy_init &options){};
- virtual void add_extra_options(po::options_description &options) {
- };
+ virtual void add_extra_options(po::options_description &options){};
virtual int main(app_execution &execution) = 0;
@@ -65,7 +64,7 @@ public:
std::string get_hostname();
-template<typename T>
+template <typename T>
class noop_delete {
public:
void operator()(T *) const {
@@ -74,6 +73,5 @@ public:
static inline void noop_deleter(void *) {
}
-
}
}
diff --git a/apps/ble-inspect-device.h b/apps/ble-inspect-device.h
index 346f9be..ff19ba1 100644
--- a/apps/ble-inspect-device.h
+++ b/apps/ble-inspect-device.h
@@ -13,7 +13,6 @@ using namespace trygvis::bluetooth;
using namespace trygvis::apps;
class ble_inspect_device : public app {
-
public:
ble_inspect_device() : app("ble-inspect-device") {
}
@@ -21,8 +20,7 @@ public:
~ble_inspect_device() = default;
void add_options(po::options_description_easy_init &options) override {
- options
- ("device", po::value<string>()->required(), "The MAC of the device to inspect");
+ options("device", po::value<string>()->required(), "The MAC of the device to inspect");
}
void scan_callback(BluetoothDevice &device) {
@@ -32,18 +30,18 @@ public:
gatt->discoverServices();
- vector < BluetoothGattService * > services = gatt->getServices();
+ vector<BluetoothGattService *> services = gatt->getServices();
cout << "Device has " << services.size() << " services" << endl;
- for (auto &s: services) {
+ for (auto &s : services) {
const vector<BluetoothGattCharacteristic *> characteristics = s->getCharacteristics();
- cout << "Service: UUID: " << s->getUuid() <<
- ", has " << characteristics.size() << " characteristics" << endl;
+ cout << "Service: UUID: " << s->getUuid() << ", has " << characteristics.size() << " characteristics"
+ << endl;
- for (auto &c: characteristics) {
- cout << "Characteristic: UUID: " << c->getUuid() <<
- ", properties: " << (int) c->getProperties() << endl;
+ for (auto &c : characteristics) {
+ cout << "Characteristic: UUID: " << c->getUuid() << ", properties: " << (int) c->getProperties()
+ << endl;
}
}
}
@@ -72,6 +70,5 @@ public:
}
}
};
-
}
}
diff --git a/apps/ble-scan.h b/apps/ble-scan.h
index 9a72388..2c183e3 100644
--- a/apps/ble-scan.h
+++ b/apps/ble-scan.h
@@ -17,11 +17,9 @@ static std::function<void(int)> onSignal;
static void signal_handler(int signal) {
onSignal(signal);
}
-
}
class ble_scan : public app {
-
public:
ble_scan() : app("ble-scan") {
}
@@ -29,8 +27,7 @@ public:
~ble_scan() = default;
void add_options(po::options_description_easy_init &options) override {
- options
- ("adapter", po::value<int>()->default_value(0), "Which adapter to use.");
+ options("adapter", po::value<int>()->default_value(0), "Which adapter to use.");
}
int main(app_execution &execution) override {
@@ -39,9 +36,7 @@ public:
struct sigaction sigIntHandler;
- ble_scan_utils::onSignal = [&](int signal) {
- adapter->stopScan();
- };
+ ble_scan_utils::onSignal = [&](int signal) { adapter->stopScan(); };
sigIntHandler.sa_handler = &ble_scan_utils::signal_handler;
sigemptyset(&sigIntHandler.sa_mask);
@@ -68,9 +63,7 @@ public:
cout << "Stopped. Found " << seen_devices.size() << " devices." << endl;
- for_each(begin(seen_devices), end(seen_devices), [&](auto mac) {
- cout << mac.str() << endl;
- });
+ for_each(begin(seen_devices), end(seen_devices), [&](auto mac) { cout << mac.str() << endl; });
return EXIT_SUCCESS;
} catch (std::runtime_error ex) {
@@ -82,6 +75,5 @@ public:
}
}
};
-
}
}
diff --git a/apps/generate.cpp b/apps/generate.cpp
index 9dcc271..a088e6e 100644
--- a/apps/generate.cpp
+++ b/apps/generate.cpp
@@ -6,7 +6,6 @@
using namespace std;
int main(int argc, char *argv[]) {
-
cout << "Generating " << argv[1] << endl;
ofstream out;
@@ -30,16 +29,14 @@ int main(int argc, char *argv[]) {
string app_name = argv[i];
stringstream buf;
- regex_replace(ostream_iterator<char>(buf),
- app_name.begin(), app_name.end(),
- r, "_");
+ regex_replace(ostream_iterator<char>(buf), app_name.begin(), app_name.end(), r, "_");
string class_name = buf.str();
apps.emplace_back(make_pair(app_name, class_name));
}
for_each(begin(apps), end(apps), [&](pair<string, string> pair) {
-// out << "class " << pair.second << ";" << endl;
+ // out << "class " << pair.second << ";" << endl;
out << "#include \"" << pair.first << ".h\"" << endl;
});
out << endl;
@@ -64,7 +61,7 @@ int main(int argc, char *argv[]) {
}
out << "if (boost::ends_with(app_name, \"" << pair.first << "\")) {" << endl
- << " return launch_app<" << pair.second << ">(argc, argv);" << endl;
+ << " return launch_app<" << pair.second << ">(argc, argv);" << endl;
});
out << " } else {" << endl
diff --git a/apps/launcher.cpp b/apps/launcher.cpp
index 2a1e039..0b97a59 100644
--- a/apps/launcher.cpp
+++ b/apps/launcher.cpp
@@ -26,7 +26,7 @@ void setup_logging(string app_name) {
h.getRoot().addAppender(SharedAppenderPtr(console));
}
-template<typename App>
+template <typename App>
int launch_app(int argc, const char *argv[]) {
App app;
diff --git a/apps/sample-add-timestamp.h b/apps/sample-add-timestamp.h
index 711cf49..8439519 100644
--- a/apps/sample-add-timestamp.h
+++ b/apps/sample-add-timestamp.h
@@ -13,11 +13,9 @@ using namespace trygvis::sensor::io;
namespace po = boost::program_options;
class TimestampAddingSampleOutputStream : public SampleOutputStream {
-
public:
TimestampAddingSampleOutputStream(shared_ptr<SampleOutputStream> output, KeyDictionary &dict, string timestamp_name)
- :
- timestamp_key(dict.indexOf(timestamp_name)) {
+ : timestamp_key(dict.indexOf(timestamp_name)) {
if (input_time_resolution_ == time_resolution::MILLISECONDS) {
factor = 1000;
} else {
@@ -43,7 +41,6 @@ private:
};
class sample_add_timestamp : public app {
-
private:
string timestamp_name;
time_resolution resolution;
@@ -56,10 +53,10 @@ public:
~sample_add_timestamp() = default;
void add_options(po::options_description_easy_init &options) override {
- options
- ("resolution", po::value<time_resolution>(&resolution)->default_value(time_resolution::SECONDS))
- ("timestamp-name", po::value<string>(&timestamp_name)->default_value("timestamp"))
- ("output-format", po::value<sample_format_type>(&output_format)->default_value(sample_format_type::KEY_VALUE));
+ options("resolution", po::value<time_resolution>(&resolution)->default_value(time_resolution::SECONDS));
+ options("timestamp-name", po::value<string>(&timestamp_name)->default_value("timestamp"));
+ options("output-format",
+ po::value<sample_format_type>(&output_format)->default_value(sample_format_type::KEY_VALUE));
}
const int buffer_size = 1024;
@@ -72,9 +69,10 @@ public:
KeyDictionary dict;
sample_output_stream_options options = {};
- unique_ptr<SampleOutputStream> unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter), dict, output_format, options);
+ auto unique_output_stream =
+ open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter), dict, output_format, options);
shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)};
- shared_ptr<SampleOutputStream> p = make_shared<TimestampAddingSampleOutputStream>(output_stream, dict, timestamp_name);
+ auto p = make_shared<TimestampAddingSampleOutputStream>(output_stream, dict, timestamp_name);
auto parser = open_sample_stream_parser(p, dict);
int recordCount = 0;
@@ -82,7 +80,7 @@ public:
while (!input->eof()) {
char buffer[buffer_size];
input->read(buffer, buffer_size);
- size_t gcount = (size_t)input->gcount();
+ size_t gcount = (size_t) input->gcount();
recordCount++;
@@ -93,6 +91,5 @@ public:
return EXIT_SUCCESS;
};
};
-
}
}
diff --git a/apps/sample-convert.h b/apps/sample-convert.h
index 6b0f368..9a2f99a 100644
--- a/apps/sample-convert.h
+++ b/apps/sample-convert.h
@@ -32,20 +32,19 @@ public:
~sample_convert() = default;
void add_options(po::options_description_easy_init &options) override {
- options
- ("input", po::value<string>(&input_file)->default_value("-"))
-// ("input-format", po::value<string>(&input_format)->default_value("csv"))
- ("output", po::value<string>(&output_file)->default_value("-"))
- ("output-format", po::value<sample_format_type>(&output_format)->default_value(sample_format_type::KEY_VALUE))
- ("fields", po::value<string>(&fields))
- ("add-timestamp", po::value<bool>(&add_timestamp)->default_value(true))
- ("timestamp-field", po::value<string>(&timestamp_field)->default_value("timestamp"));
+ options("input", po::value<string>(&input_file)->default_value("-"));
+ // ("input-format", po::value<string>(&input_format)->default_value("csv"))
+ options("output", po::value<string>(&output_file)->default_value("-"));
+ options("output-format",
+ po::value<sample_format_type>(&output_format)->default_value(sample_format_type::KEY_VALUE));
+ options("fields", po::value<string>(&fields));
+ options("add-timestamp", po::value<bool>(&add_timestamp)->default_value(true));
+ options("timestamp-field", po::value<string>(&timestamp_field)->default_value("timestamp"));
}
void add_extra_options(po::options_description &all_options) override {
po::options_description sql("SQL");
- sql.add_options()
- ("table-name", po::value<string>(&table_name));
+ sql.add_options()("table-name", po::value<string>(&table_name));
all_options.add(sql);
};
@@ -115,6 +114,5 @@ public:
return EXIT_SUCCESS;
}
};
-
}
}
diff --git a/apps/sample-select.h b/apps/sample-select.h
index 60bda32..8ae5cc3 100644
--- a/apps/sample-select.h
+++ b/apps/sample-select.h
@@ -12,7 +12,6 @@ using boost::tokenizer;
namespace po = boost::program_options;
class sample_select : public app {
-
private:
string fields;
@@ -23,8 +22,7 @@ public:
~sample_select() = default;
void add_options(po::options_description_easy_init &options) override {
- options
- ("fields", po::value<string>(&fields)->required());
+ options("fields", po::value<string>(&fields)->required());
}
int main(app_execution &execution) override {
@@ -94,9 +92,11 @@ public:
}
vector<sample_output_stream_option*> options = {};
- unique_ptr<SampleOutputStream> unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter), dict, parser->type(), options);
+ unique_ptr<SampleOutputStream> unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout,
+ noop_deleter), dict, parser->type(), options);
shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)};
- shared_ptr<SampleOutputStream> p = make_shared<TimestampFixingSampleOutputStream>(output_stream, dict, timestamp_name, relative_name, relative_resolution, start_time);
+ shared_ptr<SampleOutputStream> p = make_shared<TimestampFixingSampleOutputStream>(output_stream, dict,
+ timestamp_name, relative_name, relative_resolution, start_time);
parser = open_sample_stream_parser(p, dict, parser->type());
int recordCount = 0;
@@ -115,6 +115,5 @@ public:
return EXIT_SUCCESS;
};
};
-
}
}
diff --git a/apps/sm-db-insert.h b/apps/sm-db-insert.h
index b786e41..7e08268 100644
--- a/apps/sm-db-insert.h
+++ b/apps/sm-db-insert.h
@@ -8,13 +8,12 @@
namespace trygvis {
namespace apps {
-template<class T>
+template <class T>
using o = boost::optional<T>;
using namespace std;
using json = nlohmann::json;
class sm_db_insert : public app {
-
public:
sm_db_insert() : app("sm-db-insert") {
}
@@ -22,8 +21,7 @@ public:
~sm_db_insert() = default;
void add_options(po::options_description_easy_init &options) override {
- options
- ("file", po::value<string>()->required(), "The file to read");
+ options("file", po::value<string>()->required(), "The file to read");
}
int main(app_execution &execution) override {
@@ -42,31 +40,36 @@ public:
string mac = j["mac"]; // "aa:bb:cc:dd:ee:ff";
- auto rs = work.parameterized("select id from soil_moisture_device where mac=$1")(mac).exec();
+ auto select_device = "select id from soil_moisture_device where mac=$1";
+ auto rs = work.parameterized(select_device)(mac).exec();
if (!rs.size()) {
cout << "New device: " << mac << endl;
- rs = work.parameterized("insert into soil_moisture_device(mac) values($1) returning id")(mac).exec();
+ auto insert_device = "insert into soil_moisture_device(mac) values($1) returning id";
+ rs = work.parameterized(insert_device)(mac).exec();
}
auto deviceId = rs.begin()["id"].as<int>();
int sensor = j["sensor"];
- rs = work.parameterized("select id from soil_moisture_sensor where device=$1 and sensor=$2")(deviceId)(sensor).exec();
+ auto select_sensor = "select id from soil_moisture_sensor where device=$1 and sensor=$2";
+ rs = work.parameterized(select_sensor)(deviceId)(sensor).exec();
if (!rs.size()) {
cout << "New sensor: " << sensor << endl;
- rs = work.parameterized("insert into soil_moisture_sensor(device, sensor) values($1, $2) returning id")(deviceId)(sensor).exec();
+ auto insert_sensor = "insert into soil_moisture_sensor(device, sensor) values($1, $2) returning id";
+ rs = work.parameterized(insert_sensor)(deviceId)(sensor).exec();
}
auto sensorId = rs.begin()["id"].as<int>();
unsigned long timestamp = get<unsigned long>(j, "timestamp");
unsigned int value = get<unsigned int>(j, "value");
- work.parameterized("insert into soil_moisture_sample(sensor, timestamp, value) values($1, $2, $3)")(sensorId)(timestamp)(value).exec();
+ auto insert_sample = "insert into soil_moisture_sample(sensor, timestamp, value) values($1, $2, $3)";
+ work.parameterized(insert_sample)(sensorId)(timestamp)(value).exec();
cout << "Sample inserted" << endl;
@@ -75,6 +78,5 @@ public:
return EXIT_SUCCESS;
}
};
-
}
}
diff --git a/apps/sm-db-select.h b/apps/sm-db-select.h
index fcbe91b..78678c5 100644
--- a/apps/sm-db-select.h
+++ b/apps/sm-db-select.h
@@ -7,13 +7,12 @@
namespace trygvis {
namespace apps {
-template<class T>
+template <class T>
using o = boost::optional<T>;
using namespace std;
using json = nlohmann::json;
class sm_db_select : public app {
-
public:
sm_db_select() : app("sm-db-select") {
}
@@ -39,8 +38,8 @@ public:
auto deviceId = rs.begin()["id"].as<int>();
- rs = work.parameterized("select id from soil_moisture_sensor where device=$1 and sensor=$2")(deviceId)(
- sensor).exec();
+ rs = work.parameterized("select id from soil_moisture_sensor where device=$1 and sensor=$2")(deviceId)(sensor)
+ .exec();
if (!rs.size()) {
cout << "Unknown sensor: " << sensor << endl;
@@ -49,11 +48,11 @@ public:
auto sensorId = rs.begin()["id"].as<int>();
- rs = work.parameterized("select timestamp, sensor, value from soil_moisture_sample where sensor=$1")(
- sensorId).exec();
+ rs = work.parameterized("select timestamp, sensor, value from soil_moisture_sample where sensor=$1")(sensorId)
+ .exec();
json points = json::array();
- for (auto sample: rs) {
+ for (auto sample : rs) {
json s;
s.push_back(sample["timestamp"].as<unsigned long>());
s.push_back(sample["sensor"].as<unsigned long>());
@@ -74,8 +73,6 @@ public:
return EXIT_SUCCESS;
}
-
};
-
}
}
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:
}
}
};
-
}
}
diff --git a/apps/sm-serial-read-all.h b/apps/sm-serial-read-all.h
index 14cdf1e..b87727b 100644
--- a/apps/sm-serial-read-all.h
+++ b/apps/sm-serial-read-all.h
@@ -21,8 +21,8 @@ namespace sm_serial_read_all_utils {
class port_handler {
public:
- port_handler(string &port_name, serial_port &port, unique_ptr<SampleStreamParser> parser) :
- port_name(port_name), port(port), parser(move(parser)) {
+ port_handler(string &port_name, serial_port &port, unique_ptr<SampleStreamParser> parser)
+ : port_name(port_name), port(port), parser(move(parser)) {
}
void run() {
@@ -54,7 +54,6 @@ private:
unique_ptr<SampleStreamParser> parser;
};
-
}
// This only supports Linux
@@ -65,7 +64,7 @@ private:
vector<string> &&find_ports() {
DIR *dir = opendir("/dev");
- vector <string> ports;
+ vector<string> ports;
if (!dir) {
return move(ports);
@@ -100,13 +99,12 @@ public:
sample_format_type format;
void add_options(po::options_description_easy_init &options) override {
- options
- ("port", po::value<string>()->required(), "The serial port to read")
- ("format", po::value<sample_format_type>(&format)->default_value(sample_format_type::KEY_VALUE), "Output format");
+ options("port", po::value<string>()->required(), "The serial port to read");
+ options("format", po::value<sample_format_type>(&format)->default_value(sample_format_type::KEY_VALUE),
+ "Output format");
}
- static
- void handler_thread(port_handler *handler) {
+ static void handler_thread(port_handler *handler) {
handler->run();
}
@@ -150,7 +148,8 @@ public:
port.set_option(serial_port_base::flow_control(serial_port_base::flow_control::none));
KeyDictionary parserDict; // TODO: dette feiler
- unique_ptr<SampleStreamParser> parser = open_sample_stream_parser(thread_safe_output, parserDict, sample_format_type::KEY_VALUE);
+ unique_ptr<SampleStreamParser> parser =
+ open_sample_stream_parser(thread_safe_output, parserDict, sample_format_type::KEY_VALUE);
auto handler = new port_handler(port_name, port, move(parser));
active_ports[port_name] = handler;
@@ -163,8 +162,6 @@ public:
return EXIT_SUCCESS;
}
-
};
-
}
}
diff --git a/apps/sm-serial-read.h b/apps/sm-serial-read.h
index 7a6bcb4..dcfcc73 100644
--- a/apps/sm-serial-read.h
+++ b/apps/sm-serial-read.h
@@ -22,8 +22,8 @@ namespace sm_serial_read_utils {
class port_handler {
public:
- port_handler(string port_name, serial_port &serial_port, shared_ptr<KeyValueSampleStreamParser> input) :
- port_name(port_name), port(serial_port), input(input) {
+ port_handler(string port_name, serial_port &serial_port, shared_ptr<KeyValueSampleStreamParser> input)
+ : port_name(port_name), port(serial_port), input(input) {
}
void run() {
@@ -49,7 +49,6 @@ private:
shared_ptr<KeyValueSampleStreamParser> input;
};
-
}
class sm_serial_read : public app {
@@ -64,9 +63,9 @@ public:
sample_format_type format;
void add_options(po::options_description_easy_init &options) override {
- options
- ("port", po::value<string>()->required(), "The serial port to read")
- ("format", po::value<sample_format_type>(&format)->default_value(sample_format_type::KEY_VALUE), "Output format");
+ options("port", po::value<string>()->required(), "The serial port to read");
+ options("format", po::value<sample_format_type>(&format)->default_value(sample_format_type::KEY_VALUE),
+ "Output format");
}
int main(app_execution &execution) override {
@@ -103,8 +102,6 @@ public:
return EXIT_SUCCESS;
}
-
};
-
}
}