root/branches/libfreebob-downloader/src/bebob/bebob_dl_codes.cpp

Revision 271, 8.5 kB (checked in by wagi, 16 years ago)

2006-06-21 Daniel Wagner <wagi@monom.org>

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