source: roaraudio/roard/codecfilter_roardmx.c @ 5927:95a79080ea30

Last change on this file since 5927:95a79080ea30 was 5927:95a79080ea30, checked in by phi, 11 years ago

cleanup of code structure and added support to support events

File size: 3.9 KB
Line 
1//codecfilter_roardmx.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2013
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28#ifndef ROAR_WITHOUT_DCOMP_LIGHT
29
30static inline int __read_sset(int id, struct roar_stream_server * ss, struct roar_roardmx_message * mes) {
31 uint16_t channel;
32 uint8_t value;
33 int i, c;
34
35 // we ignore errors here at the moment as 0 not < -1
36 c = roar_roardmx_message_numchannels(mes);
37 ROAR_DBG("light_check_stream(id=%i): Number of subframes: %u", id, c);
38
39 for (i = 0; i < c; i++) {
40  if ( roar_roardmx_message_get_chanval(mes, &channel, &value, i) == -1 )
41   return -1;
42
43  if ( g_light_state.channels < channel ) {
44   ROAR_WARN("light_check_stream(id=%i): Writing on non extisting DMX channel %u", id, channel);
45   continue;
46  } else {
47   g_light_state.state[channel]   = value;
48   g_light_state.changes[channel] = 0xFF; // the channel changed
49  }
50 }
51
52 return 0;
53}
54
55static inline int __read_events(int id, struct roar_stream_server * ss, struct roar_roardmx_message * mes) {
56 const uint8_t * events;
57 size_t len;
58
59 (void)id, (void)ss;
60
61 if ( roar_roardmx_message_get_events(mes, &events, &len) == -1 )
62  return -1;
63
64 return light_dmxevent_add(events, len);
65}
66
67int cf_light_roardmx_read(int id, struct roar_stream_server * ss) {
68 struct roar_roardmx_message  mes;
69 unsigned char type;
70
71 if ( roar_roardmx_message_recv(&mes, &(ss->vio)) == -1 )
72  return -1;
73
74 if ( roar_roardmx_message_get_type(&mes, &type) == -1 )
75  return -1;
76
77 switch (type) {
78  case ROAR_ROARDMX_TYPE_SSET: return __read_sset(id, ss, &mes); break;
79  case ROAR_ROARDMX_TYPE_EVENT: return __read_events(id, ss, &mes); break;
80 }
81
82 roar_err_set(ROAR_ERROR_NSTYPE);
83 return -1;
84}
85
86static inline int __write_events(int id, struct roar_stream_server * ss) {
87 struct roar_roardmx_message  mes;
88 const uint8_t * events;
89 size_t len;
90
91 if ( light_dmxevent_read(&events, &len) == -1 )
92  return -1;
93
94 // check if we need to send events at all:
95 if ( len == 0 )
96  return 0;
97
98 // ok, now let's build the message:
99 if ( roar_roardmx_message_new_event(&mes) == -1 )
100  return -1;
101
102 if ( roar_roardmx_message_add_events(&mes, events, len) == -1 )
103  return -1;
104
105 // and send it:
106 if ( roar_roardmx_message_send(&mes, &(ss->vio)) == -1 )
107  return -1;
108
109 return 0;
110}
111
112static inline int __write_channels(int id, struct roar_stream_server * ss) {
113 struct roar_roardmx_message  mes;
114 int have_message = 0;
115 int i;
116
117 for (i = 0; i < g_light_state.channels; i++) {
118  if ( g_light_state.changes[i] ) {
119   if ( !have_message )
120    if ( roar_roardmx_message_new_sset(&mes) == -1 )
121     return -1;
122
123   have_message = 2;
124
125   if ( roar_roardmx_message_add_chanval(&mes, i, g_light_state.state[i]) == -1 ) {
126    if ( roar_roardmx_message_send(&mes, &(ss->vio)) == -1 )
127     return -1;
128
129    if ( roar_roardmx_message_new_sset(&mes) == -1 )
130     return -1;
131
132    have_message = 1;
133   }
134  }
135 }
136
137 if ( have_message == 2 )
138  if ( roar_roardmx_message_send(&mes, &(ss->vio)) == -1 )
139   return -1;
140
141 return 0;
142}
143
144int cf_light_roardmx_write(int id, struct roar_stream_server * ss) {
145 if ( __write_events(id, ss) == -1 )
146  return -1;
147
148 if ( __write_channels(id, ss) == -1 )
149  return -1;
150
151 return 0;
152}
153
154#endif
155
156//ll
Note: See TracBrowser for help on using the repository browser.