source: roaraudio/roard/rdtcs.c @ 5012:b263759832f1

Last change on this file since 5012:b263759832f1 was 4708:c9d40761088a, checked in by phi, 13 years ago

updated copyright statements

File size: 3.5 KB
Line 
1//rdtcs.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011
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_RDTCS
29
30int rdtcs_init  (void) {
31 return 0;
32}
33
34int rdtcs_free  (void) {
35 return 0;
36}
37
38int rdtcs_init_config  (void) {
39 memset(&g_rdtcs, 0, sizeof(g_rdtcs));
40
41 strncpy(g_rdtcs.rds.ps, RDTCS_RDS_PS_DEFAULT, RDTCS_RDS_PS_LEN);
42 g_rdtcs.rds.ps[RDTCS_RDS_PS_LEN] = 0;
43
44 g_rdtcs.rds.pty   = RDTCS_RDS_PTY_DEFAULT;
45 g_rdtcs.rds.pi    = RDTCS_RDS_PI_DEFAULT;
46 g_rdtcs.rds.flags = RDTCS_RDS_FLAG_NONE;
47
48 return 0;
49}
50
51int rdtcs_rds_set_ps  (char * ps) {
52 int i;
53
54 if ( ps == NULL )
55  return -1;
56
57 if ( strlen(ps) > 8 )
58  return -1;
59
60 // coppy string converting to upper case:
61 for (i = 0; ps[i]; i++) {
62  g_rdtcs.rds.ps[i] = toupper(ps[i]);
63 }
64
65 g_rdtcs.rds.ps[i] = 0; // terminating \0
66
67 return 0;
68}
69
70int rdtcs_rds_set_pty (char * pty) {
71 if ( pty == NULL )
72  return -1;
73
74 return -1;
75}
76
77int rdtcs_rds_set_flag  (unsigned int flag, int reset) {
78 
79 g_rdtcs.rds.flags |= flag;
80
81 if ( reset )
82  g_rdtcs.rds.flags -= flag;
83
84 return 0;
85}
86
87
88int rdtcs_check_stream  (int id) {
89 return -1;
90}
91
92int rdtcs_send_stream   (int id) {
93 struct roar_stream        *   s;
94 struct roar_stream_server *  ss;
95
96 if ( g_streams[id] == NULL )
97  return -1;
98
99 ROAR_DBG("rdtcs_send_stream(id=%i) = ?", id);
100
101 s = ROAR_STREAM(ss = g_streams[id]);
102
103 switch (s->info.codec) {
104  case ROAR_CODEC_RDS:
105    return rdtcs_send_stream_rds(id, ss);
106   break;
107  default:
108    streams_delete(id);
109    return -1;
110 }
111
112 return 0;
113}
114
115int rdtcs_send_stream_rds  (int id, struct roar_stream_server *  ss) {
116 struct roar_stream        *   s;
117
118 s = ROAR_STREAM(ss);
119
120
121 return rdtcs_send_stream_rds_group(id, ss);
122}
123
124int rdtcs_send_stream_rds_group  (int id, struct roar_stream_server *  ss) {
125 char out[RDTCS_RDS_GROUP_LEN];
126 char * c;
127 int      block[4] = {RDTCS_RDS_BLOCK_A, RDTCS_RDS_BLOCK_B, RDTCS_RDS_BLOCK_C0, RDTCS_RDS_BLOCK_D};
128 uint16_t data[4];
129 uint16_t crc;
130 register uint32_t s;
131 int i, fill;
132
133 // TODO: think about byte order!
134
135 for (i = 0; i < 4; i++) data[i] = 0;
136
137 data[0] = g_rdtcs.rds.pi;
138
139 memset(out, 0, sizeof(out));
140
141 c    = out;
142 s    = 0;
143 fill = 0;
144 for (i = 0; i < 4; i++) {
145  // data is 16 bit long
146  s |= data[i] << (fill & 0xFFFF);
147  fill += 16;
148
149  crc = rdtcs_rds_crc_calc(data[i], block[i]);
150
151  // CRC is 10 bit long
152  s |= crc << (fill & 0x03FF);
153  fill += 10;
154
155  // shift all complet bytes we allready have out
156  while (fill >= 8) {
157   *c     = s & 0xFF;
158    c++;
159    s   >>= 8;
160    fill -= 8;
161  }
162 }
163
164 return stream_vio_s_write(ss, out, RDTCS_RDS_GROUP_LEN) == RDTCS_RDS_GROUP_LEN ? 0 : -1;
165}
166
167uint16_t rdtcs_rds_crc_calc      (uint16_t data, int block) {
168 return 0xAAAA;
169}
170
171#endif
172
173//ll
Note: See TracBrowser for help on using the repository browser.