/* * GPCommand.cpp * * Created on: Jul 18, 2021 * Author: Andreas Berthoud */ #include "GPCommand.hpp" #include "app_ble.h" GPResponse::GPResponse(uint16_t response_identifier, bool was_successful) : Response(response_identifier) { (this->payload_ptr + this->get_payload_size())[0] = (uint8_t)was_successful; this->add_to_payload_size(1); } GPRequest::GPRequest(uint8_t * payload_ptr, uint16_t size) : Request(payload_ptr, size) { uint16_t expected_length = this->buffer_offset + 1; if (expected_length != size) { this->has_error = true; return; } uint8_t * data_ptr = payload_ptr + this->buffer_offset; this->command_id = data_ptr[0]; } GPResponse * GPRequest::execute_request(uint16_t response_identifier) { bool was_successful = true; if (this->has_error) { was_successful = false; } else { switch (this->command_id) { case 1: APP_BLE_Key_Button1_Action(); break; default: break; } } return new GPResponse(response_identifier, was_successful); }