Removed incorrect file-headers

Added rs232 library
Added abstract Rs232 device


Former-commit-id: 9a2830f71376f0716edea594afc526018a530fa3
This commit is contained in:
T. van der Zwan
2013-11-05 15:46:17 +00:00
parent 263bf93e0f
commit cb2cc5c259
13 changed files with 1292 additions and 41 deletions

View File

@@ -21,6 +21,7 @@ SET(Hyperion_HEADERS
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.h
${CURRENT_SOURCE_DIR}/ImageToLedsMap.h
${CURRENT_SOURCE_DIR}/LedSpiDevice.h
${CURRENT_SOURCE_DIR}/LedRs232Device.h
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.h
${CURRENT_SOURCE_DIR}/LedDeviceLdp6803.h
@@ -37,6 +38,7 @@ SET(Hyperion_SOURCES
${CURRENT_SOURCE_DIR}/BlackBorderProcessor.cpp
${CURRENT_SOURCE_DIR}/ImageToLedsMap.cpp
${CURRENT_SOURCE_DIR}/LedSpiDevice.cpp
${CURRENT_SOURCE_DIR}/LedRs232Device.cpp
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
${CURRENT_SOURCE_DIR}/LedDeviceWs2801.cpp
${CURRENT_SOURCE_DIR}/LedDeviceLdp6803.cpp

View File

@@ -0,0 +1,62 @@
// STL includes
#include <cstring>
#include <cstdio>
#include <iostream>
// Local Hyperion includes
#include "LedRs232Device.h"
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate) :
mDeviceName(outputDevice),
mBaudRate_Hz(baudrate),
_rs232Port()
{
// empty
}
LedRs232Device::~LedRs232Device()
{
if (_rs232Port.isOpen())
{
_rs232Port.close();
}
}
int LedRs232Device::open()
{
try
{
_rs232Port.setPort(mDeviceName);
_rs232Port.setBaudrate(mBaudRate_Hz);
_rs232Port.open();
}
catch (const std::exception& e)
{
std::cerr << "Unable to open RS232 device (" << e.what() << ")" << std::endl;
return -1;
}
return 0;
}
int LedRs232Device::writeBytes(const unsigned size, const uint8_t * data)
{
if (!_rs232Port.isOpen())
{
return -1;
}
try
{
_rs232Port.write(data, size);
}
catch (const std::exception& e)
{
std::cerr << "Unable to write to RS232 device (" << e.what() << ")" << std::endl;
return -1;
}
return 0;
}

View File

@@ -0,0 +1,54 @@
#pragma once
// Serial includes
#include <serial/serial.h>
// Hyperion includes
#include <hyperion/LedDevice.h>
///
/// The LedRs232Device implements an abstract base-class for LedDevices using a RS232-device.
///
class LedRs232Device : public LedDevice
{
public:
///
/// Constructs the LedDevice attached to a RS232-device
///
/// @param[in] outputDevice The name of the output device (eg '/etc/ttyS0')
/// @param[in] baudrate The used baudrate for writing to the output device
///
LedRs232Device(const std::string& outputDevice, const unsigned baudrate);
///
/// Destructor of the LedDevice; closes the output device if it is open
///
virtual ~LedRs232Device();
///
/// Opens and configures the output device
///
/// @return Zero on succes else negative
///
int open();
protected:
/**
* Writes the given bytes to the RS232-device and
*
* @param[in[ size The length of the data
* @param[in] data The data
*
* @return Zero on succes else negative
*/
int writeBytes(const unsigned size, const uint8_t *data);
private:
/// The name of the output device
const std::string mDeviceName;
/// The used baudrate of the output device
const int mBaudRate_Hz;
/// The RS232 serial-device
serial::Serial _rs232Port;
};

View File

@@ -17,6 +17,8 @@ public:
///
/// @param[in] outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
/// @param[in] baudrate The used baudrate for writing to the output device
/// @param[in] latchTime_ns The latch-time to latch in the values across the SPI-device (negative
/// means no latch required) [ns]
///
LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns = -1);
@@ -33,17 +35,15 @@ public:
int open();
protected:
/**
* Writes the given bytes/bits to the SPI-device and sleeps the latch time to ensure that the
* values are latched.
*
* @param[in[ size The length of the data
* @param[in] data The data
* @param[in] latchTime_ns The latch-time to latch in the values across the SPI-device (negative
* means no latch required) [ns]
*
* @return Zero on succes else negative
*/
///
/// Writes the given bytes/bits to the SPI-device and sleeps the latch time to ensure that the
/// values are latched.
///
/// @param[in[ size The length of the data
/// @param[in] data The data
///
/// @return Zero on succes else negative
///
int writeBytes(const unsigned size, const uint8_t *data);
private: