08.02.2010 - version 0.1.2

This commit is contained in:
peri4
2012-02-08 19:39:21 +04:00
parent 8bb8287dcb
commit 5558add03e
10 changed files with 169 additions and 156 deletions

View File

@@ -63,7 +63,7 @@ void timerEvent(void * data, int delim) {
cout << " tick from constuctor, delimiter = " << delim << ", data = " << data << endl;
};
bool
bool
t2 = false;
void timerEvent2(void * data, int delim) {
t2 = true;
@@ -116,7 +116,67 @@ public:
bool d;
};
#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;
};
Prot p;
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;
}
}
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();
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;
@@ -145,7 +205,7 @@ int main(int argc, char * argv[]) {
else cout << " complex convertions fail" << endl;
if (r_string) cout << "== Success ==" << endl;
else cout << "== Fail ==" << endl;
cout << endl << "== Thread test ==" << endl;
ThreadTest thread;
thread.start(100);
@@ -154,7 +214,7 @@ int main(int argc, char * argv[]) {
r_thread = thread.b && thread.r && thread.e && thread.cnt == 10;
if (r_thread) cout << "== Success ==" << endl;
else cout << "== Fail ==" << endl;
cout << endl << "== Mutex test ==" << endl << " ";
MutexTest thread_m;
MutexTest2 thread_m2;
@@ -166,7 +226,7 @@ int main(int argc, char * argv[]) {
r_mutex = gm < 5;
if (r_mutex) cout << "== Success ==" << endl;
else cout << "== Fail ==" << endl;
cout << endl << "== Timer test ==" << endl;
PITimer timer(timerEvent, (void*)255);
timer.addDelimiter(2);
@@ -177,7 +237,7 @@ int main(int argc, char * argv[]) {
r_timer = t && t2;
if (r_timer) cout << "== Success ==" << endl;
else cout << "== Fail ==" << endl;
cout << endl << "== File test ==" << endl;
PIFile file(" file_test", PIFile::New | PIFile::ReadWrite);
cout << " file \"" << file.path() << "\" is ";
@@ -192,7 +252,7 @@ int main(int argc, char * argv[]) {
file.remove();
if (r_file) cout << "== Success ==" << endl;
else cout << "== Fail ==" << endl;
cout << endl << "== Evaluator test ==" << endl;
PIEvaluator evaluator;
evaluator.setVariable("x", complexd(2., 1.));
@@ -206,7 +266,7 @@ int main(int argc, char * argv[]) {
r_eval = round(evaluator.lastResult()) == complexd(9., 12.);
if (r_eval) cout << "== Success ==" << endl;
else cout << "== Fail ==" << endl;
cout << endl << "== Event test ==" << endl;
ObjectTest object("obj");
ObjectTest2 object2("obj2");
@@ -232,7 +292,7 @@ int main(int argc, char * argv[]) {
r_event = object.h && object.hi && object.ht && cd.a && cd.b && cd.c && cd.d;
if (r_event) cout << "== Success ==" << endl;
else cout << "== Fail ==" << endl;
cout << endl << "== Results ==" << endl;
cout << "= String " << r_string << " =" << endl;
cout << "= Thread " << r_thread << " =" << endl;