Open Lighting Architecture  0.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 #include <netinet/in.h>
27 
28 #include <ola/BaseTypes.h>
30 #include "ola/network/MACAddress.h"
31 #include "plugins/sandnet/SandNetCommon.h"
32 
33 namespace ola {
34 namespace plugin {
35 namespace sandnet {
36 
37 enum { SANDNET_NAME_LENGTH = 31};
38 
39 /*
40  * Sandnet opcodes.
41  * These are transmitted as little-endian which why they appear strange.
42  */
43 enum packet_type_e {
44  SANDNET_ADVERTISMENT = 0x0100,
45  SANDNET_CONTROL = 0x0200,
46  SANDNET_DMX = 0x0300,
47  SANDNET_NAME = 0x0400,
48  SANDNET_IDENTIFY = 0x0500,
49  SANDNET_PROG = 0x0600,
50  SANDNET_LED = 0x0700,
51  SANDNET_COMPRESSED_DMX = 0x0a00,
52 }__attribute__((packed));
53 
54 typedef enum packet_type_e packet_type_t;
55 
56 enum protocol_id_e {
57  SANDNET_SANDNET = 0x02,
58  SANDNET_ARTNET = 0x04,
59  SANDNET_COMPULIGHT = 0x06,
60  SANDNET_SHOWNET = 0x09,
61  SANDNET_IPX = 0x0d,
62  SANDNET_ACN = 0x0e,
63 }__attribute__((packed));
64 
65 typedef enum protocol_id_e protocol_id_t;
66 
68  protocol_id_t protocol; // protocol
69  uint8_t mode; // mode
70  uint8_t term; // terminate
71  uint8_t b; // ??
72  uint8_t group; // group
73  uint8_t universe; // universe
74  uint8_t crap[53]; // ??
75 }__attribute__((packed));
76 
77 
78 /*
79  * A Sandnet Advertisment
80  */
82  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
83  uint32_t firmware; // firmware version
84  struct sandnet_packet_advertisement_port_s ports[SANDNET_MAX_PORTS]; // ports
85  uint8_t nlen; // length of the name field
86  char name[SANDNET_NAME_LENGTH]; // name field (null terminated)
87  uint8_t magic3[9]; // magic numbers
88  uint8_t led; // flash the led
89  uint8_t magic4; // ??
90  uint8_t zero4[64]; // null
91 }__attribute__((packed));
92 
94 
95 
96 /*
97  * The first of the DMX packets
98  */
99 struct sandnet_dmx_s {
100  uint8_t group; // group
101  uint8_t universe; // universe
102  uint8_t port; // physical port number
103  uint8_t dmx[DMX_UNIVERSE_SIZE]; // dmx buffer
104 }__attribute__((packed));
105 
106 typedef struct sandnet_dmx_s sandnet_dmx;
107 
108 
109 /*
110  * Changes the port attributes
111  */
113  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
114  uint8_t magic[4]; // ?? seems to change
115  struct sandnet_packet_advertisement_port_s ports[SANDNET_MAX_PORTS]; // ports
116 }__attribute__((packed));
117 
119 
120 
121 /*
122  * Sets the name of the sandnet node
123  */
125  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
126  uint8_t name_length; // length of the name field
127  uint8_t name[SANDNET_NAME_LENGTH]; // name field
128 }__attribute__((packed));
129 
130 typedef struct sandnet_name_s sandnet_name;
131 
132 
133 /*
134  * identify packet
135  * (presumably this flashes the leds or something)
136  */
138  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
139 }__attribute__((packed));
140 
141 typedef struct sandnet_identify_s sandnet_identify;
142 
143 
144 /*
145  * ip program packet
146  * sets the node's networking parameters
147  */
149  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
150  uint8_t ip[ola::network::IPV4Address::LENGTH];
151  uint8_t dhcp;
152  uint8_t netmask[ola::network::IPV4Address::LENGTH];
153 }__attribute__((packed));
154 
155 typedef struct sandnet_program_s sandnet_program;
156 
157 
158 /*
159  * Turns the led on and off
160  */
162  uint8_t mac[ola::network::MACAddress::LENGTH]; // mac address
163  uint8_t led; // 0x00 off, 0xff on
164 }__attribute__((packed));
165 
166 typedef struct sandnet_led_s sandnet_led;
167 
168 
169 /*
170  * DMX data
171  */
173  uint8_t group; // group
174  uint8_t universe; // universe
175  uint8_t port; // physical port number
176  uint8_t zero1[4]; // could be the offset
177  uint8_t two; // 0x02
178  uint16_t length; // length of data
179  uint8_t dmx[DMX_UNIVERSE_SIZE];
180 } __attribute__((packed));
181 
183 
184 
185 // A generic Sandnet packet containing the union of all possible packets
187  uint16_t opcode;
188  union {
189  sandnet_advertisement advertisement;
190  sandnet_port_control port_control;
191  sandnet_dmx dmx;
192  sandnet_name name;
193  sandnet_identify id;
194  sandnet_program program;
195  sandnet_led led;
196  sandnet_compressed_dmx compressed_dmx;
197  } contents;
198 } __attribute__((packed));
199 } // namespace sandnet
200 } // namespace plugin
201 } // namespace ola
202 #endif // PLUGINS_SANDNET_SANDNETPACKETS_H_