root/trunk/libffado/src/fireworks/efc/efc_cmd.cpp

Revision 665, 8.3 kB (checked in by ppalmers, 15 years ago)

Implement support for Phantom power on the fireworks devices

Line 
1 /*
2  * Copyright (C) 2007 by Pieter Palmers
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 "efc_cmd.h"
25 #include "efc_cmds_hardware.h"
26
27 #include <netinet/in.h>
28 #include <iostream>
29
30 using namespace std;
31
32 namespace FireWorks {
33
34 IMPL_DEBUG_MODULE( EfcCmd, EfcCmd, DEBUG_LEVEL_NORMAL );
35
36 // static int to keep track of the sequence index
37 uint32_t EfcCmd::m_seqnum = 1;
38
39 // some generic string generation functions
40 const char *eMixerTargetToString(const enum eMixerTarget target) {
41     switch (target) {
42         case eMT_PhysicalOutputMix:
43             return "PhysicalOutputMix";
44         case eMT_PhysicalInputMix:
45             return "PhysicalInputMix";
46         case eMT_PlaybackMix:
47             return "PlaybackMix";
48         case eMT_RecordMix:
49             return "RecordMix";
50         default:
51             return "invalid";
52     }
53 }
54
55 const char *eMixerCommandToString(const enum eMixerCommand command) {
56     switch (command) {
57         case eMC_Gain:
58             return "Gain";
59         case eMC_Solo:
60             return "Solo";
61         case eMC_Mute:
62             return "Mute";
63         case eMC_Pan:
64             return "Pan";
65         case eMC_Nominal:
66             return "Nominal";
67         default:
68             return "invalid";
69     }
70 }
71
72 const char *eIOConfigRegisterToString(const enum eIOConfigRegister reg) {
73     switch (reg) {
74         case eCR_Mirror:
75             return "Mirror";
76         case eCR_DigitalMode:
77             return "DigitalMode";
78         case eCR_Phantom:
79             return "Phantom";
80         default:
81             return "invalid";
82     }
83 }
84
85 // the real deal
86
87 EfcCmd::EfcCmd(uint32_t cat, uint32_t cmd)
88     : m_length ( 0 )
89     , m_category_id ( cat )
90     , m_command_id ( cmd )
91 {
92     memset(&m_header,0,sizeof(m_header));
93 }
94
95 EfcCmd::EfcCmd()
96     : m_length ( 0 )
97     , m_category_id ( EFC_CAT_INVALID )
98     , m_command_id ( EFC_CMD_INVALID )
99 {
100     memset(&m_header,0,sizeof(m_header));
101 }
102
103 EfcCmd::~EfcCmd()
104 {
105 }
106
107 bool
108 EfcCmd::serialize( Util::IOSSerialize& se )
109 {
110     bool result=true;
111    
112     result &= se.write(htonl(m_length), "EFC length");
113    
114     unsigned int i=0;
115    
116     // assign the category and the command
117     m_header.category=m_category_id;
118     m_header.command=m_command_id;
119    
120     // set the sequence number
121     m_header.seqnum=m_seqnum++;
122    
123     // serialize the header
124     quadlet_t *header_as_quadlets=(quadlet_t *)&m_header;
125     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header version"); i++;
126     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header seqnum"); i++;
127     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header category"); i++;
128     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header command"); i++;
129     result &= se.write(htonl(*(header_as_quadlets+i)), "EFC header return value"); i++;
130    
131     return result;
132 }
133
134 bool
135 EfcCmd::deserialize( Util::IISDeserialize& de )
136 {
137     bool result=true;
138    
139     result &= de.read(&m_length);
140     m_length=ntohl(m_length);
141    
142     // read the EFC header
143     quadlet_t *header_as_quadlets=(quadlet_t *)&m_header;
144     for (unsigned int i=0; i<sizeof(m_header)/4; i++) {
145         result &= de.read((header_as_quadlets+i));
146         *(header_as_quadlets+i)=ntohl(*(header_as_quadlets+i));
147     }
148
149     // check the EFC version
150     if(m_header.version > 1) {
151         debugError("Unsupported EFC version: %d\n", m_header.version);
152         return false;
153     }
154
155     // check whether the category and command of the response are valid
156     if (m_header.category != m_category_id) {
157         debugError("Invalid category response: %d != %d", m_header.category, m_category_id);
158         return false;
159     }
160     if (m_header.command != m_command_id) {
161         debugError("Invalid command response: %d != %d", m_header.command, m_command_id);
162         return false;
163     }
164
165 //     // delete a previous command/response if present
166 //     if(m_response) {
167 //         delete m_response;
168 //         m_response=NULL;
169 //     }
170 //
171 //     // now figure out what command it is
172 //     switch (m_header.category) {
173 //         case EFC_CAT_HARDWARE_INFO:
174 //             switch(m_header.command) {
175 //                 case EFC_CMD_HW_HWINFO_GET_CAPS:
176 //                     m_response=new EfcHardwareInfoCmd();
177 //                     if (!m_response) {
178 //                         debugError("Could not allocate response\n");
179 //                         return false;
180 //                     }
181 //                     result &= m_command->deserialize( de );
182 //                 case EFC_CMD_HW_GET_POLLED:
183 //                     debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command);
184 //                     return false;
185 //                 case EFC_CMD_HW_SET_EFR_ADDRESS:
186 //                     debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command);
187 //                     return false;
188 //                 case EFC_CMD_HW_READ_SESSION_BLOCK:
189 //                     debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command);
190 //                     return false;
191 //                 case EFC_CMD_HW_GET_DEBUG_INFO:
192 //                     debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command);
193 //                     return false;
194 //                 case EFC_CMD_HW_SET_DEBUG_TRACKING:
195 //                     debugError("Unsupported EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command);
196 //                     return false;
197 //                 default:
198 //                     debugError("Invalid EFC command %d for EFC_CAT_HARDWARE_INFO\n", m_header.command);
199 //                     return false;
200 //             }
201 //             break;
202 //         case EFC_CAT_FLASH:
203 //             debugError("Unsupported EFC category: %d\n", m_header.category);
204 //             return false;
205 //         case EFC_CAT_TRANSPORT:
206 //             debugError("Unsupported EFC category: %d\n", m_header.category);
207 //             return false;
208 //         case EFC_CAT_HARDWARE_CONTROL:
209 //             debugError("Unsupported EFC category: %d\n", m_header.category);
210 //             return false;
211 //         case EFC_CAT_PHYSICAL_OUTPUT_MIX:
212 //             debugError("Unsupported EFC category: %d\n", m_header.category);
213 //             return false;
214 //         case EFC_CAT_PHYSICAL_INPUT_MIX:
215 //             debugError("Unsupported EFC category: %d\n", m_header.category);
216 //             return false;
217 //         case EFC_CAT_PLAYBACK_MIX:
218 //             debugError("Unsupported EFC category: %d\n", m_header.category);
219 //             return false;
220 //         case EFC_CAT_RECORD_MIX:
221 //             debugError("Unsupported EFC category: %d\n", m_header.category);
222 //             return false;
223 //         case EFC_CAT_MONITOR_MIX:
224 //             debugError("Unsupported EFC category: %d\n", m_header.category);
225 //             return false;
226 //         case EFC_CAT_IO_CONFIG:
227 //             debugError("Unsupported EFC category: %d\n", m_header.category);
228 //             return false;
229 //         default:
230 //             debugError("Invalid EFC category: %d\n", m_header.category);
231 //             return false;
232 //     }
233
234     return result;
235 }
236
237 void
238 EfcCmd::showEfcCmd()
239 {
240     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Length: %d\n", m_length);
241     debugOutput(DEBUG_LEVEL_NORMAL, "EFC Header:\n");
242     debugOutput(DEBUG_LEVEL_NORMAL, " Version         : 0x%08X\n", m_header.version);
243     debugOutput(DEBUG_LEVEL_NORMAL, " Sequence number : 0x%08X\n", m_header.seqnum);
244     debugOutput(DEBUG_LEVEL_NORMAL, " Category        : 0x%08X\n", m_header.category);
245     debugOutput(DEBUG_LEVEL_NORMAL, " Command         : 0x%08X\n", m_header.command);
246     debugOutput(DEBUG_LEVEL_NORMAL, " Return Value    : 0x%08X\n", m_header.retval);
247 }
248
249 } // namespace FireWorks
Note: See TracBrowser for help on using the browser.