root/tags/release_0_0_6/libfreebob/src/libfreebobavc/avc_unit_info.cpp

Revision 125, 4.9 kB (checked in by wagi, 18 years ago)

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* avc_unit_info.cpp
2  * Copyright (C) 2005 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 "avc_unit_info.h"
22 #include "serialize.h"
23 #include "ieee1394service.h"
24
25 #include <netinet/in.h>
26 #include <iostream>
27
28 using namespace std;
29
30 UnitInfoCmd::UnitInfoCmd( Ieee1394Service* ieee1349service )
31     : AVCCommand( ieee1349service, AVC1394_CMD_UNIT_INFO )
32     , m_reserved( 0xff )
33     , m_unit_type( 0xff )
34     , m_unit( 0xff )
35     , m_company_id( 0xffffffff )
36 {
37 }
38
39 UnitInfoCmd::~UnitInfoCmd()
40 {
41 }
42
43 bool
44 UnitInfoCmd::serialize( IOSSerialize& se )
45 {
46     AVCCommand::serialize( se );
47
48     se.write( m_reserved, "UnitInfoCmd reserved" );
49     byte_t operand = ( m_unit_type << 3 ) | ( m_unit & 0x7 );
50     se.write( operand, "UnitInfoCmd unit_type and unit" );
51     operand = ( m_company_id >> 16 ) & 0xff;
52     se.write( operand, "UnitInfoCmd company_ID (2)" );
53     operand = ( m_company_id >> 8 ) & 0xff;
54     se.write( operand, "UnitInfoCmd company_ID (1)" );
55     operand = ( m_company_id >> 0 ) & 0xff;
56     se.write( operand, "UnitInfoCmd company_ID (0)" );
57
58     return true;
59 }
60
61 bool
62 UnitInfoCmd::deserialize( IISDeserialize& de )
63 {
64     AVCCommand::deserialize( de );
65
66     de.read( &m_reserved );
67
68     byte_t operand;
69     de.read( &operand );
70     m_unit_type = ( operand >> 3 );
71     m_unit = ( operand & 0x7 );
72
73     de.read( &operand );
74     m_company_id = 0;
75     m_company_id |= operand << 16;
76     de.read( &operand );
77     m_company_id |= operand << 8;
78     de.read( &operand );
79     m_company_id |= operand;
80
81     return true;
82 }
83
84 bool
85 UnitInfoCmd::fire()
86 {
87     bool result = false;
88
89     #define STREAM_FORMAT_REQUEST_SIZE 2
90     union UPacket {
91         quadlet_t     quadlet[STREAM_FORMAT_REQUEST_SIZE];
92         unsigned char byte[STREAM_FORMAT_REQUEST_SIZE*4];
93     };
94     typedef union UPacket packet_t;
95
96     packet_t  req;
97     packet_t* resp;
98
99     // initialize complete packet
100     memset( &req,  0xff,  sizeof( req ) );
101
102     BufferSerialize se( req.byte, sizeof( req ) );
103     if ( !serialize( se ) ) {
104         printf(  "UnitInoCmd::fire: Could not serialize\n" );
105         return false;
106     }
107
108     // reorder the bytes to the correct layout
109     for (int i = 0; i < STREAM_FORMAT_REQUEST_SIZE; ++i) {
110         req.quadlet[i] = ntohl( req.quadlet[i] );
111     }
112
113     if ( isVerbose() ) {
114         // debug output
115         puts("request:");
116         for (int i = 0; i < STREAM_FORMAT_REQUEST_SIZE; ++i) {
117             printf("  %2d: 0x%08x\n", i, req.quadlet[i]);
118         }
119     }
120
121     resp = reinterpret_cast<packet_t*>(
122         m_1394Service->transactionBlock( m_nodeId,
123                                          req.quadlet,
124                                          STREAM_FORMAT_REQUEST_SIZE ) );
125     if ( resp ) {
126         if ( isVerbose() ) {
127             // debug output
128             puts("response:");
129             for ( int i = 0; i < STREAM_FORMAT_REQUEST_SIZE; ++i ) {
130                 printf( "  %2d: 0x%08x\n", i, resp->quadlet[i] );
131             }
132         }
133
134         // reorder the bytes to the correct layout
135         for ( int i = 0; i < STREAM_FORMAT_REQUEST_SIZE; ++i ) {
136             resp->quadlet[i] = htonl( resp->quadlet[i] );
137         }
138
139         if ( isVerbose() ) {
140             // a more detailed debug output
141             printf( "\n" );
142             printf( " idx type                       value\n" );
143             printf( "-------------------------------------\n" );
144             printf( "  %02d                     ctype: 0x%02x\n", 0, resp->byte[0] );
145             printf( "  %02d subunit_type + subunit_id: 0x%02x\n", 1, resp->byte[1] );
146             printf( "  %02d                    opcode: 0x%02x\n", 2, resp->byte[2] );
147
148             for ( int i = 3; i < STREAM_FORMAT_REQUEST_SIZE * 4; ++i ) {
149                 printf( "  %02d                operand %2d: 0x%02x\n", i, i-3, resp->byte[i] );
150             }
151         }
152
153         // parse output
154         parseResponse( resp->byte[0] );
155         switch ( getResponse() )
156         {
157             case eR_Implemented:
158             {
159                 BufferDeserialize de( resp->byte, sizeof( req ) );
160                 deserialize( de );
161                 result = true;
162             }
163             break;
164             default:
165                 printf( "unexpected response received (0x%x)\n", getResponse() );
166         }
167     } else {
168         printf( "no response\n" );
169     }
170
171     return result;
172 }
Note: See TracBrowser for help on using the browser.