OpENer - Open Source EtherNet/IP(TM) I/O Target Stack  2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
sampleapplication.c
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2012, Rockwell Automation, Inc.
3  * All rights reserved.
4  *
5  ******************************************************************************/
6 
7 #include "opener_api.h"
8 #include "appcontype.h"
9 #include <string.h>
10 #include <stdlib.h>
11 
12 #define DEMO_APP_INPUT_ASSEMBLY_NUM 100 //0x064
13 #define DEMO_APP_OUTPUT_ASSEMBLY_NUM 150 //0x096
14 #define DEMO_APP_CONFIG_ASSEMBLY_NUM 1 //0x001
15 #define DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM 152 //0x098
16 #define DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM 153 //0x099
17 #define DEMO_APP_EXPLICT_ASSEMBLY_NUM 154 //0x09A
18 
19 /* global variables for demo application (4 assembly data fields) ************/
20 
22 
23 EipUint8 g_assembly_data064[40]; /* Input */
24 EipUint8 g_assembly_data096[40]; /* Output */
25 EipUint8 g_assembly_data097[10]; /* Config */
26 EipUint8 g_assembly_data09A[32]; /* Explicit */
27 
29  /* create 3 assembly object instances*/
30  /*INPUT*/
32  sizeof(g_assembly_data064) );
33 
34  /*OUTPUT*/
36  sizeof(g_assembly_data096) );
37 
38  /*CONFIG*/
40  sizeof(g_assembly_data097) );
41 
42  /*Heart-beat output assembly for Input only connections */
44 
45  /*Heart-beat output assembly for Listen only connections */
47 
48  /* assembly for explicit messaging */
50  sizeof(g_assembly_data09A) );
51 
63 
64  return kEipStatusOk;
65 }
66 
67 void HandleApplication(void) {
68  /* check if application needs to trigger an connection */
69 }
70 
71 void CheckIoConnectionEvent(unsigned int pa_unOutputAssembly,
72  unsigned int pa_unInputAssembly,
73  IoConnectionEvent pa_eIOConnectionEvent) {
74  /* maintain a correct output state according to the connection state*/
75 
76  (void) pa_unOutputAssembly; /* suppress compiler warning */
77  (void) pa_unInputAssembly; /* suppress compiler warning */
78  (void) pa_eIOConnectionEvent; /* suppress compiler warning */
79 }
80 
82  EipStatus nRetVal = kEipStatusOk;
83 
84  /*handle the data received e.g., update outputs of the device */
85  switch (pa_pstInstance->instance_number) {
87  /* Data for the output assembly has been received.
88  * Mirror it to the inputs */
89  memcpy( &g_assembly_data064[0], &g_assembly_data096[0],
90  sizeof(g_assembly_data064) );
91  break;
93  /* do something interesting with the new data from
94  * the explicit set-data-attribute message */
95  break;
97  /* Add here code to handle configuration data and check if it is ok
98  * The demo application does not handle config data.
99  * However in order to pass the test we accept any data given.
100  * EIP_ERROR
101  */
102  nRetVal = kEipStatusOk;
103  break;
104  }
105  return nRetVal;
106 }
107 
109  /*update data to be sent e.g., read inputs of the device */
110  /*In this sample app we mirror the data from out to inputs on data receive
111  * therefore we need nothing to do here. Just return true to inform that
112  * the data is new.
113  */
114 
115  if (pa_pstInstance->instance_number == DEMO_APP_EXPLICT_ASSEMBLY_NUM) {
116  /* do something interesting with the existing data
117  * for the explicit get-data-attribute message */
118  }
119  return true;
120 }
121 
123  /* add reset code here*/
125  return kEipStatusOk;
126 }
127 
129  /*rest the parameters */
131  /*than perform device reset*/
132  ResetDevice();
133  return kEipStatusOk;
134 }
135 
136 void *
137 CipCalloc(size_t pa_nNumberOfElements,
138  size_t pa_nSizeOfElement) {
139  return calloc(pa_nNumberOfElements, pa_nSizeOfElement);
140 }
141 
142 void CipFree(void *pa_poData) {
143  free(pa_poData);
144 }
145 
146 void RunIdleChanged(EipUint32 pa_nRunIdleValue) {
147  (void) pa_nRunIdleValue;
148 }
149 
EipStatus ApplicationInitialization(void)
Callback for the application initialization.
EipUint8 g_assembly_data064[40]
CipInstance * CreateAssemblyObject(const EipUint32 instance_id, EipByte *const data, const EipUint16 data_length)
Create an instance of an assembly object.
Definition: cipassembly.c:80
#define DEMO_APP_CONFIG_ASSEMBLY_NUM
CipUint g_encapsulation_inactivity_timeout
#13 Number of seconds of inactivity before TCP connection is closed
#define DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM
#define DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM
void CheckIoConnectionEvent(unsigned int pa_unOutputAssembly, unsigned int pa_unInputAssembly, IoConnectionEvent pa_eIOConnectionEvent)
Inform the application on changes occurred for a connection.
void * CipCalloc(size_t pa_nNumberOfElements, size_t pa_nSizeOfElement)
Allocate memory for the CIP stack.
void ConfigureListenOnlyConnectionPoint(const unsigned int connection_number, const unsigned int output_assembly, const unsigned int input_assembly, const unsigned int config_assembly)
Configures the connection point for a listen only connection.
Definition: appcontype.c:113
EipStatus
EIP stack status enum.
Definition: typedefs.h:93
uint8_t EipUint8
Definition: typedefs.h:32
void HandleApplication(void)
Allow the device specific application to perform its execution.
uint32_t EipUint32
Definition: typedefs.h:34
EipStatus ResetDevice(void)
Emulate as close a possible a power cycle of the device.
IoConnectionEvent
Definition: ciptypes.h:113
void ConfigureInputOnlyConnectionPoint(const unsigned int connection_number, const unsigned int output_assembly, const unsigned int input_assembly, const unsigned int config_assembly)
Configures the connection point for an input only connection.
Definition: appcontype.c:100
EipStatus AfterAssemblyDataReceived(CipInstance *pa_pstInstance)
Call back function to inform application on received data for an assembly object. ...
EipUint8 g_assembly_data09A[32]
#define DEMO_APP_INPUT_ASSEMBLY_NUM
void CipFree(void *pa_poData)
Free memory allocated by the OpENer.
void ConfigureExclusiveOwnerConnectionPoint(const unsigned int connection_number, const unsigned int output_assembly, const unsigned int input_assembly, const unsigned int config_assembly)
Configures the connection point for an exclusive owner connection.
Definition: appcontype.c:85
void CloseAllConnections(void)
Definition: appcontype.c:407
EipStatus ResetDeviceToInitialConfiguration(void)
Reset the device to the initial configuration and emulate as close as possible a power cycle of the d...
uint8_t EipBool8
Definition: typedefs.h:37
EipUint8 g_assembly_data097[10]
void RunIdleChanged(EipUint32 pa_nRunIdleValue)
Inform the application that the Run/Idle State has been changed by the originator.
#define DEMO_APP_EXPLICT_ASSEMBLY_NUM
#define DEMO_APP_OUTPUT_ASSEMBLY_NUM
uint16_t CipUint
Definition: typedefs.h:47
EipUint8 g_assembly_data096[40]
EipBool8 BeforeAssemblyDataSend(CipInstance *pa_pstInstance)
Inform the application that the data of an assembly object will be sent.
EipUint32 instance_number
Definition: ciptypes.h:228