CARMA C++
CanCommand.h
Go to the documentation of this file.
1 
2 #ifndef SZA_ANTENNA_CANBUS_CANCOMMAND_H
3 #define SZA_ANTENNA_CANBUS_CANCOMMAND_H
4 
15 
16 #define CAN_COMMAND_DONE_HANDLER(fn) void (fn)(unsigned seq)
17 #define CAN_COMMAND_FAILED_HANDLER(fn) void (fn)(std::string commandName, std::string message)
18 #define CAN_EXECUTE_DONE_HANDLER(fn) void (fn)(sza::antenna::control::AntennaRxMsg::MsgType type)
19 
20 namespace sza {
21  namespace antenna {
22  namespace canbus {
23 
24  class CanCommand {
25  public:
26 
30  CanCommand();
31 
35  virtual ~CanCommand();
36 
40  virtual void init(unsigned seq);
41 
45  void ignoreErrors(bool ignorexo);
46 
50  bool isComplete();
51 
52  // A wrap up function to be called when this command is complete
53 
54  void registerCompletion();
55 
59  void installCommandDoneHandler(CAN_COMMAND_DONE_HANDLER(*handler));
60 
64  void installCommandFailedHandler(CAN_COMMAND_FAILED_HANDLER(*handler));
65 
69  void installExecuteDoneHandler(CAN_EXECUTE_DONE_HANDLER(*handler),
71 
72  // Reset to the beginning of the instruction list
73 
74  void reset();
75 
76  // Run this command
77 
78  void run();
79 
80  // Insert another command into this one
81 
82  void insert(CanCommand& command);
83 
84  protected:
85 
86  friend class CanInstruction;
87 
88  // An optional string identifying this command
89 
90  std::string commandName_;
91 
92  // True if this command is active
93 
94  bool active_;
95 
96  // True if we should ignore errors
97 
98  bool ignoreErrors_;
99 
100  // A vector of instructions
101 
102  std::vector<CanInstruction> instructions_;
103 
104  // The current instruction
105 
106  std::vector<CanInstruction>::iterator nextInstruction_;
107 
108  // Execute the next isntruction of this command
109 
110  CanInstruction::Type executeNextInstruction();
111 
112  // A callback for setting the state of a condition
113 
114  static CAN_MONITOR_CONDITION_HANDLER(conditionSatisfied);
115 
116  // A handler called when this command is complete
117 
118  CAN_COMMAND_DONE_HANDLER(*commandDoneHandler_);
119 
120  // A handler called if this command fails
121 
122  CAN_COMMAND_FAILED_HANDLER(*commandFailedHandler_);
123 
124  // A handler called when an instruction has been executed
125 
126  CAN_EXECUTE_DONE_HANDLER(*executeDoneHandler_);
128 
129  void insertWait(CanDevice* device);
130 
131  protected:
132 
133  // The last requested sequence number
134 
135  static unsigned lastReq_;
136 
137  // The last acknowledged sequence number
138 
139  static unsigned lastAck_;
140 
141  }; // End class CanCommand
142 
143  } // End namespace canbus
144  } // End namespace antenna
145 } // End namespace sza
146 
147 
148 
149 #endif // End #ifndef SZA_ANTENNA_CANBUS_CANCOMMAND_H
MsgType
Enumerate supported AntennaRx messages.
Definition: AntennaRxMsg.h:48
Started: Fri Nov 21 15:46:44 UTC 2003.
Tagged: Thu Nov 13 16:53:31 UTC 2003.
Tagged: Thu Oct 28 07:32:15 PDT 2004.