Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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>
33#include "plugins/sandnet/SandNetCommon.h"
34
35namespace ola {
36namespace plugin {
37namespace sandnet {
38
39enum { 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
49enum 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
65typedef 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
71enum 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
85typedef enum protocol_id_e protocol_id_t;
86
87PACK(
88struct 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 */
102PACK(
103struct 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
115typedef struct sandnet_advertisement_s sandnet_advertisement;
116
117
118/*
119 * The first of the DMX packets
120 */
121PACK(
122struct 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
129typedef struct sandnet_dmx_s sandnet_dmx;
130
131
132/*
133 * Changes the port attributes
134 */
135PACK(
136struct 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
142typedef struct sandnet_port_control_s sandnet_port_control;
143
144
145/*
146 * Sets the name of the sandnet node
147 */
148PACK(
149struct 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
155typedef struct sandnet_name_s sandnet_name;
156
157
158/*
159 * identify packet
160 * (presumably this flashes the leds or something)
161 */
162PACK(
163struct sandnet_identify_s {
164 uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
165});
166
167typedef struct sandnet_identify_s sandnet_identify;
168
169
170/*
171 * ip program packet
172 * sets the node's networking parameters
173 */
174PACK(
175struct 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
182typedef struct sandnet_program_s sandnet_program;
183
184
185/*
186 * Turns the led on and off
187 */
188PACK(
189struct sandnet_led_s {
190 uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
191 uint8_t led; // 0x00 off, 0xff on
192});
193
194typedef struct sandnet_led_s sandnet_led;
195
196
197/*
198 * DMX data
199 */
200PACK(
201struct 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
211typedef struct sandnet_compressed_dmx_s sandnet_compressed_dmx;
212
213
214// A generic Sandnet packet containing the union of all possible packets
215PACK(
216struct 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_
Constants used throughout OLA.
Represents an IPv4 Address.
Represents a MAC Address.
#define PACK(__Declaration__)
Pack structures.
Definition Macro.h:171
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
@ DMX_UNIVERSE_SIZE
Definition Constants.h:36