@@ -78,33 +78,32 @@ void AP_Periph_FW::handle_tunnel_Targetted(CanardInstance* canard_ins, CanardRxT
78
78
if (pkt.target_node != canardGetLocalNodeID (canard_ins)) {
79
79
return ;
80
80
}
81
- if (uart_monitor.buffer == nullptr ) {
82
- uart_monitor.buffer = NEW_NOTHROW ByteBuffer (1024 );
83
- if (uart_monitor.buffer == nullptr ) {
84
- return ;
85
- }
86
- }
87
81
int8_t uart_num = pkt.serial_id ;
88
82
if (uart_num == -1 ) {
89
83
uart_num = get_default_tunnel_serial_port ();
90
84
}
91
85
if (uart_num < 0 ) {
92
86
return ;
93
87
}
94
- auto *uart = hal.serial (uart_num);
95
- if (uart == nullptr ) {
88
+ if (uint8_t (uart_num) > ARRAY_SIZE (uart_monitors)) {
96
89
return ;
97
90
}
98
- if (uart_monitor.uart_num != uart_num && uart_monitor.uart != nullptr ) {
99
- // remove monitor from previous uart
100
- hal.serial (uart_monitor.uart_num )->set_monitor_read_buffer (nullptr );
101
- }
102
- uart_monitor.uart_num = uart_num;
103
- if (uart != uart_monitor.uart ) {
104
- // change of uart or expired, clear old data
105
- uart_monitor.buffer ->clear ();
106
- uart_monitor.uart = uart;
91
+ auto &uart_monitor = uart_monitors[uart_num];
92
+ if (uart_monitor.uart == nullptr ) {
93
+ auto *uart = hal.serial (uart_num);
94
+ if (uart == nullptr ) {
95
+ return ;
96
+ }
97
+ if (uart_monitor.buffer == nullptr ) {
98
+ uart_monitor.buffer = NEW_NOTHROW ByteBuffer (1024 );
99
+ if (uart_monitor.buffer == nullptr ) {
100
+ return ;
101
+ }
102
+ uart_monitor.uart_num = uart_num;
103
+ }
107
104
uart_monitor.baudrate = 0 ;
105
+ uart_monitor.uart = uart; // setting this indicates the monitor is set up
106
+ uart_monitor.uart ->set_monitor_read_buffer (uart_monitor.buffer );
108
107
}
109
108
if (uart_monitor.uart == nullptr ) {
110
109
return ;
@@ -130,7 +129,6 @@ void AP_Periph_FW::handle_tunnel_Targetted(CanardInstance* canard_ins, CanardRxT
130
129
}
131
130
uart_monitor.baudrate = pkt.baudrate ;
132
131
}
133
- uart_monitor.uart ->set_monitor_read_buffer (uart_monitor.buffer );
134
132
uart_monitor.last_request_ms = AP_HAL::millis ();
135
133
136
134
// write to device
@@ -150,6 +148,13 @@ void AP_Periph_FW::handle_tunnel_Targetted(CanardInstance* canard_ins, CanardRxT
150
148
send tunnelled serial data
151
149
*/
152
150
void AP_Periph_FW::send_serial_monitor_data ()
151
+ {
152
+ for (auto &m : uart_monitors) {
153
+ send_serial_monitor_data_instance (m);
154
+ }
155
+ }
156
+
157
+ void AP_Periph_FW::send_serial_monitor_data_instance (AP_Periph_FW::UARTMonitor &uart_monitor)
153
158
{
154
159
if (uart_monitor.uart == nullptr ||
155
160
uart_monitor.node_id == 0 ||
0 commit comments