Skip to content

Commit 7f2dc18

Browse files
committed
usb mavlink
1 parent 7246f62 commit 7f2dc18

File tree

5 files changed

+370
-354
lines changed

5 files changed

+370
-354
lines changed

src/madflight/cli/cli.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static const struct cli_print_s cli_print_options[] = {
182182
{"pbar", "Barometer", cli_print_bar},
183183
{"palt", "Altitude estimator", cli_print_alt},
184184
{"pgps", "GPS", cli_print_gps},
185-
{"prdr", "Radar", cli_print_rdr},
185+
{"prdr", "Radar", cli_print_rdr},
186186
};
187187

188188

@@ -194,16 +194,27 @@ void Cli::setup() {
194194

195195
//returns true if a command was processed (even an invalid one)
196196
bool Cli::update() {
197-
//process chars from Serial
198-
bool rv = false;
199-
while(Serial.available()) {
200-
if(cmd_process_char(Serial.read())) rv = true;
201-
}
197+
if(mavlink) {
198+
return mavlink->update();
199+
}else{
200+
//process chars from Serial
201+
bool rv = false;
202+
while(Serial.available()) {
203+
uint8_t c = Serial.read();
204+
if(c == 0xFD || c == 0xFE) { //mavlink v1,v2 protocol header byte
205+
auto ser = &Serial;
206+
MF_Serial *ser_bus = new MF_SerialPtrWrapper<decltype(ser)>( ser );
207+
mavlink = new RclGizmoMavlink(ser_bus, 115200, nullptr);
208+
return false;
209+
}
210+
if(cmd_process_char(c)) rv = true;
211+
}
202212

203-
//handle output for pxxx commands
204-
cli_print_loop();
213+
//handle output for pxxx commands
214+
cli_print_loop();
205215

206-
return rv;
216+
return rv;
217+
}
207218
}
208219

209220
void Cli::begin() {

src/madflight/cli/cli.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ SOFTWARE.
2525
#pragma once
2626

2727
#include <Arduino.h> //String
28+
#include "../rcl/RclGizmoMavlink.h"
2829

2930
//cli command extension, return true if command was processed
3031
extern bool cli_execute(String cmd, String arg1, String arg2) __attribute__((weak));
@@ -97,6 +98,7 @@ class Cli {
9798

9899
void cli_print_all(bool val);
99100
void cli_print_loop();
101+
RclGizmoMavlink* mavlink = nullptr;
100102
};
101103

102104
extern Cli cli;

0 commit comments

Comments
 (0)