Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RenardWidget.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  * RenardWidget.h
17  * Interface for the renard widget
18  * Copyright (C) 2013 Hakan Lindestaf
19  */
20 
21 #ifndef PLUGINS_RENARD_RENARDWIDGET_H_
22 #define PLUGINS_RENARD_RENARDWIDGET_H_
23 
24 #include <fcntl.h>
25 #include <termios.h>
26 #include <string>
27 
28 #include "ola/io/SelectServer.h"
29 #include "ola/io/Serial.h"
30 #include "ola/DmxBuffer.h"
31 
32 namespace ola {
33 namespace plugin {
34 namespace renard {
35 
36 class RenardWidget {
37  public:
38  // The DMX offset is where in the DMX universe the Renard channels
39  // will be mapped. Set to 0 means the first Renard channel will be
40  // mapped to DMX channel 1, next to 2, etc. If you set the DMX offset
41  // to 100 then the first Renard channel will respond to DMX channel
42  // 101. I envisioned this would be applicable to multiple (serial)
43  // devices sharing the same DMX universe.
44  // Number of channels is how many channels we'll output on the device.
45  // There are limits to how many channels we can address for any given
46  // refresh rate, based on baud rate and escaping. Renard ignores
47  // any extra channels that are sent on the wire, so setting this too
48  // high is not a major concern.
49  // The start address is the Renard-address of the first board. The
50  // default in the standard firmware is 0x80, and it may be a reasonable
51  // future feature request to have this configurable for more advanced
52  // Renard configurations (using wireless transmitters, etc).
53  explicit RenardWidget(const std::string &path,
54  int dmxOffset,
55  int channels,
56  uint32_t baudrate,
57  uint8_t startAddress)
58  : m_path(path),
59  m_socket(NULL),
60  m_byteCounter(0),
61  m_dmxOffset(dmxOffset),
62  m_channels(channels),
63  m_baudrate(baudrate),
64  m_startAddress(startAddress) {}
65  virtual ~RenardWidget();
66 
67  // these methods are for communicating with the device
68  bool Connect();
69  int Disconnect();
70  ola::io::ConnectedDescriptor *GetSocket() { return m_socket; }
71  std::string GetPath() { return m_path; }
72  bool SendDmx(const DmxBuffer &buffer);
73  bool DetectDevice();
74 
75  static const uint8_t RENARD_CHANNELS_IN_BANK;
76 
77  private:
78  int ConnectToWidget(const std::string &path, speed_t speed);
79 
80  // instance variables
81  const std::string m_path;
83  uint32_t m_byteCounter;
84  uint32_t m_dmxOffset;
85  uint32_t m_channels;
86  uint32_t m_baudrate;
87  uint8_t m_startAddress;
88 
89  static const uint8_t RENARD_COMMAND_PAD;
90  static const uint8_t RENARD_COMMAND_START_PACKET;
91  static const uint8_t RENARD_COMMAND_ESCAPE;
92  static const uint8_t RENARD_ESCAPE_PAD;
93  static const uint8_t RENARD_ESCAPE_START_PACKET;
94  static const uint8_t RENARD_ESCAPE_ESCAPE;
95  static const uint32_t RENARD_BYTES_BETWEEN_PADDING;
96 };
97 } // namespace renard
98 } // namespace plugin
99 } // namespace ola
100 #endif // PLUGINS_RENARD_RENARDWIDGET_H_