1 |
/* |
---|
2 |
* Copyright (C) 2005-2008 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free Firewire (pro-)audio drivers for linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB |
---|
8 |
* |
---|
9 |
* This program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 2 of the License, or |
---|
12 |
* (at your option) version 3 of the License. |
---|
13 |
* |
---|
14 |
* This program 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 program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
#include "efc_cmd.h" |
---|
25 |
#include "efc_cmds_ioconfig.h" |
---|
26 |
|
---|
27 |
#include "libutil/ByteSwap.h" |
---|
28 |
#include <iostream> |
---|
29 |
#include <cstring> |
---|
30 |
|
---|
31 |
using namespace std; |
---|
32 |
|
---|
33 |
namespace FireWorks { |
---|
34 |
|
---|
35 |
EfcGenericIOConfigCmd::EfcGenericIOConfigCmd(enum eIOConfigRegister r) |
---|
36 |
: EfcCmd() |
---|
37 |
, m_value ( 0 ) |
---|
38 |
, m_reg ( r ) |
---|
39 |
{ |
---|
40 |
m_category_id = EFC_CAT_IO_CONFIG; |
---|
41 |
m_type=eCT_Get; |
---|
42 |
setRegister(r); |
---|
43 |
} |
---|
44 |
|
---|
45 |
bool |
---|
46 |
EfcGenericIOConfigCmd::serialize( Util::Cmd::IOSSerialize& se ) |
---|
47 |
{ |
---|
48 |
bool result=true; |
---|
49 |
|
---|
50 |
if (m_type == eCT_Get) { |
---|
51 |
// the length should be specified before |
---|
52 |
// the header is serialized |
---|
53 |
m_length=EFC_HEADER_LENGTH_QUADLETS; |
---|
54 |
|
---|
55 |
result &= EfcCmd::serialize ( se ); |
---|
56 |
|
---|
57 |
} else { |
---|
58 |
// the length should be specified before |
---|
59 |
// the header is serialized |
---|
60 |
m_length=EFC_HEADER_LENGTH_QUADLETS+1; |
---|
61 |
|
---|
62 |
result &= EfcCmd::serialize ( se ); |
---|
63 |
|
---|
64 |
result &= se.write(CondSwapToBus32(m_value), "Value" ); |
---|
65 |
} |
---|
66 |
return result; |
---|
67 |
} |
---|
68 |
|
---|
69 |
bool |
---|
70 |
EfcGenericIOConfigCmd::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
71 |
{ |
---|
72 |
bool result=true; |
---|
73 |
|
---|
74 |
result &= EfcCmd::deserialize ( de ); |
---|
75 |
|
---|
76 |
if (m_type == eCT_Get) { |
---|
77 |
EFC_DESERIALIZE_AND_SWAP(de, &m_value, result); |
---|
78 |
} |
---|
79 |
|
---|
80 |
return result; |
---|
81 |
} |
---|
82 |
|
---|
83 |
bool |
---|
84 |
EfcGenericIOConfigCmd::setType( enum eCmdType type ) |
---|
85 |
{ |
---|
86 |
m_type=type; |
---|
87 |
if (m_type == eCT_Get) { |
---|
88 |
switch (m_reg) { |
---|
89 |
case eCR_Mirror: |
---|
90 |
m_command_id=EFC_CMD_IO_CONFIG_GET_MIRROR; |
---|
91 |
break; |
---|
92 |
case eCR_DigitalInterface: |
---|
93 |
m_command_id=EFC_CMD_IO_CONFIG_GET_DIGITAL_MODE; |
---|
94 |
break; |
---|
95 |
case eCR_Phantom: |
---|
96 |
m_command_id=EFC_CMD_IO_CONFIG_GET_PHANTOM; |
---|
97 |
break; |
---|
98 |
default: |
---|
99 |
debugError("Invalid IOConfig get command: %d\n", m_reg); |
---|
100 |
return false; |
---|
101 |
} |
---|
102 |
} else { |
---|
103 |
switch (m_reg) { |
---|
104 |
case eCR_Mirror: |
---|
105 |
m_command_id=EFC_CMD_IO_CONFIG_SET_MIRROR; |
---|
106 |
break; |
---|
107 |
case eCR_DigitalInterface: |
---|
108 |
m_command_id=EFC_CMD_IO_CONFIG_SET_DIGITAL_MODE; |
---|
109 |
break; |
---|
110 |
case eCR_Phantom: |
---|
111 |
m_command_id=EFC_CMD_IO_CONFIG_SET_PHANTOM; |
---|
112 |
break; |
---|
113 |
default: |
---|
114 |
debugError("Invalid IOConfig set command: %d\n", m_reg); |
---|
115 |
return false; |
---|
116 |
} |
---|
117 |
} |
---|
118 |
return true; |
---|
119 |
} |
---|
120 |
bool |
---|
121 |
EfcGenericIOConfigCmd::setRegister( enum eIOConfigRegister r ) |
---|
122 |
{ |
---|
123 |
m_reg=r; |
---|
124 |
if (m_type == eCT_Get) { |
---|
125 |
switch (m_reg) { |
---|
126 |
case eCR_Mirror: |
---|
127 |
m_command_id=EFC_CMD_IO_CONFIG_GET_MIRROR; |
---|
128 |
break; |
---|
129 |
case eCR_DigitalInterface: |
---|
130 |
m_command_id=EFC_CMD_IO_CONFIG_GET_DIGITAL_MODE; |
---|
131 |
break; |
---|
132 |
case eCR_Phantom: |
---|
133 |
m_command_id=EFC_CMD_IO_CONFIG_GET_PHANTOM; |
---|
134 |
break; |
---|
135 |
default: |
---|
136 |
debugError("Invalid IOConfig get command: %d\n", m_reg); |
---|
137 |
return false; |
---|
138 |
} |
---|
139 |
} else { |
---|
140 |
switch (m_reg) { |
---|
141 |
case eCR_Mirror: |
---|
142 |
m_command_id=EFC_CMD_IO_CONFIG_SET_MIRROR; |
---|
143 |
break; |
---|
144 |
case eCR_DigitalInterface: |
---|
145 |
m_command_id=EFC_CMD_IO_CONFIG_SET_DIGITAL_MODE; |
---|
146 |
break; |
---|
147 |
case eCR_Phantom: |
---|
148 |
m_command_id=EFC_CMD_IO_CONFIG_SET_PHANTOM; |
---|
149 |
break; |
---|
150 |
default: |
---|
151 |
debugError("Invalid IOConfig set command: %d\n", m_reg); |
---|
152 |
return false; |
---|
153 |
} |
---|
154 |
} |
---|
155 |
return true; |
---|
156 |
} |
---|
157 |
|
---|
158 |
void |
---|
159 |
EfcGenericIOConfigCmd::showEfcCmd() |
---|
160 |
{ |
---|
161 |
EfcCmd::showEfcCmd(); |
---|
162 |
debugOutput(DEBUG_LEVEL_NORMAL, "EFC IOCONFIG %s %s:\n", |
---|
163 |
(m_type==eCT_Get?"GET":"SET"), |
---|
164 |
eIOConfigRegisterToString(m_reg)); |
---|
165 |
debugOutput(DEBUG_LEVEL_NORMAL, " Value : %u\n", m_value); |
---|
166 |
} |
---|
167 |
|
---|
168 |
// --- The specific commands |
---|
169 |
|
---|
170 |
EfcIsocMapIOConfigCmd::EfcIsocMapIOConfigCmd(void) |
---|
171 |
: EfcCmd() |
---|
172 |
, m_samplerate (0) |
---|
173 |
, m_flags (0) |
---|
174 |
, m_num_playmap_entries (0) |
---|
175 |
, m_num_phys_out (0) |
---|
176 |
, m_num_recmap_entries (0) |
---|
177 |
, m_num_phys_in (0) |
---|
178 |
{ |
---|
179 |
m_category_id = EFC_CAT_IO_CONFIG; |
---|
180 |
m_reg = eCR_IsocMap; |
---|
181 |
m_type = eCT_Get; |
---|
182 |
memset(m_playmap, 0, sizeof(m_playmap)); |
---|
183 |
memset(m_recmap, 0, sizeof(m_recmap)); |
---|
184 |
} |
---|
185 |
bool |
---|
186 |
EfcIsocMapIOConfigCmd::serialize( Util::Cmd::IOSSerialize& se ) |
---|
187 |
{ |
---|
188 |
bool result=true; |
---|
189 |
unsigned int i; |
---|
190 |
|
---|
191 |
assert((m_num_playmap_entries <= EFC_MAX_ISOC_MAP_ENTRIES) |
---|
192 |
|| (m_num_recmap_entries <= EFC_MAX_ISOC_MAP_ENTRIES)); |
---|
193 |
|
---|
194 |
if (m_type == eCT_Get) { |
---|
195 |
// the length should be specified before |
---|
196 |
// the header is serialized |
---|
197 |
m_length=EFC_HEADER_LENGTH_QUADLETS; |
---|
198 |
|
---|
199 |
result &= EfcCmd::serialize ( se ); |
---|
200 |
} else { |
---|
201 |
// the length should be specified before |
---|
202 |
// the header is serialized |
---|
203 |
m_length = EFC_HEADER_LENGTH_QUADLETS + sizeof(IsoChannelMap); |
---|
204 |
|
---|
205 |
result &= EfcCmd::serialize ( se ); |
---|
206 |
|
---|
207 |
result &= se.write(CondSwapToBus32(m_samplerate), "Samplerate" ); |
---|
208 |
result &= se.write(CondSwapToBus32(m_flags), "Flags" ); |
---|
209 |
|
---|
210 |
result &= se.write(CondSwapToBus32(m_num_playmap_entries), "Num. of Entries for Play Map" ); |
---|
211 |
result &= se.write(CondSwapToBus32(m_num_phys_out), "Num. of Phys. Out" ); |
---|
212 |
for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++) |
---|
213 |
result &= se.write(CondSwapToBus32(m_playmap[i]), "Play Map Entry" ); |
---|
214 |
|
---|
215 |
result &= se.write(CondSwapToBus32(m_num_recmap_entries), "Num. of Entries for Rec Map" ); |
---|
216 |
result &= se.write(CondSwapToBus32(m_num_phys_in), "Num. of Phys. In" ); |
---|
217 |
for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++) |
---|
218 |
result &= se.write(CondSwapToBus32(m_recmap[i]), "Rec Map Entry" ); |
---|
219 |
} |
---|
220 |
|
---|
221 |
return result; |
---|
222 |
} |
---|
223 |
|
---|
224 |
bool |
---|
225 |
EfcIsocMapIOConfigCmd::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
226 |
{ |
---|
227 |
bool result=true; |
---|
228 |
unsigned int i; |
---|
229 |
|
---|
230 |
result &= EfcCmd::deserialize ( de ); |
---|
231 |
|
---|
232 |
if (m_type == eCT_Get) { |
---|
233 |
EFC_DESERIALIZE_AND_SWAP(de, &m_samplerate, result); |
---|
234 |
EFC_DESERIALIZE_AND_SWAP(de, &m_flags, result); |
---|
235 |
|
---|
236 |
EFC_DESERIALIZE_AND_SWAP(de, &m_num_playmap_entries, result); |
---|
237 |
EFC_DESERIALIZE_AND_SWAP(de, &m_num_phys_out, result); |
---|
238 |
for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++) |
---|
239 |
EFC_DESERIALIZE_AND_SWAP(de, &m_playmap[i], result); |
---|
240 |
|
---|
241 |
EFC_DESERIALIZE_AND_SWAP(de, &m_num_recmap_entries, result); |
---|
242 |
EFC_DESERIALIZE_AND_SWAP(de, &m_num_phys_in, result); |
---|
243 |
for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++) |
---|
244 |
EFC_DESERIALIZE_AND_SWAP(de, &m_recmap[i], result); |
---|
245 |
} |
---|
246 |
|
---|
247 |
return result; |
---|
248 |
} |
---|
249 |
|
---|
250 |
bool |
---|
251 |
EfcIsocMapIOConfigCmd::setType( enum eCmdType type ) |
---|
252 |
{ |
---|
253 |
m_type=type; |
---|
254 |
if (m_type == eCT_Get) |
---|
255 |
m_command_id = EFC_CMD_IO_CONFIG_GET_ISOC_MAP; |
---|
256 |
else |
---|
257 |
m_command_id = EFC_CMD_IO_CONFIG_SET_ISOC_MAP; |
---|
258 |
return true; |
---|
259 |
} |
---|
260 |
|
---|
261 |
void |
---|
262 |
EfcIsocMapIOConfigCmd::showEfcCmd() |
---|
263 |
{ |
---|
264 |
unsigned int i; |
---|
265 |
|
---|
266 |
EfcCmd::showEfcCmd(); |
---|
267 |
debugOutput(DEBUG_LEVEL_NORMAL, "EFC IOCONFIG %s %s:\n", |
---|
268 |
(m_type==eCT_Get?"GET":"SET"), |
---|
269 |
eIOConfigRegisterToString(m_reg)); |
---|
270 |
debugOutput(DEBUG_LEVEL_NORMAL, " Samplerate : %u\n", m_samplerate); |
---|
271 |
debugOutput(DEBUG_LEVEL_NORMAL, " Flags : %u\n", m_flags); |
---|
272 |
debugOutput(DEBUG_LEVEL_NORMAL, " Playback:"); |
---|
273 |
debugOutput(DEBUG_LEVEL_NORMAL, " Num. of Entries : %u\n", m_num_playmap_entries); |
---|
274 |
debugOutput(DEBUG_LEVEL_NORMAL, " Num. of Phys. Out: %u\n", m_num_phys_out); |
---|
275 |
for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++) |
---|
276 |
debugOutput(DEBUG_LEVEL_NORMAL, " Entriy %02d : %u\n", i, m_playmap[i]); |
---|
277 |
debugOutput(DEBUG_LEVEL_NORMAL, " Record:"); |
---|
278 |
debugOutput(DEBUG_LEVEL_NORMAL, " Num. of Entries : %u\n", m_num_recmap_entries); |
---|
279 |
debugOutput(DEBUG_LEVEL_NORMAL, " Num. of Phys. In : %u\n", m_num_phys_in); |
---|
280 |
for (i = 0; i < EFC_MAX_ISOC_MAP_ENTRIES; i++) |
---|
281 |
debugOutput(DEBUG_LEVEL_NORMAL, " Entriy %02d : %u\n", i, m_recmap[i]); |
---|
282 |
} |
---|
283 |
|
---|
284 |
|
---|
285 |
} // namespace FireWorks |
---|