From f8bd8b97bea9273d166efdc06c3a6a54fc24ffdb Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 13 Aug 2017 16:48:27 -0400 Subject: command: Don't pass max_size to command_encodef() The command_encodef() can read the max_size parameter directly from the 'struct command_encoder' passed into it. Also, there is no need to check that a message will fit in a buffer if the buffer is declared to be MESSAGE_MAX in size. Signed-off-by: Kevin O'Connor --- src/avr/usbserial.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/avr/usbserial.c') diff --git a/src/avr/usbserial.c b/src/avr/usbserial.c index cc7bb12c..ac60e087 100644 --- a/src/avr/usbserial.c +++ b/src/avr/usbserial.c @@ -1,20 +1,17 @@ // Wrappers for AVR usb serial. // -// Copyright (C) 2016 Kevin O'Connor +// Copyright (C) 2016,2017 Kevin O'Connor // // This file may be distributed under the terms of the GNU GPLv3 license. -#include // USART0_RX_vect #include // memmove #include "../lib/pjrc_usb_serial/usb_serial.h" +#include "board/misc.h" // console_sendf #include "command.h" // command_dispatch -#include "pgm.h" // READP #include "sched.h" // DECL_INIT -#define USBSERIAL_BUFFER_SIZE 64 -static char receive_buf[USBSERIAL_BUFFER_SIZE]; +static char receive_buf[MESSAGE_MAX]; static uint8_t receive_pos; -static char transmit_buf[USBSERIAL_BUFFER_SIZE]; void usbserial_init(void) @@ -68,13 +65,11 @@ void console_sendf(const struct command_encoder *ce, va_list args) { // Generate message - uint8_t max_size = READP(ce->max_size); - if (max_size > sizeof(transmit_buf)) - return; - uint8_t msglen = command_encodef(transmit_buf, max_size, ce, args); - command_add_frame(transmit_buf, msglen); + static char buf[MESSAGE_MAX]; + uint8_t msglen = command_encodef(buf, ce, args); + command_add_frame(buf, msglen); // Transmit message - usb_serial_write((void*)transmit_buf, msglen); + usb_serial_write((void*)buf, msglen); usb_serial_flush_output(); } -- cgit v1.2.3-70-g09d2