FACT++  1.0
void ConnectionLidar::HandleRead ( const boost::system::error_code &  err,
size_t  bytes_received 
)
inlineprotected

Definition at line 47 of file magiclidar.cc.

References data, Error(), MagicLidar::DimLidar::fAz, MagicLidar::DimLidar::fCloudBaseHeight, MagicLidar::DimLidar::fT12, MagicLidar::DimLidar::fT3, MagicLidar::DimLidar::fT6, MagicLidar::DimLidar::fT9, MagicLidar::DimLidar::fZd, Time::GetAsStr(), and str.

Referenced by StartReadReport().

48  {
49  // Do not schedule a new read if the connection failed.
50  if (bytes_received==0 || err)
51  {
52  if (err==ba::error::eof)
53  Warn("Connection closed by remote host.");
54 
55  // 107: Transport endpoint is not connected (bs::error_code(107, bs::system_category))
56  // 125: Operation canceled
57  if (err && err!=ba::error::eof && // Connection closed by remote host
58  err!=ba::error::basic_errors::not_connected && // Connection closed by remote host
59  err!=ba::error::basic_errors::operation_aborted) // Connection closed by us
60  {
61  ostringstream str;
62  str << "Reading from " << URL() << ": " << err.message() << " (" << err << ")";// << endl;
63  Error(str);
64  }
65  PostClose(err!=ba::error::basic_errors::operation_aborted);
66  return;
67  }
68 
69  fLastReception = Time();
70 
71  const string str(fArray.data(), bytes_received);
72  memset(fArray.data(), 0, fArray.size());
73 
74  if (fIsVerbose)
75  Out() << str << endl;
76 
77  bool isheader = true;
78 
79  DimLidar data;
80 
81  int hh=0, mm=0, ss=0, y=0, m=0, d=0;
82 
83  bool keepalive = false;
84  bool failed = false;
85 
86  stringstream is(str);
87  string line;
88  while (getline(is, line))
89  {
90  if (line.size()==1 && line[0]==13)
91  {
92  isheader = false;
93  continue;
94  }
95 
96  if (isheader)
97  {
98  const size_t p = line.find_first_of(": ");
99  if (p==string::npos)
100  continue;
101 
102  std::transform(line.begin(), line.end(), line.begin(), (int(&)(int))std::tolower);
103 
104  const string key = line.substr(0, p);
105  const string val = line.substr(p+2);
106 
107  if (key=="connection" && val=="keep-alive")
108  keepalive = true;
109  }
110  else
111  {
112  try
113  {
114  if (line.substr(0, 2)=="ZD")
115  data.fZd = stoi(line.substr(2));
116  if (line.substr(0, 2)=="AZ")
117  data.fAz = stof(line.substr(2));
118 
119  //if (line.substr(0, 3)=="PBL")
120  // data.fPBL = stof(line.substr(3));
121  //if (line.substr(0, 3)=="CHE")
122  // data.fCHE = stof(line.substr(3));
123  //if (line.substr(0, 3)=="COT")
124  // data.fCOT = stof(line.substr(3));
125 
126  if (line.substr(0, 2)=="T3")
127  data.fT3 = stof(line.substr(2));
128  if (line.substr(0, 2)=="T6")
129  data.fT6 = stof(line.substr(2));
130  if (line.substr(0, 2)=="T9")
131  data.fT9 = stof(line.substr(2));
132  if (line.substr(0, 3)=="T12")
133  data.fT12 = stof(line.substr(3));
134 
135  if (line.substr(0, 3)=="CLB")
136  data.fCloudBaseHeight = stof(line.substr(3));
137 
138  if (line.substr(0, 4)=="HOUR")
139  hh = stoi(line.substr(4));
140  if (line.substr(0, 6)=="MINUTS")
141  mm = stoi(line.substr(6));
142  if (line.substr(0, 7)=="SECONDS")
143  ss = stoi(line.substr(7));
144 
145  if (line.substr(0, 4)=="YEAR")
146  y = stoi(line.substr(4));
147  if (line.substr(0, 5)=="MONTH")
148  m = stoi(line.substr(5));
149  if (line.substr(0, 3)=="DAY")
150  d = stoi(line.substr(3));
151  }
152  catch (const exception &e)
153  {
154  Warn("Conversion of received data failed");
155  failed = true;
156  break;
157  }
158  }
159  }
160 
161  if (!keepalive)
162  PostClose(false);
163 
164  if (failed)
165  return;
166 
167  try
168  {
169  const Time tm = Time(y>999 ? y : 2000+y, m, d, hh, mm, ss);
170  if (tm==fLastReport)
171  return;
172 
173  fLastReport = tm;
174 
175  if (data.fT3==0 && data.fT6==0 && data.fT9==0 && data.fT12==0)
176  return;
177 
178  ostringstream msg;
179  msg << tm.GetAsStr("%H:%M:%S") << ":"
180  //<< " PBL=" << data.fPBL
181  //<< " CHE=" << data.fCHE
182  //<< " COT=" << data.fCOT
183  << " T3-12=" << data.fT3
184  << "/" << data.fT6
185  << "/" << data.fT9
186  << "/" << data.fT12
187  << " H=" << data.fCloudBaseHeight/1000 << "km"
188  << " Zd=" << data.fZd << "°"
189  << " Az=" << data.fAz << "°";
190  Message(msg);
191 
192  UpdateLidar(tm, data);
193  }
194  catch (const exception &e)
195  {
196  Warn("Corrupted time received.");
197  }
198 
199  }
virtual void UpdateLidar(const Time &, const DimLidar &)
Definition: magiclidar.cc:36
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
boost::array< char, 4096 > fArray
Definition: magiclidar.cc:42
float data[4 *1440]
Error()
Definition: HeadersFTM.h:197
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
Definition: Time.cc:240

+ Here is the call graph for this function:

+ Here is the caller graph for this function: