2 * DMX Channel Data packet disassembly.
6 * This dissector is written by
8 * Erwin Rol <erwin@erwinrol.com>
9 * Copyright 2011 Erwin Rol
11 * Wireshark - Network traffic analyzer
12 * Gerald Combs <gerald@wireshark.org>
13 * Copyright 1999 Gerald Combs
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor
28 * Boston, MA 02110-1301, USA.
32 * This dissector is based on;
33 * American National Standard E1.11 - 2004
34 * Entertainment Technology USITT DMX512-A
35 * Asynchronous Serial Digital Data Transmission Standard
36 * for Controlling Lighting Equipment and Accessories
41 #include <epan/packet.h>
42 #include <epan/wmem/wmem.h>
43 #include <epan/prefs.h>
45 void proto_register_dmx_chan(void);
47 static int proto_dmx_chan
= -1;
49 static int hf_dmx_chan_output_dmx_data
= -1;
50 static int hf_dmx_chan_output_data_filter
= -1;
52 static int ett_dmx_chan
= -1;
55 * Here are the global variables associated with the preferences for DMX
57 static gint global_disp_chan_val_type
= 0;
58 static gint global_disp_col_count
= 16;
59 static gint global_disp_chan_nr_type
= 0;
62 dissect_dmx_chan(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
64 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "DMX Channels");
65 col_clear(pinfo
->cinfo
, COL_INFO
);
68 static const char *chan_format
[] = {
73 static const char *string_format
[] = {
77 wmem_strbuf_t
*chan_str
= wmem_strbuf_new_label(wmem_packet_scope());
79 guint16 length
,r
,c
,row_count
;
83 proto_tree
*ti
= proto_tree_add_item(tree
, proto_dmx_chan
, tvb
, offset
, -1, ENC_NA
);
84 proto_tree
*dmx_chan_tree
= proto_item_add_subtree(ti
, ett_dmx_chan
);
86 length
= tvb_reported_length_remaining(tvb
, offset
);
88 row_count
= (length
/ global_disp_col_count
) + ((length
% global_disp_col_count
) == 0 ? 0 : 1);
89 for (r
= 0; r
< row_count
;r
++) {
90 for (c
= 0;(c
< global_disp_col_count
) && (((r
* global_disp_col_count
) + c
) < length
);c
++) {
91 if ((global_disp_col_count
>= 2) && ((c
% (global_disp_col_count
/ 2)) == 0)) {
92 wmem_strbuf_append(chan_str
, " ");
95 v
= tvb_get_guint8(tvb
, (offset
+ (r
* global_disp_col_count
) + c
));
96 if (global_disp_chan_val_type
== 0) {
99 wmem_strbuf_append(chan_str
, "FL ");
101 wmem_strbuf_append_printf(chan_str
, chan_format
[global_disp_chan_val_type
], v
);
104 wmem_strbuf_append_printf(chan_str
, chan_format
[global_disp_chan_val_type
], v
);
108 proto_tree_add_none_format(dmx_chan_tree
, hf_dmx_chan_output_dmx_data
, tvb
,
109 offset
+(r
* global_disp_col_count
), c
,
110 string_format
[global_disp_chan_nr_type
],
111 (r
* global_disp_col_count
) + 1, wmem_strbuf_get_str(chan_str
));
114 /* Add the real type hidden */
115 item
= proto_tree_add_item(dmx_chan_tree
, hf_dmx_chan_output_data_filter
, tvb
,
116 offset
, length
, ENC_NA
);
117 PROTO_ITEM_SET_HIDDEN(item
);
122 proto_register_dmx_chan(void)
124 static hf_register_info hf
[] = {
125 { &hf_dmx_chan_output_data_filter
,
127 "dmx_chan.data_filter",
128 FT_BYTES
, BASE_NONE
, NULL
, 0x0,
131 { &hf_dmx_chan_output_dmx_data
,
134 FT_NONE
, BASE_NONE
, NULL
, 0x0,
138 static gint
*ett
[] = {
142 module_t
*dmx_chan_module
;
144 static const enum_val_t disp_chan_val_types
[] = {
145 { "pro", "Percent", 0 },
146 { "hex", "Hexadecimal", 1 },
147 { "dec", "Decimal", 2 },
151 static const enum_val_t disp_chan_nr_types
[] = {
152 { "hex", "Hexadecimal", 0 },
153 { "dec", "Decimal", 1 },
157 static const enum_val_t col_count
[] = {
166 proto_dmx_chan
= proto_register_protocol("DMX Channels","DMX Channels", "dmx-chan");
167 proto_register_field_array(proto_dmx_chan
, hf
, array_length(hf
));
168 proto_register_subtree_array(ett
, array_length(ett
));
169 register_dissector("dmx-chan", dissect_dmx_chan
, proto_dmx_chan
);
171 dmx_chan_module
= prefs_register_protocol(proto_dmx_chan
, NULL
);
173 prefs_register_enum_preference(dmx_chan_module
, "dmx_disp_chan_val_type",
174 "DMX Display channel value type",
175 "The way DMX values are displayed",
176 &global_disp_chan_val_type
,
177 disp_chan_val_types
, FALSE
);
179 prefs_register_enum_preference(dmx_chan_module
, "dmx_disp_chan_nr_type",
180 "DMX Display channel nr. type",
181 "The way DMX channel numbers are displayed",
182 &global_disp_chan_nr_type
,
183 disp_chan_nr_types
, FALSE
);
185 prefs_register_enum_preference(dmx_chan_module
, "dmx_disp_col_count",
186 "DMX Display Column Count",
187 "The number of columns for the DMX display",
188 &global_disp_col_count
,