git-svn-id: svn://db.shs.com.ru/pip@254 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
175
main.cpp
175
main.cpp
@@ -7,149 +7,62 @@
|
||||
#include "piintrospection.h"
|
||||
#include "pifile.h"
|
||||
#include "piterminal.h"
|
||||
#include "piserial.h"
|
||||
|
||||
//struct MS {
|
||||
// //MS() {i = 0; f = 0.;}
|
||||
// int i;
|
||||
// float f;
|
||||
// PIString s;
|
||||
//};
|
||||
|
||||
//PIByteArray & operator<<(PIByteArray & ba, const MS & v) {ba << v.i << v.f << v.s; return ba;}
|
||||
//PIByteArray & operator>>(PIByteArray & ba, MS & v) {ba >> v.i >> v.f >> v.s; return ba;}
|
||||
//PICout operator <<(PICout c, const MS & v) {c << "(" << v.i << v.f << v.s << ")"; return c;}
|
||||
PIScreen screen;
|
||||
PIConnection conn;
|
||||
|
||||
//REGISTER_VARIANT(MS)
|
||||
//REGISTER_VARIANT_CAST(MS, int) {return v.i;}
|
||||
//REGISTER_VARIANT_CAST(MS, float) {return v.f;}
|
||||
//REGISTER_VARIANT_CAST(MS, PIString) {return v.s;}
|
||||
template <uint N = 3u, typename T = double>
|
||||
class VC {
|
||||
public:
|
||||
T v[N];
|
||||
VC(T x) {for (uint i=0; i<N; i++) v[i] = x;}
|
||||
T dot(VC<N, T> a) {T res = T(); for (uint i=0; i<N; i++) res += v[i] * a.v[N - i - 1]; return res;}
|
||||
};
|
||||
|
||||
class TileTerminal: public PIScreenTile {
|
||||
public:
|
||||
TileTerminal(PITerminal * t = 0): term(t) {
|
||||
focus_flags = PIScreenTypes::CanHasFocus;
|
||||
}
|
||||
const char conn_config[] =
|
||||
"[connection]\n\
|
||||
device.test = ser://COM54:115200 #s\n\
|
||||
device.test.disconnectTimeout = 3.00000000 #f\n\
|
||||
[]\n";
|
||||
|
||||
private:
|
||||
void drawEvent(PIScreenDrawer * d) {
|
||||
//piCout << "draw" << visible;
|
||||
if (!term) return;
|
||||
PIVector<PIVector<PIScreenTypes::Cell> > c = term->content();
|
||||
d->fillRect(x_, y_, x_ + width_, y_ + height_, c);
|
||||
}
|
||||
bool keyEvent(PIKbdListener::KeyEvent key) {
|
||||
//piCout << "key";
|
||||
if (!term) return false;
|
||||
if (PITerminal::isSpecialKey(key.key)) term->write((PIKbdListener::SpecialKey)key.key, key.modifiers);
|
||||
else {
|
||||
PIByteArray ba;
|
||||
ba << PIChar(key.key).toConcole1Byte();
|
||||
term->write(ba);
|
||||
class Obj : public PIObject {
|
||||
PIOBJECT(Obj)
|
||||
public:
|
||||
Obj() {
|
||||
CONNECTU(&conn, dataReceivedEvent, this, recv);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void resizeEvent(int w, int h) {
|
||||
if (!term) return;
|
||||
term->resize(w, h);
|
||||
}
|
||||
EVENT_HANDLER1(void, keyEv, PIKbdListener::KeyEvent, k) {
|
||||
piCoutObj << k.key;
|
||||
if (k.key == -20) {
|
||||
PIKbdListener::exiting = true;
|
||||
|
||||
}
|
||||
if (k.key == 's') {
|
||||
PISerial * ser = (PISerial *)conn.deviceByName("test");
|
||||
if (ser) {
|
||||
PIByteArray ba;
|
||||
ba << uchar(31) << uchar(230) << uchar(0xd) << uchar(0xa);
|
||||
piCoutObj << "send";
|
||||
ser->writeThreaded(ba);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PITerminal * term;
|
||||
};
|
||||
EVENT_HANDLER2(void, recv, const PIString &, from, const PIByteArray &, data) {
|
||||
piCoutObj << from << PIString(data) << PICoutManipulators::Hex << data;
|
||||
}
|
||||
};
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
int in[8], out[8];
|
||||
memset(in, 0, 4*8);
|
||||
memset(out, 0, 4*8);
|
||||
for (int i = 0; i <= 0xF; ++i) {
|
||||
for (int b = 0; b < 4; ++b) out[b] = (i >> b) & 1;
|
||||
for (int b = 0; b < 4; ++b) PICout(0) << " " << out[b];
|
||||
PICout(0) << PICoutManipulators::NewLine;
|
||||
}
|
||||
return 0;
|
||||
PIScreen screen;
|
||||
PITerminal term;
|
||||
TileTerminal tt(&term);
|
||||
screen.rootTile()->addTile(&tt);
|
||||
tt.setFocus();
|
||||
screen.rootTile()->addTile(new TilePICout());
|
||||
screen.enableExitCapture();
|
||||
term.initialize();
|
||||
piMSleep(100);
|
||||
term.write(PIString("pisd -h").toByteArray());
|
||||
screen.start();
|
||||
screen.rootTile()->children().front()->setFocus();
|
||||
Obj * o = new Obj();
|
||||
CONNECTU(&screen, keyPressed, o, keyEv)
|
||||
PIString s = conn_config;
|
||||
conn.configureFromString(&s);
|
||||
PISerial * ser = (PISerial *)conn.deviceByName("test");
|
||||
if (ser) {
|
||||
piCout << ser->constructFullPath() << ser->isOpened();
|
||||
ser->startThreadedWrite();
|
||||
}
|
||||
conn.start();
|
||||
screen.waitForFinish();
|
||||
term.destroy();
|
||||
return 0;
|
||||
/*PISingleApplication sa("app");
|
||||
if (!sa.isFirst())
|
||||
sa.sendMessage(PIString("message to first").toByteArray());
|
||||
else
|
||||
piMSleep(5000);*/
|
||||
//piCout << PIString(argv[1]).toInt();
|
||||
//sh.destroy();
|
||||
//proc.terminate();
|
||||
/*PIByteArray v = PIString("Mandfg;kjngel").toByteArray();
|
||||
PIByteArray b64 = convertToBase64(v);
|
||||
piCout << PIString(v);
|
||||
piCout << PIString(v.toBase64());
|
||||
piCout << PIString(b64);
|
||||
piCout << PIString(PIByteArray::fromBase64(v.toBase64()));
|
||||
piCout << PIString(convertFromBase64(b64));*/
|
||||
/*uint v = 0;
|
||||
v |= (uchar(77) << 8);
|
||||
piCout << PICoutManipulators::Dec << v;
|
||||
piCout << PICoutManipulators::Hex << v;*/
|
||||
//piCout << PIString(PIByteArray::fromBase64(v.toBase64()));
|
||||
return 0;
|
||||
/*VC<30, double> x(1.5), y(3.3);
|
||||
double r = 0.0;
|
||||
PITimeMeasurer tm;
|
||||
for (int i=0; i<10000; i++)
|
||||
r = x.dot(y);
|
||||
piCout << r << tm.elapsed_m();*/
|
||||
//PIByteArray ba;
|
||||
/*PIKbdListener kbd;
|
||||
kbd.enableExitCapture();
|
||||
PIString str;
|
||||
str.reserve(1024*1024);
|
||||
PIINTROSPECTION_START
|
||||
//piCout << PIINTROSPECTION_CONTAINERS->count;
|
||||
WAIT_FOR_EXIT*/
|
||||
// PIVector<PIVariant> vl;
|
||||
// vl << PIVariant('2') << PIVariant(-5.5) << PIVariant(10) << PIVariant(complexd(2,3)) << PIVariant("text") << PIVariant(PIByteArray("bytearray", 9)) << PIVariant(PIDateTime::current());
|
||||
// piForeachC (PIVariant v, vl)
|
||||
// piCout << v << v.value<PIString>();
|
||||
// PIByteArray ba; ba << PIString("500");
|
||||
// piCout << PIVariant::fromValue(ba, "PIString");
|
||||
// piCout << PIVariant("PIString");
|
||||
// piCout << __PIVariantFunctions__<int>::typeNameHelper();
|
||||
// piCout << __PIVariantInfoStorage__::get()->map->size();
|
||||
// for (PIMap<PIString, __PIVariantInfo__*>::iterator i = __PIVariantInfoStorage__::get()->map->begin(); i != __PIVariantInfoStorage__::get()->map->end(); ++i)
|
||||
// piCout << i.key() << i.value()->cast.size();
|
||||
// PIEthernet eth;
|
||||
// piCout << eth.properties();
|
||||
// MS ms = (MS){-1, 3.3, "str"};
|
||||
// PIVariant mv = PIVariant::fromValue<MS>(ms);
|
||||
// piCout << mv << mv.type();
|
||||
// piCout << mv.toInt();
|
||||
// piCout << mv.toFloat();
|
||||
// piCout << mv.toString();
|
||||
// piCout << ms << mv.value<MS>() << vl[0].value<MS>();
|
||||
/*PIScreen screen;
|
||||
TileSimple window;
|
||||
window.back_format.color_back = PIScreenTypes::Red;
|
||||
window.content << TileSimple::Row("label", PIScreenTypes::CellFormat(PIScreenTypes::Black, PIScreenTypes::Transparent));
|
||||
screen.rootTile()->addTile(&window);
|
||||
screen.enableExitCapture(PIKbdListener::F10);
|
||||
screen.start();
|
||||
screen.waitForFinish();*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user