Ejemplo n.º 1
0
void TeamHandler::send()
{
  if(!port)
    return; // not started yet

  if(!out.isEmpty())
  {
    OutBinarySize size;
    size << out;
    char* package = new char[size.getSize() + 4];
    ASSERT(package);
    OutBinaryMemory memory(package + 4);
    memory << out;
    ((unsigned short*) package)[1] = size.getSize() + 4;
    ((unsigned short*) package)[0] = calcCRC16(package + 2, size.getSize() + 2);

    sockaddr_in address;
    address.sin_family = AF_INET;
    address.sin_port = htons(port);
    address.sin_addr.s_addr = INADDR_BROADCAST;
    if(sendto(udpSocket, package, size.getSize() + 4, 0, (struct sockaddr *) &address, sizeof(address)) == (int)size.getSize() + 4)
      out.clear();

    delete [] package;
  }
}
Ejemplo n.º 2
0
void TeamHandler::send()
{
    if(!port || out.isEmpty())
        return;

    const int teamCommHeaderSize = localId ? 8 : 6;
    char buffer[1400];

    OutBinarySize sizeStream;
    sizeStream << out;
    int size = sizeStream.getSize() + teamCommHeaderSize;
    if(size > int(sizeof(buffer)))
    {
        out.clear();
        return;
    }

    OutBinaryMemory memory(buffer + teamCommHeaderSize);
    memory << out;
    // TeamComm header (remote)
    // Byte |  0  1  2  3   |    4    5    |
    //      |   timestamp   | payload size |
    // TeamComm header (local)
    // Byte |  0  1  2  3   |    4    5    |   6  7   |
    //      |   timestamp   | payload size | local ID |
    ((unsigned int*)buffer)[0] = SystemCall::getCurrentSystemTime();
    ((unsigned short*)buffer)[2] = (unsigned short) size;
    if(localId)
    {
        ((unsigned short*)buffer)[3] = localId;
    }

    if(socket.write(buffer, size))
        out.clear();
}
Ejemplo n.º 3
0
int RemoteRobot::main() 
{
  unsigned char* sendData = 0,
               * receivedData;
  int sendSize = 0,
      receivedSize = 0;
  MessageQueue temp;

  {
    // If there is something to send, prepare a package
    if(!theDebugSender.isEmpty())
    {
      SYNC;
      OutBinarySize size;
      size << theDebugSender;
      sendSize = size.getSize();
      sendData = new unsigned char[sendSize];
      OutBinaryMemory stream(sendData);
      stream << theDebugSender;
      // make backup
      theDebugSender.moveAllMessages(temp);
    }
  }

  // exchange data with the router
  if(!sendAndReceive(sendData,sendSize,receivedData,receivedSize) && sendSize)
  { // sending failed, restore theDebugSender
    SYNC;
    // move all messages since cleared (if any)
    theDebugSender.moveAllMessages(temp);
    // restore
    temp.moveAllMessages(theDebugSender);
  }

  // If a package was prepared, remove it
  if(sendSize)
  {
    delete [] sendData;
    sendSize = 0;
  }

  // If a package was received from the router program, add it to receiver queue
  if(receivedSize > 0)
  {
    SYNC;
    InBinaryMemory stream(receivedData,receivedSize);
    stream >> theDebugReceiver;
    delete [] receivedData;
  }
Ejemplo n.º 4
0
std::size_t LogConverter::sizeofRepresentation(const Streamable& streamable)
{
  OutBinarySize outSize;
  outSize << streamable;
  return outSize.getSize();
}