Last active
August 29, 2015 14:21
-
-
Save RobinCPC/2fac50659be9867857a8 to your computer and use it in GitHub Desktop.
Add a (Variadic function) to send message from realtime controller to HMI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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