Correction Raw conversion of timestamp

This commit is contained in:
glenux 2006-03-04 22:24:36 +00:00
parent 43d2843829
commit 05100ddf29
4 changed files with 18 additions and 7 deletions

View file

@ -25,9 +25,12 @@ TimeStamp ClockCb::inc(){
// lock jusqu'a la fin de la fonction // lock jusqu'a la fin de la fonction
Glib::Mutex::Lock lock(_mutex); 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. // 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; _ticks[_cur_index] = _ticks[_cur_index] + 1;
printf("to %d\n", _ticks[_cur_index]);
TimeStamp ts(Protocol::TYPE_CBCAST, _cur_index); TimeStamp ts(Protocol::TYPE_CBCAST, _cur_index);
// on push tous les ticks de l'horloge // on push tous les ticks de l'horloge
@ -37,3 +40,4 @@ TimeStamp ClockCb::inc(){
} }
return ts; return ts;
} }

View file

@ -66,7 +66,7 @@ void LowReceiver::run(){
&sockaddr_len); &sockaddr_len);
mesg = new Message(buffer, read_buffer_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]; char * str = new char[mesg->getDataSize() + 1];
strncpy(str, mesg->getData(), mesg->getDataSize()); strncpy(str, mesg->getData(), mesg->getDataSize());
str[mesg->getDataSize()] = '\0'; str[mesg->getDataSize()] = '\0';

View file

@ -3,8 +3,8 @@
#include "message.h" #include "message.h"
#define DEBUG_INPUT 0 #define DEBUG_INPUT 1
#define DEBUG_OUTPUT 0 #define DEBUG_OUTPUT 1
Message::Message(const Message & original){ Message::Message(const Message & original){
printf("Message::Message -- copy\n"); printf("Message::Message -- copy\n");

View file

@ -3,7 +3,7 @@
#include "timestamp.h" #include "timestamp.h"
#define DEBUG 0 #define DEBUG 1
TimeStamp::TimeStamp(Protocol::Type type, short index){ TimeStamp::TimeStamp(Protocol::Type type, short index){
_index = index; _index = index;
@ -34,9 +34,13 @@ TimeStamp::TimeStamp(Protocol::Type type, char * raw, unsigned short raw_size){
_index = ntohs(_index); _index = ntohs(_index);
pos_idx += 2; pos_idx += 2;
// on cherche ensuite la taille totale
// de l'horloge
memcpy(&stamp_len, (raw + pos_idx), 2); memcpy(&stamp_len, (raw + pos_idx), 2);
stamp_len = ntohs(stamp_len); stamp_len = ntohs(stamp_len);
pos_idx += 2; pos_idx += 2;
// on choppe ensuite 'stamp_len' shorts
} }
break; break;
case Protocol::TYPE_TEST : case Protocol::TYPE_TEST :
@ -120,15 +124,18 @@ char * TimeStamp::getRaw(){
case Protocol::TYPE_CBCAST : case Protocol::TYPE_CBCAST :
{ {
result_len = 2; // 2 bytes for site index 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_len += 2 * this->size(); // 2 bytes per site-clock value
result = new char[result_len]; result = new char[result_len];
short index_value = htons(_index); short index_value = htons(_index);
short count_value = htons(this->size());
//FIXME: if (DEBUG) //FIXME: if (DEBUG)
printf("TimeStamp::raw -- (CBCAST) index_value %d -> %d\n", _index, index_value); printf("TimeStamp::raw -- (CBCAST) index_value %d -> %d\n", _index, index_value);
memcpy(result, &index_value, 2); memcpy(result, &index_value, 2);
memcpy(result + 2, &count_value, 2);
short host_clock_value, net_clock_value; short host_clock_value, net_clock_value;
for (int idx = 0; idx < this->size(); idx++){ for (int idx = 0; idx < this->size(); idx++){
@ -140,7 +147,7 @@ char * TimeStamp::getRaw(){
host_clock_value, host_clock_value,
net_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 &net_clock_value, 2); // on fixe l'index dans le résultat
} }
@ -168,7 +175,7 @@ unsigned short TimeStamp::getRawSize(){
break; break;
case Protocol::TYPE_CBCAST : 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; break;
default: default: