8071b9008a82581ffb42ae03e525786141cd31a1
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

1) /*
2)  * EtherPix simulator
3)  *
4)  * Copyright 2017 Stefan Schuermans <stefan schuermans info>
5)  *
6)  * This program is free software: you can redistribute it and/or modify
7)  * it under the terms of the GNU General Public License as published by
8)  * the Free Software Foundation, version 3 of the License.
9)  *
10)  *
11)  * This program is distributed in the hope that it will be useful,
12)  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13)  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14)  * GNU General Public License for more details.
15)  *
16)  * You should have received a copy of the GNU Lesser General Public License
17)  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18)  */
19) 
20) #ifndef DISTRI_H
21) #define DISTRI_H
22) 
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

23) #include <arpa/inet.h>
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

24) #include <gtkmm.h>
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

25) #include <map>
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

26) #include <stdint.h>
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

27) #include <vector>
28) 
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

29) #include "bbox.h"
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

30) #include "mapping.h"
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

31) #include "pixel.h"
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

32) #include "transform.h"
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

33) 
34) /// distributor
35) class Distri
36) {
37) public:
38)   /// constructor
39)   Distri();
40) 
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

41)   /// destructor
42)   ~Distri();
43) 
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

44)   /**
45)    * @brief initialize
46)    * @param[in] distno distributor number
47)    * @param[in] outputs number of outputs
48)    * @param[in] pixels number of pixels per output
49)    */
50)   void init(unsigned long distno, unsigned long outputs, unsigned long pixels);
51) 
52)   /// get distributor number
53)   unsigned long getNo() const { return m_distno; }
54) 
55)   /// get number of outputs
56)   unsigned long getOutputs() const { return m_outputs; }
57) 
58)   /// get number of pixels at each output
59)   unsigned long getPixels() const { return m_pixels; }
60) 
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

61)   /**
62)    * @brief set network address
63)    * @param[in] addr IPv4/port network address (UDP)
64)    */
65)   void setAddr(struct sockaddr_in const &addr);
66) 
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

67)   /**
68)    * @brief get mapping
69)    * @param[in] chan color channel
70)    * @return mapping mapping object of color channel
71)    * @throws std::exception in case of error
72)    */
73)   Mapping const& getMapping(Mapping::Channel chan) const;
74) 
75)   /**
76)    * @brief set mapping
77)    * @param[in] chan color channel
78)    * @param[in] mapping new mapping object for color channel
79)    * @throws std::exception in case of error
80)    */
81)   void setMapping(Mapping::Channel chan, Mapping const &mapping);
82) 
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

83)   /**
84)    * @brief add output to distributor
85)    * @param[in] outno number of output
86)    * @throws std::exception in case of error
87)    */
88)   void addOutput(unsigned long outno);
89) 
90)   /**
91)    * @brief add pixel to output of distributor
92)    * @param[in] outno number of output
93)    * @param[in] pixel pixel object to add
94)    * @throws std::exception in case of error
95)    */
96)   void addPixel(unsigned long outno, Pixel const &pixel);
97) 
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

98)   /**
99)    * @brief add all pixels of this distributor to the bounding box
100)    * @param[in,out] bb bounding box
101)    */
102)   void updateBBox(BBox &bb) const;
103) 
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

104)   /**
105)    * @brief create socket and listen for incoming packets
106)    * @throws std::exception in case of error
107)    */
108)   void start();
109) 
110)   /**
111)    * @brief stop listening for incoming packets and close socket
112)    */
113)   void stop();
114) 
115)   /// get and reset packet conter
116)   unsigned long getPacketCounterAndReset();
117) 
Stefan Schuermans implement drawing pixels

Stefan Schuermans authored 7 years ago

118)   /**
119)    * @brief draw pixels of this distributor
120)    * @param[in] cairo cairo context for drawing
121)    * @param[in] tf coordinate transformation
122)    */
123)   void draw(Cairo::RefPtr<Cairo::Context> &cairo, Transform const &tf) const;
124) 
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

125) protected:
126)   /**
127)    * @brief callback on packet input on socket
128)    */
129)   bool on_packet(Glib::IOCondition condition);
130) 
131)   /**
132)    * @brief process pixel data
133)    * @param[in] outputs number of outputs in pixel data
134)    * @param[in] pixels number of pixels per output in pixel data
Stefan Schuermans add monochrome packet suppo...

Stefan Schuermans authored 6 years ago

135)    * @param[in] channels number of channels in pixel data
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

136)    * @param[in] data pixel data
137)    */
138)   void procPixelData(unsigned long outputs, unsigned long pixels,
Stefan Schuermans add monochrome packet suppo...

Stefan Schuermans authored 6 years ago

139)                      unsigned int channels, uint8_t const *data);
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

140) 
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

141) protected:
142)   /// output data
143)   struct Output {
144)     std::vector<Pixel> m_pixels; ///< pixels at this output
145)   };
146) 
147)   /// map out outputs: output number -> output data
148)   typedef std::map<unsigned long, Output> OutputMap;
149) 
Stefan Schuermans continue implementing confi...

Stefan Schuermans authored 7 years ago

150) protected:
Stefan Schuermans complete implementation of...

Stefan Schuermans authored 7 years ago

151)   /// distributor number
152)   unsigned long m_distno;
153)   /// number of outputs
154)   unsigned long m_outputs;
155)   /// number of pixels per output
156)   unsigned long m_pixels;
157)   /// network address
158)   struct sockaddr_in m_addr;
159)   /// mappings of color channels
160)   Mapping m_mappings[Mapping::ChannelCount];
161)   /// outputs
162)   OutputMap m_outputMap;
Stefan Schuermans implement receiving packets

Stefan Schuermans authored 7 years ago

163) 
164)   /// IPv4/UDP socket
165)   int m_sock;
166)   /// Glib connection for notification of input on m_sock
167)   sigc::connection m_conn;
168) 
169)   /// received packets since last reset
170)   unsigned long m_packets;