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