From 426bd82f4198f08f153ab222d71b8311194e5e39 Mon Sep 17 00:00:00 2001 From: marco Date: Tue, 13 Jun 2006 19:07:31 +0000 Subject: [PATCH] Fixed a bug in protocol_reply. Simplified rpc. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@664 38d2e660-2303-0410-9eaa-f027e97ec537 --- app/triface/protocol.c | 45 ++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/app/triface/protocol.c b/app/triface/protocol.c index c833837d..50e0e363 100755 --- a/app/triface/protocol.c +++ b/app/triface/protocol.c @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.3 2006/06/13 19:07:31 marco + *#* Fixed a bug in protocol_reply. Simplified rpc. + *#* *#* Revision 1.2 2006/06/12 21:37:02 marco *#* implemented some commands (ver and sleep) *#* @@ -34,10 +37,6 @@ #include #include -#include /* malloc() - TODO: substitute with a more appropriate - memory allocator. */ - #include #include @@ -80,19 +79,20 @@ INLINE void NAK(Serial *ser, const char *err) static int protocol_reply(Serial *s, const struct CmdTemplate *t, const parms *args) { - int nres = strlen(t->result_fmt); + unsigned short offset = strlen(t->arg_fmt) + 1; + unsigned short nres = strlen(t->result_fmt); if (nres > 0) { - for (int i = strlen(t->arg_fmt); i < nres; ++i) + for (unsigned short i = 0; i < nres; ++i) { if (t->result_fmt[i] == 'd') { - ser_printf(s, "%ld", args[i].l); + ser_printf(s, "%ld", args[offset+i].l); } else if (t->result_fmt[i] == 's') { - ser_printf(s, "%s ", args[i].s); + ser_printf(s, "%s ", args[offset+i].s); } else { @@ -216,39 +216,28 @@ void protocol_run(Serial *ser) */ /* Version. */ -static ResultCode cmd_ver(const char **str) + + +static ResultCode cmd_ver(parms *args) { - *str = VERS_TAG; + args[1].s = VERS_TAG; return 0; } -static ResultCode cmd_ver_hunk(parms args_results[]) -{ - return cmd_ver(&args_results[0].s); -} - const struct CmdTemplate cmd_ver_template = { - "ver", "", "s", cmd_ver_hunk, 0 + "ver", "", "s", cmd_ver, 0 }; -//DECLARE_CMD_HUNK(ver, (NIL), (string)(NIL)); - -/* Sleep. */ +/* Sleep. */ -static ResultCode cmd_sleep(const long ms) +static ResultCode cmd_sleep(parms *args) { - timer_delay((mtime_t)ms); + timer_delay((mtime_t)args[1].l); return 0; } - -static ResultCode cmd_sleep_hunk(parms args[]) -{ - return cmd_sleep(args[1].l); -} - const struct CmdTemplate cmd_sleep_template = { - "sleep", "d", "", cmd_sleep_hunk, 0 + "sleep", "d", "", cmd_sleep, 0 }; /* Register commands. */ -- 2.25.1