Open Lighting Architecture  Latest Git
JaRulePortHandleImpl.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  * JaRulePortHandleImpl.h
17  * The implementation of the Ja Rule Port Handle.
18  * Copyright (C) 2015 Simon Newton
19  */
20 
21 #ifndef LIBS_USB_JARULEPORTHANDLEIMPL_H_
22 #define LIBS_USB_JARULEPORTHANDLEIMPL_H_
23 
24 #include <ola/base/Macro.h>
25 #include <ola/DmxBuffer.h>
26 #include <ola/io/ByteString.h>
27 #include <ola/rdm/DiscoveryAgent.h>
29 #include <ola/rdm/RDMCommand.h>
31 #include <ola/rdm/UID.h>
32 #include <ola/util/SequenceNumber.h>
33 
34 #include "libs/usb/JaRuleConstants.h"
35 
36 namespace ola {
37 namespace usb {
38 
48  public:
52  JaRulePortHandleImpl(class JaRuleWidgetPort *parent_port,
53  const ola::rdm::UID &uid,
54  uint8_t physical_port);
55 
57 
58  // From DiscoverableRDMControllerInterface
62  ola::rdm::RDMCallback *on_complete);
63 
64  // From DiscoveryTargetInterface
65  void MuteDevice(const ola::rdm::UID &target,
66  MuteDeviceCallback *mute_complete);
67  void UnMuteAll(UnMuteDeviceCallback *unmute_complete);
68  void Branch(const ola::rdm::UID &lower,
69  const ola::rdm::UID &upper,
70  BranchCallback *branch_complete);
71 
77  bool SendDMX(const DmxBuffer &buffer);
78 
82  bool SetPortMode(JaRulePortMode new_mode);
83 
84  private:
85  PACK(
86  struct DUBTiming {
87  uint16_t start;
88  uint16_t end;
89  });
90 
91  PACK(
92  struct GetSetTiming {
93  uint16_t break_start;
94  uint16_t mark_start;
95  uint16_t mark_end;
96  });
97 
98  class JaRuleWidgetPort* const m_port; // not owned
99  const ola::rdm::UID m_uid;
100  const uint8_t m_physical_port;
101 
102  bool m_in_shutdown;
103 
104  // DMX members
105  DmxBuffer m_dmx;
106  bool m_dmx_in_progress;
107  bool m_dmx_queued;
108  CommandCompleteCallback *m_dmx_callback;
109 
110  // RDM members
111  ola::rdm::DiscoveryAgent m_discovery_agent;
112  ola::SequenceNumber<uint8_t> m_transaction_number;
113  ola::rdm::UIDSet m_uids;
114 
115  void CheckStatusFlags(uint8_t flags);
116  void DMXComplete(USBCommandResult result, JaRuleReturnCode return_code,
117  uint8_t status_flags, const ola::io::ByteString &payload);
118  void MuteDeviceComplete(MuteDeviceCallback *mute_complete,
119  USBCommandResult result,
120  JaRuleReturnCode return_code,
121  uint8_t status_flags,
122  const ola::io::ByteString &payload);
123  void UnMuteDeviceComplete(UnMuteDeviceCallback *unmute_complete,
124  USBCommandResult result,
125  JaRuleReturnCode return_code,
126  uint8_t status_flags,
127  const ola::io::ByteString &payload);
128  void DUBComplete(BranchCallback *callback,
129  USBCommandResult status,
130  JaRuleReturnCode return_code,
131  uint8_t status_flags,
132  const ola::io::ByteString &payload);
133  void RDMComplete(const ola::rdm::RDMRequest *request,
134  ola::rdm::RDMCallback *m_rdm_callback,
135  USBCommandResult result,
136  JaRuleReturnCode return_code,
137  uint8_t status_flags,
138  const ola::io::ByteString &payload);
139  ola::rdm::RDMResponse* UnpackRDMResponse(
140  const ola::rdm::RDMRequest *request,
141  const ola::io::ByteString &payload,
142  ola::rdm::RDMStatusCode *status_code);
143  void DiscoveryComplete(ola::rdm::RDMDiscoveryCallback *callback,
144  OLA_UNUSED bool ok,
145  const ola::rdm::UIDSet &uids);
146  CommandClass GetCommandFromRequest(const ola::rdm::RDMRequest *request);
147 
149 };
150 } // namespace usb
151 } // namespace ola
152 #endif // LIBS_USB_JARULEPORTHANDLEIMPL_H_
USBCommandResult
Indicates the eventual state of a Ja Rule command.
Definition: JaRuleConstants.h:53
Represents a set of RDM UIDs.
Definition: UIDSet.h:48
Definitions and Interfaces to implement an RDMController that sends a single message at a time...
RDMStatusCode
RDM Status Codes.
Definition: RDMResponseCodes.h:45
An RDM Command that represents responses (GET, SET or DISCOVER).
Definition: RDMCommand.h:457
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
void MuteDevice(const ola::rdm::UID &target, MuteDeviceCallback *mute_complete)
Mute a device.
Definition: JaRulePortHandleImpl.cpp:121
JaRulePortHandleImpl(class JaRuleWidgetPort *parent_port, const ola::rdm::UID &uid, uint8_t physical_port)
Create a new JaRulePortHandleImpl.
Definition: JaRulePortHandleImpl.cpp:67
CommandClass
The Ja Rule command set.
Definition: JaRuleConstants.h:101
The interface that can send RDM commands, as well as perform discovery operations.
Definition: RDMControllerInterface.h:104
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition: RDMCommand.h:234
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A RDM unique identifier (UID).
JaRulePortMode
Ja Rule Port modes.
Definition: JaRuleConstants.h:42
JaRuleReturnCode
JaRule command return codes.
Definition: JaRuleConstants.h:133
A class used to hold a single universe of DMX data.
The base class for all 4 argument callbacks.
Definition: Callback.h:3811
void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start an incremental discovery operation.
Definition: JaRulePortHandleImpl.cpp:94
bool SendDMX(const DmxBuffer &buffer)
Send DMX data from this widget.
Definition: JaRulePortHandleImpl.cpp:166
void Branch(const ola::rdm::UID &lower, const ola::rdm::UID &upper, BranchCallback *branch_complete)
Send a DUB command.
Definition: JaRulePortHandleImpl.cpp:150
#define OLA_UNUSED
Mark unused arguments & types.
Definition: Macro.h:62
The internal model of a port on a JaRule device.
Definition: JaRuleWidgetPort.h:47
void UnMuteAll(UnMuteDeviceCallback *unmute_complete)
Unmute all devices.
Definition: JaRulePortHandleImpl.cpp:136
An RDM Controller that queues messages and only sends a single message at a time. ...
The base class for all 1 argument callbacks.
Definition: Callback.h:982
An asynchronous RDM Discovery algorithm.
Definition: DiscoveryAgent.h:135
void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *on_complete)
Send a RDM command.
Definition: JaRulePortHandleImpl.cpp:102
The internal implementation of a Ja Rule Port Handle.
Definition: JaRulePortHandleImpl.h:45
Helper macros.
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
std::basic_string< uint8_t > ByteString
A contiguous block of uint8_t data.
Definition: ByteString.h:40
Implements the RDM Discovery algorithm.
bool SetPortMode(JaRulePortMode new_mode)
Change the mode of this port.
Definition: JaRulePortHandleImpl.cpp:178
void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *callback)
Start a full discovery operation.
Definition: JaRulePortHandleImpl.cpp:87
The base class for all 2 argument callbacks.
Definition: Callback.h:1885
The interface used by the DiscoveryTarget to send RDM commands.
Definition: DiscoveryAgent.h:53
Classes that represent RDM commands.