Compare commits

4 Commits

Author SHA1 Message Date
93cf55d323 Merge branch 'master' of https://git.shs.tools/SHS/pip 2020-08-26 18:43:40 +03:00
2ef0ca6946 PIIODevice destructor fix 2020-08-26 18:43:33 +03:00
2a42d2a341 Merge branch 'master' of https://git.shs.tools/SHS/pip 2020-08-26 18:01:23 +03:00
7f2c82dc69 PIEthernet reconnect 2020-08-26 18:01:17 +03:00
23 changed files with 59 additions and 23 deletions

View File

@@ -25,7 +25,8 @@ PICloudServer::PICloudServer(const PIString & path, PIIODevice::DeviceMode mode)
PICloudServer::~PICloudServer() {
stop();
close();
}
@@ -33,10 +34,10 @@ bool PICloudServer::openDevice() {
piCout << "PICloudServer open device" << path();
bool op = eth.connect(path(), false);
if (op) {
// CONNECTL(&eth, disconnected, [this](bool){opened_ = false;});
return true;
} else {
eth.close();
}
eth.close();
return false;
}

View File

@@ -78,6 +78,12 @@ PIBinaryLog::PIBinaryLog() {
}
PIBinaryLog::~PIBinaryLog() {
stop();
close();
}
bool PIBinaryLog::openDevice() {
lastrecord.timestamp = PISystemTime();
lastrecord.id = 0;

View File

@@ -31,7 +31,7 @@ class PIP_EXPORT PIBinaryLog: public PIIODevice
PIIODEVICE(PIBinaryLog)
public:
explicit PIBinaryLog();
~PIBinaryLog() {closeDevice();}
virtual ~PIBinaryLog();
//! \brief Play modes for \a PIBinaryLog
enum PlayMode {

View File

@@ -46,6 +46,12 @@ PICAN::PICAN(const PIString & path, PIIODevice::DeviceMode mode) : PIIODevice(pa
}
PICAN::~PICAN() {
stop();
close();
}
bool PICAN::openDevice() {
#ifdef PIP_CAN
piCout << "PICAN open device" << path();

View File

@@ -31,7 +31,7 @@ class PIP_EXPORT PICAN: public PIIODevice
PIIODEVICE(PICAN)
public:
explicit PICAN(const PIString & path = PIString(), PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
~PICAN() {}
virtual ~PICAN();
void setCANID(int id);
int CANID() const;

View File

@@ -244,7 +244,7 @@ PIEthernet::PIEthernet(int sock_, PIString ip_port): PIIODevice("", ReadWrite) {
PIEthernet::~PIEthernet() {
//piCout << "~PIEthernet" << uint(this);
stop();
closeDevice();
close();
//piCoutObj << "~PIEthernet done";
}

View File

@@ -154,6 +154,12 @@ bool PIFile::openTemporary(PIIODevice::DeviceMode mode) {
}
PIFile::~PIFile() {
stop();
close();
}
bool PIFile::openDevice() {
close();
PIString p = path();

View File

@@ -91,7 +91,7 @@ public:
//! Open temporary file with open mode "mode"
bool openTemporary(PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
~PIFile() {closeDevice();}
virtual ~PIFile();
//! Immediate write all buffered data to disk
void flush();

View File

@@ -37,8 +37,6 @@ public:
//! Contructs %PIIOByteArray with \"buffer\" content only for read
explicit PIIOByteArray(const PIByteArray & buffer);
~PIIOByteArray() {closeDevice();}
//! Returns content
PIByteArray * byteArray() const {return data_;}

View File

@@ -137,11 +137,6 @@ PIIODevice::PIIODevice(const PIString & path, PIIODevice::DeviceMode mode): PITh
PIIODevice::~PIIODevice() {
stop();
if (opened_) {
closeDevice();
if (!opened_)
closed();
}
}

View File

@@ -37,8 +37,6 @@ public:
//! Contructs %PIIOString with \"string\" content only for read
explicit PIIOString(const PIString & string);
~PIIOString() {closeDevice();}
//! Returns content
PIString * string() const {return str;}

View File

@@ -181,6 +181,7 @@ PIPeer::PIPeer(const PIString & n): PIIODevice(), inited__(false), eth_tcp_srv(P
PIPeer::~PIPeer() {
//piCout << "~PIPeer" << uint(this);
stop();
if (destroyed) return;
destroyed = true;
sync_timer.stop();

View File

@@ -197,7 +197,8 @@ PISerial::PISerial(const PIString & device_, PISerial::Speed speed_, PIFlags<PIS
PISerial::~PISerial() {
closeDevice();
stop();
close();
}

View File

@@ -97,7 +97,7 @@ public:
//! Contructs %PISerial with device name "device", speed "speed" and parameters "params"
explicit PISerial(const PIString & device, PISerial::Speed speed = S115200, PIFlags<PISerial::Parameters> params = 0);
~PISerial();
virtual ~PISerial();
//! Set both input and output speed to "speed"

View File

@@ -89,6 +89,12 @@ PISharedMemory::PISharedMemory(const PIString & shm_name, int size, PIIODevice::
}
PISharedMemory::~PISharedMemory() {
stop();
close();
}
bool PISharedMemory::openDevice() {
close();
//piCoutObj << "try open" << path() << dsize;

View File

@@ -37,7 +37,7 @@ public:
explicit PISharedMemory(const PIString & shm_name, int size, DeviceMode mode = ReadWrite);
virtual ~PISharedMemory() {close();}
virtual ~PISharedMemory();
//! Read all shared memory object content to byte array and return it
PIByteArray readAll();

View File

@@ -59,6 +59,12 @@ PISPI::PISPI(const PIString & path, uint speed, PIIODevice::DeviceMode mode) : P
}
PISPI::~PISPI() {
stop();
close();
}
void PISPI::setSpeed(uint speed_hz) {
spi_speed = speed_hz;
}

View File

@@ -31,7 +31,7 @@ class PIP_EXPORT PISPI: public PIIODevice
PIIODEVICE(PISPI)
public:
explicit PISPI(const PIString & path = PIString(), uint speed_hz = 1000000, PIIODevice::DeviceMode mode = PIIODevice::ReadWrite);
~PISPI() {}
virtual ~PISPI();
//! \brief Parameters of PISPI
enum Parameters {

View File

@@ -37,6 +37,12 @@ PITransparentDevice::PITransparentDevice() {
}
PITransparentDevice::~PITransparentDevice() {
stop();
close();
}
int PITransparentDevice::readDevice(void * read_to, int max_size) {
if (!canRead()) return -1;
que_mutex.lock();

View File

@@ -34,7 +34,7 @@ public:
//! Contructs empty %PITransparentDevice
explicit PITransparentDevice();
~PITransparentDevice() {closeDevice();}
virtual ~PITransparentDevice();
protected:
bool openDevice();

View File

@@ -32,7 +32,7 @@ class PIP_EXPORT PIUSB: public PIIODevice
PIIODEVICE(PIUSB)
public:
explicit PIUSB(ushort vid = 0, ushort pid = 0);
~PIUSB() {closeDevice();}
virtual ~PIUSB();
struct PIP_EXPORT Endpoint {
Endpoint(uchar a = 0, uchar at = 0, ushort mps = 0) {address = a; attributes = at; max_packet_size = mps; parse();}

View File

@@ -46,6 +46,11 @@ PIUSB::PIUSB(ushort vid, ushort pid): PIIODevice("", ReadWrite) {
}
PIUSB::~PIUSB() {
stop();
close();
}
void PIUSB::Endpoint::parse() {
synchronisation_type = NoSynchonisation;
usage_type = DataEndpoint;

View File

@@ -12,6 +12,7 @@ int main() {
// }
// s.open();
s.startThreadedRead();
piSleep(200);
piSleep(2);
// s.stopThreadedRead();
return 0;
}