forked from ArduPilot/ardupilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AP_Periph: Send generic equipment temperature data
- Loading branch information
Showing
5 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "AP_Periph.h" | ||
|
||
#if AP_TEMPERATURE_SENSOR_ENABLED | ||
|
||
#include <dronecan_msgs.h> | ||
|
||
// Send temperature message occasionally | ||
void AP_Periph_FW::temperature_sensor_update(void) | ||
{ | ||
if (g.temperature_max_rate <= 0) { | ||
return; | ||
} | ||
|
||
const uint32_t now_ms = AP_HAL::millis(); | ||
if (now_ms - temperature_last_send_ms < (1000U / g.temperature_max_rate)) { | ||
return; | ||
} | ||
temperature_last_send_ms = now_ms; | ||
|
||
{ | ||
const uint8_t num_sensors = temperature_sensor.num_instances(); | ||
for (uint8_t i = 0; i < num_sensors; i++) { | ||
// Send each sensor in turn | ||
const uint8_t index = (temperature_last_sent_index + 1 + i) % num_sensors; | ||
|
||
float temp_deg = 0.0; | ||
if (!temperature_sensor.get_temperature(temp_deg, index) || | ||
(temperature_sensor.get_source(index) != AP_TemperatureSensor_Params::Source::DroneCAN)) { | ||
// Unhealthy or not configured to send | ||
continue; | ||
} | ||
|
||
uavcan_equipment_device_Temperature pkt {}; | ||
pkt.temperature = C_TO_KELVIN(temp_deg); | ||
|
||
// Use source ID from temperature lib | ||
pkt.device_id = temperature_sensor.get_source_id(index); | ||
|
||
uint8_t buffer[UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_MAX_SIZE] {}; | ||
const uint16_t total_size = uavcan_equipment_device_Temperature_encode(&pkt, buffer, !canfdout()); | ||
|
||
canard_broadcast(UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_SIGNATURE, | ||
UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_ID, | ||
CANARD_TRANSFER_PRIORITY_LOW, | ||
&buffer[0], | ||
total_size); | ||
|
||
temperature_last_sent_index = index; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
#endif // AP_TEMPERATURE_SENSOR_ENABLED |