Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/AP_Periph/temperature.cpp
Views: 1798
#include "AP_Periph.h"12#ifdef HAL_PERIPH_ENABLE_DEVICE_TEMPERATURE34#include <dronecan_msgs.h>56// Send temperature message occasionally7void AP_Periph_FW::temperature_sensor_update(void)8{9if (g.temperature_msg_rate <= 0) {10return;11}1213const uint32_t now_ms = AP_HAL::millis();14if (now_ms - temperature_last_send_ms < (1000U / g.temperature_msg_rate)) {15return;16}17temperature_last_send_ms = now_ms;1819{20const uint8_t num_sensors = temperature_sensor.num_instances();21for (uint8_t i = 0; i < num_sensors; i++) {22// Send each sensor in turn23const uint8_t index = (temperature_last_sent_index + 1 + i) % num_sensors;2425float temp_deg = 0.0;26if ((temperature_sensor.get_source(index) != AP_TemperatureSensor_Params::Source::DroneCAN) ||27!temperature_sensor.get_temperature(temp_deg, index)) {28// not configured to send or Unhealthy29continue;30}3132uavcan_equipment_device_Temperature pkt {};33pkt.temperature = C_TO_KELVIN(temp_deg);3435// Use source ID from temperature lib36pkt.device_id = temperature_sensor.get_source_id(index);3738uint8_t buffer[UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_MAX_SIZE];39const uint16_t total_size = uavcan_equipment_device_Temperature_encode(&pkt, buffer, !canfdout());4041canard_broadcast(UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_SIGNATURE,42UAVCAN_EQUIPMENT_DEVICE_TEMPERATURE_ID,43CANARD_TRANSFER_PRIORITY_LOW,44&buffer[0],45total_size);4647temperature_last_sent_index = index;48break;49}50}51}5253#endif // HAL_PERIPH_ENABLE_DEVICE_TEMPERATURE545556