- Timestamp:
- 08/04/11 18:28:29 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/biasctrl.cc
r11578 r11775 47 47 #define RESISTOR float(1000) 48 48 49 protected: 49 50 50 51 vector<uint16_t> fVolt; // Voltage in DAC units … … 58 59 59 60 bool fResetHit; 61 62 virtual void UpdateA() 63 { 64 if (!fIsVerbose) 65 return; 66 67 for (int c=0; c<kNumChannels; c++) 68 { 69 Out() << setw(2) << c << ":"; 70 for (int b=0; b<kNumBoards; b++) 71 Out() << " " << setprecision(2) << fixed << setw(5) << fCurrent[b+c*kNumBoards]; 72 Out() << endl; 73 } 74 } 60 75 61 76 private: … … 137 152 fOC[i] = false; 138 153 } 154 155 UpdateA(); 139 156 } 140 157 … … 218 235 219 236 return data; 220 }221 222 void ReadAllChannelsStatus()223 {224 vector<char> data;225 data.reserve(kNumChannels*3);226 227 // Prepare command to read all channels228 for (int i=0; i<kNumChannels; i++)229 {230 const vector<char> cmd = GetCmd(i, kCmdRead);231 data.insert(data.end(), cmd.begin(), cmd.end());232 }233 234 PostMessage(data);235 237 } 236 238 … … 253 255 } 254 256 255 256 257 void SetChannels(const map<uint16_t, uint16_t> &vals) 257 258 { … … 305 306 } 306 307 */ 307 308 void SetReferenceCurrent()309 {310 fRefCurrent = fCurrent;311 }312 313 void GlobalSet(double voltage)314 {315 if (voltage>90)316 return;317 318 GlobalSetDac(voltage/90.0*0xfff);319 }320 321 // ***** Correct voltages according to current *****322 void AdaptVoltages()323 {324 map<uint16_t, uint16_t> values;325 326 for (int i=0; i<kNumChannels; i++)327 {328 if (fRefVolt[i]==0)329 continue;330 331 // Calculate difference and convert ADC units to Amps332 const double diffcur = (fRefCurrent[i]-fCurrent[i])*1.22;333 334 // Calculate voltage difference335 const double diffvolt = diffcur*RESISTOR/1e6;336 337 // Calculate new vlaue by onverting voltage difference to DAC units338 const int32_t dac = fRefVolt[i] + diffvolt/90.0*0xfff;339 340 if (dac<0 || dac>0xfff)341 continue;342 343 values[i] = fRefVolt[i] + dac;344 }345 346 SetChannels(values);347 348 /*349 static int LastUpdate = 0;350 if (time(NULL)-LastUpdate > 5)351 {352 LastUpdate = time(NULL);353 UpdateDIM();354 }*/355 }356 308 357 309 public: … … 368 320 } 369 321 322 bool GlobalSet(double voltage) 323 { 324 if (voltage<0 || voltage>90) 325 return false; 326 327 GlobalSetDac(voltage/90.0*0xfff); 328 329 return true; 330 } 331 332 void ReadAllChannelsStatus() 333 { 334 vector<char> data; 335 data.reserve(kNumChannels*3); 336 337 // Prepare command to read all channels 338 for (int i=0; i<kNumChannels; i++) 339 { 340 const vector<char> cmd = GetCmd(i, kCmdRead); 341 data.insert(data.end(), cmd.begin(), cmd.end()); 342 } 343 344 PostMessage(data); 345 } 346 347 // ***** Correct voltages according to current ***** 348 void AdaptVoltages() 349 { 350 map<uint16_t, uint16_t> values; 351 352 for (int i=0; i<kNumChannels; i++) 353 { 354 if (fRefVolt[i]==0) 355 continue; 356 357 // Calculate difference and convert ADC units to Amps 358 const double diffcur = (fRefCurrent[i]-fCurrent[i])*1.22; 359 360 // Calculate voltage difference 361 const double diffvolt = diffcur*RESISTOR/1e6; 362 363 // Calculate new vlaue by onverting voltage difference to DAC units 364 const int32_t dac = fRefVolt[i] + diffvolt/90.0*0xfff; 365 366 if (dac<0 || dac>0xfff) 367 continue; 368 369 values[i] = fRefVolt[i] + dac; 370 } 371 372 SetChannels(values); 373 374 /* 375 static int LastUpdate = 0; 376 if (time(NULL)-LastUpdate > 5) 377 { 378 LastUpdate = time(NULL); 379 UpdateDIM(); 380 }*/ 381 } 382 383 void SetReferenceCurrent() 384 { 385 fRefCurrent = fCurrent; 386 } 387 370 388 void SetVerbose(bool b) 371 389 { … … 383 401 384 402 DimDescribedService fDimCurrent; 385 386 void Update(DimDescribedService &svc, vector<float> data, float time) const 387 { 388 data.insert(data.begin(), time); 389 svc.setData(data.data(), data.size()*sizeof(float)); 390 svc.updateService(); 391 } 392 393 void UpdateCur(float time, const vector<float> &curr) 394 { 395 Update(fDimCurrent, curr, time); 396 } 403 DimDescribedService fDimVoltage; 404 405 void UpdateA() 406 { 407 fDimCurrent.Update(fCurrent); 408 ConnectionBias::UpdateA(); 409 } 410 411 /* 412 void UpdateV() 413 { 414 fDimCurrent.Update(fRefVolt); 415 }*/ 397 416 398 417 public: 399 418 ConnectionDimBias(ba::io_service& ioservice, MessageImp &imp) : 400 419 ConnectionBias(ioservice, imp), 401 fDimCurrent("BIAS_CONTROL/CURRENT", "F:1;F:4", "") 420 fDimCurrent("BIAS_CONTROL/CURRENT", "F:416", ""), 421 fDimVoltage("BIAS_CONTROL/VOLTAGE", "F:416", "") 402 422 { 403 423 } … … 422 442 } 423 443 444 bool CheckEventSize(size_t has, const char *name, size_t size) 445 { 446 if (has==size) 447 return true; 448 449 ostringstream msg; 450 msg << name << " - Received event has " << has << " bytes, but expected " << size << "."; 451 T::Fatal(msg); 452 return false; 453 } 454 424 455 private: 425 456 S fBias; … … 430 461 kStateConnected = 2, 431 462 }; 463 464 int SetGlobal(const EventImp &evt) 465 { 466 if (!CheckEventSize(evt.GetSize(), "SetGlobal", 4)) 467 return false; 468 469 if (!fBias.GlobalSet(evt.GetFloat())) 470 T::Error("Supplied voltage out of range (0-90)"); 471 472 return T::GetCurrentState(); 473 } 474 432 475 433 476 int Disconnect() … … 475 518 } 476 519 477 bool CheckEventSize(size_t has, const char *name, size_t size)478 {479 if (has==size)480 return true;481 482 ostringstream msg;483 msg << name << " - Received event has " << has << " bytes, but expected " << size << ".";484 T::Fatal(msg);485 return false;486 }487 488 520 int SetVerbosity(const EventImp &evt) 489 521 { … … 530 562 ("(Re)connect ethernet connection to FTM, a new address can be given" 531 563 "|[host][string]:new ethernet address in the form <host:port>"); 564 565 566 AddEvent("REQUEST_STATUS", kStateConnected) 567 (Wrap(bind(&ConnectionBias::ReadAllChannelsStatus, &fBias))) 568 (""); 569 570 AddEvent("SET_GLOBAL", "F:1", kStateConnected) 571 (bind(&StateMachineBias::SetGlobal, this, _1)) 572 (""); 573 574 AddEvent("RESET", kStateConnected) 575 (Wrap(bind(&ConnectionBias::SystemReset, &fBias))) 576 (""); 577 578 AddEvent("SET_REFERENCE_CURRENT", kStateConnected) 579 (Wrap(bind(&ConnectionBias::SetReferenceCurrent, &fBias))) 580 (""); 581 582 AddEvent("ADAPT_VOLTAGES", kStateConnected) 583 (Wrap(bind(&ConnectionBias::AdaptVoltages, &fBias))) 584 (""); 532 585 } 533 586
Note:
See TracChangeset
for help on using the changeset viewer.