How to print your log in Vxworks6.x

For embedded software developer using printf  is the most used debug method on target. But in vxworks6.x, it start to change because the default stdout/stderr is redirected. If you connect to device by shell/telnet, printf in the code will not put to the stdout/stderr in the current shell.

Solution:
You can put a the following code in the debug version. Once you have connect to target by shell/telnet, call the function to redirect some task /all task io to the current shell.

void ioRedirect(void)
{
int shellTid = 0;
int shellOpFd = 0;
int globalStdFd = 0;

shellTid = taskIdSelf();
shellOpFd = ioTaskStdGet(shellTid, 1);
globalStdFd = ioGlobalStdGet(1);
(void)logMsg("LM:Initial task output.shellFd %d, GlobalFd %d.\n", shellOpFd, globalStdFd, 0, 0, 0, 0);
printf("p:Initial task output.shellFd %d, GlobalFd %d.\n", shellOpFd, globalStdFd);

/*you can specify the task who need printf*/
/*ioTaskStdSet(GSETaskId,1,shellOpFd);
ioTaskStdSet(mstEvtId,1,shellOpFd);*/

/*or set the global io*/
ioGlobalStdSet(1, shellOpFd);
globalStdFd = ioGlobalStdGet(1);
logMsg("LM:Initial task output.shellFd %d, GlobalFd change to %d.\n", shellOpFd, globalStdFd, 0, 0, 0, 0);
printf("p:Initial task output to globalStdFd %d.\n", globalStdFd);
}

Comments

Popular posts from this blog

Capture VLAN tag with wireshark

Debug embedded application over GDB Server by VS Code