[2717] | 1 | //rdtcs.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[6052] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2015 |
---|
[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 | |
---|
[5194] | 30 | // declared 'extern' |
---|
| 31 | struct rdtcs_state g_rdtcs; |
---|
| 32 | |
---|
[2718] | 33 | int rdtcs_init (void) { |
---|
| 34 | return 0; |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | int rdtcs_free (void) { |
---|
| 38 | return 0; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | int rdtcs_init_config (void) { |
---|
[2719] | 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 | |
---|
[2727] | 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; |
---|
[2719] | 50 | |
---|
[2718] | 51 | return 0; |
---|
| 52 | } |
---|
| 53 | |
---|
[2727] | 54 | int 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 | |
---|
| 73 | int rdtcs_rds_set_pty (char * pty) { |
---|
| 74 | if ( pty == NULL ) |
---|
| 75 | return -1; |
---|
| 76 | |
---|
| 77 | return -1; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | int 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 | |
---|
[2721] | 91 | int rdtcs_check_stream (int id) { |
---|
| 92 | return -1; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | int rdtcs_send_stream (int id) { |
---|
[2722] | 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 | |
---|
| 118 | int 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 | |
---|
| 127 | int rdtcs_send_stream_rds_group (int id, struct roar_stream_server * ss) { |
---|
| 128 | char out[RDTCS_RDS_GROUP_LEN]; |
---|
| 129 | char * c; |
---|
[2724] | 130 | int block[4] = {RDTCS_RDS_BLOCK_A, RDTCS_RDS_BLOCK_B, RDTCS_RDS_BLOCK_C0, RDTCS_RDS_BLOCK_D}; |
---|
[2722] | 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++) { |
---|
[2724] | 148 | // data is 16 bit long |
---|
| 149 | s |= data[i] << (fill & 0xFFFF); |
---|
[2722] | 150 | fill += 16; |
---|
| 151 | |
---|
[2724] | 152 | crc = rdtcs_rds_crc_calc(data[i], block[i]); |
---|
[2722] | 153 | |
---|
[2724] | 154 | // CRC is 10 bit long |
---|
| 155 | s |= crc << (fill & 0x03FF); |
---|
[2722] | 156 | fill += 10; |
---|
| 157 | |
---|
[2724] | 158 | // shift all complet bytes we allready have out |
---|
[2722] | 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 | |
---|
[2724] | 170 | uint16_t rdtcs_rds_crc_calc (uint16_t data, int block) { |
---|
[2722] | 171 | return 0xAAAA; |
---|
[2721] | 172 | } |
---|
| 173 | |
---|
[2718] | 174 | #endif |
---|
| 175 | |
---|
[2717] | 176 | //ll |
---|