[5741] | 1 | #include <sstream>
|
---|
| 2 | #include <iomanip>
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 |
|
---|
| 5 | #include "t_prn.h"
|
---|
| 6 |
|
---|
| 7 | using namespace std;
|
---|
| 8 |
|
---|
| 9 | //
|
---|
| 10 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 11 | int t_prn::toInt() const {
|
---|
| 12 | if (_system == 'G') {
|
---|
| 13 | return _number;
|
---|
| 14 | }
|
---|
| 15 | else if (_system == 'R') {
|
---|
| 16 | return MAXPRN_GPS + _number;
|
---|
| 17 | }
|
---|
[6014] | 18 | else if (_system == 'E') {
|
---|
| 19 | return MAXPRN_GPS + MAXPRN_GLONASS + _number;
|
---|
| 20 | }
|
---|
[6321] | 21 | else if (_system == 'J') {
|
---|
| 22 | return MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + _number;
|
---|
| 23 | }
|
---|
| 24 | else if (_system == 'S') {
|
---|
| 25 | return MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + MAXPRN_QZSS + _number;
|
---|
| 26 | }
|
---|
| 27 | else if (_system == 'C') {
|
---|
| 28 | return MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + MAXPRN_QZSS + MAXPRN_SBAS + _number;
|
---|
| 29 | }
|
---|
[5741] | 30 | return 0;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | //
|
---|
| 34 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 35 | string t_prn::toString() const {
|
---|
| 36 | stringstream ss;
|
---|
| 37 | ss << _system << setfill('0') << setw(2) << _number;
|
---|
| 38 | return ss.str();
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[6809] | 41 | //
|
---|
| 42 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 43 | string t_prn::toInternalString() const {
|
---|
| 44 | stringstream ss;
|
---|
| 45 | ss << _system << setfill('0') << setw(2) << _number << '_' << _flags;
|
---|
| 46 | return ss.str();
|
---|
| 47 | }
|
---|
| 48 |
|
---|
[5741] | 49 | // Set from string
|
---|
| 50 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5838] | 51 | void t_prn::set(const std::string& str) {
|
---|
[5741] | 52 | unsigned prn = 0;
|
---|
| 53 | char system = '\x0';
|
---|
| 54 | const char* number = 0;
|
---|
[6128] | 55 | if ( str[0] == 'G' || str[0] == 'R' || str[0] == 'E' ||
|
---|
[8149] | 56 | str[0] == 'J' || str[0] == 'S' || str[0] == 'C' ||
|
---|
| 57 | str[0] == 'I'
|
---|
| 58 | ) {
|
---|
[5741] | 59 | system = str[0];
|
---|
| 60 | number = str.c_str() + 1;
|
---|
| 61 | }
|
---|
| 62 | else if ( isdigit(str[0]) ) {
|
---|
| 63 | system = 'G';
|
---|
| 64 | number = str.c_str();
|
---|
| 65 | }
|
---|
| 66 | else {
|
---|
[5838] | 67 | throw "t_prn::set: wrong satellite ID: " + str;
|
---|
[5741] | 68 | }
|
---|
| 69 |
|
---|
| 70 | char* tmpc = 0;
|
---|
| 71 | prn = strtol(number, &tmpc, 10);
|
---|
| 72 | if ( tmpc == number || *tmpc != '\x0' ) {
|
---|
[5838] | 73 | throw "t_prn::set: wrong satellite ID: " + str;
|
---|
[5741] | 74 | }
|
---|
| 75 |
|
---|
| 76 | try {
|
---|
[5838] | 77 | this->set(system, prn);
|
---|
[5741] | 78 | }
|
---|
| 79 | catch (string exc) {
|
---|
[5838] | 80 | throw "t_prn::set: wrong satellite ID: " + str;
|
---|
[5741] | 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | //
|
---|
| 85 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 86 | t_prn::operator unsigned() const {
|
---|
| 87 | return toInt();
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | //
|
---|
| 91 | //////////////////////////////////////////////////////////////////////////////
|
---|
[5745] | 92 | istream& operator >> (istream& in, t_prn& prn) {
|
---|
[5741] | 93 | string str;
|
---|
| 94 | in >> str;
|
---|
| 95 | if (str.length() == 1 && !isdigit(str[0])) {
|
---|
| 96 | string str2;
|
---|
| 97 | in >> str2;
|
---|
| 98 | str += str2;
|
---|
| 99 | }
|
---|
[5838] | 100 | prn.set(str);
|
---|
[5741] | 101 | return in;
|
---|
| 102 | }
|
---|