From 18d169eaa572f4acac9092989b03a80a61b0a694 Mon Sep 17 00:00:00 2001 From: VineetaGupta Date: Mon, 17 Mar 2025 16:44:58 +0100 Subject: [PATCH] Node handling corrected --- .../nehemis/enduranceTestBench.c | 117 ++++++++++-------- 1 file changed, 67 insertions(+), 50 deletions(-) diff --git a/EnduranceTestBench/nehemis/enduranceTestBench.c b/EnduranceTestBench/nehemis/enduranceTestBench.c index 99c78a9..e19689b 100644 --- a/EnduranceTestBench/nehemis/enduranceTestBench.c +++ b/EnduranceTestBench/nehemis/enduranceTestBench.c @@ -56,6 +56,13 @@ static TestBenchData_en testBenchData_en; static uint8 currentNode_gu8 = 0u; static SdlTestBenchState_en testBenchState_en = TEST_BENCH_IDLE; static uint32 readPosition_gu32; +static uint8 batchCompleted_u8 = 1u; /* Indicates if we need to populate a new batch */ +static uint64 readExecutedTime_u64 = 0uLL; +static uint64 writeTime_u64 = 0uLL; +static uint8 position_u8; + +static uint16 writeCounter; +static uint16 readCounter; /****************************************************************************** * Public Function Definitions ******************************************************************************/ @@ -63,8 +70,8 @@ static uint32 readPosition_gu32; void EnduranceTestBenchRun(void) { static uint64 startTime_u64 = 0uLL; + static uint64 timeDelay_u64 = 0uLL; static uint8 alternate_u8 = 0u; - static uint8 batchCompleted_u8 = 1u; /* Indicates if we need to populate a new batch */ static uint8 retries_u8 = 0u; uint64 currentTime_u64; @@ -155,66 +162,74 @@ void EnduranceTestBenchRun(void) case TEST_BENCH_WRITE_REQUEST: + { + if (batchCompleted_u8 == 0) + { + if (currentNode_gu8 < ENDURANCE_TEST_BENCH_LSS_NODE_COUNT) + { + testBenchData_en.targetPositions_gau8[currentNode_gu8] = (uint8)(rand() % 255); + + RET_T retVal_en = coSdoWrite((19), ENDURANCE_TEST_BENCH_POSITION_SETPOINT_INDEX, ENDURANCE_TEST_BENCH_POSITION_SETPOINT_SUB_INDEX, + &testBenchData_en.targetPositions_gau8[currentNode_gu8], sizeof(uint8), CO_FALSE, ENDURANCE_TEST_BENCH_TIMEOUT); + + if (retVal_en == RET_OK) + { + retries_u8 = 0u; + currentNode_gu8++; + HalSystemGetRunTimeMs(&writeTime_u64); + } + else + { + retries_u8++; + if (retries_u8 >= ENDURANCE_TEST_BENCH_MAX_RETRY_CNT) + { + currentNode_gu8++; /* Skip this node */ + } + } + } + } + } + + break; + + case TEST_BENCH_READ_FEEDBACK: { if (currentNode_gu8 < ENDURANCE_TEST_BENCH_LSS_NODE_COUNT) { - testBenchData_en.targetPositions_gau8[currentNode_gu8] = (uint8)(rand() % 256); - - RET_T retVal_en = coSdoWrite((1), ENDURANCE_TEST_BENCH_POSITION_SETPOINT_INDEX, ENDURANCE_TEST_BENCH_POSITION_SETPOINT_SUB_INDEX, - &testBenchData_en.targetPositions_gau8[currentNode_gu8], sizeof(uint8), - CO_FALSE, ENDURANCE_TEST_BENCH_TIMEOUT); + RET_T retVal_en = coSdoRead((19),ENDURANCE_TEST_BENCH_POSITION_FEEDBACK_INDEX, ENDURANCE_TEST_BENCH_POSITION_FEEDBACK_SUB_INDEX, + (uint8*)&readPosition_gu32, sizeof(uint32), CO_FALSE, ENDURANCE_TEST_BENCH_TIMEOUT); if (retVal_en == RET_OK) { retries_u8 = 0u; currentNode_gu8++; - HalSystemGetRunTimeMs(&startTime_u64); + } + + else if (retVal_en == RET_SERVICE_BUSY && retries_u8 < ENDURANCE_TEST_BENCH_MAX_RETRY_CNT) + { + retries_u8++; } else { - retries_u8++; - if (retries_u8 >= ENDURANCE_TEST_BENCH_MAX_RETRY_CNT) - { - currentNode_gu8++; /* Skip this node */ - } + currentNode_gu8++; + retries_u8 = 0u; } } } break; - case TEST_BENCH_READ_FEEDBACK: - { - RET_T retVal_en = coSdoRead((1),ENDURANCE_TEST_BENCH_POSITION_FEEDBACK_INDEX, ENDURANCE_TEST_BENCH_POSITION_FEEDBACK_SUB_INDEX, - (uint8*)&readPosition_gu32, sizeof(uint32), CO_FALSE, ENDURANCE_TEST_BENCH_TIMEOUT); - - if (retVal_en == RET_OK) - { - /* Wait for indication */ - } - - else if (retVal_en == RET_SERVICE_BUSY && retries_u8 < ENDURANCE_TEST_BENCH_MAX_RETRY_CNT) - { - retries_u8++; - } - else - { - currentNode_gu8++; - retries_u8 = 0; - } - } - break; - case TEST_BENCH_VERIFY_RESULTS: { + timeDelay_u64 = readExecutedTime_u64 - writeTime_u64; for (uint8 index_u8 = 0u; index_u8 < ENDURANCE_TEST_BENCH_LSS_NODE_COUNT; index_u8++) { - if (testBenchData_en.targetPositions_gau8[index_u8] != testBenchData_en.readPosition_gau8[index_u8]) + if (testBenchData_en.targetPositions_gau8[index_u8] - testBenchData_en.readPosition_gau8[index_u8] <= 2u) { - testBenchData_en.status[index_u8] = 1u; + testBenchData_en.status[index_u8] = 0u; } else { - testBenchData_en.status[index_u8] = 0u; + testBenchData_en.status[index_u8] = 1u; } } testBenchState_en = TEST_BENCH_DELAY_BEFORE_NEXT; @@ -237,14 +252,16 @@ void EnduranceTestBenchRun(void) } } - /****************************************************************************** * Callback Function ******************************************************************************/ void EnduranceTestBenchWriteInd(uint8 sdoNr_u8, uint16 index_u16, uint8 subIndex_u8, uint32 errorVal_u32) { + writeCounter++; + HalSystemGetRunTimeMs(&writeTime_u64); if (currentNode_gu8 < ENDURANCE_TEST_BENCH_LSS_NODE_COUNT) { + HAL_Delay(100); testBenchState_en = TEST_BENCH_WRITE_REQUEST; } else @@ -257,17 +274,17 @@ void EnduranceTestBenchWriteInd(uint8 sdoNr_u8, uint16 index_u16, uint8 subIndex void EnduranceTestBenchReadInd(uint8 sdoNr_u8, uint16 index_u16, uint8 subIndex_u8, uint32 size, uint32 errorVal_u32) { - if (sdoNr_u8 <= ENDURANCE_TEST_BENCH_LSS_NODE_COUNT) - { - testBenchData_en.readPosition_gau8[currentNode_gu8] = readPosition_gu32; + readCounter++; + HalSystemGetRunTimeMs(&readExecutedTime_u64); + testBenchData_en.readPosition_gau8[currentNode_gu8 - 1u] = (uint8)readPosition_gu32; - if (currentNode_gu8 + 1 == ENDURANCE_TEST_BENCH_LSS_NODE_COUNT) - { - testBenchState_en = TEST_BENCH_VERIFY_RESULTS; - } - else - { - testBenchState_en = TEST_BENCH_READ_FEEDBACK; - } - } + if (currentNode_gu8 < ENDURANCE_TEST_BENCH_LSS_NODE_COUNT) + { + testBenchState_en = TEST_BENCH_READ_FEEDBACK; + } + else + { + currentNode_gu8 = 0u; + testBenchState_en = TEST_BENCH_VERIFY_RESULTS; + } }