Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added '-padding' option to uartdmx plugin. #1656

Open
wants to merge 8 commits into
base: 0.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions plugins/uartdmx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Native UART DMX Plugin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, please remove this file and edit PluginDescription if targeting 0.10.

======================

This plugin drives a supported POSIX UART (plus extensions) to produce a
direct DMX output stream. The host needs to create the DMX stream itself as
there is no external microcontroller.

This is tested with the on-board UART of the Raspberry Pi. See here for a
possible schematic:
http://eastertrail.blogspot.co.uk/2014/04/command-and-control-ii.html


## Config file: `ola-uartdmx.conf`

`enabled = true`
Enable this plugin (DISABLED by default).

`device = /dev/ttyAMA0`
The device to use for DMX output (optional). Multiple devices are supported
if the hardware exists. On later software it may also be /dev/serial0.
Using USB-serial adapters is not supported (try the
*ftdidmx* plugin instead).


### Per Device Settings (using above device name)

`<device>-break = 100`
The DMX break time in microseconds for this device (optional).

`<device>-malf = 100`
The Mark After Last Frame time in microseconds for this device (optional).

`<device>-padding = 0` Minimal slots count in DMX frame (optional).
Default is 0, which allows empty frame. Using minimal timing, frame period reaches 140 microseconds, while standard requires minimum 1204us. Using BREAK=88us and MAB=8us, frame has to include 25 slots, that gives frame period 1240us.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're feeling particularly keen, it would be really nice on initialisation to print an OLA_INFO with the minimum padding value (based on break/MAB/MALF), or even an OLA_WARN if the configured padding is insufficient!

13 changes: 12 additions & 1 deletion plugins/uartdmx/UartDmxDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ using std::string;

const char UartDmxDevice::K_MALF[] = "-malf";
const char UartDmxDevice::K_BREAK[] = "-break";
const char UartDmxDevice::K_PADDING[] = "-padding";
const unsigned int UartDmxDevice::DEFAULT_BREAK = 100;
const unsigned int UartDmxDevice::DEFAULT_MALF = 100;
const unsigned int UartDmxDevice::DEFAULT_PADDING = 0;


UartDmxDevice::UartDmxDevice(AbstractPlugin *owner,
Expand All @@ -57,7 +59,10 @@ UartDmxDevice::UartDmxDevice(AbstractPlugin *owner,
if (!StringToInt(m_preferences->GetValue(DeviceMalfKey()), &m_malft)) {
m_malft = DEFAULT_MALF;
}
m_widget.reset(new UartWidget(path));
if (!StringToInt(m_preferences->GetValue(DevicePaddingKey()), &m_paddingt)) {
m_paddingt = DEFAULT_PADDING;
}
m_widget.reset(new UartWidget(path, m_paddingt));
}

UartDmxDevice::~UartDmxDevice() {
Expand All @@ -77,6 +82,9 @@ string UartDmxDevice::DeviceMalfKey() const {
string UartDmxDevice::DeviceBreakKey() const {
return m_path + K_BREAK;
}
string UartDmxDevice::DevicePaddingKey() const {
return m_path + K_PADDING;
}

/**
* Set the default preferences for this one Device
Expand All @@ -94,6 +102,9 @@ void UartDmxDevice::SetDefaults() {
save |= m_preferences->SetDefaultValue(DeviceMalfKey(),
UIntValidator(8, 1000000),
DEFAULT_MALF);
save |= m_preferences->SetDefaultValue(DevicePaddingKey(),
UIntValidator(0, 512),
DEFAULT_PADDING);
if (save) {
m_preferences->Save();
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/uartdmx/UartDmxDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class UartDmxDevice : public Device {
// Per device options
std::string DeviceBreakKey() const;
std::string DeviceMalfKey() const;
std::string DevicePaddingKey() const;
void SetDefaults();

std::auto_ptr<UartWidget> m_widget;
Expand All @@ -60,11 +61,14 @@ class UartDmxDevice : public Device {
const std::string m_path;
unsigned int m_breakt;
unsigned int m_malft;
unsigned int m_paddingt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the t's were timing, e..g break time, mark after last frame time, so this should probably just be m_padding.


static const unsigned int DEFAULT_MALF;
static const char K_MALF[];
static const unsigned int DEFAULT_BREAK;
static const char K_BREAK[];
static const unsigned int DEFAULT_PADDING;
static const char K_PADDING[];

DISALLOW_COPY_AND_ASSIGN(UartDmxDevice);
};
Expand Down
8 changes: 7 additions & 1 deletion plugins/uartdmx/UartWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include "ola/io/IOUtils.h"
#include "ola/Logging.h"
#include "plugins/uartdmx/UartWidget.h"
#include "plugins/uartdmx/UartDmxDevice.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this include do we?


namespace ola {
namespace plugin {
Expand All @@ -54,8 +55,9 @@ namespace uartdmx {
using std::string;
using std::vector;

UartWidget::UartWidget(const string& path)
UartWidget::UartWidget(const std::string &path, unsigned int padding)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The std:: isn't needed here as we're using std::string

: m_path(path),
m_padding(padding),
m_fd(NOT_OPEN) {
}

Expand Down Expand Up @@ -122,6 +124,10 @@ bool UartWidget::Write(const ola::DmxBuffer& data) {
buffer[0] = DMX512_START_CODE;

data.Get(buffer + 1, &length);
if (length < m_padding) {
memset((buffer + 1 + length), 0x00, (m_padding - length) );
length = m_padding;
}
Comment on lines 126 to +130
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given as you've said this is probably required in a few other plugins, I wonder if it makes sense to add some extra options to DmxBuffer? e.g. GetWithPadding(uint8_t *data, unsigned int *length, unsigned int min_length). Or alternatively a Pad/Grow function which modifies the buffer in place (to save duplicating lots of functions), although the latter would need to be called on the lower level buffer in UartThread as this one is const so maybe GetWithPadding is simpler.


if (write(m_fd, buffer, length + 1) <= 0) {
// TODO(richardash1981): handle errors better as per the test code,
Expand Down
5 changes: 3 additions & 2 deletions plugins/uartdmx/UartWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class UartWidget {
/**
* Construct a new UartWidget instance for one widget.
* @param path The device file path of the serial port
* @param padding Minimum DMX frame slots count, padded with NULLs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly semantics, but I'd say they are zeros here, as they will be actual channel data.

*/
explicit UartWidget(const std::string &path);

explicit UartWidget(const std::string &path, unsigned int padding);
/** Destructor */
virtual ~UartWidget();

Expand Down Expand Up @@ -81,6 +81,7 @@ class UartWidget {

private:
const std::string m_path;
unsigned int m_padding;

/**
* variable to hold the Unix file descriptor used to open and manipulate
Expand Down