[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;
|
---|
[6014] | 38 | if ( str[0] == 'G' || str[0] == 'R' || str[0] == 'E') {
|
---|
[5741] | 39 | system = str[0];
|
---|
| 40 | number = str.c_str() + 1;
|
---|
| 41 | }
|
---|
| 42 | else if ( isdigit(str[0]) ) {
|
---|
| 43 | system = 'G';
|
---|
| 44 | number = str.c_str();
|
---|
| 45 | }
|
---|
| 46 | else {
|
---|
[5838] | 47 | throw "t_prn::set: wrong satellite ID: " + str;
|
---|
[5741] | 48 | }
|
---|
| 49 |
|
---|
| 50 | char* tmpc = 0;
|
---|
| 51 | prn = strtol(number, &tmpc, 10);
|
---|
| 52 | if ( tmpc == number || *tmpc != '\x0' ) {
|
---|
[5838] | 53 | throw "t_prn::set: wrong satellite ID: " + str;
|
---|
[5741] | 54 | }
|
---|
| 55 |
|
---|
| 56 | try {
|
---|
[5838] | 57 | this->set(system, prn);
|
---|
[5741] | 58 | }
|
---|
| 59 | catch (string exc) {
|
---|
[5838] | 60 | throw "t_prn::set: wrong satellite ID: " + str;
|
---|
[5741] | 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | //
|
---|
| 65 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 66 | t_prn::operator unsigned() const {
|
---|
| 67 | return toInt();
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | //
|
---|
| 71 | //////////////////////////////////////////////////////////////////////////////
|
---|
[5745] | 72 | istream& operator >> (istream& in, t_prn& prn) {
|
---|
[5741] | 73 | string str;
|
---|
| 74 | in >> str;
|
---|
| 75 | if (str.length() == 1 && !isdigit(str[0])) {
|
---|
| 76 | string str2;
|
---|
| 77 | in >> str2;
|
---|
| 78 | str += str2;
|
---|
| 79 | }
|
---|
[5838] | 80 | prn.set(str);
|
---|
[5741] | 81 | return in;
|
---|
| 82 | }
|
---|