git-svn-id: svn://db.shs.com.ru/pip@371 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-04-17 12:04:12 +00:00
parent f76510e74a
commit 2c68e66568
30 changed files with 380 additions and 553 deletions

View File

@@ -17,10 +17,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "piconfig.h"
#include "pifile.h"
#include "piiostring.h"
#include <iostream>
#include "pistring_std.h"
/*! \class PIConfig
* \brief Configuration file
@@ -812,3 +813,15 @@ void PIConfig::parse() {
setEntryDelim(&root, delim);
buildFullNames(&root);
}
std::ostream &operator <<(std::ostream & s, const PIConfig::Entry & v) {
s << v.value();
return s;
}
std::ostream &operator <<(std::ostream & s, const PIConfig::Branch & v) {
v.coutt(s, "");
return s;
}

View File

@@ -500,8 +500,8 @@ private:
};
inline std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v) {v.coutt(s, ""); return s;}
inline std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v) {s << v.value(); return s;}
std::ostream & operator <<(std::ostream & s, const PIConfig::Branch & v);
std::ostream & operator <<(std::ostream & s, const PIConfig::Entry & v);
inline PICout operator <<(PICout s, const PIConfig::Branch & v) {s.setControl(0, true); v.piCoutt(s, ""); s.restoreControl(); return s;}
inline PICout operator <<(PICout s, const PIConfig::Entry & v) {s << v.value(); return s;}

View File

@@ -19,6 +19,7 @@
#include "piincludes_p.h"
#include "pifile.h"
#include "pidir.h"
#include "pitime_win.h"
#ifdef WINDOWS
# undef S_IFDIR
# undef S_IFREG
@@ -378,15 +379,6 @@ int PIFile::writeDevice(const void * data, int max_size) {
}
PIFile & PIFile::writeToBinLog(ushort id, const void * data, int size) { /// DEPRECATED
if (!isWriteable() || fd == 0) return *this;
writeBinary(id).writeBinary((ushort)size);
write(data, size);
flush();
return *this;
}
PIFile &PIFile::operator <<(const PIString & v) {
if (canWrite() && fd != 0)
*this << v.toCharset(defaultCharset());
@@ -454,8 +446,8 @@ PIFile::FileInfo PIFile::fileInfo(const PIString & path) {
ret.perm_user = FileInfo::Permissions(true, (attr & FILE_ATTRIBUTE_READONLY) != FILE_ATTRIBUTE_READONLY, ext == "bat" || ext == "exe");
ret.perm_group = ret.perm_other = ret.perm_user;
ret.size = filesize.QuadPart;
ret.time_access = PIDateTime(fi.ftLastAccessTime);
ret.time_modification = PIDateTime(fi.ftLastWriteTime);
ret.time_access = FILETIME2PIDateTime(fi.ftLastAccessTime);
ret.time_modification = FILETIME2PIDateTime(fi.ftLastWriteTime);
/*PIByteArray sec;
DWORD sec_n(0);
//SECURITY_DESCRIPTOR sec;
@@ -539,7 +531,7 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
hFile = CreateFile(path.data(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
}
if (!hFile) return false;
FILETIME atime = info.time_access.toFILETIME(), mtime = info.time_modification.toFILETIME();
FILETIME atime = PIDateTime2FILETIME(info.time_access), mtime = PIDateTime2FILETIME(info.time_modification);
if (SetFileTime(hFile, 0, &atime, &mtime) == 0) {
piCout << "[PIFile] applyFileInfo: \"SetFileTime\" error:" << errorString();
return false;

View File

@@ -152,9 +152,6 @@ public:
void setPrecision(int prec);
PIFile & writeToBinLog(ushort id, const void * data, int size); /// DEPRECATED
//! Write to file binary content of "v"
PIFile & writeBinary(const char v) {write(&v, sizeof(v)); return *this;}
//! Write to file binary content of "v"

View File

@@ -66,21 +66,6 @@ PIProtocol::PIProtocol(const PIString & config, const PIString & name_, void * r
PIProtocol::~PIProtocol() {
//cout << "prot " << protName << " delete\n";
if (history_write_rec) {
if (history_file_rec.isEmpty()) {
history_file_rec.close();
history_file_rec.remove();
}
history_file_rec.close();
}
if (history_write_send) {
if (history_file_send.isEmpty()) {
history_file_send.close();
history_file_send.remove();
}
history_file_send.close();
}
delete diagTimer;
delete sendTimer;
delete secTimer;
@@ -96,7 +81,7 @@ void PIProtocol::init() {
packet_ext->setThreadedReadSlot(receiveEvent);
packet_ext->setHeaderCheckSlot(headerValidateEvent);
packet_ext->setName("__S__PIProtocol::packet_ext");
work = new_mp_prot = history_write_rec = history_write_send = false;
work = new_mp_prot = false;
eth = 0;
ser = 0;
ret_func = 0;
@@ -120,9 +105,6 @@ void PIProtocol::init() {
type_rec = type_send = PIProtocol::None;
devSenderState = devReceiverState = "Unknown";
devSenderName = devReceiverName = "no device";
history_rsize_rec = history_rsize_send = "no file";
history_file_rec.setName("__S__PIProtocol::history_file_rec");
history_file_send.setName("__S__PIProtocol::history_file_send");
secTimer->start(1000.);
/*addEvent("receiver started");
addEvent("receiver stopped");
@@ -265,27 +247,6 @@ void PIProtocol::init_sender(PIConfig::Entry & b, PIConfig::Entry & sb, const PI
if (sendDataSize_ == 0)
piCoutObj << "Warning: null send data size!";*/
}
history_write_send = sb.getValue("writeHistory", false, &ok);
bool ghist = b.getValue("writeHistory", false, &gok);
if (ok || gok) {
if (gok && !ok) history_write_send = ghist;
if (gok && ok && (history_write_send != ghist)) {
piCoutObj << "Ambiguous sender history in \"" << config << "\"!";
devSenderState = "Config error";
return;
}
if (history_write_send) {
history_path_send = sb.getValue("historyFile", "./history_" + protName + "_send_" +
PIDate::current().toString("__dd_mm_yyyy_") +
PITime::current().toString("_hh_mm_ss_")).value();
history_id_send = sb.getValue("historyID", 0, &ok);
if (!ok) {
history_id_send = ushort(protName.toByteArray().checksumPlain32()) + 1;
piCoutObj << "Warning: no sender history ID defined, write with ID = " << history_id_send;
}
history_file_send.open(history_path_send, PIIODevice::WriteOnly);
}
}
freq = sb.getValue("frequency", -1.f, &ok);
gfreq = b.getValue("frequency", -1.f, &gok);
if (gok && !ok) freq = gfreq;
@@ -440,27 +401,6 @@ void PIProtocol::init_receiver(PIConfig::Entry & b, PIConfig::Entry & rb, const
return;
}
}
history_write_rec = rb.getValue("writeHistory", false, &ok);
bool ghist = b.getValue("writeHistory", false, &gok);
if (ok || gok) {
if (gok && !ok) history_write_rec = ghist;
if (gok && ok && (history_write_rec != ghist)) {
piCoutObj << "Ambiguous receiver history in \"" << config << "\"!";
devReceiverState = "Config error";
return;
}
if (history_write_rec) {
history_path_rec = rb.getValue("historyFile", "./history_" + protName + "_rec_" +
PIDate::current().toString("__dd_mm_yyyy_") +
PITime::current().toString("_hh_mm_ss_")).value();
history_id_rec = rb.getValue("historyID", 0, &ok);
if (!ok) {
history_id_rec = ushort(protName.toByteArray().checksumPlain32());
piCoutObj << "Warning: no receiver history ID defined, write with ID = " << history_id_rec;
}
history_file_rec.open(history_path_rec, PIIODevice::WriteOnly);
}
}
freq = rb.getValue("frequency", -1.f, &ok);
gfreq = b.getValue("frequency", -1.f, &gok);
if (gok && !ok) freq = gfreq;
@@ -625,10 +565,6 @@ bool PIProtocol::receiveEvent(void * t, uchar * data, int size) {
p->work = true;
//p->lock();
if (p->validate()) {
if (p->history_write_rec) {
p->history_file_rec.writeToBinLog(p->history_id_rec, data, size);
p->history_rsize_rec.setReadableSize(p->history_file_rec.pos());
}
p->received(true);
//p->unlock();
p->ifreq = p->diag_tm.elapsed_m();
@@ -747,10 +683,6 @@ void PIProtocol::send(const void * data, int size, bool direct) {
if (data == 0 || size == 0) return;
if (!aboutSend()) return;
}
if (history_write_send) {
history_file_send.writeToBinLog(history_id_send, data, size);
history_rsize_send.setReadableSize(history_file_send.pos());
}
if (type_send == PIProtocol::Serial)
if (ser->send(data, size)) {
send_count++;
@@ -772,10 +704,6 @@ void PIProtocol::send() {
//unlock();
if (!aboutSend()) return;
if (sendDataPtr == 0 || sendDataSize == 0) return;
if (history_write_send) {
history_file_send.writeToBinLog(history_id_send, sendDataPtr, sendDataSize);
history_rsize_send.setReadableSize(history_file_send.pos());
}
if (type_send == PIProtocol::Serial)
if (ser->send(sendDataPtr, sendDataSize)) {
send_count++;

View File

@@ -162,14 +162,6 @@ public:
const PIString * receiveSpeed_ptr() const {return &speedIn;}
PIString sendSpeed() const {return speedOut;}
const PIString * sendSpeed_ptr() const {return &speedOut;}
PIString receiverHistorySize() const {return history_rsize_rec;}
const PIString * receiverHistorySize_ptr() const {return &history_rsize_rec;}
PIString senderHistorySize() const {return history_rsize_send;}
const PIString * senderHistorySize_ptr() const {return &history_rsize_send;}
bool writeReceiverHistory() const {return history_write_rec;}
const bool * writeReceiverHistory_ptr() const {return &history_write_rec;}
bool writeSenderHistory() const {return history_write_send;}
const bool * writeSenderHistory_ptr() const {return &history_write_send;}
void * receiveData() {return dataPtr;}
void * sendData() {return sendDataPtr;}
@@ -235,10 +227,7 @@ private:
PIDeque<float> last_freq;
PIDeque<char> last_packets;
PIString protName, devReceiverName, devReceiverState, devSenderName, devSenderState, speedIn, speedOut;
PIString history_path_rec, history_path_send, history_rsize_rec, history_rsize_send;
PIFile history_file_rec, history_file_send;
ushort history_id_rec, history_id_send;
bool work, new_mp_prot, history_write_rec, history_write_send;
bool work, new_mp_prot;
float exp_freq, send_freq, ifreq, immediate_freq, integral_freq, timeout_;
int packets[2], pckt_cnt, pckt_cnt_max;
char cur_pckt;