Changeset 11192
- Timestamp:
- 06/27/11 13:25:48 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fadctrl.cc
r11182 r11192 25 25 #include "tools.h" 26 26 27 #include "DimDescriptionService.h" 28 #include "EventBuilderWrapper.h" 29 27 30 namespace ba = boost::asio; 28 31 namespace bs = boost::system; … … 36 39 class ConnectionFAD : public Connection 37 40 { 41 uint16_t fSlot; 42 // tcp::endpoint fEndpoint; 43 38 44 vector<uint16_t> fBuffer; 39 45 … … 155 161 } 156 162 163 EventBuilderWrapper::This->debugStream(fSlot*7, fBuffer.data(), bytes_received); 164 157 165 if (type==kReadHeader) 158 166 { … … 183 191 UpdateEventHeader(); 184 192 193 EventBuilderWrapper::This->debugHead(fSlot*40, fEventHeader); 194 185 195 fBuffer.resize(fEventHeader.fPackageLength-sizeof(FAD::EventHeader)/2); 186 196 AsyncRead(ba::buffer(fBuffer), kReadData); … … 225 235 } 226 236 227 uint16_t *data = reinterpret_cast<uint16_t*>(ptr); 228 229 /* 230 for (uint16_t *d=data; d<data+fChannelHeader[i].fRegionOfInterest; d++) 231 { 232 const bool sign = *d & 0x2000; 233 const bool overflow = *d & 0x1000; 234 235 if (sign) 236 *d |= 0xf000; // no overflow, nagative 237 else 238 *d &= 0x07ff; // no overlow, positive 239 240 // max = [-2047;2048] 241 242 if (overflow) 243 { 244 if (sign) 245 *d = 0xF800; // overflow, negative 246 else 247 *d = 0x0800; // overflow, positive 248 } 249 } 250 */ 251 237 const uint16_t *data = reinterpret_cast<uint16_t*>(ptr); 252 238 UpdateData(data, fChannelHeader[i].fRegionOfInterest*2); 253 239 ptr += fChannelHeader[i].fRegionOfInterest*2; … … 366 352 367 353 public: 368 ConnectionFAD(ba::io_service& ioservice, MessageImp &imp ) :369 Connection(ioservice, imp()), 354 ConnectionFAD(ba::io_service& ioservice, MessageImp &imp, uint16_t slot) : 355 Connection(ioservice, imp()), fSlot(slot), 370 356 fIsVerbose(false), fIsHexOutput(false), fIsDataOutput(false), 371 357 fBlockTransmission(false), fCounter(0) … … 379 365 } 380 366 367 // void SetTcpEndpoint(const tcp::endpoint &ep) { fEndpoint = ep; } 368 // const tcp::endpoint &GetTcpEndpoint() const { return fEndpoint; } 369 381 370 void Cmd(FAD::Enable cmd, bool on=true) 382 371 { … … 557 546 558 547 // ------------------------------------------------------------------------ 559 #include "DimDescriptionService.h"560 #include "EventBuilderWrapper.h"561 562 // ------------------------------------------------------------------------563 548 564 549 template <class T> … … 566 551 { 567 552 private: 568 typedef pair<tcp::endpoint, ConnectionFAD*> Connection; 569 typedef map<uint8_t, Connection> BoardList; 553 typedef map<uint8_t, ConnectionFAD*> BoardList; 570 554 571 555 BoardList fBoards; … … 590 574 { 591 575 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 592 i->second .second->Cmd(command);576 i->second->Cmd(command); 593 577 594 578 return T::GetCurrentState(); … … 607 591 608 592 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 609 i->second .second->PostCmd(evt.GetUInt());593 i->second->PostCmd(evt.GetUInt()); 610 594 611 595 return T::GetCurrentState(); … … 632 616 633 617 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 634 i->second .second->PostCmd(ptr[0], ptr[1]);618 i->second->PostCmd(ptr[0], ptr[1]); 635 619 636 620 return T::GetCurrentState(); … … 643 627 644 628 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 645 i->second .second->Cmd(command, evt.GetBool());629 i->second->Cmd(command, evt.GetBool()); 646 630 647 631 return T::GetCurrentState(); … … 680 664 681 665 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 682 i->second .second->CmdSetRegister(dat[0], dat[1]);666 i->second->CmdSetRegister(dat[0], dat[1]); 683 667 684 668 return T::GetCurrentState(); … … 693 677 694 678 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 695 if (!i->second .second->CmdSetRoi(dat[0], dat[1]))679 if (!i->second->CmdSetRoi(dat[0], dat[1])) 696 680 { 697 681 ostringstream msg; … … 716 700 717 701 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 718 i->second .second->CmdSetDacValue(dat[0], dat[1]);702 i->second->CmdSetDacValue(dat[0], dat[1]); 719 703 720 704 return T::GetCurrentState(); … … 725 709 for (int nn=0; nn<n; nn++) 726 710 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 727 i->second .second->Cmd(FAD::kCmdSingleTrigger);711 i->second->Cmd(FAD::kCmdSingleTrigger); 728 712 729 713 return T::GetCurrentState(); … … 746 730 747 731 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 748 i->second .second->Cmd(FAD::kCmdRun, start);732 i->second->Cmd(FAD::kCmdRun, start); 749 733 750 734 return T::GetCurrentState(); … … 757 741 758 742 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 759 i->second .second->CmdPhaseShift(evt.GetShort());743 i->second->CmdPhaseShift(evt.GetShort()); 760 744 761 745 return T::GetCurrentState(); … … 776 760 777 761 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 778 i->second .second->CmdSetTriggerRate(evt.GetUInt());762 i->second->CmdSetTriggerRate(evt.GetUInt()); 779 763 780 764 return T::GetCurrentState(); … … 797 781 798 782 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 799 i->second .second->CmdSetRunNumber(num);783 i->second->CmdSetRunNumber(num); 800 784 801 785 return T::GetCurrentState(); … … 840 824 841 825 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 842 i->second .second->SetVerbose(evt.GetBool());826 i->second->SetVerbose(evt.GetBool()); 843 827 844 828 return T::GetCurrentState(); … … 851 835 852 836 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 853 i->second .second->SetHexOutput(evt.GetBool());837 i->second->SetHexOutput(evt.GetBool()); 854 838 855 839 return T::GetCurrentState(); … … 862 846 863 847 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 864 i->second .second->SetDataOutput(evt.GetBool());848 i->second->SetDataOutput(evt.GetBool()); 865 849 866 850 return T::GetCurrentState(); … … 873 857 874 858 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 875 i->second .second->SetDebugTx(evt.GetBool());859 i->second->SetDebugTx(evt.GetBool()); 876 860 877 861 return T::GetCurrentState(); … … 901 885 { 902 886 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 903 i->second .second->PrintEvent();887 i->second->PrintEvent(); 904 888 } 905 889 else … … 907 891 const BoardList::iterator it=GetSlot(slot); 908 892 if (it!=fBoards.end()) 909 it->second .second->PrintEvent();893 it->second->PrintEvent(); 910 894 } 911 895 … … 922 906 const BoardList::iterator it=GetSlot(slot); 923 907 if (it!=fBoards.end()) 924 it->second .second->SetBlockTransmission(evt.Get<uint8_t>(2));908 it->second->SetBlockTransmission(evt.Get<uint8_t>(2)); 925 909 926 910 return T::GetCurrentState(); … … 939 923 const BoardList::iterator it=GetSlot(i); 940 924 if (it!=fBoards.end()) 941 it->second .second->SetBlockTransmission(block);925 it->second->SetBlockTransmission(block); 942 926 } 943 927 … … 1013 997 for (BoardList::const_iterator i=fBoards.begin(); i!=fBoards.end(); i++) 1014 998 { 1015 if (i->second .first==endpoint)999 if (i->second->GetEndpoint()==endpoint) 1016 1000 { 1017 1001 T::Warn("Address "+addr+" already known.... ignored."); … … 1039 1023 ConnectSlot(slot, tcp::endpoint()); 1040 1024 1041 delete it->second .second;1025 delete it->second; 1042 1026 fBoards.erase(it); 1043 1027 … … 1049 1033 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 1050 1034 { 1051 const int &idx= i->first;1052 const Connection &slot= i->second;1035 const int &idx = i->first; 1036 const ConnectionFAD *fad = i->second; 1053 1037 1054 1038 ostringstream str; 1055 str << "Slot " << setw(2) << idx << ": " << slot.first; 1056 1057 const ConnectionFAD *c = slot.second; 1058 1059 if (c->IsConnecting()) 1039 str << "Slot " << setw(2) << idx << ": " << fad->GetEndpoint(); 1040 1041 if (fad->IsConnecting()) 1060 1042 str << " (0:connecting, "; 1061 1043 else 1062 1044 { 1063 if ( c->IsClosed())1045 if (fad->IsClosed()) 1064 1046 str << " (0:disconnected, "; 1065 if ( c->IsConnected())1047 if (fad->IsConnected()) 1066 1048 str << " (0:connected, "; 1067 1049 } … … 1074 1056 } 1075 1057 1076 if ( c->IsTransmissionBlocked())1058 if (fad->IsTransmissionBlocked()) 1077 1059 str << " [cmd_blocked]"; 1078 1060 … … 1093 1075 } 1094 1076 1095 void EnableConnection(Connection &c, bool enable=true) 1096 { 1097 ConnectionFAD *ptr = c.second; 1098 if (!ptr) 1099 return; 1100 1077 void EnableConnection(ConnectionFAD *ptr, bool enable=true) 1078 { 1101 1079 if (!enable) 1102 1080 { … … 1105 1083 } 1106 1084 1107 ostringstream str;1108 str << c.first;1109 1110 1085 if (!ptr->IsDisconnected()) 1111 1086 { 1087 ostringstream str; 1088 str << ptr->GetEndpoint(); 1089 1112 1090 T::Warn("Connection to "+str.str()+" already in progress."); 1113 1091 return; 1114 1092 } 1115 1093 1116 ptr->SetEndpoint(str.str());1117 1094 ptr->StartConnect(); 1118 1095 } … … 1142 1119 1143 1120 EnableConnection(it->second, enable); 1144 ConnectSlot(it->first, enable ? it->second .first: tcp::endpoint());1121 ConnectSlot(it->first, enable ? it->second->GetEndpoint() : tcp::endpoint()); 1145 1122 1146 1123 return T::GetCurrentState(); … … 1158 1135 return T::GetCurrentState(); 1159 1136 1160 const bool enable = it->second .second->IsDisconnected() && fStatus2[slot]==0;1137 const bool enable = it->second->IsDisconnected() && fStatus2[slot]==0; 1161 1138 1162 1139 EnableConnection(it->second, enable); 1163 ConnectSlot(it->first, enable ? it->second .first: tcp::endpoint());1140 ConnectSlot(it->first, enable ? it->second->GetEndpoint() : tcp::endpoint()); 1164 1141 1165 1142 return T::GetCurrentState(); … … 1171 1148 1172 1149 for (BoardList::iterator i=fBoards.begin(); i!=fBoards.end(); i++) 1173 addr[i->first] = i->second .first;1150 addr[i->first] = i->second->GetEndpoint(); 1174 1151 1175 1152 StartThread(addr); … … 1219 1196 int cnt = 0; // counter for enabled board 1220 1197 1198 const bool runs = IsThreadRunning(); 1199 1221 1200 for (int idx=0; idx<40; idx++) 1222 1201 { … … 1225 1204 if (slot!=fBoards.end()) 1226 1205 { 1227 const ConnectionFAD *c = slot->second .second;1206 const ConnectionFAD *c = slot->second; 1228 1207 if (c->IsDisconnected()) 1229 1208 { … … 1231 1210 nclosed1++; 1232 1211 1233 DisconnectSlot(idx);1212 //DisconnectSlot(idx); 1234 1213 } 1235 1214 if (c->IsConnecting()) … … 1248 1227 1249 1228 // ----- Event builder ----- 1229 1230 if (!runs) 1231 continue; 1232 1250 1233 stat2[idx] = GetNumConnected(idx); 1251 1234 1252 if ( !IsConnected(idx) && !IsDisconnected(idx))1235 if (IsConnecting(idx)) 1253 1236 nconnecting2++; 1254 1237 … … 1276 1259 1277 1260 if (nconnecting1>0 || nconnecting2>0 || nconnected1!=nconnected2) 1261 { 1262 cout << nconnecting1 << " " << nconnecting2 << " " << nconnected1 << " " << nconnected2 << endl; 1263 1264 if (nconnecting2>0) 1265 for (int i=0; i<40; i++) 1266 cout << i << ": " << GetNumConnected(i) << " " <<IsConnected(i) << " " << IsConnecting(i) << " " << IsDisconnected(i) << endl; 1267 1278 1268 return FAD::kConnecting; 1269 } 1279 1270 1280 1271 // nconnected1 == nconnected2 == 0 … … 1298 1289 } 1299 1290 1300 fBoards[i] = make_pair(addr, new ConnectionFAD(*this, *this)); 1301 fBoards[i].second->SetVerbose(fIsVerbose); 1302 fBoards[i].second->SetHexOutput(fIsHexOutput); 1303 fBoards[i].second->SetDataOutput(fIsDataOutput); 1304 fBoards[i].second->SetDebugTx(fDebugTx); 1291 ConnectionFAD *fad = new ConnectionFAD(*this, *this, i); 1292 1293 fad->SetEndpoint(addr); 1294 fad->SetVerbose(fIsVerbose); 1295 fad->SetHexOutput(fIsHexOutput); 1296 fad->SetDataOutput(fIsDataOutput); 1297 fad->SetDebugTx(fDebugTx); 1298 1299 fBoards[i] = fad; 1305 1300 } 1306 1301 1307 1302 1308 1303 DimDescribedService fDimConnection; 1309 /* 1310 template<class T> 1311 void Update(DimDescribedService &svc, const T &data) const 1312 { 1313 //cout << "Update: " << svc.getName() << " (" << sizeof(T) << ")" << endl; 1314 svc.setData(const_cast<T*>(&data), sizeof(T)); 1315 svc.updateService(); 1316 } 1317 */ 1304 1318 1305 void UpdateConnectionStatus(const vector<uint8_t> &stat1, const vector<uint8_t> &stat2, bool thread) 1319 1306 { … … 1504 1491 "|enable[bool]:Whether the event builder should ignore data from this slot (yes) or allowed (no)"); 1505 1492 1493 T::AddEvent("CLOSE_OPEN_FILES", FAD::kConnecting, FAD::kConnected) 1494 (boost::bind(&StateMachineFAD::CloseOpenFiles, this)) 1495 ("Close all run files opened by the EventBuilder."); 1496 1497 T::AddEvent("TEST", "S:1") 1498 (boost::bind(&StateMachineFAD::Test, this, _1)) 1499 (""); 1500 1501 1502 1506 1503 // Conenction commands 1507 1504 T::AddEvent("START", FAD::kOffline) … … 1529 1526 (""); 1530 1527 1531 T::AddEvent("CLOSE_OPEN_FILES", FAD::kConnecting, FAD::kConnected)1532 (boost::bind(&StateMachineFAD::CloseOpenFiles, this))1533 ("Close all run files opened by the EventBuilder.");1534 1535 T::AddEvent("TEST", "S:1")1536 (boost::bind(&StateMachineFAD::Test, this, _1))1537 ("");1538 1528 1539 1529 T::AddEvent("ADD_ADDRESS", "C", FAD::kOffline) … … 1553 1543 { 1554 1544 for (BoardList::const_iterator i=fBoards.begin(); i!=fBoards.end(); i++) 1555 delete i->second .second;1545 delete i->second; 1556 1546 fBoards.clear(); 1557 1547 }
Note:
See TracChangeset
for help on using the changeset viewer.