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.
34 lines
834 B
34 lines
834 B
/*
|
|
* 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;
|
|
}
|