master add modbus buffer propagation

This commit is contained in:
aleks
2024-05-06 14:26:30 +02:00
parent 5e7a26b640
commit 17de1dd9dd
7 changed files with 142 additions and 45 deletions

View File

@@ -207,16 +207,20 @@ void vMBMasterPortTimersDisable( void );
/* ----------------- Callback for the master error process ------------------*/ /* ----------------- Callback for the master error process ------------------*/
void vMBMasterErrorCBRespondTimeout( UCHAR ucDestAddress, const UCHAR* pucPDUData, void vMBMasterErrorCBRespondTimeout( uint64_t xTransId, UCHAR ucDestAddress,
USHORT ucPDULength ); const UCHAR* pucSendData, USHORT ucSendLength );
void vMBMasterErrorCBReceiveData( UCHAR ucDestAddress, const UCHAR* pucPDUData, void vMBMasterErrorCBReceiveData( uint64_t xTransId, UCHAR ucDestAddress,
USHORT ucPDULength ); const UCHAR* pucRecvData, USHORT ucRecvLength,
const UCHAR* pucSendData, USHORT ucSendLength );
void vMBMasterErrorCBExecuteFunction( UCHAR ucDestAddress, const UCHAR* pucPDUData, void vMBMasterErrorCBExecuteFunction( uint64_t xTransId, UCHAR ucDestAddress,
USHORT ucPDULength ); const UCHAR* pucRecvData, USHORT ucRecvLength,
const UCHAR* pucSendData, USHORT ucSendLength );
void vMBMasterCBRequestSuccess( void ); void vMBMasterCBRequestSuccess( uint64_t xTransId, UCHAR ucDestAddress,
const UCHAR* pucRecvData, USHORT ucRecvLength,
const UCHAR* pucSendData, USHORT ucSendLength );
#endif #endif
/* ----------------------- Callback for the protocol stack ------------------*/ /* ----------------------- Callback for the protocol stack ------------------*/
/*! /*!

View File

@@ -311,8 +311,8 @@ eMBMasterDisable( void )
eMBErrorCode eMBErrorCode
eMBMasterPoll( void ) eMBMasterPoll( void )
{ {
static UCHAR *ucMBSendFrame = NULL; static UCHAR *pucMBSendFrame = NULL;
static UCHAR *ucMBRcvFrame = NULL; static UCHAR *pucMBRecvFrame = NULL;
static UCHAR ucRcvAddress; static UCHAR ucRcvAddress;
static UCHAR ucFunctionCode; static UCHAR ucFunctionCode;
static USHORT usLength; static USHORT usLength;
@@ -343,9 +343,9 @@ eMBMasterPoll( void )
case EV_MASTER_FRAME_TRANSMIT: case EV_MASTER_FRAME_TRANSMIT:
ESP_LOGD(MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_FRAME_TRANSMIT", xEvent.xTransactionId); ESP_LOGD(MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_FRAME_TRANSMIT", xEvent.xTransactionId);
/* Master is busy now. */ /* Master is busy now. */
vMBMasterGetPDUSndBuf( &ucMBSendFrame ); vMBMasterGetPDUSndBuf( &pucMBSendFrame );
ESP_LOG_BUFFER_HEX_LEVEL("POLL transmit buffer", (void*)ucMBSendFrame, usMBMasterGetPDUSndLength(), ESP_LOG_DEBUG); ESP_LOG_BUFFER_HEX_LEVEL("POLL transmit buffer", (void*)pucMBSendFrame, usMBMasterGetPDUSndLength(), ESP_LOG_DEBUG);
eStatus = peMBMasterFrameSendCur( ucMBMasterGetDestAddress(), ucMBSendFrame, usMBMasterGetPDUSndLength() ); eStatus = peMBMasterFrameSendCur( ucMBMasterGetDestAddress(), pucMBSendFrame, usMBMasterGetPDUSndLength() );
if (eStatus != MB_ENOERR) { if (eStatus != MB_ENOERR) {
vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA); vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS ); ( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
@@ -356,24 +356,24 @@ eMBMasterPoll( void )
case EV_MASTER_FRAME_SENT: case EV_MASTER_FRAME_SENT:
if (xCurTransactionId == xEvent.xTransactionId) { if (xCurTransactionId == xEvent.xTransactionId) {
ESP_LOGD( MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_FRAME_SENT", xEvent.xTransactionId ); ESP_LOGD( MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_FRAME_SENT", xEvent.xTransactionId );
ESP_LOG_BUFFER_HEX_LEVEL("POLL sent buffer", (void*)ucMBSendFrame, usMBMasterGetPDUSndLength(), ESP_LOG_DEBUG); ESP_LOG_BUFFER_HEX_LEVEL("POLL sent buffer", (void*)pucMBSendFrame, usMBMasterGetPDUSndLength(), ESP_LOG_DEBUG);
} }
break; break;
case EV_MASTER_FRAME_RECEIVED: case EV_MASTER_FRAME_RECEIVED:
ESP_LOGD( MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_FRAME_RECEIVED", xEvent.xTransactionId ); ESP_LOGD( MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_FRAME_RECEIVED", xEvent.xTransactionId );
eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &ucMBRcvFrame, &usLength); eStatus = peMBMasterFrameReceiveCur( &ucRcvAddress, &pucMBRecvFrame, &usLength);
if (xCurTransactionId == xEvent.xTransactionId) { if (xCurTransactionId == xEvent.xTransactionId) {
MB_PORT_CHECK(ucMBSendFrame, MB_EILLSTATE, "Send buffer initialization fail."); MB_PORT_CHECK(pucMBSendFrame, MB_EILLSTATE, "Send buffer initialization fail.");
// Check if the frame is for us. If not ,send an error process event. // 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) ) ) { || ( ucRcvAddress == MB_TCP_PSEUDO_ADDRESS) ) ) {
if ( ( ucMBRcvFrame[MB_PDU_FUNC_OFF] & ~MB_FUNC_ERROR ) == ( ucMBSendFrame[MB_PDU_FUNC_OFF] ) ) { if ( ( pucMBRecvFrame[MB_PDU_FUNC_OFF] & ~MB_FUNC_ERROR ) == ( pucMBSendFrame[MB_PDU_FUNC_OFF] ) ) {
ESP_LOGD(MB_PORT_TAG, "%" PRIu64 ": Packet data received successfully (%u).", xEvent.xTransactionId, (unsigned)eStatus); ESP_LOGD(MB_PORT_TAG, "%" PRIu64 ": Packet data received successfully (%u).", xEvent.xTransactionId, (unsigned)eStatus);
ESP_LOG_BUFFER_HEX_LEVEL("POLL receive buffer", (void*)ucMBRcvFrame, (uint16_t)usLength, ESP_LOG_DEBUG); ESP_LOG_BUFFER_HEX_LEVEL("POLL receive buffer", (void*)pucMBRecvFrame, (uint16_t)usLength, ESP_LOG_DEBUG);
( void ) xMBMasterPortEventPost( EV_MASTER_EXECUTE ); ( void ) xMBMasterPortEventPost( EV_MASTER_EXECUTE );
} else { } else {
ESP_LOGE( MB_PORT_TAG, "Drop incorrect frame, receive_func(%u) != send_func(%u)", ESP_LOGE( MB_PORT_TAG, "Drop incorrect frame, receive_func(%u) != send_func(%u)",
ucMBRcvFrame[MB_PDU_FUNC_OFF], ucMBSendFrame[MB_PDU_FUNC_OFF]); pucMBRecvFrame[MB_PDU_FUNC_OFF], pucMBSendFrame[MB_PDU_FUNC_OFF]);
vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA); vMBMasterSetErrorType(EV_ERROR_RECEIVE_DATA);
( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS ); ( void ) xMBMasterPortEventPost( EV_MASTER_ERROR_PROCESS );
} }
@@ -393,15 +393,15 @@ eMBMasterPoll( void )
if (xCurTransactionId == xEvent.xTransactionId) { if (xCurTransactionId == xEvent.xTransactionId) {
if ( xMBMasterRequestIsBroadcast() if ( xMBMasterRequestIsBroadcast()
&& (( ucMBMasterGetCommMode() == MB_RTU ) || ( ucMBMasterGetCommMode() == MB_ASCII ) ) ) { && (( ucMBMasterGetCommMode() == MB_RTU ) || ( ucMBMasterGetCommMode() == MB_ASCII ) ) ) {
ucMBRcvFrame = ucMBSendFrame; pucMBRecvFrame = pucMBSendFrame;
} }
MB_PORT_CHECK(ucMBRcvFrame, MB_EILLSTATE, "receive buffer initialization fail."); MB_PORT_CHECK(pucMBRecvFrame, MB_EILLSTATE, "receive buffer initialization fail.");
ESP_LOGD(MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_EXECUTE", xEvent.xTransactionId); ESP_LOGD(MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_EXECUTE", xEvent.xTransactionId);
ucFunctionCode = ucMBRcvFrame[MB_PDU_FUNC_OFF]; ucFunctionCode = pucMBRecvFrame[MB_PDU_FUNC_OFF];
eException = MB_EX_ILLEGAL_FUNCTION; eException = MB_EX_ILLEGAL_FUNCTION;
/* If receive frame has exception. The receive function code highest bit is 1.*/ /* If receive frame has exception. The receive function code highest bit is 1.*/
if (ucFunctionCode & MB_FUNC_ERROR) { if (ucFunctionCode & MB_FUNC_ERROR) {
eException = (eMBException)ucMBRcvFrame[MB_PDU_DATA_OFF]; eException = (eMBException)pucMBRecvFrame[MB_PDU_DATA_OFF];
} else { } else {
for ( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ ) for ( i = 0; i < MB_FUNC_HANDLERS_MAX; i++ )
{ {
@@ -419,10 +419,10 @@ eMBMasterPoll( void )
for(j = 1; j <= MB_MASTER_TOTAL_SLAVE_NUM; j++) for(j = 1; j <= MB_MASTER_TOTAL_SLAVE_NUM; j++)
{ {
vMBMasterSetDestAddress(j); vMBMasterSetDestAddress(j);
eException = xMasterFuncHandlers[i].pxHandler(ucMBRcvFrame, &usLength); eException = xMasterFuncHandlers[i].pxHandler(pucMBRecvFrame, &usLength);
} }
} else { } else {
eException = xMasterFuncHandlers[i].pxHandler( ucMBRcvFrame, &usLength ); eException = xMasterFuncHandlers[i].pxHandler( pucMBRecvFrame, &usLength );
} }
vMBMasterSetCBRunInMasterMode( FALSE ); vMBMasterSetCBRunInMasterMode( FALSE );
break; break;
@@ -449,23 +449,31 @@ eMBMasterPoll( void )
ESP_LOGD( MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_ERROR_PROCESS", xEvent.xTransactionId); ESP_LOGD( MB_PORT_TAG, "%" PRIu64 ":EV_MASTER_ERROR_PROCESS", xEvent.xTransactionId);
/* Execute specified error process callback function. */ /* Execute specified error process callback function. */
errorType = eMBMasterGetErrorType( ); errorType = eMBMasterGetErrorType( );
vMBMasterGetPDUSndBuf( &ucMBSendFrame ); vMBMasterGetPDUSndBuf( &pucMBSendFrame );
switch ( errorType ) switch ( errorType )
{ {
case EV_ERROR_RESPOND_TIMEOUT: case EV_ERROR_RESPOND_TIMEOUT:
vMBMasterErrorCBRespondTimeout( ucMBMasterGetDestAddress( ), vMBMasterErrorCBRespondTimeout( xEvent.xTransactionId,
ucMBSendFrame, usMBMasterGetPDUSndLength( ) ); ucMBMasterGetDestAddress( ),
pucMBSendFrame, usMBMasterGetPDUSndLength( ) );
break; break;
case EV_ERROR_RECEIVE_DATA: case EV_ERROR_RECEIVE_DATA:
vMBMasterErrorCBReceiveData( ucMBMasterGetDestAddress( ), vMBMasterErrorCBReceiveData( xEvent.xTransactionId,
ucMBSendFrame, usMBMasterGetPDUSndLength( ) ); ucMBMasterGetDestAddress( ),
pucMBRecvFrame, usLength,
pucMBSendFrame, usMBMasterGetPDUSndLength( ) );
break; break;
case EV_ERROR_EXECUTE_FUNCTION: case EV_ERROR_EXECUTE_FUNCTION:
vMBMasterErrorCBExecuteFunction( ucMBMasterGetDestAddress( ), vMBMasterErrorCBExecuteFunction( xEvent.xTransactionId,
ucMBSendFrame, usMBMasterGetPDUSndLength( ) ); ucMBMasterGetDestAddress( ),
pucMBRecvFrame, usLength,
pucMBSendFrame, usMBMasterGetPDUSndLength( ) );
break; break;
case EV_ERROR_OK: case EV_ERROR_OK:
vMBMasterCBRequestSuccess( ); vMBMasterCBRequestSuccess( xEvent.xTransactionId,
ucMBMasterGetDestAddress( ),
pucMBRecvFrame, usLength,
pucMBSendFrame, usMBMasterGetPDUSndLength( ) );
break; break;
default: default:
ESP_LOGE( MB_PORT_TAG, "%" PRIu64 ":incorrect error type = %d.", xEvent.xTransactionId, (int)errorType); ESP_LOGE( MB_PORT_TAG, "%" PRIu64 ":incorrect error type = %d.", xEvent.xTransactionId, (int)errorType);

View File

@@ -105,6 +105,8 @@
#define MB_TCP_DEBUG (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) // Enable legacy debug output in TCP module. #define MB_TCP_DEBUG (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) // Enable legacy debug output in TCP module.
#define MB_ATTR_WEAK __attribute__ ((weak))
#define MB_TCP_GET_FIELD(buffer, field) ((USHORT)((buffer[field] << 8U) | buffer[field + 1])) #define MB_TCP_GET_FIELD(buffer, field) ((USHORT)((buffer[field] << 8U) | buffer[field + 1]))
#define MB_PORT_CHECK(a, ret_val, str, ...) \ #define MB_PORT_CHECK(a, ret_val, str, ...) \
@@ -198,6 +200,23 @@ UCHAR ucMBPortGetMode( void );
BOOL xMBPortSerialWaitEvent(QueueHandle_t xMbUartQueue, uart_event_t* pxEvent, ULONG xTimeout); BOOL xMBPortSerialWaitEvent(QueueHandle_t xMbUartQueue, uart_event_t* pxEvent, ULONG xTimeout);
/**
* This is modbus master user error handling funcion.
* If it is defined in the user application, then helps to handle the errors
* and received/sent buffers to transfer as well as handle the slave exception codes.
*
* @param xTransId - the identification of the trasaction
* @param ucDestAddress destination salve address
* @param usError - the error code, see the enumeration eMBMasterErrorEventType
* @param pucRecvData current receive data pointer
* @param ucRecvLength current length of receive buffer
* @param pucSendData Send buffer data
* @param ucSendLength Send buffer length
*/
MB_ATTR_WEAK
void vMBMasterErrorCBUserHandler( uint64_t xTransId, USHORT usError, UCHAR ucDestAddress, const UCHAR* pucRecvData, USHORT ucRecvLength,
const UCHAR* pucSendData, USHORT ucSendLength );
#ifdef __cplusplus #ifdef __cplusplus
PR_END_EXTERN_C PR_END_EXTERN_C
#endif /* __cplusplus */ #endif /* __cplusplus */

View File

@@ -191,30 +191,47 @@ void vMBMasterRunResRelease( void )
* This is modbus master respond timeout error process callback function. * This is modbus master respond timeout error process callback function.
* @note There functions will block modbus master poll while execute OS waiting. * @note There functions will block modbus master poll while execute OS waiting.
* *
* @param xTransId - the identification of the trasaction
* @param ucDestAddress destination salve address * @param ucDestAddress destination salve address
* @param pucPDUData PDU buffer data * @param pucRecvData current receive data pointer
* @param ucPDULength PDU buffer length * @param ucRecvLength current length of receive buffer
* @param pucSendData Send buffer data
* @param ucSendLength Send buffer length
* *
*/ */
void vMBMasterErrorCBRespondTimeout(UCHAR ucDestAddress, const UCHAR* pucPDUData, USHORT ucPDULength) void vMBMasterErrorCBRespondTimeout(uint64_t xTransId, UCHAR ucDestAddress, const UCHAR* pucSendData, USHORT ucSendLength)
{ {
(void)xEventGroupSetBits( xEventGroupMasterHdl, EV_MASTER_ERROR_RESPOND_TIMEOUT ); (void)xEventGroupSetBits( xEventGroupMasterHdl, EV_MASTER_ERROR_RESPOND_TIMEOUT );
ESP_LOGD(MB_PORT_TAG,"%s:Callback respond timeout.", __func__); ESP_LOGD(MB_PORT_TAG,"%s:Callback respond timeout.", __func__);
if (vMBMasterErrorCBUserHandler) {
vMBMasterErrorCBUserHandler( xTransId, (USHORT)EV_ERROR_RESPOND_TIMEOUT,
ucDestAddress, NULL, 0,
pucSendData, ucSendLength );
}
} }
/** /**
* This is modbus master receive data error process callback function. * This is modbus master receive data error process callback function.
* @note There functions will block modbus master poll while execute OS waiting. * @note There functions will block modbus master poll while execute OS waiting.
* *
* @param xTransId - the identification of the trasaction
* @param ucDestAddress destination salve address * @param ucDestAddress destination salve address
* @param pucPDUData PDU buffer data * @param pucRecvData current receive data pointer
* @param ucPDULength PDU buffer length * @param ucRecvLength current length of receive buffer
* @param pucSendData Send buffer data
* @param ucSendLength Send buffer length
*/ */
void vMBMasterErrorCBReceiveData(UCHAR ucDestAddress, const UCHAR* pucPDUData, USHORT ucPDULength) void vMBMasterErrorCBReceiveData(uint64_t xTransId, UCHAR ucDestAddress,
const UCHAR* pucRecvData, USHORT ucRecvLength,
const UCHAR* pucSendData, USHORT ucSendLength)
{ {
(void)xEventGroupSetBits( xEventGroupMasterHdl, EV_MASTER_ERROR_RECEIVE_DATA ); (void)xEventGroupSetBits( xEventGroupMasterHdl, EV_MASTER_ERROR_RECEIVE_DATA );
ESP_LOGD(MB_PORT_TAG,"%s:Callback receive data timeout failure.", __func__); ESP_LOGD(MB_PORT_TAG,"%s:Callback receive data failure.", __func__);
ESP_LOG_BUFFER_HEX_LEVEL("Err rcv buf", (void *)pucPDUData, (USHORT)ucPDULength, ESP_LOG_DEBUG); if (vMBMasterErrorCBUserHandler) {
vMBMasterErrorCBUserHandler( xTransId, (USHORT)EV_ERROR_RECEIVE_DATA,
ucDestAddress, pucRecvData, ucRecvLength,
pucSendData, ucSendLength );
}
} }
/** /**
@@ -222,27 +239,50 @@ void vMBMasterErrorCBReceiveData(UCHAR ucDestAddress, const UCHAR* pucPDUData, U
* @note There functions will block modbus master poll while execute OS waiting. * @note There functions will block modbus master poll while execute OS waiting.
* So,for real-time of system.Do not execute too much waiting process. * So,for real-time of system.Do not execute too much waiting process.
* *
* @param xTransId - the identification of the trasaction
* @param ucDestAddress destination salve address * @param ucDestAddress destination salve address
* @param pucPDUData PDU buffer data * @param pucRecvData current receive data pointer
* @param ucPDULength PDU buffer length * @param ucRecvLength current length of receive buffer
* @param pucSendData Send buffer data
* @param ucSendLength Send buffer length
* *
*/ */
void vMBMasterErrorCBExecuteFunction(UCHAR ucDestAddress, const UCHAR* pucPDUData, USHORT ucPDULength) void vMBMasterErrorCBExecuteFunction(uint64_t xTransId, UCHAR ucDestAddress,
const UCHAR* pucRecvData, USHORT ucRecvLength,
const UCHAR* pucSendData, USHORT ucSendLength)
{ {
xEventGroupSetBits( xEventGroupMasterHdl, EV_MASTER_ERROR_EXECUTE_FUNCTION ); xEventGroupSetBits( xEventGroupMasterHdl, EV_MASTER_ERROR_EXECUTE_FUNCTION );
ESP_LOGD(MB_PORT_TAG,"%s:Callback execute data handler failure.", __func__); ESP_LOGD(MB_PORT_TAG,"%s:Callback execute data handler failure.", __func__);
ESP_LOG_BUFFER_HEX_LEVEL("Exec func buf", (void*)pucPDUData, (USHORT)ucPDULength, ESP_LOG_DEBUG); if (vMBMasterErrorCBUserHandler) {
vMBMasterErrorCBUserHandler( xTransId, (USHORT)EV_ERROR_EXECUTE_FUNCTION,
ucDestAddress, pucRecvData, ucRecvLength,
pucSendData, ucSendLength );
}
} }
/** /**
* This is modbus master request process success callback function. * This is modbus master request process success callback function.
* @note There functions will block modbus master poll while execute OS waiting. * @note There functions will block modbus master poll while execute OS waiting.
* So,for real-time of system. Do not execute too much waiting process. * So,for real-time of system. Do not execute too much waiting process.
*
* @param xTransId - the identification of the trasaction
* @param ucDestAddress destination salve address
* @param pucRecvData current receive data pointer
* @param ucRecvLength current length of receive buffer
* @param pucSendData Send buffer data
* @param ucSendLength Send buffer length
*/ */
void vMBMasterCBRequestSuccess( void ) void vMBMasterCBRequestSuccess(uint64_t xTransId, UCHAR ucDestAddress,
const UCHAR* pucRecvData, USHORT ucRecvLength,
const UCHAR* pucSendData, USHORT ucSendLength)
{ {
(void)xEventGroupSetBits( xEventGroupMasterHdl, EV_MASTER_PROCESS_SUCCESS ); (void)xEventGroupSetBits( xEventGroupMasterHdl, EV_MASTER_PROCESS_SUCCESS );
ESP_LOGD(MB_PORT_TAG,"%s: Callback request success.", __func__); ESP_LOGD(MB_PORT_TAG,"%s: Callback request success.", __func__);
if (vMBMasterErrorCBUserHandler) {
vMBMasterErrorCBUserHandler( xTransId, (USHORT)EV_ERROR_OK,
ucDestAddress, pucRecvData, ucRecvLength,
pucSendData, ucSendLength );
}
} }
/** /**

View File

@@ -9,3 +9,5 @@ files:
- "docs" - "docs"
- "test/**/*" - "test/**/*"
- "test" - "test"
- "arch"
- "arch/**/*"

View File

@@ -2,3 +2,4 @@ set(PROJECT_NAME "modbus_master")
idf_component_register(SRCS "master.c" idf_component_register(SRCS "master.c"
INCLUDE_DIRS ".") INCLUDE_DIRS ".")

View File

@@ -483,6 +483,29 @@ static esp_err_t master_init(void)
return err; return err;
} }
#ifndef UCHAR
#define UCHAR uint8_t
#define USHORT uint16_t
#define MB_PDU_DATA_OFF 1
#endif
#define EV_ERROR_EXECUTE_FUNCTION 3
void vMBMasterErrorCBUserHandler( uint64_t xTransId, USHORT usError, UCHAR ucDestAddress, const UCHAR* pucRecvData, USHORT ucRecvLength,
const UCHAR* pucSendData, USHORT ucSendLength )
{
ESP_LOGW("USER_ERR_CB", "The transaction error type: %u", usError);
if ((usError == EV_ERROR_EXECUTE_FUNCTION) && pucRecvData && ucRecvLength) {
ESP_LOGW("USER_ERR_CB", "The command is unsupported or an exception on slave happened: %x", (int)pucRecvData[1]);
}
if (pucRecvData && ucRecvLength) {
ESP_LOG_BUFFER_HEX_LEVEL("Received buffer", (void *)pucRecvData, (USHORT)ucRecvLength, ESP_LOG_WARN);
}
if (pucSendData && ucSendLength) {
ESP_LOG_BUFFER_HEX_LEVEL("Sent buffer", (void *)pucSendData, (USHORT)ucSendLength, ESP_LOG_WARN);
}
}
void app_main(void) void app_main(void)
{ {
// Initialization of device peripheral and objects // Initialization of device peripheral and objects