SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
Toggle main menu visibility
Loading...
Searching...
No Matches
time.hpp
Go to the documentation of this file.
1
/*
2
* SatNOGS-COMMS MCU software
3
*
4
* Copyright (C) 2024, 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
#pragma once
23
24
#include "
bsp/bsp.hpp
"
25
#include <etl/string.h>
26
#include <time.h>
27
#include <zephyr/device.h>
28
#include <zephyr/drivers/gnss.h>
29
#include <zephyr/drivers/rtc.h>
30
#include <zephyr/drivers/uart.h>
31
#include <zephyr/kernel.h>
32
#include <zephyr/logging/log.h>
33
#include <zephyr/sys/timeutil.h>
34
35
namespace
satnogs::comms
36
{
37
59
class
time
60
{
61
public
:
62
static
time
&
63
get_instance
()
64
{
65
static
time
instance;
66
return
instance;
67
}
68
73
enum class
time_src
: uint8_t
74
{
75
GNSS_ASSISTED_RTC
= 0,
78
GNSS_ONLY
=
79
1,
80
UPTIME
=
81
2,
82
};
83
84
static
constexpr
size_t
to_string_max_size
= 20;
89
enum class
time_granularity
90
{
91
YEAR
,
92
MONTH
,
93
DAY
,
94
HOUR
,
95
MIN
,
96
SEC
97
};
98
99
/* Singleton */
100
time
(
time
const
&) =
delete
;
101
102
void
103
operator=
(
time
const
&) =
delete
;
104
105
void
106
gnss_data_cb
(
const
struct
device *dev,
const
struct
gnss_data *data);
107
108
time_src
109
get
(uint64_t &t);
110
111
time_src
112
get
(
struct
tm &t);
113
114
void
115
set
(
const
struct
tm &t);
116
117
void
118
gnss
(
struct
gnss_data &data);
119
120
uint64_t
121
uptime
();
122
123
uint64_t
124
last_gnss_update_uptime
();
125
126
uint64_t
127
last_nmea_update_uptime
();
128
129
size_t
130
to_string
(
const
struct
tm &tm, etl::istring &s,
131
time::time_granularity
granularity)
const
;
132
size_t
133
to_string
(
const
struct
tm &tm, etl::istring &s)
const
;
134
135
class
to_string_exception
:
public
lib::exception
136
{
137
public
:
138
to_string_exception
(
const
char
*file_name,
int
line)
139
:
exception
(
exception
::
severity
::
MINOR
, file_name, line,
140
error_msg
{
"Convertion of date to string failed"
,
"tmtostr"
,
141
ENOTSUP})
142
{
143
}
144
};
145
146
private
:
147
/* Milliseconds Since Epoch (January 1, 1970, UTC.) */
148
uint64_t m_millis_since_epoch_gnss;
149
bool
m_gnss_received_fix;
150
int64_t m_last_gnss_update_uptime;
151
int64_t m_last_nmea_update_uptime;
152
const
struct
device *m_rtc;
153
bool
m_init;
154
mutable
struct
k_mutex m_mtx;
155
struct
gnss_data m_gnss_data;
156
157
time
();
158
};
159
160
}
// namespace satnogs::comms
bsp.hpp
satnogs::comms::lib::exception::error_msg
A class representing error messages in the SatNOGS-COMMS system.
Definition
exception.hpp:83
satnogs::comms::lib::exception
Exception base class.
Definition
exception.hpp:63
satnogs::comms::lib::exception::severity
severity
Severity levels of exceptions.
Definition
exception.hpp:71
satnogs::comms::lib::exception::severity::MINOR
@ MINOR
Failure having minimal impact.
Definition
exception.hpp:75
satnogs::comms::lib::exception::exception
exception(severity sev, const char *file, int lineno, const error_msg &err_msg)
Constructor for the exception class.
Definition
exception.hpp:102
satnogs::comms::time::to_string_exception::to_string_exception
to_string_exception(const char *file_name, int line)
Definition
time.hpp:138
satnogs::comms::time::set
void set(const struct tm &t)
Sets the RTC time.
Definition
time.cpp:200
satnogs::comms::time::gnss
void gnss(struct gnss_data &data)
Retrieve latest GNSS information.
Definition
time.cpp:237
satnogs::comms::time::get
time_src get(uint64_t &t)
Gets the time in ms.
Definition
time.cpp:111
satnogs::comms::time::uptime
uint64_t uptime()
Gets the current system uptime in milliseconds.
Definition
time.cpp:167
satnogs::comms::time::last_gnss_update_uptime
uint64_t last_gnss_update_uptime()
Gets the system uptime (in milliseconds) at the time of the last GNSS fix.
Definition
time.cpp:179
satnogs::comms::time::last_nmea_update_uptime
uint64_t last_nmea_update_uptime()
Definition
time.cpp:185
satnogs::comms::time::get_instance
static time & get_instance()
Definition
time.hpp:63
satnogs::comms::time::to_string
size_t to_string(const struct tm &tm, etl::istring &s, time::time_granularity granularity) const
Return the string represantation of a struct tm time instance following the ISO-8601 paradigm....
Definition
time.cpp:290
satnogs::comms::time::operator=
void operator=(time const &)=delete
satnogs::comms::time::time_granularity
time_granularity
Granularity of time represented as string.
Definition
time.hpp:90
satnogs::comms::time::time_granularity::MONTH
@ MONTH
Definition
time.hpp:92
satnogs::comms::time::time_granularity::DAY
@ DAY
Definition
time.hpp:93
satnogs::comms::time::time_granularity::SEC
@ SEC
Definition
time.hpp:96
satnogs::comms::time::time_granularity::MIN
@ MIN
Definition
time.hpp:95
satnogs::comms::time::time_granularity::YEAR
@ YEAR
Definition
time.hpp:91
satnogs::comms::time::time_granularity::HOUR
@ HOUR
Definition
time.hpp:94
satnogs::comms::time::gnss_data_cb
void gnss_data_cb(const struct device *dev, const struct gnss_data *data)
Definition
time.cpp:54
satnogs::comms::time::time
time(time const &)=delete
satnogs::comms::time::time_src
time_src
Source of the reported time.
Definition
time.hpp:74
satnogs::comms::time::time_src::UPTIME
@ UPTIME
No RTC or GNSS time source. The uptime is used to track time.
Definition
time.hpp:80
satnogs::comms::time::time_src::GNSS_ONLY
@ GNSS_ONLY
No RTC installed, but there is time information from a GNSS fix.
Definition
time.hpp:78
satnogs::comms::time::time_src::GNSS_ASSISTED_RTC
@ GNSS_ASSISTED_RTC
Definition
time.hpp:75
satnogs::comms::time::to_string_max_size
static constexpr size_t to_string_max_size
Definition
time.hpp:84
satnogs::comms
Definition
bsp.cpp:28
src
time.hpp
Generated by
1.17.0