git-svn-id: svn://elaine/murooma/trunk@5 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-06-24 20:01:15 +00:00
parent 429490e2e3
commit 105ac263c0
2 changed files with 28 additions and 15 deletions

View file

@ -9,6 +9,15 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
const size_t size(1024);
struct Chunk
{
time_t timestamp;
char payload[size];
};
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
zmq::context_t context (1); zmq::context_t context (1);
@ -24,9 +33,6 @@ int main (int argc, char *argv[])
// Process 100 updates // Process 100 updates
int update_nbr; int update_nbr;
long total_temp = 0; long total_temp = 0;
const size_t size(1024);
char msg[size];
// for (update_nbr = 0; update_nbr < 100; update_nbr++) {
while (1) while (1)
{ {
zmq::message_t update; zmq::message_t update;
@ -34,10 +40,13 @@ int main (int argc, char *argv[])
// std::cerr << "received\n"; // std::cerr << "received\n";
// std::istringstream iss(static_cast<char*>(update.data())); // std::istringstream iss(static_cast<char*>(update.data()));
// iss >> zipcode >> relhumidity; // iss >> zipcode >> relhumidity;
memcpy(&msg[0], update.data(), size); Chunk* chunk = new Chunk();
memcpy(chunk, update.data(), sizeof(Chunk));
// std::cout << "update\n"; // std::cout << "update\n";
for (size_t n=0; n<size; ++n) for (size_t n=0; n<size; ++n)
std::cout << msg[n] << std::flush; std::cout << chunk->payload[n] << std::flush;
delete chunk;
// std::cout << std::flush; // std::cout << std::flush;
// std::cerr << "flushed\n"; // std::cerr << "flushed\n";
} }

View file

@ -15,32 +15,36 @@
using namespace std; using namespace std;
const int size(1024);
struct Chunk
{
time_t timestamp;
char payload[size];
};
int main () { int main () {
// Prepare our context and publisher // Prepare our context and publisher
zmq::context_t context (1); zmq::context_t context (1);
zmq::socket_t publisher (context, ZMQ_PUB); zmq::socket_t publisher (context, ZMQ_PUB);
publisher.bind("tcp://0.0.0.0:123458"); publisher.bind("tcp://0.0.0.0:123458");
// publisher.bind("ipc://weather.ipc");
// Initialize random number generator // Initialize random number generator
srandom ((unsigned) time (NULL));
size_t idx(0); size_t idx(0);
const int size(1024);
char msg[size];
char c;//[2]; char c;//[2];
// msg[0] = '0'; Chunk chunk;
// int fd;
// fd = open("stdin", O_RDONLY|O_BINARY, 0);
while (!cin.get(c).eof()) while (!cin.get(c).eof())
{ {
if (idx == 0)
time(&chunk.timestamp);
// read(fd, &msg[0], size); // read(fd, &msg[0], size);
msg[idx++] = c; chunk.payload[idx++] = c;
if (idx == size) if (idx == size)
{ {
zmq::message_t message(size); zmq::message_t message(size);
memcpy(message.data(), &msg[0], size); memcpy(message.data(), &chunk, sizeof(Chunk));
// snprintf ((char *) message.data(), size, "%05d %d", zipcode, c); // snprintf ((char *) message.data(), size, "%05d %d", zipcode, c);
// message.data()[0] = c; // message.data()[0] = c;
publisher.send(message); publisher.send(message);