From 05100ddf2952e3d8caa9d40476eedd66bd8c6054 Mon Sep 17 00:00:00 2001 From: glenux Date: Sat, 4 Mar 2006 22:24:36 +0000 Subject: [PATCH] Correction Raw conversion of timestamp --- src/clock_cb.cc | 6 +++++- src/lowreceiver.cc | 2 +- src/message.cc | 4 ++-- src/timestamp.cc | 13 ++++++++++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/clock_cb.cc b/src/clock_cb.cc index ccfa57f..053f40d 100644 --- a/src/clock_cb.cc +++ b/src/clock_cb.cc @@ -25,9 +25,12 @@ TimeStamp ClockCb::inc(){ // lock jusqu'a la fin de la fonction Glib::Mutex::Lock lock(_mutex); - printf("ClockAb::inc -- creating timestamp\n"); + printf("ClockCb::inc -- creating timestamp\n"); // FIXME incrémenter le nombre de messages émis localement. + + printf("ClockCb::inc -- cur_index from %d ", _ticks[_cur_index]); _ticks[_cur_index] = _ticks[_cur_index] + 1; + printf("to %d\n", _ticks[_cur_index]); TimeStamp ts(Protocol::TYPE_CBCAST, _cur_index); // on push tous les ticks de l'horloge @@ -37,3 +40,4 @@ TimeStamp ClockCb::inc(){ } return ts; } + diff --git a/src/lowreceiver.cc b/src/lowreceiver.cc index 4b53350..a2ff4f1 100644 --- a/src/lowreceiver.cc +++ b/src/lowreceiver.cc @@ -66,7 +66,7 @@ void LowReceiver::run(){ &sockaddr_len); mesg = new Message(buffer, read_buffer_len); - printf("LowReceiver::run -- READ\n"); + printf("LowReceiver::run -- READ size %d\n", read_buffer_len); char * str = new char[mesg->getDataSize() + 1]; strncpy(str, mesg->getData(), mesg->getDataSize()); str[mesg->getDataSize()] = '\0'; diff --git a/src/message.cc b/src/message.cc index 7d1bc59..b9a26e1 100644 --- a/src/message.cc +++ b/src/message.cc @@ -3,8 +3,8 @@ #include "message.h" -#define DEBUG_INPUT 0 -#define DEBUG_OUTPUT 0 +#define DEBUG_INPUT 1 +#define DEBUG_OUTPUT 1 Message::Message(const Message & original){ printf("Message::Message -- copy\n"); diff --git a/src/timestamp.cc b/src/timestamp.cc index b29ffce..cd3b419 100644 --- a/src/timestamp.cc +++ b/src/timestamp.cc @@ -3,7 +3,7 @@ #include "timestamp.h" -#define DEBUG 0 +#define DEBUG 1 TimeStamp::TimeStamp(Protocol::Type type, short index){ _index = index; @@ -34,9 +34,13 @@ TimeStamp::TimeStamp(Protocol::Type type, char * raw, unsigned short raw_size){ _index = ntohs(_index); pos_idx += 2; + // on cherche ensuite la taille totale + // de l'horloge memcpy(&stamp_len, (raw + pos_idx), 2); stamp_len = ntohs(stamp_len); pos_idx += 2; + + // on choppe ensuite 'stamp_len' shorts } break; case Protocol::TYPE_TEST : @@ -120,15 +124,18 @@ char * TimeStamp::getRaw(){ case Protocol::TYPE_CBCAST : { result_len = 2; // 2 bytes for site index + result_len += 2; // 2 bytes for site count result_len += 2 * this->size(); // 2 bytes per site-clock value result = new char[result_len]; short index_value = htons(_index); + short count_value = htons(this->size()); //FIXME: if (DEBUG) printf("TimeStamp::raw -- (CBCAST) index_value %d -> %d\n", _index, index_value); memcpy(result, &index_value, 2); + memcpy(result + 2, &count_value, 2); short host_clock_value, net_clock_value; for (int idx = 0; idx < this->size(); idx++){ @@ -140,7 +147,7 @@ char * TimeStamp::getRaw(){ host_clock_value, net_clock_value); - memcpy((result + 2 + idx * 2), + memcpy((result + 4 + idx * 2), &net_clock_value, 2); // on fixe l'index dans le résultat } @@ -168,7 +175,7 @@ unsigned short TimeStamp::getRawSize(){ break; case Protocol::TYPE_CBCAST : { - result = 2 + (2 * this->size()); // FIXME: plus la taille du vecteur * 2; + result = 4 + (2 * this->size()); // FIXME: plus la taille du vecteur * 2; } break; default: