Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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 
29 #include "uavcan/uavcan.h"
30 
31 
32 /* uavcan EQUIPMENT_ESC_STATUS message definition */
33 #define UAVCAN_EQUIPMENT_FUELCELL_STATUS_MAX_SIZE 11
34 #define UAVCAN_EQUIPMENT_FUELCELL_STATUS_SIGNATURE (0x475459FF3AA36FE5ULL)
35 #define UAVCAN_EQUIPMENT_FUELCELL_STATUS_ID 1141
36 
37 
38 /* Fuel-Cell */
40  int timeout;
41 
43  float press_reg;
44  float volt_bat;
45  float power_out;
46  float power_cell;
47  float power_batt;
51 };
52 static struct uavcan_equipment_fuelcell can_fuelcell_data = { 0, 67, 0.78, 45.9, 1457.0, 1234.0, -223.0, 2, 12, 7};
53 
54 #if !(USE_NPS)
55 
56 /* CAN feedback */
58 
59 static void fuelcell_uavcan_cb(struct uavcan_iface_t *iface __attribute__((unused)), CanardRxTransfer *transfer)
60 {
61 
62  uint32_t bit_ofs = 0;
63  canardDecodeScalar(transfer, bit_ofs, 7, false, &can_fuelcell_data.pressure);
64  bit_ofs += 7;
65  uint16_t temp = 0;
66  canardDecodeScalar(transfer, bit_ofs, 8, false, &temp);
67  can_fuelcell_data.press_reg = ((float) temp) / 100.0f;
68  bit_ofs += 8;
69  temp = 0;
70  canardDecodeScalar(transfer, bit_ofs, 10, false, &temp);
71  can_fuelcell_data.volt_bat = ((float) temp) / 10.0f;
72  bit_ofs += 10;
73  temp = 0;
74  canardDecodeScalar(transfer, bit_ofs, 14, false, &temp);
75  can_fuelcell_data.power_out = ((float) temp);
76  bit_ofs += 14;
77  temp = 0;
78  canardDecodeScalar(transfer, bit_ofs, 13, false, &temp);
79  can_fuelcell_data.power_cell = ((float) temp);
80  bit_ofs += 13;
81  int16_t temp2 = 0;
82  canardDecodeScalar(transfer, bit_ofs, 16, true, &temp2);
83  can_fuelcell_data.power_batt = ((float) temp2);
84  bit_ofs += 16;
85  canardDecodeScalar(transfer, bit_ofs, 4, false, &can_fuelcell_data.state);
86  bit_ofs += 4;
87  canardDecodeScalar(transfer, bit_ofs, 8, false, &can_fuelcell_data.error);
88  bit_ofs += 8;
89  canardDecodeScalar(transfer, bit_ofs, 8, false, &can_fuelcell_data.suberror);
90  bit_ofs += 8;
91 
93 
94 }
95 #endif
96 
97 
98 extern void can_fuelcell_periodic(void)
99 {
100 #if USE_NPS
101  // Simulate data
103 #endif
104  if (can_fuelcell_data.timeout > 0) {
106  }
107 }
108 
109 
110 
111 #if PERIODIC_TELEMETRY
113 
114 static void can_fuelcell_send_telemetry(struct transport_tx *trans, struct link_device *dev)
115 {
116  if (can_fuelcell_data.timeout > 0) {
117  // Forward
118  pprz_msg_send_FUELCELL(trans, dev, AC_ID, &can_fuelcell_data.pressure, &can_fuelcell_data.press_reg,
121  }
122 }
123 #endif /* PERIODIC_TELEMETRY */
124 
125 
126 
128 {
129 #if !(USE_NPS)
130 
131  // Bind uavcan BATTERYINFO message from EQUIPMENT.POWER
134 #endif
135 
136 
137  // Configure telemetry
138 #if PERIODIC_TELEMETRY
140 #endif
141 
142 
143 }
void can_fuelcell_periodic(void)
Definition: can_fuelcell.c:98
void can_fuelcell_init(void)
Definition: can_fuelcell.c:127
#define UAVCAN_EQUIPMENT_FUELCELL_STATUS_ID
Definition: can_fuelcell.c:35
static uavcan_event fuelcell_uavcan_ev
Definition: can_fuelcell.c:57
static struct uavcan_equipment_fuelcell can_fuelcell_data
Definition: can_fuelcell.c:52
static void can_fuelcell_send_telemetry(struct transport_tx *trans, struct link_device *dev)
Definition: can_fuelcell.c:114
static void fuelcell_uavcan_cb(struct uavcan_iface_t *iface, CanardRxTransfer *transfer)
Definition: can_fuelcell.c:59
#define UAVCAN_EQUIPMENT_FUELCELL_STATUS_SIGNATURE
Definition: can_fuelcell.c:34
Main uavcan event structure for registering/calling callbacks.
Definition: uavcan.h:60
uavcan interface structure
Definition: uavcan.h:34
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
int8_t register_periodic_telemetry(struct periodic_telemetry *_pt, uint8_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:412
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
short int16_t
Typedef defining 16 bit short type.
Definition: vl53l1_types.h:93
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98
int transfer(const Mat *from, const image_t *to)