source: roaraudio/roard/rdtcs.c @ 5826:edb28d83ca21

Last change on this file since 5826:edb28d83ca21 was 5823:f9f70dbaa376, checked in by phi, 11 years ago

updated copyright

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