29.04.2014 - Version 0.4.0_prealpha. PICodeParser, namespace PICodeInfo, new tool "pip_cmg" in dir "code_model_generator". New feature in PIIODevice - "createFromFullPath", all parameters of all I/O devices now works with PIObjects`s properties.
This commit is contained in:
@@ -42,6 +42,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
REGISTER_DEVICE(PIBinaryLog);
|
||||
|
||||
|
||||
PIBinaryLog::PIBinaryLog() {
|
||||
binlog_sig[0] = 'B';
|
||||
@@ -51,10 +53,13 @@ PIBinaryLog::PIBinaryLog() {
|
||||
binlog_sig[4] = 'O';
|
||||
binlog_sig[5] = 'G';
|
||||
setThreadedReadBufferSize(65536);
|
||||
is_started = rapid_start = false;
|
||||
playspeed = 1.0f;
|
||||
default_id = 1;
|
||||
playmode = PlayVariableSpeed;
|
||||
is_started = false;
|
||||
setPlaySpeed(1.f);
|
||||
setDefaultID(1);
|
||||
setPlayMode(PlayVariableSpeed);
|
||||
setLogDir(PIString());
|
||||
setFilePrefix(PIString());
|
||||
setRapidStart(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,23 +69,23 @@ bool PIBinaryLog::openDevice() {
|
||||
is_started = false;
|
||||
is_thread_ok = true;
|
||||
if (mode_ == ReadWrite) {
|
||||
piCoutObj << "ReadWrite mode not supported, use WriteOnly or ReadOnly";
|
||||
piCoutObj << "Error: ReadWrite mode not supported, use WriteOnly or ReadOnly";
|
||||
return false;
|
||||
}
|
||||
if (!file.open(path_, mode_))
|
||||
if (!file.open(path(), mode_))
|
||||
return false;
|
||||
setName(path_);
|
||||
setName(path());
|
||||
if (mode_ == WriteOnly) {
|
||||
file.resize(0);
|
||||
if (!writeFileHeader()) {
|
||||
piCoutObj << "Can't write binlog file header";
|
||||
piCoutObj << "Error: Can't write binlog file header";
|
||||
return false;
|
||||
}
|
||||
is_started = true;
|
||||
}
|
||||
if (mode_ == ReadOnly) {
|
||||
if (file.isEmpty()) {
|
||||
piCoutObj << "File is null";
|
||||
piCoutObj << "Error: File is null";
|
||||
fileError();
|
||||
return false;
|
||||
}
|
||||
@@ -88,11 +93,11 @@ bool PIBinaryLog::openDevice() {
|
||||
fileError();
|
||||
return false;
|
||||
}
|
||||
if (isEmpty()) piCoutObj << "Empty BinLog file";
|
||||
if (isEmpty()) piCoutObj << "Error: Empty BinLog file";
|
||||
// startlogtime = currentSystemTime();
|
||||
play_time = 0;
|
||||
// nextrecord = readsRecord();
|
||||
if (!rapid_start) is_started = true;
|
||||
if (!rapidStart()) is_started = true;
|
||||
}
|
||||
startlogtime = currentSystemTime();
|
||||
return true;
|
||||
@@ -112,7 +117,7 @@ bool PIBinaryLog::threadedRead(uchar *readed, int size) {
|
||||
is_thread_ok = false;
|
||||
PISystemTime pt;
|
||||
double delay;
|
||||
switch (playmode) {
|
||||
switch (playMode()) {
|
||||
case PlayRealTime:
|
||||
pt = currentSystemTime() - startlogtime;
|
||||
// if (real_speedX > 0)
|
||||
@@ -129,7 +134,7 @@ bool PIBinaryLog::threadedRead(uchar *readed, int size) {
|
||||
break;
|
||||
case PlayVariableSpeed:
|
||||
delay = lastrecord.timestamp.toMilliseconds() - play_time;
|
||||
delay /= playspeed;
|
||||
delay /= playSpeed();
|
||||
if (is_started) {
|
||||
if (delay > 0)
|
||||
PISystemTime::fromMilliseconds(delay).sleep();
|
||||
@@ -147,7 +152,7 @@ bool PIBinaryLog::threadedRead(uchar *readed, int size) {
|
||||
|
||||
PIString PIBinaryLog::createNewFile() {
|
||||
if (!file.close()) return PIString();
|
||||
if (open(logdir + "/" + fileprefix + currentDateTime().toString("yyyy_MM_dd__hh_mm_ss.binlog"), PIIODevice::WriteOnly))
|
||||
if (open(logDir() + "/" + filePrefix() + currentDateTime().toString("yyyy_MM_dd__hh_mm_ss.binlog"), PIIODevice::WriteOnly))
|
||||
return file.path();
|
||||
piCoutObj << "Can't create new file, maybe LogDir is invalid.";
|
||||
return PIString();
|
||||
@@ -225,15 +230,14 @@ int PIBinaryLog::read(void *read_to, int max_size) {
|
||||
}
|
||||
|
||||
|
||||
void PIBinaryLog::restart()
|
||||
{
|
||||
void PIBinaryLog::restart() {
|
||||
bool th = isRunning();
|
||||
if (th) stopThreadedRead();
|
||||
if (!canRead()) return;
|
||||
lastrecord.timestamp = PISystemTime();
|
||||
lastrecord.id = 0;
|
||||
is_thread_ok = true;
|
||||
if (rapid_start) is_started = false;
|
||||
if (rapidStart()) is_started = false;
|
||||
else is_started = true;
|
||||
play_time = 0;
|
||||
file.seekToBegin();
|
||||
@@ -302,3 +306,15 @@ PIBinaryLog::BinLogRecord PIBinaryLog::readRecord() {
|
||||
}
|
||||
|
||||
|
||||
void PIBinaryLog::configureFromFullPath(const PIString & full_path) {
|
||||
PIStringList pl = full_path.split(":");
|
||||
for (int i = 0; i < pl.size_s(); ++i) {
|
||||
PIString p(pl[i]);
|
||||
switch (i) {
|
||||
case 0: setLogDir(p); break;
|
||||
case 1: setFilePrefix(p); break;
|
||||
case 2: setDefaultID(p.toInt()); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user