EtherNet/IP™ Adapter3.09.00
 
Loading...
Searching...
No Matches

◆ EI_API_CIP_addRoutableInstanceCustService()

uint32_t EI_API_CIP_addRoutableInstanceCustService ( T *  pCipNode_p,
uint16_t  classId_p,
uint16_t  instanceId_p,
EI_API_CIP_SCustomService_t pService_p,
uint8_t  linkAddr_p 
)

Add custom service to the class instance.

This function adds one or more custom service/s to the class with the class and instance identifiers passed as parameters classId_p and instanceId_p. Compare to EI_API_CIP_addRoutableInstanceService gives the possibility to build response for remote request on side of application. Target instance is encoded by instance ID and link address.

Remarks
For details about encoding please see EI_API_CIP_createRoutableInstance.
Parameters
[in]pCipNode_pPointer to the CIP node.
[in]classId_pClass identifier.
[in]instanceId_pInstance identifier without encoding.
[in]pService_pPointer to custom service structure, see EI_API_CIP_SCustomService_t type definition.
[in]linkAddr_pLink address used to encode the target instance ID.
Returns
EI_API_CIP_EError_t as uint32_t value.
Return values
EI_API_CIP_eERR_OKSuccess.
EI_API_CIP_eERR_GENERALInstance encoding failed.
EI_API_CIP_eERR_NODE_INVALIDCIP node is invalid, possibly EI_API_CIP_NODE_new() was not called.
EI_API_CIP_eERR_CLASS_BLACKLISTOperation on the CIP object with specified identifier (class ID) are not allowed.
EI_API_CIP_eERR_CLASS_DOES_NOT_EXISTClass does not exists in CIP node dictionary.
EI_API_CIP_eERR_INSTANCE_DOES_NOT_EXISTInstance does not exist in CIP node dictionary.
EI_API_CIP_eERR_SERVICE_ALREADY_EXISTService already exist.
EI_API_CIP_eERR_SERVICE_INVALIDService is invalid, possibly NULL pointer.
EI_API_CIP_eERR_MEMALLOCMemory allocation error.
Example
#include "EI_API.h"
uint8_t EI_APP_DEVICE_PROFILE_RawGetSingle (const void *ptObj_p, void *ptConObj_p, EI_API_CIP_SBuffer_t *ptConsumeBuf_p, EI_API_CIP_SBuffer_t *ptProduceBuf_p)
{
// Check size of buffer against size of data to sent
if (4 + 232 < ptProduceBuf_p->maxData)
{
ptProduceBuf_p->pDataBuf[0] = 0x80 | 0x4B; // RESPONSE | RAW_GET_SINGLE;
ptProduceBuf_p->pDataBuf[1] = 0; // Reserved, always zero
ptProduceBuf_p->pDataBuf[2] = 0x00; // SUCCESS
ptProduceBuf_p->pDataBuf[3] = 0; // No Additional Status Data
ptProduceBuf_p->actData = 4; // Update actual number of bytes
for (int i = 0; i <= 232; i++)
{
ptProduceBuf_p->pDataBuf[4 + i] = i; // Update one data byte
ptProduceBuf_p->actData++; // Update actual number of bytes
}
ret = EI_API_CIP_SERVICE_eERR_RESPONSE; // Send response back with success.
}
else
{
ptProduceBuf_p->pDataBuf[0] = 0x80 | 0x4B; // RESPONSE | RAW_GET_SINGLE;
ptProduceBuf_p->pDataBuf[1] = 0; // Reserved, always zero
ptProduceBuf_p->pDataBuf[2] = 0x11; // DATA_TOO_LARGE
ptProduceBuf_p->pDataBuf[3] = 0; // No Additional Status Data
ptProduceBuf_p->actData = 4; // Update actual number of bytes
ret = EI_API_CIP_SERVICE_eERR_ERR_RESPONSE; // Send response back with error.
}
return ret;
}
void EI_APP_DEVICE_PROFILE_cipSetup (EI_API_CIP_NODE_T* pCipNode)
{
uint32_t errCode;
uint16_t classId = 0x010B;
const uint8_t maxlinkaddr = 8;
// Create a class
errCode = EI_API_CIP_createClass(pCipNode, classId);
EI_API_CIP_setRoutingMaxLinkAddr(pCipNode, maxlinkaddr);
for (int linkAddr = 1; ((EI_API_CIP_eERR_OK == errCode) && (linkAddr <= maxlinkaddr)); ++linkAddr)
{
for (int instance = 1; ((EI_API_CIP_eERR_OK == errCode) && (instance <= 1)); ++instance)
{
// Create instance, instance ID is encoded with specified link address
errCode = EI_API_CIP_createRoutableInstance(pCipNode, classId, instance, linkAddr);
// Add custom service to instance 0x01 for the class with classId
service.code = 0x4B; // RAW_GET_SINGLE
service.fuServiceUser = NULL;
service.fuServiceStack = EI_APP_DEVICE_PROFILE_RawGetSingle;
errCode = EI_API_CIP_addRoutableInstanceCustService(pCipNode, classId, instance, &service, linkAddr);
}
}
}
ETHIP_API uint32_t EI_API_CIP_createClass(T *pCipNode_p, uint16_t classId_p)
Create a CIP class.
Definition EI_API_CIP_stub.c:215
@ EI_API_CIP_SERVICE_eERR_INVALID
Definition EI_API_CIP_define.h:151
@ EI_API_CIP_SERVICE_eERR_ERR_RESPONSE
Definition EI_API_CIP_define.h:153
@ EI_API_CIP_SERVICE_eERR_RESPONSE
Definition EI_API_CIP_define.h:152
@ EI_API_CIP_eERR_OK
Definition EI_API_CIP_define.h:26
ETHIP_API uint32_t EI_API_CIP_setRoutingMaxLinkAddr(T *pCipNode_p, uint8_t linkAddr_p)
Initialize a maximum number of link addresses used by application.
Definition EI_API_CIP_stub.c:5457
ETHIP_API uint32_t EI_API_CIP_createRoutableInstance(T *pCipNode_p, uint16_t classId_p, uint16_t instanceId_p, uint8_t linkAddr_p)
Creates a routable CIP instance.
Definition EI_API_CIP_stub.c:5712
ETHIP_API uint32_t EI_API_CIP_addRoutableInstanceCustService(T *pCipNode_p, uint16_t classId_p, uint16_t instanceId_p, EI_API_CIP_SCustomService_t *pService_p, uint8_t linkAddr_p)
Add custom service to the class instance.
Definition EI_API_CIP_stub.c:6053
uint16_t maxData
Definition EI_API_CIP_define.h:204
uint8_t * pDataBuf
Definition EI_API_CIP_define.h:206
uint16_t actData
Definition EI_API_CIP_define.h:205
Consumer/Producer buffer structure declaration.
Definition EI_API_CIP_define.h:203
uint16_t code
Service Code Number.
Definition EI_API_CIP_define.h:228
EI_API_CIP_CBStack fuServiceStack
Function pointer to the callback required by stack.
Definition EI_API_CIP_define.h:229
EI_API_CIP_CBService fuServiceUser
Function pointer to the callback set by user.
Definition EI_API_CIP_define.h:230
Custom service structure declaration.
Definition EI_API_CIP_define.h:227
See also
EI_API_CIP_createClass EI_API_CIP_createRoutableInstance EI_API_CIP_EError_t