How to print your log in VxWorks 6.x

mershaywu

Jun wu

Posted on December 16, 2022

How to print your log in VxWorks 6.x

Issue:

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);
}
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
mershaywu
Jun wu

Posted on December 16, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024