151 lines
4.0 KiB
C++
151 lines
4.0 KiB
C++
#include <pip.h>
|
|
|
|
class Prot: public PIProtocol {
|
|
public:
|
|
Prot(): PIProtocol() {
|
|
setName("test");
|
|
ba.resize(1024);
|
|
setReceiverAddress("127.0.0.1", 3003, true);
|
|
setReceiverData(ba.data(), ba.size_s());
|
|
setSenderAddress("127.0.0.2", 3003, true);
|
|
setSenderData(ba.data(), ba.size_s());
|
|
setExpectedFrequency(100);
|
|
//setSenderFrequency();
|
|
//startReceive(100);
|
|
startSend(10);
|
|
};
|
|
PIByteArray ba;
|
|
};
|
|
|
|
class MProt: public PIMultiProtocol {
|
|
public:
|
|
MProt() {cor = incor = 0;}
|
|
|
|
int cor, incor;
|
|
|
|
virtual void received(PIProtocol * prot, bool corrected, char * data, int size) {if (corrected) cor++; else incor++; if (prot->name() == "test" && corrected) prot->send();}
|
|
|
|
|
|
};
|
|
|
|
|
|
struct BitsStruct {
|
|
uchar b1: 1;
|
|
uchar b2: 2;
|
|
uchar b4: 4;
|
|
};
|
|
|
|
int i = 1;
|
|
BitsStruct bits;
|
|
|
|
void keyFunc(char key, void * );
|
|
|
|
PIConsole c(false, keyFunc);
|
|
|
|
void keyFunc(char key, void * ) {
|
|
switch (key) {
|
|
case '-': i--; break;
|
|
case '+': i++; break;
|
|
case '[': bits.b1--; break;
|
|
case ']': bits.b1++; break;
|
|
case ';': bits.b2--; break;
|
|
case '\'': bits.b2++; break;
|
|
case ',': bits.b4--; break;
|
|
case '.': bits.b4++; break;
|
|
case 'i': i = c.getInt(1, 2); break;
|
|
}
|
|
};
|
|
|
|
void signalFunc(PISignals::Signal signal) {
|
|
if (signal == PISignals::Interrupt) cout << "Ctrl+C pressed" << endl;
|
|
};
|
|
|
|
void timerEvent(void*, int delim) {
|
|
cout << "tick " << delim << endl;
|
|
};
|
|
|
|
PITimer timer(timerEvent);
|
|
|
|
void timerEvent2(void*, int delim) {
|
|
cout << "tick2 " << delim << endl;
|
|
};
|
|
|
|
int main(int argc, char * argv[]) {
|
|
/*PICLI cli(argc, argv);
|
|
cli.addArgument("debug");
|
|
cli.addArgument("value", "V", "Val", true);
|
|
if (cli.hasArgument("debug"))
|
|
cout << "has debug" << endl;
|
|
if (cli.hasArgument("value"))
|
|
cout << "value = " << cli.argumentValue("value") << endl;*/
|
|
/*
|
|
timer.start(100);
|
|
timer.addDelimiter(2, timerEvent2);
|
|
timer.addDelimiter(5, timerEvent2);
|
|
FOREVER_WAIT
|
|
*/
|
|
/*PISignals::setSlot(signalFunc);
|
|
PISignals::grabSignals(PISignals::Interrupt);
|
|
FOREVER_WAIT*/
|
|
|
|
/*PIString ip;
|
|
int port;
|
|
PIConfig conf("protocols.conf~");
|
|
ip = conf.getValue("mcp1.receiver.ip");
|
|
port = conf.getValue("mcp1.receiver.port");
|
|
cout << ip << ":" << port << endl;*/
|
|
|
|
c.addString("PIConsole example");
|
|
c.addEmptyLine();
|
|
|
|
c.addTab("colors", '1');
|
|
c.addString("Red string", 1, PIConsole::Red);
|
|
c.addString("Blue on yellow", 1, PIConsole::Blue | PIConsole::BackYellow);
|
|
c.addEmptyLine();
|
|
|
|
c.addTab("columns", '2');
|
|
c.addString("column 1", 1, PIConsole::BackYellow);
|
|
c.addString("column 2", 2, PIConsole::BackCyan);
|
|
c.addString("column 3", 3, PIConsole::BackMagenta);
|
|
c.addEmptyLine();
|
|
|
|
c.addTab("bits", '3');
|
|
c.addBitVariable("b1", &bits, 0, 1);
|
|
c.addBitVariable("b2", &bits, 1, 2);
|
|
c.addBitVariable("b4", &bits, 3, 4);
|
|
c.addCustomStatus("[] - -/+ b1, ;\' - -/+ b2, ,. - -/+ b4");
|
|
c.addEmptyLine();
|
|
|
|
c.addTab("formats", '4');
|
|
c.addVariable("our int", &i);
|
|
c.addVariable("dec", &i);
|
|
c.addVariable("oct", &i, 1, PIConsole::Oct);
|
|
c.addVariable("hex", &i, 1, PIConsole::Hex);
|
|
c.addCustomStatus("-+ - -/+ number");
|
|
c.addEmptyLine();
|
|
|
|
c.setTab(0);
|
|
c.enableExitCapture();
|
|
c.start(true);
|
|
|
|
/*MProt mp;
|
|
Prot p;
|
|
PIRepeater r("protocols.conf", "r", 1024);
|
|
mp.addProtocol(p);
|
|
c.addVariable("rec : " + mp[0]->receiverDeviceName() + ":", mp[0]->receiverDeviceState_ptr());
|
|
c.addVariable("send: " + mp[0]->senderDeviceName() + ":", mp[0]->senderDeviceState_ptr());
|
|
c.addVariable("freq", mp[0]->immediateFrequency_ptr());
|
|
c.addVariable("sent ", mp[0]->sendCount_ptr());
|
|
c.addVariable("ok ", mp[0]->receiveCount_ptr());
|
|
c.addVariable("wrong", mp[0]->wrongCount_ptr());
|
|
c.addEmptyLine();
|
|
c.addVariable("mp_corr", &mp.cor);
|
|
c.addVariable("mp_incr", &mp.incor);
|
|
c.addVariable(r.firstChannelName() + ", rec ", r.receiveCount_ptr());
|
|
c.addVariable(r.secondChannelName() + ", send", r.sendCount_ptr());
|
|
c.enableExitCapture();
|
|
mp.start();
|
|
c.start(false);*/
|
|
c.waitForFinish();
|
|
};
|