/* * Notification.cpp * * Created on: Jul 14, 2021 * Author: Andreas Berthoud */ #include "usbd_cdc_if.h" #include "Notification.hpp" Notification::Notification() { this->payload_ptr = this->data +4; } bool Notification::execute() { uint16_t size = NOTIFICATION_COMMAND_TOTAL_OVERHEAD + this->payload_size; this->data[0] = (uint8_t)this->get_command_id(); this->data[1] = (this->payload_size & 0xFF00) >> 8; this->data[2] = this->payload_size & 0x00FF; this->data[3] = 0x00; // reserved this->data[size-1] = 0xff; // set stop byte uint8_t result = CDC_Transmit_FS(this->data, size); return result == USBD_OK || result == USBD_BUSY; } uint16_t Notification::get_payload_size() { return this->payload_size; } void Notification::add_to_payload_size(uint16_t size) { this->payload_size += size; }