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.
42 lines
1.1 KiB
42 lines
1.1 KiB
/*
|
|
* Notification.cpp
|
|
*
|
|
* Created on: Jul 14, 2021
|
|
* Author: Andreas Berthoud
|
|
*/
|
|
|
|
#include "usbd_cdc_if.h"
|
|
#include "Notification.hpp"
|
|
#include "ble_cmd_mbx.h"
|
|
|
|
|
|
Notification::Notification(com_channel_type_t com_channel_type)
|
|
: Command(), com_channel_type(com_channel_type) {
|
|
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
|
|
|
|
if (this->com_channel_type == com_channel_type_usb) {
|
|
uint8_t result = CDC_Transmit_FS(this->data, size);
|
|
return result == USBD_OK || result == USBD_BUSY;
|
|
} else {
|
|
push_ble_command(this->data, size);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
uint16_t Notification::get_payload_size() {
|
|
return this->payload_size;
|
|
}
|
|
|
|
void Notification::add_to_payload_size(uint16_t size) {
|
|
this->payload_size += size;
|
|
}
|
|
|