From fa2623130e404435cd10b11a3bdbdcbf2733fad4 Mon Sep 17 00:00:00 2001 From: Gatsby Van Date: Wed, 14 May 2025 22:44:52 +0800 Subject: [PATCH] fix: correct auto timesync and node ttlCnt mechanism for BERTEST mode --- .../src/networking/link_layer/service.c | 56 ++++++++++++++----- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/df_datalink_sp/src/networking/link_layer/service.c b/df_datalink_sp/src/networking/link_layer/service.c index 62a126e..b36049c 100644 --- a/df_datalink_sp/src/networking/link_layer/service.c +++ b/df_datalink_sp/src/networking/link_layer/service.c @@ -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*/ \ No newline at end of file +/** @} LinkLayer*/