mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-21 04:56:13 +02:00
xxx
git-svn-id: svn://elaine/murooma/trunk@10 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
2e19145eda
commit
77bd2b44d7
1 changed files with 22 additions and 7 deletions
29
client.cpp
29
client.cpp
|
@ -10,12 +10,12 @@
|
|||
#include <sstream>
|
||||
#include <sys/time.h>
|
||||
|
||||
const size_t size(1024);
|
||||
const size_t size(1764);
|
||||
|
||||
struct Chunk
|
||||
{
|
||||
long tv_sec;
|
||||
long tv_usec;
|
||||
int32_t tv_sec;
|
||||
int32_t tv_usec;
|
||||
char payload[size];
|
||||
};
|
||||
|
||||
|
@ -33,6 +33,13 @@ std::string timeToStr(const timeval& timestamp)
|
|||
}
|
||||
|
||||
|
||||
int diff_ms(const timeval& t1, const timeval& t2)
|
||||
{
|
||||
return (((t1.tv_sec - t2.tv_sec) * 1000000) +
|
||||
(t1.tv_usec - t2.tv_usec))/1000;
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
zmq::context_t context (1);
|
||||
|
@ -48,25 +55,33 @@ int main (int argc, char *argv[])
|
|||
// Process 100 updates
|
||||
int update_nbr;
|
||||
long total_temp = 0;
|
||||
int i = 0;
|
||||
while (1)
|
||||
{
|
||||
zmq::message_t update;
|
||||
subscriber.recv(&update);
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
// std::cerr << "received\n";
|
||||
// std::istringstream iss(static_cast<char*>(update.data()));
|
||||
// iss >> zipcode >> relhumidity;
|
||||
Chunk* chunk = new Chunk();
|
||||
memcpy(chunk, update.data(), sizeof(Chunk));
|
||||
|
||||
timeval ts;
|
||||
ts.tv_sec = chunk->tv_sec;
|
||||
ts.tv_usec = chunk->tv_usec;
|
||||
if (i++ == 100)
|
||||
{
|
||||
std::cerr << diff_ms(now, ts) << "\n" << std::flush;//timeToStr(ts) << "\t" << chunk->tv_usec << "\n";
|
||||
i = 0;
|
||||
}
|
||||
|
||||
// std::cout << "update\n";
|
||||
for (size_t n=0; n<size; ++n)
|
||||
std::cout << chunk->payload[n] << std::flush;
|
||||
|
||||
// std::cerr << (chunk->timestamp).tv_sec << ":" << (chunk->timestamp).tv_usec << "\n";
|
||||
timeval ts;
|
||||
ts.tv_sec = chunk->tv_sec;
|
||||
ts.tv_usec = chunk->tv_usec;
|
||||
std::cerr << timeToStr(ts) << "\t" << chunk->tv_usec << "\n";
|
||||
delete chunk;
|
||||
// std::cout << std::flush;
|
||||
// std::cerr << "flushed\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue