OpENer - Open Source EtherNet/IP(TM) I/O Target Stack  2.1
 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 {
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 */
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) {
76  break;
77  }
78  }
79 
80  /* clean up network state */
82  }
83  /* close remaining sessions and connections, cleanup used data */
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 }
void CipConnectionObjectListArrayFree(DoublyLinkedListNode **node)
EipStatus NetworkHandlerProcessOnce(void)
Tracing infrastructure for OpENer.
int main(int argc, char *arg[])
Definition: main.c:32
EipStatus NetworkHandlerFinish(void)
void SetDeviceSerialNumber(const EipUint32 serial_number)
Set the serial number of the device's identity object.
Definition: cipidentity.c:54
void ConfigureIpMacAddress(const CipUint interface_index)
Definition: networkconfig.c:29
void CipStackInit(const EipUint16 unique_connection_id)
Initialize and setup the CIP-stack.
Definition: cipcommon.c:36
#define OPENER_TRACE_STATE(...)
Definition: trace.h:88
DoublyLinkedList connection_list
int g_end_stack
Flag indicating if the stack should end its execution.
Definition: main.c:29
void DoublyLinkedListInitialize(DoublyLinkedList *list, NodeMemoryAllocator allocator, NodeMemoryDeallocator deallocator)
void ShutdownCipStack(void)
Shutdown of the CIP stack.
Definition: cipcommon.c:61
int newfd
void ConfigureDomainName(void)
Configure the domain name of the device.
Definition: networkconfig.c:87
EipStatus NetworkHandlerInitialize(void)
Initializes the network handler, shall be implemented by a port-specific networkhandler.
DoublyLinkedListNode * CipConnectionObjectListArrayAllocator()
uint16_t EipUint16
Definition: typedefs.h:33
void LeaveStack(int pa_nSig)
Signal handler function for ending stack execution.
Definition: main.c:89
void ConfigureHostName(void)
Configure the host name of the device.