- Timestamp:
- 09/01/11 15:24:26 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/biasctrl.cc
r11927 r11931 145 145 bool CheckMessageLength(int received, int expected, const string &msg) 146 146 { 147 if (received !=expected)148 return false;147 if (received==expected) 148 return true; 149 149 150 150 ostringstream str; … … 166 166 const uint16_t board = answer[2]&0xf; 167 167 168 /* 169 Out() << dec << setw(2) << board << '|' << wrap << " "; 170 if (id%8==7) 171 Out() << endl; 172 */ 173 168 174 if (fWrapCounter>=0) 169 175 { … … 171 177 { 172 178 ostringstream msg; 173 msg << "Corrupted answer : received wrap counter " << wrap << " is not last received counter (" << fWrapCounter << "+1)%8.";179 msg << "Corrupted answer (id=" << id << "): received wrap counter " << wrap << " doesn't match last received counter " << fWrapCounter << "."; 174 180 Error(msg); 175 181 return false; … … 184 190 msg << hex << setfill('0'); 185 191 msg << "Initial answer received:"; 186 msg << " 0x" << setw(2) << answer[0];187 msg << " 0x" << setw(2) << answer[1];188 msg << " 0x" << setw(2) << answer[2];192 msg << " 0x" << setw(2) << (int)answer[0]; 193 msg << " 0x" << setw(2) << (int)answer[1]; 194 msg << " 0x" << setw(2) << (int)answer[2]; 189 195 Message(msg); 190 196 191 if (status!=0 || ddd!=0 || error!=0 || board==0) 197 if (status!=0 || ddd!=0 || error!=0 || board!=0) 198 { 192 199 Warn("Initial answer doesn't seem to be a reset as naively expected."); 200 201 // FIXME: 202 //ostringstream msg; 203 //msg << hex << setfill('0'); 204 //msg << "S=" << status << " D=" << ddd << " E=" << error << " B=" << board; 205 //Message(msg); 206 } 193 207 194 208 fSendCounter = wrap; … … 299 313 300 314 // Now print the received message if requested by the user 301 if (fIsVerbose) 302 { 315 if (fIsVerbose/* && command!=kUpdate*/) 316 { 317 Out() << endl << kBold << dec << "Data received (size=" << bytes_received << "):" << endl; 318 Out() << " Command=" << command << " fWrapCounter=" << fWrapCounter << " fSendCounter=" << fSendCounter << " fIsInitializing=" << fIsInitializing << " fIsRamping=" << fIsRamping << endl; 319 Out() << hex << setfill('0'); 320 303 321 vector<uint32_t> vout((bytes_received/3)*4); 304 322 … … 306 324 { 307 325 vout[i] = 308 (uint32_t(fBuffer[i*3+ 0])<<16) |326 (uint32_t(fBuffer[i*3+2])<<16) | 309 327 (uint32_t(fBuffer[i*3+1])<< 8) | 310 (uint32_t(fBuffer[i*3+2])<< 0); 328 (uint32_t(fBuffer[i*3+0])<< 0); 329 330 Out() << setw(6) << vout[i] << " "; 331 if (i%8==7) 332 Out() << endl; 311 333 } 312 334 313 Out() << endl << kBold << "Data received (size=" << bytes_received << "):" << endl; 314 Out() << " fWrapCounter=" << fWrapCounter << " fSendCounter=" << fSendCounter << " fIsInitializing=" << fIsInitializing << " fIsRamping=" << fIsRamping << endl; 315 Out() << Converter::GetHex<uint32_t>(vout, 16) << endl; 335 //Out() << Converter::GetHex<uint32_t>(vout, 16) << endl; 316 336 } 317 337 … … 336 356 } 337 357 358 // Now we are ready to send a new message 359 // fWaitingForAnswer = false; 360 361 if (command==kSynchronize) 362 { 363 Message("Stream successfully synchronized."); 364 fIsInitializing = false; 365 366 // Cancel sending of the next 0 367 fSyncTimer.cancel(); 368 369 // Start continous reading of all channels 370 ScheduleUpdate(100); 371 return; 372 } 373 338 374 if (send_counter%8 != fWrapCounter) 339 375 { 340 376 ostringstream msg; 341 msg << "Corrupted answer: received wrap counter " << fWrapCounter << " is not send counter " << fSendCounter << "%8.";377 msg << "Corrupted answer: received wrap counter " << fWrapCounter << " is not send counter " << send_counter << "%8."; 342 378 Error(msg); 343 379 PostClose(false); 344 380 } 345 381 346 // Now we are ready to send a new message347 // fWaitingForAnswer = false;348 349 if (command==kSynchronize)350 {351 Message("Stream successfully synchronized.");352 fIsInitializing = false;353 354 // Cancel sending of the next 0355 fSyncTimer.cancel();356 357 // Start continous reading of all channels358 ScheduleUpdate(100);359 }360 382 361 383 // Take action depending on what is going on … … 367 389 UpdateV(); 368 390 UpdateA(); 369 return;370 391 } 371 392 … … 395 416 if (error==ba::error::basic_errors::operation_aborted) 396 417 { 397 Warn("Synchronization aborted..."); 398 fIsRamping = false; 418 if (fIsInitializing) 419 Warn("Synchronization aborted..."); 420 else 421 Info("Synchronization successfull."); 399 422 return; 400 423 } … … 417 440 418 441 ostringstream msg; 419 msg << "Synchronization time expired (" << counter << ")" << endl;442 msg << "Synchronization time expired (" << counter << ")"; 420 443 Info(msg); 421 444 … … 440 463 void ScheduleSync(int counter=0) 441 464 { 442 fSyncTimer.expires_from_now(boost::posix_time::milliseconds( 333));465 fSyncTimer.expires_from_now(boost::posix_time::milliseconds(1000)); 443 466 fSyncTimer.async_wait(boost::bind(&ConnectionBias::HandleSyncTimer, this, counter, dummy::error)); 444 467 } … … 453 476 fIsInitializing = true; 454 477 455 fVolt.assign( 0, kNumChannels);456 fVoltRef.assign( 0, kNumChannels);457 fVoltCmd.assign( 0, kNumChannels);478 fVolt.assign( kNumChannels, 0); 479 fVoltRef.assign(kNumChannels, 0); 480 fVoltCmd.assign(kNumChannels, 0); 458 481 459 482 // Send a single 0 (and possible two consecutive 0's 460 483 // to make sure we are in sync with the device) 461 484 PostMessage("\0", 1); 462 AsyncRead(ba::buffer(fBuffer, 3), kSynchronize, ++fSendCounter);485 AsyncRead(ba::buffer(fBuffer, 3), kSynchronize, 0);//++fSendCounter); 463 486 // fWaitingForAnswer = true; 464 487 … … 489 512 490 513 if (is_open()) 491 ReadAllChannels(true); 514 { 515 if (fIsRamping) 516 { 517 Info("Schedule of update timer skipped."); 518 ScheduleUpdate(fUpdateTime); 519 } 520 else 521 ReadAllChannels(true); 522 } 492 523 } 493 524 … … 540 571 { 541 572 dac[ch] = RampOneStep(ch); 542 if (dac[ch]!=fVolt[ch] )573 if (dac[ch]!=fVolt[ch] && fPresent[ch/kNumChannelsPerBoard]) 543 574 identical = false; 544 575 } … … 583 614 } 584 615 616 // Check whether the deadline has passed. We compare the deadline 617 // against the current time since a new asynchronous operation 618 // may have moved the deadline before this actor had a chance 619 // to run. 620 if (fRampTimer.expires_at() > ba::deadline_timer::traits_type::now()) 621 return; 622 585 623 fIsRamping = RampOneStep(); 586 624 } … … 588 626 void ScheduleRampStep() 589 627 { 628 Message("Schedule ramping"); 590 629 fRampTimer.expires_from_now(boost::posix_time::milliseconds(fRampTime)); 591 630 fRampTimer.async_wait(boost::bind(&ConnectionBias::HandleRampTimer, this, dummy::error)); … … 598 637 fUpdateTimer(ioservice), 599 638 fBuffer(3*kNumChannels), 600 fIsVerbose( true),639 fIsVerbose(false), 601 640 fVoltCmd(kNumChannels), 602 641 fVoltGapd(kNumChannels), … … 752 791 753 792 fIsRamping = RampOneStep(); 793 794 ostringstream msg; 795 msg << "Ramp=" << fIsRamping; 796 Message(msg); 754 797 } 755 798 … … 828 871 bool ExpertGlobalSetVolt(float volt) 829 872 { 830 return GlobalSetDac(volt*4096/90);873 return ExpertGlobalSetDac(volt*4096/90); 831 874 } 832 875 … … 1214 1257 T::AddEvent("REQUEST_STATUS", ConnectionBias::kConnected, ConnectionBias::kRamping) 1215 1258 (Wrapper(bind(&ConnectionBias::ReadAllChannels, &fBias, false))) 1216 (" ");1259 ("Asynchronously request the status (current) of all channels."); 1217 1260 1218 1261 T::AddEvent("RESET_OVER_CURRENT_STATUS", ConnectionBias::kConnected) 1219 1262 (Wrapper(bind(&ConnectionBias::OverCurrentReset, &fBias))) 1220 (" ");1263 ("NOT YET TESTED"); 1221 1264 1222 1265 … … 1224 1267 T::AddEvent("SET_GLOBAL_VOLTAGE", "F:1", ConnectionBias::kConnected, ConnectionBias::kRamping) 1225 1268 (bind(&StateMachineBias::SetGlobalVolt, this, placeholders::_1)) 1226 (" ");1269 ("Set all channels to a new reference voltage. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"); 1227 1270 1228 1271 T::AddEvent("SET_GLOBAL_DAC", "S:1", ConnectionBias::kConnected, ConnectionBias::kRamping) 1229 1272 (bind(&StateMachineBias::SetGlobalDac, this, placeholders::_1)) 1230 (" ");1273 ("Set all channels to a new DAC reference. Starts ramping if necessary. (This command is not realized with the GLOBAL SET command.)"); 1231 1274 1232 1275 T::AddEvent("SET_CHANNEL_VOLTAGE", "S:1;F:1", ConnectionBias::kConnected, ConnectionBias::kRamping) 1233 1276 (bind(&StateMachineBias::SetChannelVolt, this, placeholders::_1)) 1234 (" ");1277 ("Set a single channel a new reference voltage. Starts ramping if necessary."); 1235 1278 1236 1279 T::AddEvent("SET_CHANNEL_DAC", "S:1;S:1", ConnectionBias::kConnected, ConnectionBias::kRamping) 1237 1280 (bind(&StateMachineBias::SetChannelDac, this, placeholders::_1)) 1238 (" ");1281 ("Set a single channel a new DAC reference value. Starts ramping if necessary."); 1239 1282 1240 1283 T::AddEvent("SET_GAPD_REFERENCE_VOLTAGE", ConnectionBias::kConnected, ConnectionBias::kRamping) 1241 1284 (Wrapper(bind(&ConnectionBias::SetGapdVoltage, &fBias))) 1242 (" ");1285 ("Set all channels to their G-APD reference voltage. Starts ramping if necessary."); 1243 1286 1244 1287 T::AddEvent("SET_ZERO_VOLTAGE", ConnectionBias::kConnected, ConnectionBias::kRamping) 1245 1288 (Wrapper(bind(&ConnectionBias::SetZero, &fBias))) 1246 (" ");1289 ("Set all channels to a zero reference voltage. Starts ramping if necessary."); 1247 1290 1248 1291 … … 1258 1301 1259 1302 1260 T::AddEvent("PRINT", ConnectionBias::kConnected, ConnectionBias::k Ramping)1303 T::AddEvent("PRINT", ConnectionBias::kConnected, ConnectionBias::kExpertMode, ConnectionBias::kRamping) 1261 1304 (Wrapper(bind(&ConnectionBias::Print, &fBias))) 1262 1305 (""); … … 1265 1308 T::AddEvent("EXPERT_MODE", "B:1") 1266 1309 (bind(&StateMachineBias::SetExpertMode, this, placeholders::_1)) 1267 (" ");1310 ("Enable usage of expert commands (note that for safty reasons the are exclusive with the standard commands)"); 1268 1311 1269 1312 T::AddEvent("EXPERT_RESET", ConnectionBias::kExpertMode) 1270 1313 (Wrapper(bind(&ConnectionBias::ExpertReset, &fBias))) 1271 (" ");1314 ("Send the RESET command (note that this is possibly harmfull command)"); 1272 1315 1273 1316 T::AddEvent("EXPERT_SET_GLOBAL_VOLTAGE", "F:1", ConnectionBias::kExpertMode) 1274 1317 (bind(&StateMachineBias::ExpertSetGlobalVolt, this, placeholders::_1)) 1275 (" ");1318 ("Send the global set command. The given voltage is converted to DAC counts."); 1276 1319 1277 1320 T::AddEvent("EXPERT_SET_GLOBAL_DAC", "S:1", ConnectionBias::kExpertMode) 1278 1321 (bind(&StateMachineBias::ExpertSetGlobalDac, this, placeholders::_1)) 1279 (" ");1322 ("Send the global set command."); 1280 1323 1281 1324 T::AddEvent("EXPERT_SET_CHANNEL_VOLTAGE", "S:1;F:1", ConnectionBias::kExpertMode) 1282 1325 (bind(&StateMachineBias::ExpertSetChannelVolt, this, placeholders::_1)) 1283 (" ");1326 ("Send a single channel set command. The given voltage is converted to DAC commands."); 1284 1327 1285 1328 T::AddEvent("EXPERT_SET_CHANNEL_DAC", "S:1;S:1", ConnectionBias::kExpertMode) 1286 1329 (bind(&StateMachineBias::ExpertSetChannelDac, this, placeholders::_1)) 1287 (""); 1288 } 1330 ("Send a single channel set command."); 1331 } 1332 1333 ~StateMachineBias() { T::Warn("Implement rampming at shutdown!"); } 1289 1334 1290 1335 int EvalOptions(Configuration &conf) … … 1390 1435 ("ramp-time", var<uint16_t>(), "") 1391 1436 ("ramp-step", var<uint16_t>(), "") 1392 ("ramp-volt", var<float>(), "")1393 1437 ; 1394 1438
Note:
See TracChangeset
for help on using the changeset viewer.