协议栈是Molex提供的 , 集成了来自Zurich University of Applied Sciences:::
const char * PnioDevice::m_pRPC_OBJECT_UUID = "DEA00000-6C97-11D1-8271-000000000000";
PnioDevice::PolledTimer *PnioDevice::m_pConnectReqDelayTimer = NULL;
GefMutex *PnioDevice::m_pConnectReqDelayTimerLock = NULL;
/*
* Macros to send asynchronous requests to the Profinet controller stack.
*/
#define SEND_ABORT_REQ(deviceNum,pArep,pContext) {\
PnioAsyncCommandPtr pReq = PnioAbortRequest::create(deviceNum,pArep,pContext);\
PnioAsyncCmdDispatcher::getInstance()->dispatchRequest(pReq);}
#define SEND_CONNECT_REQ(deviceNum,pArep,pContext){\
PnioAsyncCommandPtr pReq = PnioConnectRequest::create(deviceNum,pArep,pContext);\
PnioAsyncCmdDispatcher::getInstance()->dispatchRequest(pReq);}
#define SEND_DECLARE_REQ(deviceNum,pArep,pContext,pDownload){\
PnioAsyncCommandPtr pReq = PnioDeclareRequest::create(deviceNum,pArep,pContext,pDownload);\
PnioAsyncCmdDispatcher::getInstance()->dispatchRequest(pReq);}
#define SEND_RELEASE_REQ(deviceNum,pArep,pContext){\
PnioAsyncCommandPtr pReq = PnioReleaseRequest::create(deviceNum,pArep,pContext);\
PnioAsyncCmdDispatcher::getInstance()->dispatchRequest(pReq);}
#define SEND_UNDECLARE_REQ(deviceNum,pArep,pContext){\
PnioAsyncCommandPtr pReq = PnioUndeclareRequest::create(deviceNum,pArep,pContext);\
PnioAsyncCmdDispatcher::getInstance()->dispatchRequest(pReq);}
#define SEND_BACKUP_REQ(deviceNum,pArep,pContext){\
PnioAsyncCommandPtr pReq = PnioRequestBackupRequest::create(deviceNum,pArep,pContext);\
PnioAsyncCmdDispatcher::getInstance()->dispatchRequest(pReq);}
/******************************************************************************
* PnioDevice
*****************************************************************************/
PnioDevice::PnioDevice(
const T_BYTE deviceNumber,
const std::string & deviceName,
const T_UINT16 vendorID,
const T_UINT16 deviceID,
const T_UINT16 deviceInstance,
const T_UINT32 ipAddress,
const T_UINT32 ipNetmask,
const T_UINT32 ipGateway,
const T_MAC_ADDRESS controllerMacAddress,
const T_UINT16 controllerVendorId,
const T_UINT16 controllerDeviceId,
const std::string controllerName,
const IPnioDeviceClientWeakPtr & pClient) :
m_pncDeviceNumber(deviceNumber),
m_stackDeviceNumber(NB_MAX_CONNEXION + UNSIGNED_ONE),
m_deviceName(deviceName),
m_vendorID(vendorID),
m_deviceID(deviceID),
m_deviceInstance(deviceInstance),
m_ipAddress(ipAddress),
m_ipAddrStr(),
m_ipNetmask(ipNetmask),
m_ipGateway(ipGateway),
m_controllerMacAddress(controllerMacAddress),
m_controllerVendorId(controllerVendorId),
m_controllerDeviceId(controllerDeviceId),
m_controllerName(controllerName),
m_pClient(pClient),
m_isDeclared(false),
m_isConnected(false),
m_hasAppReadyReceived(false),
m_onConnectResponseSent(false),
m_onFirstInputXferDelayed(false),
m_disconnecting(false),
m_arepList(),
m_weakThis(),
m_pDownload(NULL),
m_pDevCfgBlk(NULL),
m_pDevARBlk(NULL),
m_pDevListOfCRBlock(),
m_pDevListOfExpSubModBlk(),
m_pDevAlmCRBlk(NULL),
m_pDevListOfWriteBlk(),
m_pDevARVers(NULL),
m_pDevRPCBlk(NULL),
m_pDevListOfMCRBlk(),
m_pDevPrmSvrCRBlock(NULL),
m_pDevARRPCCRBlock(NULL),
m_pDevSRInfoBlock(NULL),
m_pAREP(NULL),
m_pAlarmTallySet(),
m_pConnectTallySet(),
m_pSavedModDiffBlock(),
m_DisconnectReqSelfInitiated(false)
{
if (NULL == pClient.lock())
{
throw NullPointerException(
PNIO_PNIODEVICE_MODID,
__LINE__,
PNIO_SFAIL_INVALID_ARGUMENT,
std::string(__FILE__) + " : Null PnioDeviceClient!");
}
// If we do not yet have a Connect Request Delay Timer (which is shared
// by all PnioDevice instances) Then
if (NULL == m_pConnectReqDelayTimer)
{
// Create the "static" Connect Request Delay Timer, setting it up to
// have it indicate that it is already expired (that way, the first
// connect request will proceed without delay).
// NOTE: This object is intentionally never deleted - we want this
// to mimic a real static object (can't make it a real static
// object since it is derived from GefObject, and GefObjects
// can't be static).
m_pConnectReqDelayTimer = new PolledTimer(true);
}
// If we do not yet have a Connect Request Delay Timer lock (which is shared
// by all PnioDevice instances) Then
if (NULL == m_pConnectReqDelayTimerLock)
{
// Create the "static" lock for the Connect Request Delay Timer.
// NOTE: This object is intentionally never deleted - we want this
// to mimic a real static object (can't make it a real static
// object since it is derived from GefObject, and GefObjects
// can't be static).
m_pConnectReqDelayTimerLock = new GefMutex();
}
// Get the device's IP address in string format.
SCODE status = osaNetDwordInetAddrToStr(m_ipAddress, m_ipAddrStr);
if (FAILED(status))
{
throw InstanceNotInitializedException(
PNIO_PNIODEVICE_MODID,
__LINE__,
status,
"PnioDevice::PnioDevice - Failed IP addr string convert.");
}
// Create and clear the alarm tallies for this device.
m_pAlarmTallySet = PnioAlarmTallySet::create();
m_pAlarmTallySet->reset();
// Create and clear the tallies for Connects, Disconnects and Aborts on this device.
m_pConnectTallySet = PnioConnectTallySet::create();
m_pConnectTallySet->reset();
}
/******************************************************************************
* ~PnioDevice
*****************************************************************************/
PnioDevice::~PnioDevice()
{
try
{
// Note, freePnioDeviceHeapMemory is called here to free the memories
// allocated using the new operator in declarePnioDevice.
// The static analysis tool fails to catch this redirection, it
// expects to find the corresponding deletes being done explicitly
// in the destructor.
freePnioDeviceHeapMemory();
// Note: We do not free the objects pointed to by
// m_pConnectReqDelayTimer and m_pConnectReqDelayTimerLock, since
// those objects are intended to be "static" objects used by all
// instances of the PnioDevice class.
}
catch(...)
{
// Log a fault to indicate we had a failure.
logPncFault(PNIO_PNIODEVICE_MODID,
__LINE__,
IOC_SOFT_FAULT,
IOCSW_MODULE_FW,
INTERNAL_RUNTIME_ERROR,
DIAGNOSTIC,
0,
0,
PNIO_SFAIL_OBJ_DTOR_FAILURE,
0, NULL);
}
}
/***************************************************************************************
*********** Copyright 2005 Zurich University of Applied Sciences / InES **************
***************************************************************************************
**
** File : mrp_portitf.c
**
** Description : This file implements the mrp_portitf interface used to access
** the OS dependent system calls from the MRP protocol.
**
** Functions to implement:
** - MRP_PortItf_T_Init
** - MRP_PortItf_T_Cleanup
** - MRP_PortItf_T_receive
** - MRP_PortItf_T_send
** - MRP_PortItf_T_setPortState
** - MRP_PortItf_T_getPortState
** - MRP_PortItf_T_signalLocalLinkChange
** - MRP_PortItf_T_getLinkState
** - MRP_PortItf_T_getMAC
** - MRP_PortItf_T_getNumberOfPorts
**
** The interfaces in this file assume "logical" (as opposed to physical) port number
** references. In the case of the RX3i PNS, 0-3 refer to external ports 1-4,
** respectively. Port 4 refers to the "interface" port. It's not expected
** that any of these routines use the interface port.
***************************************************************************************
楼主最近还看过