OpENer - Open Source EtherNet/IP(TM) I/O Target Stack
2.1
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
main.c
Go to the documentation of this file.
1
/*******************************************************************************
2
* Copyright (c) 2009, Rockwell Automation, Inc.
3
* All rights reserved.
4
*
5
******************************************************************************/
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <signal.h>
9
10
#include "
generic_networkhandler.h
"
11
#include "
opener_api.h
"
12
#include "
cipcommon.h
"
13
#include "
trace.h
"
14
#include "
networkconfig.h
"
15
16
extern
int
newfd
;
17
18
/******************************************************************************/
23
void
24
LeaveStack
(
int
pa_nSig);
25
26
/*****************************************************************************/
29
int
g_end_stack
= 0;
30
31
/******************************************************************************/
32
int
main
(
int
argc,
33
char
*arg[]) {
34
EipUint16
nUniqueConnectionID;
35
36
if
(argc != 2) {
37
printf(
"Wrong number of command line parameters!\n"
);
38
printf(
"The correct command line parameters are:\n"
);
39
printf(
40
"./OpENer index\n"
);
41
printf(
42
" e.g. ./OpENer index\n"
);
43
exit(0);
44
}
else
{
45
DoublyLinkedListInitialize
(&
connection_list
,
46
CipConnectionObjectListArrayAllocator
,
47
CipConnectionObjectListArrayFree
);
48
/* fetch Internet address info from the platform */
49
ConfigureDomainName
(atoi(arg[1]) );
50
ConfigureHostName
(atoi(arg[1]) );
51
ConfigureIpMacAddress
(atoi(arg[1]) );
52
}
53
54
/*for a real device the serial number should be unique per device */
55
SetDeviceSerialNumber
(123456789);
56
57
/* nUniqueConnectionID should be sufficiently random or incremented and stored
58
* in non-volatile memory each time the device boots.
59
*/
60
nUniqueConnectionID = rand();
61
62
/* Setup the CIP Layer */
63
CipStackInit
(nUniqueConnectionID);
64
65
/* Setup Network Handles */
66
if
(
kEipStatusOk
==
NetworkHandlerInitialize
() ) {
67
g_end_stack
= 0;
68
#ifndef WIN32
69
/* register for closing signals so that we can trigger the stack to end */
70
signal(SIGHUP,
LeaveStack
);
71
#endif
72
73
/* The event loop. Put other processing you need done continually in here */
74
while
(1 !=
g_end_stack
) {
75
if
(
kEipStatusOk
!=
NetworkHandlerProcessOnce
() ) {
76
break
;
77
}
78
}
79
80
/* clean up network state */
81
NetworkHandlerFinish
();
82
}
83
/* close remaining sessions and connections, cleanup used data */
84
ShutdownCipStack
();
85
86
return
-1;
87
}
88
89
void
LeaveStack
(
int
pa_nSig) {
90
(void) pa_nSig;
/* kill unused parameter warning */
91
OPENER_TRACE_STATE
(
"got signal HUP\n"
);
92
g_end_stack
= 1;
93
}
opener_api.h
CipConnectionObjectListArrayFree
void CipConnectionObjectListArrayFree(DoublyLinkedListNode **node)
Definition:
cipconnectionobject.c:74
NetworkHandlerProcessOnce
EipStatus NetworkHandlerProcessOnce(void)
Definition:
generic_networkhandler.c:347
trace.h
Tracing infrastructure for OpENer.
main
int main(int argc, char *arg[])
Definition:
main.c:32
cipcommon.h
kEipStatusOk
Definition:
typedefs.h:94
NetworkHandlerFinish
EipStatus NetworkHandlerFinish(void)
Definition:
generic_networkhandler.c:419
SetDeviceSerialNumber
void SetDeviceSerialNumber(const EipUint32 serial_number)
Set the serial number of the device's identity object.
Definition:
cipidentity.c:54
networkconfig.h
ConfigureIpMacAddress
void ConfigureIpMacAddress(const CipUint interface_index)
Definition:
networkconfig.c:29
generic_networkhandler.h
CipStackInit
void CipStackInit(const EipUint16 unique_connection_id)
Initialize and setup the CIP-stack.
Definition:
cipcommon.c:36
OPENER_TRACE_STATE
#define OPENER_TRACE_STATE(...)
Definition:
trace.h:88
connection_list
DoublyLinkedList connection_list
Definition:
cipconnectionobject.c:53
g_end_stack
int g_end_stack
Flag indicating if the stack should end its execution.
Definition:
main.c:29
DoublyLinkedListInitialize
void DoublyLinkedListInitialize(DoublyLinkedList *list, NodeMemoryAllocator allocator, NodeMemoryDeallocator deallocator)
Definition:
doublylinkedlist.c:13
ShutdownCipStack
void ShutdownCipStack(void)
Shutdown of the CIP stack.
Definition:
cipcommon.c:61
newfd
int newfd
ConfigureDomainName
void ConfigureDomainName(void)
Configure the domain name of the device.
Definition:
networkconfig.c:87
NetworkHandlerInitialize
EipStatus NetworkHandlerInitialize(void)
Initializes the network handler, shall be implemented by a port-specific networkhandler.
Definition:
generic_networkhandler.c:67
CipConnectionObjectListArrayAllocator
DoublyLinkedListNode * CipConnectionObjectListArrayAllocator()
Definition:
cipconnectionobject.c:59
EipUint16
uint16_t EipUint16
Definition:
typedefs.h:33
LeaveStack
void LeaveStack(int pa_nSig)
Signal handler function for ending stack execution.
Definition:
main.c:89
ConfigureHostName
void ConfigureHostName(void)
Configure the host name of the device.
Definition:
networkconfig.c:218
src
ports
WIN32
main.c
Generated on Fri May 15 2020 21:07:15 for OpENer - Open Source EtherNet/IP(TM) I/O Target Stack by
1.8.6