/*******************************************************************************
* Copyright (c) 2012, Rockwell Automation, Inc.
* All rights reserved.
*
******************************************************************************/
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <syslog.h>
#include <unistd.h> //Header file for sleep(). man 3 sleep for details.
#include <pthread.h>
#include <stdbool.h>
#include <time.h>
#include "opener_api.h"
#include "appcontype.h"
#include "trace.h"
#include "cipidentity.h"
#include "ciptcpipinterface.h"
#include "cipqos.h"
#include "nvdata.h"
#if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
#include "cipethernetlink.h"
#include "../../amco_application/ethlinkcbs.h"
#endif
#include "../XlsHandler.h"
#include "../UtilitiesC.h"
#include "../UtilitiesCpp.h"
int newCipParam(char* name,unsigned char *value,int valueSize);
void lg(char verbose,char * text);
pthread_mutex_t lock1;
int DEMO_APP_OUTPUT_ASSEMBLY_NUM_101 = 101; //0x180
int DEMO_APP_INPUT_ASSEMBLY_NUM_100 = 100; //0x188
int DEMO_APP_INPUT_ASSEMBLY_NUM_110 = 110; //0x189
int DEMO_APP_INPUT_ASSEMBLY_NUM_111 = 111; //0x18A
int DEMO_APP_INPUT_ASSEMBLY_NUM_112 = 112; //0x18B
int DEMO_APP_INPUT_ASSEMBLY_NUM_113 = 113; //0x18C
int DEMO_APP_CONFIG_ASSEMBLY_NUM = 1; //0x001
int DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM = 254; //0x098
int DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM =254; //0x099
EipUint8 l_assembly_data101[assembly_data101_size];//={0};//128
EipUint8 l_assembly_data100[assembly_data100_size+4];//724+4
EipUint8 l_assembly_data110[assembly_data110_size+4];
EipUint8 l_assembly_data111[assembly_data111_size+4];
EipUint8 l_assembly_data112[assembly_data112_size+4];
EipUint8 l_assembly_data113[assembly_data113_size+4];
EipUint8 g_assembly_data101[assembly_data101_size];//={0};//128
EipUint8 g_assembly_data100[assembly_data100_size+4];//724+4
EipUint8 g_assembly_data110[assembly_data110_size+4];
EipUint8 g_assembly_data111[assembly_data111_size+4];
EipUint8 g_assembly_data112[assembly_data112_size+4];
EipUint8 g_assembly_data113[assembly_data113_size+4];
EipUint8 g_assembly_data097[assembly_data097_size];//32 iarv
extern ParamStruct paramStructArray[paramStructArraySize];
void updateParamStructArray(EipUint8 l_assembly_data101[],int size);
//void updateParamStructArray(EipUint8 *array,int size,char msgType[5]);
//int call_from_c_newParam(CIP_Manager* p, unsigned char * value, int valueSize);
/* global variables for demo application (4 assembly data fields) ************/
/* local functions */
/* global functions called by the stack */
EipStatus ApplicationInitialization(void) {
/* create 3 assembly object instances*/
/*INPUT*/
CreateAssemblyObject( DEMO_APP_OUTPUT_ASSEMBLY_NUM_101, g_assembly_data101,
sizeof(g_assembly_data101));
/*OUTPUT*/
CreateAssemblyObject( DEMO_APP_INPUT_ASSEMBLY_NUM_100, g_assembly_data100,
sizeof(g_assembly_data100));
/*OUTPUT*/
CreateAssemblyObject( DEMO_APP_INPUT_ASSEMBLY_NUM_110, g_assembly_data110,
sizeof(g_assembly_data110));
/*OUTPUT*/
CreateAssemblyObject( DEMO_APP_INPUT_ASSEMBLY_NUM_111, g_assembly_data111,
sizeof(g_assembly_data111));
/*OUTPUT*/
CreateAssemblyObject( DEMO_APP_INPUT_ASSEMBLY_NUM_112, g_assembly_data112,
sizeof(g_assembly_data112));
/*OUTPUT*/
CreateAssemblyObject( DEMO_APP_INPUT_ASSEMBLY_NUM_113, g_assembly_data113,
sizeof(g_assembly_data113));
/*CONFIG*/
CreateAssemblyObject( DEMO_APP_CONFIG_ASSEMBLY_NUM, g_assembly_data097,
sizeof(g_assembly_data097));
/*Heart-beat output assembly for Input only connections */
//CreateAssemblyObject(DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM, NULL, 0);
CreateAssemblyObject(DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM, g_assembly_data_input_heartbeat,
sizeof(g_assembly_data_input_heartbeat));
/*Heart-beat output assembly for Listen only connections */
CreateAssemblyObject(DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM, NULL, 0);
//CreateAssemblyObject(DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM, g_assembly_data_input_heartbeat,
// sizeof(g_assembly_data_input_heartbeat));
/* assembly for explicit messaging */
//CreateAssemblyObject( DEMO_APP_EXPLICT_ASSEMBLY_NUM, g_assembly_data09A,
// sizeof(g_assembly_data09A) );
ConfigureExclusiveOwnerConnectionPoint(0,
DEMO_APP_OUTPUT_ASSEMBLY_NUM_101,
DEMO_APP_INPUT_ASSEMBLY_NUM_100,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureInputOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_100,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureListenOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_100,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
///////////////////////////////////////////////////
ConfigureExclusiveOwnerConnectionPoint(0,
DEMO_APP_OUTPUT_ASSEMBLY_NUM_101,
DEMO_APP_INPUT_ASSEMBLY_NUM_110,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureInputOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_110,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureListenOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_110,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
///////////////////////////////////////////////////
ConfigureExclusiveOwnerConnectionPoint(0,
DEMO_APP_OUTPUT_ASSEMBLY_NUM_101,
DEMO_APP_INPUT_ASSEMBLY_NUM_111,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureInputOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_111,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureListenOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_111,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
///////////////////////////////////////////////////
ConfigureExclusiveOwnerConnectionPoint(0,
DEMO_APP_OUTPUT_ASSEMBLY_NUM_101,
DEMO_APP_INPUT_ASSEMBLY_NUM_112,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureInputOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_112,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureListenOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_112,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
///////////////////////////////////////////////////
ConfigureExclusiveOwnerConnectionPoint(0,
DEMO_APP_OUTPUT_ASSEMBLY_NUM_101,
DEMO_APP_INPUT_ASSEMBLY_NUM_113,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureInputOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_INPUT_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_113,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
ConfigureListenOnlyConnectionPoint(0,
DEMO_APP_HEARTBEAT_LISTEN_ONLY_ASSEMBLY_NUM,
DEMO_APP_INPUT_ASSEMBLY_NUM_113,
DEMO_APP_CONFIG_ASSEMBLY_NUM);
/* For NV data support connect callback functions for each object class with
* NV data.
*/
InsertGetSetCallback(GetCipClass(kCipQoSClassCode), NvQosSetCallback,
kNvDataFunc);
InsertGetSetCallback(GetCipClass(kCipTcpIpInterfaceClassCode),
NvTcpipSetCallback,
kNvDataFunc);
#if defined(OPENER_ETHLINK_CNTRS_ENABLE) && 0 != OPENER_ETHLINK_CNTRS_ENABLE
/* For the Ethernet Interface & Media Counters connect a PreGetCallback and
* a PostGetCallback.
* The PreGetCallback is used to fetch the counters from the hardware.
* The PostGetCallback is utilized by the GetAndClear service to clear
* the hardware counters after the current data have been transmitted.
*/
{
CipClass *p_eth_link_class = GetCipClass(kCipEthernetLinkClassCode);
InsertGetSetCallback(p_eth_link_class,
EthLnkPreGetCallback,
kPreGetFunc);
InsertGetSetCallback(p_eth_link_class,
EthLnkPostGetCallback,
kPostGetFunc);
/* Specify the attributes for which the callback should be executed. */
for (int idx = 0; idx < OPENER_ETHLINK_INSTANCE_CNT; ++idx)
{
CipAttributeStruct *p_eth_link_attr;
CipInstance *p_eth_link_inst =
GetCipInstance(p_eth_link_class, idx+1);
OPENER_ASSERT(p_eth_link_inst);
/* Interface counters attribute */
p_eth_link_attr = GetCipAttribute(p_eth_link_inst, 4);
p_eth_link_attr->attribute_flags |= (kPreGetFunc | kPostGetFunc);
/* Media counters attribute */
p_eth_link_attr = GetCipAttribute(p_eth_link_inst, 5);
p_eth_link_attr->attribute_flags |= (kPreGetFunc | kPostGetFunc);
}
}
#endif
return kEipStatusOk;
}