implement a check if tty device is working

pull/60/head
Michal Bursa 2020-01-19 20:48:20 +01:00
rodzic 2404330740
commit 210148b223
1 zmienionych plików z 16 dodań i 0 usunięć

Wyświetl plik

@ -29,6 +29,7 @@
#include <sys/select.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/statvfs.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
@ -191,6 +192,7 @@ struct SerialDeviceTTY : public SerialDeviceImp
void close();
void checkIfShouldReopen();
bool send(vector<uchar> &data);
bool working();
SerialCommunicationManager *manager() { return manager_; }
private:
@ -300,6 +302,20 @@ bool SerialDeviceTTY::send(vector<uchar> &data)
return rc;
}
bool SerialDeviceTTY::working()
{
// test if the device is working by checking if the virtual file has been deleted using stat
struct statvfs sb;
int working = (statvfs(device_.c_str(), &sb) == 0);
if (!working) {
debug("(serial) device %s is gone\n", device_.c_str());
}
return working;
}
struct SerialDeviceCommand : public SerialDeviceImp
{
SerialDeviceCommand(string command, vector<string> args, vector<string> envs,