📄 dnet.c
字号:
if ((allocChoice.byte & 0x70) == 0x40)
{
mRoutePutError(ERR_INVALID_ATTRIB_VALUE);
mRoutePutByte(_DNET_ERR_INVALID_PARAM);
return (1);
}
// Cannot continue if a parent has not been allocated
if (!allocChoice.bits.b0)
{
mRoutePutError(ERR_INVALID_ATTRIB_VALUE);
mRoutePutByte(_DNET_ERR_INVALID_PARAM);
return (1);
}
// Set the master's MAC before attempting to create any
// connections because the Master's MAC is needed for the
// bit-strobe connection upon creation.
uDNet.AllocInfo.MasterMACID = allocMAC;
// Try to create the connections
if (!_DNetCreateConnections(allocChoice))
{
mRoutePutError(ERR_RESOURCE_UNAVAILABLE);
mRoutePutByte(_DNET_ERR_RSRC_NOT_AVAIL);
// Reset the Master's MAC
uDNet.AllocInfo.MasterMACID = 0xFF;
return (1);
}
uDNet.AllocInfo.AllocChoice.byte = allocChoice.byte;
}
// Connection is allocated
else
{
// Verify the request is from the allocated master
if (uDNet.AllocInfo.MasterMACID != allocMAC)
{
mRoutePutError(ERR_OBJECT_STATE_CONFLICT);
mRoutePutByte(_DNET_ERR_CONFLICT);
return (1);
}
// A NULL allocation choice is not valid
if (allocChoice.byte == 0)
{
mRoutePutError(ERR_INVALID_ATTRIB_VALUE);
mRoutePutByte(_DNET_ERR_INVALID_PARAM);
return (1);
}
// Check for connection support
if (_DNetAllocNoSupportChk(allocChoice))
{
mRoutePutError(ERR_RESOURCE_UNAVAILABLE);
mRoutePutByte(_DNET_ERR_INVALID_PARAM);
return (1);
}
#if SUPPORT_COS && SUPPORT_CYCLIC
// Cannot allocate both COS and cyclic
if (((allocChoice.byte | uDNet.AllocInfo.AllocChoice.byte) & 0x30) == 0x30)
{
mRoutePutError(ERR_INVALID_ATTRIB_VALUE);
mRoutePutByte(_DNET_ERR_INVALID_PARAM);
return (1);
}
#endif
#if (SUPPORT_COS || SUPPORT_CYCLIC) && SUPPORT_POLLED
// Cannot support polling if COS or cyclic is already enabled
if ((uDNet.AllocInfo.AllocChoice.byte & 0x30) && (allocChoice.byte & 0x02))
{
mRoutePutError(ERR_RESOURCE_UNAVAILABLE);
mRoutePutByte(_DNET_ERR_RSRC_NOT_AVAIL);
return (1);
}
#endif
// Cannot support acknowledge supression if COS or cyclic not enabled
if (((allocChoice.byte | uDNet.AllocInfo.AllocChoice.byte) & 0x70) == 0x40)
{
mRoutePutError(ERR_INVALID_ATTRIB_VALUE);
mRoutePutByte(_DNET_ERR_INVALID_PARAM);
return (1);
}
// Cannot continue if the request matches existing connections
if ((allocChoice.byte & uDNet.AllocInfo.AllocChoice.byte) & 0x3F)
{
mRoutePutError(ERR_OBJECT_STATE_CONFLICT);
mRoutePutByte(_DNET_ERR_CONFLICT);
return (1);
}
// Try to create the connections
if (!_DNetCreateConnections(allocChoice))
{
mRoutePutError(ERR_RESOURCE_UNAVAILABLE);
mRoutePutByte(_DNET_ERR_RSRC_NOT_AVAIL);
return (1);
}
// Set the alloc choice
uDNet.AllocInfo.AllocChoice.byte |= allocChoice.byte;
}
// Set the responce format (Message Body Format)
#if ((!CLASS_WIDTH_16BIT) && (!INSTANCE_WIDTH_16BIT))
mRoutePutByte(0);
#endif
#if ((!CLASS_WIDTH_16BIT) && INSTANCE_WIDTH_16BIT)
mRoutePutByte(1);
#endif
#if (CLASS_WIDTH_16BIT && INSTANCE_WIDTH_16BIT)
mRoutePutByte(2);
#endif
#if (CLASS_WIDTH_16BIT && (!INSTANCE_WIDTH_16BIT))
mRoutePutByte(3);
#endif
return (1);
}
/*********************************************************************
* Function: unsigned char DNetReleaseConnection(void)
*
* PreCondition: The path (aService, aClassID, aInstanceID) must
* be loaded prior to using this function. If service
* indicates any type of IO then the buffer pointers
* must be initialized.
*
* Input: aHeader, aClassID, aInstanceID, aService
* *pOutBuf, *pInBuf, aOutBufDataLen, aInBufDataLen
* aOutBufLen, aInBufLen
*
* Output: aHeader, aService
* *pOutBuf, *pInBuf, aOutBufDataLen, aInBufDataLen
*
* Side Effects:
*
* Overview: Release predefined master/slave connection set.
*
* Note: None
********************************************************************/
unsigned char _DNetReleaseConnection(void)
{
BYTE releaseChoice;
releaseChoice.byte = mRouteGetByte();
// Check for connection support
if (_DNetAllocNoSupportChk(releaseChoice))
{
mRoutePutError(ERR_RESOURCE_UNAVAILABLE);
mRoutePutByte(_DNET_ERR_INVALID_PARAM);
return (1);
}
// A NULL release choice is not valid
if (releaseChoice.byte == 0)
{
mRoutePutError(ERR_INVALID_ATTRIB_VALUE);
mRoutePutByte(_DNET_ERR_INVALID_PARAM);
return (1);
}
// Cannot continue if the request matches non-existant connections
if (((releaseChoice.byte) & (~uDNet.AllocInfo.AllocChoice.byte)) & 0x3F)
{
mRoutePutError(ERR_OBJECT_STATE_CONFLICT);
mRoutePutByte(_DNET_ERR_CONFLICT);
return (1);
}
// Close the connections
_DNetCloseConnections(releaseChoice);
// Release the connection(s)
uDNet.AllocInfo.AllocChoice.byte &= (~(releaseChoice.byte));
// If all connections are released then reset the master MAC ID
if (uDNet.AllocInfo.AllocChoice.byte == 0) uDNet.AllocInfo.MasterMACID = 0xFF;
// If ack supression is set and cyclic/COS is not then clear the bit
if ((uDNet.AllocInfo.AllocChoice.byte & 0x70) == 0x40) uDNet.AllocInfo.AllocChoice.byte &= 0x0F;
return (1);
}
/*********************************************************************
* Function: unsigned char _DNetAllocNoSupportChk(BYTE choice)
*
* PreCondition: None
*
* Input: The allocation choice as a bitmap
*
* Output: 1 or 0
*
* Side Effects: None
*
* Overview: Validates the allocation choice to determine if a
* connection is not supported. Returns TRUE if the
* any of the connections are not supported.
*
* Note: None
********************************************************************/
unsigned char _DNetAllocNoSupportChk(BYTE choice)
{
#if SUPPORT_POLLED == 0
if (choice.bits.b1) return (1); // Polled messgae not supported
#endif
#if SUPPORT_BIT_STROBED == 0
if (choice.bits.b2) return (1); // Bit Strobed not supported
#endif
#if SUPPORT_MULTICAST_POLL == 0
if (choice.bits.b3) return (1); // Multicast Polled Message not supported
#endif
#if SUPPORT_COS == 0
if (choice.bits.b4) return (1); // COS Message not supported
#endif
#if SUPPORT_CYCLIC == 0
if (choice.bits.b5) return (1); // Cyclic Message not supported
#endif
if (choice.bits.b7) return (1); // Reserved bit never supported
return (0);
}
/*********************************************************************
* Function: void _DNetCreateConnections(BYTE choice)
*
* PreCondition: None
*
* Input: The allocation choice as a bitmap
*
* Output: None
*
* Side Effects: This function will call to individual connection
* objects to open. If any open request fails then
* any objects that were just opened will be closed
* immediately.
*
* Overview: This function decodes the request and calls
* the appropriate functions to create the connection.
*
* Note: None
********************************************************************/
unsigned char _DNetCreateConnections(BYTE choice)
{
BYTE allocProgress;
unsigned char err_stat;
err_stat = 1;
allocProgress.byte = 0;
// Allocate Explicit Messaging if not already allocated
if (choice.bits.b0) // Explicit message
{
if (_Conn1Create()) allocProgress.bits.b0 = 1;
else err_stat = 0;
}
#if SUPPORT_POLLED
if (choice.bits.b1) // Polled message
{
if (_Conn2Create()) allocProgress.bits.b1 = 1;
else err_stat = 0;
}
#endif
#if SUPPORT_BIT_STROBED
if (choice.bits.b2) // Bit Strobed Message
{
if (_Conn3Create()) allocProgress.bits.b2 = 1;
else err_stat = 0;
}
#endif
#if SUPPORT_MULTICAST_POLL
if (choice.bits.b3) // Multicast Polled Message
{
if (_Conn5Create()) allocProgress.bits.b4 = 1;
else err_stat = 0;
}
#endif
#if SUPPORT_COS
if (choice.bits.b4) // COS Message
{
if (_Conn4Create())
{
allocProgress.bits.b3 = 1;
#if SUPPORT_COS_BOTH_DIR
#if SUPPORT_POLLED
if (!uDNet.AllocInfo.AllocChoice.bits.poll)
{
if (_Conn2Create()) allocProgress.bits.b1 = 1;
else err_stat = 0;
}
#else
if (_Conn2Create()) allocProgress.bits.b1 = 1;
else err_stat = 0;
#endif
#endif
}
else err_stat = 0;
}
#endif
#if SUPPORT_CYCLIC
if (choice.bits.b5) // Cyclic Message
{
if (_Conn4Create())
{
allocProgress.bits.b3 = 1;
#if SUPPORT_COS_BOTH_DIR
#if SUPPORT_POLLED
if (!uDNet.AllocInfo.AllocChoice.bits.poll)
{
if (_Conn2Create()) allocProgress.bits.b1 = 1;
else err_stat = 0;
}
#else
if (_Conn2Create()) allocProgress.bits.b1 = 1;
else err_stat = 0;
#endif
#endif
}
else err_stat = 0;
}
#endif
// Close all just opened connections if there was an error
if (err_stat == 0)
{
if (allocProgress.bits.b0) _Conn1Close();
#if SUPPORT_POLLED || SUPPORT_COS_BOTH_DIR
if (allocProgress.bits.b1) _Conn2Close();
#endif
#if SUPPORT_BIT_STROBED
if (allocProgress.bits.b2) _Conn3Close();
#endif
#if SUPPORT_COS || SUPPORT_CYCLIC
if (allocProgress.bits.b3) _Conn4Close();
#endif
#if SUPPORT_MULTICAST_POLL
if (allocProgress.bits.b4) _Conn5Close();
#endif
}
return (err_stat);
}
/*********************************************************************
* Function: void _DNetCreateConnections(BYTE choice)
*
* PreCondition:
*
* Input:
*
* Output:
*
* Side Effects:
*
* Overview: This function decodes the choice byte and calls
* the appropriate functions to delete the connections.
*
* Note: None
********************************************************************/
void _DNetCloseConnections(BYTE choice)
{
if (choice.bits.b0) _Conn1Close(); // Explicit message
#if SUPPORT_POLLED
if (choice.bits.b1) _Conn2Close(); // Polled messgae
#endif
#if SUPPORT_BIT_STROBED
if (choice.bits.b2) _Conn3Close(); // Bit Strobed
#endif
#if SUPPORT_MULTICAST_POLL
if (choice.bits.b3) _Conn5Close(); // Multicast Polled Message
#endif
#if SUPPORT_COS
if (choice.bits.b4) // COS Message
{
_Conn4Close();
#if SUPPORT_COS_BOTH_DIR
#if SUPPORT_POLLED
if (!uDNet.AllocInfo.AllocChoice.bits.poll)
{
_Conn2Close();
}
#else
_Conn2Close();
#endif
#endif
#if SUPPORT_POLLED
if (!uDNet.AllocInfo.AllocChoice.bits.poll)
#endif
#if SUPPORT_COS_BOTH_DIR
_Conn2Close();
#endif
}
#endif
#if SUPPORT_CYCLIC
if (choice.bits.b5) // Cyclic Message
{
_Conn4Close();
#if SUPPORT_POLLED
if (!uDNet.AllocInfo.AllocChoice.bits.poll)
#endif
#if SUPPORT_COS_BOTH_DIR
_Conn2Close();
#endif
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -