2012-09-18 15:09:08 -03:00
|
|
|
// -*- Mode: C++; c-basic-offset: 8; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
//
|
|
|
|
// Example code for the AP_HAL AVRUARTDriver, based on FastSerial
|
|
|
|
//
|
|
|
|
// This code is placed into the public domain.
|
|
|
|
//
|
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Progmem/AP_Progmem.h>
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_HAL_AVR/AP_HAL_AVR.h>
|
2012-09-18 15:09:08 -03:00
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
|
|
|
#include <AP_Mission/AP_Mission.h>
|
|
|
|
#include <StorageManager/StorageManager.h>
|
|
|
|
#include <AP_Terrain/AP_Terrain.h>
|
|
|
|
#include <GCS_Console/GCS_Console.h>
|
2012-09-18 15:09:08 -03:00
|
|
|
|
|
|
|
#include "simplegcs.h"
|
|
|
|
|
2012-12-18 21:26:58 -04:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL_BOARD_DRIVER;
|
2012-09-18 15:09:08 -03:00
|
|
|
|
|
|
|
void flush_console_to_statustext() {
|
|
|
|
uint8_t data[50];
|
|
|
|
int n = hal.console->backend_read(data, 50);
|
|
|
|
if (n > 0) {
|
|
|
|
try_send_statustext(MAVLINK_COMM_0, (char*) data, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-18 21:18:50 -03:00
|
|
|
void console_loopback() {
|
|
|
|
int a = hal.console->available();
|
|
|
|
if (a > 0) {
|
|
|
|
hal.console->print("Console loopback:");
|
|
|
|
int r = hal.console->read();
|
|
|
|
while (r > 0) {
|
|
|
|
hal.console->write( (uint8_t) r );
|
|
|
|
r = hal.console->read();
|
|
|
|
}
|
|
|
|
hal.console->println();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-18 15:09:08 -03:00
|
|
|
void setup(void) {
|
2012-12-04 18:22:00 -04:00
|
|
|
/* Allocate large enough buffers on uartA to support mavlink */
|
|
|
|
hal.uartA->begin(115200, 128, 256);
|
2012-09-18 15:09:08 -03:00
|
|
|
|
|
|
|
/* Setup GCS_Mavlink library's comm 0 port. */
|
2015-05-15 02:40:47 -03:00
|
|
|
mavlink_comm_port[0] = hal.uartA;
|
2012-09-18 15:09:08 -03:00
|
|
|
|
|
|
|
char hello[] = "Hello statustext\r\n";
|
|
|
|
try_send_statustext(MAVLINK_COMM_0, hello, strlen(hello));
|
|
|
|
|
|
|
|
hal.console->backend_open();
|
|
|
|
hal.console->printf_P(PSTR("Hello hal.console\r\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
void loop(void) {
|
|
|
|
try_send_message(MAVLINK_COMM_0, MAVLINK_MSG_ID_HEARTBEAT);
|
|
|
|
simplegcs_update(MAVLINK_COMM_0);
|
2012-09-18 21:18:50 -03:00
|
|
|
// flush_console_to_statustext();
|
|
|
|
gcs_console_send(MAVLINK_COMM_0);
|
|
|
|
|
|
|
|
console_loopback();
|
|
|
|
hal.scheduler->delay(100);
|
2012-09-18 15:09:08 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
AP_HAL_MAIN();
|