From 2d687cec933581863941908b398b7a6dc36dbba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D0=BB=D0=B8=D0=BF=D0=B5=D0=BD=D0=BA=D0=BE=20?= =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD?= Date: Tue, 15 Dec 2015 12:50:12 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@167 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src/io/pibinarylog.cpp | 16 ++++++++++++---- src/io/pibinarylog.h | 4 ++-- src/io/piserial.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/io/piserial.h | 23 ++++++++++++++++------- 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/io/pibinarylog.cpp b/src/io/pibinarylog.cpp index 784af74a..c8bcbca2 100644 --- a/src/io/pibinarylog.cpp +++ b/src/io/pibinarylog.cpp @@ -209,6 +209,10 @@ void PIBinaryLog::createNewFile(const PIString &path) { int PIBinaryLog::writeBinLog(int id, const void *data, int size) { if (size <= 0 || !canWrite()) return -1; + if (id == 0) { + piCoutObj << "Error: can`t write with id = 0!"; + return -1; + } switch (split_mode) { case SplitSize: if (logSize() > split_size) createNewFile(); @@ -243,7 +247,7 @@ int PIBinaryLog::writeBinLog_raw(int id, const PISystemTime &time, const void *d } -PIByteArray PIBinaryLog::readBinLog(int id) { +PIByteArray PIBinaryLog::readBinLog(int id, PISystemTime * time) { if (!canRead()) return PIByteArray(); BinLogRecord br = readRecord(); if (br.id == -1) { @@ -258,15 +262,19 @@ PIByteArray PIBinaryLog::readBinLog(int id) { fileEnd(); return PIByteArray(); } - if (br.id == id) return br.data; + if (br.id == id) { + if (time) + *time = br.timestamp; + return br.data; + } piCoutObj << "Can't find record with id =" << id; return PIByteArray(); } -int PIBinaryLog::readBinLog(int id, void *read_to, int max_size) { +int PIBinaryLog::readBinLog(int id, void *read_to, int max_size, PISystemTime * time) { if (max_size <= 0 || read_to == 0) return -1; - PIByteArray ba = readBinLog(id); + PIByteArray ba = readBinLog(id, time); if (ba.isEmpty()) return -1; int sz = piMini(max_size, ba.size()); memcpy(read_to, ba.data(), sz); diff --git a/src/io/pibinarylog.h b/src/io/pibinarylog.h index 3eced154..47a1611b 100644 --- a/src/io/pibinarylog.h +++ b/src/io/pibinarylog.h @@ -179,10 +179,10 @@ public: int writeCount() const {return write_count;} //! Read one record from BinLog file, with ID = id, if id = 0 than any id will be readed - PIByteArray readBinLog(int id = 0); + PIByteArray readBinLog(int id = 0, PISystemTime * time = 0); //! Read one record from BinLog file, with ID = id, if id = 0 than any id will be readed - int readBinLog(int id, void * read_to, int max_size); + int readBinLog(int id, void * read_to, int max_size, PISystemTime * time = 0); //! Returns binary log file size llong logSize() const {return file.size();} diff --git a/src/io/piserial.cpp b/src/io/piserial.cpp index a1d912fe..e49016a8 100755 --- a/src/io/piserial.cpp +++ b/src/io/piserial.cpp @@ -47,7 +47,14 @@ # define B57600 57600 # define B115200 115200 # define B128000 128000 +# define B230400 230400 # define B256000 256000 +# define B460800 460800 +# define B500000 500000 +# define B576000 576000 +# define B921600 921600 +# define B1000000 1000000 +# define B1152000 1152000 # define B1500000 1500000 # define B2000000 2000000 # define B2500000 2500000 @@ -64,6 +71,27 @@ # ifndef B75 # define B75 0000002 # endif +# ifndef B230400 +# define B230400 0010003 +# endif +# ifndef B460800 +# define B460800 0010004 +# endif +# ifndef B500000 +# define B500000 0010005 +# endif +# ifndef B576000 +# define B576000 0010006 +# endif +# ifndef B921600 +# define B921600 0010007 +# endif +# ifndef B1000000 +# define B1000000 0010010 +# endif +# ifndef B1152000 +# define B1152000 0010011 +# endif # ifndef B1500000 # define B1500000 0010012 # endif @@ -299,6 +327,15 @@ int PISerial::convertSpeed(PISerial::Speed speed) { case S38400: return B38400; case S57600: return B57600; case S115200: return B115200; + case S128000: return B128000; + case S230400: return B230400; + case S256000: return B256000; + case S460800: return B460800; + case S500000: return B500000; + case S576000: return B576000; + case S921600: return B921600; + case S1000000: return B1000000; + case S1152000: return B1152000; case S1500000: return B1500000; case S2000000: return B2000000; case S2500000: return B2500000; diff --git a/src/io/piserial.h b/src/io/piserial.h index 26005007..ec50dbb9 100755 --- a/src/io/piserial.h +++ b/src/io/piserial.h @@ -56,14 +56,23 @@ public: S38400 /*! 38400 baud */ = 38400, S57600 /*! 57600 baud */ = 57600, S115200 /*! 115200 baud */ = 115200, - S1500000 = 1500000, // Linux only - S2000000 = 2000000, // Linux only - S2500000 = 2500000, // Linux only - S3000000 = 3000000, // Linux only - S3500000 = 3500000, // Linux only - S4000000 = 4000000 // Linux only + S128000 /*! 128000 baud */ = 128000, + S230400 /*! 230400 baud */ = 230400, + S256000 /*! 256000 baud */ = 256000, + S460800 /*! 460800 baud */ = 460800, + S500000 /*! 500000 baud */ = 500000, + S576000 /*! 576000 baud */ = 576000, + S921600 /*! 921600 baud */ = 921600, + S1000000 /*! 1000000 baud */ = 1000000, + S1152000 /*! 1152000 baud */ = 1152000, + S1500000 /*! 1500000 baud */ = 1500000, + S2000000 /*! 2000000 baud */ = 2000000, + S2500000 /*! 2500000 baud */ = 2500000, + S3000000 /*! 3000000 baud */ = 3000000, + S3500000 /*! 3500000 baud */ = 3500000, + S4000000 /*! 4000000 baud */ = 4000000 }; - + //! Contructs %PISerial with device name "device", speed "speed" and parameters "params" explicit PISerial(const PIString & device, PISerial::Speed speed = S115200, PIFlags params = 0);