From 619b96eb49363eff5971b1052c1747bb20351d14 Mon Sep 17 00:00:00 2001 From: henryk Date: Sun, 3 Feb 2008 23:51:20 +0000 Subject: Factor out time print code and enhance it git-svn-id: https://svn.openpcd.org:2342/trunk@404 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- openpicc/application/cmd.c | 40 ++++++++++++++++++++++++++++------------ openpicc/application/cmd.h | 1 + 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/openpicc/application/cmd.c b/openpicc/application/cmd.c index ac1d605..5fe143b 100644 --- a/openpicc/application/cmd.c +++ b/openpicc/application/cmd.c @@ -87,6 +87,31 @@ void DumpBufferToUSB(char* buffer, int len) } /**********************************************************************/ +void DumpTimeToUSB(long ticks) +{ + int h, s, m, ms; + ms = ticks; + + s=ms/1000; + ms%=1000; + h=s/3600; + s%=3600; + m=s/60; + s%=60; + DumpUIntToUSB(h); + DumpStringToUSB("h:"); + if(m < 10) DumpStringToUSB("0"); + DumpUIntToUSB(m); + DumpStringToUSB("m:"); + if(s < 10) DumpStringToUSB("0"); + DumpUIntToUSB(s); + DumpStringToUSB("s."); + if(ms < 10) DumpStringToUSB("0"); + if(ms < 100) DumpStringToUSB("0"); + DumpUIntToUSB(ms); + DumpStringToUSB("ms"); +} + /* * Convert a string to an integer. Ignores leading spaces. * Optionally returns a pointer to the end of the number in the string */ @@ -145,7 +170,7 @@ void prvExecCommand(u_int32_t cmd, portCHAR *args) { static int led = 0; portCHAR cByte = cmd & 0xff; portLONG j; - int i,h,m,s; + int i,ms; if(cByte>='A' && cByte<='Z') cByte-=('A'-'a'); @@ -242,17 +267,8 @@ void prvExecCommand(u_int32_t cmd, portCHAR *args) { " * compiled " COMPILE_DATE " by " COMPILE_BY "\n\r" " *\n\r"); DumpStringToUSB(" * Uptime is "); - s=xTaskGetTickCount()/1000; - h=s/3600; - s%=3600; - m=s/60; - s%=60; - DumpUIntToUSB(h); - DumpStringToUSB("h:"); - DumpUIntToUSB(m); - DumpStringToUSB("m:"); - DumpUIntToUSB(s); - DumpStringToUSB("s"); + ms=xTaskGetTickCount(); + DumpTimeToUSB(ms); DumpStringToUSB("\n\r"); DumpStringToUSB(" * The reader id is "); DumpUIntToUSB(env.e.reader_id); diff --git a/openpicc/application/cmd.h b/openpicc/application/cmd.h index 0033b58..a93d8f0 100644 --- a/openpicc/application/cmd.h +++ b/openpicc/application/cmd.h @@ -14,6 +14,7 @@ portBASE_TYPE vCmdInit(void); extern void DumpUIntToUSB(unsigned int data); extern void DumpStringToUSB(char *string); extern void DumpBufferToUSB(char* buffer, int len); +extern void DumpTimeToUSB(long ticks); extern xQueueHandle xCmdQueue; #endif /*CMD_H_*/ -- cgit v1.2.3