FACT++  1.0
bool ConnectionDrive::ProcessDriveReport ( const string &  line)
inline

Definition at line 262 of file cosyctrl.cc.

References dev, Drive::State::kOnTrack, StateMachineImp::kSM_Error, and Drive::State::kTracking.

263  {
264  // DRIVE-REPORT M1
265  // 01 2011 05 14 11 31 19 038
266  // 02 1858 11 17 00 00 00 000
267  // + 000 00 000 + 000 00 000
268  // + 000 00 000
269  // 55695.480081
270  // + 000 00 000 + 000 00 000
271  // + 000 00 000 + 000 00 000
272  // 0000.000 0000.000
273  // 0 2
274 
275  // status
276  // year month day hour minute seconds millisec
277  // year month day hour minute seconds millisec
278  // ra(+ h m s) dec(+ d m s) ha(+ h m s)
279  // mjd
280  // zd(+ d m s) az(+ d m s)
281  // zd(+ d m s) az(+ d m s)
282  // zd_err az_err
283  // armed(0=unlocked, 1=locked)
284  // stgmd(0=none, 1=starguider, 2=starguider off)
285  istringstream stream(line);
286 
287  uint16_t status1;
288  stream >> status1;
289  const Time t1 = ReadTime(stream);
290 
291  uint16_t status2;
292  stream >> status2;
293  /*const Time t2 =*/ ReadTime(stream);
294 
295  const double ra = ReadAngle(stream);
296  const double dec = ReadAngle(stream);
297  const double ha = ReadAngle(stream);
298 
299  double mjd;
300  stream >> mjd;
301 
302  const double zd1 = ReadAngle(stream); // Nominal (zd/az asynchronous, dev synchronous, mjd synchronous with zd)
303  const double az1 = ReadAngle(stream); // Nominal (zd/az asynchronous, dev synchronous, mjd synchronous with z)
304  const double zd2 = ReadAngle(stream); // Masured (zd/az synchronous, dev asynchronous, mjd asynchronous)
305  const double az2 = ReadAngle(stream); // Measurd (zd/az synchronous, dev asynchronous, mjd asynchronous)
306 
307  double zd_err, az_err;
308  stream >> zd_err; // Deviation = Nominal - Measured
309  stream >> az_err; // Deviation = Nominal - Measured
310 
311  uint16_t armed, stgmd;
312  stream >> armed;
313  stream >> stgmd;
314 
315  uint32_t pdo3;
316  stream >> hex >> pdo3;
317 
318  if (stream.fail())
319  return false;
320 
321  // Status 0: Error
322  // Status 1: Stopped
323  // Status 3: Stopping || Moving
324  // Status 4: Tracking
325  if (status1==0)
326  status1 = StateMachineImp::kSM_Error - Drive::State::kNotReady;
327 
328  const bool ready = (pdo3&0xef00ef)==0xef00ef;
329  if (!ready)
330  fState = Drive::State::kNotReady;
331  else
332  fState = status1==1 ?
333  Drive::State::kReady+armed :
334  Drive::State::kNotReady+status1;
335 
336  // kDisconnected = 1,
337  // kConnected,
338  // kNotReady,
339  // kReady,
340  // kArmed,
341  // kMoving,
342  // kTracking,
343  // kOnTrack,
344 
345  // pdo3:
346  // 1 Ab
347  // 2 1
348  // 4 Emergency
349  // 8 OverVolt
350  // 10 Move (Drehen-soll)
351  // 20 Af
352  // 40 1
353  // 80 Power on Az
354  // ------------------
355  // 100 NOT UPS Alarm
356  // 200 UPS on Battery
357  // 400 UPS charging
358 
359  // Power cut: 2ef02ef
360  // charging: 4ef04ef
361 
362  // Convert to deg
363  zd_err /= 3600;
364  az_err /= 3600;
365 
366  // Calculate absolut deviation on the sky
367 
368  const double dev = GetDevAbs(zd1, zd1-zd_err, az_err)*3600;
369 
370  fDevBuffer[fDevCount++%5] = dev;
371 
372  const uint8_t cnt = fDevCount<5 ? fDevCount : 5;
373  const double avgdev = accumulate(fDevBuffer.begin(), fDevBuffer.begin()+cnt, 0)/cnt;
374 
375  // If any other state than tracking or a deviation
376  // larger than 60, reset the counter
377  if (fState!=State::kTracking || avgdev>fDeviationLimit)
378  fTrackingCounter = 0;
379  else
381 
382  // If in tracking, at least five consecutive reports (5s)
383  // must be below 60arcsec deviation, this is considered OnTrack
386 
387  // Having th state as Tracking will reset the counter
388  if (fState==State::kOnTrack && avgdev>fDeviationMax)
390 
392  fDevCount = 0;
393 
394  // 206 206 ce ce pwr vlt emcy fs | pwr vlt emcy fs
395  // 239 239 ef ef pwr vlt emcy fs bb rf | pwr vlt emcy fs bb rf
396  // 111 78 6f 4e vlt emcy fs bb rf | emcy fs bb
397 
398  /*
399  fArmed = data[3]&0x01; // armed status
400  fPosActive = data[3]&0x02; // positioning active
401  fRpmActive = data[3]&0x04; // RPM mode switched on
402  // data[3]&0x08; // - unused -
403  // data[3]&0x10; // - unused -
404  // data[3]&0x20; // - unused -
405  //fInControl = data[3]&0x40; // motor uncontrolled
406  // data[3]&0x80; // axis resetted (after errclr, motor stop, motor on)
407 
408  fStatus = data[3];
409  }
410 
411  const LWORD_t stat = data[0] | (data[1]<<8);
412  if (fStatusPdo3!=stat)
413  {
414  gLog << inf << MTime(-1) << ": " << GetNodeName() << " - PDO3(0x" << hex << (int)stat << dec << ") = ";
415  const Bool_t ready = stat&0x001;
416  const Bool_t fuse = stat&0x002;
417  const Bool_t emcy = stat&0x004;
418  const Bool_t vltg = stat&0x008;
419  const Bool_t mode = stat&0x010;
420  const Bool_t rf = stat&0x020;
421  const Bool_t brake = stat&0x040;
422  const Bool_t power = stat&0x080;
423  const Bool_t alarm = stat&0x100; // UPS Alarm (FACT only)
424  const Bool_t batt = stat&0x200; // UPS on battery (FACT only)
425  const Bool_t charge = stat&0x400; // UPS charging (FACT only)
426  if (ready) gLog << "DKC-Ready ";
427  if (fuse) gLog << "FuseOk ";
428  if (emcy) gLog << "EmcyOk ";
429  if (vltg) gLog << "OvervoltOk ";
430  if (mode) gLog << "SwitchToManualMode ";
431  if (rf) gLog << "RF ";
432  if (brake) gLog << "BrakeOpen ";
433  if (power) gLog << "PowerOn ";
434  if (alarm) gLog << "UPS-PowerLoss ";
435  if (batt) gLog << "UPS-OnBattery ";
436  if (charge) gLog << "UPS-Charging ";
437  gLog << endl;
438 
439  fStatusPdo3 = stat;
440  }*/
441 
442  // ((stat1&0xffff)<<16)|(stat2&0xffff)
443  // no alarm, no batt, no charge
444  const array<uint8_t, 3> state = {{ uint8_t(pdo3>>16), uint8_t(pdo3), uint8_t(pdo3>>24) }};
445  UpdateStatus(t1, state);
446 
447  const array<double, 2> point = {{ zd2, az2 }};
448  UpdatePointing(t1, point);
449 
450  const array<double, 8> track =
451  {{
452  ra, dec, ha,
453  zd1, az1,
454  zd_err, az_err,
455  dev
456  }};
457  if (mjd>0)
458  UpdateTracking(Time(mjd), track);
459 
460  // ---- DIM ----> t1 as event time
461  // status1
462  // mjd
463  // ra/dec/ha
464  // zd/az (nominal)
465  // zd/az (current)
466  // err(zd/az)
467  // [armed] [stgmd]
468 
469  // Maybe:
470  // POINTING_POSITION --> t1, zd/az (current), [armed, stgmd, status1]
471  //
472  // if (mjd>0)
473  // TRACKING_POSITION --> mjd, zd/az (nominal), err(zd/az)
474  // ra/dec, ha(not well defined),
475  // [Nominal + Error == Current]
476 
477  // MJD is the time which corresponds to the nominal position
478  // t1 is the time which corresponds to the current position/HA
479 
480  return true;
481  }
uint16_t fDeviationMax
Definition: cosyctrl.cc:127
vector< double > fDevBuffer
Definition: cosyctrl.cc:129
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
static double ReadAngle(istream &in)
Definition: cosyctrl.cc:101
static Time ReadTime(istream &in)
Definition: cosyctrl.cc:93
uint64_t fTrackingCounter
Definition: cosyctrl.cc:132
double GetDevAbs(double nomzd, double meszd, double devaz)
Definition: cosyctrl.cc:113
virtual void UpdateTracking(const Time &, const array< double, 8 > &)
Definition: cosyctrl.cc:63
virtual void UpdateStatus(const Time &, const array< uint8_t, 3 > &)
Definition: cosyctrl.cc:67
Error states should be between 0x100 and 0xffff.
uint16_t fDeviationLimit
Definition: cosyctrl.cc:125
Return to feeserver c CVS log Up to[MAIN] dcscvs FeeServer feeserver src Wed FeeServer_v0 v0 dev
Definition: feeserver.c:5
uint64_t fDevCount
Definition: cosyctrl.cc:130
virtual void UpdatePointing(const Time &, const array< double, 2 > &)
Definition: cosyctrl.cc:59
uint16_t fDeviationCounter
Definition: cosyctrl.cc:126