Http Version - Fix to show error when requests fail, and changed display type of distance in UI from float to Int
This commit is contained in:
parent
026ea97284
commit
e1d57eae32
1 changed files with 53 additions and 24 deletions
|
|
@ -48,6 +48,7 @@ void RequestWorker::stop()
|
|||
if(timer->isActive())
|
||||
timer->stop();
|
||||
stop_timer = true;
|
||||
qDebug() << "Stopping" << timer->isActive();
|
||||
}
|
||||
|
||||
void RequestWorker::makeRequest()
|
||||
|
|
@ -70,11 +71,18 @@ void RequestWorker::requestFinished(QNetworkReply *rep)
|
|||
rep = nullptr;
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto time_diff = std::chrono::duration_cast<std::chrono::microseconds>(now - prev_time);
|
||||
if(data.size() == 0) {
|
||||
prev_time = now;
|
||||
timer->start();
|
||||
emit requestFailed();
|
||||
emit setStatus("Invalid Response; Resending Request");
|
||||
return;
|
||||
}
|
||||
unsigned int time_in_microseconds = time_diff.count();
|
||||
QJsonObject jdata = QJsonDocument::fromJson(data).object();
|
||||
auto data_water_level = jdata["water_level"].toInt();
|
||||
float water_level = (float) ((float) (data_water_level) / 10.0);
|
||||
float rate_of_fill = ( float )(water_level - prev_distance) /(float) time_in_microseconds;
|
||||
float rate_of_fill = ( float )(prev_distance - water_level) /(float) time_in_microseconds;
|
||||
rate_of_fill = rate_of_fill * 1'000'000;
|
||||
int expected_to_fill = (max_height - water_level) / rate_of_fill;
|
||||
if(reply_number == 0) {
|
||||
|
|
@ -87,7 +95,7 @@ void RequestWorker::requestFinished(QNetworkReply *rep)
|
|||
qDebug() << "Got expected to fill: " << expected_to_fill;
|
||||
qDebug() << "Time difference: " << time_in_microseconds;
|
||||
prev_distance = water_level;
|
||||
emit networkReply(water_level, rate_of_fill, expected_to_fill);
|
||||
emit networkReply(data_water_level, rate_of_fill, expected_to_fill);
|
||||
if(stop_timer) {
|
||||
setStatus("Timer stopped.");
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue