GCC Code Coverage Report


Directory: telemetry-recorder/
File: telemetry-recorder/src/telemetry-recorder.cpp
Date: 2024-03-31 12:31:59
Exec Total Coverage
Lines: 0 34 0.0%
Functions: 0 3 0.0%
Branches: 0 32 0.0%

Line Branch Exec Source
1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "telemetry-recorder/telemetry-recorder.hpp"
16
17 namespace hal::telemetry_recorder {
18
19 result<telemetry_recorder> telemetry_recorder::create(
20 hal::icm::icm20948& p_imu,
21 hal::neo::neo_m9n& p_gps,
22 hal::mpl::mpl3115a2& p_baro)
23 {
24 telemetry_recorder recorder{ p_imu, p_gps, p_baro };
25 return recorder;
26 }
27
28 hal::result<telemetry_recorder::telemetry_data> telemetry_recorder::record()
29 {
30 auto accel = HAL_CHECK(m_icm->read_acceleration());
31 auto gyro = HAL_CHECK(m_icm->read_gyroscope());
32 auto mag = HAL_CHECK(m_icm->read_magnetometer());
33 auto imu_temp = HAL_CHECK(m_icm->read_temperature());
34 auto gps = HAL_CHECK(m_gps->read());
35 auto baro_temp = HAL_CHECK(m_mpl->read_temperature());
36 auto pressure = HAL_CHECK(m_mpl->read_pressure());
37 auto altitude = HAL_CHECK(m_mpl->read_altitude());
38
39 m_data.accel_x = accel.x;
40 m_data.accel_y = accel.y;
41 m_data.accel_z = accel.z;
42 m_data.gyro_x = gyro.x;
43 m_data.gyro_y = gyro.y;
44 m_data.gyro_z = gyro.z;
45 m_data.mag_x = mag.x;
46 m_data.mag_y = mag.y;
47 m_data.mag_z = mag.z;
48 m_data.imu_temp = imu_temp.temp;
49
50
51 m_data.gps_locked = gps.is_locked;
52 m_data.gps_time = gps.time;
53 m_data.gps_lat = gps.latitude;
54 m_data.gps_long = gps.longitude;
55 m_data.gps_sats = gps.satellites_used;
56 m_data.gps_alt = gps.altitude;
57
58 m_data.baro_temp = baro_temp.temperature;
59 m_data.baro_pressure = pressure.pressure;
60 m_data.baro_altitude = altitude.altitude;
61
62 return hal::result<telemetry_recorder::telemetry_data>{ m_data };
63 }
64
65 hal::result<float> telemetry_recorder::gps_baro_altitude_offset()
66 {
67 return m_data.gps_alt - m_data.baro_altitude;
68 }
69
70 } // namespace hal::telemetry_recorder
71