Hi Mark
Tried "Dummy task idea" above and it seems to work partially. I am only able to write out one message (the first one). The rest of the messages don't seem to be stored. The fnRead() in the while-loop is not reading anything (returns 0) when it's supposed to read the sekund message.
I have the following code to read the content of the queue:
//include
#include "config.h"
//Global variables
static QUEUE_HANDLE PortIDInternalQueue; // queue ID for task input
//Prototypes
void fnDummyQueueTask(TTASKTABLE *ptrTaskTable);
//functions
void fnRxMessage(TTASKTABLE *ptrTaskTable) // scheduled once every 2s
{
unsigned char ucRxMessage[SMALL_MESSAGE] = {0};
static QUEUE_HANDLE SerialID;
int len = 0;
while ( fnRead( PortIDInternalQueue, ucRxMessage, HEADER_LENGTH + 1 )) // read the queued inputs every 2s.
{
SerialID = ucRxMessage[MSG_CONTENT_COMMAND];
switch(ucRxMessage[MSG_SOURCE_TASK]) // Source of message
{
case TASK_TX_MESSAGE:
{
fnRead( PortIDInternalQueue, ucRxMessage, SMALL_MESSAGE);
len = uStrlen(ucRxMessage);
fnWrite(SerialID, ucRxMessage, len);
}
}
}
}
void fnDummyQueueTask(TTASKTABLE *ptrTaskTable)
{
PortIDInternalQueue = ptrTaskTable->TaskID; // remember the input handle but don't read the queue
}
The following code is used to build and send the message to the fnDummyQueueTask() and to set up the UART. :
//Includes
#include "config.h"
//defines
//Global varables
//Prototypes
void fnSendToDummy(unsigned char ucCommand, unsigned char *ucData, unsigned char ucLength);
QUEUE_HANDLE fnConfigureUART(unsigned char mode);
//functions
void fnTxMessage(TTASKTABLE *ptrTaskTable)
{
static unsigned int uiState;
unsigned char ucRxUART[SMALL_MESSAGE] = {0};
static QUEUE_HANDLE SerialID;
if(uiState == 0)
{
SerialID = fnConfigureUART(FOR_I_O);
uTaskerStateChange(TASK_TX_MESSAGE, UTASKER_STOP);
uiState = 1;
}
if(fnRead(SerialID, (unsigned char *)ucRxUART, SMALL_MESSAGE) != 0)
fnSendToDummy(SerialID, (unsigned char *)ucRxUART, uStrlen(ucRxUART));
else
fnSendToDummy(SerialID, (unsigned char *)"empty\r", uStrlen("empty\r"));
}
void fnSendToDummy(unsigned char ucCommand, unsigned char *ucData, unsigned char ucLength)
{
unsigned char ucTxMessage[ HEADER_LENGTH + SMALL_MESSAGE + 1];
ucTxMessage[ MSG_DESTINATION_NODE ] = INTERNAL_ROUTE;
ucTxMessage[ MSG_SOURCE_NODE ] = INTERNAL_ROUTE;
ucTxMessage[ MSG_DESTINATION_TASK ] = TASK_DUMMY;
ucTxMessage[ MSG_SOURCE_TASK ] = TASK_TX_MESSAGE;
ucTxMessage[ MSG_CONTENT_LENGTH ] = ucLength;
ucTxMessage[ MSG_CONTENT_COMMAND ] = ucCommand;
if (fnWrite(INTERNAL_ROUTE, ucTxMessage, 0))
fnWrite(INTERNAL_ROUTE, ucData, ucLength);
}
QUEUE_HANDLE fnConfigureUART(unsigned char mode)
{
TTYTABLE tInterfaceParameters; //table for passing information to driver
QUEUE_HANDLE SerialPortID;
tInterfaceParameters.Channel = 0; // serial 0, 1, 2, 3, 4, etc.
tInterfaceParameters.ucSpeed = SERIAL_BAUD_19200; // baud rate
tInterfaceParameters.Rx_tx_sizes.RxQueueSize = RX_BUFFER_SIZE; // input buffer size
tInterfaceParameters.Rx_tx_sizes.TxQueueSize = TX_BUFFER_SIZE;
tInterfaceParameters.Task_to_wake = TASK_TX_MESSAGE;
tInterfaceParameters.usConfig = (CHAR_8| NO_PARITY | ONE_STOP | NO_HANDSHAKE | MSG_MODE);
tInterfaceParameters.ucMessageTerminator = '\r';
if (SerialPortID = fnOpen( TYPE_TTY, mode, &tInterfaceParameters )) // open or change the channel with defined configurations (initially inactive)
fnDriver( SerialPortID, (RX_ON | TX_ON ), 0 ); // enable RX
return SerialPortID;
}
In TaskConfig.h I have the following configuration:
{ "1_Tx", fnTxMessage, NO_QUE, 0, 0, UTASKER_GO},
{ "2_Rx", fnRxMessage, NO_QUE, 0, (DELAY_LIMIT)(10 * SEC), UTASKER_STOP},
{ "3_Dummy", fnDummyQueueTask, (2 * 1024), 0, 0, UTASKER_STOP},
I am fully able to send and recieve from the UART using message mode. During the 10 sec I can send messages from the UART and everytime the fnTxMessage() is called so the messages can be build, sent and stored. When the 10 sec are done only the first message sent is recieved the rest is gone.
Can't figure out what is wrong
ZeroOne