summaryrefslogtreecommitdiff
path: root/n/avr/proto/proto.c
diff options
context:
space:
mode:
authorschodet2005-01-20 23:51:01 +0000
committerschodet2005-01-20 23:51:01 +0000
commit063362de35410ac94c958db519264d86d498d5ca (patch)
treec00bcc252832909025d31f546aff0f407b399559 /n/avr/proto/proto.c
parent1b06d41e837f192a9f94c2c92ffa7a0d92c37118 (diff)
Modification du fonctionnement de proto.
Diffstat (limited to 'n/avr/proto/proto.c')
-rw-r--r--n/avr/proto/proto.c138
1 files changed, 24 insertions, 114 deletions
diff --git a/n/avr/proto/proto.c b/n/avr/proto/proto.c
index a426c41..b23c6b4 100644
--- a/n/avr/proto/proto.c
+++ b/n/avr/proto/proto.c
@@ -35,42 +35,29 @@ proto_accept_digit (uint8_t c);
static void
proto_hex (uint8_t h);
-/* Send a arg. */
+/* Send a byte. */
inline static void
-proto_arg (proto_arg_t a);
+proto_arg (uint8_t a);
/* -AutoDec */
static uint8_t cmd;
-static proto_arg_t argv[AC_PROTO_MAX_ARGS];
-static uint8_t argc;
+static uint8_t size;
+static uint8_t args[AC_PROTO_ARGS_MAX_SIZE];
/** Step of decoding:
* - 0: nothing received.
* - 1: bang received.
* - 2: command received.
- * - 3, 4, 5: command received, and processing a number. */
+ * - 3: command received, and processing a number. */
static uint8_t step;
-static proto_cb_f func_cb;
-static proto_putc_f func_putc;
-
-/** Initialize and set the callback function. */
-void
-proto_init (proto_cb_f f_cb, proto_putc_f f_putc)
-{
- func_cb = f_cb;
- func_putc = f_putc;
-}
-
/** Accept a new character. */
void
proto_accept (uint8_t c)
{
if (c == '!')
- {
step = 1;
- }
else
{
switch (step)
@@ -83,12 +70,12 @@ proto_accept (uint8_t c)
if (isalpha (c))
{
cmd = c;
+ size = 0;
step = 2;
- argc = 0;
}
else
{
- func_cb ('?', 0, 0);
+ proto_callback ('?', 0, 0);
step = 0;
}
break;
@@ -96,21 +83,16 @@ proto_accept (uint8_t c)
/* Command received yet. */
if (c == '\r')
{
- func_cb (cmd, argc, argv);
+ proto_callback (cmd, size, args);
step = 0;
}
- else if (c == ',')
- {
- }
else
{
- step += sizeof (proto_arg_t) * 2 - 1;
+ step = 3;
proto_accept_digit (c);
}
break;
case 3:
- case 4:
- case 5:
step--;
proto_accept_digit (c);
break;
@@ -123,9 +105,9 @@ static void
proto_accept_digit (uint8_t c)
{
/* Test for argument list overflow. */
- if (argc >= AC_PROTO_MAX_ARGS)
+ if (size >= AC_PROTO_ARGS_MAX_SIZE)
{
- func_cb ('?', 0, 0);
+ proto_callback ('?', 0, 0);
step = 0;
return;
}
@@ -138,111 +120,39 @@ proto_accept_digit (uint8_t c)
c -= 'A' - 10;
else
{
- func_cb ('?', 0, 0);
+ proto_callback ('?', 0, 0);
return;
}
/* Add digit. */
- argv[argc] <<= 4;
- argv[argc] |= c;
+ args[size] <<= 4;
+ args[size] |= c;
if (step == 2)
- argc++;
+ size++;
}
/* Send a hex digit. */
static void
proto_hex (uint8_t h)
{
- func_putc (h >= 10 ? h - 10 + 'a' : h + '0');
+ proto_putc (h >= 10 ? h - 10 + 'a' : h + '0');
}
-/* Send a arg. */
+/* Send a byte. */
inline static void
-proto_arg (proto_arg_t a)
+proto_arg (uint8_t a)
{
- if (sizeof (proto_arg_t) == 2)
- {
- proto_hex (a >> 12);
- proto_hex ((a >> 8) & 0xf);
- }
proto_hex ((a >> 4) & 0xf);
proto_hex ((a >> 0) & 0xf);
}
/** Send a command, generic function. */
void
-proto_send (uint8_t cmd, uint8_t argc, proto_arg_t *argv)
-{
- func_putc ('!');
- func_putc (cmd);
- while (argc-- > 1)
- {
- proto_arg (*argv++);
- func_putc (',');
- }
- if (!argc)
- proto_arg (*argv);
- func_putc ('\r');
-}
-
-/** Send a command, no arg. */
-void
-proto_send0 (uint8_t cmd)
-{
- func_putc ('!');
- func_putc (cmd);
- func_putc ('\r');
-}
-
-/** Send a command, one arg. */
-void
-proto_send1 (uint8_t cmd, proto_arg_t a0)
-{
- func_putc ('!');
- func_putc (cmd);
- proto_arg (a0);
- func_putc ('\r');
-}
-
-/** Send a command, two arg. */
-void
-proto_send2 (uint8_t cmd, proto_arg_t a0, proto_arg_t a1)
-{
- func_putc ('!');
- func_putc (cmd);
- proto_arg (a0);
- func_putc (',');
- proto_arg (a1);
- func_putc ('\r');
-}
-
-/** Send a command, three arg. */
-void
-proto_send3 (uint8_t cmd, proto_arg_t a0, proto_arg_t a1, proto_arg_t a2)
-{
- func_putc ('!');
- func_putc (cmd);
- proto_arg (a0);
- func_putc (',');
- proto_arg (a1);
- func_putc (',');
- proto_arg (a2);
- func_putc ('\r');
-}
-
-/** Send a command, four arg. */
-void
-proto_send4 (uint8_t cmd, proto_arg_t a0, proto_arg_t a1, proto_arg_t a2,
- proto_arg_t a3)
+proto_send (uint8_t cmd, uint8_t size, uint8_t *args)
{
- func_putc ('!');
- func_putc (cmd);
- proto_arg (a0);
- func_putc (',');
- proto_arg (a1);
- func_putc (',');
- proto_arg (a2);
- func_putc (',');
- proto_arg (a3);
- func_putc ('\r');
+ proto_putc ('!');
+ proto_putc (cmd);
+ while (size--)
+ proto_arg (*args++);
+ proto_putc ('\r');
}