diff --git a/src/io/pibinarylog.cpp b/src/io/pibinarylog.cpp index 69ec5548..19f389e7 100644 --- a/src/io/pibinarylog.cpp +++ b/src/io/pibinarylog.cpp @@ -187,6 +187,12 @@ PIString PIBinaryLog::createNewFile() { } +void PIBinaryLog::createNewFile(const PIString &path) { + if (open(path, PIIODevice::WriteOnly)) newFile(file.path()); + else piCoutObj << "Can't create new file, maybe path is invalid."; +} + + int PIBinaryLog::writeBinLog(int id, const void *data, int size) { if (size <= 0 || !canWrite()) return -1; switch (split_mode) { @@ -211,6 +217,18 @@ int PIBinaryLog::writeBinLog(int id, const void *data, int size) { } +int PIBinaryLog::writeBinLog_raw(int id, const PISystemTime &time, const void *data, int size) { + if (size <= 0 || !canWrite()) return -1; + PIByteArray logdata; + logdata << id << size << time << PIByteArray::RawData(data, size); + int res = file.write(logdata.data(), logdata.size()); + file.flush(); + write_count++; + if (res > 0) return size; + else return res; +} + + PIByteArray PIBinaryLog::readBinLog(int id) { if (!canRead()) return PIByteArray(); BinLogRecord br = readRecord(); diff --git a/src/io/pibinarylog.h b/src/io/pibinarylog.h index 219ec6a7..8d7b6650 100644 --- a/src/io/pibinarylog.h +++ b/src/io/pibinarylog.h @@ -120,6 +120,8 @@ public: //! Returns if rapid start enabled bool rapidStart() const {return rapid_start;} + //! Create binlog file with Filename = path + void createNewFile(const PIString &path); //! Set \a PlayMode void setPlayMode(PlayMode mode) {setProperty("playMode", (int)mode);} @@ -169,6 +171,10 @@ public: //! Write one record to BinLog file, with ID = id, id must be greather than 0 int writeBinLog(int id, const void * data, int size); + //! Write one RAW record to BinLog file, with ID = id, Timestamp = time + int writeBinLog_raw(int id, const PISystemTime &time, const PIByteArray &data) {return writeBinLog_raw(id, time, data.data(), data.size_s());} + int writeBinLog_raw(int id, const PISystemTime &time, const void * data, int size); + //! Returns count of writed records int writeCount() const {return write_count;}