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

Revision 665, 4.5 kB (checked in by ppalmers, 13 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_ioconfig.h"
26
27 #include <netinet/in.h>
28 #include <iostream>
29
30 using namespace std;
31
32 namespace FireWorks {
33
34 EfcGenericIOConfigCmd::EfcGenericIOConfigCmd(enum eIOConfigRegister r)
35     : EfcCmd()
36     , m_value ( 0 )
37     , m_reg ( r )
38 {
39     m_type=eCT_Get;
40     setRegister(r);
41 }
42
43 bool
44 EfcGenericIOConfigCmd::serialize( Util::IOSSerialize& se )
45 {
46     bool result=true;
47
48     if (m_type == eCT_Get) {
49         // the length should be specified before
50         // the header is serialized
51         m_length=EFC_HEADER_LENGTH_QUADLETS;
52
53         result &= EfcCmd::serialize ( se );
54
55     } else {
56         // the length should be specified before
57         // the header is serialized
58         m_length=EFC_HEADER_LENGTH_QUADLETS+1;
59
60         result &= EfcCmd::serialize ( se );
61
62         result &= se.write(htonl(m_value), "Value" );
63     }
64     return result;
65 }
66
67 bool
68 EfcGenericIOConfigCmd::deserialize( Util::IISDeserialize& de )
69 {
70     bool result=true;
71
72     result &= EfcCmd::deserialize ( de );
73
74     EFC_DESERIALIZE_AND_SWAP(de, &m_value, result);
75
76     return result;
77 }
78
79 bool
80 EfcGenericIOConfigCmd::setType( enum eCmdType type )
81 {
82     m_type=type;
83     if (m_type == eCT_Get) {
84         switch (m_reg) {
85             case eCR_Mirror:
86                 m_command_id=EFC_CMD_IO_CONFIG_GET_MIRROR;
87                 break;
88             case eCR_DigitalMode:
89                 m_command_id=EFC_CMD_IO_CONFIG_GET_DIGITAL_MODE;
90                 break;
91             case eCR_Phantom:
92                 m_command_id=EFC_CMD_IO_CONFIG_GET_PHANTOM;
93                 break;
94             default:
95                 debugError("Invalid IOConfig get command: %d\n", m_reg);
96                 return false;
97         }
98     } else {
99         switch (m_reg) {
100             case eCR_Mirror:
101                 m_command_id=EFC_CMD_IO_CONFIG_SET_MIRROR;
102                 break;
103             case eCR_DigitalMode:
104                 m_command_id=EFC_CMD_IO_CONFIG_SET_DIGITAL_MODE;
105                 break;
106             case eCR_Phantom:
107                 m_command_id=EFC_CMD_IO_CONFIG_SET_PHANTOM;
108                 break;
109             default:
110                 debugError("Invalid IOConfig set command: %d\n", m_reg);
111                 return false;
112         }
113     }
114     return true;
115 }
116 bool
117 EfcGenericIOConfigCmd::setRegister( enum eIOConfigRegister r )
118 {
119     m_reg=r;
120     if (m_type == eCT_Get) {
121         switch (m_reg) {
122             case eCR_Mirror:
123                 m_command_id=EFC_CMD_IO_CONFIG_GET_MIRROR;
124                 break;
125             case eCR_DigitalMode:
126                 m_command_id=EFC_CMD_IO_CONFIG_GET_DIGITAL_MODE;
127                 break;
128             case eCR_Phantom:
129                 m_command_id=EFC_CMD_IO_CONFIG_GET_PHANTOM;
130                 break;
131             default:
132                 debugError("Invalid IOConfig get command: %d\n", m_reg);
133                 return false;
134         }
135     } else {
136         switch (m_reg) {
137             case eCR_Mirror:
138                 m_command_id=EFC_CMD_IO_CONFIG_SET_MIRROR;
139                 break;
140             case eCR_DigitalMode:
141                 m_command_id=EFC_CMD_IO_CONFIG_SET_DIGITAL_MODE;
142                 break;
143             case eCR_Phantom:
144                 m_command_id=EFC_CMD_IO_CONFIG_SET_PHANTOM;
145                 break;
146             default:
147                 debugError("Invalid IOConfig set command: %d\n", m_reg);
148                 return false;
149         }
150     }
151     return true;
152 }
153
154 void
155 EfcGenericIOConfigCmd::showEfcCmd()
156 {
157     EfcCmd::showEfcCmd();
158     debugOutput(DEBUG_LEVEL_NORMAL, "EFC IOCONFIG %s %s:\n",
159                                     (m_type==eCT_Get?"GET":"SET"),
160                                     eIOConfigRegisterToString(m_reg));
161     debugOutput(DEBUG_LEVEL_NORMAL, " Value       : %lu\n", m_value);
162 }
163
164 // --- The specific commands
165
166
167
168 } // namespace FireWorks
Note: See TracBrowser for help on using the browser.