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 <string.h>
9 #include <stdlib.h>
10 
11 #define DEMO_APP_INPUT_ASSEMBLY_NUM 100 //0x064
12 #define DEMO_APP_OUTPUT_ASSEMBLY_NUM 150 //0x096
13 #define DEMO_APP_CONFIG_ASSEMBLY_NUM 151 //0x097
14 #define DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM 152 //0x098
15 #define DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM 153 //0x099
16 #define DEMO_APP_EXPLICT_ASSEMBLY_NUM 154 //0x09A
17 
18 /* global variables for demo application (4 assembly data fields) ************/
19 
21 
22 EipUint8 g_assembly_data064[32]; /* Input */
23 EipUint8 g_assembly_data096[32]; /* Output */
24 EipUint8 g_assembly_data097[10]; /* Config */
25 EipUint8 g_assembly_data09A[32]; /* Explicit */
26 
28  /* create 3 assembly object instances*/
29  /*INPUT*/
31  sizeof(g_assembly_data064) );
32 
33  /*OUTPUT*/
35  sizeof(g_assembly_data096) );
36 
37  /*CONFIG*/
39  sizeof(g_assembly_data097) );
40 
41  /*Heart-beat output assembly for Input only connections */
43 
44  /*Heart-beat output assembly for Listen only connections */
46 
47  /* assembly for explicit messaging */
49  sizeof(g_assembly_data09A) );
50 
62 
63  return kEipStatusOk;
64 }
65 
66 void HandleApplication(void) {
67  /* check if application needs to trigger an connection */
68 }
69 
70 void CheckIoConnectionEvent(unsigned int pa_unOutputAssembly,
71  unsigned int pa_unInputAssembly,
72  IoConnectionEvent pa_eIOConnectionEvent) {
73  /* maintain a correct output state according to the connection state*/
74 
75  (void) pa_unOutputAssembly; /* suppress compiler warning */
76  (void) pa_unInputAssembly; /* suppress compiler warning */
77  (void) pa_eIOConnectionEvent; /* suppress compiler warning */
78 }
79 
81  EipStatus nRetVal = kEipStatusOk;
82 
83  /*handle the data received e.g., update outputs of the device */
84  switch (pa_pstInstance->instance_number) {
86  /* Data for the output assembly has been received.
87  * Mirror it to the inputs */
88  memcpy( &g_assembly_data064[0], &g_assembly_data096[0],
89  sizeof(g_assembly_data064) );
90  break;
92  /* do something interesting with the new data from
93  * the explicit set-data-attribute message */
94  break;
96  /* Add here code to handle configuration data and check if it is ok
97  * The demo application does not handle config data.
98  * However in order to pass the test we accept any data given.
99  * EIP_ERROR
100  */
101  nRetVal = kEipStatusOk;
102  break;
103  }
104  return nRetVal;
105 }
106 
108  /*update data to be sent e.g., read inputs of the device */
109  /*In this sample app we mirror the data from out to inputs on data receive
110  * therefore we need nothing to do here. Just return true to inform that
111  * the data is new.
112  */
113 
114  if (pa_pstInstance->instance_number == DEMO_APP_EXPLICT_ASSEMBLY_NUM) {
115  /* do something interesting with the existing data
116  * for the explicit get-data-attribute message */
117  }
118  return true;
119 }
120 
122  /* add reset code here*/
124  return kEipStatusOk;
125 }
126 
128  /*rest the parameters */
130  /*than perform device reset*/
131  ResetDevice();
132  return kEipStatusOk;
133 }
134 
135 void *
136 CipCalloc(unsigned pa_nNumberOfElements,
137  unsigned pa_nSizeOfElement) {
138  return calloc(pa_nNumberOfElements, pa_nSizeOfElement);
139 }
140 
141 void CipFree(void *pa_poData) {
142  free(pa_poData);
143 }
144 
145 void RunIdleChanged(EipUint32 pa_nRunIdleValue) {
146  (void) pa_nRunIdleValue;
147 }
148 
EipStatus ApplicationInitialization(void)
Callback for the application initialization.
#define DEMO_APP_INPUT_ASSEMBLY_NUM
#define DEMO_APP_EXPLICT_ASSEMBLY_NUM
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_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM
CipUint g_encapsulation_inactivity_timeout
#13 Number of seconds of inactivity before TCP connection is closed
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]
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
#define DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM
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.
uint16_t CipUint
Definition: typedefs.h:47
#define DEMO_APP_CONFIG_ASSEMBLY_NUM
EipUint8 g_assembly_data096[40]
EipBool8 BeforeAssemblyDataSend(CipInstance *pa_pstInstance)
Inform the application that the data of an assembly object will be sent.
#define DEMO_APP_OUTPUT_ASSEMBLY_NUM
EipUint32 instance_number
Definition: ciptypes.h:228