rllib  1
rlsiemenstcp.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                           rlsiemenstcp.h  -  description
00003                              -------------------
00004     begin                : Mon Mar 08 2004
00005     copyright            : (C) 2004 by Rainer Lehrig
00006     email                : lehrig@t-online.de
00007 
00008     S7_200 update        : Wed Mar 21 2007
00009     copyright            : (C) 2007 by Aljosa Merljak
00010     Email                : aljosa.merljak@datapan.si
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This library is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
00017  *   published by the Free Software Foundation                             *
00018  *                                                                         *
00019  ***************************************************************************/
00020 #ifndef _RL_SIEMENS_TCP_H_
00021 #define _RL_SIEMENS_TCP_H_
00022 
00023 #include "rldefine.h"
00024 #include "rlsocket.h"
00025 
00029 class rlSiemensTCP : public rlSocket
00030 {
00031 public:
00032   enum ORG
00033   {
00034     ORG_DB   = 1,
00035     ORG_M    = 2,
00036     ORG_E    = 3,
00037     ORG_A    = 4,
00038     ORG_PEPA = 5,
00039     ORG_Z    = 6,
00040     ORG_T    = 7
00041   };
00042   enum PLC_TYPE
00043   {
00044     S7_200    = 1,
00045     S7_300    = 2,
00046     S7_400    = 3,
00047     S5        = 4,
00048     RACK_SLOT = 5
00049   };
00050   enum SiemensFunctionCodes
00051   {
00052     WriteBit   = 1,
00053     WriteByte  = 2
00054   };
00055   rlSiemensTCP(const char *adr, int _plc_type, int _fetch_write = 1, int function = -1, int rack_slot = -1);
00056   virtual ~rlSiemensTCP();
00059   int write(int org, int dbnr, int start_adr, int length, const unsigned char *buf, int function=WriteByte);
00060   int fetch(int org, int dbnr, int start_adr, int length, unsigned char *buf);
00061 private:
00062   void doConnect();
00063   int read_iso(unsigned char *buf);
00064   int write_iso(unsigned char *buf, int len);
00065   int getOrg(int org);
00066   int write_bit(int& i, int org, int dbnr, int start_adr, int len, const unsigned char *buf);
00067   int write_byte(int& i, int org, int dbnr, int start_adr, int length, const unsigned char *buf);
00068   typedef struct
00069   {
00070     unsigned char version;
00071     unsigned char reserved;
00072     unsigned char length_high;
00073     unsigned char length_low;
00074   }IH; // iso header
00075   typedef struct
00076   {
00077     unsigned char ident[2];
00078     unsigned char header_len;
00079     unsigned char ident_op_code;
00080     unsigned char op_code_len;
00081     unsigned char op_code;
00082     unsigned char ident_org_block;
00083     unsigned char len_org_block;
00084     unsigned char org_block;
00085     unsigned char dbnr;
00086     unsigned char start_adr[2];
00087     unsigned char len[2];
00088     unsigned char spare1;
00089     unsigned char spare1_len;
00090   }WH; // write header
00091   typedef struct
00092   {
00093     unsigned char ident[2];
00094     unsigned char header_len;
00095     unsigned char ident_op_code;
00096     unsigned char op_code_len;
00097     unsigned char op_code;
00098     unsigned char ack_block;
00099     unsigned char ack_block_len;
00100     unsigned char error_block;
00101     unsigned char spare1;
00102     unsigned char spare1_len;
00103     unsigned char spare2[5];
00104   }WA; // write ack
00105   typedef struct
00106   {
00107     unsigned char ident[2];
00108     unsigned char header_len;
00109     unsigned char ident_op_code;
00110     unsigned char op_code_len;
00111     unsigned char op_code;
00112     unsigned char ident_org_block;
00113     unsigned char len_org_block;
00114     unsigned char org_block;
00115     unsigned char dbnr;
00116     unsigned char start_adr[2];
00117     unsigned char len[2];
00118     unsigned char spare1;
00119     unsigned char spare1_len;
00120   }FH; // fetch header
00121   typedef struct
00122   {
00123     unsigned char ident[2];
00124     unsigned char header_len;
00125     unsigned char ident_op_code;
00126     unsigned char op_code_len;
00127     unsigned char op_code;
00128     unsigned char ack_block;
00129     unsigned char ack_block_len;
00130     unsigned char error_block;
00131     unsigned char spare1;
00132     unsigned char spare1_len;
00133     unsigned char spare2[5];
00134   }FA; // fetch ack
00135   WH wh;
00136   WA wa;
00137   FH fh;
00138   FA fa;
00139   IH ih;
00140   int function, rack_slot;
00141   int plc_type;
00142   int fetch_write;
00143   unsigned char pdu[2048];
00144 };
00145 
00146 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines