[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 | }
|
---|
[5741] | 21 | return 0;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | //
|
---|
| 25 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 26 | string t_prn::toString() const {
|
---|
| 27 | stringstream ss;
|
---|
| 28 | ss << _system << setfill('0') << setw(2) << _number;
|
---|
| 29 | return ss.str();
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | // Set from string
|
---|
| 33 | ////////////////////////////////////////////////////////////////////////////
|
---|
[5838] | 34 | void t_prn::set(const std::string& str) {
|
---|
[5741] | 35 | unsigned prn = 0;
|
---|
| 36 | char system = '\x0';
|
---|
| 37 | const char* number = 0;
|
---|
[6128] | 38 | if ( str[0] == 'G' || str[0] == 'R' || str[0] == 'E' ||
|
---|
| 39 | str[0] == 'J' || str[0] == 'S' || str[0] == 'C' ) {
|
---|
[5741] | 40 | system = str[0];
|
---|
| 41 | number = str.c_str() + 1;
|
---|
| 42 | }
|
---|
| 43 | else if ( isdigit(str[0]) ) {
|
---|
| 44 | system = 'G';
|
---|
| 45 | number = str.c_str();
|
---|
| 46 | }
|
---|
| 47 | else {
|
---|
[5838] | 48 | throw "t_prn::set: wrong satellite ID: " + str;
|
---|
[5741] | 49 | }
|
---|
| 50 |
|
---|
| 51 | char* tmpc = 0;
|
---|
| 52 | prn = strtol(number, &tmpc, 10);
|
---|
| 53 | if ( tmpc == number || *tmpc != '\x0' ) {
|
---|
[5838] | 54 | throw "t_prn::set: wrong satellite ID: " + str;
|
---|
[5741] | 55 | }
|
---|
| 56 |
|
---|
| 57 | try {
|
---|
[5838] | 58 | this->set(system, prn);
|
---|
[5741] | 59 | }
|
---|
| 60 | catch (string exc) {
|
---|
[5838] | 61 | throw "t_prn::set: wrong satellite ID: " + str;
|
---|
[5741] | 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | //
|
---|
| 66 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 67 | t_prn::operator unsigned() const {
|
---|
| 68 | return toInt();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | //
|
---|
| 72 | //////////////////////////////////////////////////////////////////////////////
|
---|
[5745] | 73 | istream& operator >> (istream& in, t_prn& prn) {
|
---|
[5741] | 74 | string str;
|
---|
| 75 | in >> str;
|
---|
| 76 | if (str.length() == 1 && !isdigit(str[0])) {
|
---|
| 77 | string str2;
|
---|
| 78 | in >> str2;
|
---|
| 79 | str += str2;
|
---|
| 80 | }
|
---|
[5838] | 81 | prn.set(str);
|
---|
[5741] | 82 | return in;
|
---|
| 83 | }
|
---|