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

Definition at line 38 of file pfminictrl.cc.

References data, Error(), Tools::Fletcher16(), PFmini::Data::hum, PFmini::State::kReceiving, str, and PFmini::Data::temp.

39  {
40  // Do not schedule a new read if the connection failed.
41  if (bytes_received==0 || (err && err!=ba::error::eof))
42  {
43  // 107: Transport endpoint is not connected (bs::error_code(107, bs::system_category))
44  // 125: Operation canceled
45  if (err && err!=ba::error::eof && // Connection closed by remote host
46  err!=ba::error::basic_errors::not_connected && // Connection closed by remote host
47  err!=ba::error::basic_errors::operation_aborted) // Connection closed by us
48  {
49  ostringstream str;
50  str << "Reading from " << URL() << ": " << err.message() << " (" << err << ")";// << endl;
51  Error(str);
52  }
53  PostClose(false);
54  return;
55  }
56 
57  const uint16_t chk0 = Tools::Fletcher16(fBuffer.data(), 2);
58  const uint16_t chk1 = uint16_t(fBuffer[2]);
59 
60  if (chk0!=chk1)
61  {
62  ostringstream out;
63  out << "Checksum error (";
64  out << hex << setfill('0');
65  out << setw(4) << fBuffer[0] << ":";
66  out << setw(4) << fBuffer[1] << "|";
67  out << setw(4) << fBuffer[2] << "!=";
68  out << setw(4) << chk1 << ")";
69 
70  Error(out);
71 
72  PostClose(false);
73 
74  return;
75  }
76 
78  data.hum = 110*fBuffer[0]/1024.;
79  data.temp = 110*fBuffer[1]/1024.-20;
80 
81  Update(data);
82 
83  ostringstream msg;
84  msg << fixed << setprecision(1) << "H=" << data.hum << "% T=" << data.temp << "°C" ;
85  Message(msg);
86 
88  fReceived = true;
89  }
virtual void Update(const PFmini::Data &)
Definition: pfminictrl.cc:24
char str[80]
Definition: test_client.c:7
uint16_t Fletcher16(const T *t, size_t cnt)
Definition: tools.h:22
vector< int16_t > fBuffer
Definition: pfminictrl.cc:36
float data[4 *1440]
Error()
Definition: HeadersFTM.h:197

+ Here is the call graph for this function: