Ghost protocol

ghst: add ghost protocol
This commit is contained in:
jciberlin
2021-02-20 11:29:57 +01:00
committed by Lorenz Meier
parent 711a69854b
commit 64342f568d
12 changed files with 781 additions and 32 deletions
+85
View File
@@ -0,0 +1,85 @@
/****************************************************************************
*
* Copyright (c) 2021 PX4 Development Team. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name PX4 nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/**
* @file ghst_telemetry.cpp
*
* IRC Ghost (Immersion RC Ghost) telemetry.
*
* @author Igor Misic <igy1000mb@gmail.com>
* @author Juraj Ciberlin <jciberlin1@gmail.com>
*/
#include "ghst_telemetry.h"
#include <lib/rc/ghst.h>
GHSTTelemetry::GHSTTelemetry(int uart_fd) :
_uart_fd(uart_fd)
{
}
bool GHSTTelemetry::update(const hrt_abstime &now)
{
const int update_rate_hz = 10;
if (now - _last_update <= 1_s / (update_rate_hz * num_data_types)) {
return false;
}
bool sent = false;
switch (_next_type) {
case 0:
sent = send_battery_status();
break;
}
_last_update = now;
_next_type = (_next_type + 1) % num_data_types;
return sent;
}
bool GHSTTelemetry::send_battery_status()
{
battery_status_s battery_status;
if (!_battery_status_sub.update(&battery_status)) {
return false;
}
uint16_t voltage = battery_status.voltage_filtered_v * 10;
uint16_t current = battery_status.current_filtered_a * 10;
uint16_t fuel = battery_status.discharged_mah;
return ghst_send_telemetry_battery(_uart_fd, voltage, current, fuel);
}