rllib  1
Defines | Enumerations | Functions
rleibnetip.cpp File Reference
#include "rleibnetip.h"
#include "rltime.h"
#include "rldataacquisitionprovider.h"
#include <stdio.h>
#include <string.h>
#include <math.h>
Include dependency graph for rleibnetip.cpp:

Go to the source code of this file.

Defines

#define EIB_HEADERSIZE   6
#define EIB_VERSION   0x10
#define EIB_ADRSIZE   8
#define EIB_CRICRDSIZE   4
#define TUNNEL_CONNECTION   4
#define REMLOG_CONNECTION   6
#define OBJSVR_CONNECTION   8
#define TUNNEL_LINKLAYER   2
#define E_NO_ERROR   0
#define E_NO_MORE_CONNECTIONS   0x24
#define E_SEQUENCE_NUMBER   0x04
#define L_Data_Req   0x11
#define L_Data_Con   0x2E
#define L_Data_Ind   0x29

Enumerations

enum  ServiceType {
  SEARCH_REQUEST = 0x0201, SEARCH_RESPONSE = 0x0202, DESCRIPTION_REQUEST = 0x0203, DESCRIPTION_RESPONSE = 0x0204,
  CONNECT_REQUEST = 0x0205, CONNECT_RESPONSE = 0x0206, CONNECTIONSTATE_REQUEST = 0x0207, CONNECTIONSTATE_RESPONSE = 0x0208,
  DISCONNECT_REQUEST = 0x0209, DISCONNECT_RESPONSE = 0x020A, TUNNELLING_REQUEST = 0x0420, TUNNELLING_ACK = 0x0421
}

Functions

static void * eib_reader (void *arg)

Define Documentation

#define E_NO_ERROR   0

Definition at line 32 of file rleibnetip.cpp.

#define E_NO_MORE_CONNECTIONS   0x24

Definition at line 33 of file rleibnetip.cpp.

#define E_SEQUENCE_NUMBER   0x04

Definition at line 34 of file rleibnetip.cpp.

#define EIB_ADRSIZE   8

Definition at line 25 of file rleibnetip.cpp.

#define EIB_CRICRDSIZE   4

Definition at line 27 of file rleibnetip.cpp.

#define EIB_HEADERSIZE   6

Definition at line 23 of file rleibnetip.cpp.

#define EIB_VERSION   0x10

Definition at line 24 of file rleibnetip.cpp.

#define L_Data_Con   0x2E

Definition at line 37 of file rleibnetip.cpp.

#define L_Data_Ind   0x29

Definition at line 38 of file rleibnetip.cpp.

#define L_Data_Req   0x11

Definition at line 36 of file rleibnetip.cpp.

#define OBJSVR_CONNECTION   8

Definition at line 30 of file rleibnetip.cpp.

#define REMLOG_CONNECTION   6

Definition at line 29 of file rleibnetip.cpp.

#define TUNNEL_CONNECTION   4

Definition at line 28 of file rleibnetip.cpp.

#define TUNNEL_LINKLAYER   2

Definition at line 31 of file rleibnetip.cpp.


Enumeration Type Documentation

Enumerator:
SEARCH_REQUEST 
SEARCH_RESPONSE 
DESCRIPTION_REQUEST 
DESCRIPTION_RESPONSE 
CONNECT_REQUEST 
CONNECT_RESPONSE 
CONNECTIONSTATE_REQUEST 
CONNECTIONSTATE_RESPONSE 
DISCONNECT_REQUEST 
DISCONNECT_RESPONSE 
TUNNELLING_REQUEST 
TUNNELLING_ACK 

Definition at line 40 of file rleibnetip.cpp.


Function Documentation

static void* eib_reader ( void *  arg) [static]

Definition at line 56 of file rleibnetip.cpp.

{
  THREAD_PARAM *p = (THREAD_PARAM *) arg;
  rlEIBnetIP *eib = (rlEIBnetIP *) p->user;
  rlEIBnetIP::PDU pdu;
  rlTime now, last, diff;
  int ret, len;
  int recseq = 0;
  int expected_recseq = 0;
  unsigned char b[4];

  last.getLocalTime();
  while(eib->running)
  {
    if(eib->isConnected() == 0)
    {
      eib->connect();
      expected_recseq = 0;
      last.getLocalTime();
    }
    ret = eib->recv(&pdu, sizeof(pdu));
    now.getLocalTime();
    if(ret > 0)
    {
      switch (ntohs(pdu.servicetype))
      {
        case DISCONNECT_REQUEST:
          eib->disconnect();
          expected_recseq = 0;
          break;
        case CONNECTIONSTATE_RESPONSE:
          if(eib->debug) ::printf("eib_reader() CONNECTIONSTATE_RESPONSE\n");
          break;
        case TUNNELLING_REQUEST:
          if(eib->debug)
            ::printf("eib_reader() TUNNELING_REQUEST sequenzecounter=%d\n",recseq);
          recseq = pdu.data[2];                 // sequencecounter
          b[0]   = pdu.data[0];                 // remember 4 bytes of data
          b[1]   = pdu.data[1];
          b[2]   = pdu.data[2];
          b[3]   = pdu.data[3];
          len    = ntohs(pdu.totalsize) - 6;    // remember len (-headerlength)
          pdu.headersize  = EIB_HEADERSIZE;     // fill acknowledge
          pdu.version     = EIB_VERSION;
          pdu.servicetype = htons(TUNNELLING_ACK);
          pdu.totalsize   = htons(EIB_HEADERSIZE+4);
          pdu.data[0]     = 4;                  // structlength
          pdu.data[1]     = eib->channelid;     // channelid
          pdu.data[2]     = recseq;             // sequencecounter
          pdu.data[3]     = E_NO_ERROR;         // typespecific
          if(recseq != expected_recseq)
          {
            if(eib->debug)
              ::printf("eib_reader() recseq=%d expected_recseq=%d\n",recseq,expected_recseq);
            // we simply ignore the sequencecounter
            // pdu.data[4] = E_SEQUENCE_NUMBER;
          }
          expected_recseq = (expected_recseq+1) & 0x0ff;
          eib->rlUdpSocket::sendto(&pdu, ntohs(pdu.totalsize), eib->server);
          pdu.data[0] = b[0];                   // restore received data
          pdu.data[1] = b[1];
          pdu.data[2] = b[2];
          pdu.data[3] = b[3];
          eib->storeBuffer(&pdu.data[4],len-4); // +EIBNETIP_COMMON_CONNECTION_HEADER
          break;
        case TUNNELLING_ACK:
          if(pdu.data[3] == E_NO_ERROR)
          {
            eib->tunnel_ack = 1;
            if(eib->debug) ::printf("eib_reader() TUNNELLING_ACK typespecific=0x%x\n",pdu.data[3]);
          }
          else
          {
            eib->tunnel_ack = -1;
            if(eib->debug) ::printf("eib_reader() TUNNELLING_NACK typespecific=0x%x\n",pdu.data[3]);
          }
          break;
        default:
          ::printf("eib_reader() unknown servicetype=0x%x\n",ntohs(pdu.servicetype));
          break;
      }
    }
    diff = now - last;
    if(eib->isConnected() && eib->channelid != -1 && diff.second > 50)
    { // send heartbeat
      if(eib->debug) ::printf("send heartbeat\n");
      pdu.headersize  = EIB_HEADERSIZE;
      pdu.version     = EIB_VERSION;
      pdu.servicetype = htons(CONNECTIONSTATE_REQUEST);
      pdu.totalsize   = htons(EIB_HEADERSIZE+EIB_ADRSIZE*2+EIB_CRICRDSIZE);
      pdu.data[0]     = eib->channelid;
      pdu.data[1]     = 0;
      eib->rlUdpSocket::sendto(&pdu, ntohs(pdu.totalsize), eib->server);
      last.getLocalTime();
    }
  }
  return NULL;
  /*
  for(int i=0; i<50; i++)
  {
    p->thread->lock();
    //do something critical
    printf("this is the thread\n");
    p->thread->unlock();
  }
  */
}