Changeset 10606 for trunk/FACT++/src/ftmctrl.cc
- Timestamp:
- 05/06/11 09:52:22 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/ftmctrl.cc
r10587 r10606 1 1 #include <boost/bind.hpp> 2 2 #include <boost/array.hpp> 3 #if BOOST_VERSION<1440 4 #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 4)) 5 #undef BOOST_HAS_RVALUE_REFS 6 #error test 7 #endif 8 #endif 3 9 #include <boost/thread.hpp> 4 10 #include <boost/asio/error.hpp> … … 18 24 #include "LocalControl.h" 19 25 #include "HeadersFTM.h" 26 20 27 21 28 namespace ba = boost::asio; … … 61 68 // ... 62 69 70 protected: 63 71 map<uint16_t, int> fCounter; 64 72 65 protected:66 73 FTM::Header fHeader; 67 74 FTM::FtuList fFtuList; … … 138 145 } 139 146 147 virtual void UpdateCounter() 148 { 149 if (!fIsVerbose) 150 return; 151 152 if (!fIsDynamicOut) 153 return; 154 155 Out() << "Received: "; 156 Out() << "H=" << fCounter[kHeader] << " "; 157 Out() << "S=" << fCounter[kStaticData] << " "; 158 Out() << "D=" << fCounter[kDynamicData] << " "; 159 Out() << "F=" << fCounter[kFtuList] << " "; 160 Out() << "E=" << fCounter[kError] << " "; 161 Out() << "R=" << fCounter[kRegister] << endl; 162 } 163 140 164 private: 141 165 void HandleReceivedData(const bs::error_code& err, size_t bytes_received, int /*type*/) 142 166 { 167 cout << "Data received " << err << " " << bytes_received << endl; 168 143 169 // Do not schedule a new read if the connection failed. 144 170 if (bytes_received==0 || err) … … 205 231 UpdateFirstHeader(); 206 232 233 UpdateCounter(); 207 234 UpdateHeader(); 208 235 … … 254 281 255 282 fCounter[fHeader.fType]++; 283 UpdateCounter(); 284 285 cout << "TYPE=" << fHeader.fType << endl; 256 286 257 287 switch (fHeader.fType) … … 263 293 264 294 case kStaticData: 295 cout << fBuffer.size() << " " << sizeof(fStaticData) << endl; 265 296 fStaticData = fBuffer; 266 297 UpdateStaticData(); 267 break;298 break; 268 299 269 300 case kDynamicData: … … 416 447 public: 417 448 ConnectionFTM(ba::io_service& ioservice, MessageImp &imp) : Connection(ioservice, imp()), 418 fIsVerbose(true), fIsDynamicOut( false), fIsHexOutput(false)449 fIsVerbose(true), fIsDynamicOut(true), fIsHexOutput(true) 419 450 { 420 451 SetLogStream(&imp); … … 512 543 } 513 544 545 void SetHexOutput(bool b) 546 { 547 fIsHexOutput = b; 548 } 549 550 void SetDynamicOut(bool b) 551 { 552 fIsDynamicOut = b; 553 } 554 514 555 bool LoadStaticData(string name) 515 556 { … … 536 577 fStaticData = data; 537 578 538 CmdSendStatDat(); 579 for (int i=0; i<100; i++) 580 CmdSendStatDat(); 539 581 540 582 return true; … … 557 599 bool SetThreshold(int32_t patch, int32_t value) 558 600 { 559 560 601 if (patch>159) 561 602 return false; … … 566 607 if (patch<0) 567 608 { 609 bool ident = true; 610 for (int i=0; i<160; i++) 611 if (fStaticData[i/4].fDAC[patch%4] != value) 612 { 613 ident = false; 614 break; 615 } 616 617 if (ident) 618 return; 619 568 620 for (int i=0; i<160; i++) 569 621 fStaticData[i/4].fDAC[i%4] = value; 570 622 } 571 623 else 624 { 625 if (fStaticData[patch/4].fDAC[patch%4] == value) 626 return true; 627 572 628 fStaticData[patch/4].fDAC[patch%4] = value; 629 } 630 631 // Maybe move to a "COMMIT" command? 632 CmdSendStatDat(); 633 634 return true; 635 } 636 637 bool SetPrescaling(uint16_t value) 638 { 639 if (value>0xffff) 640 return false; 641 642 643 bool ident = true; 644 for (int i=0; i<40; i++) 645 if (fStaticData[i].fPrescaling != value) 646 { 647 ident = false; 648 break; 649 } 650 651 if (ident) 652 return true; 653 654 for (int i=0; i<40; i++) 655 fStaticData[i].fPrescaling = value; 573 656 574 657 // Maybe move to a "COMMIT" command? … … 672 755 DimDescribedService fDimStaticData; 673 756 DimDescribedService fDimDynamicData; 757 DimDescribedService fDimCounter; 674 758 675 759 template<class T> … … 681 765 } 682 766 683 v irtual void UpdateFirstHeader()767 void UpdateFirstHeader() 684 768 { 685 769 ConnectionFTM::UpdateFirstHeader(); … … 689 773 } 690 774 691 v irtual void UpdateHeader()775 void UpdateHeader() 692 776 { 693 777 ConnectionFTM::UpdateHeader(); … … 697 781 } 698 782 699 v irtual void UpdateFtuList()783 void UpdateFtuList() 700 784 { 701 785 ConnectionFTM::UpdateFtuList(); … … 705 789 } 706 790 707 v irtual void UpdateStaticData()791 void UpdateStaticData() 708 792 { 709 793 ConnectionFTM::UpdateStaticData(); … … 713 797 } 714 798 715 v irtual void UpdateDynamicData()799 void UpdateDynamicData() 716 800 { 717 801 ConnectionFTM::UpdateDynamicData(); … … 721 805 } 722 806 723 v irtual void UpdateError()807 void UpdateError() 724 808 { 725 809 ConnectionFTM::UpdateError(); … … 727 811 const DimError data(fHeader, fError); 728 812 Update(fDimError, data); 813 } 814 815 void UpdateCounter() 816 { 817 ConnectionFTM::UpdateCounter(); 818 819 const uint32_t counter[6] = 820 { 821 fCounter[kHeader], 822 fCounter[kStaticData], 823 fCounter[kDynamicData], 824 fCounter[kFtuList], 825 fCounter[kError], 826 fCounter[kRegister], 827 }; 828 829 Update(fDimCounter, counter); 729 830 } 730 831 … … 737 838 fDimFtuList ("FTM_CONTROL/FTU_LIST", "X:1;X:1;S:1;C:4;X:40;C:40;C:40", NULL, 0, ""), 738 839 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, ""), 739 fDimDynamicData ("FTM_CONTROL/DYNAMIC_DATA", "X:1;X:1;F:4;I:160;I:40;S:40;S:40", NULL, 0, "") 840 fDimDynamicData ("FTM_CONTROL/DYNAMIC_DATA", "X:1;X:1;F:4;I:160;I:40;S:40;S:40", NULL, 0, ""), 841 fDimCounter ("FTM_CONTROL/COUNTER", "I:6", NULL, 0, "") 740 842 { 741 843 } … … 867 969 } 868 970 971 int SetHexOutput(const EventImp &evt) 972 { 973 if (!CheckEventSize(evt.GetSize(), "SetHexOutput", 1)) 974 return T::kSM_FatalError; 975 976 fFTM.SetHexOutput(evt.GetText()[0]!=0); 977 978 return T::GetCurrentState(); 979 } 980 981 int SetDynamicOut(const EventImp &evt) 982 { 983 if (!CheckEventSize(evt.GetSize(), "SetDynamicOut", 1)) 984 return T::kSM_FatalError; 985 986 fFTM.SetDynamicOut(evt.GetText()[0]!=0); 987 988 return T::GetCurrentState(); 989 } 990 869 991 int LoadStaticData(const EventImp &evt) 870 992 { … … 966 1088 if (!fFTM.SetTimeMarkerDelay(evt.GetInt())) 967 1089 T::Warn("SetTimeMarkerDelay - Value out of range."); 1090 1091 return T::GetCurrentState(); 1092 } 1093 1094 int SetPrescaling(const EventImp &evt) 1095 { 1096 if (!CheckEventSize(evt.GetSize(), "SetPrescaling", 4)) 1097 return T::kSM_FatalError; 1098 1099 if (!fFTM.SetPrescaling(evt.GetInt())) 1100 T::Warn("SetPrescaling - Value out of range."); 968 1101 969 1102 return T::GetCurrentState(); … … 1113 1246 "|Threshold[counts]:Threshold to be set in binary counts"); 1114 1247 1248 AddConfiguration("SET_PRESCALING", "I:1", kStateIdle) 1249 (boost::bind(&StateMachineFTM::SetPrescaling, this, _1)) 1250 ("" 1251 "|[]:"); 1252 1115 1253 AddConfiguration("ENABLE_FTU", "I:1;B:1", kStateIdle) 1116 1254 (boost::bind(&StateMachineFTM::EnableFTU, this, _1)) … … 1144 1282 "|[]:"); 1145 1283 1284 1285 1286 // Load/save static data block 1287 T::AddConfiguration("SAVE", "C", kStateIdle) 1288 (boost::bind(&StateMachineFTM::SaveStaticData, this, _1)) 1289 ("Saves the static data (FTM configuration) from memory to a file" 1290 "|filename[string]:Filename (can include a path), .bin is automatically added"); 1291 1292 T::AddConfiguration("LOAD", "C", kStateIdle) 1293 (boost::bind(&StateMachineFTM::LoadStaticData, this, _1)) 1294 ("Loads the static data (FTM configuration) from a file into memory and sends it to the FTM" 1295 "|filename[string]:Filename (can include a path), .bin is automatically added"); 1296 1297 1298 1299 // Verbosity commands 1146 1300 T::AddConfiguration("SET_VERBOSE", "B") 1147 1301 (boost::bind(&StateMachineFTM::SetVerbosity, this, _1)) … … 1149 1303 "|verbosity[bool]:disable or enable verbosity for received data (yes/no)"); 1150 1304 1151 T::AddConfiguration("SAVE", "C", kStateIdle) 1152 (boost::bind(&StateMachineFTM::SaveStaticData, this, _1)) 1153 ("Saves the static data (FTM configuration) from memory to a file" 1154 "|filename[string]:Filename (can include a path), .bin is automatically added"); 1155 1156 T::AddConfiguration("LOAD", "C", kStateIdle) 1157 (boost::bind(&StateMachineFTM::LoadStaticData, this, _1)) 1158 ("Loads the static data (FTM configuration) from a file into memory and sends it to the FTM" 1159 "|filename[string]:Filename (can include a path), .bin is automatically added"); 1305 T::AddConfiguration("SET_HEX_OUTPUT", "B") 1306 (boost::bind(&StateMachineFTM::SetHexOutput, this, _1)) 1307 ("enable or disable hex output for received data" 1308 "|hexout[bool]:disable or enable hex output for verbose and received data (yes/no)"); 1309 1310 T::AddConfiguration("SET_DYNAMIC_OUTPUT", "B") 1311 (boost::bind(&StateMachineFTM::SetDynamicOut, this, _1)) 1312 ("enable or disable output for received dynamic data (data is still broadcasted via Dim)" 1313 "|dynout[bool]:disable or enable output for dynamic data (yes/no)"); 1314 1160 1315 1161 1316 // Conenction commands … … 1389 1544 << endl; 1390 1545 } 1546 /* 1547 string GetLocalIp() 1548 { 1549 const char *kDnsIp = getenv("DIM_DNS_NODE"); 1550 1551 struct addrinfo hints, *servinfo, *p; 1552 1553 memset(&hints, 0, sizeof hints); 1554 hints.ai_family = AF_INET; //AF_UNSPEC; // use AF_INET6 to force IPv6 1555 hints.ai_socktype = SOCK_STREAM; 1556 1557 int rv; 1558 if ((rv = getaddrinfo(kDnsIp, NULL, &hints, &servinfo)) != 0) 1559 { 1560 cout << "WARNING - getaddrinfo: " << gai_strerror(rv) << endl; 1561 return kDnsIp; 1562 } 1563 1564 // loop through all the results and connect to the first we can 1565 for (p=servinfo; p; p=p->ai_next) 1566 { 1567 const int sock = socket(AF_INET, SOCK_DGRAM, 0); 1568 if (sock==-1) 1569 continue; 1570 1571 if (connect(sock, p->ai_addr, p->ai_addrlen)==-1) 1572 { 1573 cout << "WARNING - connect: " << strerror(errno) << endl; 1574 close(sock); 1575 continue; 1576 } 1577 1578 sockaddr_in name; 1579 socklen_t namelen = sizeof(name); 1580 if (getsockname(sock, (sockaddr*)&name, &namelen)==-1) 1581 { 1582 cout << "WARNING - getsockname: " << strerror(errno) << endl; 1583 close(sock); 1584 continue; 1585 } 1586 1587 char buffer[16]; 1588 if (!inet_ntop(AF_INET, &name.sin_addr, buffer, 16)) 1589 { 1590 cout << "WARNING - inet_ntop: " << strerror(errno) << endl; 1591 close(sock); 1592 continue; 1593 } 1594 1595 close(sock); 1596 1597 freeaddrinfo(servinfo); // all done with this structure 1598 1599 cout << "DIM_HOST_NODE=" << buffer << endl; 1600 return buffer; 1601 } 1602 1603 freeaddrinfo(servinfo); // all done with this structure 1604 return kDnsIp; 1605 } 1606 */ 1391 1607 1392 1608 int main(int argc, const char* argv[]) … … 1434 1650 // To allow overwriting of DIM_DNS_NODE set 0 to 1 1435 1651 setenv("DIM_DNS_NODE", conf.Get<string>("dns").c_str(), 1); 1652 //setenv("DIM_HOST_NODE", GetLocalIp().c_str(), 1); 1436 1653 1437 1654 //try
Note:
See TracChangeset
for help on using the changeset viewer.