root/trunk/freebob/src/avdevice.cpp

Revision 18, 4.2 kB (checked in by pieterpalmers, 19 years ago)

- Placed some extra debug functions in a new file debugmodule.cpp
- Added AvDescriptor? class as a generic AVC descriptor handler class
- Added the new files to the makefile

REMARK: The new code is still quite messy and undebugged. This commit is mainly to expose my current work, to make sure no work is duplicated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* avdevice.cpp
2  * Copyright (C) 2004 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 #include <errno.h>
21 #include <libavc1394/avc1394.h>
22 #include <libavc1394/avc1394_vcr.h>
23 #include "debugmodule.h"
24 #include "avdevice.h"
25
26 AvDevice::AvDevice(int port, int node)
27 {
28         iNodeId=node;
29         m_iPort=port;
30
31         // check to see if a device is really present?
32 }
33
34 FBReturnCodes
35 AvDevice::Initialize() {
36    if (!m_bInitialised) {
37
38         m_handle = raw1394_new_handle();
39         if ( !m_handle ) {
40             if ( !errno ) {
41                 fprintf( stderr,  "libraw1394 not compatible.\n" );
42             } else {
43                 perror ("Could not get 1394 handle");
44                 fprintf (stderr, "Is ieee1394 and raw1394 driver loaded?\n");
45             }
46             return eFBRC_Creating1394HandleFailed;
47         }
48        
49         raw1394_set_userdata( m_handle, this );
50        
51         if ( raw1394_set_port( m_handle,  m_iPort ) < 0 ) {
52             perror( "Could not set port" );
53             return eFBRC_Setting1394PortFailed;
54         }
55    }
56    
57    m_bInitialised = true;
58    return eFBRC_Success;
59        
60 }
61
62 bool AvDevice::isInitialised() {
63         return m_bInitialised;
64 }
65
66 AvDevice::~AvDevice()
67 {
68     if ( m_handle ) {
69         raw1394_destroy_handle( m_handle );
70         m_handle = 0;
71     }
72 }
73
74 /* Function to execute an AVC transaction, i.e. send command/status and get response
75  * main purpose is wrapping the avc1394 function call to output some debugging comments.
76  */
77 quadlet_t * AvDevice::avcExecuteTransaction(quadlet_t *request, unsigned int request_len, unsigned int response_len) {
78         quadlet_t *response;
79         unsigned char *request_pos;
80         unsigned int i;
81         response = avc1394_transaction_block(m_handle, iNodeId, request, request_len, 2);
82         if (request != NULL) {
83                 fprintf(stderr,"  REQUEST:     ");
84                 /* request is in machine byte order. this function is for intel architecure */
85                 for (i=0;i<request_len;i++) {
86                         request_pos=(unsigned char *)(request+i);
87                         fprintf(stderr, "0x%02X%02X%02X%02X ", *(request_pos),*(request_pos+1),*(request_pos+2),*(request_pos+3));
88                 }
89                 fprintf(stderr,"\n");
90                 fprintf(stderr,"      => ");
91                 fprintf(stderr,"                     ");
92                 request_pos=(unsigned char *)(request);
93                 fprintf(stderr, "subunit_type=%02X  subunit_id=%02X  opcode=%02X",((*(request_pos+1))>>3)&0x1F,(*(request_pos+1))&0x07,(*(request_pos+2))&0xFF);
94                 fprintf(stderr,"\n");
95         }       
96         if (response != NULL) {
97                 /* response is in order of receiving, i.e. msb first */
98                 fprintf(stderr,"  -> RESPONSE: ");
99                 for (i=0;i<response_len;i++) {
100                         fprintf(stderr, "0x%08X ", response[i]);
101                 }
102                 fprintf(stderr,"\n");
103                 fprintf(stderr,"      => ");
104                 switch (response[0]&0xFF000000) {
105                         case AVC1394_RESPONSE_NOT_IMPLEMENTED:
106                                 fprintf(stderr,"Not Implemented      ");
107                         break;
108                         case AVC1394_RESPONSE_ACCEPTED:
109                                 fprintf(stderr,"Accepted             ");
110                         break;
111                         case AVC1394_RESPONSE_REJECTED:
112                                 fprintf(stderr,"Rejected             ");
113                         break;
114                         case AVC1394_RESPONSE_IN_TRANSITION:
115                                 fprintf(stderr,"In Transition        ");
116                         break;
117                         case AVC1394_RESPONSE_IMPLEMENTED:
118                                 fprintf(stderr,"Implemented / Stable ");
119                         break;
120                         case AVC1394_RESPONSE_CHANGED:
121                                 fprintf(stderr,"Changed              ");
122                         break;
123                         case AVC1394_RESPONSE_INTERIM:         
124                                 fprintf(stderr,"Interim              ");
125                         break;
126                         default:
127                                 fprintf(stderr,"Unknown response     ");
128                         break;
129                 }
130                 fprintf(stderr, "subunit_type=%02X  subunit_id=%02X  opcode=%02X",(response[0]>>19)&0x1F,(response[0]>>16)&0x07,(response[0]>>8)&0xFF);
131                 fprintf(stderr,"\n");
132         }
133         return response;
134
135 }
Note: See TracBrowser for help on using the browser.