forked from gatsby/df_datalink
feat: 增加上位机消息发送队列
This commit is contained in:
@@ -601,8 +601,8 @@ int32_t Linklayer_Init(L2_INST **instPtr, const L2_CONFIG *config)
|
||||
(*instPtr)->tor.last = L2_TOR_SUSPEND;
|
||||
(*instPtr)->tor.curr = L2_TOR_SUSPEND;
|
||||
(*instPtr)->tor.next = L2_TOR_SUSPEND;
|
||||
(*instPtr)->rtneConfig.rtneTable = initTable;
|
||||
(*instPtr)->rtneConfig.rtnePrd = ARRAY_SIZE(initTable);
|
||||
(*instPtr)->rtneConfig.rtneTable = (*instPtr)->config.initTable;
|
||||
(*instPtr)->rtneConfig.rtnePrd = ARRAY_SIZE(initRoutTable);
|
||||
(*instPtr)->mainState = L2_INIT_STATE;
|
||||
(*instPtr)->nextState = L2_INIT_STATE;
|
||||
(*instPtr)->myInfo.nodeId = config->myId;
|
||||
@@ -698,8 +698,8 @@ int32_t Linklayer_Reconfig(L2_INST *instPtr, const L2_CONFIG *config)
|
||||
instPtr->tor.last = L2_TOR_SUSPEND;
|
||||
instPtr->tor.curr = L2_TOR_SUSPEND;
|
||||
instPtr->tor.next = L2_TOR_SUSPEND;
|
||||
instPtr->rtneConfig.rtneTable = initTable;
|
||||
instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(initTable);
|
||||
instPtr->rtneConfig.rtneTable = instPtr->config.initTable;
|
||||
instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(initRoutTable);
|
||||
instPtr->mainState = L2_INIT_STATE;
|
||||
instPtr->nextState = L2_INIT_STATE;
|
||||
instPtr->myInfo.nodeId = config->myId;
|
||||
@@ -883,14 +883,14 @@ int32_t Linklayer_EventHandler(L2_INST *instPtr, const L2_EVENT *l2Event)
|
||||
// Reset scan net FMS for next scan process.
|
||||
L2_Scan_Reset(instPtr->scanFSM);
|
||||
UpdateMainSate(instPtr, L2_INIT_STATE);
|
||||
// instPtr->rtneConfig.rtneTable = initTable;
|
||||
// instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(initTable);
|
||||
instPtr->rtneConfig.rtneTable = instPtr->config.initTable;
|
||||
instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(initRoutTable);
|
||||
}
|
||||
else if (instPtr->nextState == L2_NORMAL_STATE)
|
||||
{
|
||||
UpdateMainSate(instPtr, L2_NORMAL_STATE);
|
||||
// instPtr->rtneConfig.rtneTable = normalTable0;
|
||||
// instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(normalTable0);
|
||||
instPtr->rtneConfig.rtneTable = instPtr->config.normalTable;
|
||||
instPtr->rtneConfig.rtnePrd = ARRAY_SIZE(normalRoutTable0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -45,6 +45,8 @@ typedef struct
|
||||
uint8_t headId; ///< head node id
|
||||
uint8_t netScale; ///< net scale
|
||||
L2_SVC_RATE serviceRate; ///< service data rate
|
||||
L2_RTNE_TABLE_ENTRY **initTable;
|
||||
L2_RTNE_TABLE_ENTRY **normalTable;
|
||||
PHY_INST *phyInstPtr; ///< pointer to system physical layer instance
|
||||
TMC_INST *tmcInstPtr; ///< pointer to system timer controller layer instance
|
||||
} L2_CONFIG;
|
||||
@@ -129,10 +131,10 @@ typedef struct
|
||||
} L2_INST;
|
||||
|
||||
/************************** Variable Definitions *****************************/
|
||||
extern L2_RTNE_TABLE_ENTRY *initTable[L2_INIT_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY *normalTable0[L2_INIT_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY *normalTable1[L2_INIT_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY *normalTable2[L2_INIT_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY *initRoutTable[L2_INIT_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY *normalRoutTable0[L2_INIT_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY *normalRoutTable1[L2_INIT_RTNE_PERIOD];
|
||||
extern L2_RTNE_TABLE_ENTRY *normalRoutTable2[L2_INIT_RTNE_PERIOD];
|
||||
/************************** Function Prototypes ******************************/
|
||||
/**
|
||||
* @defgroup LinkLayer_Main
|
||||
|
||||
@@ -37,8 +37,9 @@
|
||||
#define L2_BROADCAST_ID2 0xF2
|
||||
#define L2_BROADCAST_ID3 0xF4
|
||||
#define L2_UNICAST_ID 0xF0
|
||||
#define L2_NONE_ID 0
|
||||
#define L2_HEAD_ID 0x01
|
||||
#define L2_NONE_ID 0U
|
||||
#define L2_HEAD_ID 1U
|
||||
#define L2_NET_SCALE 10U
|
||||
|
||||
// Routine configure
|
||||
#define L2_INIT_RTNE_PERIOD 1
|
||||
|
||||
@@ -853,22 +853,22 @@ L2_RTNE_TABLE_ENTRY tab3Mng3Svc[L2_SLOTS_PER_FRAME] =
|
||||
{L2_SLOT_IDLE, 0x00, 0x00, 0x00}
|
||||
};
|
||||
|
||||
L2_RTNE_TABLE_ENTRY *initTable[L2_INIT_RTNE_PERIOD] =
|
||||
L2_RTNE_TABLE_ENTRY *initRoutTable[L2_INIT_RTNE_PERIOD] =
|
||||
{
|
||||
tab10Mng10Svc
|
||||
};
|
||||
|
||||
L2_RTNE_TABLE_ENTRY *normalTable0[L2_INIT_RTNE_PERIOD] =
|
||||
L2_RTNE_TABLE_ENTRY *normalRoutTable0[L2_INIT_RTNE_PERIOD] =
|
||||
{
|
||||
tab10Mng10Svc
|
||||
};
|
||||
|
||||
L2_RTNE_TABLE_ENTRY *normalTable1[L2_INIT_RTNE_PERIOD] =
|
||||
L2_RTNE_TABLE_ENTRY *normalRoutTable1[L2_INIT_RTNE_PERIOD] =
|
||||
{
|
||||
tab10Mng3Svc
|
||||
};
|
||||
|
||||
L2_RTNE_TABLE_ENTRY *normalTable2[L2_INIT_RTNE_PERIOD] =
|
||||
L2_RTNE_TABLE_ENTRY *normalRoutTable2[L2_INIT_RTNE_PERIOD] =
|
||||
{
|
||||
tab3Mng3Svc
|
||||
};
|
||||
|
||||
@@ -256,6 +256,7 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
||||
recvPayload->dataLen = message->dataLen;
|
||||
memcpy(recvPayload->data, message->data, message->dataLen);
|
||||
SysMonitor_GenRecvRsp(recvPayload);
|
||||
free(recvPayload);
|
||||
}
|
||||
|
||||
// Logging...
|
||||
@@ -276,7 +277,7 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
||||
|
||||
L2_MSG_ACK *message = (L2_MSG_ACK *)msg;
|
||||
size_t msgLen = sizeof(L2_MSG_ACK);
|
||||
size_t dataLen = L2_PAYLOAD_LEN_ACK;
|
||||
size_t maxDataLen = L2_PAYLOAD_LEN_ACK;
|
||||
|
||||
// Update node status.
|
||||
uint8_t nodeId = message->common.src;
|
||||
@@ -326,12 +327,21 @@ int32_t L2_Scan_PktHandler(L2_INST *instPtr, uint8_t *msg)
|
||||
}
|
||||
|
||||
// Get data payload & upload
|
||||
SYSBUS_SVC_PLD recvPayload;
|
||||
recvPayload.dataId = message->dataId;
|
||||
recvPayload.nodeId = message->common.src;
|
||||
recvPayload.dataLen = message->dataLen;
|
||||
memcpy(recvPayload.data, message->data, dataLen);
|
||||
SysMonitor_GenRecvRsp(&recvPayload);
|
||||
if (message->dataId != DATA_ID_NONE)
|
||||
{
|
||||
if (message->dataLen > maxDataLen)
|
||||
{
|
||||
DBG_ERROR("Payload length" PRIu16 " out of range.\n", message->dataLen);
|
||||
return EIGNORE;
|
||||
}
|
||||
SYSBUS_SVC_PLD *recvPayload = calloc(1, sizeof(SYSBUS_SVC_PLD));
|
||||
recvPayload->dataId = message->dataId;
|
||||
recvPayload->nodeId = message->common.src;
|
||||
recvPayload->dataLen = message->dataLen;
|
||||
memcpy(recvPayload->data, message->data, message->dataLen);
|
||||
SysMonitor_GenRecvRsp(recvPayload);
|
||||
free(recvPayload);
|
||||
}
|
||||
|
||||
// Logging...
|
||||
instPtr->log.rxLog.dataId = message->dataId;
|
||||
|
||||
@@ -201,7 +201,7 @@ static int32_t Service_Packing128K(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t
|
||||
{
|
||||
// Packing extra payload
|
||||
SYSBUS_SVC_PLD *sendPayload;
|
||||
SysMonitor_GetSendPayload(&sendPayload);
|
||||
SysMonitor_GetSendPayload(&sendPayload, dstId);
|
||||
if(sendPayload == NULL)
|
||||
{
|
||||
message->common.dst = L2_NONE_ID;
|
||||
@@ -211,7 +211,7 @@ static int32_t Service_Packing128K(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t
|
||||
}
|
||||
else
|
||||
{
|
||||
// message->common.dst = sendPayload->nodeId;
|
||||
// message->common.dst = sendPayload->nodeId;
|
||||
message->dataId = sendPayload->dataId;
|
||||
message->dataLen = sendPayload->dataLen;
|
||||
memset(message->data, 0xAA, maxDataLen);
|
||||
@@ -279,7 +279,7 @@ static int32_t Service_Packing512K(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t
|
||||
|
||||
// Pack extra payload
|
||||
SYSBUS_SVC_PLD *sendPayload;
|
||||
SysMonitor_GetSendPayload(&sendPayload);
|
||||
SysMonitor_GetSendPayload(&sendPayload, dstId);
|
||||
if(sendPayload == NULL)
|
||||
{
|
||||
message->common.dst = L2_NONE_ID;
|
||||
@@ -289,7 +289,7 @@ static int32_t Service_Packing512K(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t
|
||||
}
|
||||
else
|
||||
{
|
||||
// message->common.dst = sendPayload->nodeId;
|
||||
// message->common.dst = sendPayload->nodeId;
|
||||
message->dataId = sendPayload->dataId;
|
||||
message->dataLen = sendPayload->dataLen;
|
||||
memset(message->data, 0xAA, maxDataLen);
|
||||
@@ -349,7 +349,7 @@ static int32_t Service_Packing2M(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t d
|
||||
|
||||
// Packing extra payload
|
||||
SYSBUS_SVC_PLD *sendPayload;
|
||||
SysMonitor_GetSendPayload(&sendPayload);
|
||||
SysMonitor_GetSendPayload(&sendPayload, dstId);
|
||||
if(sendPayload == NULL)
|
||||
{
|
||||
message->common.dst = L2_NONE_ID;
|
||||
@@ -359,7 +359,7 @@ static int32_t Service_Packing2M(L2_INST *instPtr, L2_FRAME_TYPE type, uint8_t d
|
||||
}
|
||||
else
|
||||
{
|
||||
// message->common.dst = sendPayload->nodeId;
|
||||
// message->common.dst = sendPayload->nodeId;
|
||||
message->dataId = sendPayload->dataId;
|
||||
message->dataLen = sendPayload->dataLen;
|
||||
memset(message->data, 0xAA, maxDataLen);
|
||||
@@ -541,6 +541,7 @@ static int32_t Service_PktHandler128K(L2_INST *instPtr, uint8_t *msg)
|
||||
recvPayload->dataLen = message->dataLen;
|
||||
memcpy(recvPayload->data, message->data, message->dataLen);
|
||||
SysMonitor_GenRecvRsp(recvPayload);
|
||||
free(recvPayload);
|
||||
}
|
||||
|
||||
// Logging...
|
||||
@@ -629,6 +630,7 @@ static int32_t Service_PktHandler512K(L2_INST *instPtr, uint8_t *msg)
|
||||
recvPayload->dataLen = message->dataLen;
|
||||
memcpy(recvPayload->data, message->data, message->dataLen);
|
||||
SysMonitor_GenRecvRsp(recvPayload);
|
||||
free(recvPayload);
|
||||
}
|
||||
|
||||
// Logging...
|
||||
@@ -717,6 +719,7 @@ static int32_t Service_PktHandler2M(L2_INST *instPtr, uint8_t *msg)
|
||||
recvPayload->dataLen = message->dataLen;
|
||||
memcpy(recvPayload->data, message->data, message->dataLen);
|
||||
SysMonitor_GenRecvRsp(recvPayload);
|
||||
free(recvPayload);
|
||||
}
|
||||
|
||||
// Logging...
|
||||
|
||||
Reference in New Issue
Block a user