POSIX FTDI: Count LIBUSB_ERROR_IO as a disconnection
parent
3764a2e814
commit
c847d68f3c
|
|
@ -54,6 +54,7 @@ private:
|
||||||
|
|
||||||
static std::vector<std::tuple<int, std::string>> handles;
|
static std::vector<std::tuple<int, std::string>> handles;
|
||||||
|
|
||||||
|
static bool ErrorIsDisconnection(int errorCode);
|
||||||
void readTask();
|
void readTask();
|
||||||
void writeTask();
|
void writeTask();
|
||||||
bool openable; // Set to false in the constructor if the object has not been found in searchResultDevices
|
bool openable; // Set to false in the constructor if the object has not been found in searchResultDevices
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,12 @@ bool FTDI::FTDIContext::closeDevice() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FTDI::ErrorIsDisconnection(int errorCode) {
|
||||||
|
return errorCode == LIBUSB_ERROR_NO_DEVICE ||
|
||||||
|
errorCode == LIBUSB_ERROR_PIPE ||
|
||||||
|
errorCode == LIBUSB_ERROR_IO;
|
||||||
|
}
|
||||||
|
|
||||||
void FTDI::readTask() {
|
void FTDI::readTask() {
|
||||||
constexpr size_t READ_BUFFER_SIZE = 8;
|
constexpr size_t READ_BUFFER_SIZE = 8;
|
||||||
uint8_t readbuf[READ_BUFFER_SIZE];
|
uint8_t readbuf[READ_BUFFER_SIZE];
|
||||||
|
|
@ -192,7 +198,7 @@ void FTDI::readTask() {
|
||||||
while(!closing && !isDisconnected()) {
|
while(!closing && !isDisconnected()) {
|
||||||
auto readBytes = ftdi.read(readbuf, READ_BUFFER_SIZE);
|
auto readBytes = ftdi.read(readbuf, READ_BUFFER_SIZE);
|
||||||
if(readBytes < 0) {
|
if(readBytes < 0) {
|
||||||
if(readBytes == LIBUSB_ERROR_NO_DEVICE || readBytes == LIBUSB_ERROR_PIPE) {
|
if(ErrorIsDisconnection(readBytes)) {
|
||||||
if(!isDisconnected()) {
|
if(!isDisconnected()) {
|
||||||
disconnected = true;
|
disconnected = true;
|
||||||
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
|
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
|
||||||
|
|
@ -215,7 +221,7 @@ void FTDI::writeTask() {
|
||||||
while(offset < writeOp.bytes.size()) {
|
while(offset < writeOp.bytes.size()) {
|
||||||
auto writeBytes = ftdi.write(writeOp.bytes.data() + offset, (int)writeOp.bytes.size() - offset);
|
auto writeBytes = ftdi.write(writeOp.bytes.data() + offset, (int)writeOp.bytes.size() - offset);
|
||||||
if(writeBytes < 0) {
|
if(writeBytes < 0) {
|
||||||
if(writeBytes == LIBUSB_ERROR_NO_DEVICE || writeBytes == LIBUSB_ERROR_PIPE) {
|
if(ErrorIsDisconnection(writeBytes)) {
|
||||||
if(!isDisconnected()) {
|
if(!isDisconnected()) {
|
||||||
disconnected = true;
|
disconnected = true;
|
||||||
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
|
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue