aboutsummaryrefslogtreecommitdiff
path: root/apps/sm-serial-read.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-03-04 23:02:15 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-03-04 23:02:15 +0100
commite03bf5d416776cb5ea27c7354657920939c04e71 (patch)
tree184e66ef69966c7671ef2f3d4750283bb0b4f149 /apps/sm-serial-read.cpp
parent4fa6e39b7e74761dc54b6203cd05c8d5b89cb7c8 (diff)
downloadble-toys-e03bf5d416776cb5ea27c7354657920939c04e71.tar.gz
ble-toys-e03bf5d416776cb5ea27c7354657920939c04e71.tar.bz2
ble-toys-e03bf5d416776cb5ea27c7354657920939c04e71.tar.xz
ble-toys-e03bf5d416776cb5ea27c7354657920939c04e71.zip
o Adding the hostname to the data.
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;
}