Paparazzi UAS v7.1_unstable
Paparazzi is a free software Unmanned Aircraft System.
Loading...
Searching...
No Matches
can_fuelcell.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 Freek van Tienen <freek.v.tienen@gmail.com>
3 *
4 * This file is part of paparazzi
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, see
18 * <http://www.gnu.org/licenses/>.
19 */
20
26
29#include "uavcan/uavcan.h"
30#include "pprz.equipment.fuelcell.Status.h"
31
32/* Fuel-Cell */
46static struct uavcan_equipment_fuelcell can_fuelcell_data = { 0, 67, 0.78, 45.9, 1457.0, 1234.0, -223.0, 2, 12, 7};
47
48#if !(USE_NPS)
49
50/* CAN feedback */
52
53static void fuelcell_uavcan_cb(struct uavcan_iface_t *iface __attribute__((unused)), CanardRxTransfer *transfer)
54{
55
56 struct pprz_equipment_fuelcell_Status msg;
57 if(pprz_equipment_fuelcell_Status_decode(transfer, &msg)) {
58 return; // decode error
59 }
60
61 can_fuelcell_data.pressure = msg.tank_pressure;
62 can_fuelcell_data.press_reg = msg.regulated_pressure / 100.0f;
63 can_fuelcell_data.volt_bat = msg.battery_voltage / 10.0f;
64 can_fuelcell_data.power_out = msg.output_power;
65 can_fuelcell_data.power_cell = msg.spm_power;
66 can_fuelcell_data.power_batt = msg.battery_power;
67 can_fuelcell_data.state = msg.psu_state;
68 can_fuelcell_data.error = msg.error_code;
69 can_fuelcell_data.suberror = msg.sub_code;
70
71 can_fuelcell_data.timeout = 10;
72
73}
74#endif
75
76
77extern void can_fuelcell_periodic(void)
78{
79#if USE_NPS
80 // Simulate data
81 can_fuelcell_data.timeout = 10;
82#endif
83 if (can_fuelcell_data.timeout > 0) {
84 can_fuelcell_data.timeout--;
85 }
86}
87
88
89
90#if PERIODIC_TELEMETRY
92
93static void can_fuelcell_send_telemetry(struct transport_tx *trans, struct link_device *dev)
94{
95 if (can_fuelcell_data.timeout > 0) {
96 // Forward
97 pprz_msg_send_FUELCELL(trans, dev, AC_ID, &can_fuelcell_data.pressure, &can_fuelcell_data.press_reg,
98 &can_fuelcell_data.volt_bat, &can_fuelcell_data.power_out, &can_fuelcell_data.power_cell,
99 &can_fuelcell_data.power_batt, &can_fuelcell_data.state, &can_fuelcell_data.error, &can_fuelcell_data.suberror);
100 }
101}
102#endif /* PERIODIC_TELEMETRY */
103
104
105
107{
108#if !(USE_NPS)
109
110 // Bind uavcan BATTERYINFO message from EQUIPMENT.POWER
111 uavcan_bind(PPRZ_EQUIPMENT_FUELCELL_STATUS_ID, PPRZ_EQUIPMENT_FUELCELL_STATUS_SIGNATURE, &fuelcell_uavcan_ev,
113#endif
114
115
116 // Configure telemetry
117#if PERIODIC_TELEMETRY
119#endif
120
121
122}
void can_fuelcell_periodic(void)
void can_fuelcell_init(void)
static uavcan_event fuelcell_uavcan_ev
static struct uavcan_equipment_fuelcell can_fuelcell_data
static void can_fuelcell_send_telemetry(struct transport_tx *trans, struct link_device *dev)
static void fuelcell_uavcan_cb(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
static struct uart_periph * dev
int16_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint16_t _id, telemetry_cb _cb)
Register a telemetry callback function.
Definition telemetry.c:51
Periodic telemetry system header (includes downlink utility and generated code).
#define DefaultPeriodic
Set default periodic telemetry.
Definition telemetry.h:66
void uavcan_bind(uint16_t data_type_id, uint64_t data_type_signature, uavcan_event *ev, uavcan_callback cb)
Bind to a receiving message from uavcan.
Definition uavcan.c:272
struct uavcan_event_t uavcan_event
Definition uavcan.h:98
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
int transfer(const Mat *from, const image_t *to)