Changeset 14514
- Timestamp:
- 10/24/12 10:34:39 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/pwrctrl.cc
r14451 r14514 26 26 using namespace std; 27 27 28 class Connection Lid: public Connection28 class ConnectionInterlock : public Connection 29 29 { 30 30 protected: 31 31 32 struct Lid 33 { 34 bool fc_ok; 35 bool bp_on; 36 bool il_on; 37 bool fl_ok; 38 bool fp_en; 39 bool x_on; 40 bool y_on; 41 bool z_on; 42 43 Lid() { } 32 struct Status 33 { 34 bool fWaterFlowOk; 35 bool fWaterLevelOk; 36 37 bool fPwrBiasOn; 38 bool fPwr24VOn; 39 bool fPwrPumpOn; 40 bool fPwrDriveOn; 41 42 bool fDriveMainSwitchOn; 43 bool fDriveFeedbackOn; 44 45 Status() { } 46 47 bool Set(bool &rc, const QString &value) 48 { 49 rc = value.toInt(); 50 return true; 51 } 44 52 45 53 bool Set(const QDomNamedNodeMap &map) 46 54 { 47 if (!map.contains("id") || !map.contains(" value"))55 if (!map.contains("id") || !map.contains("title")) 48 56 return false; 49 57 50 58 QString item = map.namedItem("id").nodeValue(); 51 QString value = map.namedItem("value").nodeValue(); 52 53 if (item==(QString("FC_OK"))) 54 { 55 fc_ok = value.toInt(); 56 return true; 57 } 58 59 if (item==(QString("BP_ON"))) 60 { 61 bp_on = value.toInt(); 62 return true; 63 } 64 65 if (item==(QString("IL_ON"))) 66 { 67 il_on = value.toInt(); 68 return true; 69 } 70 71 if (item==(QString("FL_OK"))) 72 { 73 fl_ok = value.toInt(); 74 return true; 75 } 76 77 if (item==(QString("FP_EN"))) 78 { 79 fp_en = value.toInt(); 80 return true; 81 } 82 83 if (item==(QString("X_ON"))) 84 { 85 x_on = value.toInt(); 86 return true; 87 } 88 89 if (item==(QString("Y_ON"))) 90 { 91 y_on = value.toInt(); 92 return true; 93 } 94 95 if (item==(QString("Z_ON"))) 96 { 97 z_on = value.toInt(); 98 return true; 99 } 59 QString value = map.namedItem("title").nodeValue(); 60 61 if (item==(QString("flow_meter"))) 62 return Set(fWaterFlowOk, value); 63 64 if (item==(QString("level"))) 65 return Set(fWaterLevelOk, value); 66 67 if (item==(QString("bias_power"))) 68 return Set(fPwrBiasOn, value); 69 70 if (item==(QString("power_24v"))) 71 return Set(fPwr24VOn, value); 72 73 if (item==(QString("pump"))) 74 return Set(fPwrPumpOn, value); 75 76 if (item==(QString("drive_power"))) 77 return Set(fPwrDriveOn, value); 78 79 if (item==(QString("drive_on"))) 80 return Set(fDriveMainSwitchOn, value); 81 82 if (item==(QString("drive_enable"))) 83 return Set(fDriveFeedbackOn, value); 100 84 101 85 return false; 102 86 } 103 87 88 void Print(ostream &out, const string &title, const bool &val, const string &t="enabled", const string &f="disabled") 89 { 90 out << setw(15) << (title+":"); 91 if (val) 92 out << kGreen << t << endl; 93 else 94 out << kRed << f << endl; 95 } 96 104 97 void Print(ostream &out) 105 98 { 106 out << "FC_OK=" << fc_ok << endl;107 out << "BP_ON=" << bp_on << endl;108 out << "IL_ON=" << il_on << endl;109 out << "FL_OK=" << fl_ok << endl;110 out << "FP_EN=" << fp_en << endl;111 out << "X_ON =" << x_on << endl;112 out << "Y_ON =" << y_on << endl;113 out << "Z_ON =" << z_on << endl;99 Print(out, "Water flow", fWaterFlowOk, "ok", "low"); 100 Print(out, "Water level", fWaterLevelOk, "ok", "low"); 101 Print(out, "Power bias", fPwrBiasOn); 102 Print(out, "Power 24V", fPwr24VOn); 103 Print(out, "Power pump", fPwrPumpOn); 104 Print(out, "Power drive", fPwrDriveOn); 105 Print(out, "Drive main", fDriveMainSwitchOn, "on", "off"); 106 Print(out, "Drive feedback", fDriveFeedbackOn, "on", "off"); 114 107 } 115 108 … … 130 123 Time fLastReport; 131 124 132 Lid fLid1;133 134 virtual void Update(const Lid&)125 Status fStatus; 126 127 virtual void Update(const Status &) 135 128 { 136 129 } … … 224 217 const QDomNamedNodeMap att = e.attributes(); 225 218 226 f Lid1.Set(att);219 fStatus.Set(att); 227 220 } 228 221 229 222 if (fIsVerbose) 230 223 { 231 f Lid1.Print(Out());224 fStatus.Print(Out()); 232 225 Out() << "------------------------------------------------------" << endl; 233 226 } 234 227 235 Update(f Lid1);228 Update(fStatus); 236 229 237 230 fRdfData = ""; … … 302 295 { 303 296 async_read_some(ba::buffer(fArray), 304 boost::bind(&Connection Lid::HandleRead, this,297 boost::bind(&ConnectionInterlock::HandleRead, this, 305 298 dummy::error, dummy::bytes_transferred)); 306 299 } … … 374 367 375 368 public: 376 Connection Lid(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()),369 ConnectionInterlock(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()), 377 370 fIsVerbose(true), fLastReport(Time::none), fKeepAlive(ioservice) 378 371 { … … 411 404 412 405 fKeepAlive.expires_from_now(boost::posix_time::seconds(fInterval)); 413 fKeepAlive.async_wait(boost::bind(&Connection Lid::HandleRequest,406 fKeepAlive.async_wait(boost::bind(&ConnectionInterlock::HandleRequest, 414 407 this, dummy::error)); 415 408 } … … 449 442 }; 450 443 451 const uint16_t Connection Lid::kMaxAddr = 0xfff;444 const uint16_t ConnectionInterlock::kMaxAddr = 0xfff; 452 445 453 446 // ------------------------------------------------------------------------ … … 455 448 #include "DimDescriptionService.h" 456 449 457 class ConnectionDimWeather : public Connection Lid450 class ConnectionDimWeather : public ConnectionInterlock 458 451 { 459 452 private: … … 462 455 public: 463 456 ConnectionDimWeather(ba::io_service& ioservice, MessageImp &imp) : 464 Connection Lid(ioservice, imp)/*,457 ConnectionInterlock(ioservice, imp)/*, 465 458 fDim("PWR_CONTROL/DATA", "S:2;F:2;F:2", 466 459 "|status[bool]:Lid1/2 open or closed" … … 470 463 } 471 464 472 void Update(const Lid &l1)473 465 void Update(const Status &status) 466 { 474 467 /* 475 468 struct DimData … … 508 501 509 502 template <class T, class S> 510 class StateMachine LidControl : public T, public ba::io_service, public ba::io_service::work503 class StateMachinePowerControl : public T, public ba::io_service, public ba::io_service::work 511 504 { 512 505 private: … … 594 587 595 588 public: 596 StateMachine LidControl(ostream &out=cout) :589 StateMachinePowerControl(ostream &out=cout) : 597 590 T(out, "LID_CONTROL"), ba::io_service::work(static_cast<ba::io_service&>(*this)), 598 591 fLid(*this, *this) … … 627 620 // Verbosity commands 628 621 T::AddEvent("SET_VERBOSE", "B") 629 (bind(&StateMachine LidControl::SetVerbosity, this, placeholders::_1))622 (bind(&StateMachinePowerControl::SetVerbosity, this, placeholders::_1)) 630 623 ("set verbosity state" 631 624 "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data"); 632 625 633 626 T::AddEvent("OPEN", Lid::State::kInconsistent, Lid::State::kClosed) 634 (bind(&StateMachine LidControl::Open, this));627 (bind(&StateMachinePowerControl::Open, this)); 635 628 636 629 T::AddEvent("CLOSE", Lid::State::kInconsistent, Lid::State::kOpen) 637 (bind(&StateMachine LidControl::Close, this));630 (bind(&StateMachinePowerControl::Close, this)); 638 631 639 632 T::AddEvent("POST", "C") 640 (bind(&StateMachine LidControl::Post, this, placeholders::_1))633 (bind(&StateMachinePowerControl::Post, this, placeholders::_1)) 641 634 ("set verbosity state" 642 635 "|verbosity[bool]:disable or enable verbosity for received data (yes/no), except dynamic data"); … … 664 657 int RunShell(Configuration &conf) 665 658 { 666 return Main::execute<T, StateMachine LidControl<S, R>>(conf);659 return Main::execute<T, StateMachinePowerControl<S, R>>(conf); 667 660 } 668 661 … … 742 735 { 743 736 if (conf.Get<bool>("no-dim")) 744 return RunShell<LocalStream, StateMachine, Connection Lid>(conf);737 return RunShell<LocalStream, StateMachine, ConnectionInterlock>(conf); 745 738 else 746 739 return RunShell<LocalStream, StateMachineDim, ConnectionDimWeather>(conf); … … 750 743 { 751 744 if (conf.Get<int>("console")==0) 752 return RunShell<LocalShell, StateMachine, Connection Lid>(conf);745 return RunShell<LocalShell, StateMachine, ConnectionInterlock>(conf); 753 746 else 754 return RunShell<LocalConsole, StateMachine, Connection Lid>(conf);747 return RunShell<LocalConsole, StateMachine, ConnectionInterlock>(conf); 755 748 } 756 749 else
Note:
See TracChangeset
for help on using the changeset viewer.