Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] CLI 命令 time 总是返回 0 ms #20

Closed
chunhuajiang opened this issue Oct 28, 2017 · 3 comments
Closed

[bug] CLI 命令 time 总是返回 0 ms #20

chunhuajiang opened this issue Oct 28, 2017 · 3 comments

Comments

@chunhuajiang
Copy link
Contributor

chunhuajiang commented Oct 28, 2017

MK3060 开发板, 随便烧写一个 APP(例如 helloworld),板子上电后
在串口终端输入命令 time
总是返回 UP Time 0ms


进一步检查,发现应该是函数 aos_cli_printf 的问题,例如,对于我下面的代码:

long long testval = 8888;

static void uptime_cmd(char *buf, int len, int argc, char **argv)
{
    testval = aos_now_ms();
    aos_cli_printf("time: %ld ms, 22=%d \r\n", testval, 22);
    aos_cli_printf("hello:%s \r\n", "hello");
    aos_cli_printf("UP time %ld ms \r\n", aos_now_ms());
}

程序的输出却是这样的:

# time

time: 22 ms, 22=2364 
hello:hello 
UP time 0 ms 

更进一步来讲的话,应该是库函数 vsnprintf 不能正确地对字符串进行格式化,但是我没找到这个函数的源码。


PS: 我的 arm-none-eabi-gcc 的版本是:

work@ubuntu:~/me/AliOS-Things$ /opt/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 5.4.1 20160919 (release) [ARM/embedded-5-branch revision 240496]
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@junjiec
Copy link
Contributor

junjiec commented Oct 28, 2017

aos_cli_printf("UP time %ld ms \r\n", aos_now_ms());
的 %ld -> %lld ,因为aos_now_ms()返回long long

@chunhuajiang
Copy link
Contributor Author

@junjiec 换 %lld 依然有问题:

# time

UP time ld ms

@junjiec
Copy link
Contributor

junjiec commented Oct 29, 2017

看来c库支持不好,那只能强制转换一下:
aos_cli_printf("UP time %ld ms \r\n", (long)aos_now_ms());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants