rllib  1
rleibnetip.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                         rleibnetip.h  -  description
00003                              -------------------
00004     begin                : Wed Apr 04 2007
00005     copyright            : (C) 2007 by Rainer Lehrig
00006     email                : lehrig@t-online.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
00013  *   published by the Free Software Foundation                             *
00014  *                                                                         *
00015  ***************************************************************************/
00016 #ifndef _RL_EIB_NET_IP_H_
00017 #define _RL_EIB_NET_IP_H_
00018 
00019 #include "rldefine.h"
00020 #include "rludpsocket.h"
00021 #include "rlthread.h"
00022 #include <stdio.h>
00023 
00024 #define EIB_ON  0x81
00025 #define EIB_OFF 0x80
00026 
00027 class rlDataAcquisitionProvider;
00028 
00032 class rlEIBnetIP : public rlUdpSocket
00033 {
00034 public:
00035 
00036   enum EIBnetIP
00037   {
00038     PORT              = 3671,
00039     SUCCESS           = 0,
00040     EIBERROR          = 0x0ffffffff,
00041     TIMEOUT           = -1,
00042     COULD_NOT_CONNECT = -2
00043   };
00044 
00045   typedef struct
00046   {
00047     unsigned char  headersize;
00048     unsigned char  version;
00049     unsigned short servicetype;
00050     unsigned short totalsize;
00051     unsigned char  data[128-6];
00052   }PDU;
00053 
00054   typedef struct
00055   {
00056     unsigned char  mc;          // 0x29
00057     unsigned char  addi1;       // 0x0
00058     unsigned char  ctrl1;       // 0xbc
00059     unsigned char  ctrl2;       // 0xe0
00060     unsigned short saddr;       // 0x1
00061     unsigned short daddr;       // 0x100
00062     unsigned char  apci_length; // 0x1
00063     unsigned char  apci;        // 0x0
00064     unsigned char  val[14];     // 0x80
00065   }EIB_TEL;
00066 
00067   // this may be used by the application programmer
00068   rlEIBnetIP(int num_signals = 1000, int debug = 0, rlDataAcquisitionProvider *provider = NULL);
00069   virtual ~rlEIBnetIP();
00070 
00071   int setServer(rlIpAdr *server);
00072   int setClient(rlIpAdr *client);
00073   int startReading();
00074   int stopReading();
00075   int value(const char *name);
00076   unsigned int valueUnsigned(const char *name);
00077   float valueFloat2(const char *name);
00078   float valueFloat4(const char *name);
00079   int setValue(const char *name, int val, int length=-1, int addi1=-1, int ctrl=-1, int apci=-1);
00080   int setValueUnsigned(const char *name, unsigned int val, int length=-1, int addi1=-1, int ctrl=-1, int apci=-1);
00081   int setValueFloat(const char *name, float val, int length=-1, int addi1=-1, int ctrl=-1, int apci=-1);
00082   int setText(const char *name, const char *text);
00083   int getText(const char *name, char *text, int maxlen);
00084   int setSourceAdr(const char *adr);
00085   int dump(FILE *fout);
00086   int setValuesFromCSV(const char *filename);
00087   int debug;
00088   int watch_eib;
00089 
00090   // the rest is for internal use only
00091   int connect();
00092   int disconnect();
00093   int isConnected();
00094 #ifndef SWIG_SESSION
00095   int getDescription(PDU *pdu);
00096 #endif
00097   int recv(void *buf, int maxlen);
00098   int storeBuffer(unsigned char *buf, int len);
00099   int sendDisconnectRequest();
00100 
00101   void     *mem;
00102   int      memsize;
00103   int      running;
00104   int      channelid;
00105   rlThread thread;
00106   rlIpAdr  *server;
00107   int      send_sequencecounter;
00108   int      tunnel_ack;
00109   rlDataAcquisitionProvider *provider;
00110 
00111 private:
00112   int      printTelegram(EIB_TEL *tel);
00113   int      storeInProvider(EIB_TEL *tel);
00114   rlIpAdr  client;
00115   rlIpAdr  from;
00116   int      maxvalues;
00117   int      is_connected;
00118   short    saddr;
00119 };
00120 
00121 #endif