forked from espressif/esp-modbus
freemodbus: fix clang warnings
* Original commit: espressif/esp-idf@cf4c95532f
This commit is contained in:
@@ -76,6 +76,8 @@ PR_BEGIN_EXTERN_C
|
||||
/* ----------------------- Type definitions ---------------------------------*/
|
||||
#ifndef _MB_M_H
|
||||
|
||||
#define MB_FUNC_CODE_MAX 127
|
||||
|
||||
/*! \ingroup modbus
|
||||
* \brief Modbus serial transmission modes (RTU/ASCII).
|
||||
*
|
||||
|
@@ -53,7 +53,7 @@ PR_BEGIN_EXTERN_C
|
||||
#define MB_FUNC_DIAG_GET_COM_EVENT_CNT ( 11 )
|
||||
#define MB_FUNC_DIAG_GET_COM_EVENT_LOG ( 12 )
|
||||
#define MB_FUNC_OTHER_REPORT_SLAVEID ( 17 )
|
||||
#define MB_FUNC_ERROR ( 128 )
|
||||
#define MB_FUNC_ERROR ( 128u )
|
||||
/* ----------------------- Type definitions ---------------------------------*/
|
||||
typedef enum
|
||||
{
|
||||
|
@@ -229,7 +229,7 @@ eMBRegisterCB( UCHAR ucFunctionCode, pxMBFunctionHandler pxHandler )
|
||||
int i;
|
||||
eMBErrorCode eStatus;
|
||||
|
||||
if( ( 0 < ucFunctionCode ) && ( ucFunctionCode <= 127 ) )
|
||||
if( ( 0 < ucFunctionCode ) && ( ucFunctionCode <= MB_FUNC_CODE_MAX ) )
|
||||
{
|
||||
ENTER_CRITICAL_SECTION( );
|
||||
if( pxHandler != NULL )
|
||||
@@ -332,7 +332,7 @@ eMBDisable( void )
|
||||
eMBErrorCode
|
||||
eMBPoll( void )
|
||||
{
|
||||
static UCHAR *ucMBFrame;
|
||||
static UCHAR *ucMBFrame = NULL;
|
||||
static UCHAR ucRcvAddress;
|
||||
static UCHAR ucFunctionCode;
|
||||
static USHORT usLength;
|
||||
@@ -373,8 +373,10 @@ eMBPoll( void )
|
||||
break;
|
||||
|
||||
case EV_EXECUTE:
|
||||
ESP_LOGD(MB_PORT_TAG, "%s:EV_EXECUTE", __func__);
|
||||
ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
|
||||
if ( !ucMBFrame ) {
|
||||
return MB_EILLSTATE;
|
||||
}
|
||||
ESP_LOGD(MB_PORT_TAG, "%s:EV_EXECUTE", __func__); ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
|
||||
eException = MB_EX_ILLEGAL_FUNCTION;
|
||||
for( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
|
||||
{
|
||||
@@ -416,7 +418,10 @@ eMBPoll( void )
|
||||
case EV_FRAME_SENT:
|
||||
ESP_LOGD(MB_PORT_TAG, "%s:EV_FRAME_SENT", __func__);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return MB_ENOERR;
|
||||
return eStatus;
|
||||
}
|
||||
|
@@ -44,17 +44,17 @@
|
||||
#include "mbfunc.h"
|
||||
|
||||
#include "mbport.h"
|
||||
#if MB_MASTER_RTU_ENABLED == 1
|
||||
#if MB_MASTER_RTU_ENABLED
|
||||
#include "mbrtu.h"
|
||||
#endif
|
||||
#if MB_MASTER_ASCII_ENABLED == 1
|
||||
#if MB_MASTER_ASCII_ENABLED
|
||||
#include "mbascii.h"
|
||||
#endif
|
||||
#if MB_MASTER_TCP_ENABLED == 1
|
||||
#if MB_MASTER_TCP_ENABLED
|
||||
#include "mbtcp.h"
|
||||
#endif
|
||||
|
||||
#if MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
|
||||
#if MB_MASTER_RTU_ENABLED || MB_MASTER_ASCII_ENABLED
|
||||
|
||||
#ifndef MB_PORT_HAS_CLOSE
|
||||
#define MB_PORT_HAS_CLOSE 1
|
||||
@@ -264,25 +264,28 @@ eMBMasterDisable( void )
|
||||
eMBErrorCode
|
||||
eMBMasterPoll( void )
|
||||
{
|
||||
static UCHAR *ucMBFrame;
|
||||
static UCHAR *ucMBFrame = NULL;
|
||||
static UCHAR ucRcvAddress;
|
||||
static UCHAR ucFunctionCode;
|
||||
static USHORT usLength;
|
||||
static eMBException eException;
|
||||
|
||||
int i , j;
|
||||
int i;
|
||||
int j;
|
||||
eMBErrorCode eStatus = MB_ENOERR;
|
||||
eMBMasterEventType eEvent;
|
||||
eMBMasterErrorEventType errorType;
|
||||
|
||||
/* Check if the protocol stack is ready. */
|
||||
if( eMBState != STATE_ENABLED ) {
|
||||
if( eMBState != STATE_ENABLED )
|
||||
{
|
||||
return MB_EILLSTATE;
|
||||
}
|
||||
|
||||
/* Check if there is a event available. If not return control to caller.
|
||||
* Otherwise we will handle the event. */
|
||||
if( xMBMasterPortEventGet( &eEvent ) == TRUE ) {
|
||||
if( xMBMasterPortEventGet( &eEvent ) == TRUE )
|
||||
{
|
||||
switch ( eEvent )
|
||||
{
|
||||
case EV_MASTER_NO_EVENT:
|
||||
@@ -308,40 +311,57 @@ eMBMasterPoll( void )
|
||||
case EV_MASTER_FRAME_RECEIVED:
|
||||
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBFrame, &usLength );
|
||||
// Check if the frame is for us. If not ,send an error process event.
|
||||
if ( ( eStatus == MB_ENOERR ) && ( ucRcvAddress == ucMBMasterGetDestAddress() ) ) {
|
||||
if ( ( eStatus == MB_ENOERR ) && ( ucRcvAddress == ucMBMasterGetDestAddress() ) )
|
||||
{
|
||||
ESP_LOGD(MB_PORT_TAG, "%s: Packet data received successfully (%u).", __func__, eStatus);
|
||||
( void ) xMBMasterPortEventPost( EV_MASTER_EXECUTE );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
|
||||
ESP_LOGD(MB_PORT_TAG, "%s: Packet data receive failed (addr=%u)(%u).", __func__, ucRcvAddress, eStatus);
|
||||
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
|
||||
}
|
||||
break;
|
||||
case EV_MASTER_EXECUTE:
|
||||
if ( !ucMBFrame )
|
||||
{
|
||||
return MB_EILLSTATE;
|
||||
}
|
||||
ESP_LOGD(MB_PORT_TAG, "%s:EV_MASTER_EXECUTE", __func__);
|
||||
ucFunctionCode = ucMBFrame[MB_PDU_FUNC_OFF];
|
||||
eException = MB_EX_ILLEGAL_FUNCTION;
|
||||
/* If receive frame has exception. The receive function code highest bit is 1.*/
|
||||
if(ucFunctionCode >> 7) {
|
||||
if (ucFunctionCode & MB_FUNC_ERROR)
|
||||
{
|
||||
eException = (eMBException)ucMBFrame[MB_PDU_DATA_OFF];
|
||||
} else {
|
||||
for (i = 0; i < MB_FUNC_HANDLERS_MAX; i++) {
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < MB_FUNC_HANDLERS_MAX; i++)
|
||||
{
|
||||
/* No more function handlers registered. Abort. */
|
||||
if (xMasterFuncHandlers[i].ucFunctionCode == 0) {
|
||||
if (xMasterFuncHandlers[i].ucFunctionCode == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (xMasterFuncHandlers[i].ucFunctionCode == ucFunctionCode) {
|
||||
if (xMasterFuncHandlers[i].ucFunctionCode == ucFunctionCode)
|
||||
{
|
||||
vMBMasterSetCBRunInMasterMode(TRUE);
|
||||
/* If master request is broadcast,
|
||||
* the master need execute function for all slave.
|
||||
*/
|
||||
if ( xMBMasterRequestIsBroadcast() ) {
|
||||
if ( xMBMasterRequestIsBroadcast() )
|
||||
{
|
||||
usLength = usMBMasterGetPDUSndLength();
|
||||
for(j = 1; j <= MB_MASTER_TOTAL_SLAVE_NUM; j++){
|
||||
for(j = 1; j <= MB_MASTER_TOTAL_SLAVE_NUM; j++)
|
||||
{
|
||||
vMBMasterSetDestAddress(j);
|
||||
eException = xMasterFuncHandlers[i].pxHandler(ucMBFrame, &usLength);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
eException = xMasterFuncHandlers[i].pxHandler(ucMBFrame, &usLength);
|
||||
}
|
||||
vMBMasterSetCBRunInMasterMode(FALSE);
|
||||
@@ -350,10 +370,13 @@ eMBMasterPoll( void )
|
||||
}
|
||||
}
|
||||
/* If master has exception ,Master will send error process.Otherwise the Master is idle.*/
|
||||
if (eException != MB_EX_NONE) {
|
||||
if (eException != MB_EX_NONE)
|
||||
{
|
||||
vMBMasterSetErrorType(EV_ERROR_EXECUTE_FUNCTION);
|
||||
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
vMBMasterCBRequestSuccess( );
|
||||
vMBMasterRunResRelease( );
|
||||
}
|
||||
@@ -363,10 +386,10 @@ eMBMasterPoll( void )
|
||||
/* Master is busy now. */
|
||||
vMBMasterGetPDUSndBuf( &ucMBFrame );
|
||||
eStatus = peMBMasterFrameSendCur( ucMBMasterGetDestAddress(), ucMBFrame, usMBMasterGetPDUSndLength() );
|
||||
if (eStatus != MB_ENOERR) {
|
||||
if (eStatus != MB_ENOERR)
|
||||
{
|
||||
ESP_LOGD(MB_PORT_TAG, "%s:Frame send error. %d", __func__, eStatus);
|
||||
}
|
||||
|
||||
break;
|
||||
case EV_MASTER_FRAME_SENT:
|
||||
ESP_LOGD(MB_PORT_TAG, "%s:EV_MASTER_FRAME_SENT", __func__);
|
||||
@@ -396,6 +419,9 @@ eMBMasterPoll( void )
|
||||
}
|
||||
vMBMasterRunResRelease();
|
||||
break;
|
||||
default:
|
||||
ESP_LOGD(MB_PORT_TAG, "%s: incorrect event triggered = %d.", __func__, eEvent);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// xMBMasterPortEventGet has unbloked the task but the event bits are not set
|
||||
@@ -465,13 +491,13 @@ void vMBMasterSetCurTimerMode( eMBMasterTimerMode eMBTimerMode )
|
||||
}
|
||||
|
||||
/* Get Modbus Master current timer mode.*/
|
||||
eMBMasterTimerMode xMBMasterGetCurTimerMode( void )
|
||||
eMBMasterTimerMode MB_PORT_ISR_ATTR xMBMasterGetCurTimerMode( void )
|
||||
{
|
||||
return eMasterCurTimerMode;
|
||||
}
|
||||
|
||||
/* The master request is broadcast? */
|
||||
BOOL xMBMasterRequestIsBroadcast( void ){
|
||||
BOOL MB_PORT_ISR_ATTR xMBMasterRequestIsBroadcast( void ){
|
||||
return xFrameIsBroadcast;
|
||||
}
|
||||
|
||||
@@ -480,5 +506,4 @@ void vMBMasterRequestSetType( BOOL xIsBroadcast ){
|
||||
xFrameIsBroadcast = xIsBroadcast;
|
||||
}
|
||||
|
||||
|
||||
#endif // MB_MASTER_RTU_ENABLED > 0 || MB_MASTER_ASCII_ENABLED > 0
|
||||
#endif // MB_MASTER_RTU_ENABLED || MB_MASTER_ASCII_ENABLED
|
||||
|
@@ -362,7 +362,7 @@ BOOL MB_PORT_ISR_ATTR xMBMasterRTUTimerExpired(void)
|
||||
/* An error occured while receiving the frame. */
|
||||
case STATE_M_RX_ERROR:
|
||||
vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
|
||||
xNeedPoll = xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
|
||||
xNeedPoll = xMBMasterPortEventPost(EV_MASTER_ERROR_PROCESS);
|
||||
break;
|
||||
|
||||
/* Function called in an illegal state. */
|
||||
|
@@ -119,18 +119,18 @@ xMBMasterPortEventGet( eMBMasterEventType * eEvent)
|
||||
EventBits_t uxBits;
|
||||
BOOL xEventHappened = FALSE;
|
||||
uxBits = xEventGroupWaitBits(
|
||||
xEventGroupMasterHdl, // The event group being tested.
|
||||
MB_EVENT_POLL_MASK, // The bits within the event group to wait for.
|
||||
pdTRUE, // Masked bits should be cleared before returning.
|
||||
pdFALSE, // Don't wait for both bits, either bit will do.
|
||||
portMAX_DELAY); // Wait forever for either bit to be set.
|
||||
xEventGroupMasterHdl, // The event group being tested.
|
||||
MB_EVENT_POLL_MASK, // The bits within the event group to wait for.
|
||||
pdTRUE, // Masked bits should be cleared before returning.
|
||||
pdFALSE, // Don't wait for both bits, either bit will do.
|
||||
portMAX_DELAY); // Wait forever for either bit to be set.
|
||||
|
||||
// Check if poll event is correct
|
||||
if (uxBits & MB_EVENT_POLL_MASK) {
|
||||
*eEvent = (eMBMasterEventType)(uxBits);
|
||||
xEventHappened = TRUE;
|
||||
} else {
|
||||
ESP_LOGE(MB_PORT_TAG,"%s: Incorrect event triggered.", __func__);
|
||||
ESP_LOGE(MB_PORT_TAG,"%s: Incorrect event triggered = %d.", __func__, uxBits);
|
||||
xEventHappened = FALSE;
|
||||
}
|
||||
return xEventHappened;
|
||||
|
Reference in New Issue
Block a user