versadac  1
versadac - Scalable Recorder Firmware
eipc_client.h
1 /*
2  * Copyright (c) 2002-2007 by Real Time Automation
3  *
4  * This software is copyrighted by and is the sole property of
5  * Real Time Automation (RTA). All rights, title, ownership, or other
6  * interests in the software remain the property of RTA. This
7  * software may only be used in accordance with the corresponding
8  * license agreement. Any unauthorized use, duplication, transmission,
9  * distribution, or disclosure of this software is expressly forbidden.
10  *
11  * This Copyright notice MAY NOT be removed or modified without prior
12  * written consent of RTA.
13  *
14  * RTA reserves the right to modify this software without notice.
15  *
16  * Real Time Automation
17  * 2825 N. Mayfair Road USA 414.453.5100
18  * Suite 11 http://www.rtaautomation.com
19  * Wauwatosa, WI 53222 software@rtaautomation.com
20  *
21  *************************************************************************
22  *
23  * Module Name: eips_cnxn.h
24  * Version: 2.05
25  * Version Date: 4/02/2007
26  * Author: Jamin D. Wendorf (jwendorf@rtaautomation.com)
27  * Language: Ansi C
28  * Compile Options: N/A
29  * Compile defines: N/A
30  * Libraries: N/A
31  * Link Options: N/A
32  *
33  * Description.
34  * =======================================================================
35  * This file contains EtherNet/IP Client definitions.
36  *
37  */
38 
39 #ifndef __EIPC_CLIENT_H__
40 #define __EIPC_CLIENT_H__
41 
42 // all user defines for the client code are in this file
43 #include "eipc_usersys.h"
44 
45 /* *************** */
46 /* DEFINES */
47 /* *************** */
48 
49 /* I/O Server States */
50 #define EIPC_CLIENT_IOSERVERSTATE_NONEXIST 0x00
51 #define EIPC_CLIENT_IOSERVERSTATE_IOCONNECTED 0x01
52 
53 /* UCMM Server States */
54 #define EIPC_CLIENT_UCMMSERVERSTATE_NONEXIST 0x00
55 #define EIPC_CLIENT_UCMMSERVERSTATE_REGSES 0x01
56 #define EIPC_CLIENT_UCMMSERVERSTATE_READY 0x02
57 #define EIPC_CLIENT_UCMMSERVERSTATE_BUSY 0x03
58 
59 /* I/O Connection Types */
60 #define EIPC_CLIENT_IOCNXNTYPE_NULL 0x00
61 #define EIPC_CLIENT_IOCNXNTYPE_MULTICAST 0x20
62 #define EIPC_CLIENT_IOCNXNTYPE_POINT2POINT 0x40
63 #define EIPC_CLIENT_IOCNXNTYPE_RESERVED 0x60
64 #define EIPC_CLIENT_IOCNXNTYPE_ANDVAL 0x60
65 
66 /* I/O Priority */
67 #define EIPC_CLIENT_IOPRIORITY_LOW 0x00
68 #define EIPC_CLIENT_IOPRIORITY_HIGH 0x04
69 #define EIPC_CLIENT_IOPRIORITY_SCHED 0x08
70 #define EIPC_CLIENT_IOPRIORITY_URGENT 0x0C
71 #define EIPC_CLIENT_IOPRIORITY_ANDVAL 0x0C
72 
73 /* I/O Ownership */
74 #define EIPC_CLIENT_OWNERSHIP_EXCLUSIVE 0x00
75 #define EIPC_CLIENT_OWNERSHIP_INPUTONLY 0x01
76 #define EIPC_CLIENT_OWNERSHIP_LISTENONLY 0x02
77 #define EIPC_CLIENT_OWNERSHIP_REDUNDANT 0x80
78 #define EIPC_CLIENT_OWNERSHIP_ANDVAL 0x80
79 
80 /* I/O Modes */
81 #define EIPC_CLIENT_IOMODE_IDLE 0
82 #define EIPC_CLIENT_IOMODE_RUN 1
83 
84 /* This must be Class 1 CYCLIC for now */
85 #define EIPC_USERSYS_CNXNXPORT 1
86 
87 /* I/O Open Error Codes - General */
88 #define EIPC_CLIENT_OPENERR_SERVHAND 0x01
89 #define EIPC_CLIENT_OPENERR_IOEXISTS 0x02
90 #define EIPC_CLIENT_OPENERR_T2ONULL 0x03
91 #define EIPC_CLIENT_OPENERR_CONFIGPTR 0x04
92 #define EIPC_CLIENT_OPENERR_UCMMBUSY 0x05
93 
94 /* I/O Open Error Codes - O_to_T */
95 #define EIPC_CLIENT_OPENERR_O2T_RPI 0x11
96 #define EIPC_CLIENT_OPENERR_O2T_DATAPTR 0x12
97 
98 /* I/O Open Error Codes - T_to_O */
99 #define EIPC_CLIENT_OPENERR_T2O_RPI 0x21
100 #define EIPC_CLIENT_OPENERR_T2O_DATAPTR 0x22
101 
102 /* UCMM Error Codes - General */
103 #define EIPC_CLIENT_UCMMERR_SUCCESS 0
104 #define EIPC_CLIENT_UCMMERR_SERVHAND -1
105 #define EIPC_CLIENT_UCMMERR_BUSY -2
106 #define EIPC_CLIENT_UCMMERR_FORMAT -3
107 #define EIPC_CLIENT_UCMMERR_RSPFUNCPTR -4
108 #define EIPC_CLIENT_UCMMERR_TMOINVALID -5
109 #define EIPC_CLIENT_UCMMERR_TAGCNT -6
110 #define EIPC_CLIENT_UCMMERR_TAGPTR -7
111 #define EIPC_CLIENT_UCMMERR_TAGFMT -8
112 #define EIPC_CLIENT_UCMMERR_PLCTYPEINVALID -9
113 
114 /* ****************** */
115 /* STRUCTURES */
116 /* ****************** */
117 
118 #ifdef EUROTHERM_VXWORKS
119 typedef struct
120 {
121  uint16 EncapVersion;
122 
123  uint16 SinFamily;
124  uint16 SinPort;
125  uint32 SinAddr;
126  uint8 SinZero8[8];
127 
128  /* From Identity Object */
129 /* ATTR 01 */ uint16 Vendor;
130 /* ATTR 02 */ uint16 DeviceType;
131 /* ATTR 03 */ uint16 ProductCode;
132 /* ATTR 04 */ uint16 Revision;
133 /* ATTR 05 */ uint16 Status;
134 /* ATTR 06 */ uint32 SerialNum;
135 /* ATTR 07 */ uint8 ProductName[32]; /* user defined */
136  uint8 SizOfName; /* user defined */
137 /* ATTR 08 */ uint8 State;
138 }EIPC_LIST_IDENTITY_STRUCT;
139 #endif
140 
141 /* structure definitions */
142 typedef struct
143 {
144  uint8 RunIdle32Used; // TRUE - use 32-bit header; FALSE - use 0 length for IDLE
145  uint8 Ownership; // redundant owner, exclusive-owner, input only or listen-only
146  uint32 RPIusec;
147  uint8 CnxnPtId;
148  uint8 Priority;
149  uint8 CnxnType;
150  uint16 DataSize;
151  uint8 *DataPtr;
152  void (*IOChgFuncPtr) (uint16 server_handle, uint8 cnxnpt_id, uint16 size_written);
154 
155 /* connection structure */
156 typedef struct
157 {
158  EIPS_USERSYS_SOCKTYPE SockID; // UDP socket id
159  uint32 IPAddr;
160  uint16 Port;
161  EIPC_OPENCNXN_CNXNPARAM_STRUCT OpenCnxn; // connection information provided by the user
162  uint16 TimerNum; // timer number
163  uint16 PDUSeqNum; // PDU sequence number (incremented when data changes)
164  uint32 SequenceNumber; // I/O sequence number (incremented on every send)
165  uint32 ConnectionID; // used to find the connection from a given UDP port
166  uint32 API;
167  uint8 CnxnParam;
168  uint8 CnxnSize;
170 
171 /* structure definitions */
172 typedef struct
173 {
174  uint8 InstId;
175  uint16 DataSize;
176  uint8 *DataPtr;
178 
179 /* port segment is needed for point I/O */
180 typedef struct
181 {
182  uint8 Port;
183  uint8 Address;
185 
186 /* structure definitions */
187 typedef struct
188 {
189  uint8 gen_stat; /* 0 = Success; 1-255 = Error */
190  uint8 ext_stat_size; /* 0 - EIPS_USER_MSGRTR_EXTSTAT_SIZE */
191  uint16 ext_stat[EIPC_USERSYS_EXT_STAT_SIZE];
192  uint16 rsp_data_size; /* 0 - EIPS_USER_MSGRTR_DATA_SIZE */
193  uint8 rsp_data[EIPC_USERSYS_RSP_DATA_SIZE];
195 
196 /* structure definitions */
197 typedef struct
198 {
199  uint8 service_code;
200  uint8 classID;
201  uint16 instID;
202  uint8 attrID;
203  uint8 attrID_used;
204  uint16 data_size;
205  uint8 *data_ptr;
206  uint16 tmo_in_sec;
207  bool inst_addressing_16bit;
208 
209  /* we need to send the response to the user */
210  void (*ucmmrsp_func_ptr) (uint16 server_handle, EIPC_UCMM_RESPONSE_STRUCT *response);
212 
213 #ifdef EIPC_TAG_CLIENT_USED
214 /* ***************** */
215 /* TAG CONFIGURATION */
216 /* ***************** */
217 #define EIPC_USEROBJ_TAGNAME_SIZE EIP_MAX_TAGNAME_SIZE /* in characters */
218 #define EIPC_USEROBJ_TAGDATA_SIZE 256 /* in bytes */
219 #define EIPC_USEROBJ_MAXTAGS_PER_MSG EIP_MAX_NUMBER_OF_TAGS /* number of tags per read/write */
220 #define EIPC_USEROBJ_MINTMOVAL 100 /* minimum timeout value, should be 100 or larger */
221 
222 /* ====================================================================
223  TAG STRUCTURE (reads and writes)
224 ======================================================================= */
225 typedef struct
226 {
227  // tag name and offset
228  char tag_name[EIPC_USEROBJ_TAGNAME_SIZE];
229  uint8 tag_name_len;
230  uint16 tag_offset;
231 
232  // number of elements
233  uint16 tag_num_elements;
234 
235  // message processing
236  uint8 service_code;
237  uint8 gen_status;
238  uint16 ext_status;
239 
240  uint16 tag_data_type;
241  uint16 tag_data_len;
242  uint8 tag_data_ptr[EIPC_USEROBJ_TAGDATA_SIZE];
243 
245 
246 typedef struct
247 {
248  /* store the last tag request so processing the response is easier */
249  uint16 tmo_in_ms;
250  uint8 plc_slot;
251  uint16 tag_cnt;
252  uint8 service_code;
253  EIPC_TAG_STRUCT tag_ptr[EIPC_USEROBJ_MAXTAGS_PER_MSG];
254 
255  /* we need to send the tag response to the user */
256  void (*tagrsp_func_ptr) (uint16 server_handle, uint8 status, uint16 tag_cnt, EIPC_TAG_STRUCT *);
258 #endif
259 
260 #ifdef EIPC_PCCC_CLIENT_USED
261 /* ****************** */
262 /* PCCC CONFIGURATION */
263 /* ****************** */
264 #define EIPC_USEROBJ_PCCCDATA_SIZE 256 /* in bytes */
265 #define EIPC_USEROBJ_MINTMOVAL 100 /* minimum timeout value, should be 100 or larger */
266 #define EIPC_PCCC_PLC_TYPE_SLC505 0
267 #define EIPC_PCCC_PLC_TYPE_PLC5E 1
268 
269 /* ====================================================================
270  PCCC STRUCTURE (reads and writes)
271 ======================================================================= */
272 typedef struct
273 {
274  // message processing
275  uint8 service_code;
276  uint8 gen_status;
277  uint16 ext_status;
278 
279  // request information
280  uint8 pccc_plc_type;
281  uint16 pccc_file_num;
282  uint16 pccc_file_offset;
283  uint8 pccc_data_type;
284  char pccc_file_string[10];
285  uint16 pccc_element_size_in_bytes;
286  uint16 pccc_num_elements;
287 
288  uint16 pccc_data_len;
289  uint8 pccc_data_ptr[EIPC_USEROBJ_PCCCDATA_SIZE];
290 }EIPC_PCCC_STRUCT;
291 
292 typedef struct
293 {
294  /* store the last tag request so processing the response is easier */
295  uint16 tmo_in_ms;
296  uint8 plc_slot;
297  EIPC_PCCC_STRUCT pccc_ptr;
298 
299  /* we need to send the pccc response to the user */
300  void (*pcccrsp_func_ptr) (uint16 server_handle, uint8 status, int8 rta_status, uint16 rsp_size, uint8 *rsp_data);
301 }EIPC_PCCC_REQUEST_STRUCT;
302 #endif
303 
304 /* structure definitions */
305 typedef struct
306 {
307  /* general variables needed for all clients */
308  uint16 ServerHandle; // internal reference for the server (1-65535 valid)
309  uint16 TimerNum; // used for connecting, ucmm and retry delay timeouts
310  uint32 IPAddr; // IP Address of the server (Big-endian)
311  uint32 SessionID; // 32-bit session handle returned by the server
312  uint8 UCMMState; // UCMM State (Non-exist, Ready or Busy)
313  uint8 IOState; // I/O State (connected, unconnected)
314  EIPS_USERSYS_SOCKTYPE SockID; // main socket for TCP traffic
315 
316  /* we need to send the UCMM response to the user */
317  void (*UCMMRspFuncPtr) (uint16 server_handle, EIPC_UCMM_RESPONSE_STRUCT *response);
318 
319  /* we need to be able to pass config data */
320  EIPC_OPENCNXN_CFGDATA_STRUCT UserConfigStruct;
321  uint8 Config_Used;
322 
323  /* we need to be able to pass port config */
324  EIPC_OPENCNXN_PORT_STRUCT UserPortStruct;
325  uint8 Port_Used;
326 
327  /* O_to_T (Produce Data) */
328  EIPC_IOCNXN_STRUCT O2TCnxn;
329  uint8 O2T_Used;
330 
331  /* T_to_O (Consume Data) */
332  EIPC_IOCNXN_STRUCT T2OCnxn; // this must be used
333 
334 #ifdef EIPC_TAG_CLIENT_USED
335  /* we need to send the UCMM response to the user */
336  void (*TagRspFuncPtr) (uint16 server_handle, uint8 status, uint16 tag_cnt, EIPC_TAG_STRUCT *);
337 #endif
338 
339 #ifdef EIPC_PCCC_CLIENT_USED
340  uint16 tns;
341  /* we need to send the UCMM response to the user */
342  void (*PcccRspFuncPtr) (uint16 server_handle, uint8 status, int8 rta_status, uint16 rsp_size, uint8 *rsp_data);
343 #endif
345 
346 /* ********************************** */
347 /* Global Functions in eipc_usersys.cpp */
348 /* ********************************** */
349 /* user defined functions */
350 void eipc_usersys_init (void);
351 void eipc_usersys_process (void);
352 void eipc_usersys_newConsumeData (uint16 server_handle, uint8 cnxn_id);
353 void eipc_usersys_IOStateChanged (uint16 server_handle, uint8 io_server_state);
354 void eipc_usersys_UCMMStateChanged (uint16 server_handle, uint8 ucmm_server_state);
355 
356 /* *********************************** */
357 /* Global Functions in eipc_usersock.c */
358 /* *********************************** */
359 EIPS_USERSYS_SOCKTYPE eips_usersock_connect(uint32 ipaddr);
360 EIPS_USERSYS_SOCKTYPE eips_usersock_openUDPIOSocket (uint16 port, uint8 type);
361 EIPS_USERSYS_SOCKTYPE eips_usersock_joinMulitcast(EIPS_USERSYS_SOCKTYPE sockid, uint32 ipaddr, uint16 port);
362 void eips_usersock_leaveMulitcast(EIPS_USERSYS_SOCKTYPE sockid, uint32 ipaddr, uint16 port);
363 
364 /* ********************************* */
365 /* Global Functions in eipc_client.c */
366 /* ********************************* */
367 /* user called functions */
368 uint16 eipc_client_connectToServer (uint32 ip_addr); // return the server_handle
369 void eipc_client_disconnectFromServer (uint16 server_handle);
370 uint8 eipc_client_openIOConnection (uint16 server_handle, EIPC_OPENCNXN_PORT_STRUCT *port, EIPC_OPENCNXN_CFGDATA_STRUCT *config, EIPC_OPENCNXN_CNXNPARAM_STRUCT *O2T, EIPC_OPENCNXN_CNXNPARAM_STRUCT *T2O);
371 void eipc_client_closeIOConnection (uint16 server_handle);
372 void eipc_client_newProduceData (uint16 server_handle, uint8 cnxn_id);
373 uint8 eipc_client_sendUCMMRequest (uint16 server_handle, EIPC_UCMM_REQUEST_STRUCT *request);
374 void eipc_client_changeToRunMode (void);
375 void eipc_client_changeToIdleMode (void);
376 
377 /* rta called functions */
378 void eipc_client_init (void);
379 void eipc_client_process (void);
380 void eipc_client_onConnect (EIPS_USERSYS_SOCKTYPE socket_id);
381 void eipc_client_onClose (EIPS_USERSYS_SOCKTYPE socket_id);
382 uint16 eipc_client_onTCPData (EIPS_USERSYS_SOCKTYPE socket_id, uint8 * socket_data, uint16 socket_data_size);
383 void eipc_client_onUDPData (uint32 ipaddr, uint8 * socket_data, uint16 socket_data_size);
384 
385 #ifdef EIPC_TAG_CLIENT_USED
386 /* tag access functions */
387 int16 eipc_tagclient_sendTagRead (uint16 server_handle, EIPC_TAG_REQUEST_STRUCT *tag_ptr);
388 int16 eipc_tagclient_sendTagWrite (uint16 server_handle, EIPC_TAG_REQUEST_STRUCT *tag_ptr);
389 #endif
390 
391 #ifdef EIPC_PCCC_CLIENT_USED
392 /* pccc access functions */
393 int16 eipc_client_sendPcccRead (uint16 server_handle, EIPC_PCCC_REQUEST_STRUCT *pccc_ptr);
394 int16 eipc_client_sendPcccWrite (uint16 server_handle, EIPC_PCCC_REQUEST_STRUCT *pccc_ptr);
395 #endif
396 
397 /* ********************************* */
398 /* Global Functions in eips_rtasys.c */
399 /* ********************************* */
400 void eips_rtasys_onTCPConnect (EIPS_USERSYS_SOCKTYPE socket_id);
401 
402 #endif /* __EIPC_CLIENT_H__ */
403 
Definition: zlib_deflate.c:118
Definition: eipc_client.h:246
Definition: eipc_client.h:142
Definition: eipc_client.h:225
Definition: eipc_client.h:197
Definition: eipc_client.h:305
Definition: eipc_client.h:156
Definition: eipc_client.h:187
Definition: eipc_client.h:172
Definition: eipc_client.h:180