add diag to basetransfer
fix pibinarylog delay git-svn-id: svn://db.shs.com.ru/pip@63 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
project(pip)
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
|
||||
include(CheckFunctionExists)
|
||||
@@ -120,7 +120,7 @@ if (${WIN32})
|
||||
#list(APPEND CPPS "pip_resource_win.o")
|
||||
list(APPEND CPPS "pip_resource_win.rc")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPSAPI_VERSION=1")
|
||||
add_library(pip SHARED ${CPPS})
|
||||
add_library(pip SHARED ${CPPS} ${HDRS})
|
||||
if (${CMAKE_C_COMPILER} STREQUAL "cl")
|
||||
include(GenerateExportHeader)
|
||||
generate_export_header(pip)
|
||||
@@ -154,7 +154,7 @@ set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
#find_package(Qt4 REQUIRED)
|
||||
#include_directories(${QT_INCLUDES})
|
||||
add_executable(pip_test "main.cpp" "ccm_kbd.cpp")
|
||||
target_link_libraries(pip_test pip)# ${QT_QTCORE_LIBRARY})
|
||||
target_link_libraries(pip_test pip gmp-3)# ${QT_QTCORE_LIBRARY})
|
||||
#target_link_libraries(pip_test pip)
|
||||
|
||||
|
||||
|
||||
112
main.cpp
112
main.cpp
@@ -133,9 +133,119 @@ public:
|
||||
void print() {piCout << "Child"; Parent::print();}
|
||||
};
|
||||
|
||||
|
||||
//#include <netdb.h>
|
||||
|
||||
|
||||
template<int Precision = 0, typename Type = int>
|
||||
class FixedPoint {
|
||||
// friend PICout operator <<(PICout s, const FixedPoint<> & v);
|
||||
public:
|
||||
typedef FixedPoint<Precision, Type> fp;
|
||||
FixedPoint(const Type &v = Type()) {val = fpv(v);}
|
||||
FixedPoint(const fp &v) {val = v.val;}
|
||||
FixedPoint(const float &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));}
|
||||
FixedPoint(const double &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));}
|
||||
// FixedPoint(const long double &v) {val = Precision == 0 ? Type(v) : Type(v * (2 << Precision-1));}
|
||||
|
||||
template<typename T>
|
||||
fp & operator=(const T & v) {val = fpv(Type(v)); return *this;}
|
||||
fp & operator=(const fp & v) {val = v.val; return *this;}
|
||||
fp & operator=(const float &v) {val = FixedPoint(v).val; return *this;}
|
||||
fp & operator=(const double &v) {val = FixedPoint(v).val; return *this;}
|
||||
fp & operator=(const long double &v) {val = FixedPoint(v).val; return *this;}
|
||||
fp & operator-() {fp p = fp(*this); p.val = -val; return p;}
|
||||
bool operator==(const fp & v) const {val == v.val;}
|
||||
bool operator!=(const fp & v) const {val != v.val;}
|
||||
|
||||
void operator+=(const fp & v) {val += v.val;}
|
||||
void operator-=(const fp & v) {val -= v.val;}
|
||||
|
||||
void operator*=(const fp & v) {val = fpi(val *v.val);}
|
||||
void operator/=(const fp & v) {val = fpv(val) / v.val;}
|
||||
|
||||
fp operator+(const fp & v) {fp p = fp(*this); p.val += v.val; return p;}
|
||||
fp operator-(const fp & v) {fp p = fp(*this); p.val -= v.val; return p;}
|
||||
|
||||
fp operator*(const fp & v) {fp p; p.val = fpi(val * v.val); return p;}
|
||||
fp operator/(const fp & v) {fp p; p.val = fpv(val) / v.val; return p;}
|
||||
|
||||
/*fp & operator =(const Type & v) {val = fpv(v); return *this;}
|
||||
bool operator ==(const Type & v) const {val == fpv(v);}
|
||||
bool operator !=(const Type & v) const {val != fpv(v);}
|
||||
void operator +=(const Type & v) {val += fpv(v);}
|
||||
void operator -=(const Type & v) {val -= fpv(v);}
|
||||
void operator *=(const Type & v) {val *= fpv(v);}
|
||||
void operator /=(const Type & v) {val /= fpv(v);}
|
||||
fp operator +(const Type & v) {fp p = fp(*this); p.val += fpv(v); return p;}
|
||||
fp operator -(const Type & v) {fp p = fp(*this); p.val -= fpv(v); return p;}
|
||||
fp operator *(const Type & v) {fp p = fp(*this); p.val *= fpv(v); return p;}
|
||||
fp operator /(const Type & v) {fp p = fp(*this); p.val /= fpv(v); return p;}*/
|
||||
|
||||
Type fpv(Type v) const {return Type(v << Precision);}
|
||||
Type fpi(Type v) const {return Type(v >> Precision);}
|
||||
Type fpc(Type v) const {return v - fpv(fpi(v));}
|
||||
Type val;
|
||||
};
|
||||
|
||||
template<int Precision, typename Type>
|
||||
inline PICout operator <<(PICout s, const FixedPoint<Precision, Type> & v) {
|
||||
s.space(); s.setControl(0, true);
|
||||
if (Precision == 0) s << v.val;
|
||||
else {
|
||||
std::stringstream ss,sr;
|
||||
Type tmp = 10;
|
||||
int n = 1;
|
||||
Type rs = (2 << Precision-1);
|
||||
while(tmp < rs) tmp = tmp*10, n++;
|
||||
tmp *= 10; n++;
|
||||
Type rv = v.fpc(v.val);
|
||||
if (rv != 0) tmp = tmp / (rs / rv);
|
||||
ss << tmp;
|
||||
PIString r = ss.str();
|
||||
if (rv == 0) r.pop_front();
|
||||
else r.expandLeftTo(n,'0');
|
||||
sr << v.fpi(v.val);
|
||||
s << PIString(sr.str()) + "." + r;
|
||||
}
|
||||
s.restoreControl();
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#include "mpint.h"
|
||||
int main (int argc, char * argv[]) {
|
||||
piCout << PIDir::allEntries(argv[1]);
|
||||
FixedPoint<16, long long> a, b;
|
||||
a = 10;
|
||||
b = 3;
|
||||
piCout << a << b << a/b;
|
||||
FixedPoint<7,ushort> c = 507.03;
|
||||
piCout << c;
|
||||
// gmp::mpint m1("1003456789098765432334567890743278908743789087345678909876543213456789098765422"),
|
||||
// m2("523456789085039345678909856787656787654383071478723617832987864856248765784547826784659267894659782645824317172186776677");
|
||||
// FixedPoint<1, gmp::mpint> mf1(m1);
|
||||
// PITimeMeasurer tm3;
|
||||
// for (int i=0; i< 1000; i++)
|
||||
// m1 = m1*m2;//gmp::mpint(1);
|
||||
//// m1 = m1 >> 64;
|
||||
// piCout << tm3.elapsed_m();
|
||||
// tm3.reset();
|
||||
// piCout << m1;
|
||||
// piCout << tm3.elapsed_m();
|
||||
//m1++;
|
||||
complex<FixedPoint<8,int> > ccc;
|
||||
piCout << ccc;
|
||||
return 0;
|
||||
|
||||
FixedPoint<4> x,y,z;
|
||||
y = 20;
|
||||
z = 0.01;
|
||||
x = z*y;
|
||||
piCout << x;
|
||||
piCout << y;
|
||||
piCout << z;
|
||||
return 0;
|
||||
/*
|
||||
hostent * he = 0;
|
||||
|
||||
@@ -12,6 +12,7 @@ PIBaseTransfer::PIBaseTransfer(): crc(standardCRC_16()) {
|
||||
bytes_all = bytes_cur = 0;
|
||||
replies_cnt = send_queue = 0;
|
||||
timeout_ = 10.;
|
||||
diag.setDisconnectTimeout(10.);
|
||||
packets_count = 32;
|
||||
setPacketSize(4096);
|
||||
srand(PISystemTime::current().toMilliseconds());
|
||||
@@ -41,11 +42,15 @@ void PIBaseTransfer::stopReceive() {
|
||||
void PIBaseTransfer::received(PIByteArray data) {
|
||||
packet_header_size = sizeof(PacketHeader) + customHeader().size();
|
||||
// piCoutObj << "receive" << data.size();
|
||||
if (data.size() < sizeof(PacketHeader)) return;
|
||||
if (data.size() < sizeof(PacketHeader)) {
|
||||
diag.received(data.size(), false);
|
||||
return;
|
||||
}
|
||||
PacketHeader h;
|
||||
data >> h;
|
||||
PacketType pt = (PacketType)h.type;
|
||||
// piCoutObj << "receive" << h.session_id << h.type << h.id;
|
||||
diag.received(data.size(), true);
|
||||
switch (pt) {
|
||||
case pt_Unknown: break;
|
||||
case pt_Data:
|
||||
@@ -117,6 +122,8 @@ void PIBaseTransfer::received(PIByteArray data) {
|
||||
replies.fill(pt_Unknown);
|
||||
is_receiving = true;
|
||||
break_ = false;
|
||||
diag.reset();
|
||||
diag.start();
|
||||
receiveStarted();
|
||||
replies_cnt = send_queue = 0;
|
||||
state_string = "receiving";
|
||||
@@ -133,6 +140,8 @@ bool PIBaseTransfer::send_process() {
|
||||
packet_header_size = sizeof(PacketHeader) + customHeader().size();
|
||||
break_ = false;
|
||||
is_sending = true;
|
||||
diag.reset();
|
||||
diag.start();
|
||||
sendStarted();
|
||||
replies.resize(session.size() + 1);
|
||||
replies.fill(pt_Unknown);
|
||||
@@ -154,6 +163,7 @@ bool PIBaseTransfer::send_process() {
|
||||
}
|
||||
stm.reset();
|
||||
ba = build_packet(i);
|
||||
diag.sended(ba.size());
|
||||
sendRequest(ba);
|
||||
send_queue++;
|
||||
if (break_) return finish_send(false);
|
||||
@@ -178,6 +188,7 @@ bool PIBaseTransfer::send_process() {
|
||||
continue;
|
||||
}
|
||||
ba = build_packet(chk - 1);
|
||||
diag.sended(ba.size());
|
||||
sendRequest(ba);
|
||||
send_queue++;
|
||||
}
|
||||
@@ -275,6 +286,7 @@ void PIBaseTransfer::sendReply(PacketType reply) {
|
||||
header.type = reply;
|
||||
PIByteArray ba;
|
||||
ba << header;
|
||||
diag.sended(ba.size());
|
||||
sendRequest(ba);
|
||||
}
|
||||
|
||||
@@ -291,6 +303,7 @@ bool PIBaseTransfer::getStartRequest() {
|
||||
ba << st;
|
||||
state_string = "send request";
|
||||
while (tm.elapsed_s() < timeout_) {
|
||||
diag.sended(ba.size());
|
||||
sendRequest(ba);
|
||||
if (break_) return false;
|
||||
//piCoutObj << send_replyes[0];
|
||||
@@ -372,6 +385,7 @@ bool PIBaseTransfer::finish_send(bool ok) {
|
||||
header.id = 0;
|
||||
if (!ok) sendBreak(header.session_id);
|
||||
else sendReply(pt_ReplySuccess);
|
||||
diag.stop();
|
||||
sendFinished(ok);
|
||||
bytes_all = bytes_cur = 0;
|
||||
return ok;
|
||||
@@ -384,6 +398,7 @@ void PIBaseTransfer::finish_receive(bool ok) {
|
||||
// piCoutObj << state_string << PIString::readableSize(bytes_all);
|
||||
is_receiving = false;
|
||||
if (!ok) sendBreak(header.session_id);
|
||||
diag.stop();
|
||||
receiveFinished(ok);
|
||||
bytes_all = bytes_cur = 0;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "picrc.h"
|
||||
#include "pitimer.h"
|
||||
#include "pidiagnostics.h"
|
||||
|
||||
class PIBaseTransfer: public PIObject
|
||||
{
|
||||
@@ -38,7 +39,7 @@ public:
|
||||
void setPacketSize(int size) {packet_size = size;}
|
||||
int packetSize() const {return packet_size;}
|
||||
|
||||
void setTimeout(double sec) {timeout_ = sec;}
|
||||
void setTimeout(double sec) {timeout_ = sec; diag.setDisconnectTimeout(sec);}
|
||||
double timeout() const {return timeout_;}
|
||||
|
||||
const PIString & stateString() const {return state_string;}
|
||||
@@ -47,6 +48,7 @@ public:
|
||||
const PIString * stateString_ptr() const {return &state_string;}
|
||||
const llong * bytesAll_ptr() const {return &bytes_all;}
|
||||
const llong * bytesCur_ptr() const {return &bytes_cur;}
|
||||
const PIDiagnostics &diagnostic() {return diag;}
|
||||
|
||||
EVENT(receiveStarted)
|
||||
EVENT1(receiveFinished, bool, ok)
|
||||
@@ -89,7 +91,8 @@ private:
|
||||
PITimeMeasurer send_tm;
|
||||
PacketHeader header;
|
||||
CRC_16 crc;
|
||||
int replies_cnt, send_queue;
|
||||
int replies_cnt, send_queue;
|
||||
PIDiagnostics diag;
|
||||
|
||||
void processData(int id, PIByteArray &data);
|
||||
PIByteArray build_packet(int id);
|
||||
|
||||
@@ -142,11 +142,20 @@ bool PIBinaryLog::threadedRead(uchar *readed, int size) {
|
||||
break;
|
||||
case PlayVariableSpeed:
|
||||
delay = lastrecord.timestamp.toMilliseconds() - play_time;
|
||||
delay /= play_speed;
|
||||
double cdelay;
|
||||
int dtc;
|
||||
if (is_started) {
|
||||
if (delay > 0)
|
||||
/// TODO: Sleep by steps (about 100ms)
|
||||
PISystemTime::fromMilliseconds(delay).sleep();
|
||||
if (delay > 0) {
|
||||
cdelay = delay / play_speed;
|
||||
dtc = int(cdelay) /100;
|
||||
for (int j=0; j<dtc; j++) {
|
||||
cdelay = delay / play_speed;
|
||||
dtc = int(cdelay) /100;
|
||||
PISystemTime::fromMilliseconds(100).sleep();
|
||||
}
|
||||
cdelay = cdelay - dtc*100;
|
||||
PISystemTime::fromMilliseconds(cdelay).sleep();
|
||||
}
|
||||
} else is_started = true;
|
||||
play_time = lastrecord.timestamp.toMilliseconds();
|
||||
break;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#define PIBINARYLOG_VERSION 0x31
|
||||
namespace __S__PIBinaryLog {
|
||||
static const uchar binlog_sig[] = {'B','I','N','L','O','G'};
|
||||
};
|
||||
}
|
||||
#define PIBINARYLOG_SIGNATURE_SIZE sizeof(__S__PIBinaryLog::binlog_sig)
|
||||
|
||||
/// TODO: Create static functions to split and join binlog files
|
||||
|
||||
@@ -47,8 +47,8 @@ private:
|
||||
};
|
||||
|
||||
EVENT_HANDLER1(void, keyEvent, PIKbdListener::KeyEvent, key);
|
||||
EVENT1(tileKey, PIKbdListener::KeyEvent, key);
|
||||
EVENT(menuRequest);
|
||||
EVENT1(tileKey, PIKbdListener::KeyEvent, key)
|
||||
EVENT(menuRequest)
|
||||
static void tileKey_s(void * fm, PIKbdListener::KeyEvent key) {((FileManager*)fm)->tileKey(key);}
|
||||
void updateConsole();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user