diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-05-24 13:07:43 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-05-28 10:43:39 -0400 |
commit | c8af3feee6b35e33ab989ca8af0b48d738d4aedf (patch) | |
tree | 1a50e691bfe80403f38b7cec5c45f8171c7e8ae5 | |
parent | cb4e165071ad56c4cf881f5221f02eeefde5de53 (diff) | |
download | kutter-c8af3feee6b35e33ab989ca8af0b48d738d4aedf.tar.gz kutter-c8af3feee6b35e33ab989ca8af0b48d738d4aedf.tar.xz kutter-c8af3feee6b35e33ab989ca8af0b48d738d4aedf.zip |
command: Add a command_encode_and_frame() helper
Add a helper function that calls command_encodef() followed by
command_add_frame().
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r-- | src/avr/usbserial.c | 3 | ||||
-rw-r--r-- | src/command.c | 10 | ||||
-rw-r--r-- | src/command.h | 4 | ||||
-rw-r--r-- | src/generic/serial_irq.c | 3 | ||||
-rw-r--r-- | src/generic/usb_cdc.c | 3 | ||||
-rw-r--r-- | src/linux/console.c | 3 |
6 files changed, 17 insertions, 9 deletions
diff --git a/src/avr/usbserial.c b/src/avr/usbserial.c index 6dbe4f0d..fe378227 100644 --- a/src/avr/usbserial.c +++ b/src/avr/usbserial.c @@ -65,8 +65,7 @@ console_sendf(const struct command_encoder *ce, va_list args) { // Generate message static uint8_t buf[MESSAGE_MAX]; - uint8_t msglen = command_encodef(buf, ce, args); - command_add_frame(buf, msglen); + uint8_t msglen = command_encode_and_frame(buf, ce, args); // Transmit message usb_serial_write((void*)buf, msglen); diff --git a/src/command.c b/src/command.c index 6161a031..965f91ed 100644 --- a/src/command.c +++ b/src/command.c @@ -167,6 +167,16 @@ command_add_frame(uint8_t *buf, uint_fast8_t msglen) buf[msglen - MESSAGE_TRAILER_SYNC] = MESSAGE_SYNC; } +// Encode a message and then add a message block frame around it +uint_fast8_t +command_encode_and_frame(uint8_t *buf, const struct command_encoder *ce + , va_list args) +{ + uint_fast8_t msglen = command_encodef(buf, ce, args); + command_add_frame(buf, msglen); + return msglen; +} + static uint8_t in_sendf; // Encode and transmit a "response" message diff --git a/src/command.h b/src/command.h index dd960cdf..2dd195ea 100644 --- a/src/command.h +++ b/src/command.h @@ -65,8 +65,10 @@ uint8_t *command_parsef(uint8_t *p, uint8_t *maxend , const struct command_parser *cp, uint32_t *args); uint_fast8_t command_encodef(uint8_t *buf, const struct command_encoder *ce , va_list args); -void command_sendf(const struct command_encoder *ce, ...); void command_add_frame(uint8_t *buf, uint_fast8_t msglen); +uint_fast8_t command_encode_and_frame( + uint8_t *buf, const struct command_encoder *ce, va_list args); +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); diff --git a/src/generic/serial_irq.c b/src/generic/serial_irq.c index 7c7842ea..6b682a0f 100644 --- a/src/generic/serial_irq.c +++ b/src/generic/serial_irq.c @@ -108,8 +108,7 @@ console_sendf(const struct command_encoder *ce, va_list args) // Generate message uint8_t *buf = &transmit_buf[tmax]; - uint_fast8_t msglen = command_encodef(buf, ce, args); - command_add_frame(buf, msglen); + uint_fast8_t msglen = command_encode_and_frame(buf, ce, args); // Start message transmit writeb(&transmit_max, tmax + msglen); diff --git a/src/generic/usb_cdc.c b/src/generic/usb_cdc.c index 49bb483e..56a60fac 100644 --- a/src/generic/usb_cdc.c +++ b/src/generic/usb_cdc.c @@ -65,8 +65,7 @@ console_sendf(const struct command_encoder *ce, va_list args) // Generate message uint8_t *buf = &transmit_buf[tpos]; - uint_fast8_t msglen = command_encodef(buf, ce, args); - command_add_frame(buf, msglen); + uint_fast8_t msglen = command_encode_and_frame(buf, ce, args); // Start message transmit transmit_pos = tpos + msglen; diff --git a/src/linux/console.c b/src/linux/console.c index a1086942..9064171f 100644 --- a/src/linux/console.c +++ b/src/linux/console.c @@ -176,8 +176,7 @@ console_sendf(const struct command_encoder *ce, va_list args) { // Generate message uint8_t buf[MESSAGE_MAX]; - uint_fast8_t msglen = command_encodef(buf, ce, args); - command_add_frame(buf, msglen); + uint_fast8_t msglen = command_encode_and_frame(buf, ce, args); // Transmit message int ret = write(main_pfd[MP_TTY_IDX].fd, buf, msglen); |