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

Revision 618, 9.3 kB (checked in by ppalmers, 13 years ago)

move serialization routines to libutil such that they can be used for non-AVC stuff too (fireworks EFC)

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