Open Lighting Architecture  0.9.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 PLUGINS_E131_E131_DMPE131INFLATOR_H_
23 #define PLUGINS_E131_E131_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 "plugins/e131/e131/DMPInflator.h"
31 
32 namespace ola {
33 namespace plugin {
34 namespace e131 {
35 
37  friend class DMPE131InflatorTest;
38 
39  public:
40  explicit DMPE131Inflator(bool ignore_preview):
41  DMPInflator(),
42  m_ignore_preview(ignore_preview) {
43  }
44  ~DMPE131Inflator();
45 
46  bool SetHandler(unsigned int universe, ola::DmxBuffer *buffer,
47  uint8_t *priority, ola::Callback0<void> *handler);
48  bool RemoveHandler(unsigned int universe);
49 
50  void RegisteredUniverses(std::vector<unsigned int> *universes);
51 
52  protected:
53  virtual bool HandlePDUData(uint32_t vector,
54  const HeaderSet &headers,
55  const uint8_t *data,
56  unsigned int pdu_len);
57 
58  private:
59  typedef struct {
60  ola::acn::CID cid;
61  uint8_t sequence;
62  TimeStamp last_heard_from;
63  DmxBuffer buffer;
64  } dmx_source;
65 
66  typedef struct {
67  DmxBuffer *buffer;
68  Callback0<void> *closure;
69  uint8_t active_priority;
70  uint8_t *priority;
71  std::vector<dmx_source> sources;
72  } universe_handler;
73 
74  std::map<unsigned int, universe_handler> m_handlers;
75  bool m_ignore_preview;
76  ola::Clock m_clock;
77 
78  bool TrackSourceIfRequired(universe_handler *universe_data,
79  const HeaderSet &headers,
80  DmxBuffer **buffer);
81 
82  // The max number of sources we'll track per universe.
83  static const uint8_t MAX_MERGE_SOURCES = 6;
84  static const uint8_t MAX_PRIORITY = 200;
85  // ignore packets that differ by less than this amount from the last one
86  static const int8_t SEQUENCE_DIFF_THRESHOLD = -20;
87  // expire sources after 2.5s
88  static const TimeInterval EXPIRY_INTERVAL;
89 };
90 } // namespace e131
91 } // namespace plugin
92 } // namespace ola
93 #endif // PLUGINS_E131_E131_DMPE131INFLATOR_H_