forked from gatsby/df_datalink
feat: 修改聆听逻辑, 增加超时时间判定与下发
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define NET_START_TIME_INFTY UINT32_MAX
|
||||
#define LINK_BROCK_THRESHOLD L2_SLOTS_PER_FRAME // 0.5 seconds
|
||||
#define LISTEN_TIMEOUT_INT L2_SLOTS_PER_FRAME // number of 2 ms slots
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
/***************** Macros (Inline Functions) Definitions *********************/
|
||||
@@ -1313,17 +1312,6 @@ int32_t L2_SetupNextSlot(L2_INST *instPtr, L2_TOR_TYPE txrxMode, L2_FRAME_TYPE f
|
||||
L2_RcdShift(&(instPtr->frame), frameType);
|
||||
L2_RcdShift(&(instPtr->tor), txrxMode);
|
||||
|
||||
if (L2_isCxn2Net(instPtr) == false)
|
||||
{
|
||||
// NOTE: LISTENING mode is assumed.
|
||||
TIME_WORD listenTime = {LISTEN_TIMEOUT_INT, 0};
|
||||
Status = Phy_SetTimeWord(phyRef, &listenTime, PHY_TIME_WORD_LISTEN_TIMEOUT);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Physical set listening timeout failed, with error code: %" PRId32 "\n", Status);
|
||||
}
|
||||
}
|
||||
|
||||
TIME_WORD pollTime = {0, 0};
|
||||
pollTime.int_part = TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr) + 1;
|
||||
Status = Phy_SetTimeWord(phyRef, &pollTime, PHY_TIME_WORD_POLL);
|
||||
|
||||
@@ -213,8 +213,8 @@ typedef struct
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
bool isAdvRecvd; ///< indicates if advertisement frame done(antenna locked).
|
||||
uint8_t advCnt; ///< adv receive try count
|
||||
TIME_WORD timeoutWord; ///< listening timeout word
|
||||
uint8_t timeoutCnt; ///< listening timeout count
|
||||
} L2_SCAN_FSM;
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
#include "../phy_layer/phy_layer.h"
|
||||
|
||||
/************************** Constant Definitions *****************************/
|
||||
#define ACK_FRAME_SLOTS 4
|
||||
#define LISTEN_TIMEOUT_INT 2*L2_SLOTS_PER_FRAME // number of 2 ms slots
|
||||
|
||||
/***************** Macros (In-line Functions) Definitions *********************/
|
||||
|
||||
/**************************** Type Definitions *******************************/
|
||||
@@ -39,52 +40,8 @@
|
||||
/************************** Variable Definitions *****************************/
|
||||
|
||||
/************************** Function Prototypes ******************************/
|
||||
static void AdvRecvStateUpdate(L2_SCAN_FSM *scanFsmPtr, bool state);
|
||||
static int32_t Scan_AdvHandler(L2_INST *instPtr);
|
||||
static int32_t ScanMsg_Packing(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t dstId);
|
||||
|
||||
/**
|
||||
* @brief Update Base-info Advertisement state.
|
||||
*/
|
||||
static void AdvRecvStateUpdate(L2_SCAN_FSM *scanFsmPtr, bool state)
|
||||
{
|
||||
ASSERT(scanFsmPtr != NULL);
|
||||
DBG_INFO("Update AdvRecvState from [%" PRId8 "] to [%" PRId8 "].\n",
|
||||
scanFsmPtr->isAdvRecvd, state);
|
||||
scanFsmPtr->isAdvRecvd = state;
|
||||
return;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Member node scan net BmAdvt stage handler.
|
||||
*
|
||||
* @param instPtr Pointer to linklayer layer instance.
|
||||
*
|
||||
* @return used slot (2 ms slot).
|
||||
*
|
||||
******************************************************************************/
|
||||
static int32_t Scan_AdvHandler(L2_INST *instPtr)
|
||||
{
|
||||
ASSERT(instPtr != NULL);
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
||||
DBG_INFO("** Net-Setup - Advertisement Procedure (Attempts: %" PRIu8 ") **\n", scanFsmPtr->advCnt);
|
||||
|
||||
// Network status is updated in L2_Scan_PktHandler() if valid ADV frame is received.
|
||||
if (scanFsmPtr->isAdvRecvd == true)
|
||||
{
|
||||
DBG_ERROR("Only unconnected node can execute Scan_AdvHandler().\n");
|
||||
return EUNEXP;
|
||||
}
|
||||
// no valid bm frame was received.
|
||||
else
|
||||
{
|
||||
(void)L2_SetupNextSlot(instPtr, L2_TOR_RX, L2_FRAME_ADV);
|
||||
scanFsmPtr->advCnt++;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Packing Scan message to a bit array.
|
||||
@@ -292,8 +249,6 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
||||
memcpy(instPtr->log.rxLog.data, msg, sizeof(L2_MSG_ADV));
|
||||
instPtr->log.rxLog.dataId = dataId;
|
||||
|
||||
// trigger flag
|
||||
AdvRecvStateUpdate(scanFsmPtr, true);
|
||||
Status = SUCCESS;
|
||||
break;
|
||||
}
|
||||
@@ -408,8 +363,9 @@ int32_t L2_Scan_Init(L2_SCAN_FSM **scanFSMPtr)
|
||||
void L2_Scan_Reset(L2_SCAN_FSM *scanFSMPtr)
|
||||
{
|
||||
ASSERT(scanFSMPtr != NULL);
|
||||
scanFSMPtr->isAdvRecvd = false;
|
||||
scanFSMPtr->advCnt = 0;
|
||||
scanFSMPtr->timeoutWord.int_part = 0;
|
||||
scanFSMPtr->timeoutWord.frac_part = 0;
|
||||
scanFSMPtr->timeoutCnt = 0;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -428,26 +384,53 @@ void L2_Scan_Destroy(L2_SCAN_FSM *scanFSMPtr)
|
||||
|
||||
/*****************************************************************************/
|
||||
/**
|
||||
* @brief Execute a member node scan net procedure.
|
||||
* @brief Member node listening procedure.
|
||||
*
|
||||
* @param instPtr a pointer to linklayer layer instance
|
||||
* @param instPtr Pointer to linklayer layer instance.
|
||||
*
|
||||
* @return used slot (2 ms slot).
|
||||
*
|
||||
******************************************************************************/
|
||||
int32_t L2_Scan_Proc(L2_INST *instPtr)
|
||||
{
|
||||
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
||||
{
|
||||
DBG_ERROR("Only member node needs to execute L2_Scan_Proc. \n");
|
||||
return FAILURE;
|
||||
}
|
||||
ASSERT(instPtr != NULL);
|
||||
PHY_INST *phyRef = instPtr->config.phyInstPtr;
|
||||
L2_SCAN_FSM *scanFsmPtr = instPtr->scanFSM;
|
||||
int32_t Status;
|
||||
DBG_INFO("-------- ScanNet Process --------\n");
|
||||
DBG_INFO("** Net-Setup - Listening Procedure (Attempts: %" PRIu8 ") **\n", scanFsmPtr->advCnt);
|
||||
|
||||
Status = Scan_AdvHandler(instPtr);
|
||||
uint32_t currTimeInt = TimeCtrl_GetIntCnt(instPtr->config.tmcInstPtr);
|
||||
|
||||
if (scanFsmPtr->timeoutWord.int_part < currTimeInt)
|
||||
{
|
||||
// listening timeout: current system time + listening duration
|
||||
TIME_WORD listenTime = {currTimeInt + LISTEN_TIMEOUT_INT, 0};
|
||||
Status = Phy_SetTimeWord(phyRef, &listenTime, PHY_TIME_WORD_LISTEN_TIMEOUT);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Physical set listening timeout failed, with error code: %" PRId32 "\n", Status);
|
||||
}
|
||||
scanFsmPtr->timeoutWord = listenTime;
|
||||
|
||||
// physical start time: set to next slot
|
||||
TIME_WORD pollTime = {0, 0};
|
||||
pollTime.int_part = currTimeInt + 1;
|
||||
Status = Phy_SetTimeWord(phyRef, &pollTime, PHY_TIME_WORD_POLL);
|
||||
if (Status != SUCCESS)
|
||||
{
|
||||
DBG_ERROR("Physical set poll time failed, with error code: %" PRId32 "\n", Status);
|
||||
}
|
||||
|
||||
Status = Phy_SetupNextSlot(phyRef, PHY_TOR_RX, L2_L2frame2L1frame(L2_FRAME_ADV, L2_SVC_NONE),
|
||||
instPtr->sendPktData);
|
||||
|
||||
// record
|
||||
scanFsmPtr->timeoutCnt++;
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
@@ -649,7 +649,7 @@ static int32_t Service_PktHandler2M(L2_INST *instPtr, uint8_t *msg)
|
||||
/**
|
||||
* @brief Initialize service net FSM
|
||||
*
|
||||
* @param serviceFSM A pointer to service FSM instance.
|
||||
* @param svcFSMPtr A pointer to service FSM instance.
|
||||
*
|
||||
* @return SUCCESS Initialize successfully.
|
||||
* Other Initialize failed.
|
||||
@@ -671,7 +671,7 @@ int32_t L2_Service_Init(L2_SVC_FSM **svcFSMPtr)
|
||||
/**
|
||||
* @brief Reset ServiceNet FSM
|
||||
*
|
||||
* @param scanFsmPtr a pointer to service net finite state machine
|
||||
* @param svcFSMPtr a pointer to service net finite state machine
|
||||
*
|
||||
* @return NONE
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user