source: roaraudio/libroarlight/roardmx.c @ 1955:06f801cd9bd6

Last change on this file since 1955:06f801cd9bd6 was 1955:06f801cd9bd6, checked in by phi, 15 years ago

added support to send a ROARDMX frame

File size: 3.2 KB
Line 
1//roardmx.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
5 *
6 *  This file is part of libroardsp 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 *  libroardsp 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, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "libroarlight.h"
26
27// base(ic) check
28#define BCHK(x) if ( (x) == NULL ) return -1
29
30int roar_roardmx_message_new (struct roar_roardmx_message * mes) {
31 BCHK(mes);
32
33 memset(mes, 0, sizeof(struct roar_roardmx_message));
34
35 mes->version = ROAR_ROARDMX_VERSION;
36
37 return 0;
38}
39
40// low level:
41//int roar_roardmx_message_set_flag(struct roar_roardmx_message * mes, unsigned char   flag);
42//int roar_roardmx_message_set_len (struct roar_roardmx_message * mes, size_t          type);
43//int roar_roardmx_message_get_data(struct roar_roardmx_message * mes, unsigned char ** data);
44
45// mdium level:
46int roar_roardmx_message_set_type(struct roar_roardmx_message * mes, unsigned char   type) {
47 BCHK(mes);
48
49 if ( (type | ROAR_ROARDMX_MASK_TYPE) - ROAR_ROARDMX_MASK_TYPE )
50  return -1;
51
52 mes->type = type;
53
54 return 0;
55}
56
57int roar_roardmx_message_get_flag(struct roar_roardmx_message * mes, unsigned char * flag) {
58 BCHK(mes);
59
60 *flag = mes->flags;
61
62 return 0;
63}
64
65int roar_roardmx_message_get_type(struct roar_roardmx_message * mes, unsigned char * type) {
66 BCHK(mes);
67
68 *type = mes->type;
69
70 return 0;
71}
72
73int roar_roardmx_message_get_len (struct roar_roardmx_message * mes, size_t        * length) {
74 BCHK(mes);
75
76 *length = mes->length;
77
78 return 0;
79}
80
81
82// IO:
83int roar_roardmx_message_send(struct roar_roardmx_message * mes, struct roar_vio_calls * vio) {
84 BCHK(mes);
85 BCHK(vio);
86
87 if ( mes->length > ROAR_ROARDMX_DATA_LENGTH ) // this is very fatal!
88  return -1;
89
90 mes->data[0] =  mes->version;
91 mes->data[1] = (mes->flags & ROAR_ROARDMX_MASK_FLAGS) |
92                (mes->type  & ROAR_ROARDMX_MASK_TYPE ) ;
93
94 mes->data[2] = mes->length;
95
96 return roar_vio_write(vio, mes->data, mes->length + 3);
97}
98
99int roar_roardmx_message_recv(struct roar_roardmx_message * mes, struct roar_vio_calls * vio);
100
101// Data/high level:
102// * SSET:
103int roar_roardmx_message_new_sset   (struct roar_roardmx_message * mes) {
104 if ( roar_roardmx_message_new(mes) == -1 )
105  return -1;
106
107 mes->type = ROAR_ROARDMX_TYPE_SSET;
108
109 return 0;
110}
111
112int roar_roardmx_message_add_chanval(struct roar_roardmx_message * mes, uint16_t channel, unsigned char val) {
113 uint16_t * chan;
114
115 BCHK(mes);
116
117 if ( (mes->length + 3) > ROAR_ROARDMX_DATA_LENGTH ) // message would be to long
118  return -1;
119
120 chan = (uint16_t *) &(mes->data[mes->length]);
121
122 *chan = ROAR_HOST2NET16(channel);
123
124 mes->data[mes->length + 2] = val;
125
126 mes->length += 3;
127
128 return 0;
129}
130
131
132//ll
Note: See TracBrowser for help on using the repository browser.