rllib  1
Macros | 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.

Macros

#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)
 

Macro Definition Documentation

◆ E_NO_ERROR

#define E_NO_ERROR   0

Definition at line 32 of file rleibnetip.cpp.

◆ E_NO_MORE_CONNECTIONS

#define E_NO_MORE_CONNECTIONS   0x24

Definition at line 33 of file rleibnetip.cpp.

◆ E_SEQUENCE_NUMBER

#define E_SEQUENCE_NUMBER   0x04

Definition at line 34 of file rleibnetip.cpp.

◆ EIB_ADRSIZE

#define EIB_ADRSIZE   8

Definition at line 25 of file rleibnetip.cpp.

◆ EIB_CRICRDSIZE

#define EIB_CRICRDSIZE   4

Definition at line 27 of file rleibnetip.cpp.

◆ EIB_HEADERSIZE

#define EIB_HEADERSIZE   6

Definition at line 23 of file rleibnetip.cpp.

◆ EIB_VERSION

#define EIB_VERSION   0x10

Definition at line 24 of file rleibnetip.cpp.

◆ L_Data_Con

#define L_Data_Con   0x2E

Definition at line 37 of file rleibnetip.cpp.

◆ L_Data_Ind

#define L_Data_Ind   0x29

Definition at line 38 of file rleibnetip.cpp.

◆ L_Data_Req

#define L_Data_Req   0x11

Definition at line 36 of file rleibnetip.cpp.

◆ OBJSVR_CONNECTION

#define OBJSVR_CONNECTION   8

Definition at line 30 of file rleibnetip.cpp.

◆ REMLOG_CONNECTION

#define REMLOG_CONNECTION   6

Definition at line 29 of file rleibnetip.cpp.

◆ TUNNEL_CONNECTION

#define TUNNEL_CONNECTION   4

Definition at line 28 of file rleibnetip.cpp.

◆ TUNNEL_LINKLAYER

#define TUNNEL_LINKLAYER   2

Definition at line 31 of file rleibnetip.cpp.

Enumeration Type Documentation

◆ ServiceType

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

◆ eib_reader()

static void* eib_reader ( void *  arg)
static

Definition at line 56 of file rleibnetip.cpp.

57 {
58  THREAD_PARAM *p = (THREAD_PARAM *) arg;
59  rlEIBnetIP *eib = (rlEIBnetIP *) p->user;
60  rlEIBnetIP::PDU pdu;
61  rlTime now, last, diff;
62  int ret, len;
63  int recseq = 0;
64  int expected_recseq = 0;
65  unsigned char b[4];
66 
67  last.getLocalTime();
68  while(eib->running)
69  {
70  if(eib->isConnected() == 0)
71  {
72  eib->connect();
73  expected_recseq = 0;
74  last.getLocalTime();
75  }
76  ret = eib->recv(&pdu, sizeof(pdu));
77  now.getLocalTime();
78  if(ret > 0)
79  {
80  switch (ntohs(pdu.servicetype))
81  {
82  case DISCONNECT_REQUEST:
83  eib->disconnect();
84  expected_recseq = 0;
85  break;
87  if(eib->debug) ::printf("eib_reader() CONNECTIONSTATE_RESPONSE\n");
88  break;
89  case TUNNELLING_REQUEST:
90  if(eib->debug)
91  ::printf("eib_reader() TUNNELING_REQUEST sequenzecounter=%d\n",recseq);
92  recseq = pdu.data[2]; // sequencecounter
93  b[0] = pdu.data[0]; // remember 4 bytes of data
94  b[1] = pdu.data[1];
95  b[2] = pdu.data[2];
96  b[3] = pdu.data[3];
97  len = ntohs(pdu.totalsize) - 6; // remember len (-headerlength)
98  pdu.headersize = EIB_HEADERSIZE; // fill acknowledge
99  pdu.version = EIB_VERSION;
100  pdu.servicetype = htons(TUNNELLING_ACK);
101  pdu.totalsize = htons(EIB_HEADERSIZE+4);
102  pdu.data[0] = 4; // structlength
103  pdu.data[1] = eib->channelid; // channelid
104  pdu.data[2] = recseq; // sequencecounter
105  pdu.data[3] = E_NO_ERROR; // typespecific
106  if(recseq != expected_recseq)
107  {
108  if(eib->debug)
109  ::printf("eib_reader() recseq=%d expected_recseq=%d\n",recseq,expected_recseq);
110  // we simply ignore the sequencecounter
111  // pdu.data[4] = E_SEQUENCE_NUMBER;
112  }
113  expected_recseq = (expected_recseq+1) & 0x0ff;
114  eib->rlUdpSocket::sendto(&pdu, ntohs(pdu.totalsize), eib->server);
115  pdu.data[0] = b[0]; // restore received data
116  pdu.data[1] = b[1];
117  pdu.data[2] = b[2];
118  pdu.data[3] = b[3];
119  eib->storeBuffer(&pdu.data[4],len-4); // +EIBNETIP_COMMON_CONNECTION_HEADER
120  break;
121  case TUNNELLING_ACK:
122  if(pdu.data[3] == E_NO_ERROR)
123  {
124  eib->tunnel_ack = 1;
125  if(eib->debug) ::printf("eib_reader() TUNNELLING_ACK typespecific=0x%x\n",pdu.data[3]);
126  }
127  else
128  {
129  eib->tunnel_ack = -1;
130  if(eib->debug) ::printf("eib_reader() TUNNELLING_NACK typespecific=0x%x\n",pdu.data[3]);
131  }
132  break;
133  default:
134  ::printf("eib_reader() unknown servicetype=0x%x\n",ntohs(pdu.servicetype));
135  break;
136  }
137  }
138  diff = now - last;
139  if(eib->isConnected() && eib->channelid != -1 && diff.second > 50)
140  { // send heartbeat
141  if(eib->debug) ::printf("send heartbeat\n");
142  pdu.headersize = EIB_HEADERSIZE;
143  pdu.version = EIB_VERSION;
144  pdu.servicetype = htons(CONNECTIONSTATE_REQUEST);
145  pdu.totalsize = htons(EIB_HEADERSIZE+EIB_ADRSIZE*2+EIB_CRICRDSIZE);
146  pdu.data[0] = eib->channelid;
147  pdu.data[1] = 0;
148  eib->rlUdpSocket::sendto(&pdu, ntohs(pdu.totalsize), eib->server);
149  last.getLocalTime();
150  }
151  }
152  return NULL;
153  /*
154  for(int i=0; i<50; i++)
155  {
156  p->thread->lock();
157  //do something critical
158  printf("this is the thread\n");
159  p->thread->unlock();
160  }
161  */
162 }
void getLocalTime()
Definition: rltime.cpp:342
#define EIB_VERSION
Definition: rleibnetip.cpp:24
int channelid
Definition: rleibnetip.h:104
#define E_NO_ERROR
Definition: rleibnetip.cpp:32
#define EIB_HEADERSIZE
Definition: rleibnetip.cpp:23
void * user
Definition: rlthread.h:30
#define EIB_ADRSIZE
Definition: rleibnetip.cpp:25
int isConnected()
Definition: rleibnetip.cpp:572
int recv(void *buf, int maxlen)
int disconnect()
Definition: rleibnetip.cpp:534
#define EIB_CRICRDSIZE
Definition: rleibnetip.cpp:27
int storeBuffer(unsigned char *buf, int len)
Definition: rleibnetip.cpp:201
int tunnel_ack
Definition: rleibnetip.h:108
int connect()
Definition: rleibnetip.cpp:474
Definition: rltime.h:25
rlIpAdr * server
Definition: rleibnetip.h:106