9 changed files with 107 additions and 30 deletions
@ -0,0 +1,30 @@ |
|||||
|
/*
|
||||
|
* 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) { |
||||
|
|
||||
|
CDC_Transmit_FS(buf, *len); // echo
|
||||
|
|
||||
|
if (*len < 5) { |
||||
|
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]; |
||||
|
} |
||||
|
|
||||
|
log_debug("received command, id: 0x%x", 1, command_id); |
||||
|
log_debug("length: %n", 1, length); |
||||
|
log_debug("stop_byte: 0x%x", 1, stop_byte); |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
/*
|
||||
|
* commands.hpp |
||||
|
* |
||||
|
* Created on: Jul 13, 2021 |
||||
|
* Author: Andreas Berthoud |
||||
|
*/ |
||||
|
|
||||
|
#ifndef COMMANDS_HPP_ |
||||
|
#define COMMANDS_HPP_ |
||||
|
|
||||
|
extern "C" void log_debug(const char * format, int nargs, ...); |
||||
|
extern "C" void log_info(const char * format, int nargs, ...); |
||||
|
extern "C" void log_warning(const char * format, int nargs, ...); |
||||
|
extern "C" void log_error(const char * format, int nargs, ...); |
||||
|
|
||||
|
#endif /* COMMANDS_HPP_ */ |
||||
Loading…
Reference in new issue