source: roaraudio/roard/rdtcs.c @ 3358:7f9d211148e0

Last change on this file since 3358:7f9d211148e0 was 2727:f95c3e9cc1c8, checked in by phi, 15 years ago

added some functions fo simpler config of rds

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