FACT++  1.0
bool ConnectionGPS::ParseAnswer ( const string &  buffer)
inlineprivate

Definition at line 58 of file gpsctrl.cc.

References GPS::NEMA::count, Error(), GPS::NEMA::geosep, GPS::NEMA::hdop, GPS::NEMA::height, i, GPS::State::kDisabled, GPS::State::kEnabled, GPS::State::kLocked, GPS::NEMA::lat, GPS::NEMA::lng, GPS::NEMA::qos, Tools::Split(), and GPS::NEMA::time.

59  {
60  if (buffer=="Invalid command, type help")
61  {
62  Error("Command was ignored by GPS.");
63  return false;
64  }
65 
66  // answer to get_status or veto_[on|off|60]
67  if (buffer=="veto_60" || buffer=="veto 60 now on")
68  {
71  PostMessage(string("get_nema\r\n"), 10);
72  return true;
73  }
74  if (buffer=="veto_on" || buffer=="veto now on")
75  {
77  PostMessage(string("get_nema\r\n"), 10);
78  return true;
79  }
80  /*
81  if (buffer=="veto_off" || buffer=="veto now off")
82  {
83  fState = GPS::State::kVetoOff;
84  PostMessage(string("get_nema\r\n"), 10);
85  return true;
86  }*/
87 
88  // answer to get_nema
89  if (buffer[0]=='$')
90  {
91  /*
92  1 = UTC of Position
93  2 = Latitude
94  3 = N or S
95  4 = Longitude
96  5 = E or W
97  6 = GPS quality indicator (0=invalid; 1=GPS fix;
98  2=Diff. GPS fix)
99  7 = Number of satellites in use [not those in view]
100  8 = Horizontal dilution of position
101  9 = Antenna altitude above/below mean sea level (geoid)
102  10 = Meters (Antenna height unit)
103  11 = Geoidal separation (Diff. between WGS-84 earth ellipsoid
104  and mean sea level. -=geoid is below WGS-84 ellipsoid)
105  12 = Meters (Units of geoidal separation)
106  13 = Age in seconds since last update from diff.
107  reference station
108  14 = Diff. reference station ID#
109  */
110 
111  const vector<string> cs = Tools::Split(buffer, "$*");
112  if (cs.size()!=3)
113  throw runtime_error("syntax error");
114 
115  // check checksum
116  uint8_t c = cs[1][0];
117  for (size_t i=1; i<cs[1].size(); i++)
118  c ^= cs[1][i];
119 
120  stringstream ss;
121  ss << std::hex << cs[2];
122 
123  unsigned int x;
124  ss >> x;
125 
126  if (x!=c)
127  throw runtime_error("checksum error");
128 
129  // interpret contents
130  const vector<string> dat = Tools::Split(cs[1], ",");
131  if (dat.size()!=15)
132  throw runtime_error("size mismatch");
133  if (dat[0]!="GPGGA")
134  throw runtime_error("type mismatch");
135  if (dat[5]!="W" && dat[5]!="E")
136  throw runtime_error("longitude type unknown");
137  if (dat[10]!="M")
138  throw runtime_error("height unit unknown");
139  if (dat[12]!="M")
140  throw runtime_error("hdop unit unknown");
141  if (!dat[13].empty())
142  throw runtime_error("unexpected data at position 13");
143  if (dat[14]!="0000")
144  throw runtime_error("unexpected data at position 14");
145 
146  GPS::NEMA nema;
147  nema.time = ConvTm(dat[1]);
148  nema.lat = dat[3]=="N" ? ConvLngLat(dat[2]) : -ConvLngLat(dat[3]);
149  nema.lng = dat[5]=="W" ? ConvLngLat(dat[4]) : -ConvLngLat(dat[4]);
150  nema.qos = stoi(dat[6]);
151  nema.count = stoi(dat[7]);
152  nema.hdop = stof(dat[8]);
153  nema.height = stof(dat[9]);
154  nema.geosep = stof(dat[11]);
155 
156  if (fabs(nema.time-fmod(Time().Mjd(), 1))*24*3600>5)
157  {
158  Error("Time mismatch: GPS time deviates from PC time by more than 5s");
159  return false;
160  }
161 
164 
165  Update(nema);
166 
167  return true;
168  }
169 
170  return false;
171  }
float ConvLngLat(const string &l) const
Definition: gpsctrl.cc:35
float hdop
Definition: HeadersGPS.h:23
int i
Definition: db_dim_client.c:21
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
float time
Definition: HeadersGPS.h:20
float lng
Definition: HeadersGPS.h:22
float ConvTm(const string &t) const
Definition: gpsctrl.cc:46
float height
Definition: HeadersGPS.h:24
std::map< std::string, std::string > Split(std::string &, bool=false)
Definition: tools.cc:230
uint16_t qos
Definition: HeadersGPS.h:27
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
float lat
Definition: HeadersGPS.h:21
float geosep
Definition: HeadersGPS.h:25
virtual void Update(const GPS::NEMA &)
Definition: gpsctrl.cc:24
Error()
Definition: HeadersFTM.h:197
uint16_t count
Definition: HeadersGPS.h:26

+ Here is the call graph for this function: