snapcast/server.cpp
(no author) ab215e07f5 chunks have shorts
git-svn-id: svn://elaine/murooma/trunk@61 d8a302eb-03bc-478d-80e4-98257eca68ef
2014-07-03 19:31:43 +00:00

74 lines
1.8 KiB
C++

//
// Weather update server in C++
// Binds PUB socket to tcp://*:5556
// Publishes random weather updates
//
// Olivier Chamoux <olivier.chamoux@fr.thalesgroup.com>
//
#include <zmq.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
#include <stdint.h>
#include "chunk.h"
#include "timeUtils.h"
using namespace std;
int main () {
// Prepare our context and publisher
zmq::context_t context (1);
zmq::socket_t publisher (context, ZMQ_PUB);
publisher.bind("tcp://0.0.0.0:123458");
// Initialize random number generator
size_t idx(0);
char c[2];
Chunk* chunk = new Chunk();
timeval ts;
ts.tv_sec = 0;
ts.tv_usec = 0;
timeval last;
gettimeofday(&last, NULL);
last.tv_sec -= 1000;
while (true)
{
c[0] = cin.get();
c[1] = cin.get();
chunk->payload[idx++] = 0;//(int)c[0] + ((int)c[1] * 256);
if (idx == WIRE_CHUNK_SIZE)
{
timeval now;
gettimeofday(&now, NULL);
if (diff_ms(now, last) > 200)
ts = now;
last = now;
// if (ts.tv_sec == 0)
// ts = now;
// else if (diff_ms(now, ts) > 1000)
// ts = now;
chunk->tv_sec = (int16_t)now.tv_sec;
chunk->tv_usec = 0;//now.tv_usec;
zmq::message_t message(8*2*WIRE_CHUNK_SIZE);//sizeof(Chunk));
memcpy(message.data(), chunk, 8+2*WIRE_CHUNK_SIZE);//sizeof(Chunk));
// snprintf ((char *) message.data(), size, "%05d %d", zipcode, c);
// message.data()[0] = c;
publisher.send(message);
/// addMs(ts, WIRE_CHUNK_MS);
idx = 0;
// msg[0] = '0';
}
}
delete chunk;
return 0;
}