Changeset 10631 for trunk/FACT++/src/ftmctrl.cc
- Timestamp:
- 05/09/11 20:13:40 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/ftmctrl.cc
r10623 r10631 19 19 #include "Converter.h" 20 20 21 #include "FACT.h" 21 22 #include "tools.h" 22 23 … … 29 30 30 31 using namespace std; 31 using namespace FTM;32 32 33 33 // ------------------------------------------------------------------------ … … 91 91 return; 92 92 93 if (fHeader.fType== kDynamicData && !fIsDynamicOut)93 if (fHeader.fType==FTM::kDynamicData && !fIsDynamicOut) 94 94 return; 95 95 … … 153 153 154 154 Out() << "Received: "; 155 Out() << "H=" << fCounter[kHeader] << " "; 156 Out() << "S=" << fCounter[kStaticData] << " "; 157 Out() << "D=" << fCounter[kDynamicData] << " "; 158 Out() << "F=" << fCounter[kFtuList] << " "; 159 Out() << "E=" << fCounter[kErrorList] << " "; 160 Out() << "R=" << fCounter[kRegister] << endl; 161 } 162 163 void CheckConsistency() 164 { 165 if (fStaticData.IsEnabled(StaticData::kPedestal) != (fStaticData.GetSequencePed() >0) || 166 fStaticData.IsEnabled(StaticData::kLPint) != (fStaticData.GetSequenceLPint()>0) || 167 fStaticData.IsEnabled(StaticData::kLPext) != (fStaticData.GetSequenceLPext()>0)) 168 { 169 Warn("GeneralSettings not consistent with trigger sequence."); 170 } 171 155 Out() << "H=" << fCounter[FTM::kHeader] << " "; 156 Out() << "S=" << fCounter[FTM::kStaticData] << " "; 157 Out() << "D=" << fCounter[FTM::kDynamicData] << " "; 158 Out() << "F=" << fCounter[FTM::kFtuList] << " "; 159 Out() << "E=" << fCounter[FTM::kErrorList] << " "; 160 Out() << "R=" << fCounter[FTM::kRegister] << endl; 161 } 162 163 bool CheckConsistency() 164 { 165 bool warn1 = false; 166 if (fStaticData.IsEnabled(FTM::StaticData::kPedestal) != (fStaticData.GetSequencePed() >0) || 167 fStaticData.IsEnabled(FTM::StaticData::kLPint) != (fStaticData.GetSequenceLPint()>0) || 168 fStaticData.IsEnabled(FTM::StaticData::kLPext) != (fStaticData.GetSequenceLPext()>0)) 169 { 170 warn1 = true; 171 fStaticData.Enable(FTM::StaticData::kPedestal, fStaticData.GetSequencePed()>0); 172 fStaticData.Enable(FTM::StaticData::kLPint, fStaticData.GetSequenceLPint()>0); 173 fStaticData.Enable(FTM::StaticData::kLPext, fStaticData.GetSequenceLPext()>0); 174 } 175 176 bool warn2 = false; 172 177 const uint16_t ref = fStaticData[0].fPrescaling; 173 178 for (int i=1; i<40; i++) … … 175 180 if (fStaticData[i].fPrescaling != ref) 176 181 { 177 Warn("Prescaling not consistent for all boards.");178 break;182 warn2 = true; 183 fStaticData[i].fPrescaling = ref; 179 184 } 180 185 } 181 186 187 if (warn1) 188 Warn("GeneralSettings not consistent with trigger sequence."); 189 if (warn2) 190 Warn("Prescaling not consistent for all boards."); 191 192 return !warn1 && !warn2; 182 193 } 183 194 … … 223 234 224 235 // Check the data integrity 225 if (fHeader.fDelimiter!= kDelimiterStart)236 if (fHeader.fDelimiter!=FTM::kDelimiterStart) 226 237 { 227 238 stringstream str; 228 str << "Invalid header received: start delimiter wrong, received " << hex << fHeader.fDelimiter << " expected " << kDelimiterStart << ".";239 str << "Invalid header received: start delimiter wrong, received " << hex << fHeader.fDelimiter << " expected " << FTM::kDelimiterStart << "."; 229 240 Error(str); 230 241 PostClose(false); … … 248 259 } 249 260 250 if (++fCounter[ kHeader]==1)261 if (++fCounter[FTM::kHeader]==1) 251 262 UpdateFirstHeader(); 252 263 … … 257 268 switch (fHeader.fType) 258 269 { 259 case kStaticData:260 case kDynamicData:261 case kFtuList:262 case kRegister:263 case kErrorList:270 case FTM::kStaticData: 271 case FTM::kDynamicData: 272 case FTM::kFtuList: 273 case FTM::kRegister: 274 case FTM::kErrorList: 264 275 // This is not very efficient because the space is reallocated 265 276 // maybe we can check if the capacity of the std::vector … … 286 297 stringstream str; 287 298 str << "Invalid data received: end delimiter wrong, received "; 288 str << hex << ntohs(fBuffer.back()) << " expected " << kDelimiterEnd << ".";299 str << hex << ntohs(fBuffer.back()) << " expected " << FTM::kDelimiterEnd << "."; 289 300 Error(str); 290 301 PostClose(false); … … 307 318 switch (fHeader.fType) 308 319 { 309 case kFtuList:320 case FTM::kFtuList: 310 321 fFtuList = fBuffer; 311 322 UpdateFtuList(); 312 323 break; 313 324 314 case kStaticData:325 case FTM::kStaticData: 315 326 fStaticData = fBuffer; 316 327 317 if (fCounter[kStaticData]==1) 318 CheckConsistency(); 328 if (fCounter[FTM::kStaticData]==1) 329 if (!CheckConsistency()) 330 { 331 CmdSendStatDat(); 332 break; 333 } 319 334 320 335 UpdateStaticData(); 321 336 break; 322 337 323 case kDynamicData:338 case FTM::kDynamicData: 324 339 fDynamicData = fBuffer; 325 340 UpdateDynamicData(); 326 341 break; 327 342 328 case kRegister:343 case FTM::kRegister: 329 344 if (fIsVerbose) 330 345 { … … 335 350 break; 336 351 337 case kErrorList:352 case FTM::kErrorList: 338 353 fError = fBuffer; 339 354 UpdateError(); … … 478 493 void CmdToggleLed() 479 494 { 480 PostCmd( kCmdToggleLed);495 PostCmd(FTM::kCmdToggleLed); 481 496 } 482 497 483 498 void CmdPing() 484 499 { 485 PostCmd( kCmdPing);500 PostCmd(FTM::kCmdPing); 486 501 } 487 502 488 503 void CmdReqDynDat() 489 504 { 490 PostCmd( kCmdRead,kReadDynamicData);505 PostCmd(FTM::kCmdRead, FTM::kReadDynamicData); 491 506 } 492 507 493 508 void CmdReqStatDat() 494 509 { 495 PostCmd( kCmdRead,kReadStaticData);510 PostCmd(FTM::kCmdRead, FTM::kReadStaticData); 496 511 } 497 512 498 513 void CmdSendStatDat() 499 514 { 500 PostCmd(fStaticData.HtoN(), kCmdWrite, kWriteStaticData); 501 502 // Request the changed configuration to ensure the 503 // change is distributed in the network 504 //CmdReqStatDat(); 505 } 506 507 void CmdStartRun() 508 { 509 PostCmd(kCmdStartRun, kStartRun); 510 511 // Update state information by requesting a new header 512 CmdGetRegister(0); 513 } 514 515 void CmdStopRun() 516 { 517 PostCmd(kCmdStopRun); 518 519 // Update state information by requesting a new header 520 CmdGetRegister(0); 521 } 522 523 void CmdTakeNevents(uint32_t n) 524 { 525 const boost::array<uint16_t, 2> data = {{ uint16_t(n>>16), uint16_t(n&0xffff) }}; 526 PostCmd(data, kCmdStartRun, kTakeNevents); 527 528 // Update state information by requesting a new header 529 CmdGetRegister(0); 530 } 531 532 bool CmdSetRegister(uint16_t addr, uint16_t val) 533 { 534 if (addr>kMaxAddr) 535 return false; 536 537 const boost::array<uint16_t, 2> data = {{ addr, val }}; 538 PostCmd(data, kCmdWrite, kWriteRegister); 515 PostCmd(fStaticData.HtoN(), FTM::kCmdWrite, FTM::kWriteStaticData); 539 516 540 517 // Request the changed configuration to ensure the 541 518 // change is distributed in the network 542 519 CmdReqStatDat(); 543 544 return true; 545 } 546 547 bool CmdGetRegister(uint16_t addr) 520 } 521 522 void CmdStartRun() 523 { 524 PostCmd(FTM::kCmdStartRun, FTM::kStartRun); 525 526 // Update state information by requesting a new header 527 CmdGetRegister(0); 528 } 529 530 void CmdStopRun() 531 { 532 PostCmd(FTM::kCmdStopRun); 533 534 // Update state information by requesting a new header 535 CmdGetRegister(0); 536 } 537 538 void CmdTakeNevents(uint32_t n) 539 { 540 const boost::array<uint16_t, 2> data = {{ uint16_t(n>>16), uint16_t(n&0xffff) }}; 541 PostCmd(data, FTM::kCmdStartRun, FTM::kTakeNevents); 542 543 // Update state information by requesting a new header 544 CmdGetRegister(0); 545 } 546 547 bool CmdSetRegister(uint16_t addr, uint16_t val) 548 548 { 549 549 if (addr>kMaxAddr) 550 550 return false; 551 551 552 const boost::array<uint16_t, 2> data = {{ addr, val }}; 553 PostCmd(data, FTM::kCmdWrite, FTM::kWriteRegister); 554 555 // Request the changed configuration to ensure the 556 // change is distributed in the network 557 CmdReqStatDat(); 558 559 return true; 560 } 561 562 bool CmdGetRegister(uint16_t addr) 563 { 564 if (addr>kMaxAddr) 565 return false; 566 552 567 const boost::array<uint16_t, 1> data = {{ addr }}; 553 PostCmd(data, kCmdRead,kReadRegister);568 PostCmd(data, FTM::kCmdRead, FTM::kReadRegister); 554 569 555 570 return true; … … 558 573 bool CmdDisableReports(bool b) 559 574 { 560 PostCmd( kCmdDisableReports, b ? uint16_t(0) : uint16_t(1));575 PostCmd(FTM::kCmdDisableReports, b ? uint16_t(0) : uint16_t(1)); 561 576 return true; 562 577 } … … 742 757 bool SetTriggerInterval(uint32_t val) 743 758 { 744 return SetVal(&fStaticData.fTriggerInterval, val, StaticData::kMaxTriggerInterval); 759 return SetVal(&fStaticData.fTriggerInterval, val, 760 FTM::StaticData::kMaxTriggerInterval); 745 761 } 746 762 747 763 bool SetTriggerDelay(uint32_t val) 748 764 { 749 return SetVal(&fStaticData.fDelayTrigger, val, StaticData::kMaxDelayTrigger); 765 return SetVal(&fStaticData.fDelayTrigger, val, 766 FTM::StaticData::kMaxDelayTrigger); 750 767 } 751 768 752 769 bool SetTimeMarkerDelay(uint32_t val) 753 770 { 754 return SetVal(&fStaticData.fDelayTimeMarker, val, StaticData::kMaxDelayTimeMarker); 771 return SetVal(&fStaticData.fDelayTimeMarker, val, 772 FTM::StaticData::kMaxDelayTimeMarker); 755 773 } 756 774 757 775 bool SetDeadTime(uint32_t val) 758 776 { 759 return SetVal(&fStaticData.fDeadTime, val, StaticData::kMaxDeadTime); 777 return SetVal(&fStaticData.fDeadTime, val, 778 FTM::StaticData::kMaxDeadTime); 760 779 } 761 780 … … 770 789 const uint16_t oldseq = fStaticData.fTriggerSequence; 771 790 772 fStaticData.Enable( StaticData::kPedestal, d[0]>0);773 fStaticData.Enable( StaticData::kLPext, d[1]>0);774 fStaticData.Enable( StaticData::kLPint, d[2]>0);775 776 if (d[0]> StaticData::kMaxSequence ||777 d[1]> StaticData::kMaxSequence ||778 d[2]> StaticData::kMaxSequence)791 fStaticData.Enable(FTM::StaticData::kPedestal, d[0]>0); 792 fStaticData.Enable(FTM::StaticData::kLPext, d[1]>0); 793 fStaticData.Enable(FTM::StaticData::kLPint, d[2]>0); 794 795 if (d[0]>FTM::StaticData::kMaxSequence || 796 d[1]>FTM::StaticData::kMaxSequence || 797 d[2]>FTM::StaticData::kMaxSequence) 779 798 return false; 780 799 … … 790 809 bool SetTriggerCoincidence(uint16_t n, uint16_t win) 791 810 { 792 if (n==0 || n>StaticData::kMaxCoincidence || win>StaticData::kMaxWindow) 811 if (n==0 || n>FTM::StaticData::kMaxCoincidence || 812 win>FTM::StaticData::kMaxWindow) 793 813 return false; 794 814 … … 807 827 bool SetCalibCoincidence(uint16_t n, uint16_t win) 808 828 { 809 if (n==0 || n>StaticData::kMaxCoincidence || win>StaticData::kMaxWindow) 829 if (n==0 || n>FTM::StaticData::kMaxCoincidence || 830 win>FTM::StaticData::kMaxWindow) 810 831 return false; 811 832 … … 855 876 ConnectionFTM::UpdateFirstHeader(); 856 877 857 const DimPassport data(fHeader);878 const FTM::DimPassport data(fHeader); 858 879 Update(fDimPassport, data); 859 880 } … … 863 884 ConnectionFTM::UpdateHeader(); 864 885 865 const DimTriggerCounter data(fHeader);886 const FTM::DimTriggerCounter data(fHeader); 866 887 Update(fDimTriggerCounter, data); 867 888 } … … 871 892 ConnectionFTM::UpdateFtuList(); 872 893 873 const DimFtuList data(fHeader, fFtuList);894 const FTM::DimFtuList data(fHeader, fFtuList); 874 895 Update(fDimFtuList, data); 875 896 } … … 879 900 ConnectionFTM::UpdateStaticData(); 880 901 881 const DimStaticData data(fHeader, fStaticData);902 const FTM::DimStaticData data(fHeader, fStaticData); 882 903 Update(fDimStaticData, data); 883 904 } … … 887 908 ConnectionFTM::UpdateDynamicData(); 888 909 889 const DimDynamicData data(fHeader, fDynamicData);910 const FTM::DimDynamicData data(fHeader, fDynamicData); 890 911 Update(fDimDynamicData, data); 891 912 } … … 895 916 ConnectionFTM::UpdateError(); 896 917 897 const DimError data(fHeader, fError);918 const FTM::DimError data(fHeader, fError); 898 919 Update(fDimError, data); 899 920 } … … 905 926 const uint32_t counter[6] = 906 927 { 907 fCounter[ kHeader],908 fCounter[ kStaticData],909 fCounter[ kDynamicData],910 fCounter[ kFtuList],911 fCounter[ kErrorList],912 fCounter[ kRegister],928 fCounter[FTM::kHeader], 929 fCounter[FTM::kStaticData], 930 fCounter[FTM::kDynamicData], 931 fCounter[FTM::kFtuList], 932 fCounter[FTM::kErrorList], 933 fCounter[FTM::kRegister], 913 934 }; 914 935 … … 919 940 ConnectionDimFTM(ba::io_service& ioservice, MessageImp &imp) : 920 941 ConnectionFTM(ioservice, imp), 921 fDimPassport ("FTM_CONTROL/PASSPORT", "X:1;S:1", NULL, 0,""),922 fDimTriggerCounter("FTM_CONTROL/TRIGGER_COUNTER", "X:1; L:1", NULL, 0, ""),923 fDimError ("FTM_CONTROL/ERROR", "X:1;S:1;S:28", NULL, 0,""),924 fDimFtuList ("FTM_CONTROL/FTU_LIST", "X:1;X:1;S:1;C:4;X:40;C:40;C:40", NULL, 0,""),925 fDimStaticData ("FTM_CONTROL/STATIC_DATA", "X:1;S:1;S:1;X:1;S:1;S:3;S:1;S:1;S:1;S:1;S:1;S:1;I:1;S:8;S:80;S:160;S:40;S:40", NULL, 0,""),926 fDimDynamicData ("FTM_CONTROL/DYNAMIC_DATA", "X:1;X:1;F:4;I:160;I:40;S:40;S:40", NULL, 0,""),927 fDimCounter ("FTM_CONTROL/COUNTER", "I:6", NULL, 0,"")942 fDimPassport ("FTM_CONTROL/PASSPORT", "X:1;S:1", ""), 943 fDimTriggerCounter("FTM_CONTROL/TRIGGER_COUNTER", "X:1;S:1;S:1;S:2;S:1;S:1;S:21;S:1;S:1", ""), 944 fDimError ("FTM_CONTROL/ERROR", "X:1;S:1;S:28", ""), 945 fDimFtuList ("FTM_CONTROL/FTU_LIST", "X:1;X:1;S:1;C:4;X:40;C:40;C:40", ""), 946 fDimStaticData ("FTM_CONTROL/STATIC_DATA", "X:1;S:1;S:1;X:1;S:1;S:3;S:1;S:1;S:1;S:1;S:1;S:1;I:1;S:8;S:80;S:160;S:40;S:40", ""), 947 fDimDynamicData ("FTM_CONTROL/DYNAMIC_DATA", "X:1;X:1;F:4;I:160;I:40;S:40;S:40", ""), 948 fDimCounter ("FTM_CONTROL/COUNTER", "I:6", "") 928 949 { 929 950 } … … 1522 1543 { 1523 1544 SetEndpoint(conf.Get<string>("addr")); 1545 1546 fFTM.SetVerbose(conf.Get<bool>("verbose")); 1547 fFTM.SetHexOutput(conf.Get<bool>("hex-out")); 1548 fFTM.SetDynamicOut(conf.Get<bool>("dynamic-out")); 1549 1524 1550 return true; 1525 1551 } … … 1626 1652 po::options_description control("FTM control options"); 1627 1653 control.add_options() 1628 ("addr", var<string>("localhost:5000"), "Network address of FTM") 1654 ("addr,a", var<string>("localhost:5000"), "Network address of FTM") 1655 ("verbose,v", po_switch(), "Enable printing contents of all received messages (except dynamic data) in clear text.") 1656 ("hex-out", po_switch(), "Enable printing contents of all printed messages also as hex data.") 1657 ("dynamic-out", po_switch(), "Enable printing received dynamic data.") 1629 1658 ; 1630 1659 … … 1655 1684 "\n" 1656 1685 "Usage: ftmctrl [-c type] [OPTIONS]\n" 1657 " or: ftmctrl [OPTIONS]\n" 1658 "\n" 1659 "Options:\n" 1660 "The following describes the available commandline options. " 1661 "For further details on how command line option are parsed " 1662 "and in which order which configuration sources are accessed " 1663 "please refer to the class reference of the Configuration class."; 1686 " or: ftmctrl [OPTIONS]\n"; 1664 1687 cout << endl; 1665 1666 1688 } 1667 1689 1668 1690 void PrintHelp() 1669 1691 { 1692 /* Additional help text which is printed after the configuration 1693 options goes here */ 1694 1695 /* 1696 cout << "bla bla bla" << endl << endl; 1697 cout << endl; 1698 cout << "Environment:" << endl; 1699 cout << "environment" << endl; 1700 cout << endl; 1701 cout << "Examples:" << endl; 1702 cout << "test exam" << endl; 1703 cout << endl; 1704 cout << "Files:" << endl; 1705 cout << "files" << endl; 1706 cout << endl; 1707 */ 1670 1708 } 1671 1709 1672 /*1673 The first line of the --version information is assumed to be in one1674 of the following formats:1675 1676 <version>1677 <program> <version>1678 {GNU,Free} <program> <version>1679 <program> ({GNU,Free} <package>) <version>1680 <program> - {GNU,Free} <package> <version>1681 1682 and separated from any copyright/author details by a blank line.1683 1684 Handle multi-line bug reporting sections of the form:1685 1686 Report <program> bugs to <addr>1687 GNU <package> home page: <url>1688 ...1689 */1690 void PrintVersion(const char *name)1691 {1692 cout <<1693 name << " - "PACKAGE_STRING"\n"1694 "\n"1695 "Written by Thomas Bretz et al.\n"1696 "\n"1697 "Report bugs to <"PACKAGE_BUGREPORT">\n"1698 "Home page: "PACKAGE_URL"\n"1699 "\n"1700 "Copyright (C) 2011 by the FACT Collaboration.\n"1701 "This is free software; see the source for copying conditions.\n"1702 << endl;1703 }1704 1710 /* 1705 1711 string GetLocalIp() … … 1796 1802 if (conf.HasVersion()) 1797 1803 { 1798 PrintVersion(argv[0]);1804 FACT::PrintVersion(argv[0]); 1799 1805 return -1; 1800 1806 }
Note:
See TracChangeset
for help on using the changeset viewer.