15.10.2012 - version 0.2.0 - PIIODevice - base of file, ethernet, serial and packets extractor. PIEthernet now support also TCP (client and server). PIConsole now can align labels in each column individually.
This commit is contained in:
107
main.cpp
Normal file → Executable file
107
main.cpp
Normal file → Executable file
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Test program
|
||||
Copyright (C) 2011 Ivan Pelipenko peri4ko@gmail.com
|
||||
Copyright (C) 2012 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
|
||||
@@ -117,66 +117,67 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
#pragma pack(push, 1)
|
||||
struct Data {
|
||||
ushort header;
|
||||
int counter;
|
||||
float f0;
|
||||
float f1;
|
||||
ushort checksum;
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
class Prot: public PIProtocol {
|
||||
public:
|
||||
Prot() {
|
||||
setReceiverDevice("/dev/ttyS0", PISerial::S115200, true);
|
||||
setReceiverDataHeader(&rec, 2);
|
||||
setReceiverData(&rec.counter, sizeof(rec) - 2);
|
||||
setSenderData(&send, sizeof(send));
|
||||
setExpectedFrequency(20.f);
|
||||
setSenderFrequency(20.f);
|
||||
send.header = 0xAABB;
|
||||
rec.header = 0xAABB;
|
||||
start();
|
||||
}
|
||||
|
||||
virtual bool validate() {
|
||||
if (rec.checksum != PIByteArray(&rec, sizeof(rec)-2).checksumCRC16()) return false;
|
||||
return true;
|
||||
}
|
||||
virtual bool aboutSend() {
|
||||
send.counter++;
|
||||
send.checksum = PIByteArray(&send, sizeof(send)-2).checksumCRC16();
|
||||
return true;
|
||||
}
|
||||
|
||||
Data send, rec;
|
||||
struct Packet {
|
||||
int from;
|
||||
int to;
|
||||
float data;
|
||||
int cs;
|
||||
};
|
||||
|
||||
Prot p;
|
||||
bool retH(void * d, uchar * src, uchar * rec, int size) {
|
||||
return (*((int*)rec)) == 1;
|
||||
};
|
||||
|
||||
void key(char k, void*) {
|
||||
switch (k) {
|
||||
case '0': p.setSenderData(&p.send, sizeof(p.send)); break;
|
||||
case '1': p.setSenderData(&p.send, sizeof(p.send) - 1); break;
|
||||
case '2': p.send.header = 0xAABB; break;
|
||||
case '3': p.send.header = 0xACBD; break;
|
||||
}
|
||||
}
|
||||
bool retF(void * d, uchar * data, int size) {
|
||||
cout << "rec " << size << endl;
|
||||
return true;
|
||||
};
|
||||
|
||||
PIConsole c(false, key);
|
||||
int main(int argc, char * argv[]) {
|
||||
c.enableExitCapture();
|
||||
c.addVariable("prot", &p);
|
||||
if (argc > 1) c.start();
|
||||
c.waitForFinish();
|
||||
c.stop();
|
||||
/*Packet p, mp;
|
||||
p.from = mp.from = 1;
|
||||
p.to = mp.to = 2;
|
||||
PISerial ser("/dev/ttyS0");
|
||||
ser.setSpeed(PISerial::S115200);
|
||||
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;
|
||||
|
||||
exit(0);
|
||||
/*
|
||||
vec<int> my_v; vector<int> stl_v; QVector<int> qt_v;
|
||||
double el;
|
||||
PITimer tm;
|
||||
|
||||
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);
|
||||
*/
|
||||
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;
|
||||
@@ -239,7 +240,7 @@ int main(int argc, char * argv[]) {
|
||||
else cout << "== Fail ==" << endl;
|
||||
|
||||
cout << endl << "== File test ==" << endl;
|
||||
PIFile file(" file_test", PIFile::New | PIFile::ReadWrite);
|
||||
PIFile file(" file_test", PIIODevice::ReadWrite);
|
||||
cout << " file \"" << file.path() << "\" is ";
|
||||
if (!file.isOpened()) cout << "not ";
|
||||
cout << "opened" << endl;
|
||||
|
||||
Reference in New Issue
Block a user