Skip to content

Instantly share code, notes, and snippets.

@RobinCPC
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobinCPC/2fac50659be9867857a8 to your computer and use it in GitHub Desktop.
Save RobinCPC/2fac50659be9867857a8 to your computer and use it in GitHub Desktop.
Add a (Variadic function) to send message from realtime controller to HMI
void PMC_SendCtrlMsg(MSG_TYPE Type, char Text[256], ...); // variadic function Delcaration
void PMC_SendCtrlMsg(MSG_TYPE Type, char Text[256], ...) // variadic function Definetion
{
MsgQueue[MsgQueueIndex+1].rtMsgType = Type;
//get final string according to parameters
char temp_text[256];
sprintf(temp_text, Text);
/* method for variadic function to retrieve the rest of parameters*/
va_list ap; // the rest parameter insert by user, will change inside (va_start-va_end) loop
int retval;
va_start(ap,Text);
retval = vsprintf(temp_text, Text, ap);
va_end(ap);
/*================================================================*/
strncpy(MsgQueue[MsgQueueIndex+1].msg, temp_text, 256 );
MsgQueueIndex++;
}
enum MSG_TYPE
{
RT_START,
RT_END,
RT_NORMAL,
RT_DEBUG,
RT_ECAT_ERR,
RT_ROB_ERR
};
typedef struct CTRL_MSG
{
MSG_TYPE rtMsgType;
char msg[256];
};
/* Controller MSG queue process*/
CTRL_MSG MsgQueue[100];
int MsgQueueIndex = -1;
int main(int argc, char *argv[])
{
...
...
PMC_SendCtrlMsg(RT_START, "SdoThread = %x\n", SdoThread);
return 0;
}
void RTFCNDCL PMCLogTimer(void *nContext)
{
if( MsgQueueIndex> -1 & /*UISharedMemory->b_IS_RT_SEND_MSG &*/ !UISharedMemory->b_IS_HMI_SHOW_MSG )
{
UISharedMemory->PMC_Ctrl_Msg = MsgQueue[0]; // get the first message
//MsgQueue command shift up 1 element
for(int i = 1; i <= MsgQueueIndex; i++)
{
memcpy(&(MsgQueue[i - 1]), &(MsgQueue[i]), sizeof(CTRL_MSG));
}
MsgQueueIndex--;
UISharedMemory->b_IS_HMI_SHOW_MSG = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment