git-svn-id: svn://db.shs.com.ru/libs@125 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -68,6 +68,7 @@ CDCore::CDCore() {
|
||||
CONNECTU(&datatr, sendRequest, this, dtSendRequest)
|
||||
CONNECTU(&datatr, receiveFinished, this, dtReceiveFinished)
|
||||
CONNECTU(&sendt, started, this, sendThread)
|
||||
CONNECTU(&x_timer, tickEvent, this, xTimerTick)
|
||||
|
||||
/*k_[1] = KType(1, "123", "120+3", "comment");
|
||||
k_[2] = KType(2, "1", "2", "comm");
|
||||
@@ -77,22 +78,16 @@ CDCore::CDCore() {
|
||||
k_.section(11)[3] = KType(3, "1", "1", "88");
|
||||
k_.section(11)[4] = KType(4, "0", "0", "88");
|
||||
k_.section(11)[6] = KType(6, "0", "0", "88");*/
|
||||
//piCout << s;
|
||||
//piCout << s;
|
||||
}
|
||||
|
||||
|
||||
void CDCore::k_rec(const PIByteArray & data) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CDCore::x_rec(const PIByteArray & data) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void CDCore::c_rec(const PIByteArray & data) {
|
||||
|
||||
CDCore::~CDCore() {
|
||||
datatr.stop();
|
||||
x_timer.stop();
|
||||
sendt.stop();
|
||||
sendt.waitForFinish(10);
|
||||
connection.stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -142,11 +137,29 @@ void CDCore::reinitConnection(const PIString &configuration) {
|
||||
}
|
||||
|
||||
|
||||
void CDCore::startPing() {
|
||||
x_timer.start(1);
|
||||
}
|
||||
|
||||
|
||||
void CDUtils::CDCore::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
// piCoutObj << "dataReceived" << from << data.size();
|
||||
PIIODevice * d = connection.deviceByName("cd");
|
||||
if (d && d == connection.deviceByFullPath(from)) {
|
||||
datatr.received(data);
|
||||
if (data.size() >= sizeof(4)) {
|
||||
const uint sig = *((const uint*)(data.data()));
|
||||
if (sig == 0x54424950) datatr.received(data);
|
||||
else {
|
||||
CDPacketType pt = (CDPacketType)sig;
|
||||
switch(pt) {
|
||||
case CD_Ping:
|
||||
piCoutObj << "ping";
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,6 +222,15 @@ void CDCore::sendThread() {
|
||||
}
|
||||
|
||||
|
||||
void CDCore::xTimerTick() {
|
||||
PacketHeader ph;
|
||||
ph.type = CD_Ping;
|
||||
PIByteArray ba;
|
||||
ba << ph;
|
||||
connection.writeByName("cd", ba);
|
||||
}
|
||||
|
||||
|
||||
void CDCore::dtSendRequest(PIByteArray &data) {
|
||||
connection.writeByName("cd", data);
|
||||
// piCoutObj << "send" << data.size() << ret;
|
||||
|
||||
@@ -45,17 +45,17 @@ public:
|
||||
PIString pultConfig() {return PIString(pult_config);}
|
||||
PIString appConfig() {return PIString(app_config);}
|
||||
void reinitConnection(const PIString & configuration);
|
||||
void startPing();
|
||||
bool inProgress() {return sendt.isRunning();}
|
||||
|
||||
private:
|
||||
CDCore();
|
||||
~CDCore();
|
||||
EVENT_HANDLER2(void, dataReceived, const PIString &, from, const PIByteArray &, data);
|
||||
EVENT_HANDLER1(void, dtSendRequest, PIByteArray &, data);
|
||||
EVENT_HANDLER1(void, dtReceiveFinished, bool, ok);
|
||||
EVENT_HANDLER(void, sendThread);
|
||||
void k_rec(const PIByteArray & data);
|
||||
void x_rec(const PIByteArray & data);
|
||||
void c_rec(const PIByteArray & data);
|
||||
EVENT_HANDLER(void, xTimerTick);
|
||||
|
||||
static const char app_config[], pult_config[];
|
||||
PIConnection connection;
|
||||
@@ -63,6 +63,7 @@ private:
|
||||
PacketHeader wheader;
|
||||
PIByteArray send_data;
|
||||
PIThread sendt;
|
||||
PITimer x_timer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -93,6 +93,11 @@ void KInterface::reinitConnection(const PIString &configuration) {
|
||||
}
|
||||
|
||||
|
||||
void KInterface::startPing() {
|
||||
core->startPing();
|
||||
}
|
||||
|
||||
|
||||
void KInterface::write(PIIODevice * d) {
|
||||
core->k_write(d);
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ public:
|
||||
void setFileName(const PIString & file) {k_file = file;}
|
||||
bool configure(const PIString & config, const PIString & sect = PIStringAscii("k"));
|
||||
void reinitConnection(const PIString & configuration);
|
||||
void startPing();
|
||||
void write(PIIODevice * d);
|
||||
void read(PIIODevice * d);
|
||||
void parse(PIIODevice * d);
|
||||
|
||||
@@ -9,15 +9,15 @@ enum CDPacketType {CD_Ping, CD_Pong, CD_KQuery, CD_KSend, CD_Command, CD_XData,
|
||||
|
||||
# pragma pack(push,1)
|
||||
struct PacketHeader {
|
||||
int session_id;
|
||||
int type; // CDPacketType
|
||||
int session_id;
|
||||
};
|
||||
|
||||
# pragma pack(pop)
|
||||
|
||||
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PacketHeader & v) {s << v.session_id << v.type; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PacketHeader & v) {s >> v.session_id >> v.type; return s;}
|
||||
inline PIByteArray & operator <<(PIByteArray & s, const PacketHeader & v) {s << v.type << v.session_id; return s;}
|
||||
inline PIByteArray & operator >>(PIByteArray & s, PacketHeader & v) {s >> v.type >> v.session_id; return s;}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,11 @@ void CDKView::setKFile(const QString &filename) {
|
||||
}
|
||||
|
||||
|
||||
void CDKView::startPing() {
|
||||
K.startPing();
|
||||
}
|
||||
|
||||
|
||||
void CDKView::sendK() {
|
||||
bisyStatusChanged(true);
|
||||
K.send();
|
||||
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
~CDKView();
|
||||
void refresh();
|
||||
void setKFile(const QString & filename);
|
||||
void startPing();
|
||||
|
||||
CDKItemModel * CDKModel() {return kmodel;}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ Form::Form(QWidget *parent) : QWidget(parent), ui(new Ui::Form) {
|
||||
ui->setupUi(this);
|
||||
ui->treeView->setKFile("");
|
||||
ui->treeView->refresh();
|
||||
ui->treeView->startPing();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user