FACT++  1.0
void ConnectionAgilent::HandleReceivedData ( const bs::error_code &  err,
size_t  bytes_received,
int  line 
)
inlineprivate

Definition at line 131 of file agilentctrl.cc.

References Error(), Agilent::Data::fCurrentLimit, Agilent::Data::fCurrentMeasured, Agilent::Data::fVoltageMeasured, Agilent::Data::fVoltageSet, kBold, and str.

Referenced by StartRead().

132  {
133 
134  // Do not schedule a new read if the connection failed.
135  if (bytes_received==0 || err)
136  {
137  if (err==ba::error::eof)
138  Warn("Connection closed by remote host (FTM).");
139 
140  // 107: Transport endpoint is not connected (bs::error_code(107, bs::system_category))
141  // 125: Operation canceled
142  if (err && err!=ba::error::eof && // Connection closed by remote host
143  err!=ba::error::basic_errors::not_connected && // Connection closed by remote host
144  err!=ba::error::basic_errors::operation_aborted) // Connection closed by us
145  {
146  ostringstream str;
147  str << "Reading from " << URL() << ": " << err.message() << " (" << err << ")";// << endl;
148  Error(str);
149  }
150  PostClose(err!=ba::error::basic_errors::operation_aborted);
151  return;
152  }
153 
154 
155  if (fDebugRx)
156  {
157  Out() << kBold << "Received (" << bytes_received << ", " << fBuffer.size() << " bytes):" << endl;
158  Out() << "-----\n" << string(ba::buffer_cast<const char*>(fBuffer.data()), bytes_received) << "-----\n";
159  }
160 
161  istream is(&fBuffer);
162 
163  string str;
164  getline(is, str, '\n');
165 
166  try
167  {
168  switch (line)
169  {
170  case 1: Out() << "ID: " << str << endl; break;
171  case 2: fData.fVoltageSet = stof(str); break;
172  case 3: fData.fVoltageMeasured = stof(str); break;
173  case 4: fData.fCurrentMeasured = stof(str); break;
174  case 5: fData.fCurrentLimit = stof(str); break;
175  default:
176  return;
177  }
178  }
179  catch (const exception &e)
180  {
181  Error("String conversion failed for '"+str+" ("+e.what()+")");
182 
183  // We need to synchronize the stream again
184  PostClose(true);
185  return;
186  }
187 
188  if (line==5)
189  {
190  if (fIsVerbose)
191  {
192  Out() << "Voltage: " << fData.fVoltageMeasured << "V/" << fData.fVoltageSet << "V\n";
193  Out() << "Current: " << fData.fCurrentMeasured << "A/" << fData.fCurrentLimit << "A\n" << endl;
194  }
195 
196  UpdateDim(fData);
197 
198  fLastReceived = Time();
199 
200  line = 0;
201 
202  }
203 
204  StartRead(line);
205  }
void PostClose(bool restart=true)
Definition: Connection.cc:125
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
boost::asio::streambuf fBuffer
Definition: agilentctrl.cc:37
float fCurrentMeasured
virtual void UpdateDim(const Data &)
Definition: agilentctrl.cc:46
std::ostream & Out()
Definition: Connection.h:51
std::string URL() const
Definition: Connection.h:151
int Error(const std::string &str)
Definition: MessageImp.h:49
int Warn(const std::string &str)
Definition: MessageImp.h:48
void StartRead(int line=0)
Definition: agilentctrl.cc:124
float fVoltageMeasured
Set attribute Bold.
Definition: WindowLog.h:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function: