Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5735 in orxonox.OLD for branches/network/src/lib


Ignore:
Timestamp:
Nov 23, 2005, 3:13:01 PM (19 years ago)
Author:
bwuest
Message:

network_protocol.cc and network_protocol.h changed

Location:
branches/network/src/lib/network
Files:
2 edited

Legend:

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

    r5617 r5735  
    2727#include "netdefs.h"
    2828
     29/* include this file for debugging */
     30#include "debug.h"
     31
    2932/* using namespace std is default, this needs to be here */
    3033using namespace std;
    31 
    32 
    33 
    34 
    35 
    36 
    37 
    38 
    39 
    40 
    41 
    42 
    43 
    44 
    45 
    46 
    47 
    48 
    49 
    5034
    5135
     
    6650
    6751/**
     52    * creates a new packet header from the function arguments
     53    *
     54    * @arg data: the binary data without header -> return the data in this binary array
     55    * @arg length: the data length without header
     56    * @arg bufferLength: the length of the internal buffer
     57    * @arg source: reference to the source Synchronizeable object
     58    * @arg remoteID: id number of the remote Synchronizeable object
     59    * @return: the new data length with header (the header data is included into byte* data)
     60    *          -1 if there isn't enough space in the buffer for the header
     61*/
     62NetworkProtocol::createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source, unsigned int remoteID)
     63{
     64  //If there isn't enough space for the header return -1
     65  if (length + headerLength > bufferLength)
     66    return -1;
     67 
     68  //Create space for the header
     69  for (unsigned int i = length - 1; i >= 0; i--)
     70    data[i + headerLength] = data[i];
     71 
     72  //Include header
     73  data[0] = 255;
     74}
    6875
     76/**
     77    * extracts the header from the binary data stream
     78    * @arg data: the binary data with the header
     79    * @arg length: the length of the binary data (including header)
     80    * @return: a Header struct with the header information and the binary data
    6981*/
    70 void NetworkProtocol::writeDataField( /* Attribute: Any*/ )
     82Header NetworkProtocol::ExtractHeader(byte* data, int length)
    7183{
     84  //Test if received data can contain a header
     85  if (length < headerLength)
     86  {
     87    PRINTF(0)("Received data is to short; it can't contain a header!");
     88    Header h;
     89    h.protocol = -1;
     90    return h;
     91  }
     92 
     93  //Extract header
     94  Header h;
     95  h.protocol = data[0];
     96 
     97  h.length = length - headerLength;
     98  h.data = data;
     99 
     100  //Remove header
     101  for (int i = headerLength; i < length; i++)
     102    data[i - headerLength] = data[i];
     103 
     104  return h;
    72105}
  • branches/network/src/lib/network/network_protocol.h

    r5617 r5735  
    88#include "base_object.h"
    99
     10
     11typedef struct Header
     12{
     13  byte protocol;
     14  byte version;
     15  byte senderID;
     16  byte receiverID;
     17  byte length;
     18  byte* data;
     19};
     20
    1021/*!
    1122
     
    1627    NetworkProtocol();
    1728    ~NetworkProtocol();
    18     void writeDataField( /* Attribute: Any*/ );
     29
     30    int createHeader(byte* data, int length, int bufferLength, const Synchronizeable& source, unsigned int remoteID);
     31    Header ExtractHeader(byte* data, int length);
    1932
    2033  private:
    21    
     34    const unsigned int headerLength = 1; //The Length of the Header in bytes
     35    dataFields dFields;
    2236
    2337};
Note: See TracChangeset for help on using the changeset viewer.