18.03.2013 - Bug fixes, add in/out speed diagnostic to PIProtocol, fixed PIConsole tab switch segfault, PIObject EVENT / EVENT_HANDLER mechanism update - new EVENT macros that use EVENT_HANDLER with raiseEvent implementation.
This allow compile check event for CONNECT and use EVENT as CONNECT target, also raise event now is simple execute EVENT function.
This commit is contained in:
264
main.cpp
Executable file → Normal file
264
main.cpp
Executable file → Normal file
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Test program
|
||||
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
|
||||
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
|
||||
@@ -63,8 +63,7 @@ void timerEvent(void * data, int delim) {
|
||||
cout << " tick from constuctor, delimiter = " << delim << ", data = " << data << endl;
|
||||
};
|
||||
|
||||
bool
|
||||
t2 = false;
|
||||
bool t2 = false;
|
||||
void timerEvent2(void * data, int delim) {
|
||||
t2 = true;
|
||||
cout << " tick from delimiter " << delim << ", data = " << data << endl;
|
||||
@@ -86,12 +85,16 @@ public:
|
||||
ObjectTest2(const PIString & name = PIString()): PIObject(name) {;}
|
||||
void raise0(const PIString & e) {cout << " event \"" << e << "\" from \"" << name() << "\"" << endl; raiseEvent(this, e);}
|
||||
void raise2(const PIString & e, int i, const PIString & s) {cout << " event \"" << e << "\" from \"" << name() << "\"" << endl; raiseEvent<int, PIString>(this, e, i, s);}
|
||||
EVENT(ObjectTest2, event0)
|
||||
EVENT(ObjectTest2, event2)
|
||||
|
||||
};
|
||||
|
||||
class CA: public PIObject {
|
||||
public:
|
||||
CA(const PIString & n): PIObject(n) {;}
|
||||
EVENT_HANDLER(CA, void, handler_ca) {a = true; cout << " handler CA" << endl;}
|
||||
EVENT(CA, event_ca)
|
||||
bool a;
|
||||
};
|
||||
|
||||
@@ -124,60 +127,212 @@ struct Packet {
|
||||
int cs;
|
||||
};
|
||||
|
||||
bool retH(void * d, uchar * src, uchar * rec, int size) {
|
||||
return (*((int*)rec)) == 1;
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
struct InpuData {
|
||||
uint first_number; // Номер первого отсчета
|
||||
struct {
|
||||
uchar packet_number: 7; // Идентификационный код пакета
|
||||
uchar packet_last : 1; // Признак последнего пакета
|
||||
};
|
||||
struct {
|
||||
uchar antenna_number : 3; // Номер антенного канала
|
||||
uchar frequency_number: 3; // Номер частотного канала
|
||||
uchar data_type : 2; // Вид передаваемой информации: 0 – оцифровка, 1 – измеренные параметры
|
||||
};
|
||||
uchar data[122]; // Данные
|
||||
};
|
||||
|
||||
struct msgHeader {
|
||||
char sign[4];
|
||||
unsigned short size;
|
||||
unsigned short cnt;
|
||||
unsigned char fragment;
|
||||
unsigned short msg_id;
|
||||
unsigned char sys_id;
|
||||
unsigned char subsys_id;
|
||||
unsigned char security;
|
||||
bool verify_sign()
|
||||
{
|
||||
bool ok;
|
||||
ok = sign[0] == 'B';
|
||||
ok = ok && sign[1] == 'R';
|
||||
ok = ok && sign[2] == 'K';
|
||||
ok = ok && sign[3] == 'D';
|
||||
return ok;
|
||||
}
|
||||
};
|
||||
struct FilterCommand {
|
||||
FilterCommand() {
|
||||
memset(this, 0, sizeof(FilterCommand));
|
||||
header.sign[0] = 'B'; header.sign[1] = 'R'; header.sign[2] = 'K'; header.sign[3] = 'D';
|
||||
header.size = sizeof(FilterCommand);
|
||||
header.cnt = header.fragment = header.security = 0;
|
||||
header.msg_id = 2102;
|
||||
header.sys_id = header.subsys_id = 2;
|
||||
command = 3;
|
||||
}
|
||||
|
||||
msgHeader header;
|
||||
uchar command; // 3
|
||||
struct {
|
||||
uchar fi_number: 7; // номер частотного участка, 1 - 36
|
||||
uchar bort : 1; // борт: 0 - левый, 1 - правый
|
||||
};
|
||||
ushort freq_start; // начальная частота, 0 - 6100
|
||||
ushort freq_end; // конечная частота, 0 - 6100
|
||||
uchar filter_bandwith; // полоса проспускания фильтра
|
||||
ushort filter_time_step; // время шага фильтра по времени
|
||||
uchar reserve;
|
||||
ushort record_time_start; // начальное время записи, 1 - 60 мс
|
||||
ushort record_time_end; // конечное время записи, 1 - 60 мс
|
||||
uchar record_channels; // номера каналов для записи, 0 - 5 биты
|
||||
uchar play_channels; // номера каналов для воспроизведения, 0 - 5 биты
|
||||
uchar signal_type; // тип сигнала для выдачи, 0 - С3, 1 - С4, 2 - С4Ф, 3 - выборка
|
||||
ushort play_time_start; // начальное время воспроизведения, 1 - 60 мс
|
||||
ushort play_time_end; // конечное время воспроизведения, 1 - 60 мс
|
||||
uchar checksum;
|
||||
};
|
||||
|
||||
bool retF(void * d, uchar * data, int size) {
|
||||
cout << "rec " << size << endl;
|
||||
return true;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
void te(void*, int);
|
||||
PITimer tm_(te);
|
||||
PISerial ser("/dev/ttyS0");
|
||||
bool pins[9];
|
||||
void te(void*, int) {
|
||||
for (int i = 1; i <= 9; ++i)
|
||||
pins[i - 1] = ser.isPin(i);
|
||||
}
|
||||
void ke(char key, void*) {
|
||||
int p = key - '0';
|
||||
if (key >= '1' && key <= '9')
|
||||
ser.setPin(p, !pins[p - 1]);
|
||||
}
|
||||
int main(int argc, char * argv[]) {
|
||||
/*Packet p, mp;
|
||||
p.from = mp.from = 1;
|
||||
p.to = mp.to = 2;
|
||||
PISerial ser("/dev/ttyS0");
|
||||
ser.setSpeed(PISerial::S115200);
|
||||
/*tm_.start(10.);
|
||||
PIConsole con(false, ke);
|
||||
con.enableExitCapture();
|
||||
//ser.setParameter(PISerial::HardwareFlowControl);
|
||||
ser.open();
|
||||
ser.setReadIsBlocking(true);
|
||||
PIPacketExtractor pe(&ser, &mp, 8, 8);
|
||||
pe.setThreadedReadSlot(retF);
|
||||
pe.setHeaderCheckSlot(retH);
|
||||
pe.startThreadedRead();
|
||||
ser.write(&p, sizeof(p));
|
||||
p.from = 2;
|
||||
ser.write(&p, sizeof(p));
|
||||
msleep(1000);
|
||||
exit(0);*/
|
||||
PICodec codec;
|
||||
con.addVariable("1 (CAR)", pins);
|
||||
con.addVariable("2 (SR) ", pins + 1);
|
||||
con.addVariable("3 (ST) ", pins + 2);
|
||||
con.addVariable("4 (DTR)", pins + 3);
|
||||
con.addVariable("5 (GND)", pins + 4);
|
||||
con.addVariable("6 (DSR)", pins + 5);
|
||||
con.addVariable("7 (RTS)", pins + 6);
|
||||
con.addVariable("8 (CTS)", pins + 7);
|
||||
con.addVariable("9 (RNG)", pins + 8);
|
||||
con.start();
|
||||
con.waitForFinish();
|
||||
return 0;*/
|
||||
|
||||
/*FilterCommand fc;
|
||||
PIEthernet eth(PIEthernet::TCP_SingleTCP);
|
||||
eth.open("127.0.0.1:10201");
|
||||
while (1) {
|
||||
eth.read(&fc, sizeof(fc));
|
||||
cout << int(fc.fi_number) << ", " << int(fc.bort) << ", " << int(fc.freq_start) << ", " << int(fc.freq_end) << ", " << int(fc.play_channels) << ", " << int(fc.record_channels) << endl;
|
||||
}
|
||||
return 0;*/
|
||||
|
||||
exit(0);
|
||||
/*
|
||||
vec<int> my_v; vector<int> stl_v; QVector<int> qt_v;
|
||||
double el;
|
||||
PITimer tm;
|
||||
/*PIDir dir(argv[1]);
|
||||
FILE*f = popen("cd ../ && pwd", "w");
|
||||
char fd[4096];
|
||||
int ret = fread(fd, 4096, 1, f);
|
||||
pclose(f);
|
||||
cout << PIString(fd, ret);
|
||||
f = popen("cd ../ && pwd", "w");
|
||||
ret = fread(fd, 4096, 1, f);
|
||||
pclose(f);
|
||||
cout << PIString(fd, ret);
|
||||
return 0;
|
||||
cout << dir.path() << endl;
|
||||
dir.up();
|
||||
cout << dir.path() << endl;
|
||||
PIVector<PIDir::DirEntry> ent = dir.entries();
|
||||
piForeachC (PIDir::DirEntry & i, ent)
|
||||
cout << i.mode << " " << PIString::readableSize(i.size).expandRightTo(10, ' ') << " " << i.name << endl;*/
|
||||
|
||||
/*PISystemTime st_time, inc_time;
|
||||
PITimer tm_;
|
||||
tm_.reset();
|
||||
inc_time = PISystemTime::fromMilliseconds(50);
|
||||
st_time = currentSystemTime() + inc_time;
|
||||
int cnt = 100;
|
||||
while (cnt--) {
|
||||
(st_time - currentSystemTime()).sleep();
|
||||
{
|
||||
msleep(49);
|
||||
cout << "tick " << cnt << endl;
|
||||
}
|
||||
st_time += inc_time;
|
||||
}
|
||||
cout << tm_.elapsed_s() - 0.049 << endl;*/
|
||||
|
||||
/*PISystemTime t0, inc_time;
|
||||
PITimer tm_;
|
||||
tm_.reset();
|
||||
inc_time = PISystemTime::fromMilliseconds(50);
|
||||
inc_time.sleep();
|
||||
int cnt = 100;
|
||||
while (cnt--) {
|
||||
t0 = currentSystemTime();
|
||||
{
|
||||
msleep(49);
|
||||
cout << "tick " << cnt << endl;
|
||||
}
|
||||
(inc_time - (currentSystemTime() - t0)).sleep();
|
||||
}
|
||||
cout << tm_.elapsed_s() - 0.049 << endl;*/
|
||||
|
||||
//return 0;
|
||||
|
||||
/*InpuData data;
|
||||
PIEthernet eth(PIEthernet::UDP);
|
||||
data.first_number = 0;
|
||||
data.packet_number = 0;
|
||||
data.packet_last = 0;
|
||||
data.antenna_number = data.frequency_number = data.data_type = 0;
|
||||
PIBitArray ba_;
|
||||
for (int i = 0; i < 97; ++i) {
|
||||
for (int b = 0; b < 10; ++b)
|
||||
ba_.push_back(((i >> b) & 1) == 1);
|
||||
}
|
||||
//cout << ba_.byteSize() << ", " << ba_.bitSize() << endl;
|
||||
memcpy(data.data, ba_.data(), 122);
|
||||
cout << ba_ << endl;
|
||||
for (int i = 0; i < 122; ++i)
|
||||
cout << int(data.data[i]) << ", ";
|
||||
cout << endl;
|
||||
eth.send("127.0.0.1:5000", &data, sizeof(data));
|
||||
return 0;*/
|
||||
|
||||
/*QApplication app(argc, argv);
|
||||
PIFFT fft;
|
||||
PIVector<complexd> in;
|
||||
in.resize(50*1000);
|
||||
for (int i=400; i<404; i++) in[i] = complexd(1,0);
|
||||
PITimer timer_;
|
||||
fft.prepareFFT(in.size());
|
||||
timer_.reset();
|
||||
PIVector<complexd> * out = fft.calcFFT(in);
|
||||
cout << timer_.elapsed_m() << endl;
|
||||
Graphic * g = new Graphic();
|
||||
QVector<QPointF> res;
|
||||
fft.getAmplitude();
|
||||
for (int i=0; i<out->size(); i++) res.append(QPointF(i,abs(out->at(i))));
|
||||
g->setGraphicData(res);
|
||||
g->addGraphic("arg", Qt::darkBlue);
|
||||
res.clear();
|
||||
for (int i=0; i< out->size(); i++) res.append(QPointF(i,arg(out->at(i))));
|
||||
g->setGraphicData(res, 1);
|
||||
g->show();
|
||||
|
||||
tm.reset();
|
||||
for (uint i = 0; i < 500000; ++i)
|
||||
my_v.push_back(i);
|
||||
el = tm.elapsed_m();
|
||||
cout << el << endl;
|
||||
|
||||
tm.reset();
|
||||
for (uint i = 0; i < 500000; ++i)
|
||||
stl_v.push_back(i);
|
||||
el = tm.elapsed_m();
|
||||
cout << el << endl;
|
||||
|
||||
tm.reset();
|
||||
for (uint i = 0; i < 500000; ++i)
|
||||
qt_v.append(i);
|
||||
el = tm.elapsed_m();
|
||||
cout << el << endl;
|
||||
|
||||
exit(0);
|
||||
*/
|
||||
return app.exec();*/
|
||||
|
||||
bool r_string = true, r_thread = true, r_mutex = true, r_timer = true, r_file = true, r_eval = true, r_event = true;
|
||||
bool succ = true;
|
||||
cout << "== PIP test program ==" << endl;
|
||||
@@ -189,8 +344,10 @@ int main(int argc, char * argv[]) {
|
||||
cout << " to char * = \"" << string.data() << "\"" << endl;
|
||||
cout << " to std::string = \"" << string.stdString() << "\"" << endl;
|
||||
if (string.stdString().length() != 11) succ = r_string = false;
|
||||
#ifdef HAS_LOCALE
|
||||
cout << " to std::wstring = \"" << string.stdWString() << "\"" << endl;
|
||||
if (string.stdWString().length() != 11) succ = r_string = false;
|
||||
#endif
|
||||
if (succ) cout << " convertions success" << endl;
|
||||
else cout << " convertions fail" << endl;
|
||||
succ = true;
|
||||
@@ -199,9 +356,11 @@ int main(int argc, char * argv[]) {
|
||||
if (string.length() != 5) succ = r_string = false;
|
||||
cout << " to char * = \"" << string.data() << "\"" << endl;
|
||||
cout << " to std::string = \"" << string.stdString() << "\"" << endl;
|
||||
if (string.stdString().length() != 10) succ = r_string = false;
|
||||
if (string.stdString().length() != 11) succ = r_string = false;
|
||||
#ifdef HAS_LOCALE
|
||||
cout << " to std::wstring = \"" << string.stdWString() << "\"" << endl;
|
||||
if (string.stdWString().length() != 5) succ = r_string = false;
|
||||
#endif
|
||||
if (succ) cout << " complex convertions success" << endl;
|
||||
else cout << " complex convertions fail" << endl;
|
||||
if (r_string) cout << "== Success ==" << endl;
|
||||
@@ -244,6 +403,7 @@ int main(int argc, char * argv[]) {
|
||||
cout << " file \"" << file.path() << "\" is ";
|
||||
if (!file.isOpened()) cout << "not ";
|
||||
cout << "opened" << endl;
|
||||
file.clear();
|
||||
file << "test string";
|
||||
cout << " write " << file.pos() << " bytes" << endl;
|
||||
if (file.pos() != 11) r_file = false;
|
||||
@@ -264,7 +424,7 @@ int main(int argc, char * argv[]) {
|
||||
cout << " error = \"" << evaluator.error() << '\"' << endl;
|
||||
cout << " \"x\" = " << evaluator.content.variable("x").value << endl;
|
||||
cout << " result = " << evaluator.evaluate() << endl;
|
||||
r_eval = round(evaluator.lastResult()) == complexd(9., 12.);
|
||||
r_eval = round(evaluator.lastResult()) == complexd(6., 9.);
|
||||
if (r_eval) cout << "== Success ==" << endl;
|
||||
else cout << "== Fail ==" << endl;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user