aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/avr/usbserial.c6
-rw-r--r--src/command.c11
-rw-r--r--src/command.h2
-rw-r--r--src/generic/usb_cdc.c4
-rw-r--r--src/linux/console.c4
5 files changed, 17 insertions, 10 deletions
diff --git a/src/avr/usbserial.c b/src/avr/usbserial.c
index fe378227..2a16160d 100644
--- a/src/avr/usbserial.c
+++ b/src/avr/usbserial.c
@@ -7,7 +7,7 @@
#include <string.h> // memmove
#include "../lib/pjrc_usb_serial/usb_serial.h"
#include "board/misc.h" // console_sendf
-#include "command.h" // command_dispatch
+#include "command.h" // command_find_and_dispatch
#include "sched.h" // DECL_INIT
static uint8_t receive_buf[MESSAGE_MAX], receive_pos;
@@ -51,9 +51,7 @@ console_task(void)
{
console_check_input();
uint_fast8_t pop_count;
- int8_t ret = command_find_block(receive_buf, receive_pos, &pop_count);
- if (ret > 0)
- command_dispatch(receive_buf, pop_count);
+ int8_t ret = command_find_and_dispatch(receive_buf, receive_pos, &pop_count);
if (ret)
console_pop_input(pop_count);
}
diff --git a/src/command.c b/src/command.c
index 965f91ed..2df70d85 100644
--- a/src/command.c
+++ b/src/command.c
@@ -307,3 +307,14 @@ command_dispatch(uint8_t *buf, uint_fast8_t msglen)
func(args);
}
}
+
+// Find a message block and then dispatch all the commands in it
+int_fast8_t
+command_find_and_dispatch(uint8_t *buf, uint_fast8_t buf_len
+ , uint_fast8_t *pop_count)
+{
+ int_fast8_t ret = command_find_block(buf, buf_len, pop_count);
+ if (ret > 0)
+ command_dispatch(buf, *pop_count);
+ return ret;
+}
diff --git a/src/command.h b/src/command.h
index 2dd195ea..035d3929 100644
--- a/src/command.h
+++ b/src/command.h
@@ -72,6 +72,8 @@ void command_sendf(const struct command_encoder *ce, ...);
int_fast8_t command_find_block(uint8_t *buf, uint_fast8_t buf_len
, uint_fast8_t *pop_count);
void command_dispatch(uint8_t *buf, uint_fast8_t msglen);
+int_fast8_t command_find_and_dispatch(uint8_t *buf, uint_fast8_t buf_len
+ , uint_fast8_t *pop_count);
// out/compile_time_request.c (auto generated file)
extern const struct command_parser command_index[];
diff --git a/src/generic/usb_cdc.c b/src/generic/usb_cdc.c
index 56a60fac..ab1869f8 100644
--- a/src/generic/usb_cdc.c
+++ b/src/generic/usb_cdc.c
@@ -93,9 +93,7 @@ usb_bulk_out_task(void)
return;
// Process any existing message blocks
uint_fast8_t rpos = receive_pos, pop_count;
- int_fast8_t ret = command_find_block(receive_buf, rpos, &pop_count);
- if (ret > 0)
- command_dispatch(receive_buf, pop_count);
+ int_fast8_t ret = command_find_and_dispatch(receive_buf, rpos, &pop_count);
if (ret) {
// Move buffer
uint_fast8_t needcopy = rpos - pop_count;
diff --git a/src/linux/console.c b/src/linux/console.c
index 9064171f..4afa6151 100644
--- a/src/linux/console.c
+++ b/src/linux/console.c
@@ -156,9 +156,7 @@ console_task(void)
// Find and dispatch message blocks in the input
int len = receive_pos + ret;
uint_fast8_t pop_count, msglen = len > MESSAGE_MAX ? MESSAGE_MAX : len;
- ret = command_find_block(receive_buf, msglen, &pop_count);
- if (ret > 0)
- command_dispatch(receive_buf, pop_count);
+ ret = command_find_and_dispatch(receive_buf, msglen, &pop_count);
if (ret) {
len -= pop_count;
if (len) {