root/trunk/libffado/src/libavc/general/avc_subunit_info.cpp

Revision 618, 2.5 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)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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 "avc_subunit_info.h"
25 #include "libutil/cmd_serialize.h"
26 #include "libieee1394/ieee1394service.h"
27
28 #include <netinet/in.h>
29 #include <iostream>
30
31 using namespace std;
32
33 namespace AVC {
34
35
36 SubUnitInfoCmd::SubUnitInfoCmd( Ieee1394Service& ieee1349service )
37     : AVCCommand( ieee1349service, AVC1394_CMD_SUBUNIT_INFO )
38 {
39     clear();
40 }
41
42 bool
43 SubUnitInfoCmd::clear()
44 {
45     m_page = 0xff;
46     m_extension_code = 0x7;
47     for ( int i = 0; i < eMaxSubunitsPerPage; ++i ) {
48         m_table[i].m_subunit_type = 0xff;
49         m_table[i].m_max_subunit_id = 0xff;
50     }
51     m_nrOfValidEntries = 0;
52     return true;
53 }
54
55
56 SubUnitInfoCmd::~SubUnitInfoCmd()
57 {
58 }
59
60 bool
61 SubUnitInfoCmd::serialize( Util::IOSSerialize& se )
62 {
63     AVCCommand::serialize( se );
64
65     byte_t operand = 0;
66     operand = ((  m_page & 0x7 ) << 4 ) | ( m_extension_code & 0x7 );
67     se.write( operand, "SubUnitInfoCmd page and extension_code" );
68
69     for ( int i = 0; i < eMaxSubunitsPerPage; ++i ) {
70         operand =  ( m_table[i].m_subunit_type << 3 )
71                    | ( m_table[i].m_max_subunit_id & 0x7 );
72         se.write( operand, "SubUnitInfoCmd subunit_type and max_subunit_ID" );
73     }
74
75     return true;
76 }
77
78 bool
79 SubUnitInfoCmd::deserialize( Util::IISDeserialize& de )
80 {
81     AVCCommand::deserialize( de );
82
83     byte_t operand;
84     de.read( &operand );
85     m_page = ( operand >> 4 ) & 0x7;
86     m_extension_code = operand & 0x7;
87
88     m_nrOfValidEntries = 0;
89     for ( int i = 0; i < eMaxSubunitsPerPage; ++i ) {
90         de.read( &operand );
91         m_table[i].m_subunit_type = operand >> 3;
92         m_table[i].m_max_subunit_id = operand & 0x7;
93
94         if ( operand != 0xff ) {
95             m_nrOfValidEntries++;
96         }
97     }
98
99     return true;
100 }
101
102 }
Note: See TracBrowser for help on using the browser.