/* * command_interpreter.c * * Created on: Jul 10, 2021 * Author: Andreas Berthoud */ #include "usbd_cdc_if.h" #include "commands.h" void usb_receive(uint8_t *buf, uint32_t *len) { if (*len < 5) { log_error("usb_receive", "received command which cannot be interpreted", 0); return; } uint8_t command_id = buf[0]; uint16_t length = buf[1] << 8 | buf[2]; uint8_t * payload_ptr = buf + 4; uint8_t stop_byte = 0x1; if (*len >= 4 + length) { stop_byte = buf[4+ length]; } if (stop_byte != 0xFF) { log_error("usb_receive", "received command has invalid stop byte: 0x%x", 1, stop_byte); } else { handle_received_usb_command(command_id, payload_ptr, length); } }