| 1 | #include <sstream>
|
|---|
| 2 | #include <iomanip>
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 |
|
|---|
| 5 | #include "t_prn.h"
|
|---|
| 6 |
|
|---|
| 7 | using namespace std;
|
|---|
| 8 |
|
|---|
| 9 | // Set from number
|
|---|
| 10 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 11 | void t_prn::set(unsigned nn) {
|
|---|
| 12 | const static unsigned maxGPS = MAXPRN_GPS;
|
|---|
| 13 | const static unsigned maxGLONASS = MAXPRN_GPS + MAXPRN_GLONASS;
|
|---|
| 14 | const static unsigned maxGALILEO = MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO;
|
|---|
| 15 | const static unsigned maxQZSS = MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + MAXPRN_QZSS;
|
|---|
| 16 | const static unsigned maxSBAS = MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + MAXPRN_QZSS + MAXPRN_SBAS;
|
|---|
| 17 | const static unsigned maxBDS = MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + MAXPRN_QZSS + MAXPRN_SBAS + MAXPRN_BDS;
|
|---|
| 18 | const static unsigned maxNavIC = MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + MAXPRN_QZSS + MAXPRN_SBAS + MAXPRN_BDS + MAXPRN_NavIC;
|
|---|
| 19 | _system = 'G';
|
|---|
| 20 | _number = 0;
|
|---|
| 21 | _flag = 0;
|
|---|
| 22 | if (nn <= maxGPS) {
|
|---|
| 23 | _system = 'G';
|
|---|
| 24 | _number = nn;
|
|---|
| 25 | }
|
|---|
| 26 | else if (nn <= maxGLONASS) {
|
|---|
| 27 | _system = 'R';
|
|---|
| 28 | _number = nn - maxGPS;
|
|---|
| 29 | }
|
|---|
| 30 | else if (nn <= maxGALILEO) {
|
|---|
| 31 | _system = 'E';
|
|---|
| 32 | _number = nn - maxGLONASS;
|
|---|
| 33 | }
|
|---|
| 34 | else if (nn <= maxQZSS) {
|
|---|
| 35 | _system = 'J';
|
|---|
| 36 | _number = nn - maxGALILEO;
|
|---|
| 37 | }
|
|---|
| 38 | else if (nn <= maxSBAS) {
|
|---|
| 39 | _system = 'S';
|
|---|
| 40 | _number = nn - maxQZSS;
|
|---|
| 41 | }
|
|---|
| 42 | else if (nn <= maxBDS) {
|
|---|
| 43 | _system = 'C';
|
|---|
| 44 | _number = nn - maxSBAS;
|
|---|
| 45 | }
|
|---|
| 46 | else if (nn <= maxNavIC) {
|
|---|
| 47 | _system = 'I';
|
|---|
| 48 | _number = nn - maxBDS;
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | //
|
|---|
| 53 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 54 | int t_prn::toInt() const {
|
|---|
| 55 | if (_system == 'G') {
|
|---|
| 56 | return _number;
|
|---|
| 57 | }
|
|---|
| 58 | else if (_system == 'R') {
|
|---|
| 59 | return MAXPRN_GPS + _number;
|
|---|
| 60 | }
|
|---|
| 61 | else if (_system == 'E') {
|
|---|
| 62 | return MAXPRN_GPS + MAXPRN_GLONASS + _number;
|
|---|
| 63 | }
|
|---|
| 64 | else if (_system == 'J') {
|
|---|
| 65 | return MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + _number;
|
|---|
| 66 | }
|
|---|
| 67 | else if (_system == 'S') {
|
|---|
| 68 | return MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + MAXPRN_QZSS + _number;
|
|---|
| 69 | }
|
|---|
| 70 | else if (_system == 'C') {
|
|---|
| 71 | return MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + MAXPRN_QZSS + MAXPRN_SBAS + _number;
|
|---|
| 72 | }
|
|---|
| 73 | else if (_system == 'I') {
|
|---|
| 74 | return MAXPRN_GPS + MAXPRN_GLONASS + MAXPRN_GALILEO + MAXPRN_QZSS + MAXPRN_SBAS + MAXPRN_BDS + _number;
|
|---|
| 75 | }
|
|---|
| 76 | return 0;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | //
|
|---|
| 80 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 81 | string t_prn::toString() const {
|
|---|
| 82 | stringstream ss;
|
|---|
| 83 | ss << _system << setfill('0') << setw(2) << _number;
|
|---|
| 84 | return ss.str();
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | //
|
|---|
| 88 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 89 | string t_prn::toInternalString() const {
|
|---|
| 90 | stringstream ss;
|
|---|
| 91 | ss << _system << setfill('0') << setw(2) << _number << '_' << _flag;
|
|---|
| 92 | return ss.str();
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | // Set from string
|
|---|
| 96 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 97 | void t_prn::set(const std::string& str) {
|
|---|
| 98 | unsigned prn = 0;
|
|---|
| 99 | char system = '\x0';
|
|---|
| 100 | const char* number = 0;
|
|---|
| 101 | if ( str[0] == 'G' || str[0] == 'R' || str[0] == 'E' ||
|
|---|
| 102 | str[0] == 'J' || str[0] == 'S' || str[0] == 'C' ||
|
|---|
| 103 | str[0] == 'I') {
|
|---|
| 104 | system = str[0];
|
|---|
| 105 | number = str.c_str() + 1;
|
|---|
| 106 | }
|
|---|
| 107 | else if ( isdigit(str[0]) ) {
|
|---|
| 108 | system = 'G';
|
|---|
| 109 | number = str.c_str();
|
|---|
| 110 | }
|
|---|
| 111 | else {
|
|---|
| 112 | throw "t_prn::set: wrong satellite ID: " + str;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | char* tmpc = 0;
|
|---|
| 116 | prn = strtol(number, &tmpc, 10);
|
|---|
| 117 | if ( tmpc == number || *tmpc != '\x0' ) {
|
|---|
| 118 | throw "t_prn::set: wrong satellite ID: " + str;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | try {
|
|---|
| 122 | this->set(system, prn);
|
|---|
| 123 | }
|
|---|
| 124 | catch (string exc) {
|
|---|
| 125 | throw "t_prn::set: wrong satellite ID: " + str;
|
|---|
| 126 | }
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | //
|
|---|
| 130 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 131 | t_prn::operator unsigned() const {
|
|---|
| 132 | return toInt();
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | //
|
|---|
| 136 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 137 | istream& operator >> (istream& in, t_prn& prn) {
|
|---|
| 138 | string str;
|
|---|
| 139 | in >> str;
|
|---|
| 140 | if (str.length() == 1 && !isdigit(str[0])) {
|
|---|
| 141 | string str2;
|
|---|
| 142 | in >> str2;
|
|---|
| 143 | str += str2;
|
|---|
| 144 | }
|
|---|
| 145 | prn.set(str);
|
|---|
| 146 | return in;
|
|---|
| 147 | }
|
|---|