Open Lighting Architecture  0.9.3
 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(uint16_t universe, ola::DmxBuffer *buffer,
47  uint8_t *priority, ola::Callback0<void> *handler);
48  bool RemoveHandler(uint16_t universe);
49 
50  void RegisteredUniverses(std::vector<uint16_t> *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  typedef std::map<uint16_t, universe_handler> UniverseHandlers;
75 
76  UniverseHandlers m_handlers;
77  bool m_ignore_preview;
78  ola::Clock m_clock;
79 
80  bool TrackSourceIfRequired(universe_handler *universe_data,
81  const HeaderSet &headers,
82  DmxBuffer **buffer);
83 
84  // The max number of sources we'll track per universe.
85  static const uint8_t MAX_MERGE_SOURCES = 6;
86  // The max merge priority.
87  static const uint8_t MAX_E131_PRIORITY = 200;
88  // ignore packets that differ by less than this amount from the last one
89  static const int8_t SEQUENCE_DIFF_THRESHOLD = -20;
90  // expire sources after 2.5s
91  static const TimeInterval EXPIRY_INTERVAL;
92 };
93 } // namespace e131
94 } // namespace plugin
95 } // namespace ola
96 #endif // PLUGINS_E131_E131_DMPE131INFLATOR_H_