You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
915 B
43 lines
915 B
/*
|
|
* Command.cpp
|
|
*
|
|
* Created on: Jul 8, 2021
|
|
* Author: Andreas Berthoud
|
|
*/
|
|
#include <queue>
|
|
|
|
#include "Command.hpp"
|
|
#include "string.h"
|
|
#include "usbd_cdc_if.h"
|
|
|
|
Command::Command(CommandId id) : id(id) {
|
|
this->data[0] = id;
|
|
this->data[3] = 0x00; // reserved
|
|
this->payload_ptr = this->data + 4;
|
|
}
|
|
|
|
void Command::send() {
|
|
uint16_t size = this->payload_length + 5;
|
|
this->data[size-1] = 0xff;
|
|
CDC_Transmit_FS(this->data, size);
|
|
}
|
|
|
|
void Command::set_payload_length(uint16_t payload_length) {
|
|
this->payload_length = payload_length;
|
|
data[1] = (payload_length & 0xFF00) >> 8;
|
|
data[2] = payload_length & 0x00FF;
|
|
}
|
|
|
|
std::queue<Command> command_queue;
|
|
|
|
void push_command(const Command &command) {
|
|
command_queue.push(command);
|
|
}
|
|
|
|
void pop_and_execute_commands() {
|
|
while (!command_queue.empty()) {
|
|
Command command = command_queue.front();
|
|
command.send();
|
|
command_queue.pop();
|
|
}
|
|
}
|
|
|