FACT++  1.0
void tcp_connection::HandleReceivedData ( const boost::system::error_code &  error,
size_t  bytes_received 
)
inline

Definition at line 251 of file fad.cc.

References buffer, fRegionOfInterest, i, kCmdBusyOff, kCmdBusyOn, kCmdContTrigger, kCmdDrsEnable, kCmdDwrite, kCmdResetEventCounter, kCmdRun, kCmdSclk, kCmdSingleTrigger, kCmdSocket, kCmdSrclk, kCmdTriggerLine, kCmdWriteDac, kCmdWriteExecute, kCmdWriteRate, kCmdWriteRoi, kCmdWriteRunNumberLSW, kCmdWriteRunNumberMSW, kNumChannels, kNumDac, TriggerSendData(), Time::UnixTime(), and Time::utc.

Referenced by AsyncRead().

252  {
253  // Do not schedule a new read if the connection failed.
254  if (bytes_received==0)
255  {
256  // Close the connection
257  close();
258  return;
259  }
260 
261  // No command received yet
262  if (fCommand.size()==0)
263  {
264  transform(fBufCommand.begin(), fBufCommand.begin()+bytes_received/2,
265  fBufCommand.begin(), ntohs);
266 
267  switch (fBufCommand[0])
268  {
269  case kCmdDrsEnable:
270  case kCmdDrsEnable+0x100:
271  fHeader.Enable(FAD::EventHeader::kDenable, fBufCommand[0]==kCmdDrsEnable);
272  cout << "-> DrsEnable " << fBoardId << " " << (fBufCommand[0]==kCmdDrsEnable) << endl;
273  break;
274 
275  case kCmdDwrite:
276  case kCmdDwrite+0x100:
277  fHeader.Enable(FAD::EventHeader::kDwrite, fBufCommand[0]==kCmdDwrite);
278  cout << "-> Dwrite " << fBoardId << " " << (fBufCommand[0]==kCmdDwrite) << endl;
279  break;
280 
281  case kCmdTriggerLine:
282  case kCmdTriggerLine+0x100:
283  cout << "-> Trigger line " << fBoardId << " " << (fBufCommand[0]==kCmdTriggerLine) << endl;
284  fTriggerEnabled = fBufCommand[0]==kCmdTriggerLine;
285  fHeader.Enable(FAD::EventHeader::kTriggerLine, fTriggerEnabled);
286  break;
287 
288  case kCmdSclk:
289  case kCmdSclk+0x100:
290  cout << "-> Sclk " << fBoardId << endl;
291  fHeader.Enable(FAD::EventHeader::kSpiSclk, fBufCommand[0]==kCmdSclk);
292  break;
293 
294  case kCmdSrclk:
295  case kCmdSrclk+0x100:
296  cout << "-> Srclk " << fBoardId << endl;
297  break;
298 
299  case kCmdRun:
300  case kCmdRun+0x100:
302  cout << "-> Run " << fBoardId << endl;
303  break;
304 
305  case kCmdBusyOff:
306  case kCmdBusyOff+0x100:
307  cout << "-> BusyOff " << fBoardId << " " << (fBufCommand[0]==kCmdBusyOff) << endl;
308  fHeader.Enable(FAD::EventHeader::kBusyOff, fBufCommand[0]==kCmdBusyOff);
309  break;
310 
311  case kCmdBusyOn:
312  case kCmdBusyOn+0x100:
313  cout << "-> BusyOn " << fBoardId << " " << (fBufCommand[0]==kCmdBusyOn) << endl;
314  fHeader.Enable(FAD::EventHeader::kBusyOn, fBufCommand[0]==kCmdBusyOn);
315  break;
316 
317  case kCmdSocket:
318  case kCmdSocket+0x100:
319  cout << "-> Socket " << fBoardId << " " << (fBufCommand[0]==kCmdSocket) << endl;
320  fCommandSocket = fBufCommand[0]==kCmdSocket;
321  fHeader.Enable(FAD::EventHeader::kSock17, !fCommandSocket);
322  break;
323 
324  case kCmdContTrigger:
325  case kCmdContTrigger+0x100:
326  if (fBufCommand[0]==kCmdContTrigger)
328  else
329  fTriggerSendData.cancel();
330  fHeader.Enable(FAD::EventHeader::kContTrigger, fBufCommand[0]==kCmdContTrigger);
331  cout << "-> ContTrig " << fBoardId << " " << (fBufCommand[0]==kCmdContTrigger) << endl;
332  break;
333 
335  cout << "-> ResetId " << fBoardId << endl;
336  fHeader.fEventCounter = 0;
337  break;
338 
339  case kCmdSingleTrigger:
340  cout << "-> Trigger " << fBoardId << endl;
341  SendData(0);
342  break;
343 
344  case kCmdWriteExecute:
345  cout << "-> Execute " << fBoardId << endl;
346  memcpy(fHeader.fDac, fRam.fDac, sizeof(fHeader.fDac));
347  for (int i=0; i<kNumChannels; i++)
349  fHeader.fRunNumber = fRam.fRunNumber;
350  break;
351 
354  break;
355 
358  break;
359 
360  default:
361  if (fBufCommand[0]>=kCmdWriteRoi && fBufCommand[0]<kCmdWriteRoi+kNumChannels)
362  {
363  fCommand.resize(2);
364  fCommand[0] = kCmdWriteRoi;
365  fCommand[1] = fBufCommand[0]-kCmdWriteRoi;
366  break;
367  }
368  if (fBufCommand[0]>= kCmdWriteDac && fBufCommand[0]<kCmdWriteDac+kNumDac)
369  {
370  fCommand.resize(2);
371  fCommand[0] = kCmdWriteDac;
372  fCommand[1] = fBufCommand[0]-kCmdWriteDac;
373  break;
374  }
375  if (fBufCommand[0]==kCmdWriteRate)
376  {
377  fCommand.resize(1);
378  fCommand[0] = kCmdWriteRate;
379  break;
380  }
381 
382  cout << "Received b=" << bytes_received << ": " << error.message() << " (" << error << ")" << endl;
383  cout << "Hex:" << Converter::GetHex<uint16_t>(&fBufCommand[0], bytes_received) << endl;
384  return;
385  }
386 
387  fBufCommand.resize(1);
388  AsyncRead(ba::buffer(fBufCommand));
389  return;
390  }
391 
392  transform(fBufCommand.begin(), fBufCommand.begin()+bytes_received/2,
393  fBufCommand.begin(), ntohs);
394 
395  switch (fCommand[0])
396  {
398  fRam.fRunNumber &= 0xffff;
399  fRam.fRunNumber |= fBufCommand[0]<<16;
400  cout << "-> Set RunNumber " << fBoardId << " MSW" << endl;
401  break;
403  fRam.fRunNumber &= 0xffff0000;
404  fRam.fRunNumber |= fBufCommand[0];
405  cout << "-> Set RunNumber " << fBoardId << " LSW" << endl;
406  break;
407  case kCmdWriteRoi:
408  cout << "-> Set " << fBoardId << " Roi[" << fCommand[1] << "]=" << fBufCommand[0] << endl;
409  //fChHeader[fCommand[1]].fRegionOfInterest = fBufCommand[0];
410  fRamRoi[fCommand[1]] = fBufCommand[0];
411  break;
412 
413  case kCmdWriteDac:
414  cout << "-> Set " << fBoardId << " Dac[" << fCommand[1] << "]=" << fBufCommand[0] << endl;
415  fRam.fDac[fCommand[1]] = fBufCommand[0];
416  break;
417 
418  case kCmdWriteRate:
419  cout << "-> Set " << fBoardId << " Rate =" << fBufCommand[0] << endl;
420  fHeader.fTriggerGeneratorPrescaler = fBufCommand[0];
421  break;
422  }
423 
424  fCommand.resize(0);
425 
426  fBufCommand.resize(1);
427  AsyncRead(ba::buffer(fBufCommand));
428  }
vector< uint16_t > fCommand
Definition: fad.cc:115
uint16_t fRegionOfInterest
Definition: HeadersFAD.h:95
void TriggerSendData(const boost::system::error_code &ec)
Definition: fad.cc:225
void AsyncWait(ba::deadline_timer &timer, int seconds, void(tcp_connection::*handler)(const bs::error_code &))
Definition: fad.cc:79
ba::deadline_timer fTriggerSendData
Definition: fad.cc:123
void SendData()
Definition: fsc.cc:71
int i
Definition: db_dim_client.c:21
Initialize with UTC.
Definition: Time.h:52
const int fBoardId
Definition: fad.cc:62
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
void AsyncRead(ba::mutable_buffers_1 buffers)
Definition: fad.cc:66
bool fCommandSocket
Definition: fad.cc:126
double fStartTime
Definition: fad.cc:64
FAD::ChannelHeader fChHeader[kNumChannels]
Definition: fad.cc:119
double UnixTime() const
Definition: Time.cc:195
bool fTriggerEnabled
Definition: fad.cc:125
int buffer[BUFFSIZE]
Definition: db_dim_client.c:14
FAD::EventHeader fHeader
Definition: fad.cc:117
FAD::EventHeader fRam
Definition: fad.cc:118
vector< uint16_t > fBufCommand
Definition: fad.cc:113
vector< uint16_t > fRamRoi
Definition: fad.cc:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function: