server timing

git-svn-id: svn://elaine/murooma/trunk@80 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-07-09 17:00:38 +00:00
parent 8f6e32cc76
commit 72dcc37d57

View file

@ -28,46 +28,34 @@ int main () {
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");
// Initialize random number generator
size_t idx(0);
char c[2]; char c[2];
Chunk* chunk = new Chunk(); Chunk* chunk = new Chunk();
timeval ts; timeval now;
ts.tv_sec = 0; gettimeofday(&now, NULL);
ts.tv_usec = 0; long nextTick = getTickCount();
timeval last;
gettimeofday(&last, NULL);
last.tv_sec -= 1000;
while (cin.good()) while (cin.good())
{ {
c[0] = cin.get(); long currentTick = getTickCount();
c[1] = cin.get(); nextTick += WIRE_CHUNK_MS;
chunk->payload[idx++] = (int)c[0] + ((int)c[1] * 256); for (size_t n=0; (n<WIRE_CHUNK_SIZE) && cin.good(); ++n)
if (idx == WIRE_CHUNK_SIZE) {
{ c[0] = cin.get();
timeval now; c[1] = cin.get();
gettimeofday(&now, NULL); chunk->payload[n] = (int)c[0] + ((int)c[1] * 256);
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 = ts.tv_sec; chunk->tv_sec = now.tv_sec;
chunk->tv_usec = ts.tv_usec; chunk->tv_usec = now.tv_usec;
chunk->idx = 0; chunk->idx = 0;
zmq::message_t message(sizeof(Chunk)); zmq::message_t message(sizeof(Chunk));
memcpy(message.data(), chunk, sizeof(Chunk)); memcpy(message.data(), chunk, sizeof(Chunk));
// snprintf ((char *) message.data(), size, "%05d %d", zipcode, c); publisher.send(message);
// message.data()[0] = c; addMs(now, WIRE_CHUNK_MS);
publisher.send(message);
addMs(ts, WIRE_CHUNK_MS); if (nextTick - currentTick > 0)
idx = 0; {
// msg[0] = '0'; usleep((nextTick - currentTick) * 1000);
} }
} }
delete chunk; delete chunk;
return 0; return 0;