diff --git a/freemodbus/modbus/ascii/mbascii.c b/freemodbus/modbus/ascii/mbascii.c index 1b7636e..3650d53 100644 --- a/freemodbus/modbus/ascii/mbascii.c +++ b/freemodbus/modbus/ascii/mbascii.c @@ -158,7 +158,7 @@ eMBASCIIReceive( UCHAR * pucRcvAddress, UCHAR ** pucFrame, USHORT * pusLength ) { return MB_EIO; } - + ENTER_CRITICAL_SECTION( ); assert( usFrameLength < MB_SER_PDU_SIZE_MAX ); @@ -193,7 +193,7 @@ eMBASCIISend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength ) eMBErrorCode eStatus = MB_ENOERR; UCHAR usLRC; - + /* Check if the receiver is still in idle state. If not we where too * slow with processing the received frame and the master sent another * frame on the network. We have to abort sending the frame. diff --git a/freemodbus/modbus/ascii/mbascii_m.c b/freemodbus/modbus/ascii/mbascii_m.c index fae0506..2e16567 100644 --- a/freemodbus/modbus/ascii/mbascii_m.c +++ b/freemodbus/modbus/ascii/mbascii_m.c @@ -437,7 +437,7 @@ xMBMasterASCIITransmitFSM( void ) /* Notify the task which called eMBMasterASCIISend that the frame has * been sent. */ case STATE_M_TX_NOTIFY: - xFrameIsBroadcast = ( ucMasterASCIISndBuf[MB_SEND_BUF_PDU_OFF - MB_SER_PDU_PDU_OFF] + xFrameIsBroadcast = ( ucMasterASCIISndBuf[MB_SEND_BUF_PDU_OFF - MB_SER_PDU_PDU_OFF] == MB_ADDRESS_BROADCAST ) ? TRUE : FALSE; vMBMasterRequestSetType( xFrameIsBroadcast ); eSndState = STATE_M_TX_XFWR; diff --git a/freemodbus/modbus/include/mbport.h b/freemodbus/modbus/include/mbport.h index aa9602a..4b072d5 100644 --- a/freemodbus/modbus/include/mbport.h +++ b/freemodbus/modbus/include/mbport.h @@ -163,7 +163,7 @@ BOOL xMBMasterPortSerialGetByte( CHAR * pucByte ); BOOL xMBMasterPortSerialPutByte( CHAR ucByte ); -BOOL xMBMasterPortSerialGetResponse( UCHAR **ppucMBSerialFrame, USHORT * usSerialLength ); +BOOL xMBMasterPortSerialGetResponse( UCHAR **ppucMBSerialFrame, USHORT * usSerialLength ); BOOL xMBMasterPortSerialSendRequest( UCHAR *pucMBSerialFrame, USHORT usSerialLength ); diff --git a/freemodbus/modbus/mb_m.c b/freemodbus/modbus/mb_m.c index fa3d386..5bfad56 100644 --- a/freemodbus/modbus/mb_m.c +++ b/freemodbus/modbus/mb_m.c @@ -363,8 +363,8 @@ eMBMasterPoll( void ) MB_PORT_CHECK(ucMBRcvFrame, MB_EILLSTATE, "Receive buffer initialization fail."); MB_PORT_CHECK(ucMBSendFrame, MB_EILLSTATE, "Send buffer initialization fail."); // 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() ) + || ( ucRcvAddress == MB_TCP_PSEUDO_ADDRESS) ) ) { if ( ( ucMBRcvFrame[MB_PDU_FUNC_OFF] & ~MB_FUNC_ERROR ) == ( ucMBSendFrame[MB_PDU_FUNC_OFF] ) ) { ESP_LOGD(MB_PORT_TAG, "%s: Packet data received successfully (%u).", __func__, eStatus); ESP_LOG_BUFFER_HEX_LEVEL("POLL receive buffer", (void*)ucMBRcvFrame, (uint16_t)usLength, ESP_LOG_DEBUG); @@ -376,9 +376,7 @@ eMBMasterPoll( void ) vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA); ( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS ); } - } - else - { + } else { vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA); ( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS ); ESP_LOGD( MB_PORT_TAG, "%s: Packet data receive failed (addr=%u)(%u).", diff --git a/freemodbus/modbus/rtu/mbrtu_m.c b/freemodbus/modbus/rtu/mbrtu_m.c index 8e5271d..85b1980 100644 --- a/freemodbus/modbus/rtu/mbrtu_m.c +++ b/freemodbus/modbus/rtu/mbrtu_m.c @@ -230,12 +230,12 @@ eMBMasterRTUSend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength /* Activate the transmitter. */ eSndState = STATE_M_TX_XMIT; - + if ( xMBMasterPortSerialSendRequest( ( UCHAR * ) pucMasterSndBufferCur, usMasterSndBufferCount ) == FALSE ) { eStatus = MB_EIO; } - + // The place to enable RS485 driver vMBMasterPortSerialEnable( FALSE, TRUE ); } diff --git a/freemodbus/port/port.c b/freemodbus/port/port.c index 6dca483..ca8eb5b 100644 --- a/freemodbus/port/port.c +++ b/freemodbus/port/port.c @@ -91,7 +91,7 @@ BOOL xMBPortSerialWaitEvent(QueueHandle_t xMbUartQueue, uart_event_t* pxEvent, U * received buffer and its length using parameters. */ __attribute__ ((weak)) -BOOL xMBMasterPortSerialGetResponse( UCHAR **ppucMBSerialFrame, USHORT * usSerialLength ) +BOOL xMBMasterPortSerialGetResponse( UCHAR **ppucMBSerialFrame, USHORT * usSerialLength ) { ESP_LOGD(MB_PORT_TAG, " %s default", __func__); return TRUE; diff --git a/freemodbus/tcp_master/port/port_tcp_master.c b/freemodbus/tcp_master/port/port_tcp_master.c index 9aeb063..390026d 100644 --- a/freemodbus/tcp_master/port/port_tcp_master.c +++ b/freemodbus/tcp_master/port/port_tcp_master.c @@ -298,7 +298,7 @@ static int xMBTCPPortMasterGetBuf(MbSlaveInfo_t* pxInfo, UCHAR* pucDstBuf, USHOR // Receive data from connected client while (usBytesLeft > 0) { xMBTCPPortMasterCheckShutdown(); - xLength = recv(pxInfo->xSockId, pucBuf, usBytesLeft, 0); + xLength = recv(pxInfo->xSockId, pucBuf, usBytesLeft, 0); if (xLength < 0) { if (errno == EAGAIN) { // Read timeout occurred, check the timeout and return @@ -334,7 +334,7 @@ static int vMBTCPPortMasterReadPacket(MbSlaveInfo_t* pxInfo) if (pxInfo) { MB_PORT_CHECK((pxInfo->xSockId > 0), -1, "Try to read incorrect socket = #%d.", pxInfo->xSockId); // Read packet header - xRet = xMBTCPPortMasterGetBuf(pxInfo, &pxInfo->pucRcvBuf[0], + xRet = xMBTCPPortMasterGetBuf(pxInfo, &pxInfo->pucRcvBuf[0], MB_TCP_UID, xMBTCPPortMasterGetRespTimeLeft(pxInfo)); if (xRet < 0) { pxInfo->xRcvErr = xRet; @@ -348,7 +348,7 @@ static int vMBTCPPortMasterReadPacket(MbSlaveInfo_t* pxInfo) // If we have received the MBAP header we can analyze it and calculate // the number of bytes left to complete the current request. xLength = (int)MB_TCP_GET_FIELD(pxInfo->pucRcvBuf, MB_TCP_LEN); - xRet = xMBTCPPortMasterGetBuf(pxInfo, &pxInfo->pucRcvBuf[MB_TCP_UID], + xRet = xMBTCPPortMasterGetBuf(pxInfo, &pxInfo->pucRcvBuf[MB_TCP_UID], xLength, xMBTCPPortMasterGetRespTimeLeft(pxInfo)); if (xRet < 0) { pxInfo->xRcvErr = xRet; diff --git a/freemodbus/tcp_slave/port/port_tcp_slave.c b/freemodbus/tcp_slave/port/port_tcp_slave.c index bf7e997..722cc75 100644 --- a/freemodbus/tcp_slave/port/port_tcp_slave.c +++ b/freemodbus/tcp_slave/port/port_tcp_slave.c @@ -561,7 +561,7 @@ static void vMBTCPPortServerTask(void *pvParameters) pxClientInfo->xSockId, pxClientInfo->pcIpAddr, xErr); break; } - + if (xShutdownSemaphore) { xSemaphoreGive(xShutdownSemaphore); vTaskDelete(NULL); diff --git a/idf_component.yml b/idf_component.yml index dbe4eb2..aa6d96e 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -1,4 +1,4 @@ -version: "1.0.6" +version: "1.0.7" description: ESP-MODBUS is the official Modbus library for Espressif SoCs. url: https://github.com/espressif/esp-modbus dependencies: