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.
51 lines
1.2 KiB
51 lines
1.2 KiB
/*
|
|
* GPCommand.cpp
|
|
*
|
|
* Created on: Jul 18, 2021
|
|
* Author: Andreas Berthoud
|
|
*/
|
|
|
|
#include "GPCommand.hpp"
|
|
|
|
#include "app_conf.h"
|
|
#include "stm32_seq.h"
|
|
|
|
|
|
GPResponse::GPResponse(com_channel_type_t com_channel_type, uint16_t response_identifier, bool was_successful)
|
|
: Response(com_channel_type, response_identifier) {
|
|
(this->payload_ptr + this->get_payload_size())[0] = (uint8_t)was_successful;
|
|
this->add_to_payload_size(1);
|
|
}
|
|
|
|
GPRequest::GPRequest(com_channel_type_t com_channel_type, uint8_t * payload_ptr, uint16_t size)
|
|
: Request(com_channel_type, 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(com_channel_type_t com_channel_type, uint16_t response_identifier) {
|
|
bool was_successful = true;
|
|
|
|
if (this->has_error) {
|
|
was_successful = false;
|
|
} else {
|
|
switch (this->command_id)
|
|
{
|
|
case 1:
|
|
UTIL_SEQ_SetTask(1<<CFG_TASK_SW1_BUTTON_PUSHED_ID, CFG_SCH_PRIO_0);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return new GPResponse(com_channel_type, response_identifier, was_successful);
|
|
}
|
|
|
|
|