-
Notifications
You must be signed in to change notification settings - Fork 1
/
RepeaterTask.hpp
75 lines (58 loc) · 2.68 KB
/
RepeaterTask.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
******************************************************************************
* File Name : RepeaterTask.hpp
* Description :
******************************************************************************
*/
#ifndef SOAR_SYSTEM_PROTOCOL_REPEATER_HPP_
#define SOAR_SYSTEM_PROTOCOL_REPEATER_HPP_
/* Includes ------------------------------------------------------------------*/
#include "Task.hpp"
#include "SystemDefines.hpp"
#include "UARTTask.hpp"
#include "WriteBufferFixedSize.h"
#include "CoreProto.h"
#include "ControlMessage.hpp"
#include "ProtocolTask.hpp"
/* Enums ------------------------------------------------------------------*/
enum REPEATER_TASK_COMMANDS {
REPEATER_TASK_COMMAND_NONE = 0,
EVENT_REPEATER_RX_COMPLETE = PROTOCOL_TX_REQUEST_DATA + 1 // We start after Protocol Task Commands
};
/* Macros ------------------------------------------------------------------*/
// Task Definition
constexpr uint8_t TASK_REPEATER_PRIORITY = 2; // Priority of the repeater task
constexpr uint8_t TASK_REPEATER_QUEUE_DEPTH_OBJS = 10; // Size of the repeater task queue
constexpr uint16_t TASK_REPEATER_STACK_DEPTH_WORDS = 300; // Size of the repeater task stack
/* Class ------------------------------------------------------------------*/
class RepeaterTask : public Task, public UARTReceiverBase
{
public:
RepeaterTask(UARTDriver* uartDriver, uint16_t uartTaskCmd);
virtual void InitTask() = 0;
//Public Interfaces
// Sends data to the linked UART. Does not wrap in transport layer, use SendProtobufMessage for messages not already wrapped
inline void SendData(uint8_t* data, uint16_t size);
// Sends a protobuf message to the linked UART. Wraps in transport layer, does processing in the calling task
void SendProtobufMessage(EmbeddedProto::WriteBufferFixedSize<DEFAULT_PROTOCOL_WRITE_BUFFER_SIZE>& writeBuffer, Proto::MessageID msgId);
//Functions exposed to HAL callbacks
void InterruptRxData(uint8_t errors);
protected:
void Run(void* pvParams); // Main run code
bool ReceiveData(); // Arms the UART to receive data
// Member variables
uint8_t* protocolRxBuffer;
uint16_t protocolMsgIdx;
bool isProtocolMsgReady;
uint8_t protocolRxChar; // Character received from UART Interrupt
UARTDriver* const kUart_;
const uint16_t uartTaskCommand;
};
inline void RepeaterTask::SendData(uint8_t* data, uint16_t size)
{
Command cm(DATA_COMMAND, uartTaskCommand);
cm.CopyDataToCommand(data, size);
// Send it to the UART task using the task's registered uartTaskCommand
UARTTask::Inst().SendCommandReference(cm);
}
#endif // SOAR_SYSTEM_PROTOCOL_REPEATER_TASK_HPP_