Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DMPE131Inflator.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  * DMPE131Inflator.h
17  * This is a subclass of the DMPInflator which knows how to handle DMP over
18  * E1.31 messages.
19  * Copyright (C) 2009 Simon Newton
20  */
21 
22 #ifndef LIBS_ACN_DMPE131INFLATOR_H_
23 #define LIBS_ACN_DMPE131INFLATOR_H_
24 
25 #include <map>
26 #include <vector>
27 #include "ola/Clock.h"
28 #include "ola/Callback.h"
29 #include "ola/DmxBuffer.h"
30 #include "libs/acn/DMPInflator.h"
31 
32 namespace ola {
33 namespace acn {
34 
36  friend class DMPE131InflatorTest;
37 
38  public:
39  explicit DMPE131Inflator(bool ignore_preview):
40  DMPInflator(),
41  m_ignore_preview(ignore_preview) {
42  }
43  ~DMPE131Inflator();
44 
45  bool SetHandler(uint16_t universe, ola::DmxBuffer *buffer,
46  uint8_t *priority, ola::Callback0<void> *handler);
47  bool RemoveHandler(uint16_t universe);
48 
49  void RegisteredUniverses(std::vector<uint16_t> *universes);
50 
51  protected:
52  virtual bool HandlePDUData(uint32_t vector,
53  const HeaderSet &headers,
54  const uint8_t *data,
55  unsigned int pdu_len);
56 
57  private:
58  typedef struct {
59  ola::acn::CID cid;
60  uint8_t sequence;
61  TimeStamp last_heard_from;
62  DmxBuffer buffer;
63  } dmx_source;
64 
65  typedef struct {
66  DmxBuffer *buffer;
67  Callback0<void> *closure;
68  uint8_t active_priority;
69  uint8_t *priority;
70  std::vector<dmx_source> sources;
71  } universe_handler;
72 
73  typedef std::map<uint16_t, universe_handler> UniverseHandlers;
74 
75  UniverseHandlers m_handlers;
76  bool m_ignore_preview;
77  ola::Clock m_clock;
78 
79  bool TrackSourceIfRequired(universe_handler *universe_data,
80  const HeaderSet &headers,
81  DmxBuffer **buffer);
82 
83  // The max number of sources we'll track per universe.
84  static const uint8_t MAX_MERGE_SOURCES = 6;
85  // The max merge priority.
86  static const uint8_t MAX_E131_PRIORITY = 200;
87  // ignore packets that differ by less than this amount from the last one
88  static const int8_t SEQUENCE_DIFF_THRESHOLD = -20;
89  // expire sources after 2.5s
90  static const TimeInterval EXPIRY_INTERVAL;
91 };
92 } // namespace acn
93 } // namespace ola
94 #endif // LIBS_ACN_DMPE131INFLATOR_H_
Definition: Clock.h:118
Definition: HeaderSet.h:35
void RegisteredUniverses(std::vector< uint16_t > *universes)
Definition: DMPE131Inflator.cpp:224
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A class used to hold a single universe of DMX data.
The ACN component identifier.
Definition: CID.h:47
Used to get the current time.
Definition: Clock.h:221
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: Clock.h:171
Definition: DMPE131Inflator.h:35
Definition: DMPInflator.h:31