[2717] | 1 | //rdtcs.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[3811] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2010 |
---|
[2717] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[2717] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "roard.h" |
---|
| 27 | |
---|
[2718] | 28 | #ifndef ROAR_WITHOUT_DCOMP_RDTCS |
---|
| 29 | |
---|
| 30 | int rdtcs_init (void) { |
---|
| 31 | return 0; |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | int rdtcs_free (void) { |
---|
| 35 | return 0; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | int rdtcs_init_config (void) { |
---|
[2719] | 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 | |
---|
[2727] | 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; |
---|
[2719] | 47 | |
---|
[2718] | 48 | return 0; |
---|
| 49 | } |
---|
| 50 | |
---|
[2727] | 51 | int 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 | |
---|
| 70 | int rdtcs_rds_set_pty (char * pty) { |
---|
| 71 | if ( pty == NULL ) |
---|
| 72 | return -1; |
---|
| 73 | |
---|
| 74 | return -1; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | int 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 | |
---|
[2721] | 88 | int rdtcs_check_stream (int id) { |
---|
| 89 | return -1; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | int rdtcs_send_stream (int id) { |
---|
[2722] | 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 | |
---|
| 115 | int 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 | |
---|
| 124 | int rdtcs_send_stream_rds_group (int id, struct roar_stream_server * ss) { |
---|
| 125 | char out[RDTCS_RDS_GROUP_LEN]; |
---|
| 126 | char * c; |
---|
[2724] | 127 | int block[4] = {RDTCS_RDS_BLOCK_A, RDTCS_RDS_BLOCK_B, RDTCS_RDS_BLOCK_C0, RDTCS_RDS_BLOCK_D}; |
---|
[2722] | 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++) { |
---|
[2724] | 145 | // data is 16 bit long |
---|
| 146 | s |= data[i] << (fill & 0xFFFF); |
---|
[2722] | 147 | fill += 16; |
---|
| 148 | |
---|
[2724] | 149 | crc = rdtcs_rds_crc_calc(data[i], block[i]); |
---|
[2722] | 150 | |
---|
[2724] | 151 | // CRC is 10 bit long |
---|
| 152 | s |= crc << (fill & 0x03FF); |
---|
[2722] | 153 | fill += 10; |
---|
| 154 | |
---|
[2724] | 155 | // shift all complet bytes we allready have out |
---|
[2722] | 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 | |
---|
[2724] | 167 | uint16_t rdtcs_rds_crc_calc (uint16_t data, int block) { |
---|
[2722] | 168 | return 0xAAAA; |
---|
[2721] | 169 | } |
---|
| 170 | |
---|
[2718] | 171 | #endif |
---|
| 172 | |
---|
[2717] | 173 | //ll |
---|