fix: correct auto timesync and node ttlCnt mechanism for BERTEST mode

This commit is contained in:
Gatsby Van
2025-05-14 22:44:52 +08:00
parent 6462daabdf
commit fa2623130e
@@ -261,26 +261,54 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg)
}
return Status;
#else
NODE_ENTRY *node;
uint8_t nodeId = (L2_GetNodeType(instPtr) == L2_NODE_HEAD) ? 0x02 : 0x01;
node = L2_GetNodeById(instPtr->nodeList, nodeId);
if (node == NULL)
{
node = L2_AppendNode(instPtr->nodeList, nodeId, L2_NODE_MEMBER);
if (node == NULL)
{
DBG_ERROR("Failed to append new node [id: %" PRIu8 "]", nodeId);
return ENOMEM;
}
}
// Reset node ttl
node->ttlCnt = 0;
// Calculate time deviation
Status = L2_GetTimeDeviation(instPtr, L2_GetLastFrameNum(instPtr), L2_GetLastSlotNum(instPtr), true, &(instPtr->log.timeDev));
if (Status != SUCCESS)
{
DBG_ERROR("Failed to compute time deviation.\n")
return Status;
}
// Implement a auto time sync.
if (L2_GetNodeType(instPtr) != L2_NODE_HEAD)
{
// Time sync.
L2_TimeAdjust(instPtr, &(instPtr->log.timeDev));
}
uint32_t frameNum = L2_GetCurrentFrameNum(instPtr);
uint32_t slotNum = L2_GetCurrentSlotNum(instPtr);
// //NOTE: Service frame length is 20ms with 5ms idle
// if(slotNum < 5)
// {
// slotNum = L2_SLOTS_PER_FRAME - 5;
// frameNum = frameNum - 1;
// }
// else
// {
// slotNum = slotNum / 5 * 5 - 5;
// }
// Status = L2_GetTimeDeviation(instPtr, frameNum, slotNum, true, &(instPtr->log.timeDev));
// if (Status != SUCCESS)
// {
// DBG_ERROR("Failed to compute time deviation.\n")
// return Status;
// }
// // Implement a auto time sync.
// if (L2_GetNodeType(instPtr) != L2_NODE_HEAD)
// {
// // Time sync.
// L2_TimeAdjust(instPtr, &(instPtr->log.timeDev));
// }
return SUCCESS;
#endif
}
bool L2_Service_PktCheck(L2_INST *instPtr, uint8_t *msg)
{
size_t packLen = Phy_GetFrameLen(L2_L2frame2L1frame(L2_SVC_FRAME));
size_t packLen = Phy_GetFrameLen(L2_L2frame2L1frame(L2_SVC_FRAME)) & 0xFFFFFFFE;
uint32_t errorBits = 0;
for (int i = 0; i < packLen; i++)
{
@@ -433,4 +461,4 @@ int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntr
}
/** @} LinkLayer_Service*/
/** @} LinkLayer*/
/** @} LinkLayer*/