- Timestamp:
- 05/25/11 13:43:41 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fadctrl.cc
r10811 r10816 1 #include <boost/bind.hpp> 1 2 #include <boost/bind.hpp> 2 3 #include <boost/array.hpp> … … 107 108 } 108 109 110 // FIXME FIXME FIXME. The data block could have the same size!!!!! 111 // !!!!!!!!!!!!!!!!!!! 109 112 if (bytes_received == sizeof(FAD::EventHeader)) 110 113 { … … 130 133 fBuffer.resize(fEventHeader.fPackageLength-sizeof(FAD::EventHeader)/2); 131 134 AsyncRead(ba::buffer(fBuffer)); 135 AsyncWait(fInTimeout, 50, &Connection::HandleReadTimeout); 132 136 133 137 return; 134 138 } 139 140 fInTimeout.cancel(); 135 141 136 142 if (ntohs(fBuffer.back())!=FAD::kDelimiterEnd) … … 198 204 } 199 205 206 void HandleReadTimeout(const bs::error_code &error) 207 { 208 if (error && error!=ba::error::basic_errors::operation_aborted) 209 { 210 ostringstream str; 211 str << "Read timeout of " << URL() << ": " << error.message() << " (" << error << ")";// << endl; 212 Error(str); 213 214 PostClose(); 215 return; 216 217 } 218 219 if (!is_open()) 220 { 221 // For example: Here we could schedule a new accept if we 222 // would not want to allow two connections at the same time. 223 return; 224 } 225 226 if (error==ba::error::basic_errors::operation_aborted) 227 return; 228 229 // Check whether the deadline has passed. We compare the deadline 230 // against the current time since a new asynchronous operation 231 // may have moved the deadline before this actor had a chance 232 // to run. 233 if (fInTimeout.expires_at() > ba::deadline_timer::traits_type::now()) 234 return; 235 236 Error("Timeout reading data from "+URL()); 237 PostClose(); 238 } 239 200 240 // This is called when a connection was established 201 241 void ConnectionEstablished() … … 213 253 // CmdSetRoi(i, 100); 214 254 215 Cmd( ConnectionFAD::kCmdTriggerLine, true);216 Cmd( ConnectionFAD::kCmdSingleTrigger);255 Cmd(FAD::kCmdTriggerLine, true); 256 Cmd(FAD::kCmdSingleTrigger); 217 257 } 218 258 … … 291 331 292 332 public: 293 enum Enable_t294 {295 kCmdDrsEnable = 0x0600, // CMD_DENABLE/CMD_DISABLE296 kCmdDwrite = 0x0800, // CMD_DWRITE_RUN/CMD_DWRITE_STOP297 kCmdSclk = 0x1000, // CMD_SCLK_ON/OFF298 kCmdSrclk = 0x1500, // CMD_SRCLK_ON/OFF299 kCmdTriggerLine = 0x1800, // CMD_TRIGGERS_ON/CMD_TRIGGERS_OFF300 //kCmdContTrigger = 0x1f00,301 kCmdContTriggerOff = 0x2000,302 kCmdRun = 0x2200, // CMD_Start/Stop303 kCmdResetTriggerId = 0x2A00, //304 kCmdSocket = 0x3000, // CMD_mode_command/CMD_mode_all_sockets305 kCmdSingleTrigger = 0xA000, // CMD_Trigger306 kCmdContTriggerOn = 0xB000,307 };308 309 private:310 enum311 {312 kCmdWrite = 0x0500, // write to Config-RAM313 kCmdWriteRoi = kCmdWrite|0x00, // Baseaddress ROI-Values314 kCmdWriteDac = kCmdWrite|0x24, // Baseaddress DAC-Values315 316 kCmdWriteRate = kCmdWrite|0x2c, // Continous trigger rate317 kCmdWriteRunNumber = kCmdWrite|0x2d, //318 319 /*320 kCmdRead = 0x0a00, // read from Config-RAM321 kCmdReadRoi = kCmdRead|0x00, // Baseaddress ROI-Values322 kCmdReadDac = kCmdRead|0x24, // Baseaddress DAC-Values323 */324 325 kCmdPhaseIncrease = 0x1200, // CMD_PS_DIRINC326 kCmdPhaseDecrease = 0x1300, // CMD_PS_DIRDEC327 kCmdPhaseApply = 0x1400, // CMD_PS_DO328 kCmdPhaseReset = 0x1700, // CMD_PS_RESET329 };330 331 public:332 333 ConnectionFAD(ba::io_service& ioservice, MessageImp &imp) : 333 334 Connection(ioservice, imp()), … … 338 339 } 339 340 340 void Cmd( Enable_tcmd, bool on=true)341 void Cmd(FAD::Enable cmd, bool on=true) 341 342 { 342 343 PostCmd(cmd + (on ? 0 : 0x100)); … … 348 349 void CmdPhaseShift(int16_t val) 349 350 { 350 vector<uint16_t> cmd(abs(val)+2, kCmdPhaseApply);351 cmd[0] = kCmdPhaseReset;352 cmd[1] = val<0 ? kCmdPhaseDecrease :kCmdPhaseIncrease;351 vector<uint16_t> cmd(abs(val)+2, FAD::kCmdPhaseApply); 352 cmd[0] = FAD::kCmdPhaseReset; 353 cmd[1] = val<0 ? FAD::kCmdPhaseDecrease : FAD::kCmdPhaseIncrease; 353 354 PostCmd(cmd); 354 355 } … … 359 360 return false; 360 361 361 PostCmd( kCmdWriteRate, val);//uint8_t(1000./val/12.5));362 PostCmd(FAD::kCmdWriteRate, val);//uint8_t(1000./val/12.5)); 362 363 //PostCmd(kCmdContTriggerRate, uint8_t(80/val)); 363 364 … … 369 370 // Allowed addr: [0, MAX_ADDR] 370 371 // Allowed value: [0, MAX_VAL] 371 PostCmd( kCmdWrite + addr, val);372 PostCmd(FAD::kCmdWrite + addr, val); 372 373 } 373 374 … … 377 378 return false; 378 379 379 PostCmd( kCmdWriteDac + addr, val);380 PostCmd(FAD::kCmdWriteDac + addr, val); 380 381 return true; 381 382 } … … 390 391 391 392 if (addr<0) 392 for (int i=0; i< FAD::kMaxRoiAddr; i++)393 PostCmd( kCmdWriteRoi + i, val);393 for (int i=0; i<=FAD::kMaxRoiAddr; i++) 394 PostCmd(FAD::kCmdWriteRoi + i, val); 394 395 else 395 PostCmd( kCmdWriteRoi + addr, val);396 PostCmd(FAD::kCmdWriteRoi + addr, val); 396 397 397 398 return true; … … 712 713 } 713 714 714 int Cmd( ConnectionFAD::Enable_tcommand)715 int Cmd(FAD::Enable command) 715 716 { 716 717 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) … … 720 721 } 721 722 722 int CmdEnable(const EventImp &evt, ConnectionFAD::Enable_tcommand)723 int CmdEnable(const EventImp &evt, FAD::Enable command) 723 724 { 724 725 if (!CheckEventSize(evt.GetSize(), "CmdEnable", 1)) … … 806 807 for (int nn=0; nn<n; nn++) 807 808 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 808 i->second.second->Cmd( ConnectionFAD::kCmdSingleTrigger);809 i->second.second->Cmd(FAD::kCmdSingleTrigger); 809 810 810 811 return T::GetCurrentState(); … … 827 828 828 829 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 829 i->second.second->Cmd( ConnectionFAD::kCmdRun, start);830 i->second.second->Cmd(FAD::kCmdRun, start); 830 831 831 832 return T::GetCurrentState(); … … 1218 1219 // FAD Commands 1219 1220 T::AddEvent("ENABLE_SRCLK", "B:1") 1220 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdSrclk))1221 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdSrclk)) 1221 1222 ("Set SRCLK"); 1222 1223 T::AddEvent("ENABLE_SCLK", "B:1") 1223 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdSclk))1224 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdSclk)) 1224 1225 ("Set SCLK"); 1225 1226 T::AddEvent("ENABLE_DRS", "B:1") 1226 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdDrsEnable))1227 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdDrsEnable)) 1227 1228 ("Switch Domino wave"); 1228 1229 T::AddEvent("ENABLE_DWRITE", "B:1") 1229 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdDwrite))1230 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdDwrite)) 1230 1231 ("Set Dwrite (possibly high / always low)"); 1231 1232 T::AddEvent("SET_DEBUG_MODE", "B:1") 1232 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdSocket))1233 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdSocket)) 1233 1234 ("Set debug mode (yes: dump events through command socket, no=dump events through other sockets)"); 1234 1235 T::AddEvent("ENABLE_TRIGGER_LINE", "B:1") 1235 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, ConnectionFAD::kCmdTriggerLine))1236 (boost::bind(&StateMachineFAD::CmdEnable, this, _1, FAD::kCmdTriggerLine)) 1236 1237 ("Incoming triggers can be accepted/will not be accepted"); 1237 1238 T::AddEvent("SET_TRIGGER_RATE", "I:1") … … 1255 1256 1256 1257 T::AddEvent("CONTINOUS_TRIGGER_ON") 1257 (boost::bind(&StateMachineFAD::Cmd, this, ConnectionFAD::kCmdContTriggerOn))1258 (boost::bind(&StateMachineFAD::Cmd, this, FAD::kCmdContTriggerOn)) 1258 1259 (""); 1259 1260 T::AddEvent("CONTINOUS_TRIGGER_OFF") 1260 (boost::bind(&StateMachineFAD::Cmd, this, ConnectionFAD::kCmdContTriggerOff))1261 (boost::bind(&StateMachineFAD::Cmd, this, FAD::kCmdContTriggerOff)) 1261 1262 (""); 1262 1263 1263 1264 T::AddEvent("RESET_TRIGGER_ID") 1264 (boost::bind(&StateMachineFAD::Cmd, this, ConnectionFAD::kCmdResetTriggerId))1265 (boost::bind(&StateMachineFAD::Cmd, this, FAD::kCmdResetTriggerId)) 1265 1266 (""); 1266 1267
Note:
See TracChangeset
for help on using the changeset viewer.