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.
28 lines
618 B
28 lines
618 B
/*
|
|
* Command.cpp
|
|
*
|
|
* Created on: Jul 8, 2021
|
|
* Author: Andreas Berthoud
|
|
*/
|
|
|
|
#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;
|
|
}
|
|
|