Changeset 13911


Ignore:
Timestamp:
05/26/12 14:18:58 (12 years ago)
Author:
tbretz
Message:
Moved drivectrl headers to HeadersDrive.h and state machien states to namespace State
File:
1 edited

Legend:

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

    r13767 r13911  
    2222#endif
    2323
     24#include "HeadersDrive.h"
     25
    2426namespace ba = boost::asio;
    2527namespace bs = boost::system;
     
    2729
    2830using namespace std;
    29 
    30 // ------------------------------------------------------------------------
    31 
    32 namespace Drive
    33 {
    34     struct DimPointing
    35     {
    36     } __attribute__((__packed__));
    37 
    38     struct DimTracking
    39     {
    40     } __attribute__((__packed__));
    41 
    42     struct DimStarguider
    43     {
    44         double fMissZd;
    45         double fMissAz;
    46 
    47         double fNominalZd;
    48         double fNominalAz;
    49 
    50         double fCenterX;
    51         double fCenterY;
    52 
    53         double fBrightness;
    54 
    55         uint16_t fNumCorrelated;
    56         uint16_t fNumLeds;
    57         uint16_t fNumRings;
    58         uint16_t fNumStars;
    59 
    60     } __attribute__((__packed__));
    61 
    62     struct DimTPoint
    63     {
    64         double fRa;
    65         double fDec;
    66 
    67         double fNominalZd;
    68         double fNominalAz;
    69 
    70         double fPointingZd;
    71         double fPointingAz;
    72 
    73         double fFeedbackZd;
    74         double fFeedbackAz;
    75 
    76         uint16_t fNumLeds;
    77         uint16_t fNumRings;
    78  
    79         double fCenterX;
    80         double fCenterY;
    81         double fCenterMag;
    82 
    83         double fStarX;
    84         double fStarY;
    85         double fStarMag;
    86 
    87         double fRealMag;
    88 
    89     } __attribute__((__packed__));
    90 };
    91 
    92 
     31using namespace Drive;
    9332
    9433// ------------------------------------------------------------------------
     
    13574    }
    13675
    137     virtual void UpdateStarguider(const Time &, const Drive::DimStarguider &)
    138     {
    139     }
    140 
    141     virtual void UpdateTPoint(const Time &, const Drive::DimTPoint &, const string &)
     76    virtual void UpdateStarguider(const Time &, const DimStarguider &)
     77    {
     78    }
     79
     80    virtual void UpdateTPoint(const Time &, const DimTPoint &, const string &)
    14281    {
    14382    }
     
    252191                return;
    253192
    254             Drive::DimStarguider data;
     193            DimStarguider data;
    255194
    256195            data.fMissZd = misszd;
     
    308247                return;
    309248
    310             Drive::DimTPoint tpoint;
     249            DimTPoint tpoint;
    311250
    312251            tpoint.fRa         = ra;
     
    594533};
    595534
    596 const uint16_t ConnectionDrive::kMaxAddr = 0xfff;
     535const uint16_t ConnectionkMaxAddr = 0xfff;
    597536
    598537// ------------------------------------------------------------------------
     
    627566    }
    628567
    629     void UpdateTPoint(const Time &t, const Drive::DimTPoint &data,
     568    void UpdateTPoint(const Time &t, const DimTPoint &data,
    630569                      const string &name)
    631570    {
     
    708647class StateMachineDrive : public T, public ba::io_service, public ba::io_service::work
    709648{
    710     int Wrap(boost::function<void()> f)
    711     {
    712         f();
    713         return T::GetCurrentState();
    714     }
    715 
    716     boost::function<int(const EventImp &)> Wrapper(boost::function<void()> func)
    717     {
    718         return bind(&StateMachineDrive::Wrap, this, func);
    719     }
    720 
    721649private:
    722650    S fDrive;
    723 
    724     enum states_t
    725     {
    726         kStateDisconnected = 1,
    727         kStateConnected,
    728         kStateNotReady,
    729         kStateReady,
    730         kStateArmed,
    731         kStateMoving,
    732         kStateTracking,
    733     };
    734651
    735652    string fDatabase;
     
    1014931        fDrive(*this, *this)
    1015932    {
    1016         // ba::io_service::work is a kind of keep_alive for the loop.
    1017         // It prevents the io_service to go to stopped state, which
    1018         // would prevent any consecutive calls to run()
    1019         // or poll() to do nothing. reset() could also revoke to the
    1020         // previous state but this might introduce some overhead of
    1021         // deletion and creation of threads and more.
    1022 
    1023933        // State names
    1024         AddStateName(kStateDisconnected, "Disconnected",
     934        T::AddStateName(State::kDisconnected, "Disconnected",
    1025935                     "No connection to cosy");
    1026936
    1027         AddStateName(kStateConnected, "Connected",
     937        T::AddStateName(State::kConnected, "Connected",
    1028938                     "Cosy connected, drive stopped");
    1029939
    1030         AddStateName(kStateNotReady, "NotReady",
     940        T::AddStateName(State::kNotReady, "NotReady",
    1031941                     "Drive system not ready for movement");
    1032942
    1033         AddStateName(kStateReady, "Ready",
     943        T::AddStateName(State::kReady, "Ready",
    1034944                     "Drive system ready for movement");
    1035945
    1036         AddStateName(kStateArmed, "Armed",
     946        T::AddStateName(State::kArmed, "Armed",
    1037947                     "Cosy armed, drive stopped");
    1038948
    1039         AddStateName(kStateMoving, "Moving",
     949        T::AddStateName(State::kMoving, "Moving",
    1040950                     "Telescope moving");
    1041951
    1042         AddStateName(kStateTracking, "Tracking",
     952        T::AddStateName(State::kTracking, "Tracking",
    1043953                     "Telescope tracking");
    1044954
    1045         // kStateIdle
    1046         // kStateArmed
    1047         // kStateMoving
    1048         // kStateTracking
     955        // State::kIdle
     956        // State::kArmed
     957        // State::kMoving
     958        // State::kTracking
    1049959
    1050960        // Init
     
    1068978
    1069979        // Drive Commands
    1070         T::AddEvent("MOVE_TO", "D:2", kStateArmed)  // ->ZDAZ
     980        T::AddEvent("MOVE_TO", "D:2", State::kArmed)  // ->ZDAZ
    1071981            (bind(&StateMachineDrive::SendCoordinates, this, placeholders::_1, kPoint))
    1072982            ("Move the telescope to the given local coordinates"
     
    1074984             "|Az[deg]:Azimuth");
    1075985
    1076         T::AddEvent("TRACK", "D:2", kStateArmed)   // ->RADEC/GRB
     986        T::AddEvent("TRACK", "D:2", State::kArmed)   // ->RADEC/GRB
    1077987            (bind(&StateMachineDrive::SendCoordinates, this, placeholders::_1, kTrackSlow))
    1078988            ("Move the telescope to the given sky coordinates and start tracking them"
     
    1080990             "|Dec[deg]:Declination");
    1081991
    1082         T::AddEvent("WOBBLE", "D:4", kStateArmed)   // ->RADEC/GRB
     992        T::AddEvent("WOBBLE", "D:4", State::kArmed)   // ->RADEC/GRB
    1083993            (bind(&StateMachineDrive::Wobble, this, placeholders::_1))
    1084994            ("Move the telescope to the given wobble position around the given sky coordinates and start tracking them"
     
    1088998             "|Angle[deg]:Wobble angle");
    1089999
    1090         T::AddEvent("TRACK_SOURCE", "D:2;C", kStateArmed)   // ->RADEC/GRB
     1000        T::AddEvent("TRACK_SOURCE", "D:2;C", State::kArmed)   // ->RADEC/GRB
    10911001            (bind(&StateMachineDrive::Track, this, placeholders::_1))
    10921002            ("Move the telescope to the given wobble position around the given source and start tracking"
     
    10951005             "|Name[string]:Source name");
    10961006
    1097         T::AddEvent("MOON", kStateArmed)
     1007        T::AddEvent("MOON", State::kArmed)
    10981008            (bind(&StateMachineDrive::SendCommand, this, "MOON 0 0", true))
    10991009            ("Start tracking the moon");
    1100         T::AddEvent("VENUS", kStateArmed)
     1010        T::AddEvent("VENUS", State::kArmed)
    11011011            (bind(&StateMachineDrive::SendCommand, this, "CELEST 2 0 0", true))
    11021012            ("Start tracking Venus");
    1103         T::AddEvent("MARS", kStateArmed)
     1013        T::AddEvent("MARS", State::kArmed)
    11041014            (bind(&StateMachineDrive::SendCommand, this, "CELEST 4 0 0", true))
    11051015            ("Start tracking Mars");
    1106         T::AddEvent("JUPITER", kStateArmed)
     1016        T::AddEvent("JUPITER", State::kArmed)
    11071017            (bind(&StateMachineDrive::SendCommand, this, "CELEST 5 0 0", true))
    11081018            ("Start tracking Jupiter");
    1109         T::AddEvent("SATURN", kStateArmed)
     1019        T::AddEvent("SATURN", State::kArmed)
    11101020            (bind(&StateMachineDrive::SendCommand, this, "CELEST 6 0 0", true))
    11111021            ("Start tracking Saturn");
     
    11291039            ("Stop any kind of movement.");
    11301040
    1131 //        T::AddEvent("ARM", kStateConnected)
    1132 //            (bind(&StateMachineDrive::SendCommand, this, "ARM lock"))
     1041//        T::AddEvent("ARM", State::kConnected)
     1042//            (bind(&StateMachineSendCommand, this, "ARM lock"))
    11331043//            ("");
    11341044
     
    11411051
    11421052        // Conenction commands
    1143         AddEvent("DISCONNECT", kStateConnected, kStateArmed)
     1053        T::AddEvent("DISCONNECT", State::kConnected, State::kArmed)
    11441054            (bind(&StateMachineDrive::Disconnect, this))
    11451055            ("disconnect from ethernet");
    11461056
    1147         AddEvent("RECONNECT", "O", kStateDisconnected, kStateConnected, kStateArmed)
     1057        T::AddEvent("RECONNECT", "O", State::kDisconnected, State::kConnected, State::kArmed)
    11481058            (bind(&StateMachineDrive::Reconnect, this, placeholders::_1))
    11491059            ("(Re)connect ethernet connection to FTM, a new address can be given"
Note: See TracChangeset for help on using the changeset viewer.