tests: add transaction time handling

This commit is contained in:
aleks
2024-06-06 12:06:02 +02:00
parent cfa8767c18
commit f81ef8229e
3 changed files with 34 additions and 5 deletions

View File

@ -272,7 +272,7 @@ eMBMasterSerialInit( eMBMode eMode, UCHAR ucPort, ULONG ulBaudRate, eMBParity eP
atomic_init(&usMasterSendPDULength, 0);
atomic_init(&eMBMasterCurErrorType, EV_ERROR_INIT);
atomic_init(&xMBRunInMasterMode, FALSE);
atomic_init(&ucMBMasterDestAddress, MB_TCP_PSEUDO_ADDRESS);
atomic_init(&ucMBMasterDestAddress, 0);
}
/* initialize the OS resource for modbus master. */
vMBMasterOsResInit();
@ -514,7 +514,7 @@ eMBMasterPoll( void )
ESP_LOGD( MB_PORT_TAG, "Transaction (%" PRIu64 "), processing time(us) = %" PRId64, xCurTransactionId, xProcTime );
MB_ATOMIC_SECTION {
xTransactionInfo.xTransId = xCurTransactionId;
xTransactionInfo.ucDestAddr = atomic_load(&ucMBMasterDestAddress);
xTransactionInfo.ucDestAddr = ucMBMasterGetDestAddress();
xTransactionInfo.ucFuncCode = ucFunctionCode;
xTransactionInfo.eException = eException;
xTransactionInfo.ucFrameError = errorType;

View File

@ -6,6 +6,7 @@
#include "string.h"
#include "esp_log.h"
#include "esp_timer.h"
#include "modbus_params.h" // for modbus parameters structures
#include "mbcontroller.h"
#include "sdkconfig.h"
@ -378,6 +379,7 @@ static void master_operation_func(void *arg)
}
#endif
} else if (cid <= CID_HOLD_DATA_2) {
uint64_t start_timestamp = esp_timer_get_time(); // Get current timestamp in microseconds
if (TEST_VERIFY_VALUES(param_descriptor, (float *)temp_data_ptr) == ESP_OK) {
ESP_LOGI(TAG, "Characteristic #%d %s (%s) value = %f (0x%" PRIx32 ") read successful.",
(int)param_descriptor->cid,
@ -394,10 +396,19 @@ static void master_operation_func(void *arg)
}
mb_trans_info_t tinfo = {0};
if (mbc_master_get_transaction_info(&tinfo) == ESP_OK) {
ESP_LOGI("TRANS_INFO", "Id: %" PRIu64 ", Addr: %x, FC: %x, Exp: %u, Err: %x",
bool trans_is_expired = (tinfo.trans_id >= (start_timestamp + (CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND * 1000)));
ESP_LOGW("TRANS_INFO", "Id: %" PRIu64 ", Addr: %x, FC: 0x%x, Exception: %u, Err: %u %s",
(uint64_t)tinfo.trans_id, (int)tinfo.dest_addr,
(unsigned)tinfo.func_code, (unsigned)tinfo.exception,
(int)tinfo.err_type);
(int)tinfo.func_code, (unsigned)tinfo.exception,
(int)tinfo.err_type,
trans_is_expired ? "(EXPIRED)" : "");
// Check if the response time is expired sinse start of transaction,
// or the other IO is performed from different thread.
if (trans_is_expired) {
ESP_LOGE("TRANS_INFO", "Transaction Id: %" PRIu64 ", is expired.", tinfo.trans_id);
alarm_state = true;
break;
}
}
} else if ((cid >= CID_RELAY_P1) && (cid <= CID_DISCR_P1)) {
if (TEST_VERIFY_VALUES(param_descriptor, (uint8_t *)temp_data_ptr) == ESP_OK) {

View File

@ -9,6 +9,7 @@
#include <string.h>
#include <sys/queue.h>
#include "esp_log.h"
#include "esp_timer.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
@ -729,6 +730,7 @@ static void master_operation_func(void *arg)
}
#endif
} else if (cid <= CID_HOLD_DATA_2) {
uint64_t start_timestamp = esp_timer_get_time(); // Get current timestamp in microseconds
if (TEST_VERIFY_VALUES(param_descriptor, (float *)temp_data_ptr) == ESP_OK) {
ESP_LOGI(TAG, "Characteristic #%d %s (%s) value = %f (0x%" PRIx32 ") read successful.",
(int)param_descriptor->cid,
@ -743,6 +745,22 @@ static void master_operation_func(void *arg)
alarm_state = true;
break;
}
mb_trans_info_t tinfo = {0}; // The transaction information structure
if (mbc_master_get_transaction_info(&tinfo) == ESP_OK) {
bool trans_is_expired = (tinfo.trans_id >= (start_timestamp + (CONFIG_FMB_MASTER_TIMEOUT_MS_RESPOND * 1000)));
ESP_LOGW("TRANS_INFO", "Id: %" PRIu64 ", Addr: %x, FC: 0x%x, Exception: %u, Err: %u %s",
(uint64_t)tinfo.trans_id, (int)tinfo.dest_addr,
(int)tinfo.func_code, (unsigned)tinfo.exception,
(int)tinfo.err_type,
trans_is_expired ? "(EXPIRED)" : "");
// Check if the response time is expired sinse start of transaction,
// or the other IO is performed from different thread.
if (trans_is_expired) {
ESP_LOGE("TRANS_INFO", "Transaction Id: %" PRIu64 ", is expired.", tinfo.trans_id);
alarm_state = true;
break;
}
}
} else if ((cid >= CID_RELAY_P1) && (cid <= CID_DISCR_P1)) {
if (TEST_VERIFY_VALUES(param_descriptor, (uint8_t *)temp_data_ptr) == ESP_OK) {
uint8_t state = *(uint8_t *)temp_data_ptr;