Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Stm32RailcomSender.cxx
1
38
39#include "stm32f_hal_conf.hxx"
40
43{
44 const auto* pkt = ch1Pkt_;
45 if (!pkt || pkt->feedbackKey != expectedFeedbackKey_)
46 {
47 // Nothing to send or came too late and should not be sent.
48 return;
49 }
50 if (!__HAL_UART_GET_IT(&uartHandle, UART_IT_TXE)) {
51 // Transmission is not complete yet. That's weird.
52 return;
53 }
54 if (pkt->ch1Size == 0) {
55 // Nothing to send.
56 return;
57 }
58 uartHandle.Instance->TDR = pkt->ch1Data[0];
59 if (pkt->ch1Size > 1)
60 {
61 txBuf->put(pkt->ch1Data + 1, 1);
62 __HAL_UART_ENABLE_IT(&uartHandle, UART_IT_TXE);
63 }
64}
65
67{
68 const auto* pkt = ch2Pkt_;
69 if (!pkt || pkt->feedbackKey != expectedFeedbackKey_)
70 {
71 // Nothing to send or came too late and should not be sent.
72 return;
73 }
74 if (!__HAL_UART_GET_IT(&uartHandle, UART_IT_TXE)) {
75 // Transmission is not complete yet. That's weird.
76 return;
77 }
78 if (pkt->ch2Size == 0) {
79 // Nothing to send.
80 return;
81 }
82 uartHandle.Instance->TDR = pkt->ch2Data[0];
83 if (pkt->ch2Size > 1)
84 {
85 txBuf->put(pkt->ch2Data + 1, pkt->ch2Size - 1);
86 __HAL_UART_ENABLE_IT(&uartHandle, UART_IT_TXE);
87 }
88}
size_t put(const T *buf, size_t items)
Insert a number of items to the buffer.
DeviceBuffer< uint8_t > * txBuf
transmit buffer
Definition Serial.hxx:84
uintptr_t expectedFeedbackKey_
What should be the feedback key in the packet.
void start_cutout() override
Called at the beginning of the first window.
const DCCFeedback * ch1Pkt_
The packet to send in channel 1. Externally owned.
void middle_cutout() override
Called at the beginning of the middle window.
const DCCFeedback * ch2Pkt_
The packet to send in channel 2. Externally owned.
UART_HandleTypeDef uartHandle
Handle to the UART setup.
uint8_t ch1Data[2]
Payload of channel 1.
Definition railcom.h:47
uint8_t ch2Data[6]
Payload of channel 2.
Definition railcom.h:51