2014-12-16 19:28:56 -04:00
|
|
|
//
|
|
|
|
// Simple test for the GCS_MAVLink routing
|
|
|
|
//
|
|
|
|
|
2015-08-11 03:28:46 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <GCS_MAVLink/GCS.h>
|
2015-10-20 10:05:13 -03:00
|
|
|
#include <GCS_MAVLink/GCS_MAVLink.h>
|
2014-12-16 19:28:56 -04:00
|
|
|
|
2017-04-13 08:33:33 -03:00
|
|
|
void setup();
|
|
|
|
void loop();
|
|
|
|
|
2015-10-16 17:22:11 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
2014-12-16 19:28:56 -04:00
|
|
|
|
2018-06-13 07:29:52 -03:00
|
|
|
const AP_FWVersion AP_FWVersion::fwver
|
2017-08-18 20:07:42 -03:00
|
|
|
{
|
|
|
|
major: 3,
|
|
|
|
minor: 1,
|
|
|
|
patch: 4,
|
|
|
|
fw_type: FIRMWARE_VERSION_TYPE_DEV,
|
|
|
|
fw_string: "routing example"
|
|
|
|
};
|
|
|
|
|
2016-05-27 21:56:07 -03:00
|
|
|
class GCS_MAVLINK_routing : public GCS_MAVLINK
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2016-07-01 02:35:49 -03:00
|
|
|
uint32_t telem_delay() const override { return 0; }
|
2017-07-16 21:46:54 -03:00
|
|
|
Compass *get_compass() const override { return nullptr; };
|
2017-07-08 06:09:06 -03:00
|
|
|
AP_Mission *get_mission() override { return nullptr; }
|
2017-07-12 21:20:45 -03:00
|
|
|
AP_Rally *get_rally() const override { return nullptr; }
|
2017-07-26 02:48:01 -03:00
|
|
|
AP_Camera *get_camera() const override { return nullptr; };
|
2017-07-12 04:21:15 -03:00
|
|
|
uint8_t sysid_my_gcs() const override { return 1; }
|
2017-08-11 02:52:09 -03:00
|
|
|
bool set_mode(uint8_t mode) override { return false; };
|
2016-05-29 20:54:11 -03:00
|
|
|
|
2018-03-22 05:49:33 -03:00
|
|
|
// dummy information:
|
|
|
|
MAV_TYPE frame_type() const override { return MAV_TYPE_FIXED_WING; }
|
|
|
|
MAV_MODE base_mode() const override { return (MAV_MODE)MAV_MODE_FLAG_CUSTOM_MODE_ENABLED; }
|
|
|
|
uint32_t custom_mode() const override { return 3; } // magic number
|
|
|
|
MAV_STATE system_status() const override { return MAV_STATE_CALIBRATING; }
|
|
|
|
|
2016-05-27 21:56:07 -03:00
|
|
|
private:
|
|
|
|
|
|
|
|
void handleMessage(mavlink_message_t * msg) { }
|
|
|
|
bool handle_guided_request(AP_Mission::Mission_Command &cmd) override { return false ; }
|
|
|
|
void handle_change_alt_request(AP_Mission::Mission_Command &cmd) override { }
|
|
|
|
bool try_send_message(enum ap_message id) override { return false; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-12-16 19:28:56 -04:00
|
|
|
static const uint8_t num_gcs = MAVLINK_COMM_NUM_BUFFERS;
|
2016-05-30 07:05:00 -03:00
|
|
|
static GCS_MAVLINK_routing gcs_link[MAVLINK_COMM_NUM_BUFFERS];
|
2014-12-16 19:28:56 -04:00
|
|
|
|
|
|
|
extern mavlink_system_t mavlink_system;
|
|
|
|
|
2015-10-25 14:03:46 -03:00
|
|
|
const AP_Param::GroupInfo GCS_MAVLINK::var_info[] = {
|
2014-12-16 19:28:56 -04:00
|
|
|
AP_GROUPEND
|
|
|
|
};
|
|
|
|
|
|
|
|
static MAVLink_routing routing;
|
|
|
|
|
|
|
|
void setup(void)
|
|
|
|
{
|
2016-05-30 07:05:00 -03:00
|
|
|
hal.console->printf("routing test startup...");
|
|
|
|
gcs_link[0].init(hal.uartA, MAVLINK_COMM_0);
|
2014-12-16 19:28:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop(void)
|
|
|
|
{
|
|
|
|
uint16_t err_count = 0;
|
|
|
|
|
|
|
|
// incoming heartbeat
|
|
|
|
mavlink_message_t msg;
|
|
|
|
mavlink_heartbeat_t heartbeat = {0};
|
|
|
|
|
|
|
|
mavlink_msg_heartbeat_encode(3, 1, &msg, &heartbeat);
|
|
|
|
|
|
|
|
if (!routing.check_and_forward(MAVLINK_COMM_0, &msg)) {
|
|
|
|
hal.console->printf("heartbeat should be processed locally\n");
|
|
|
|
err_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// incoming non-targetted message
|
|
|
|
mavlink_attitude_t attitude = {0};
|
|
|
|
mavlink_msg_attitude_encode(3, 1, &msg, &attitude);
|
|
|
|
if (!routing.check_and_forward(MAVLINK_COMM_0, &msg)) {
|
|
|
|
hal.console->printf("attitude should be processed locally\n");
|
|
|
|
err_count++;
|
|
|
|
}
|
|
|
|
|
2016-05-12 13:51:11 -03:00
|
|
|
// incoming targeted message for someone else
|
2014-12-16 19:28:56 -04:00
|
|
|
mavlink_param_set_t param_set = {0};
|
|
|
|
param_set.target_system = mavlink_system.sysid+1;
|
|
|
|
param_set.target_component = mavlink_system.compid;
|
|
|
|
mavlink_msg_param_set_encode(3, 1, &msg, ¶m_set);
|
|
|
|
if (routing.check_and_forward(MAVLINK_COMM_0, &msg)) {
|
|
|
|
hal.console->printf("param set 1 should not be processed locally\n");
|
|
|
|
err_count++;
|
|
|
|
}
|
|
|
|
|
2016-05-12 13:51:11 -03:00
|
|
|
// incoming targeted message for us
|
2014-12-16 19:28:56 -04:00
|
|
|
param_set.target_system = mavlink_system.sysid;
|
|
|
|
param_set.target_component = mavlink_system.compid;
|
|
|
|
mavlink_msg_param_set_encode(3, 1, &msg, ¶m_set);
|
|
|
|
if (!routing.check_and_forward(MAVLINK_COMM_0, &msg)) {
|
|
|
|
hal.console->printf("param set 2 should be processed locally\n");
|
|
|
|
err_count++;
|
|
|
|
}
|
|
|
|
|
2016-05-12 13:51:11 -03:00
|
|
|
// incoming targeted message for our system, but other compid
|
2014-12-16 19:28:56 -04:00
|
|
|
// should be processed locally
|
|
|
|
param_set.target_system = mavlink_system.sysid;
|
|
|
|
param_set.target_component = mavlink_system.compid+1;
|
|
|
|
mavlink_msg_param_set_encode(3, 1, &msg, ¶m_set);
|
|
|
|
if (!routing.check_and_forward(MAVLINK_COMM_0, &msg)) {
|
|
|
|
hal.console->printf("param set 3 should be processed locally\n");
|
|
|
|
err_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// incoming broadcast message should be processed locally
|
|
|
|
param_set.target_system = 0;
|
|
|
|
param_set.target_component = mavlink_system.compid+1;
|
|
|
|
mavlink_msg_param_set_encode(3, 1, &msg, ¶m_set);
|
|
|
|
if (!routing.check_and_forward(MAVLINK_COMM_0, &msg)) {
|
|
|
|
hal.console->printf("param set 4 should be processed locally\n");
|
|
|
|
err_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err_count == 0) {
|
|
|
|
hal.console->printf("All OK\n");
|
|
|
|
}
|
|
|
|
hal.scheduler->delay(1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
AP_HAL_MAIN();
|