3.10.2013 - PIPeer release, PIConsole now can work as server and remote client. Remote console test program in directory "remote_console"
This commit is contained in:
99
pidiagnostics.cpp
Normal file
99
pidiagnostics.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Speed and quality in/out diagnostics
|
||||
Copyright (C) 2013 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "pidiagnostics.h"
|
||||
|
||||
|
||||
PIDiagnostics::PIDiagnostics(bool start_): PITimer() {
|
||||
PITimer::reset();
|
||||
reset();
|
||||
if (start_) start();
|
||||
}
|
||||
|
||||
|
||||
void PIDiagnostics::reset() {
|
||||
lock();
|
||||
qual = PIDiagnostics::Unknown;
|
||||
speedIn = speedOut = PIString::readableSize(0) + "/s";
|
||||
ifreq = immediate_freq = integral_freq = 0.f;
|
||||
packets[0] = packets[1] = 0;
|
||||
cur_pckt = rec_once = 0;
|
||||
wrong_count = receive_count = send_count = 0;
|
||||
packets_in_sec = packets_out_sec = bytes_in_sec = bytes_out_sec = 0;
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIDiagnostics::received(int size, bool correct) {
|
||||
lock();
|
||||
packets[correct ? 1 : 0]++;
|
||||
rec_once = 1;
|
||||
if (correct) {
|
||||
float el = elapsed_s();
|
||||
if (el > 0.f) immediate_freq = ifreq = 1.f / el;
|
||||
else immediate_freq = ifreq = 0.f;
|
||||
PITimer::reset();
|
||||
receive_count++;
|
||||
packets_in_sec++;
|
||||
bytes_in_sec += size;
|
||||
} else {
|
||||
immediate_freq = ifreq = 0.f;
|
||||
wrong_count++;
|
||||
}
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIDiagnostics::sended(int size) {
|
||||
lock();
|
||||
send_count++;
|
||||
packets_out_sec++;
|
||||
bytes_out_sec += size;
|
||||
unlock();
|
||||
}
|
||||
|
||||
|
||||
void PIDiagnostics::tick(void * data, int delimiter) {
|
||||
lock();
|
||||
PIDiagnostics::Quality diag;
|
||||
float fdel = 1. / (interval() / 1000.);
|
||||
immediate_freq = ifreq;
|
||||
ifreq = 0.f;
|
||||
speedIn = PIString::readableSize(bytes_in_sec * fdel) + "/s";
|
||||
speedOut = PIString::readableSize(bytes_out_sec * fdel) + "/s";
|
||||
bytes_in_sec = bytes_out_sec = packets_in_sec = packets_out_sec = 0;
|
||||
int arc = packets[0] + packets[1];
|
||||
float good_percents = 0.f;
|
||||
if (arc > 0) good_percents = (float)packets[1] / arc * 100.f;
|
||||
integral_freq = packets[1] * fdel;
|
||||
if (rec_once == 0) {
|
||||
diag = PIDiagnostics::Unknown;
|
||||
} else {
|
||||
if (good_percents == 0.f) diag = PIDiagnostics::Failure;
|
||||
else if (good_percents <= 20.f) diag = PIDiagnostics::Bad;
|
||||
else if (good_percents > 20.f && good_percents <= 80.f) diag = PIDiagnostics::Average;
|
||||
else diag = PIDiagnostics::Good;
|
||||
if (diag != qual) {
|
||||
qualityChanged(diag, qual);
|
||||
qual = diag;
|
||||
}
|
||||
}
|
||||
packets[0] = packets[1] = 0;
|
||||
unlock();
|
||||
}
|
||||
Reference in New Issue
Block a user