Skip to content

Commit

Permalink
Fixes to UART class for Windows. Doesn't *work* yet but should at lea…
Browse files Browse the repository at this point in the history
…st compile now. See #4.
  • Loading branch information
azonenberg committed Sep 20, 2020
1 parent 289b8bb commit 2101269
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions UART.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ UART::UART(const std::string& devfile, int baud)
*/
UART::UART()
: m_networked(false)
, m_fd(-1)
, m_fd(INVALID_FILE_DESCRIPTOR)
, m_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
{
}
Expand Down Expand Up @@ -180,8 +180,9 @@ void UART::Close()
//TODO
#else
close(m_fd);
m_fd = -1;
#endif

m_fd = INVALID_FILE_DESCRIPTOR;
}

bool UART::Read(unsigned char* data, int len)
Expand Down
8 changes: 6 additions & 2 deletions UART.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
#ifdef _WIN32

typedef HANDLE FILE_DESCRIPTOR;
#define INVALID_FILE_DESCRIPTOR INVALID_HANDLE_VALUE

#else

typedef int FILE_DESCRIPTOR;
#define INVALID_FILE_DESCRIPTOR -1

#endif

Expand All @@ -71,8 +73,10 @@ class UART

bool IsValid() const
{
if (m_networked) return m_socket.IsValid();
return (m_fd >= 0);
if (m_networked)
return m_socket.IsValid();

return (m_fd != INVALID_FILE_DESCRIPTOR);
}

protected:
Expand Down

0 comments on commit 2101269

Please sign in to comment.