From 50be53914013b194939f254ca347d61c38047235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=8B=D1=87=D0=BA=D0=BE=D0=B2=20=D0=90=D0=BD=D0=B4?= =?UTF-8?q?=D1=80=D0=B5=D0=B9?= Date: Fri, 22 Dec 2017 10:41:52 +0000 Subject: [PATCH] git-svn-id: svn://db.shs.com.ru/pip@585 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5 --- src_main/io/pispi.cpp | 26 +++++++++++++++++++++++++- src_main/io/pispi.h | 5 +++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src_main/io/pispi.cpp b/src_main/io/pispi.cpp index 547966a4..80a9741d 100644 --- a/src_main/io/pispi.cpp +++ b/src_main/io/pispi.cpp @@ -24,6 +24,8 @@ PISPI::PISPI(const PIString & path, uint speed, PIIODevice::DeviceMode mode) : P setSpeed(speed); setBits(8); spi_mode = 0; + if (mode == ReadOnly) + piCoutObj << "error, SPI can't work in ReadOnly mode"; #ifndef WINDOWS PRIVATE->fd = 0; #endif @@ -111,10 +113,32 @@ int PISPI::writeDevice(const void * data, int max_size) { //piCoutObj << "write" << max_size << tx_buf.size(); ret = ioctl(PRIVATE->fd, SPI_IOC_MESSAGE(1), &PRIVATE->spi_ioc_tr); if (ret < 1) {piCoutObj << "can't send spi message" << ret; return -1;} - recv_buf.append(rx_buf); + if (canRead()) recv_buf.append(rx_buf); if (recv_buf.size_s() > threadedReadBufferSize()) recv_buf.resize(threadedReadBufferSize()); return max_size; } #endif return 0; } + + +PIString PISPI::constructFullPathDevice() const { + PIString ret; + ret << path() << ":" << int(speed()) << ":" << int(bits()) << ":" << (int)parameters(); + return ret; +} + + +void PISPI::configureFromFullPathDevice(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: setPath(p); break; + case 1: setSpeed(p.toInt()); break; + case 2: setBits(p.toInt()); break; + case 3: setParameters(p.toInt()); break; + default: break; + } + } +} diff --git a/src_main/io/pispi.h b/src_main/io/pispi.h index 4d5c21f5..fe74881f 100644 --- a/src_main/io/pispi.h +++ b/src_main/io/pispi.h @@ -42,6 +42,11 @@ protected: int readDevice(void * read_to, int max_size); int writeDevice(const void * data, int max_size); + PIString fullPathPrefix() const {return PIStringAscii("spi");} + PIString constructFullPathDevice() const; + void configureFromFullPathDevice(const PIString & full_path); + DeviceInfoFlags deviceInfoFlags() const {return PIIODevice::Sequential;} + private: uint spi_speed; uchar spi_mode;