|
|
|
@@ -91,68 +91,115 @@ static int32_t Service_Packing(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t dst
|
|
|
|
|
#ifndef DATALINK_ENABLE_BERTEST
|
|
|
|
|
ASSERT(instPtr != NULL);
|
|
|
|
|
int32_t Status;
|
|
|
|
|
uint32_t dataChunk;
|
|
|
|
|
uint8_t *buff = instPtr->sendPktData;
|
|
|
|
|
|
|
|
|
|
// Common section of link layer package
|
|
|
|
|
dataChunk = L2_GetNextFrameNum(instPtr);
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_FRAME_NUM, L2_MSG_FRAME_NUM_LEN, &dataChunk);
|
|
|
|
|
dataChunk = L2_GetNextSlotNum(instPtr);
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SLOT_NUM, L2_MSG_SLOT_NUM_LEN, &dataChunk);
|
|
|
|
|
dataChunk = L2_GetNodeId(instPtr);
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SRC_ID, L2_MSG_SRC_ID_LEN, &dataChunk);
|
|
|
|
|
dataChunk = dstId;
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_DST_ID, L2_MSG_DST_ID_LEN, &dataChunk);
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case L2_SVC_FRAME:
|
|
|
|
|
{
|
|
|
|
|
dataChunk = L2_SVC_FRAME;
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_TYPE, L2_MSG_TYPE_LEN, &dataChunk);
|
|
|
|
|
case L2_FRAME_DIS:
|
|
|
|
|
case L2_FRAME_MNG:
|
|
|
|
|
case L2_FRAME_RTT:
|
|
|
|
|
L2_MSG_SVC_128K *message = (L2_MSG_SVC_128K *)(instPtr->sendPktData);
|
|
|
|
|
|
|
|
|
|
// Common section of link layer package
|
|
|
|
|
message->common->frameNum = L2_GetNextFrameNum(instPtr);
|
|
|
|
|
message->common->slotNum = L2_GetNextSlotNum(instPtr);
|
|
|
|
|
message->common->src = L2_GetNodeId(instPtr);
|
|
|
|
|
message->common->dst = dstId;
|
|
|
|
|
message->common.msgType = L2_FRAME_ADV;
|
|
|
|
|
|
|
|
|
|
SysMonitor_GetSysinfo(&(instPtr->sysInfo));
|
|
|
|
|
// insert position and speed info
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SVC_SRC_POSX, L2_MSG_SVC_SRC_POSX_LEN, &(instPtr->sysInfo.posX));
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SVC_SRC_POSY, L2_MSG_SVC_SRC_POSY_LEN, &(instPtr->sysInfo.posY));
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SVC_SRC_POSZ, L2_MSG_SVC_SRC_POSZ_LEN, &(instPtr->sysInfo.posZ));
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SVC_SRC_SPEEDX, L2_MSG_SVC_SRC_SPEEDX_LEN, &(instPtr->sysInfo.vX));
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SVC_SRC_SPEEDY, L2_MSG_SVC_SRC_SPEEDY_LEN, &(instPtr->sysInfo.vY));
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SVC_SRC_SPEEDZ, L2_MSG_SVC_SRC_SPEEDZ_LEN, &(instPtr->sysInfo.vZ));
|
|
|
|
|
SysMonitor_GetSysinfo(&(instPtr->sysInfo));
|
|
|
|
|
message->srcPosX = instPtr->sysInfo.posX;
|
|
|
|
|
message->srcPosY = instPtr->sysInfo.posY;
|
|
|
|
|
message->srcPosZ = instPtr->sysInfo.posZ;
|
|
|
|
|
message->srcSpeedX = instPtr->sysInfo.vX;
|
|
|
|
|
message->srcSpeedY = instPtr->sysInfo.vY;
|
|
|
|
|
message->srcSpeedZ = instPtr->sysInfo.vZ;
|
|
|
|
|
|
|
|
|
|
uint32_t dataId;
|
|
|
|
|
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
|
|
|
|
// Packing extra payload
|
|
|
|
|
SysMonitor_GetSendPayload(message->svcData, message->svcDataId, L2_PAYLOAD_LEN_SVC_128K);
|
|
|
|
|
if (message->svcDataId == DATA_ID_NONE)
|
|
|
|
|
{
|
|
|
|
|
SysMonitor_GetSendPayload(buff + L2_MSG_SVC_PAYLOAD, &dataId, PAYLOAD_LEN_FLJ_TX);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SysMonitor_GetSendPayload(buff + L2_MSG_SVC_PAYLOAD, &dataId, PAYLOAD_LEN_LJ_TX);
|
|
|
|
|
memset(message->svcData, 0xAA, L2_PAYLOAD_LEN_SVC_128K);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SVC_PAYLOAD_ID, L2_MSG_SVC_PAYLOAD_ID_LEN, &dataId);
|
|
|
|
|
if (dataId == DATA_ID_NONE)
|
|
|
|
|
{
|
|
|
|
|
L2_FrameInsertChunk(buff, L2_MSG_SVC_PAYLOAD, L2_MSG_SVC_PAYLOAD_LEN, testData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Status = L2_CrcAppend(buff, L2_SVC_PACK_LEN - L2_MSG_SVC_CRC_LEN, L2_MSG_SVC_CRC, L2_CRC16_1021);
|
|
|
|
|
// Append CRC
|
|
|
|
|
uint32_t crcVal;
|
|
|
|
|
Status = L2_CrcGen(message, sizeof(L2_MSG_SVC_128K) - L2_MSG_CRC_LEN, L2_CRC8_31, &crcVal);
|
|
|
|
|
if (Status != SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
DBG_ERROR("Fail to append CRC...\n");
|
|
|
|
|
DBG_ERROR("Fail to generate CRC, error code: %" PRId32 ".\n", Status);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
message->crc = crcVal;
|
|
|
|
|
|
|
|
|
|
// Logging...
|
|
|
|
|
memcpy(instPtr->log.txLog.data, message, sizeof(L2_MSG_SVC_128K));
|
|
|
|
|
instPtr->log.txLog.dataId = message->svcDataId;
|
|
|
|
|
|
|
|
|
|
memcpy(instPtr->log.txLog.data, buff, L2_SVC_PACK_LEN);
|
|
|
|
|
instPtr->log.txLog.dataId = dataId;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
case L2_FRAME_SVC:
|
|
|
|
|
// retrieve basic info
|
|
|
|
|
size_t msgLen = L2_GetSvcPacketLen(instPtr->config.serviceRate);
|
|
|
|
|
size_t dataLen = L2_GetSvcPayloadLen(instPtr->config.serviceRate);
|
|
|
|
|
switch (instPtr->config.serviceRate)
|
|
|
|
|
{
|
|
|
|
|
case L2_SVC_128K:
|
|
|
|
|
L2_MSG_SVC_128K *message = (L2_MSG_SVC_128K *)(instPtr->sendPktData);
|
|
|
|
|
break;
|
|
|
|
|
case L2_SVC_512K:
|
|
|
|
|
L2_MSG_SVC_512K *message = (L2_MSG_SVC_512K *)(instPtr->sendPktData);
|
|
|
|
|
break;
|
|
|
|
|
case L2_SVC_2M:
|
|
|
|
|
L2_MSG_SVC_2M *message = (L2_MSG_SVC_2M *)(instPtr->sendPktData);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
DBG_ERROR("Unsupported service rate: %" PRId8 ".\n", instPtr->config.serviceRate);
|
|
|
|
|
return EPARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Common section of link layer package
|
|
|
|
|
message->common->frameNum = L2_GetNextFrameNum(instPtr);
|
|
|
|
|
message->common->slotNum = L2_GetNextSlotNum(instPtr);
|
|
|
|
|
message->common->src = L2_GetNodeId(instPtr);
|
|
|
|
|
message->common->dst = dstId;
|
|
|
|
|
message->common.msgType = L2_FRAME_ADV;
|
|
|
|
|
|
|
|
|
|
// insert position and speed info
|
|
|
|
|
SysMonitor_GetSysinfo(&(instPtr->sysInfo));
|
|
|
|
|
message->srcPosX = instPtr->sysInfo.posX;
|
|
|
|
|
message->srcPosY = instPtr->sysInfo.posY;
|
|
|
|
|
message->srcPosZ = instPtr->sysInfo.posZ;
|
|
|
|
|
message->srcSpeedX = instPtr->sysInfo.vX;
|
|
|
|
|
message->srcSpeedY = instPtr->sysInfo.vY;
|
|
|
|
|
message->srcSpeedZ = instPtr->sysInfo.vZ;
|
|
|
|
|
|
|
|
|
|
// Packing extra payload
|
|
|
|
|
SysMonitor_GetSendPayload(message->svcData, message->svcDataId, dataLen);
|
|
|
|
|
if (message->svcDataId == DATA_ID_NONE)
|
|
|
|
|
{
|
|
|
|
|
memset(message->svcData, 0xAA, dataLen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Append CRC
|
|
|
|
|
uint32_t crcVal;
|
|
|
|
|
Status = L2_CrcGen(message, msgLen - L2_MSG_CRC_LEN, L2_CRC8_31, &crcVal);
|
|
|
|
|
if (Status != SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
DBG_ERROR("Fail to generate CRC, error code: %" PRId32 ".\n", Status);
|
|
|
|
|
return Status;
|
|
|
|
|
}
|
|
|
|
|
message->crc = crcVal;
|
|
|
|
|
|
|
|
|
|
// Logging...
|
|
|
|
|
memcpy(instPtr->log.txLog.data, message, msgLen);
|
|
|
|
|
instPtr->log.txLog.dataId = message->svcDataId;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
DBG_ERROR("Unexpected frame type: %" PRIu8 ".\n", type);
|
|
|
|
|
return EPARAM;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
#else
|
|
|
|
|
DBG_ERROR("Unexpected call of Service_Packing in BER test mode.\n");
|
|
|
|
@@ -178,12 +225,35 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
|
|
|
|
#ifndef DATALINK_ENABLE_BERTEST
|
|
|
|
|
L2_FRAME_TYPE frameType = L2_NONE_FRAME;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_TYPE, L2_MSG_TYPE_LEN, &frameType);
|
|
|
|
|
size_t msgLen, dataLen;
|
|
|
|
|
|
|
|
|
|
// retrieve basic info
|
|
|
|
|
switch (frameType)
|
|
|
|
|
{
|
|
|
|
|
case L2_SVC_FRAME:
|
|
|
|
|
case L2_FRAME_DIS:
|
|
|
|
|
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
|
|
|
|
{
|
|
|
|
|
uint8_t nodeId;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SRC_ID, L2_MSG_SRC_ID_LEN, &nodeId);
|
|
|
|
|
DBG_ERROR("Unexpected call from head node, only member Node can handle L2_FRAME_DIS.\n");
|
|
|
|
|
Status = EUNEXP;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case L2_FRAME_MNG:
|
|
|
|
|
case L2_FRAME_RTT:
|
|
|
|
|
L2_MSG_SVC_128K *message = (L2_MSG_SVC_128K *)msg;
|
|
|
|
|
msgLen = sizeof(L2_MSG_SVC_128K);
|
|
|
|
|
dataLen = L2_PAYLOAD_LEN_SVC_128K;
|
|
|
|
|
break;
|
|
|
|
|
case L2_FRAME_SVC:
|
|
|
|
|
msgLen = L2_GetSvcPacketLen(instPtr->config.serviceRate);
|
|
|
|
|
dataLen = L2_GetSvcPayloadLen(instPtr->config.serviceRate);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
DBG_ERROR("Unsupported frame type: %" PRIu8 ".\n", frameType);
|
|
|
|
|
return EPARAM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update node status.
|
|
|
|
|
uint8_t nodeId = message->common.src;
|
|
|
|
|
NODE_ENTRY *node;
|
|
|
|
|
node = L2_GetNodeById(instPtr->nodeList, nodeId);
|
|
|
|
|
if (node == NULL)
|
|
|
|
@@ -191,35 +261,27 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
|
|
|
|
node = L2_AppendNode(instPtr->nodeList, nodeId, L2_NODE_MEMBER);
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
{
|
|
|
|
|
DBG_ERROR("Failed to append new node [id: %" PRIu8 "]", nodeId);
|
|
|
|
|
DBG_ERROR("Failed to append new node [id: %" PRId8 "]", nodeId);
|
|
|
|
|
Status = ENOMEM;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update node info.
|
|
|
|
|
float nodePos;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SVC_SRC_POSX, L2_MSG_SVC_SRC_POSX_LEN, &nodePos);
|
|
|
|
|
node->nodeInfo.pos.x = (double)nodePos;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SVC_SRC_POSY, L2_MSG_SVC_SRC_POSY_LEN, &nodePos);
|
|
|
|
|
node->nodeInfo.pos.y = (double)nodePos;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SVC_SRC_POSZ, L2_MSG_SVC_SRC_POSZ_LEN, &nodePos);
|
|
|
|
|
node->nodeInfo.pos.z = (double)nodePos;
|
|
|
|
|
float nodeSpeed;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SVC_SRC_SPEEDX, L2_MSG_SVC_SRC_SPEEDX_LEN, &nodeSpeed);
|
|
|
|
|
node->nodeInfo.speed.x = (double)nodePos;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SVC_SRC_SPEEDY, L2_MSG_SVC_SRC_SPEEDY_LEN, &nodeSpeed);
|
|
|
|
|
node->nodeInfo.speed.y = (double)nodePos;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SVC_SRC_SPEEDZ, L2_MSG_SVC_SRC_SPEEDZ_LEN, &nodeSpeed);
|
|
|
|
|
node->nodeInfo.speed.z = (double)nodePos;
|
|
|
|
|
node->nodeInfo.pos.x = message->srcPosX;
|
|
|
|
|
node->nodeInfo.pos.y = message->srcPosY;
|
|
|
|
|
node->nodeInfo.pos.z = message->srcPosZ;
|
|
|
|
|
node->nodeInfo.speed.x = message->srcSpeedX;
|
|
|
|
|
node->nodeInfo.speed.y = message->srcSpeedY;
|
|
|
|
|
node->nodeInfo.speed.z = message->srcSpeedZ;
|
|
|
|
|
node->nodeInfo.antIndex = Phy_ReceiveAntIndex(instPtr->config.phyInstPtr);
|
|
|
|
|
|
|
|
|
|
// Reset node ttl
|
|
|
|
|
node->ttlCnt = 0;
|
|
|
|
|
|
|
|
|
|
// Calculate time deviation
|
|
|
|
|
uint32_t frameNum, slotNum = 0;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_FRAME_NUM, L2_MSG_FRAME_NUM_LEN, &frameNum);
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SLOT_NUM, L2_MSG_SLOT_NUM_LEN, &slotNum);
|
|
|
|
|
uint32_t frameNum = message->common.frameNum;
|
|
|
|
|
uint32_t slotNum = (uint32_t)message->common.slotNum;
|
|
|
|
|
Status = L2_GetTimeDeviation(instPtr, frameNum, slotNum, true, &(instPtr->log.timeDev));
|
|
|
|
|
if (Status != SUCCESS)
|
|
|
|
|
{
|
|
|
|
@@ -227,22 +289,12 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint32_t dataId;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SVC_PAYLOAD_ID, L2_MSG_SVC_PAYLOAD_ID_LEN, &dataId);
|
|
|
|
|
// Get data payload
|
|
|
|
|
SysMonitor_UpdateRecvPayload(message->svcData, message->svcDataId, dataLen);
|
|
|
|
|
|
|
|
|
|
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD)
|
|
|
|
|
{
|
|
|
|
|
SysMonitor_UpdateRecvPayload(msg + L2_MSG_SVC_PAYLOAD, dataId, PAYLOAD_LEN_FLJ_RX);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SysMonitor_UpdateRecvPayload(msg + L2_MSG_SVC_PAYLOAD, dataId, PAYLOAD_LEN_LJ_RX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Logging
|
|
|
|
|
memcpy(instPtr->log.rxLog.data, msg, L2_SVC_PACK_LEN);
|
|
|
|
|
instPtr->log.rxLog.dataId = dataId;
|
|
|
|
|
instPtr->serviceFSM->rxdCnt++;
|
|
|
|
|
// Logging...
|
|
|
|
|
memcpy(instPtr->log.rxLog.data, msg, msgLen);
|
|
|
|
|
instPtr->log.rxLog.dataId = message->svcDataId;
|
|
|
|
|
|
|
|
|
|
#ifdef DATALINK_ENABLE_AUTOTIMESYNC
|
|
|
|
|
// Implement a auto time sync.
|
|
|
|
@@ -252,27 +304,21 @@ int32_t L2_Service_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
|
|
|
|
L2_TimeAdjust(instPtr, &(instPtr->log.timeDev));
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
DBG_ERROR("Unsupported frame type: %" PRIu8 ".\n", frameType);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return Status;
|
|
|
|
|
#else
|
|
|
|
|
uint32_t errorBits = 0;
|
|
|
|
|
for (int i = 0; i < L2_SVC_PACK_LEN; i++)
|
|
|
|
|
uint32_t pktLen = L2_GetSvcPacketLen(instPtr->config.serviceRate);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < pktLen; i++)
|
|
|
|
|
{
|
|
|
|
|
errorBits += count_ones(msg[i] ^ testData[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instPtr->serviceFSM->bitError += errorBits;
|
|
|
|
|
instPtr->serviceFSM->bitTotal += L2_SVC_PACK_LEN * 8;
|
|
|
|
|
instPtr->serviceFSM->bitTotal += pktLen * 8;
|
|
|
|
|
|
|
|
|
|
// Calculate time deviation
|
|
|
|
|
uint32_t frameNum, slotNum = 0;
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_FRAME_NUM, L2_MSG_FRAME_NUM_LEN, &frameNum);
|
|
|
|
|
L2_FrameGetChunk(msg, L2_MSG_SLOT_NUM, L2_MSG_SLOT_NUM_LEN, &slotNum);
|
|
|
|
|
uint32_t frameNum = message->common.frameNum;
|
|
|
|
|
uint32_t slotNum = (uint32_t)message->common.slotNum;
|
|
|
|
|
Status = L2_GetTimeDeviation(instPtr, frameNum, slotNum, true, &(instPtr->log.timeDev));
|
|
|
|
|
if (Status != SUCCESS)
|
|
|
|
|
{
|
|
|
|
@@ -338,7 +384,7 @@ void L2_Service_Reset(L2_SVC_FSM *svcFSMPtr)
|
|
|
|
|
/**
|
|
|
|
|
* @brief Destroy ServiceNet FSM, free memory
|
|
|
|
|
*
|
|
|
|
|
* @param scanFsmPtr a pointer to service net finite state machine
|
|
|
|
|
* @param serviceFSM a pointer to service net finite state machine
|
|
|
|
|
*
|
|
|
|
|
* @return NONE
|
|
|
|
|
*
|
|
|
|
@@ -369,55 +415,157 @@ int32_t L2_Service_Routine(L2_INST *instPtr, const L2_RTNE_TABLE_ENTRY *rtneEntr
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PHY_INST *phyRef = instPtr->config.phyInstPtr;
|
|
|
|
|
PHY_ANT_INDEX antIndex;
|
|
|
|
|
L2_SVC_FSM *svcFSMPtr = instPtr->serviceFSM;
|
|
|
|
|
L2_TOR_TYPE torState;
|
|
|
|
|
const NODE_ENTRY *commNode;
|
|
|
|
|
if (rtneEntry->src == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
torState = L2_TOR_TX;
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->dst);
|
|
|
|
|
}
|
|
|
|
|
else if (rtneEntry->dst == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
torState = L2_TOR_RX;
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->src);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
torState = L2_TOR_SUSPEND;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Setup antenna beam
|
|
|
|
|
if (L2_GetNodeType(instPtr) != L2_NODE_HEAD && commNode != NULL)
|
|
|
|
|
{
|
|
|
|
|
Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_16);
|
|
|
|
|
Phy_SetBeamNo(phyRef, commNode->nodeInfo.beamNo, PHY_ANT_BEAM_16);
|
|
|
|
|
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_16;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Phy_SetBeamWidth(phyRef, PHY_ANT_BEAM_120);
|
|
|
|
|
instPtr->log.lastBeamWidth = PHY_ANT_BEAM_120;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (rtneEntry->slotType)
|
|
|
|
|
{
|
|
|
|
|
case L2_SLOT_SERVICE:
|
|
|
|
|
if (torState == L2_TOR_TX)
|
|
|
|
|
case L2_SLOT_DISTRIBUTE:
|
|
|
|
|
if (L2_GetNodeType(instPtr) == L2_NODE_HEAD && rtneEntry->src == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
svcFSMPtr->txCnt++;
|
|
|
|
|
#ifndef DATALINK_ENABLE_BERTEST
|
|
|
|
|
// Packing service data
|
|
|
|
|
Service_Packing(instPtr, L2_SVC_FRAME, rtneEntry->dst);
|
|
|
|
|
#else
|
|
|
|
|
memcpy(instPtr->sendPktData, testData, L2_SVC_PACK_LEN);
|
|
|
|
|
#endif
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->dst);
|
|
|
|
|
// antenna selection based on destination id in routing table
|
|
|
|
|
antIndex = commNode->nodeInfo.antIndex;
|
|
|
|
|
// head node transmits messages in distribute slot
|
|
|
|
|
torState = L2_TOR_TX;
|
|
|
|
|
|
|
|
|
|
// reset memory
|
|
|
|
|
memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX);
|
|
|
|
|
// pack message
|
|
|
|
|
if (Service_Packing(instPtr, L2_FRAME_DIS, rtneEntry->dst) != SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (L2_GetNodeType(instPtr) == L2_NODE_MEMBER && rtneEntry->dst == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->src);
|
|
|
|
|
// antenna selection based on node list
|
|
|
|
|
antIndex = commNode->nodeInfo.antIndex;
|
|
|
|
|
// member node receives message in advertise slot
|
|
|
|
|
torState = L2_TOR_RX;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// otherwise suspend
|
|
|
|
|
antIndex = PHY_ANT_INDEX_NONE;
|
|
|
|
|
torState = L2_TOR_SUSPEND;
|
|
|
|
|
}
|
|
|
|
|
(void)Phy_SetAntIndex(instPtr->config.phyInstPtr, antIndex);
|
|
|
|
|
(void)L2_SetupNextSlot(instPtr, torState, L2_FRAME_DIS);
|
|
|
|
|
break;
|
|
|
|
|
case L2_SLOT_MANAGE:
|
|
|
|
|
if (rtneEntry->src == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->dst);
|
|
|
|
|
// antenna selection based on destination id in routing table
|
|
|
|
|
antIndex = commNode->nodeInfo.antIndex;
|
|
|
|
|
// head node transmits messages in distribute slot
|
|
|
|
|
torState = L2_TOR_TX;
|
|
|
|
|
|
|
|
|
|
// reset memory
|
|
|
|
|
memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX);
|
|
|
|
|
// pack message
|
|
|
|
|
if (Service_Packing(instPtr, L2_FRAME_MNG, rtneEntry->dst) != SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (rtneEntry->dst == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->src);
|
|
|
|
|
// antenna selection based on node list
|
|
|
|
|
antIndex = commNode->nodeInfo.antIndex;
|
|
|
|
|
// member node receives message in advertise slot
|
|
|
|
|
torState = L2_TOR_RX;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// otherwise suspend
|
|
|
|
|
antIndex = PHY_ANT_INDEX_NONE;
|
|
|
|
|
torState = L2_TOR_SUSPEND;
|
|
|
|
|
}
|
|
|
|
|
(void)Phy_SetAntIndex(instPtr->config.phyInstPtr, antIndex);
|
|
|
|
|
(void)L2_SetupNextSlot(instPtr, torState, L2_FRAME_MNG);
|
|
|
|
|
break;
|
|
|
|
|
case L2_SLOT_RTT:
|
|
|
|
|
if (rtneEntry->src == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->dst);
|
|
|
|
|
// antenna selection based on destination id in routing table
|
|
|
|
|
antIndex = commNode->nodeInfo.antIndex;
|
|
|
|
|
// head node transmits messages in distribute slot
|
|
|
|
|
torState = L2_TOR_TX;
|
|
|
|
|
|
|
|
|
|
// reset memory
|
|
|
|
|
memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX);
|
|
|
|
|
// pack message
|
|
|
|
|
if (Service_Packing(instPtr, L2_FRAME_RTT, rtneEntry->dst) != SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (rtneEntry->dst == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->src);
|
|
|
|
|
// antenna selection based on node list
|
|
|
|
|
antIndex = commNode->nodeInfo.antIndex;
|
|
|
|
|
// member node receives message in advertise slot
|
|
|
|
|
torState = L2_TOR_RX;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// otherwise suspend
|
|
|
|
|
antIndex = PHY_ANT_INDEX_NONE;
|
|
|
|
|
torState = L2_TOR_SUSPEND;
|
|
|
|
|
}
|
|
|
|
|
(void)Phy_SetAntIndex(instPtr->config.phyInstPtr, antIndex);
|
|
|
|
|
(void)L2_SetupNextSlot(instPtr, torState, L2_FRAME_RTT);
|
|
|
|
|
break;
|
|
|
|
|
case L2_SLOT_SERVICE:
|
|
|
|
|
if (rtneEntry->src == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->dst);
|
|
|
|
|
// antenna selection based on destination id in routing table
|
|
|
|
|
antIndex = commNode->nodeInfo.antIndex;
|
|
|
|
|
// head node transmits messages in distribute slot
|
|
|
|
|
torState = L2_TOR_TX;
|
|
|
|
|
|
|
|
|
|
svcFSMPtr->txCnt++;
|
|
|
|
|
|
|
|
|
|
// reset memory
|
|
|
|
|
memset(instPtr->sendPktData, 0xAA, L2_PACK_LEN_MAX);
|
|
|
|
|
#ifndef DATALINK_ENABLE_BERTEST
|
|
|
|
|
// pack message
|
|
|
|
|
if (Service_Packing(instPtr, L2_FRAME_SVC, rtneEntry->dst) != SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
return FAILURE;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
size_t msgLen = L2_GetSvcPacketLen(instPtr->config.serviceRate);
|
|
|
|
|
memcpy(instPtr->sendPktData, testData, msgLen);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else if (rtneEntry->dst == L2_GetNodeId(instPtr))
|
|
|
|
|
{
|
|
|
|
|
commNode = L2_GetNodeById(instPtr->nodeList, rtneEntry->src);
|
|
|
|
|
// antenna selection based on node list
|
|
|
|
|
antIndex = commNode->nodeInfo.antIndex;
|
|
|
|
|
// member node receives message in advertise slot
|
|
|
|
|
torState = L2_TOR_RX;
|
|
|
|
|
|
|
|
|
|
svcFSMPtr->rxCnt++;
|
|
|
|
|
}
|
|
|
|
|
L2_SetupNextSlot(instPtr, torState, L2_SVC_FRAME);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// otherwise suspend
|
|
|
|
|
antIndex = PHY_ANT_INDEX_NONE;
|
|
|
|
|
torState = L2_TOR_SUSPEND;
|
|
|
|
|
}
|
|
|
|
|
(void)Phy_SetAntIndex(instPtr->config.phyInstPtr, antIndex);
|
|
|
|
|
(void)L2_SetupNextSlot(instPtr, torState, L2_FRAME_SVC);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
DBG_ERROR("UNKNOWN slot type [%" PRIu8 "].\n", rtneEntry->slotType);
|
|
|
|
|