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

Last change on this file since 6387 was 6321, checked in by stuerze, 10 years ago

maxprn added for systems J,S,C

File size: 2.2 KB
RevLine 
[5741]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 }
[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//////////////////////////////////////////////////////////////////////////////
35string t_prn::toString() const {
36 stringstream ss;
37 ss << _system << setfill('0') << setw(2) << _number;
38 return ss.str();
39}
40
41// Set from string
42////////////////////////////////////////////////////////////////////////////
[5838]43void t_prn::set(const std::string& str) {
[5741]44 unsigned prn = 0;
45 char system = '\x0';
46 const char* number = 0;
[6128]47 if ( str[0] == 'G' || str[0] == 'R' || str[0] == 'E' ||
48 str[0] == 'J' || str[0] == 'S' || str[0] == 'C' ) {
[5741]49 system = str[0];
50 number = str.c_str() + 1;
51 }
52 else if ( isdigit(str[0]) ) {
53 system = 'G';
54 number = str.c_str();
55 }
56 else {
[5838]57 throw "t_prn::set: wrong satellite ID: " + str;
[5741]58 }
59
60 char* tmpc = 0;
61 prn = strtol(number, &tmpc, 10);
62 if ( tmpc == number || *tmpc != '\x0' ) {
[5838]63 throw "t_prn::set: wrong satellite ID: " + str;
[5741]64 }
65
66 try {
[5838]67 this->set(system, prn);
[5741]68 }
69 catch (string exc) {
[5838]70 throw "t_prn::set: wrong satellite ID: " + str;
[5741]71 }
72}
73
74//
75//////////////////////////////////////////////////////////////////////////////
76t_prn::operator unsigned() const {
77 return toInt();
78}
79
80//
81//////////////////////////////////////////////////////////////////////////////
[5745]82istream& operator >> (istream& in, t_prn& prn) {
[5741]83 string str;
84 in >> str;
85 if (str.length() == 1 && !isdigit(str[0])) {
86 string str2;
87 in >> str2;
88 str += str2;
89 }
[5838]90 prn.set(str);
[5741]91 return in;
92}
Note: See TracBrowser for help on using the repository browser.