Skip to content

Commit f971ad2

Browse files
committed
lib: sgp4: move tests from module to lib, expose public API
Move NTN tests from `tests/module/` to `tests/lib/` and update testcase identifiers from `fw` to `lib` prefix. Move `sat_data_sib32` struct to the header and expose `parse_sibconfig32_at` and `jd_from_unix_time_ms` as public functions with proper documentation. Use `ASSET_TRACKER_TEMPLATE_DIR` variable in CMake files instead of relative paths. Signed-off-by: Simen S. Røstad <simen.rostad@nordicsemi.no>
1 parent 47257dd commit f971ad2

10 files changed

Lines changed: 58 additions & 30 deletions

File tree

lib/sgp4/sgp4_pass_predict.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,6 @@ struct datetime {
3434
double second;
3535
};
3636

37-
/* 3GPP TS 36.331 ephemeris parameters format */
38-
struct sat_data_sib32 {
39-
int64_t satelliteId;
40-
int64_t epochStar;
41-
int64_t meanMotion;
42-
int64_t eccentricity;
43-
int64_t inclination;
44-
int64_t rightAscension;
45-
int64_t argumentPerigee;
46-
int64_t meanAnomaly;
47-
int64_t bStarDecimal;
48-
int64_t bStarExponent;
49-
int64_t serviceStart;
50-
int64_t elevationAngleLeft;
51-
int64_t elevationAngleRight;
52-
int64_t referencePointLongitude;
53-
int64_t referencePointLatitude;
54-
int64_t radius;
55-
};
56-
5737
/* SIBCONFIG 32 AT ephemeris struct field order */
5838
enum sib_ephemeris_field {
5939
FIELD_SATELLITE_ID = 0,
@@ -190,7 +170,7 @@ static uint64_t datetime_to_ts(struct datetime *dt)
190170
return days*86400000 + dt->hour*3600000 + dt->minute*60000 + dt->second*1000;
191171
}
192172

193-
static void jd_from_unix_time_ms(int64_t unix_time_ms, double *jd, double *jdfract)
173+
void jd_from_unix_time_ms(int64_t unix_time_ms, double *jd, double *jdfract)
194174
{
195175
*jd = (unix_time_ms / 86400000) + 2440587.5;
196176
*jdfract = (unix_time_ms % 86400000) / 86400000.0;
@@ -359,7 +339,7 @@ static int parse_ephemeris_struct(char **saveptr, struct sat_data_sib32 *sib32)
359339
return 0;
360340
}
361341

362-
static int parse_sibconfig32_at(const char *atsib32, char *cell_id, struct sat_data_sib32 *sib32)
342+
int parse_sibconfig32_at(const char *atsib32, char *cell_id, struct sat_data_sib32 *sib32)
363343
{
364344
int err;
365345
int sibnr;

lib/sgp4/sgp4_pass_predict.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@
1313

1414
#define MAX_SATELLITES 4
1515

16+
/* 3GPP TS 36.331 ephemeris parameters format */
17+
struct sat_data_sib32 {
18+
int64_t satelliteId;
19+
int64_t epochStar;
20+
int64_t meanMotion;
21+
int64_t eccentricity;
22+
int64_t inclination;
23+
int64_t rightAscension;
24+
int64_t argumentPerigee;
25+
int64_t meanAnomaly;
26+
int64_t bStarDecimal;
27+
int64_t bStarExponent;
28+
int64_t serviceStart;
29+
int64_t elevationAngleLeft;
30+
int64_t elevationAngleRight;
31+
int64_t referencePointLongitude;
32+
int64_t referencePointLatitude;
33+
int64_t radius;
34+
};
35+
1636
struct next_pass {
1737
int64_t start_time_ms;
1838
int64_t end_time_ms;
@@ -83,4 +103,24 @@ int sat_data_calculate_next_pass(struct sat_data *sat_data, int sat_index,
83103
*/
84104
int sat_data_set_name(struct sat_data *sat_data, const char *name);
85105

106+
/**
107+
* @brief Parse SIBCONFIG 32 AT command ephemeris parameters
108+
*
109+
* @param atsib32 The AT SIB32 parameters from modem
110+
* @param cell_id Output buffer for cell ID (at least 9 bytes)
111+
* @param sib32 Output array for parsed SIB entries, or NULL to only count entries
112+
*
113+
* @return Number of SIB entries on success, negative error code otherwise
114+
*/
115+
int parse_sibconfig32_at(const char *atsib32, char *cell_id, struct sat_data_sib32 *sib32);
116+
117+
/**
118+
* @brief Convert Unix time in milliseconds to Julian date
119+
*
120+
* @param unix_time_ms Unix timestamp in milliseconds
121+
* @param jd Whole Julian day
122+
* @param jdfract Fractional part of Julian day
123+
*/
124+
void jd_from_unix_time_ms(int64_t unix_time_ms, double *jd, double *jdfract);
125+
86126
#endif
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
cmake_minimum_required(VERSION 3.20.0)
88

99
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10-
project(sgp4_pass_test)
10+
project(ntn_sib32_test)
1111

1212
test_runner_generate(src/test_sib32_tle.c)
1313

14+
set(ASSET_TRACKER_TEMPLATE_DIR ../../..)
15+
1416
target_sources(app
1517
PRIVATE
1618
src/test_sib32_tle.c
1719
)
1820

1921
zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/)
2022
zephyr_include_directories(${ZEPHYR_BASE}/subsys/testsuite/include)
21-
zephyr_include_directories(../../../app/src/common)
22-
zephyr_include_directories(../../../lib/sgp4)
23+
zephyr_include_directories(${ASSET_TRACKER_TEMPLATE_DIR}/app/src/common)
24+
zephyr_include_directories(${ASSET_TRACKER_TEMPLATE_DIR}/lib/sgp4)
2325

2426
target_link_options(app PRIVATE --whole-archive)

tests/module/ntn-sib32/src/test_sib32_tle.c renamed to tests/lib/ntn-sib32/src/test_sib32_tle.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ char *strtok_r(char *str, const char *delim, char **saveptr);
2222

2323
DEFINE_FFF_GLOBALS;
2424

25+
LOG_MODULE_REGISTER(ntn_sib32_test, LOG_LEVEL_DBG);
26+
2527
/* Thu Feb 12 2026 09:38:29 GMT+0000 */
2628
#define FAKE_TIME_MS 1770889109000LL
2729
int date_time_now(int64_t *time)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests:
2-
asset_tracker_template.fw.ntn-sib32:
2+
asset_tracker_template.lib.ntn-sib32:
33
platform_allow:
44
- native_sim
55
- native_sim/native/64
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
cmake_minimum_required(VERSION 3.20.0)
88

99
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10-
project(sgp4_pass_test)
10+
project(ntn_sgp4_test)
1111

1212
test_runner_generate(src/sgp4_pass_test.c)
1313

14+
set(ASSET_TRACKER_TEMPLATE_DIR ../../..)
15+
1416
target_sources(app
1517
PRIVATE
1618
src/sgp4_pass_test.c
1719
)
1820

1921
zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/)
2022
zephyr_include_directories(${ZEPHYR_BASE}/subsys/testsuite/include)
21-
zephyr_include_directories(../../../app/src/common)
22-
zephyr_include_directories(../../../lib/sgp4)
23+
zephyr_include_directories(${ASSET_TRACKER_TEMPLATE_DIR}/app/src/common)
24+
zephyr_include_directories(${ASSET_TRACKER_TEMPLATE_DIR}/lib/sgp4)
2325

2426
target_link_options(app PRIVATE --whole-archive)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ char *strtok_r(char *str, const char *delim, char **saveptr);
2222

2323
DEFINE_FFF_GLOBALS;
2424

25+
LOG_MODULE_REGISTER(ntn_sgp4_test, LOG_LEVEL_DBG);
26+
2527
static struct sat_data sat_data_tle;
2628

2729
/* Mon Mar 02 2026 08:50:24 */
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tests:
2-
asset_tracker_template.fw.ntn:
2+
asset_tracker_template.lib.ntn:
33
platform_allow:
44
- native_sim
55
- native_sim/native/64

0 commit comments

Comments
 (0)