A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
leo-orbital-shell.cc
Go to the documentation of this file.
1// Copyright (c) Tim Schubert
2//
3// SPDX-License-Identifier: GPL-2.0-only
4//
5// Author: Tim Schubert <ns-3-leo@timschubert.net>
6// Porting: Thiago Miyazaki <miyathiago@gmail.com> <t.miyazaki@unesp.br>
7
8/**
9 * @file
10 * @ingroup leo
11 * Implementation of LeoOrbitalShell serialization helpers.
12 */
13
14#include "leo-orbital-shell.h"
15
16#include "ns3/csv-reader.h"
17#include "ns3/log.h"
18
19NS_LOG_COMPONENT_DEFINE("LeoOrbitalShell");
20
21namespace ns3
22{
23
24std::ostream&
25operator<<(std::ostream& os, const LeoOrbitalShell& orbit)
26{
27 os << orbit.alt << "," << orbit.inc << "," << orbit.planes << "," << orbit.sats << ","
28 << orbit.phasing << "," << orbit.raanSpanDeg;
29 return os;
30}
31
32std::istream&
33operator>>(std::istream& is, LeoOrbitalShell& orbit)
34{
35 // Use CsvReader to parse the CSV from the input stream.
36 CsvReader csv(is);
37 orbit = LeoOrbitalShell{}; // Reset to default values first.
38 if (!csv.FetchNextRow())
39 {
40 return is;
41 }
42 if (csv.ColumnCount() < 4)
43 {
44 NS_LOG_WARN("Skipping row " << csv.RowNumber() << ": expected at least 4 columns, got "
45 << csv.ColumnCount());
46 return is;
47 }
48 bool ok = csv.GetValue(0, orbit.alt);
49 ok &= csv.GetValue(1, orbit.inc);
50 ok &= csv.GetValue(2, orbit.planes);
51 ok &= csv.GetValue(3, orbit.sats);
52 if (!ok)
53 {
54 return is;
55 }
56 // Optional 5th column: Walker Delta phasing factor.
57 csv.GetValue(4, orbit.phasing);
58 // Optional 6th column: RAAN span in degrees.
59 csv.GetValue(5, orbit.raanSpanDeg);
60 return is;
61}
62
63}; // namespace ns3
Provides functions for parsing and extracting data from Comma Separated Value (CSV) formatted text fi...
Definition csv-reader.h:221
bool GetValue(std::size_t columnIndex, T &value) const
Attempt to convert from the string data in the specified column to the specified data type.
Definition csv-reader.h:399
std::size_t RowNumber() const
The number of lines that have been read.
Definition csv-reader.cc:91
std::size_t ColumnCount() const
Returns the number of columns in the csv data.
Definition csv-reader.cc:83
bool FetchNextRow()
Reads one line from the input until a new line is encountered.
Orbit definition.
double inc
Inclination of orbit (degrees).
std::size_t sats
Number of satellites in those planes.
double raanSpanDeg
RAAN span in degrees (360 for Walker Delta, 180 for Walker Star).
std::size_t planes
Number of planes with that altitude and inclination.
double alt
Altitude of orbit (km, from earth surface).
double phasing
Walker Delta phasing factor F (0 means no inter-plane stagger).
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:253
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172