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>
This commit is contained in:
parent
cb4e165071
commit
c8af3feee6
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue