Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EspNetPackets.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  * EspNetPackets.h
17  * Datagram definitions for EspNet
18  * Copyright (C) 2005-2009 Simon Newton
19  */
20 
21 #ifndef PLUGINS_ESPNET_ESPNETPACKETS_H_
22 #define PLUGINS_ESPNET_ESPNETPACKETS_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 
31 namespace ola {
32 namespace plugin {
33 namespace espnet {
34 
35 enum { ESPNET_NAME_LENGTH = 10 };
36 enum { ESPNET_DATA_LENGTH = 200 };
37 
38 enum espnet_packet_type_e {
39  ESPNET_POLL = 'E' << 24 | 'S' << 16 | 'P' << 8 | 'P',
40  ESPNET_REPLY = 'E' << 24 | 'S' << 16 | 'P' << 8 | 'R',
41  ESPNET_DMX = 'E' << 24 | 'S' << 16 | 'D' << 8 | 'D',
42  ESPNET_ACK = 'E' << 24 | 'S' << 16 | 'A' << 8 | 'P'
43 }__attribute__((packed));
44 
45 typedef enum espnet_packet_type_e espnet_packet_type_t;
46 
47 /*
48  * poll datagram
49  */
50 struct espnet_poll_s {
51  uint32_t head;
52  uint8_t type;
53 } __attribute__((packed));
54 
55 typedef struct espnet_poll_s espnet_poll_t;
56 
57 
58 /*
59  * This is used in the poll reply and config
60  */
62  uint8_t listen;
63  uint8_t ip[4];
64  uint8_t universe; // bit bizzare that nodes only listen to one universe??
65 };
66 
68 
69 /*
70  * poll reply
71  */
73  uint32_t head;
74  uint8_t mac[ola::network::MAC_LENGTH];
75  uint16_t type;
76  uint8_t version;
77  uint8_t sw;
78  uint8_t name[ESPNET_NAME_LENGTH];
79  uint8_t option;
80  uint8_t tos;
81  uint8_t ttl;
82  espnet_node_config_t config;
83 } __attribute__((packed));
84 
86 
87 /*
88  * ack datagram
89  */
90 struct espnet_ack_s {
91  uint32_t head;
92  uint8_t status;
93  uint8_t crc;
94 } __attribute__((packed));
95 
96 typedef struct espnet_ack_s espnet_ack_t;
97 
98 /*
99  * dmx datagram
100  */
102  uint32_t head;
103  uint8_t universe;
104  uint8_t start;
105  uint8_t type;
106  uint16_t size;
107  uint8_t data[DMX_UNIVERSE_SIZE];
108 } __attribute__((packed));
109 
110 typedef struct espnet_data_s espnet_data_t;
111 
112 
113 // we need to add the TCP config crap here
114 
115 
116 /*
117  * union of all espnet packets
118  */
119 typedef union {
120  espnet_poll_t poll;
121  espnet_poll_reply_t reply;
122  espnet_ack_t ack;
123  espnet_data_t dmx;
125 } // namespace espnet
126 } // namespace plugin
127 } // namespace ola
128 #endif // PLUGINS_ESPNET_ESPNETPACKETS_H_