source: ntrip/trunk/BNC/src/t_prn.cpp@ 6914

Last change on this file since 6914 was 6809, checked in by stuerze, 10 years ago

I/NAV - F/NAV issue (hopefully:) solved in another way

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