Changeset 14495 for trunk/FACT++/src


Ignore:
Timestamp:
10/19/12 13:38:50 (12 years ago)
Author:
tbretz
Message:
Added resume and auto-resume functionality.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/drivectrl.cc

    r14368 r14495  
    346346            // Status 4: Tracking
    347347            if (status1==0)
    348                 status1 = 0x100-Drive::State::kNotReady;
     348                status1 = StateMachineImp::kSM_Error - Drive::State::kNotReady;
    349349
    350350            const bool ready = (pdo3&0xef00ef)==0xef00ef;
     
    673673    sources fSources;
    674674
     675    string fLastCommand;  // Last tracking (RADEC) command
     676    int fAutoResume;      // 0: disabled, 1: enables, 2: resuming
     677
    675678    // Status 0: Error
    676679    // Status 1: Unlocked
     
    720723    int SendCommand(const string &str, bool upd=true)
    721724    {
     725        // This happens if fLastCommand should be send,
     726        // but the last command was not a tracking command
     727        if (str.empty())
     728        {
     729            T::Info("Last command was not a tracking command. RESUME ignored.");
     730            return T::GetCurrentState();
     731        }
     732
     733        fLastCommand = str.compare(0, 6, "RADEC ")==0 ? str : "";
     734
    722735        fDrive.PostMessage(str);
    723736        T::Message("Sending: "+str);
     
    727740
    728741        return T::GetCurrentState();
     742    }
     743
     744    int Resume()
     745    {
     746        if (fLastCommand.empty())
     747        {
     748            T::Info("Last command was not a tracking command. RESUME ignored.");
     749            return T::GetCurrentState();
     750        }
     751
     752        return SendCommand(fLastCommand, false);
    729753    }
    730754
     
    923947    }
    924948
     949    int SetAutoResume(const EventImp &evt)
     950    {
     951        if (!CheckEventSize(evt.GetSize(), "SetAutoResume", 1))
     952            return T::kSM_FatalError;
     953
     954        fAutoResume = evt.GetBool();
     955
     956        return T::GetCurrentState();
     957    }
     958
    925959    int Unlock()
    926960    {
     
    10541088        }
    10551089
    1056         return fDrive.GetState();
     1090        const int state = fDrive.GetState();
     1091
     1092        if (!fLastCommand.empty())
     1093        {
     1094            // If auto resume is enabled and the drive is in error,
     1095            // resume tracking
     1096            if (fAutoResume==1 && state==StateMachineImp::kSM_Error)
     1097            {
     1098                Resume();
     1099                fAutoResume = 2;
     1100            }
     1101
     1102            // If drive got out of the error state,
     1103            // enable auto resume again
     1104            if (fAutoResume==2 && state!=StateMachineImp::kSM_Error)
     1105                fAutoResume = 1;
     1106        }
     1107
     1108        return state;
    10571109    }
    10581110
     
    11451197             "|id:Wobble angle id (1 or 2)"
    11461198             "|Name[string]:Source name");
     1199
     1200        T::AddEvent("RESUME", StateMachineImp::kSM_Error)
     1201            (bind(&StateMachineDrive::Resume, this))
     1202            ("If drive is in Error state, this can b used to resume the last tracking command, if the last command sent to cosy was a tracking command.");
    11471203
    11481204        T::AddEvent("MOON", State::kArmed, State::kTracking)
     
    11921248            ("Stop any kind of movement.");
    11931249
     1250        T::AddEvent("SET_AUTORESUME", "B")
     1251            (bind(&StateMachineDrive::SetAutoResume, this, placeholders::_1))
     1252            ("Enable/disable auto resume"
     1253             "|resume[bool]:if enabled, drive is tracking and goes to error state, the last tracking command is repeated automatically.");
    11941254
    11951255        // Verbosity commands
    11961256        T::AddEvent("SET_VERBOSE", "B")
    11971257            (bind(&StateMachineDrive::SetVerbosity, this, placeholders::_1))
    1198             ("set verbosity state"
     1258            ("Set verbosity state"
    11991259             "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data");
    12001260
     
    13041364            }
    13051365        }
     1366
     1367        fAutoResume = conf.Get<bool>("auto-resume");
    13061368
    13071369        if (conf.Has("source-database"))
     
    13461408        ("source-database", var<string>(), "Database link as in\n\tuser:password@server[:port]/database.")
    13471409        ("source", vars<string>(), "Additional source entry in the form \"name,hh:mm:ss,dd:mm:ss\"")
     1410        ("auto-resume", po_bool(false), "Enable auto result during tracking")
    13481411        ;
    13491412
Note: See TracChangeset for help on using the changeset viewer.