Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6341 in orxonox.OLD for trunk/src/lib/network/network_protocol.cc


Ignore:
Timestamp:
Dec 30, 2005, 1:57:12 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the network branche back to the trunk, so we do not get away from each other to fast

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/network_protocol.cc

    r6139 r6341  
    3030#include "debug.h"
    3131
     32#include "converter.h"
     33
    3234/* using namespace std is default, this needs to be here */
    3335using namespace std;
     
    4143  /* set the class id for the base object */
    4244  this->setClassID(CL_NETWORK_PROTOCOL, "NetworkProtocol");
    43   this->headerLength = sizeof(Header);
     45  this->headerLength = INTSIZE+FLOATSIZE;
    4446}
    4547
     
    6466  PRINTF(5)("create header length = %i, bufferLength = %i\n", length, bufferLength);
    6567  //If there isn't enough space for the header return -1
    66   if (length + this->headerLength > bufferLength)
     68  if (length + 2*INTSIZE > bufferLength)
    6769    return -1;
    6870
     
    7072  // FIXME: without move Create space for the header
    7173  for( int i = length - 1; i >= 0; i--)
    72     data[i + this->headerLength] = data[i];
     74    data[i + INTSIZE+INTSIZE] = data[i];
    7375
    7476  //Now create the header
    7577  /* sender ID: FIXME: there will be a better ID (for example unique:D)*/
    76   data[0] = (byte)(source.getUniqueID());
     78  //data[0] = (byte)(source.getUniqueID());
     79  int res = Converter::intToByteArray( source.getUniqueID(), data, bufferLength );
     80
    7781  /* data length*/
    78   data[1] = length;
     82  //data[1] = length;
     83  res += Converter::intToByteArray( length, data+res, bufferLength-res );
    7984
    8085
    81   return length + this->headerLength;
     86  return length + res;
    8287}
    8388
     
    9297  PRINTF(5)("extract Header\n");
    9398  //Test if received data can contain a header
    94   if (length < headerLength)
     99  if (length < 2*INTSIZE)
    95100  {
    96101    PRINTF(1)("Received data is to short; it can't contain a header!\n");
     
    105110
    106111  /* unique ID */
    107   h.synchronizeableID = data[0];
     112  //h.synchronizeableID = data[0];
     113  int res = Converter::byteArrayToInt( data, &(h.synchronizeableID) );
    108114  /* data length*/
    109   h.length = data[1];
     115  //h.length = data[1];
     116  Converter::byteArrayToInt( data+res, &(h.length) );
    110117
    111118
Note: See TracChangeset for help on using the changeset viewer.