FACT++  1.0
void ConnectionBias::HandleReceivedData ( const bs::error_code &  err,
size_t  bytes_received,
int  command,
int  send_counter 
)
inlineprivate

This replaces the send counter and the command argument

Definition at line 474 of file biasctrl.cc.

References Error(), BIAS::kCmdChannelSet, BIAS::kCmdGlobalSet, BIAS::kCmdRead, BIAS::kCmdReset, BIAS::kExpertChannelSet, BIAS::kResetChannels, BIAS::kSynchronize, BIAS::kUpdate, and str.

475  {
476  // Do not schedule a new read if the connection failed.
477  if (bytes_received==0 || err)
478  {
479  if (err==ba::error::eof)
480  {
481  ostringstream msg;
482  msg << "Connection closed by remote host (BIAS, fSendCounter=" << fSendCounter << ")";
483  Warn(msg);
484  }
485 
486  // 107: Transport endpoint is not connected (bs::error_code(107, bs::system_category))
487  // 125: Operation canceled
488  if (err && err!=ba::error::eof && // Connection closed by remote host
489  err!=ba::error::basic_errors::not_connected && // Connection closed by remote host
490  err!=ba::error::basic_errors::operation_aborted) // Connection closed by us
491  {
492  ostringstream str;
493  str << "Reading from " << URL() << ": " << err.message() << " (" << err << ")";// << endl;
494  Error(str);
495  }
496  CloseImp(-1);//err!=ba::error::basic_errors::operation_aborted);
497  return;
498  }
499 
500  // Check if the number of received bytes is correctly dividable by 3
501  // This check should never fail - just for sanity
502  if (bytes_received%3)
503  {
504  Error("Number of received bytes not a multiple of 3, can't read data.");
505  CloseImp(-1);
506  return;
507  }
508 
509  // We have three different parallel streams:
510  // 1) The setting of voltages due to ramping
511  // 2) The cynclic request of the currents
512  // 3) Answers to commands
513  // For each of these three streams an own buffer is needed, otherwise
514  // a buffer which is filled in the background might overwrite
515  // a buffer which is currently evaluated. In all other programs
516  // this is no problem because the boards don't answer and if
517  // they do the answer identifies itself. Consequently,
518  // there is always only one async_read in progress. Here we have
519  // three streams which need to be connected somehow to the
520  // commands.
521 
522  // Maybe a better possibility would be to setup a command
523  // queue (each command will be queued in a buffer)
524  // and whenever an answer has been received, a new async_read is
525  // scheduled.
526  // Build a command queue<pair<command, vector<char>>>
528  // in handleReceivedData
529 
530  switch (command&0xff)
531  {
532  case kSynchronize:
533  case kCmdReset:
534  case kExpertChannelSet:
535  case kCmdGlobalSet:
536  case kResetChannels:
537  case kCmdRead:
538  HandleReceivedData(fBuffer, bytes_received, command, send_counter);
539  fWaitingForAnswer = -1;
540  return;
541 
542  case kCmdChannelSet:
543  HandleReceivedData(fBufferRamp, bytes_received, command, send_counter);
544  return;
545 
546  case kUpdate:
547  HandleReceivedData(fBufferUpdate, bytes_received, command, send_counter);
548  return;
549  }
550  }
std::string URL() const
vector< uint8_t > fBuffer
Definition: biasctrl.cc:38
void CloseImp(int64_t delay=0)
char str[80]
Definition: test_client.c:7
vector< uint8_t > fBufferRamp
Definition: biasctrl.cc:39
vector< uint8_t > fBufferUpdate
Definition: biasctrl.cc:40
int64_t fSendCounter
Definition: biasctrl.cc:48
void HandleReceivedData(const vector< uint8_t > &buf, size_t bytes_received, int command, int send_counter)
Definition: biasctrl.cc:325
int Error(const std::string &str)
Definition: MessageImp.h:49
int Warn(const std::string &str)
Definition: MessageImp.h:48
int fWaitingForAnswer
Definition: biasctrl.cc:61

+ Here is the call graph for this function: