root/trunk/libffado/src/bebob/bebob_dl_codes.cpp

Revision 554, 9.2 kB (checked in by ppalmers, 15 years ago)

Merge echoaudio branch into trunk.

This adds support for the Echo Audiofire devices to FFADO. Possibly also other devices working with the Apple Class Driver will work with this code. It is not fully complete yet, but the main rework is
done.

First of all the IAvDevice class/interface is renamed to FFADODevice, in order to separate the AV/C code from the FFADO API code. A device supported by FFADO implements a FFADODevice.

The BeBoB device has been split up into three groups:
- libavc/* : all code and commands that are specified by AV/C specs. Note that a lot of the code that used to be in BeBoB::AvDevice? now resides in AVC::Unit
- genericavc/* : a FFADODevice that uses AV/C descriptors & commands for discovery and config
- bebob/* : the bebob FFADODevice that inherits from GenericAVC::AvDevice? but that uses BridgeCo? commands for discovery

Everything has been moved as high as possible in the class hierarchy. If necessary, a subclass that uses device specific commands is introduced (e.g. BeBoB::Plug inherits from AVC::Plug and uses the
BridgeCo? extended plug info command to discover it's properties).

There are some other fixes along the way that have been done too.

Line 
1 /*
2  * Copyright (C) 2005-2007 by Daniel Wagner
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 library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
22  */
23
24 #include "bebob/bebob_dl_codes.h"
25 #include "bebob/bebob_dl_bcd.h"
26
27 using namespace AVC;
28
29 unsigned short BeBoB::CommandCodes::m_gCommandId = 0;
30
31 BeBoB::CommandCodes::CommandCodes( fb_quadlet_t protocolVersion,
32                                    fb_byte_t commandCode,
33                                    size_t     msgSize,
34                                    fb_byte_t operandSizeRequest,
35                                    fb_byte_t operandSizeRespone )
36     : m_commandId( m_gCommandId++ )
37     , m_protocolVersion( protocolVersion )
38     , m_commandCode( commandCode )
39     , m_msgSize( msgSize )
40     , m_operandSizeRequest( operandSizeRequest )
41     , m_operandSizeResponse( operandSizeRespone )
42     , m_resp_protocolVersion( 0 )
43     , m_resp_commandId( 0 )
44     , m_resp_commandCode( 0 )
45     , m_resp_operandSize( 0 )
46 {
47 }
48
49 BeBoB::CommandCodes::~CommandCodes()
50 {
51 }
52
53 bool
54 BeBoB::CommandCodes::serialize( IOSSerialize& se )
55 {
56     byte_t tmp;
57
58     bool result = se.write( m_protocolVersion, "CommandCodes: protocol version" );
59     tmp = m_commandId & 0xff;
60     result &= se.write( tmp, "CommandCodes: command id low" );
61     tmp = m_commandId >> 8;
62     result &= se.write( tmp, "CommandCodes: command id high" );
63     result &= se.write( m_commandCode, "CommandCodes: command code" );
64     result &= se.write( m_operandSizeRequest, "CommandCodes: request operand size" );
65
66     return result;
67 }
68
69 bool
70 BeBoB::CommandCodes::deserialize( IISDeserialize& de )
71 {
72     bool result = de.read( &m_resp_protocolVersion );
73     fb_byte_t tmp;
74     result &= de.read( &tmp );
75     m_resp_commandId = tmp;
76     result &= de.read( &tmp );
77     m_resp_commandId |= tmp << 8;
78     result &= de.read( &m_resp_commandCode );
79     result &= de.read( &m_resp_operandSize );
80
81     return result;
82 }
83
84 size_t
85 BeBoB::CommandCodes::getMaxSize()
86 {
87     return 2 * sizeof( fb_quadlet_t ) + m_msgSize;
88 }
89
90
91 ////////////////////////////////
92
93 BeBoB::CommandCodesReset::CommandCodesReset( fb_quadlet_t protocolVersion,
94                                              EStartMode startMode )
95     : CommandCodes( protocolVersion, eCmdC_Reset, sizeof( m_startMode ), 1, 0 )
96     , m_startMode( startMode )
97 {
98 }
99
100 BeBoB::CommandCodesReset::~CommandCodesReset()
101 {
102 }
103
104 bool
105 BeBoB::CommandCodesReset::serialize( IOSSerialize& se )
106 {
107     bool result = CommandCodes::serialize( se );
108     result &= se.write( m_startMode, "CommandCodesReset: boot mode" );
109
110     return result;
111 }
112
113 bool
114 BeBoB::CommandCodesReset::deserialize( IISDeserialize& de )
115 {
116     return CommandCodes::deserialize( de );
117 }
118
119 ////////////////////////////////
120
121 BeBoB::CommandCodesProgramGUID::CommandCodesProgramGUID(
122     fb_quadlet_t protocolVersion,
123     fb_octlet_t guid )
124     : CommandCodes( protocolVersion, eCmdC_ProgramGUID, sizeof( m_guid ), 2, 0 )
125     , m_guid( guid )
126 {
127 }
128
129 BeBoB::CommandCodesProgramGUID::~CommandCodesProgramGUID()
130 {
131 }
132
133 bool
134 BeBoB::CommandCodesProgramGUID::serialize( IOSSerialize& se )
135 {
136     bool result = CommandCodes::serialize( se );
137     fb_quadlet_t tmp = m_guid >> 32;
138     result &= se.write( tmp, "CommandCodesProgramGUID: GUID (high)" );
139     tmp = m_guid & 0xffffffff;
140     result &= se.write( tmp, "CommandCodesProgramGUID: GUID (low)" );
141
142     return result;
143 }
144
145 bool
146 BeBoB::CommandCodesProgramGUID::deserialize( IISDeserialize& de )
147 {
148     return CommandCodes::deserialize( de );
149 }
150
151 ////////////////////////////////
152
153 BeBoB::CommandCodesDownloadStart::CommandCodesDownloadStart(
154     fb_quadlet_t protocolVersion,
155     EObject object )
156     : CommandCodes( protocolVersion, eCmdC_DownloadStart, 10*4, 10, 1 )
157     , m_object( object )
158     , m_date( 0 )
159     , m_time( 0 )
160     , m_id( 0 )
161     , m_version( 0 )
162     , m_address( 0 )
163     , m_length( 0 )
164     , m_crc( 0 )
165 {
166 }
167
168 BeBoB::CommandCodesDownloadStart::~CommandCodesDownloadStart()
169 {
170 }
171
172 bool
173 BeBoB::CommandCodesDownloadStart::serialize( IOSSerialize& se )
174 {
175     bool result = CommandCodes::serialize( se );
176
177     result &= se.write( m_object,  "CommandCodesDownloadStart: object" );
178     for (  unsigned int i = 0; i < sizeof( m_date ); ++i ) {
179         fb_byte_t* tmp = ( fb_byte_t* )( &m_date );
180         result &= se.write( tmp[i], "CommandCodesDownloadStart: date" );
181     }
182     for (  unsigned int i = 0; i < sizeof( m_date ); ++i ) {
183         fb_byte_t* tmp = ( fb_byte_t* )( &m_time );
184         result &= se.write( tmp[i], "CommandCodesDownloadStart: time" );
185     }
186     result &= se.write( m_id,      "CommandCodesDownloadStart: id" );
187     result &= se.write( m_version, "CommandCodesDownloadStart: version" );
188     result &= se.write( m_address, "CommandCodesDownloadStart: address" );
189     result &= se.write( m_length,  "CommandCodesDownloadStart: length" );
190     result &= se.write( m_crc,     "CommandCodesDownloadStart: crc" );
191
192     return result;
193 }
194
195 bool
196 BeBoB::CommandCodesDownloadStart::deserialize( IISDeserialize& de )
197 {
198     bool result = CommandCodes::deserialize( de );
199     result &= de.read( reinterpret_cast<fb_quadlet_t*>( &m_resp_max_block_size ) );
200
201     return result;
202 }
203
204 ////////////////////////////////
205
206 BeBoB::CommandCodesDownloadBlock::CommandCodesDownloadBlock(
207     fb_quadlet_t protocolVersion )
208     : CommandCodes( protocolVersion,
209                     eCmdC_DownloadBlock,
210                     12,
211                     3,
212                     2 )
213     , m_seqNumber( 0 )
214     , m_address ( 0 )
215     , m_resp_seqNumber( 0 )
216     , m_resp_errorCode( 0 )
217 {
218 }
219
220 BeBoB::CommandCodesDownloadBlock::~CommandCodesDownloadBlock()
221 {
222 }
223
224 bool
225 BeBoB::CommandCodesDownloadBlock::serialize( IOSSerialize& se )
226 {
227     bool result = CommandCodes::serialize( se );
228     result &= se.write( m_seqNumber, "CommandCodesDownloadBlock: sequence number" );
229     result &= se.write( m_address, "CommandCodesDownloadBlock: address" );
230     result &= se.write( m_numBytes, "CommandCodesDownloadBlock: number of bytes" );
231     return result;
232 }
233
234 bool
235 BeBoB::CommandCodesDownloadBlock::deserialize( IISDeserialize& de )
236 {
237     bool result = CommandCodes::deserialize( de );
238     result &= de.read( &m_resp_seqNumber );
239     result &= de.read( &m_resp_errorCode );
240
241     return result;
242 }
243
244 ////////////////////////////////
245
246 BeBoB::CommandCodesDownloadEnd::CommandCodesDownloadEnd(
247     fb_quadlet_t protocolVersion )
248     : CommandCodes( protocolVersion, eCmdC_DownloadEnd, 2, 0, 2 )
249 {
250 }
251
252 BeBoB::CommandCodesDownloadEnd::~CommandCodesDownloadEnd()
253 {
254 }
255
256 bool
257 BeBoB::CommandCodesDownloadEnd::serialize( IOSSerialize& se )
258 {
259     return CommandCodes::serialize( se );
260 }
261
262 bool
263 BeBoB::CommandCodesDownloadEnd::deserialize( IISDeserialize& de )
264 {
265     bool result = CommandCodes::deserialize( de );
266     result &= de.read( &m_resp_crc32 );
267     result &= de.read( &m_resp_valid );
268
269     return result;
270 }
271
272
273 ////////////////////////////////
274
275 BeBoB::CommandCodesInitializePersParam::CommandCodesInitializePersParam(
276     fb_quadlet_t protocolVersion )
277     : CommandCodes( protocolVersion, eCmdC_InitPersParams, 0, 0, 0 )
278 {
279 }
280
281 BeBoB::CommandCodesInitializePersParam::~CommandCodesInitializePersParam()
282 {
283 }
284
285 bool
286 BeBoB::CommandCodesInitializePersParam::serialize( IOSSerialize& se )
287 {
288     return CommandCodes::serialize( se );
289 }
290
291 bool
292 BeBoB::CommandCodesInitializePersParam::deserialize( IISDeserialize& de )
293 {
294     return CommandCodes::deserialize( de );
295 }
296
297 ////////////////////////////////
298
299 BeBoB::CommandCodesInitializeConfigToFactorySetting::CommandCodesInitializeConfigToFactorySetting(
300     fb_quadlet_t protocolVersion )
301     : CommandCodes( protocolVersion, eCmdC_InitConfigToFactorySetting, 0, 0, 0 )
302 {
303 }
304
305 BeBoB::CommandCodesInitializeConfigToFactorySetting::~CommandCodesInitializeConfigToFactorySetting()
306 {
307 }
308
309 bool
310 BeBoB::CommandCodesInitializeConfigToFactorySetting::serialize( IOSSerialize& se )
311 {
312     return CommandCodes::serialize( se );
313 }
314
315 bool
316 BeBoB::CommandCodesInitializeConfigToFactorySetting::deserialize( IISDeserialize& de )
317 {
318     return CommandCodes::deserialize( de );
319 }
320
321 ////////////////////////////////
322
323 BeBoB::CommandCodesGo::CommandCodesGo( fb_quadlet_t protocolVersion,
324                                              EStartMode startMode )
325     : CommandCodes( protocolVersion, eCmdC_Go, sizeof( m_startMode ), 1, 1 )
326     , m_startMode( startMode )
327 {
328 }
329
330 BeBoB::CommandCodesGo::~CommandCodesGo()
331 {
332 }
333
334 bool
335 BeBoB::CommandCodesGo::serialize( IOSSerialize& se )
336 {
337     bool result = CommandCodes::serialize( se );
338     result &= se.write( m_startMode, "CommandCodesGo: start mode" );
339
340     return result;
341 }
342
343 bool
344 BeBoB::CommandCodesGo::deserialize( IISDeserialize& de )
345 {
346     bool result = CommandCodes::deserialize( de );
347     result &= de.read( &m_resp_validCRC );
348
349     return result;
350 }
Note: See TracBrowser for help on using the browser.