aboutsummaryrefslogtreecommitdiff
path: root/apps/sm-serial-read.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'apps/sm-serial-read.cpp')
-rw-r--r--apps/sm-serial-read.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/apps/sm-serial-read.cpp b/apps/sm-serial-read.cpp
index ff311a1..f1cabad 100644
--- a/apps/sm-serial-read.cpp
+++ b/apps/sm-serial-read.cpp
@@ -56,10 +56,13 @@ using namespace trygvis::apps;
namespace po = boost::program_options;
using json = nlohmann::json;
+Format format;
+string hostname = get_hostname();
+
class port_handler {
public:
- port_handler(Format format, string device, serial_port &serial_port) :
- format(format), device(device), port(serial_port) {
+ port_handler(string device, serial_port &serial_port) :
+ device(device), port(serial_port) {
}
void run() {
@@ -103,6 +106,7 @@ public:
static const string device_type = "serial";
if (format == Format::JSON) {
json j;
+ j["hostname"] = hostname;
j["device_type"] = device_type;
j["device"] = device;
j["timestamp"] = timestamp;
@@ -110,14 +114,15 @@ public:
j["value"] = value;
cout << j << endl;
} else if (format == Format::SQL) {
- cout << "INSERT INTO serial_sample(device_type, device, sensor, timestamp, value) VALUES("
+ cout << "INSERT INTO serial_sample(hostname, device_type, device, sensor, timestamp, value) VALUES("
+ << hostname << ", "
<< device_type << ", "
<< device << ", "
<< timestamp << ", "
<< sensor << ", "
<< value << ");"
<< endl;
- } else {// plain
+ } else { // plain
cout << "sensor #" << sensor << " = " << value << endl;
}
@@ -131,15 +136,12 @@ private:
static const uint8_t packet_delimiter = '\n';
string device;
serial_port &port;
- Format format;
uint8_t data[size];
mutable_buffers_1 buffer = boost::asio::buffer(data, size);
};
class sm_serial_read : public app {
- Format format;
-
public:
void add_options(po::options_description_easy_init &options) override {
options
@@ -170,7 +172,7 @@ public:
cerr << "port is not open" << endl;
}
- port_handler(format, port_name, port).run();
+ port_handler(port_name, port).run();
return EXIT_SUCCESS;
}