documentation for class Port added.
This commit is contained in:
+144
-2
@@ -28,90 +28,232 @@
|
|||||||
namespace libebus
|
namespace libebus
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** available device types. */
|
||||||
enum DeviceType { SERIAL, NETWORK };
|
enum DeviceType { SERIAL, NETWORK };
|
||||||
|
|
||||||
|
/** max size of receive buffer. */
|
||||||
#define MAX_READ_SIZE 100
|
#define MAX_READ_SIZE 100
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Base class for input devices.
|
||||||
|
*/
|
||||||
class Device
|
class Device
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructs a new instance.
|
||||||
|
*/
|
||||||
Device() : m_fd(-1), m_open(false), m_noDeviceCheck(false) {}
|
Device() : m_fd(-1), m_open(false), m_noDeviceCheck(false) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructor.
|
||||||
|
*/
|
||||||
virtual ~Device() {}
|
virtual ~Device() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief virtual open function for opening file descriptor
|
||||||
|
* @param deviceName to determine device type.
|
||||||
|
* @param noDeviceCheck en-/disable device check.
|
||||||
|
*/
|
||||||
virtual void openDevice(const std::string deviceName, const bool noDeviceCheck) = 0;
|
virtual void openDevice(const std::string deviceName, const bool noDeviceCheck) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief virtual close function for closing opened file descriptor
|
||||||
|
*/
|
||||||
virtual void closeDevice() = 0;
|
virtual void closeDevice() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief connection state of device.
|
||||||
|
* @return true if device is open
|
||||||
|
*/
|
||||||
bool isOpen();
|
bool isOpen();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sendBytes write bytes into opened file descriptor.
|
||||||
|
* @param buffer data to send.
|
||||||
|
* @param nbytes number of bytes to send.
|
||||||
|
* @return number of written bytes or -1 if an error has occured.
|
||||||
|
*/
|
||||||
ssize_t sendBytes(const unsigned char* buffer, size_t nbytes);
|
ssize_t sendBytes(const unsigned char* buffer, size_t nbytes);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief recvBytes read bytes from opened file descriptor.
|
||||||
|
* @param timeout max time out for new input data.
|
||||||
|
* @param maxCount max size of receive buffer.
|
||||||
|
* @return number of read bytes or -1 if an error has occured.
|
||||||
|
*/
|
||||||
ssize_t recvBytes(const long timeout, size_t maxCount);
|
ssize_t recvBytes(const long timeout, size_t maxCount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief fetch first byte from receive buffer.
|
||||||
|
* @return first byte (raw)
|
||||||
|
*/
|
||||||
unsigned char getByte();
|
unsigned char getByte();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief get current size (bytes) of the receive buffer.
|
||||||
|
* @return number of bytes in queued.
|
||||||
|
*/
|
||||||
ssize_t sizeRecvBuffer() const { return m_recvBuffer.size(); }
|
ssize_t sizeRecvBuffer() const { return m_recvBuffer.size(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/** if of file descriptor */
|
||||||
int m_fd;
|
int m_fd;
|
||||||
|
/** state of device*/
|
||||||
bool m_open;
|
bool m_open;
|
||||||
|
/** state of device check */
|
||||||
bool m_noDeviceCheck;
|
bool m_noDeviceCheck;
|
||||||
|
/** queue for received bytes */
|
||||||
std::queue<unsigned char> m_recvBuffer;
|
std::queue<unsigned char> m_recvBuffer;
|
||||||
|
/** receive buffer */
|
||||||
unsigned char m_buffer[MAX_READ_SIZE];
|
unsigned char m_buffer[MAX_READ_SIZE];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief system check if opened file descriptor is valid
|
||||||
|
* @return true if file descriptor is valid
|
||||||
|
*/
|
||||||
bool isValid();
|
bool isValid();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class for serial input device.
|
||||||
|
*/
|
||||||
class DeviceSerial : public Device
|
class DeviceSerial : public Device
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Destructor.
|
||||||
|
*/
|
||||||
~DeviceSerial() { closeDevice(); }
|
~DeviceSerial() { closeDevice(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief open function for opening file descriptor
|
||||||
|
* @param deviceName to determine device type.
|
||||||
|
* @param noDeviceCheck en-/disable device check.
|
||||||
|
*/
|
||||||
void openDevice(const std::string deviceName, const bool noDeviceCheck);
|
void openDevice(const std::string deviceName, const bool noDeviceCheck);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief close function for closing opened file descriptor
|
||||||
|
*/
|
||||||
void closeDevice();
|
void closeDevice();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** save settings from serial device */
|
||||||
termios m_oldSettings;
|
termios m_oldSettings;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class for network input device.
|
||||||
|
*/
|
||||||
class DeviceNetwork : public Device
|
class DeviceNetwork : public Device
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Destructor.
|
||||||
|
*/
|
||||||
~DeviceNetwork() { closeDevice(); }
|
~DeviceNetwork() { closeDevice(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief open function for opening file descriptor
|
||||||
|
* @param deviceName to determine device type.
|
||||||
|
* @param noDeviceCheck en-/disable device check.
|
||||||
|
*/
|
||||||
void openDevice(const std::string deviceName, const bool noDeviceCheck);
|
void openDevice(const std::string deviceName, const bool noDeviceCheck);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief close opened file descriptor
|
||||||
|
*/
|
||||||
void closeDevice();
|
void closeDevice();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Wrapper class for class Device.
|
||||||
|
*/
|
||||||
class Port
|
class Port
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Constructs a new instance and determine device type.
|
||||||
|
* @param deviceName to determine device type.
|
||||||
|
* @param noDeviceCheck en-/disable device check.
|
||||||
|
*/
|
||||||
Port(const std::string deviceName, const bool noDeviceCheck);
|
Port(const std::string deviceName, const bool noDeviceCheck);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructor.
|
||||||
|
*/
|
||||||
~Port() { delete m_device; }
|
~Port() { delete m_device; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief open device
|
||||||
|
*/
|
||||||
void open() { m_device->openDevice(m_deviceName, m_noDeviceCheck); }
|
void open() { m_device->openDevice(m_deviceName, m_noDeviceCheck); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief close device
|
||||||
|
*/
|
||||||
void close() { m_device->closeDevice(); }
|
void close() { m_device->closeDevice(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief connection state of device.
|
||||||
|
* @return true if device is open
|
||||||
|
*/
|
||||||
bool isOpen() { return m_device->isOpen(); }
|
bool isOpen() { return m_device->isOpen(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief send write bytes into opened file descriptor.
|
||||||
|
* @param buffer data to send.
|
||||||
|
* @param nbytes number of bytes to send.
|
||||||
|
* @return number of written bytes or -1 if an error has occured.
|
||||||
|
*/
|
||||||
ssize_t send(const unsigned char* buffer, size_t nbytes)
|
ssize_t send(const unsigned char* buffer, size_t nbytes)
|
||||||
{ return m_device->sendBytes(buffer, nbytes); }
|
{ return m_device->sendBytes(buffer, nbytes); }
|
||||||
ssize_t recv(const long timeout, size_t maxCount=MAX_READ_SIZE) { return m_device->recvBytes(timeout, maxCount); }
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief recv read bytes from opened file descriptor.
|
||||||
|
* @param timeout max time out for new input data.
|
||||||
|
* @param maxCount max size of receive buffer.
|
||||||
|
* @return number of read bytes or -1 if an error has occured.
|
||||||
|
*/
|
||||||
|
ssize_t recv(const long timeout, size_t maxCount = MAX_READ_SIZE)
|
||||||
|
{ return m_device->recvBytes(timeout, maxCount); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief fetch first byte from receive buffer.
|
||||||
|
* @return first byte (raw)
|
||||||
|
*/
|
||||||
unsigned char byte() { return m_device->getByte(); }
|
unsigned char byte() { return m_device->getByte(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief get current size (bytes) of the receive buffer.
|
||||||
|
* @return number of bytes in queued.
|
||||||
|
*/
|
||||||
ssize_t size() const { return m_device->sizeRecvBuffer(); }
|
ssize_t size() const { return m_device->sizeRecvBuffer(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/** the device name */
|
||||||
std::string m_deviceName;
|
std::string m_deviceName;
|
||||||
|
/** pointer to device instance */
|
||||||
Device* m_device;
|
Device* m_device;
|
||||||
|
/** true if device check is disabled */
|
||||||
bool m_noDeviceCheck;
|
bool m_noDeviceCheck;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief internal setter for device type.
|
||||||
|
* @param type of device
|
||||||
|
*/
|
||||||
void setType(const DeviceType type);
|
void setType(const DeviceType type);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) John Baier 2012-2014 <ebusd@johnm.de>
|
* Copyright (C) John Baier 2014 <ebusd@johnm.de>
|
||||||
*
|
*
|
||||||
* This file is part of ebusd.
|
* This file is part of ebusd.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) John Baier 2012-2014 <ebusd@johnm.de>
|
* Copyright (C) John Baier 2014 <ebusd@johnm.de>
|
||||||
*
|
*
|
||||||
* This file is part of ebusd.
|
* This file is part of ebusd.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) John Baier 2012-2014 <ebusd@johnm.de>
|
* Copyright (C) John Baier 2014 <ebusd@johnm.de>
|
||||||
*
|
*
|
||||||
* This file is part of ebusd.
|
* This file is part of ebusd.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) John Baier 2012-2014 <ebusd@johnm.de>
|
* Copyright (C) John Baier 2014 <ebusd@johnm.de>
|
||||||
*
|
*
|
||||||
* This file is part of ebusd.
|
* This file is part of ebusd.
|
||||||
*
|
*
|
||||||
@@ -41,6 +41,7 @@ static const unsigned char BROADCAST = 0xFE; // the broadcast destination addres
|
|||||||
*/
|
*/
|
||||||
class SymbolString
|
class SymbolString
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @brief Creates a new empty SymbolString.
|
* @brief Creates a new empty SymbolString.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) John Baier 2012-2014 <ebusd@johnm.de>
|
* Copyright (C) John Baier 2014 <ebusd@johnm.de>
|
||||||
*
|
*
|
||||||
* This file is part of ebusd.
|
* This file is part of ebusd.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user