CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/AP_Periph/relay.cpp
Views: 1798
1
#include "AP_Periph.h"
2
3
#ifdef HAL_PERIPH_ENABLE_RELAY
4
5
#include <dronecan_msgs.h>
6
7
void AP_Periph_FW::handle_hardpoint_command(CanardInstance* canard_instance, CanardRxTransfer* transfer)
8
{
9
uavcan_equipment_hardpoint_Command cmd {};
10
if (uavcan_equipment_hardpoint_Command_decode(transfer, &cmd)) {
11
// Failed to decode
12
return;
13
}
14
15
// Command must be 0 or 1, other values may be supported in the future
16
// rejecting them now ensures no change in behaviour
17
if ((cmd.command != 0) && (cmd.command != 1)) {
18
return;
19
}
20
21
// Translate hardpoint ID to relay function
22
AP_Relay_Params::FUNCTION fun;
23
switch (cmd.hardpoint_id) {
24
case 0 ... 15:
25
// 0 to 15 are continuous
26
fun = AP_Relay_Params::FUNCTION(cmd.hardpoint_id + (uint8_t)AP_Relay_Params::FUNCTION::DroneCAN_HARDPOINT_0);
27
break;
28
29
default:
30
// ID not supported
31
return;
32
}
33
34
// Set relay
35
relay.set(fun, cmd.command);
36
37
}
38
#endif
39
40