00001
00114
00115 #ifndef SEESControl_H_
00116 #define SEESControl_H_
00117
00118 #include <list>
00119 #include <vector>
00120 #include <map>
00121 #include <ObjectsManager_LT.h>
00122 #include <TriggerOR.h>
00123 #include <TriggerOutput.h>
00124 #include <Trigger.h>
00125 #include "SEESMessages.h"
00126 #include "AutomatMessages.h"
00127 #include "APSLamp.h"
00128 #include "SEESControl_SK.h"
00129 #include "SEESGroup.h"
00130 #include "ASensor.h"
00131 #include "PriorityController.h"
00132 #include "UnionGroups.h"
00133
00134 class SEES;
00135 class Automat;
00136
00151 class SEESControl:
00152 public SEESControl_SK
00153 {
00154 public:
00155 SEESControl( int num, const std::string& sname, xmlNode* node=UniSetTypes::conf->getNode("SEESControl") );
00156 virtual ~SEESControl();
00157
00158 bool isAlone( int num );
00159 bool acceptQG( int num );
00160 void releaseQG( int num );
00162 bool canRun( int num );
00164 friend std::ostream& operator<<(std::ostream& os, SEESControl& am );
00165 friend std::ostream& operator<<(std::ostream& os, SEESControl* am );
00166
00167 enum Timers
00168 {
00169 tmUpdatePowerInfo,
00170 tmOffTimerBeg
00171 };
00172
00174 enum StructureObjectTypes
00175 {
00176 soUnknown,
00177 soSEESGroup,
00178 soAutomat,
00179 soASensor
00180 };
00181
00183 struct StructureObject
00184 {
00185 StructureObject( UnionGroups* group ):
00186 type(soSEESGroup),
00187 group(group),
00188 avt(0),
00189 asens(0)
00190 {}
00191
00192 StructureObject( Automat* avt ):
00193 type(soAutomat),
00194 group(0),
00195 avt(avt),
00196 asens(0)
00197 {}
00198
00199 StructureObject( ASensor* s ):
00200 type(soASensor),
00201 group(0),
00202 avt(0),
00203 asens(s)
00204 {}
00205
00206 StructureObjectTypes type;
00207 UnionGroups* group;
00208 Automat* avt;
00209 ASensor* asens;
00210
00211 friend std::ostream& operator<<(std::ostream& os, StructureObject& o );
00212 friend std::ostream& operator<<(std::ostream& os, StructureObject* o );
00213 };
00214
00215 typedef std::list<StructureObject> StructureObjectList;
00216
00217 struct Structure
00218 {
00219 Structure(){}
00220
00221 StructureObjectList lst;
00222
00223 void addGroup( UnionGroups* group );
00224 void addAutomat( Automat* avt );
00225 void addASensor( ASensor* asens );
00226
00227 };
00228
00229 friend std::ostream& operator<<(std::ostream& os, Structure* s );
00230 friend std::ostream& operator<<(std::ostream& os, const Structure& s );
00231
00232 static DebugStream dlog;
00233 static void init_dlog( DebugStream& dlog );
00234
00235 protected:
00236 SEESControl();
00237
00238 virtual void step();
00239 void processingMessage( UniSetTypes::VoidMessage *msg );
00240 void sensorInfo( UniSetTypes::SensorMessage *sm );
00241 void timerInfo( UniSetTypes::TimerMessage *tm );
00242 void seesInfo( SEESMessage *sm );
00243 void automatInfo( AutomatMessage* m );
00244 virtual void askSensors( UniversalIO::UIOCommand cmd );
00245
00246 void command( UniSetTypes::ObjectId id, bool st );
00247
00248 void setControl( bool state );
00249 bool checkSESProtection();
00250 void checkReservPower();
00251 void updatePowerInfo();
00252 void updateStructure();
00253 void updateGroupData();
00254
00255 private:
00256 void init();
00257 void buildSESList( xmlNode* confnode );
00258 void buildAutomatList( xmlNode* confnode );
00259 void buildOFFList( xmlNode* confnode );
00260 void buildStructure( xmlNode* confnode );
00261 void buildGroup( UniXML_iterator& it );
00262 void buildAutomat( UniXML_iterator& it );
00263 void buildASensor( UniXML_iterator& it );
00264
00265 int findAutomat( const std::string name );
00266 SEES* findSESByName( const std::string name );
00267 Automat* findAutomatByName( const std::string name );
00268
00269 PriorityController* prior;
00270
00272 TriggerOutput<SEESControl, UniSetTypes::ObjectId, bool>* msg;
00273
00274
00275 int maxWorkingDG;
00278
00279 typedef std::list<SEES*> SEESList;
00280 SEESList seslist;
00281
00282 GroupList grouplist;
00283 UniSetTypes::uniset_mutex grMutex;
00284 int qf_locked;
00285
00286 Structure sesStructure;
00287
00288 typedef std::list<ASensor*> ASensorList;
00289 ASensorList asenslist;
00290
00291 bool sesProtection;
00292
00293 int checkReservTime;
00294 int reservStatePause;
00295 int reservCommandTimeout;
00298
00299
00300 struct AInfo
00301 {
00302 AInfo():avt(0),pwr(0),name(""){}
00303 Automat* avt;
00304 int pwr;
00305 std::string name;
00306 };
00307
00308 typedef std::vector<AInfo> AList;
00309 AList alst;
00310
00311 struct OffInfo
00312 {
00313 OffInfo():a(-1),b(-1),off_msec(0),
00314 tmrRunning(false),
00315 prepare_mid(UniSetTypes::DefaultObjectId),
00316 mid(UniSetTypes::DefaultObjectId)
00317 {}
00318
00319 int a;
00320 int b;
00321 int off_msec;
00322 bool tmrRunning;
00323 UniSetTypes::ObjectId prepare_mid;
00324 UniSetTypes::ObjectId mid;
00325 };
00326
00327 typedef std::vector<OffInfo> OFFList;
00328 OFFList olst;
00329 void checkOffList( UniSetTypes::ObjectId id );
00330
00331 PassiveTimer ptCheckReservPower;
00332 int num;
00333
00334 PassiveTimer ptUpdatePowerInfo;
00336
00337 int f_min;
00338 int f_max;
00339 int U_min;
00340 int U_max;
00341 int f_msec;
00342 int U_msec;
00343 };
00344
00345 #endif // SEESControl_H_