SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
Toggle main menu visibility
Loading...
Searching...
No Matches
power.cpp
Go to the documentation of this file.
1
/*
2
* SatNOGS-COMMS control library
3
*
4
* Copyright (C) 2023, Libre Space Foundation <http://libre.space>
5
*
6
* This program 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 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
18
*
19
* SPDX-License-Identifier: GNU General Public License v3.0 or later
20
*/
21
22
#include <
satnogs-comms-lib/board.hpp
>
23
#include <
satnogs-comms-lib/power.hpp
>
24
25
namespace
satnogs::comms::lib
26
{
27
34
void
35
power::enable
(
subsys
sys,
bool
en)
36
{
37
switch
(sys) {
38
case
subsys::CAN1
:
39
m_can1_en.set(en);
40
m_can1_low_pwr.set(!en);
41
break
;
42
case
subsys::CAN2
:
43
m_can2_en.set(en);
44
m_can2_low_pwr.set(!en);
45
break
;
46
case
subsys::RF_5V
:
47
if
(en) {
48
m_imon_5v_rf.start();
49
}
else
{
50
m_imon_5v_rf.stop();
51
}
52
m_rf_5v_en.set(en);
53
break
;
54
case
subsys::FPGA_5V
:
55
if
(en) {
56
m_imon_fpga.start();
57
}
else
{
58
m_imon_fpga.stop();
59
}
60
m_fpga_5v_en.set(en);
61
break
;
62
case
subsys::CAN1_LPWR
:
63
m_can1_low_pwr.set(en);
64
break
;
65
case
subsys::CAN2_LPWR
:
66
m_can2_low_pwr.set(en);
67
break
;
68
case
subsys::UHF
:
69
m_uhf_en.set(en);
70
break
;
71
case
subsys::SBAND
:
72
m_sband_en.set(en);
73
break
;
74
default
:
75
throw
inval_arg_exception
(__FILE__, __LINE__);
76
}
77
}
78
85
bool
86
power::enabled
(
subsys
sys)
const
87
{
88
switch
(sys) {
89
case
subsys::CAN1
:
90
return
m_can1_en.get();
91
case
subsys::CAN2
:
92
return
m_can2_en.get();
93
case
subsys::RF_5V
:
94
return
m_rf_5v_en.get();
95
case
subsys::FPGA_5V
:
96
return
m_fpga_5v_en.get();
97
case
subsys::CAN1_LPWR
:
98
return
m_can1_low_pwr.get();
99
case
subsys::CAN2_LPWR
:
100
return
m_can2_low_pwr.get();
101
case
subsys::UHF
:
102
return
m_uhf_en.get();
103
case
subsys::SBAND
:
104
return
m_sband_en.get();
105
default
:
106
throw
inval_arg_exception
(__FILE__, __LINE__);
107
}
108
}
109
116
bool
117
power::pgood
(
pgood_tp
tp)
const
118
{
119
switch
(tp) {
120
/* In v0.3 if the 3V3 has fault, the MCU will reset */
121
case
pgood_tp::RAIL_5V
:
122
return
m_pgood_5v.get();
123
case
pgood_tp::RAIL_FPGA
:
124
return
m_pgood_fpga.get();
125
case
pgood_tp::RAIL_UHF
:
126
return
m_uhf_pgood.get();
127
case
pgood_tp::RAIL_SBAND
:
128
return
m_sband_pgood.get();
129
default
:
130
throw
inval_arg_exception
(__FILE__, __LINE__);
131
}
132
}
133
145
float
146
power::voltage
(
channel
sys)
const
147
{
148
try
{
149
switch
(sys) {
150
case
channel::VIN
:
151
return
m_monitor.get_source_voltage();
152
case
channel::V_BAT
:
153
return
m_v_mon.vbat();
154
default
:
155
throw
inval_arg_exception
(__FILE__, __LINE__);
156
}
157
}
catch
(...) {
158
return
std::nanf(
"nan"
);
159
}
160
}
161
173
float
174
power::current
(
channel
sys)
const
175
{
176
try
{
177
switch
(sys) {
178
case
channel::DIG_3V3
:
179
return
(m_imon_3v3.voltage() * 1000000 /
180
(m_efuse_adc_current_gain * m_r_lim.dig_3v3));
181
case
channel::RF_5V
:
182
return
(m_imon_5v_rf.voltage() * 1000000 /
183
(m_efuse_adc_current_gain * m_r_lim.rf_5v));
184
case
channel::FPGA
:
185
return
(m_imon_fpga.voltage() * 1000000 /
186
(m_efuse_adc_current_gain * m_r_lim.fpga_5v));
187
case
channel::VIN
:
188
return
m_monitor.get_sense_current();
189
default
:
190
throw
inval_arg_exception
(__FILE__, __LINE__);
191
return
0;
192
}
193
}
catch
(...) {
194
return
std::nanf(
"nan"
);
195
}
196
}
197
208
float
209
power::get_power
(
sensor
src)
const
210
{
211
try
{
212
switch
(src) {
213
case
sensor::EFUSES
:
214
return
(
power::current
(
channel::DIG_3V3
) * 3.3f +
215
power::current
(
channel::RF_5V
) * 5.0f +
216
power::current
(
channel::FPGA
) * 5.0f);
217
case
sensor::EMC1702
:
218
return
m_monitor.get_power();
219
case
sensor::AVERAGE
:
220
return
(((
power::current
(
channel::DIG_3V3
) * 3.3f +
221
power::current
(
channel::RF_5V
) * 5.0f +
222
power::current
(
channel::FPGA
) * 5.0f) +
223
m_monitor.get_power()) /
224
2);
225
default
:
226
throw
inval_arg_exception
(__FILE__, __LINE__);
227
}
228
}
catch
(...) {
229
return
std::nanf(
"nan"
);
230
}
231
}
232
233
power::power
(
const
io_conf
&
io
)
234
: m_rf_5v_en(
io
.rf_5v_en),
235
m_fpga_5v_en(
io
.fpga_5v_en),
236
m_can1_en(
io
.
can1_en
),
237
m_can1_low_pwr(
io
.
can1_low_pwr
),
238
m_can2_en(
io
.
can2_en
),
239
m_can2_low_pwr(
io
.
can2_low_pwr
),
240
m_pgood_5v(
io
.rf_5v_pgood),
241
m_pgood_fpga(
io
.fpga_5v_pgood),
242
m_monitor(
"current-sensor"
,
io
.mon_i2c, 0b101101),
243
m_uhf_en(
io
.uhf_en),
244
m_uhf_pgood(
io
.
uhf_pgood
),
245
m_sband_en(
io
.sband_en),
246
m_sband_pgood(
io
.
sband_pgood
),
247
m_imon_5v_rf(
io
.imon_5v_rf),
248
m_imon_3v3(
io
.imon_3v3_d),
249
m_imon_fpga(
io
.imon_fpga),
250
m_v_mon(
io
.v_mon),
251
m_r_lim(
io
.rlim),
252
m_efuse_adc_current_gain(
io
.efuse_adc_current_gain)
253
254
{
255
/* Disable all at startup */
256
enable
(
subsys::CAN1
,
false
);
257
enable
(
subsys::CAN2
,
false
);
258
enable
(
subsys::RF_5V
,
false
);
259
enable
(
subsys::FPGA_5V
,
false
);
260
enable
(
subsys::UHF
,
false
);
261
enable
(
subsys::SBAND
,
false
);
262
263
/* Start the ADC of the 3V3 which remains always on */
264
m_imon_3v3.start();
265
}
266
267
}
// namespace satnogs::comms::lib
board.hpp
satnogs::comms::io
Definition
io.hpp:47
satnogs::comms::lib::inval_arg_exception
Generic exception indicating an invalid argument.
Definition
exception.hpp:180
satnogs::comms::lib::power::io_conf
Represents the I/O configuration for the power management system.
Definition
power.hpp:143
satnogs::comms::lib::power::voltage
float voltage(channel sys) const
Retrieves the voltage of a specified channel.
Definition
power.cpp:146
satnogs::comms::lib::power::current
float current(channel sys) const
Retrieves the current of a specified channel.
Definition
power.cpp:174
satnogs::comms::lib::power::power
power(const io_conf &io)
Definition
power.cpp:233
satnogs::comms::lib::power::pgood
bool pgood(pgood_tp tp) const
Gets the power good indication from various power supplies.
Definition
power.cpp:117
satnogs::comms::lib::power::sensor
sensor
Identifies power measurement sources.
Definition
power.hpp:66
satnogs::comms::lib::power::sensor::AVERAGE
@ AVERAGE
Average power from all available sources.
Definition
power.hpp:69
satnogs::comms::lib::power::sensor::EFUSES
@ EFUSES
Power measured by eFuses.
Definition
power.hpp:67
satnogs::comms::lib::power::sensor::EMC1702
@ EMC1702
Power measured by the EMC1702 sensor.
Definition
power.hpp:68
satnogs::comms::lib::power::pgood_tp
pgood_tp
Power good indicator.
Definition
power.hpp:90
satnogs::comms::lib::power::pgood_tp::RAIL_SBAND
@ RAIL_SBAND
S-Band rail.
Definition
power.hpp:94
satnogs::comms::lib::power::pgood_tp::RAIL_5V
@ RAIL_5V
5V rail
Definition
power.hpp:91
satnogs::comms::lib::power::pgood_tp::RAIL_FPGA
@ RAIL_FPGA
FPGA rail.
Definition
power.hpp:92
satnogs::comms::lib::power::pgood_tp::RAIL_UHF
@ RAIL_UHF
UHF rail.
Definition
power.hpp:93
satnogs::comms::lib::power::get_power
float get_power(sensor src) const
Calculates the power consumption for a specified sensor source.
Definition
power.cpp:209
satnogs::comms::lib::power::subsys
subsys
Identifies subsystems managed by the power class.
Definition
power.hpp:50
satnogs::comms::lib::power::subsys::CAN2_LPWR
@ CAN2_LPWR
Low-power mode for CAN Bus 2.
Definition
power.hpp:56
satnogs::comms::lib::power::subsys::CAN1_LPWR
@ CAN1_LPWR
Low-power mode for CAN Bus 1.
Definition
power.hpp:55
satnogs::comms::lib::power::subsys::RF_5V
@ RF_5V
RF 5V supply.
Definition
power.hpp:53
satnogs::comms::lib::power::subsys::CAN2
@ CAN2
CAN Bus 2.
Definition
power.hpp:52
satnogs::comms::lib::power::subsys::CAN1
@ CAN1
CAN Bus 1.
Definition
power.hpp:51
satnogs::comms::lib::power::subsys::SBAND
@ SBAND
S-Band subsystem.
Definition
power.hpp:58
satnogs::comms::lib::power::subsys::UHF
@ UHF
UHF subsystem.
Definition
power.hpp:57
satnogs::comms::lib::power::subsys::FPGA_5V
@ FPGA_5V
FPGA 5V supply.
Definition
power.hpp:54
satnogs::comms::lib::power::channel
channel
Identifies voltage and current measurement channels.
Definition
power.hpp:77
satnogs::comms::lib::power::channel::RF_5V
@ RF_5V
RF 5V voltage/current channel.
Definition
power.hpp:79
satnogs::comms::lib::power::channel::V_BAT
@ V_BAT
Battery voltage channel.
Definition
power.hpp:82
satnogs::comms::lib::power::channel::FPGA
@ FPGA
FPGA voltage/current channel.
Definition
power.hpp:78
satnogs::comms::lib::power::channel::DIG_3V3
@ DIG_3V3
Digital 3.3V voltage/current channel.
Definition
power.hpp:80
satnogs::comms::lib::power::channel::VIN
@ VIN
Input voltage channel.
Definition
power.hpp:81
satnogs::comms::lib::power::enable
void enable(subsys sys, bool en=true)
Enable/disable the power of subsystems.
Definition
power.cpp:35
satnogs::comms::lib::power::enabled
bool enabled(subsys sys) const
Checks the if the subsystem is enabled.
Definition
power.cpp:86
satnogs::comms::lib
Definition
ad8318.hpp:30
satnogs::comms::sband_pgood
const struct gpio_dt_spec sband_pgood
Definition
startup.cpp:90
satnogs::comms::can1_en
const struct gpio_dt_spec can1_en
Definition
startup.cpp:63
satnogs::comms::can2_low_pwr
const struct gpio_dt_spec can2_low_pwr
Definition
startup.cpp:69
satnogs::comms::can2_en
const struct gpio_dt_spec can2_en
Definition
startup.cpp:67
satnogs::comms::uhf_pgood
const struct gpio_dt_spec uhf_pgood
Definition
startup.cpp:86
satnogs::comms::can1_low_pwr
const struct gpio_dt_spec can1_low_pwr
Definition
startup.cpp:65
power.hpp
libsatnogs-comms
src
power.cpp
Generated by
1.17.0