source: roaraudio/libroarlight/roardmx.c @ 1950:1ae5ccbd2fd2

Last change on this file since 1950:1ae5ccbd2fd2 was 1950:1ae5ccbd2fd2, checked in by phi, 15 years ago

wrote some basic functions

File size: 2.9 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);
84int roar_roardmx_message_recv(struct roar_roardmx_message * mes, struct roar_vio_calls * vio);
85
86// Data/high level:
87// * SSET:
88int roar_roardmx_message_new_sset   (struct roar_roardmx_message * mes) {
89 if ( roar_roardmx_message_new(mes) == -1 )
90  return -1;
91
92 mes->type = ROAR_ROARDMX_TYPE_SSET;
93
94 return 0;
95}
96
97int roar_roardmx_message_add_chanval(struct roar_roardmx_message * mes, uint16_t channel, unsigned char val) {
98 uint16_t * chan;
99
100 BCHK(mes);
101
102 if ( (mes->length + 3) > ROAR_ROARDMX_DATA_LENGTH ) // message would be to long
103  return -1;
104
105 chan = (uint16_t *) &(mes->data[mes->length]);
106
107 *chan = ROAR_HOST2NET16(channel);
108
109 mes->data[mes->length + 2] = val;
110
111 mes->length += 3;
112
113 return 0;
114}
115
116
117//ll
Note: See TracBrowser for help on using the repository browser.