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

Revision 1135, 2.5 kB (checked in by ppalmers, 16 years ago)

centralize byteswapping and make it conditional

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2  * Copyright (C) 2005-2008 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 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 "avc_subunit_info.h"
25 #include "libutil/cmd_serialize.h"
26 #include "libieee1394/ieee1394service.h"
27
28 #include "libutil/ByteSwap.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::Cmd::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::Cmd::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.