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 <string.h>
8 #include <stdlib.h>
9 #include <stdbool.h>
10 
11 #include "opener_api.h"
12 #include "appcontype.h"
13 #include "trace.h"
14 #include "cipidentity.h"
15 
16 #define DEMO_APP_INPUT_ASSEMBLY_NUM 100 //0x064
17 #define DEMO_APP_OUTPUT_ASSEMBLY_NUM 150 //0x096
18 #define DEMO_APP_CONFIG_ASSEMBLY_NUM 151 //0x097
19 #define DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM 152 //0x098
20 #define DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM 153 //0x099
21 #define DEMO_APP_EXPLICT_ASSEMBLY_NUM 154 //0x09A
22 
23 /* global variables for demo application (4 assembly data fields) ************/
24 
26 
27 EipUint8 g_assembly_data064[32]; /* Input */
28 EipUint8 g_assembly_data096[32]; /* Output */
29 EipUint8 g_assembly_data097[10]; /* Config */
30 EipUint8 g_assembly_data09A[32]; /* Explicit */
31 
33  /* create 3 assembly object instances*/
34  /*INPUT*/
36  sizeof(g_assembly_data064) );
37 
38  /*OUTPUT*/
40  sizeof(g_assembly_data096) );
41 
42  /*CONFIG*/
44  sizeof(g_assembly_data097) );
45 
46  /*Heart-beat output assembly for Input only connections */
48 
49  /*Heart-beat output assembly for Listen only connections */
51 
52  /* assembly for explicit messaging */
54  sizeof(g_assembly_data09A) );
55 
67 
68  return kEipStatusOk;
69 }
70 
71 void HandleApplication(void) {
72  /* check if application needs to trigger an connection */
73 }
74 
75 void CheckIoConnectionEvent(unsigned int output_assembly_id,
76  unsigned int input_assembly_id,
77  IoConnectionEvent io_connection_event) {
78  /* maintain a correct output state according to the connection state*/
79 
80  (void) output_assembly_id; /* suppress compiler warning */
81  (void) input_assembly_id; /* suppress compiler warning */
82  (void) io_connection_event; /* suppress compiler warning */
83 }
84 
86  EipStatus status = kEipStatusOk;
87 
88  /*handle the data received e.g., update outputs of the device */
89  switch (instance->instance_number) {
91  /* Data for the output assembly has been received.
92  * Mirror it to the inputs */
93  memcpy( &g_assembly_data064[0], &g_assembly_data096[0],
94  sizeof(g_assembly_data064) );
95  break;
97  /* do something interesting with the new data from
98  * the explicit set-data-attribute message */
99  break;
101  /* Add here code to handle configuration data and check if it is ok
102  * The demo application does not handle config data.
103  * However in order to pass the test we accept any data given.
104  * EIP_ERROR
105  */
106  status = kEipStatusOk;
107  break;
108  default:
110  "Unknown assembly instance ind AfterAssemblyDataReceived");
111  break;
112  }
113  return status;
114 }
115 
117  /*update data to be sent e.g., read inputs of the device */
118  /*In this sample app we mirror the data from out to inputs on data receive
119  * therefore we need nothing to do here. Just return true to inform that
120  * the data is new.
121  */
122 
123  if (pa_pstInstance->instance_number == DEMO_APP_EXPLICT_ASSEMBLY_NUM) {
124  /* do something interesting with the existing data
125  * for the explicit get-data-attribute message */
126  }
127  return true;
128 }
129 
131  /* add reset code here*/
133  return kEipStatusOk;
134 }
135 
137  /*rest the parameters */
139  /*than perform device reset*/
140  ResetDevice();
141  return kEipStatusOk;
142 }
143 
144 void *
145 CipCalloc(size_t number_of_elements,
146  size_t size_of_element) {
147  return calloc(number_of_elements, size_of_element);
148 }
149 
150 void CipFree(void *data) {
151  free(data);
152 }
153 
154 void RunIdleChanged(EipUint32 run_idle_value) {
155  OPENER_TRACE_INFO("Run/Idle handler triggered\n");
156  if((0x0001 & run_idle_value) == 1) {
158  } else {
160  }
161  (void) run_idle_value;
162 }
163 
EipStatus ApplicationInitialization(void)
Callback for the application initialization.
Tracing infrastructure for OpENer.
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_LISTEN_ONLY_ASSEMBLY_NUM
#define DEMO_APP_EXPLICT_ASSEMBLY_NUM
CipUint g_encapsulation_inactivity_timeout
#13 Number of seconds of inactivity before TCP connection is closed
#define DEMO_APP_CONFIG_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 OPENER_TRACE_INFO(...)
Definition: trace.h:89
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
CipIdentitySetExtendedDeviceStatus(CipIdentityExtendedStatus extended_status)
Definition: cipidentity.c:185
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_INPUT_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
#define DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM