我正在寫一個多線程通信接口,其中一個函數(在我的主線程中)將數據推入隊列(VxWorks msgQLib
),並在我的通信任務中提供另一個函數,從隊列中提取數據以轉發到硬件接口。 現在,我的推送數據似乎不符合我的提取數據(反之亦然)。我插入了一些調試信息來了解發生了什麼,但迄今未能找到罪魁禍首。我有的代碼:爲什麼我推入隊列的數據不會在另一端出現?
有點解釋。我構建了這樣的函數,以便在實際消息之前插入帶有一些元數據的消息標記,即每條消息都會將兩個項插入到隊列中。 請不要擔心「回覆」部分,但仍需要雙方的一些工作。我現在只是擔心等式中即將離任的部分。
是推動數據到隊列(在應用程序的任務)的函數:
static STATUS SPIQWriteRead_TDM(UINT8 cmdlen, UINT8 *cmd, UINT8 retdatlen, UINT8 *retdat)
{
UINT8 BytesRead;
UINT8 *msgTag[MSGTAGLEN]={0};
static UINT spi_init = 0;
UINT i=0;
//assemble message tag
msgTag[0] = 0x01; //FrameID
msgTag[1] = cmdlen/255; //MsgLen MSB
msgTag[2] = cmdlen%255; //MsgLen LSB
msgTag[3] = CS_TDM; // ChipSelect
msgTag[4] = 0; //SlotID
//copy message tag into queue
for(i=0;i<MSGTAGLEN;i++)
printf("<= msgTag[%d] 0x%x\n",i,msgTag[i]);
msgQSend(TDMTxQ,msgTag,MSGTAGLEN,NO_WAIT,MSG_PRI_NORMAL);
printf("<= TxQueue(0x%x) contains %d items\n",TDMTxQ, msgQNumMsgs(TDMTxQ));
for(i=0;i<cmdlen;i++)
printf("<= msg[%d] 0x%x\n",i,cmd[i]);
// copy message into queue
msgQSend(TDMTxQ,cmd,cmdlen,NO_WAIT,MSG_PRI_NORMAL);
printf("<= TxQueue(0x%x) contains %d items\n",TDMTxQ, msgQNumMsgs(TDMTxQ));
// wait for a maximum of 10 ticks (~1600ms) for the Reply
BytesRead = msgQReceive(TDMRxQ,retdat,retdatlen,100);
for(i=0;i<retdatlen;i++)
printf("retdat[%d] 0x%x\n",i,retdat[i]);
printf("BytesRead 0x%x\n",BytesRead);
// compare reply and return
if (BytesRead != retdatlen)
return ERROR;
else
return OK;
}
和從該隊列讀取的數據(在通信任務)的函數:
static FROM_Q_DAT *GetFromQueue(MSG_Q_ID TxQId)
{
UINT8 msgTag[MSGTAGLEN]= {0};
UINT8 FrameID = 0;
UINT16 MsgLen = 0;
UINT8 ChipSelect = 99;
UINT8 SlotID = 99;
static UINT8 *cmd=NULL;
UINT8 retdat[2]={0};
UINT8 cs=99;
static FROM_Q_DAT Qdat;
int retval = 0;
UINT8 i=0;
// read message tag from queue
msgQReceive(TxQId, msgTag, MSGTAGLEN, NO_WAIT);
for(i=0;i<MSGTAGLEN;i++)
printf("=> msgTag[%d] 0x%x\n",i,msgTag[i]);
// parse received message tag
FrameID = msgTag[0];
MsgLen = (((UINT16)msgTag[1])<<8) | (msgTag[2]);
ChipSelect = msgTag[3];
SlotID = msgTag[4];
printf("FrameID: %d\n",FrameID);
printf("MsgLen: %d\n",MsgLen);
printf("ChipSelect: %d\n",ChipSelect);
printf("SlotID: %d\n",SlotID);
printf("=> TxQueue(0x%x) contains %d items\n",TxQId, msgQNumMsgs(TxQId));
cmd = (UINT8*) calloc(MsgLen, sizeof(UINT8));
// Get the message from the queue
msgQReceive(TxQId, cmd, MsgLen, NO_WAIT);
for(i=0;i<MsgLen;i++)
printf("=> cmd[%d] 0x%x\n",i,cmd[i]);
printf("=> TxQueue(0x%x) contains %d items\n",TxQId, msgQNumMsgs(TxQId));
Qdat.cs = ChipSelect;
Qdat.len = MsgLen;
Qdat.data = cmd;
return &Qdat;
}
而屏幕捕獲如下:
<= msgTag[0] 0x1
<= msgTag[1] 0x0
<= msgTag[2] 0x9
<= msgTag[3] 0x2
<= msgTag[4] 0x0
<= TxQueue(0x261c6010) contains 1 items
<= msg[0] 0x5e
<= msg[1] 0x8
<= msg[2] 0x40
<= msg[3] 0x6
<= msg[4] 0x0
<= msg[5] 0x0
<= msg[6] 0x0
<= msg[7] 0x0
<= msg[8] 0x0
<= TxQueue(0x261c6010) contains 2 items
//the next message (with '==' is from the communication engine that checks for content in the communication Queue:
== TxQueue(1) contains 2 items
=> msgTag[0] 0x0
=> msgTag[1] 0x0
=> msgTag[2] 0x0
=> msgTag[3] 0x1
=> msgTag[4] 0x0
FrameID: 0
MsgLen: 0
ChipSelect: 1
SlotID: 0
=> TxQueue(0x261c6010) contains 1 items
=> TxQueue(0x261c6010) contains 0 items
我不明白爲什麼我的數據進入排隊不會出來...
@nos非常真實的,立即修復此問題! – cerr