root/branches/streaming-rework/src/libavc/avc_generic.cpp

Revision 413, 7.3 kB (checked in by pieterpalmers, 17 years ago)

- moved all generic IEEE1394 classes into libieee1394

src/libieee1394/ieee1394service.h
src/libieee1394/csr1212.h
src/libieee1394/configrom.cpp
src/libieee1394/configrom.h
src/libieee1394/ieee1394service.cpp
src/libieee1394/csr1212.c

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* avc_generic.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_generic.h"
22 #include "avc_serialize.h"
23 #include "libieee1394/ieee1394service.h"
24
25 #include "debugmodule/debugmodule.h"
26
27 #include <netinet/in.h>
28
29 #define DEBUG_EXTRA_VERBOSE 5
30
31 IMPL_DEBUG_MODULE( AVCCommand, AVCCommand, DEBUG_LEVEL_NORMAL );
32
33 int AVCCommand::m_time = 0;
34
35 AVCCommand::AVCCommand( Ieee1394Service& ieee1394service,
36                         opcode_t opcode )
37     : m_p1394Service( &ieee1394service )
38     , m_nodeId( 0 )
39     , m_ctype( eCT_Unknown )
40     , m_subunit( 0xff )
41     , m_opcode( opcode )
42     , m_eResponse( eR_Unknown )
43 {
44
45 }
46
47 bool
48 AVCCommand::serialize( IOSSerialize& se )
49 {
50     // XXX \todo improve IOSSerialize::write interface
51     char* buf;
52     asprintf( &buf, "AVCCommand ctype ('%s')",
53               responseToString( static_cast<AVCCommand::EResponse>( m_ctype ) ) );
54     se.write( m_ctype, buf );
55     free( buf );
56
57     asprintf( &buf, "AVCCommand subunit (subunit_type = %d, subunit_id = %d)",
58               getSubunitType(), getSubunitId() );
59     se.write( m_subunit, buf );
60     free( buf );
61
62     se.write( m_opcode, "AVCCommand opcode" );
63     return true;
64 }
65
66 bool
67 AVCCommand::deserialize( IISDeserialize& de )
68 {
69     de.read( &m_ctype );
70     de.read( &m_subunit );
71     de.read( &m_opcode );
72     return true;
73 }
74
75 bool
76 AVCCommand::setCommandType( ECommandType commandType )
77 {
78     m_ctype = commandType;
79     m_commandType = commandType;
80     return true;
81 }
82
83 AVCCommand::ECommandType
84 AVCCommand::getCommandType()
85 {
86     return m_commandType;
87 }
88
89 AVCCommand::EResponse
90 AVCCommand::getResponse()
91 {
92     return m_eResponse;
93 }
94
95 bool
96 AVCCommand::setSubunitType(ESubunitType subunitType)
97 {
98     byte_t subT = subunitType;
99
100     m_subunit = ( subT << 3 ) | ( m_subunit & 0x7 );
101     return true;
102 }
103
104 bool
105 AVCCommand::setNodeId( fb_nodeid_t nodeId )
106 {
107     m_nodeId = nodeId;
108     return true;
109 }
110
111 bool
112 AVCCommand::setSubunitId(subunit_id_t subunitId)
113 {
114     m_subunit = ( subunitId & 0x7 ) | ( m_subunit & 0xf8 );
115     return true;
116 }
117
118 AVCCommand::ESubunitType
119 AVCCommand::getSubunitType()
120 {
121     return static_cast<ESubunitType>( ( m_subunit >> 3 ) );
122 }
123
124 subunit_id_t
125 AVCCommand::getSubunitId()
126 {
127     return m_subunit & 0x7;
128 }
129
130 bool
131 AVCCommand::setVerbose( int verboseLevel )
132 {
133     setDebugLevel(verboseLevel);
134     return true;
135 }
136
137 int
138 AVCCommand::getVerboseLevel()
139 {
140     return getDebugLevel();
141 }
142
143
144 void
145 AVCCommand::showFcpFrame( const unsigned char* buf,
146                           unsigned short frameSize ) const
147 {
148     for ( int i = 0; i < frameSize; ++i ) {
149         if ( ( i % 16 ) == 0 ) {
150             if ( i > 0 ) {
151                 debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "\n" );
152             }
153             debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "  %3d:\t", i );
154         } else if ( ( i % 4 ) == 0 ) {
155             debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, " " );
156         }
157         debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "%02x ", buf[i] );
158     }
159     debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "\n" );
160 }
161
162 bool
163 AVCCommand::fire()
164 {
165     memset( &m_fcpFrame,  0x0,  sizeof( m_fcpFrame ) );
166
167     BufferSerialize se( m_fcpFrame, sizeof( m_fcpFrame ) );
168     if ( !serialize( se ) ) {
169         debugFatal(  "ExtendedPlugInfoCmd::fire: Could not serialize\n" );
170         return false;
171     }
172
173     unsigned short fcpFrameSize = se.getNrOfProducesBytes();
174
175     if (getDebugLevel() >= DEBUG_LEVEL_VERY_VERBOSE) {
176         debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "%s:\n", getCmdName() );
177         debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE,  "  Request:\n");
178         showFcpFrame( m_fcpFrame, fcpFrameSize );
179
180         StringSerializer se_dbg;
181         serialize( se_dbg );
182
183         debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "%s\n",
184                          se_dbg.getString().c_str());
185     }
186
187     unsigned int resp_len;
188     quadlet_t* resp = m_p1394Service->transactionBlock( m_nodeId,
189                                                         (quadlet_t*)m_fcpFrame,
190                                                         ( fcpFrameSize+3 ) / 4,
191                                                         &resp_len );
192     bool result = false;
193     if ( resp ) {
194         resp_len *= 4;
195         unsigned char* buf = ( unsigned char* ) resp;
196
197         m_eResponse = ( EResponse )( *buf );
198         switch ( m_eResponse )
199         {
200         case eR_Accepted:
201         case eR_Implemented:
202         case eR_Rejected:
203         case eR_NotImplemented:
204         {
205             BufferDeserialize de( buf, resp_len );
206             result = deserialize( de );
207
208             debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE,"  Response:\n");
209             showFcpFrame( buf, de.getNrOfConsumedBytes() );
210
211             StringSerializer se_dbg;
212             serialize( se_dbg );
213
214             debugOutputShort(DEBUG_LEVEL_VERY_VERBOSE, "%s\n",
215                              se_dbg.getString().c_str());
216         }
217         break;
218         default:
219             debugWarning( "unexpected response received (0x%x)\n", m_eResponse );
220             debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE,"  Response:\n");
221
222             BufferDeserialize de( buf, resp_len );
223             deserialize( de );
224
225             showFcpFrame( buf, de.getNrOfConsumedBytes() );
226
227         }
228     } else {
229            debugWarning( "no response\n" );
230     }
231
232     debugOutputShort( DEBUG_LEVEL_VERY_VERBOSE, "\n" );
233
234     m_p1394Service->transactionBlockClose();
235
236     usleep( m_time );
237
238     return result;
239 }
240
241 void
242 AVCCommand::setSleepAfterAVCCommand( int time )
243 {
244     m_time = time;
245 }
246
247 const char* subunitTypeStrings[] =
248 {
249     "Monitor",
250     "Audio",
251     "Printer",
252     "Disc recorder",
253     "Tape recorder/VCR",
254     "Tuner",
255     "CA",
256     "Video camera",
257     "unknown",
258     "Panel",
259     "Bulletin board",
260     "Camera storage",
261     "Music",
262 };
263
264 const char*
265 subunitTypeToString( subunit_type_t subunitType )
266 {
267     if ( subunitType == AVCCommand::eST_Unit ) {
268         return "Unit";
269     }
270     if ( subunitType > ( int ) ( sizeof( subunitTypeStrings )
271              / sizeof( subunitTypeStrings[0] ) ) ) {
272         return "unknown";
273     } else {
274         return subunitTypeStrings[subunitType];
275     }
276 }
277
278 const char* responseToStrings[] =
279 {
280     "control",
281     "status",
282     "specific inquiry",
283     "notify",
284     "general inquiry",
285     "reserved for future specification",
286     "reserved for future specification",
287     "reserved for future specification",
288     "not implemented",
289     "accepted",
290     "rejected",
291     "in transition",
292     "implemented/stable",
293     "changed"
294     "reserved for future specification",
295     "interim",
296 };
297
298 const char*
299 responseToString( AVCCommand::EResponse eResponse )
300 {
301     if ( eResponse > ( int )( sizeof( responseToStrings ) / sizeof( responseToStrings[0] ) ) ) {
302         return "unknown";
303     }
304     return responseToStrings[eResponse];
305 }
Note: See TracBrowser for help on using the browser.