Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SandNetPackets.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  * SandNetPackets.h
17  * Datagram definitions for SandNet
18  * Copyright (C) 2005 Simon Newton
19  */
20 
21 #ifndef PLUGINS_SANDNET_SANDNETPACKETS_H_
22 #define PLUGINS_SANDNET_SANDNETPACKETS_H_
23 
24 #include <sys/types.h>
25 #include <stdint.h>
26 #ifndef _WIN32
27 #include <netinet/in.h>
28 #endif // _WIN32
29 
30 #include <ola/Constants.h>
32 #include "ola/network/MACAddress.h"
33 #include "plugins/sandnet/SandNetCommon.h"
34 
35 namespace ola {
36 namespace plugin {
37 namespace sandnet {
38 
39 enum { SANDNET_NAME_LENGTH = 31};
40 
41 /*
42  * SandNet opcodes.
43  * These are transmitted as little-endian which is why they appear strange.
44  */
45 // We can't use the PACK macro for enums
46 #ifdef _WIN32
47 #pragma pack(push, 1)
48 #endif // _WIN32
49 enum packet_type_e {
50  SANDNET_ADVERTISEMENT = 0x0100,
51  SANDNET_CONTROL = 0x0200,
52  SANDNET_DMX = 0x0300,
53  SANDNET_NAME = 0x0400,
54  SANDNET_IDENTIFY = 0x0500,
55  SANDNET_PROG = 0x0600,
56  SANDNET_LED = 0x0700,
57  SANDNET_COMPRESSED_DMX = 0x0a00,
58 #ifdef _WIN32
59 };
60 #pragma pack(pop)
61 #else
62 } __attribute__((packed));
63 #endif // _WIN32
64 
65 typedef enum packet_type_e packet_type_t;
66 
67 // We can't use the PACK macro for enums
68 #ifdef _WIN32
69 #pragma pack(push, 1)
70 #endif // _WIN32
71 enum protocol_id_e {
72  SANDNET_SANDNET = 0x02,
73  SANDNET_ARTNET = 0x04,
74  SANDNET_COMPULIGHT = 0x06,
75  SANDNET_SHOWNET = 0x09,
76  SANDNET_IPX = 0x0d,
77  SANDNET_ACN = 0x0e,
78 #ifdef _WIN32
79 };
80 #pragma pack(pop)
81 #else
82 } __attribute__((packed));
83 #endif // _WIN32
84 
85 typedef enum protocol_id_e protocol_id_t;
86 
87 PACK(
88 struct sandnet_packet_advertisement_port_s {
89  protocol_id_t protocol; // protocol
90  uint8_t mode; // mode
91  uint8_t term; // terminate
92  uint8_t b; // ??
93  uint8_t group; // group
94  uint8_t universe; // universe
95  uint8_t crap[53]; // ??
96 });
97 
98 
99 /*
100  * A Sandnet Advertisement
101  */
102 PACK(
103 struct sandnet_advertisement_s {
104  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
105  uint32_t firmware; // firmware version
106  struct sandnet_packet_advertisement_port_s ports[SANDNET_MAX_PORTS]; // ports
107  uint8_t nlen; // length of the name field
108  char name[SANDNET_NAME_LENGTH]; // name field (null terminated)
109  uint8_t magic3[9]; // magic numbers
110  uint8_t led; // flash the led
111  uint8_t magic4; // ??
112  uint8_t zero4[64]; // null
113 });
114 
115 typedef struct sandnet_advertisement_s sandnet_advertisement;
116 
117 
118 /*
119  * The first of the DMX packets
120  */
121 PACK(
122 struct sandnet_dmx_s {
123  uint8_t group; // group
124  uint8_t universe; // universe
125  uint8_t port; // physical port number
126  uint8_t dmx[DMX_UNIVERSE_SIZE]; // dmx buffer
127 });
128 
129 typedef struct sandnet_dmx_s sandnet_dmx;
130 
131 
132 /*
133  * Changes the port attributes
134  */
135 PACK(
136 struct sandnet_port_control_s {
137  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
138  uint8_t magic[4]; // ?? seems to change
139  struct sandnet_packet_advertisement_port_s ports[SANDNET_MAX_PORTS]; // ports
140 });
141 
142 typedef struct sandnet_port_control_s sandnet_port_control;
143 
144 
145 /*
146  * Sets the name of the sandnet node
147  */
148 PACK(
149 struct sandnet_name_s {
150  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
151  uint8_t name_length; // length of the name field
152  uint8_t name[SANDNET_NAME_LENGTH]; // name field
153 });
154 
155 typedef struct sandnet_name_s sandnet_name;
156 
157 
158 /*
159  * identify packet
160  * (presumably this flashes the leds or something)
161  */
162 PACK(
163 struct sandnet_identify_s {
164  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
165 });
166 
167 typedef struct sandnet_identify_s sandnet_identify;
168 
169 
170 /*
171  * ip program packet
172  * sets the node's networking parameters
173  */
174 PACK(
175 struct sandnet_program_s {
176  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
177  uint8_t ip[ola::network::IPV4Address::LENGTH];
178  uint8_t dhcp;
179  uint8_t netmask[ola::network::IPV4Address::LENGTH];
180 });
181 
182 typedef struct sandnet_program_s sandnet_program;
183 
184 
185 /*
186  * Turns the led on and off
187  */
188 PACK(
189 struct sandnet_led_s {
190  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
191  uint8_t led; // 0x00 off, 0xff on
192 });
193 
194 typedef struct sandnet_led_s sandnet_led;
195 
196 
197 /*
198  * DMX data
199  */
200 PACK(
201 struct sandnet_compressed_dmx_s {
202  uint8_t group; // group
203  uint8_t universe; // universe
204  uint8_t port; // physical port number
205  uint8_t zero1[4]; // could be the offset
206  uint8_t two; // 0x02
207  uint16_t length; // length of data
208  uint8_t dmx[DMX_UNIVERSE_SIZE];
209 });
210 
211 typedef struct sandnet_compressed_dmx_s sandnet_compressed_dmx;
212 
213 
214 // A generic Sandnet packet containing the union of all possible packets
215 PACK(
216 struct sandnet_packet {
217  uint16_t opcode;
218  union {
219  sandnet_advertisement advertisement;
220  sandnet_port_control port_control;
221  sandnet_dmx dmx;
222  sandnet_name name;
223  sandnet_identify id;
224  sandnet_program program;
225  sandnet_led led;
226  sandnet_compressed_dmx compressed_dmx;
227  } contents;
228 });
229 } // namespace sandnet
230 } // namespace plugin
231 } // namespace ola
232 #endif // PLUGINS_SANDNET_SANDNETPACKETS_H_
#define PACK(__Declaration__)
Pack structures.
Definition: Macro.h:170
Constants used throughout OLA.
Definition: Constants.h:36
Represents an IPv4 Address.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Represents a MAC Address.