-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathZMQSensorPublisher.cpp
40 lines (31 loc) · 1.14 KB
/
ZMQSensorPublisher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <syslog.h>
#include <vector>
#include <sstream>
#include "ZMQSensorPublisher.hpp"
#include "ZMQSendUtils.hpp"
ZMQSensorPublisher::ZMQSensorPublisher():context(1), socket(context, ZMQ_PUSH){
stringstream socketAddressStream;
socketAddressStream << "tcp://localhost:" << PUSH_PORT;
syslog(LOG_DAEMON|LOG_INFO, "Socket address %s",socketAddressStream.str().c_str());
socket.connect(socketAddressStream.str().c_str());
int highWaterMark = 3;
socket.setsockopt(ZMQ_SNDHWM, &highWaterMark, sizeof(highWaterMark));
}
ZMQSensorPublisher::~ZMQSensorPublisher(){
}
void ZMQSensorPublisher::sensorStarting(){
}
void ZMQSensorPublisher::processReading(const SensorReadingSet& set){
if(set.readings.size() > 0){
stringstream datastream;
datastream << set.readings[0].text;
vector<SensorReading>::const_iterator it;
for(it = set.readings.begin()+1; it != set.readings.end(); ++it){
datastream << "," << it->text;
}
string dataString = datastream.str();
sendLirMessage(socket, 'S', set.sensorID, set.time, dataString);
}
}
void ZMQSensorPublisher::sensorStopping(){
}