28 ShutterRemoteControl::ShutterRemoteControl( std::string name, 
const std::string &conffile) 
throw (AOException) : 
AOApp(name, conffile)
 
   33 ShutterRemoteControl::ShutterRemoteControl( 
int argc, 
char **argv) 
throw (AOException) : 
AOApp( argc, argv)
 
   38 void ShutterRemoteControl::Create() 
throw (AOException)
 
   43    Logger::get()->log( Logger::LOG_LEV_TRACE, 
"ShutterRemoteControl Create");
 
   55 int ShutterRemoteControl::LoadConfig()
 
   59    std::string visao_root = getenv(
"VISAO_ROOT");
 
   62       pathtmp = (std::string)(ConfigDictionary())[
"fifo_path"];
 
   64    catch(Config_File_Exception)
 
   68    fifo_path = visao_root + 
"/" + pathtmp + 
"/shuttercontrol_com_remote_";
 
   69    _logger->log(Logger::LOG_LEV_INFO, 
"Set fifo_path: %s", fifo_path.c_str());
 
   77       wait_to = (float32)(ConfigDictionary())[
"wait_to"];
 
   78       _logger->log(Logger::LOG_LEV_INFO, 
"shutter timeout (wait_to) set to %f sec.", (
float) wait_to);
 
   80    catch(Config_File_Exception)
 
   82       wait_to = DEFAULT_WAIT_TO;
 
   83       _logger->log(Logger::LOG_LEV_INFO, 
"shutter timeout (wait_to) set to default: %f sec.", (
float) wait_to);
 
   88       wait_sleep = (float32)(ConfigDictionary())[
"wait_sleep"];
 
   89       _logger->log(Logger::LOG_LEV_INFO, 
"shutter comm. sleep (wait_sleep) set to %f sec.", (
float) wait_sleep);
 
   91    catch(Config_File_Exception)
 
   93       wait_sleep = DEFAULT_WAIT_SLEEP;
 
   94       _logger->log(Logger::LOG_LEV_INFO, 
"shutter comm. sleep (wait_sleep) set to default: %f sec.", (
float) wait_sleep);
 
  100 void ShutterRemoteControl::SetupVars()
 
  104       var_state_cur = RTDBvar( MyFullName(), 
"STATE", CUR_VAR, INT_VARIABLE, 1,1);
 
  105       var_state_req = RTDBvar( MyFullName(), 
"STATE", REQ_VAR, INT_VARIABLE, 1,1);
 
  107       var_sw_state = RTDBvar( MyFullName(), 
"SW_STATE", CUR_VAR, INT_VARIABLE, 1,1);
 
  108       var_hw_state = RTDBvar( MyFullName(), 
"HW_STATE", CUR_VAR, INT_VARIABLE, 1,1);
 
  110       var_cmode_cur = RTDBvar( MyFullName(), 
"ConMode", CUR_VAR, INT_VARIABLE, 1,1);
 
  111       var_cmode_req = RTDBvar( MyFullName(), 
"ConMode", REQ_VAR, INT_VARIABLE, 1,1);
 
  113    catch (AOVarException &e)  
 
  115       Logger::get()->log(Logger::LOG_LEV_FATAL, 
"%s:%s: %s", __FILE__, __LINE__, e.what().c_str());
 
  116       throw AOException(
"Error creating RTDB variables");
 
  119    this->Notify( var_state_req, ((ShutterRemoteControl *)
this)->StateReqChanged);
 
  120    this->Notify( var_cmode_req, ((ShutterRemoteControl *)
this)->CModeReqChanged);
 
  124 int ShutterRemoteControl::parse_state_string(std::string ansstr)
 
  129    int st, swst, hwst, pwrst;
 
  130    int sp = ansstr.find_first_of(
" \r\n", 0);
 
  131    tmp.assign(ansstr, 0, sp);
 
  148          var_state_cur.Set(0, 0, FORCE_SEND);
 
  149          var_sw_state.Set(0, 0, FORCE_SEND);
 
  150          var_hw_state.Set(0, 0, FORCE_SEND);
 
  151          var_cmode_cur.Set(cmode, 0, FORCE_SEND);
 
  152          setCurState(STATE_OPERATING);
 
  159    int sp2 = ansstr.find_first_of(
" \r\n", sp+1);
 
  160    tmp.assign(ansstr, sp+1, sp2-sp-1);
 
  161    st = atoi(tmp.c_str());
 
  163    sp2 = ansstr.find_first_of(
" \r\n", sp+1);
 
  164    tmp.assign(ansstr, sp+1, sp2-sp-1);
 
  165    swst = atoi(tmp.c_str());
 
  167    sp2 = ansstr.find_first_of(
" \r\n", sp+1);
 
  168    tmp.assign(ansstr, sp+1, sp2-sp-1);
 
  169    hwst = atoi(tmp.c_str());
 
  172    sp2 = ansstr.find_first_of(
" \r\n", sp+1);
 
  173    tmp.assign(ansstr, sp+1, sp2-sp-1);
 
  174    pwrst = atoi(tmp.c_str());
 
  176    if(pwrst) setCurState(STATE_READY);
 
  177    else setCurState(STATE_OFF);
 
  179    var_state_cur.Set(st, 0, FORCE_SEND);
 
  180    var_sw_state.Set(swst, 0, FORCE_SEND);
 
  181    var_hw_state.Set(hwst, 0, FORCE_SEND);
 
  182    var_cmode_cur.Set(cmode, 0, FORCE_SEND);
 
  190    gettimeofday(&tp, 0);
 
  191    return (
double) tp.tv_sec + ((double) tp.tv_usec)/1e6;
 
  195 int ShutterRemoteControl::TestNetwork(
void)
 
  199    pthread_mutex_lock(&mutex);
 
  203    stat = send_shutter_command(
"state?");
 
  206       Logger::get()->log( Logger::LOG_LEV_TRACE, 
"Shutter: Error sending test command");
 
  207       pthread_mutex_unlock(&mutex);
 
  215    startT = get_curr_t();
 
  217    while((fl.fifo_ch[0].server_response[0] == 
'\0') && (get_curr_t() - startT < wait_to))
 
  219       nusleep((
int) (wait_sleep * 1e6)); 
 
  224    if(fl.fifo_ch[0].server_response[0] == 
'\0')
 
  226       _logger->log(Logger::LOG_LEV_ERROR, 
"ShutterControl response timeout in TestNetwork.  wait_to=%f.", wait_to);
 
  229    else stat = NO_ERROR;
 
  231    pthread_mutex_unlock(&mutex);
 
  236       Logger::get()->log( Logger::LOG_LEV_TRACE, 
"Shutter: No answer to test command");
 
  237       return COMMUNICATION_ERROR;
 
  240    std::string ansstr = fl.fifo_ch[0].server_response;
 
  242    parse_state_string(ansstr);
 
  244    Logger::get()->log( Logger::LOG_LEV_TRACE, 
"Network test OK - answer %s", fl.fifo_ch[0].server_response);
 
  248 void ShutterRemoteControl::Run()
 
  250    signal(SIGIO, SIG_IGN);
 
  256    _logger->log( Logger::LOG_LEV_INFO, 
"Running...");
 
  264       catch (AOException &e) 
 
  266          _logger->log( Logger::LOG_LEV_ERROR, 
"Caught exception (at %s:%d): %s", __FILE__, __LINE__, e.what().c_str());
 
  275 int ShutterRemoteControl::DoFSM()
 
  279    static float delay=1.0;
 
  284       if(TestNetwork() != NO_ERROR) setCurState(STATE_NOCONNECTION);
 
  306    setCurState( getCurState());
 
  308    nusleep( (
unsigned int)(delay * 1e6));
 
  313 int ShutterRemoteControl::StateReqChanged(
void *pt, Variable *msgb)
 
  319    newstate = msgb->Value.Lv[0];
 
  321    if(newstate == 1) stat = ((ShutterRemoteControl *)pt)->send_shutter_command(
"open");
 
  322    if(newstate == -1) stat = ((ShutterRemoteControl *)pt)->send_shutter_command(
"close");
 
  329 int ShutterRemoteControl::CModeReqChanged(
void *pt, Variable *msgb)
 
  334    newstate = msgb->Value.Lv[0];
 
  336    if(newstate == 1) stat = ((ShutterRemoteControl *)pt)->send_shutter_command(
"REMOTE");
 
  337    if(newstate == 10) stat = ((ShutterRemoteControl *)pt)->send_shutter_command(
"XREMOTE");
 
  338    if(newstate == 0) stat = ((ShutterRemoteControl *)pt)->send_shutter_command(
"~REMOTE");
 
  344 int ShutterRemoteControl::send_shutter_command(
const char * com)
 
int write_fifo_channel(fifo_channel *fc, const char *com, int comlen)
Write data to the output channel. 
int setup_fifo_list(fifo_list *fl, int nch)
Setup a fifo_list. 
fifo_list * global_fifo_list
The global fifo_list, for signal handling. 
int read_fifo_channel(fifo_channel *fc)
Read data from the input fifo channel. 
pthread_mutex_t threadMutex
Mutex to lock out other threads during complex operations. 
int TimeToDie
Global set by SIGTERM. 
int connect_fifo_list(fifo_list *fl)
Open each fifo in the list, with exclusive lock on the input fifo. 
Declarations for shutter control from the AO Supervisor. 
The namespace of VisAO software. 
int set_fifo_list_channel(fifo_list *fl, int nch, int buffsz, const char *fin, const char *fout, int(*inp_hand)(fifo_channel *), void *adata)
Set the details of one channel in the list.