The VisAO Camera
FilterWheelLocal.cpp
Go to the documentation of this file.
1 /************************************************************
2 * FilterWheelLocal.cpp
3 *
4 * Author: Jared R. Males (jrmales@email.arizona.edu)
5 *
6 * Declarations for the FilterWheelLocal class, which adapts
7 * the SimpleMotorCtrl class for use as a VisAO App.
8 *
9 * Developed as part of the Magellan Adaptive Optics system.
10 ************************************************************/
11 
12 /** \file FilterWheelLocal.cpp
13  * \author Jared R. Males
14  * \brief Declarations for the FilterWheelLocal class.
15  *
16 */
17 
18 #include "FilterWheelLocal.h"
19 
20 int need_restart;
21 
22 namespace VisAO
23 {
24 
25 FilterWheelLocal::FilterWheelLocal( std::string name, const std::string &conffile) throw (AOException) : AOApp( name, conffile)
26 {
27  setupVisAOApp();
28 }
29 
30 FilterWheelLocal::FilterWheelLocal( int argc, char **argv) throw (AOException) : AOApp( argc, argv)
31 {
32  setupVisAOApp();
33 }
34 
36 {
37  need_restart = 0;
38 
39  std::string pathtmp;
40  setup_fifo_list(2); //We're only going to use the local and script fifos.
41 
42  set_app_name(MyName());
43 
44  aoapp_name = MyFullName();
45 
46  int spos = aoapp_name.find("Local", 0);
47  int epos = aoapp_name.find(".L", 0);
48 
49  if(spos < 0 || epos < 0)
50  {
51  std::cerr << "Can't create aoapp_name.\n";
52  Logger::get()->log( Logger::LOG_LEV_ERROR, "Can't create aoapp_name.");
53  throw AOException("Fatal: cannot create name of filterwheel AOApp.");
54  }
55 
56  aoapp_name.erase(spos, epos-spos);
57 
58  std::cerr << "aoapp_name set to: " << aoapp_name << "\n";
60 
61  //Set up the com_paths
62  try
63  {
64  pathtmp = (std::string)((ConfigDictionary()))["com_path"];
65  }
66  catch(Config_File_Exception)
67  {
68  pathtmp = "fifos";
69  }
70  com_path = std::string(getenv("VISAO_ROOT")) + "/" + pathtmp + "/" + MyName();
71 
72  pause_time = 1.; //Hard coded because it corresponds to the adopt DoFSM loop.
73 
74  //Set up the VisAO status board
75  try
76  {
77  statusboard_shmemkey = (ConfigDictionary())["statusboard_shmemkey"];
78  }
79  catch(Config_File_Exception)
80  {
82  }
83 
85  {
87  {
89  _logger->log(Logger::LOG_LEV_ERROR, "Could not create status board.");
90  }
91  else
92  {
94  strncpy(bsb->appname, MyFullName().c_str(), 25);
95  bsb->max_update_interval = pause_time;
96 
98  fwsb->pos = -99999;
99  strncpy(fwsb->filter_name, "unknown", 50);
100  fwsb->type = -1;
101  }
102  }
103 
104  setup_baseApp(0, 1, 1, 0, false); //Only make the local and script fifos.
105 
106  signal(SIGIO, SIG_IGN);
107 
108 
109 
110 }
111 
113 {
114  Config_File* adopt_cfg;
115  int dotpos = aoapp_name.find(".L", 0);
116 
117  if(dotpos < 0)
118  {
119  throw AOException("Fatal: cannot create name of filterwheel config file.");
120  }
121  std::cerr << aoapp_name.substr(0, dotpos) << "\n";
122  try
123  {
124  adopt_cfg = new Config_File(Utils::getConffile(aoapp_name.substr(0, dotpos)));
125  }
126  catch (Config_File_Exception &e)
127  {
128  Logger::get()->log( Logger::LOG_LEV_FATAL, "%s", e.what().c_str());
129  throw AOException("Fatal: cannot find adopt filter wheel configuration.");
130  }
131 
132  try
133  {
134  _abortPos = (double)(*adopt_cfg)["AbortPosition"];
135  std::cout << "_abortPos " << _abortPos << "\n";
136  _homingPos = (double)(*adopt_cfg)["HomingPosition"];
137  std::cout << "_homingPos " << _homingPos << "\n";
138  _startingPos = (double)(*adopt_cfg)["StartingPos"];
139  std::cout << "_startingPos " << _startingPos << "\n";
140 
141  }
142  catch(Config_File_Exception &e)
143  {
144  Logger::get()->log( Logger::LOG_LEV_FATAL, "%s", e.what().c_str());
145  throw AOException("Fatal: cannot find required config values.");
146  }
147 
148  // Read custom position list, if present.
149  _customPos.clear();
150  int numCustomPos=0;
151  try
152  {
153  numCustomPos = (*adopt_cfg)["customPositionNum"];
154  }
155  catch (Config_File_Exception &e)
156  {
157  _logger->log( Logger::LOG_LEV_INFO, "No custom positions defined in cfg file.");
158  }
159 
160  if (numCustomPos >0)
161  {
162  for (int i=0; i<numCustomPos; i++)
163  {
164  ostringstream namekey, poskey;
165  namekey << "pos" << i << "_name";
166  poskey << "pos" << i << "_pos";
167  string name;
168  float pos;
169  try
170  {
171  name = (std::string) (*adopt_cfg)[namekey.str()];
172  pos = (float)(*adopt_cfg)[poskey.str()];
173  _customPos[name] = pos;
174  }
175  catch (Config_File_Exception &e)
176  {
177  _logger->log( Logger::LOG_LEV_ERROR, "Custom position %d not found in cfg file.", i);
178  }
179  }
180  }
181 
182  //Read custom types from list, if present.
183  _customTypes.clear();
184  int numCustomTypes=0;
185  try
186  {
187  numCustomTypes = (*adopt_cfg)["customPositionNum"];
188  }
189  catch (Config_File_Exception &e)
190  {
191  Logger::get()->log( Logger::LOG_LEV_INFO, "No custom positions defined in cfg file.");
192  }
193 
194  if (numCustomTypes >0)
195  {
196  std::cout << "Loading " << numCustomTypes << " custom types.\n";
197 
198  for (int i=0; i<numCustomTypes; i++)
199  {
200  ostringstream typekey, poskey;
201  typekey << "pos" << i << "_type";
202  poskey << "pos" << i << "_pos";
203  int type;
204  float pos;
205  try
206  {
207  type = (int) (*adopt_cfg)[typekey.str()];
208  pos = (float) (*adopt_cfg)[poskey.str()];
209  _customTypes.insert(std::pair<int, float>(type, pos));
210  }
211  catch (Config_File_Exception &e)
212  {
213  Logger::get()->log( Logger::LOG_LEV_ERROR, "Custom type for %d not found in cfg file.", i);
214  }
215  }
216  }
217 
218 }
219 
221 {
222 
223 
224  //Add the control mode variables to RTDB.
225  try
226  {
227  var_status = RTDBvar ( aoapp_name, "STATUS", NO_DIR, INT_VARIABLE, 1, 1);
228  var_cmode_cur = RTDBvar( aoapp_name, "ConMode", CUR_VAR, INT_VARIABLE, 1,1);
230  var_cmode_req = RTDBvar( aoapp_name, "ConMode", REQ_VAR, INT_VARIABLE, 1,1);
231  var_pos_cur = RTDBvar( aoapp_name, "POS", CUR_VAR, REAL_VARIABLE, 1,1);
232  var_pos_req = RTDBvar( aoapp_name, "POS", REQ_VAR, REAL_VARIABLE, 1);
233  var_pos_local_req = RTDBvar( aoapp_name, "POS_LOCAL", REQ_VAR, REAL_VARIABLE, 1,1);
234  var_pos_script_req = RTDBvar( aoapp_name, "POS_SCRIPT", REQ_VAR, REAL_VARIABLE, 1,1);
235 
236 
237 // if(control_mode == CMODE_NONE)
238 // {
239 // var_pos_cur.Update();
240 // var_pos_cur.Get(&req_pos);
241 // }
242 // if(control_mode == CMODE_REMOTE)
243 // {
244 // var_pos_req.Update();
245 // var_pos_req.Get(&req_pos);
246 // }
247 // if(control_mode == CMODE_LOCAL)
248 // {
249 // var_pos_local_req.Update();
250 // var_pos_local_req.Get(&req_pos);
251 // }
252 // if(control_mode == CMODE_SCRIPT)
253 // {
254 // var_pos_script_req.Update();
255 // var_pos_script_req.Get(&req_pos);
256 // }
257 // std::cout << "Initialized req_pos: " << req_pos << "\n";
258 
259 
260  }
261  catch (AOVarException &e)
262  {
263  Logger::get()->log(Logger::LOG_LEV_FATAL, "%s:%s: %s", __FILE__, __LINE__, e.what().c_str());
264  throw AOException("Error creating RTDB variables");
265  }
266 
267  //Reset the RTDB notifier to our handler.
268  this->Notify( var_status, StatusChanged);
269  this->Notify(var_cmode_cur, CModeCurChanged);
270  this->Notify(var_pos_cur, PosCurChanged);
271  this->Notify(var_pos_req, PosReqChanged);
272  //this->Notify(var_pos_local_req, PosReqChanged);
273  //this->Notify(var_pos_script_req, PosReqChanged);
274 }
275 
276 std::string FilterWheelLocal::GetPosName(double pos)
277 {
278  double np, ul, ll;
279  std::string name;
280 
281  pos = fmod(pos, _customPos.size());
282  if(pos < 0) pos += _customPos.size();
283 
284  cpos_it = _customPos.begin();
285  while(cpos_it != _customPos.end())
286  {
287  name = (*cpos_it).first;
288  np = (*cpos_it).second;
289  ll = fmod(np-.25, _customPos.size());
290  if(ll < 0) ll += _customPos.size();
291  ul = fmod(np+.25, _customPos.size());
292  if(ul < 0) ul += _customPos.size();
293  if((pos > ll && pos < ul) || (ul-ll < 0 && (pos < ul || pos > ll)))
294  {
295  return name;
296  break;
297  }
298 
299  cpos_it++;
300  }
301 
302  return "intermediate";
303 }
304 
306 {
307 
308  double np, ul, ll;
309  int type;
310 
311  pos = fmod(pos, _customTypes.size());
312  if(pos < 0) pos += _customTypes.size();
313 
314  ctype_it = _customTypes.begin();
315  while(ctype_it != _customTypes.end())
316  {
317  type = (*ctype_it).first;
318  np = (*ctype_it).second;
319  ll = fmod(np-.25, _customTypes.size());
320  if(ll < 0) ll += _customTypes.size();
321  ul = fmod(np+.25, _customTypes.size());
322  if(ul < 0) ul += _customTypes.size();
323  if((pos > ll && pos < ul) || (ul-ll < 0 && (pos < ul || pos > ll)))
324  {
325  //std::cout << type << "\n";
326  return type;
327  break;
328  }
329 
330  ctype_it++;
331  }
332 
333  return 0;
334 }
335 
336 
338 {
339 
340  //Startup the I/O signal handling thread
341  if(start_signal_catcher(true) != 0)
342  {
343  _logger->log( Logger::LOG_LEV_FATAL, "Error starting signal thread.");
344  SetTimeToDie(true);
345  return;
346  }
347 
348  sigset_t set;
349 
350  sigemptyset(&set);
351  sigaddset(&set, SIGIO);
352  sigaddset(&set, RTSIGIO);
353 
354  if(pthread_sigmask(SIG_BLOCK, &set, 0) != 0)
355  {
356  _logger->log( Logger::LOG_LEV_FATAL, "Error blocking SIGIO in main thread.");
357  SetTimeToDie(true);
358  return;
359  }
360 
361  try
362  {
363  while(!TimeToDie()) DoFSM();
364  }
365  catch(...)
366  {
367  std::cerr << "Main thread: exception caught." << std::endl;
368  }
369 
370  std::cerr << "Main thread exiting." << std::endl;
371 }
372 
374 {
375 
376  sleep(1);
377  //update_statusboard();
378 
379  return 0;
380 }
381 
383 {
384  //std::cout << "cur_pos = " << pos << std::endl;
385  cur_pos = pos;
386 
387 }
388 
390 {
391  //std::cout << "req_pos = " << pos << std::endl;
392  req_pos = pos;
393 
394 
395 }
396 
397 void FilterWheelLocal::set_control_mode(int cmode)
398 {
399  control_mode = cmode;
400 }
401 
402 void FilterWheelLocal::set_status(int stat)
403 {
404  cur_state = stat;
405 }
406 
408 {
409  double dt, t0;
410 
411  if(connect_fifo_list() == 0)
412  {
413  logss.clear();
414  logss << "fifo_list connected.";
415  log_msg(Logger::LOG_LEV_INFO, logss.str());
416  }
417  else
418  {
419  error_report(Logger::LOG_LEV_FATAL, "Error connecting the fifo list.");
420  SetTimeToDie(true);
421  return;
422  }
423 
424  global_fifo_list = &fl;
425 
426  setup_RTsigio();
427 
428 
429  while(!TimeToDie())
430  {
431  try
432  {
433  t0 = get_curr_time();
434 
435  while((dt = get_curr_time() - t0) < pause_time && !TimeToDie())
436  {
438  usleep((int) 100);
439  }
442  }
443  catch(AOVarException e)
444  {
445  need_restart = 1;
446  SetTimeToDie(true);
447  std::cerr << "Fifo thread: exception caught. " << __LINE__ << " " << e.what() << std::endl;
448  }
449  catch(...)
450  {
451  std::cerr << "Fifo thread: exception caught. " << __LINE__ << std::endl;
452  }
453  }
454  std::cerr << "Fifo thread exiting." << std::endl;
455 }
456 
457 void * __fwstart_signal_catcher(void * ptr)
458 {
459  ((FilterWheelLocal *) ptr)->signal_catcher();
460  return 0;
461 }
462 
464 {
465  struct sched_param schedpar;
466  pthread_attr_t attr;
467 
468  pthread_attr_init(&attr);
469 
470  if(!inherit_sched)
471  {
472  //Start the signal catcher as a lower priority thread.
473 
474  schedpar.sched_priority = 0;
475 
476  pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
477  pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
478  pthread_attr_setschedparam(&attr, &schedpar);
479  }
480  else
481  {
482  //Start with inherit sched, use the same priority as the main thread
483  pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED);
484  }
485 
486  //This is weird, but the doc for pthread_create says it returns an "error number" instead of -1
487  if(pthread_create(&signal_thread, &attr, &__fwstart_signal_catcher, (void *) this) == 0) return 0;
488  else return -1;
489 
490 }
491 
493 {
494  return request_control(cmode, 0);
495 }
496 
497 int FilterWheelLocal::request_control(int cmode, bool override)
498 {
499  std::cout << "Requesting control\n";
500 
501  try
502  {
503  if(override) cmode *= 10;
504  var_cmode_req.Set(cmode, 0, FORCE_SEND);
505  return cmode;
506  }
507  catch(AOVarException e)
508  {
509  std::cerr << "request_control: exception caught " << __LINE__ << " " << e.what() << std::endl;
510  need_restart = 1;
511  SetTimeToDie(true);
512  return -1;
513  }
514 
515 }
516 
517 int FilterWheelLocal::CModeCurChanged(void *pt, Variable *msgb)
518 {
519  //std::cout << "In CModeReqChanged\n";
520  FilterWheelLocal * vmc = (FilterWheelLocal *) pt;
521 
522  vmc->set_control_mode(msgb->Value.Lv[0]);
523 
524  return NO_ERROR;
525 }
526 
527 int FilterWheelLocal::PosCurChanged( void *pt, Variable *var)
528 {
529  //std::cout << "In PosCurChanged\n";
530 
531  FilterWheelLocal * vmc = (FilterWheelLocal *) pt;
532  /***** Don't lock the mutex! it will get locked by PosReqChanged *******/
533 
534  vmc->updatePos(var->Value.Dv[0]);
535 
536  return NO_ERROR;
537 }
538 
539 int FilterWheelLocal::PosReqChanged( void *pt, Variable *var)
540 {
541  //std::cout << "In PosCurChanged\n";
542 
543  FilterWheelLocal * vmc = (FilterWheelLocal *) pt;
544  /***** Don't lock the mutex! it will get locked by PosReqChanged *******/
545 
546  vmc->updateReq(var->Value.Dv[0]);
547 
548  return NO_ERROR;
549 }
550 
551 
552 int FilterWheelLocal::StatusChanged(void *pt, Variable *var)
553 {
554  //std::cout << "In StatusCurChanged\n";
555 
556  FilterWheelLocal * vmc = (FilterWheelLocal *) pt;
557  /***** Don't lock the mutex! it will get locked by PosReqChanged *******/
558 
559  vmc->set_status(var->Value.Lv[0]);
560 
561  return NO_ERROR;
562 }
563 
565 {
566 
567  std::cout << "Changing Pos\n";
568 
569  try
570  {
571  if(pos == getAbortPos())
572  {
573  var_pos_local_req.Set(pos, 0, FORCE_SEND);
574  return 0;
575  }
576 
577  if(control_mode == CMODE_LOCAL)
578  {
579  var_pos_local_req.Set(pos, 0, FORCE_SEND);
580  updateReq(pos);
581  return 0;
582  }
583 
584  if(control_mode == CMODE_SCRIPT)
585  {
586  var_pos_script_req.Set(pos, 0, FORCE_SEND);
587  updateReq(pos);
588  return 0;
589  }
590  }
591  catch(AOVarException e)
592  {
593  std::cerr << "ChangePos: exception caught " << " " << __LINE__ << " " << e.what() << std::endl;
594  SetTimeToDie(true);
595  need_restart = 1;
596 
597  return -1;
598  }
599 
600  return -1;
601 }
602 
603 
604 
605 std::string FilterWheelLocal::remote_command(std::string com)
606 {
607  std::string rstr;
608 
609  _logger->log(Logger::LOG_LEV_TRACE, "Received remote command: %s.", com.c_str());
610 
611  rstr = common_command(com, CMODE_REMOTE);
612 
613  if(rstr == "") rstr = "UNKOWN COMMAND: " + com + "\n";
614 
615  _logger->log(Logger::LOG_LEV_TRACE, "Response to remote command: %s.", rstr.c_str());
616 
617  return rstr;
618 }
619 
620 std::string FilterWheelLocal::local_command(std::string com)
621 {
622  std::string rstr;
623 
624  _logger->log(Logger::LOG_LEV_TRACE, "Received local command: %s.", com.c_str());
625 
626  rstr = common_command(com, CMODE_LOCAL);
627 
628  if(rstr == "") rstr = "UNKOWN COMMAND: " + com + "\n";
629 
630  _logger->log(Logger::LOG_LEV_TRACE, "Response to local command: %s.", rstr.c_str());
631 
632  return rstr;
633 }
634 
635 std::string FilterWheelLocal::script_command(std::string com)
636 {
637  std::string rstr;
638 
639  _logger->log(Logger::LOG_LEV_TRACE, "Received script command: %s.", com.c_str());
640 
641  rstr = common_command(com, CMODE_SCRIPT);
642 
643  if(rstr == "") rstr = "UNKOWN COMMAND: " + com + "\n";
644 
645  _logger->log(Logger::LOG_LEV_TRACE, "Response to script command: %s.", rstr.c_str());
646 
647  return rstr;
648 }
649 
651 {
652  char statestr[100];
653 
654  int ismov = 0, ishom = 0;
655  std::string filt;
656  int status;
657 
658  status = cur_state;
659 
660  std::string str = control_mode_response();
661 
662 // if(status == STATE_READY || status == STATE_OPERATING || status == STATE_HOMING)
663 // {
664 //
665 // //motor->var_pos_cur.Get(&cur_pos);
666 // ismov = 0;motor->IsMoving();
667 // //ishom = ((VisAOFilterWheel*)motor)->IsHoming();
668 // }
669 // else
670 // {
671 // ismov = 0;
672 // ishom = 0;
673 // }
674 
675 
676  filt = GetPosName(cur_pos);
677 
678  snprintf(statestr, 100, "%c %2i %i %i %09.4f %s\n", str[0], status, ismov, ishom, cur_pos, filt.c_str());
679 
680  return statestr;
681 }
682 
683 std::string FilterWheelLocal::common_command(std::string com, int calling_ctype)
684 {
685  int rv;
686  char rvstr[50];
687 
688  int pos = com.find_first_of("\n\r", 0);
689  if(pos > -1) com.erase(pos, com.length()-pos);
690 
691  if(com == "state?")
692  {
693  return get_state_str();
694  }
695  if(com == "abort")
696  {
697  //Can always abort, from anywhere.
698  rv = ChangePos(_abortPos);
699  snprintf(rvstr, 5, "%i\n", rv);
700  return rvstr;
701  }
702  if(com == "home")
703  {
704  if(control_mode == calling_ctype)
705  {
706  rv = ChangePos(_homingPos);
707  snprintf(rvstr, 5, "%i\n", rv);
708  return rvstr;
709  }
710  else
711  {
712  return control_mode_response();
713  }
714  }
715  if(com == "pos?")
716  {
717  snprintf(rvstr, 50, "%0.3f\n", cur_pos );
718  return rvstr;
719  }
720 
721  if(com == "moving?")
722  {
723  int ismov = 0;
724  if(cur_state == STATE_OPERATING || cur_state == STATE_HOMING)
725  {
726 
727  ismov = 1;
728 
729  }
730  snprintf(rvstr, 50, "%i\n", ismov);
731  return rvstr;
732  }
733 
734  if(com == "homing?")
735  {
736  int ishom = 0;
737  if(cur_state == STATE_HOMING)
738  {
739 
740  ishom = 1;
741  }
742  snprintf(rvstr, 50, "%i\n", ishom);
743  return rvstr;
744  }
745 
746  if(com == "filter?")
747  {
748  return GetPosName(cur_pos);
749  }
750 
751  if(com.substr(0,3) == "pos")
752  {
753  std::cout << "pos " << control_mode << "\n";
754  if(control_mode == calling_ctype)
755  {
756  double pos = strtod(com.substr(3, com.size()-3).c_str(), 0);
757  std::cout << "Here we go\n";
758  rv = ChangePos(pos);
759  snprintf(rvstr, 5, "%i\n", rv);
760  return rvstr;
761  }
762  else
763  {
764  return control_mode_response();
765  }
766  }
767 
768  if(com.substr(0,6) == "filter")
769  {
770  if(control_mode == calling_ctype)
771  {
772  int idx = com.find_first_not_of(' ', 6);
773  std::string filt = com.substr(idx, com.size()-idx);
774  double pos = _customPos[filt];
775  //std::cout << "Moving to filter " << filt << " at " << pos << "\n";
776  rv = ChangePos(pos);
777  snprintf(rvstr, 5, "%i\n", rv);
778  return rvstr;
779  }
780  else
781  {
782  return control_mode_response();
783  }
784  }
785 
786  return "";
787 }
788 
790 {
791 
793  {
795 
797 
798  int status = cur_state;
799 
800  fwsb->state = status;
801  if(status == STATE_READY || status == STATE_OPERATING || status == STATE_HOMING)
802  {
803  var_pos_cur.Update();
804  var_pos_cur.Get(&cur_pos);
805 
806  fwsb->pos = cur_pos;
807 
808  //Update requested position
809  if(cur_state == STATE_HOMING)
810  {
811  std::cout << "STATE_HOMING\n";
812  //If homing was requested, then the home position should be sent
813  //Could also be homing without having a request (at startup)
814  fwsb->req_pos = _startingPos;
815  }
816  else if(cur_state == STATE_OPERATING)
817  {
818  std::cout << "STATE_OPERATING\n";
819  fwsb->req_pos = req_pos;
820  }
821  else
822  {
823  std::cout << "NOT MOVING\n";
824  fwsb->req_pos = cur_pos;
825  }
826 // else if (req_pos == _abortPos)
827 // {
828 // //If aborted, then current position is the requested position.
829 // fwsb->req_pos = cur_pos;
830 // }
831 // else
832 // {
833 // fwsb->req_pos = req_pos;
834 // }
835 
836  strncpy(fwsb->filter_name, GetPosName(fwsb->pos).c_str(), 50);
837  fwsb->type = GetType(fwsb->pos);
838  fwsb->req_type = GetType(fwsb->req_pos);
839  //std::cout << "rt= " << fwsb->req_type << std::endl;
840  }
841  }
842  return 0;
843 }
844 
845 
846 } //namespace VisAO
847 
RTDBvar var_status
The current status of the controller, STATE_CONNECTED, STATE_OPERATING,STATE_HOMING, etc.
A class to provide Filter Wheel functionality for the VisAO Camera.
virtual void updatePos(double pos)
Update position variables in RTDB.
virtual std::string local_command(std::string com)
VisAO local command fifo handler.
RTDBvar var_pos_cur
The current position.
fifo_list * global_fifo_list
The global fifo_list, for signal handling.
Definition: dioserver.cpp:19
double get_curr_time(void)
Gets the current CLOCK_REALTIME time, returns it in seconds to double precision.
Definition: libvisaoc.c:40
RTDBvar var_cmode_cur
The current control mode in the RTDB.
void readFilterConfig()
Read the corresponding filter wheel controller configuration file.
void SetupVars()
Virtual function to setup variables in RTDB.
std::string common_command(std::string com, int)
Where the command logic actually happens, since it is common.
int GetType(double pos)
Get the position type from the wheel position.
std::ostringstream logss
Conveninence string stream for building log messages.
void * statusboard_shmemptr
The pointer to the shared memory block for the statusboard.
virtual void error_report(int LogLevel, std::string emsg)
Report an error. Also calls log_msg.
std::string GetPosName(double pos)
Get the position name from wheel position.
Declarations for the FilterWheelLocal class, which interfaces with the VisAOSimpleMotorCtrl class via...
double getAbortPos()
Exposes the abort Position (_abortPos) for use in PosReqChanged (which is static) ...
std::string com_path
The control fifo path base name.
virtual int start_signal_catcher(bool inherit_sched=true)
Starts the signal catching loop.
virtual int update_statusboard()
Update the status board.
multimap< int, float >::iterator ctype_it
An iterator for accessing the custom pos list.
virtual int setup_baseApp(bool usethreads=false)
Install fifo channels.
int check_fifo_list_RTpending()
Check for pending reads for the fifo list while using the RT signals.
multimap< int, float > _customTypes
Custom filter types list.
int setup_fifo_list(int nfifos)
Allocate the fifo_list.
pthread_t signal_thread
The thread where fifo async signals are caught.
FilterWheelLocal(std::string name, const std::string &conffile)
Standard adopt style config file constructor.
static int PosCurChanged(void *pt, Variable *msgb)
RTDB handler for a position change by the AO Supervisor.
void Run()
The main loop.
key_t statusboard_shmemkey
The key used to lookup the shared memory.
RTDBvar var_pos_local_req
Position requester for local control.
int TimeToDie
Global set by SIGTERM.
std::string control_mode_response()
Convenience function to return the control type response string, e.g. "A\n".
std::string get_state_str()
Produce the state string for response to state?
fifo_list fl
The list of named-pipe fifos used for inter-process comms.
virtual std::string remote_command(std::string com)
VisAO remote command fifo handler.
void setupVisAOApp()
Basic setup of the class, called by both constructors.
double pause_time
Time to pause during application main loop.
Definition: VisAOApp_base.h:84
virtual int request_control(int cmode)
Calls request_control(cmode, 0).
int set_app_name(std::string an)
Set the application name.
RTDBvar var_pos_script_req
Position requester for script control.
int create_statusboard(size_t sz)
Creates and attaches to the statusboard shared memory.
RTDBvar var_cmode_req
The requested control mode in the RTDB.
void signal_catcher()
Signal loop, normally won't need to be overridden.
virtual std::string script_command(std::string com)
VisAO script command fifo handler.
int connect_fifo_list()
Connect the fifo_list with exclusive locking.
static int control_mode
The current control mode.
int setup_RTsigio()
Setup SIGIO signal handling using realtime signals.
The namespace of VisAO software.
RTDBvar var_pos_req
The requested position.
int ChangePos(double pos)
An interface to SimpleMotorCtrl::PosReqChanged for the fifo command processors.
virtual void log_msg(int LogLevel, std::string lmsg)
Log a message.
virtual void updateReq(double pos)
Update req position variables in RTDB.
virtual int update_statusboard()
Update the status board.
static int CModeCurChanged(void *pt, Variable *msgb)
RTDB handler for a control mode change request from the AO Supervisor.
map< std::string, float >::iterator cpos_it
An iterator for accessing the custom pos list.