1 |
/* |
---|
2 |
* Copyright (C) 2005-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 program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 3 of the License, or |
---|
12 |
* (at your option) any later version. |
---|
13 |
* |
---|
14 |
* This program is distributed in the hope that it will be useful, |
---|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 |
* GNU General Public License for more details. |
---|
18 |
* |
---|
19 |
* You should have received a copy of the GNU General Public License |
---|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
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::Cmd::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::Cmd::IISDeserialize& de ) |
---|
69 |
{ |
---|
70 |
bool result=true; |
---|
71 |
|
---|
72 |
result &= EfcCmd::deserialize ( de ); |
---|
73 |
|
---|
74 |
if (m_type == eCT_Get) { |
---|
75 |
EFC_DESERIALIZE_AND_SWAP(de, &m_value, result); |
---|
76 |
} |
---|
77 |
|
---|
78 |
return result; |
---|
79 |
} |
---|
80 |
|
---|
81 |
bool |
---|
82 |
EfcGenericIOConfigCmd::setType( enum eCmdType type ) |
---|
83 |
{ |
---|
84 |
m_type=type; |
---|
85 |
if (m_type == eCT_Get) { |
---|
86 |
switch (m_reg) { |
---|
87 |
case eCR_Mirror: |
---|
88 |
m_command_id=EFC_CMD_IO_CONFIG_GET_MIRROR; |
---|
89 |
break; |
---|
90 |
case eCR_DigitalMode: |
---|
91 |
m_command_id=EFC_CMD_IO_CONFIG_GET_DIGITAL_MODE; |
---|
92 |
break; |
---|
93 |
case eCR_Phantom: |
---|
94 |
m_command_id=EFC_CMD_IO_CONFIG_GET_PHANTOM; |
---|
95 |
break; |
---|
96 |
default: |
---|
97 |
debugError("Invalid IOConfig get command: %d\n", m_reg); |
---|
98 |
return false; |
---|
99 |
} |
---|
100 |
} else { |
---|
101 |
switch (m_reg) { |
---|
102 |
case eCR_Mirror: |
---|
103 |
m_command_id=EFC_CMD_IO_CONFIG_SET_MIRROR; |
---|
104 |
break; |
---|
105 |
case eCR_DigitalMode: |
---|
106 |
m_command_id=EFC_CMD_IO_CONFIG_SET_DIGITAL_MODE; |
---|
107 |
break; |
---|
108 |
case eCR_Phantom: |
---|
109 |
m_command_id=EFC_CMD_IO_CONFIG_SET_PHANTOM; |
---|
110 |
break; |
---|
111 |
default: |
---|
112 |
debugError("Invalid IOConfig set command: %d\n", m_reg); |
---|
113 |
return false; |
---|
114 |
} |
---|
115 |
} |
---|
116 |
return true; |
---|
117 |
} |
---|
118 |
bool |
---|
119 |
EfcGenericIOConfigCmd::setRegister( enum eIOConfigRegister r ) |
---|
120 |
{ |
---|
121 |
m_reg=r; |
---|
122 |
if (m_type == eCT_Get) { |
---|
123 |
switch (m_reg) { |
---|
124 |
case eCR_Mirror: |
---|
125 |
m_command_id=EFC_CMD_IO_CONFIG_GET_MIRROR; |
---|
126 |
break; |
---|
127 |
case eCR_DigitalMode: |
---|
128 |
m_command_id=EFC_CMD_IO_CONFIG_GET_DIGITAL_MODE; |
---|
129 |
break; |
---|
130 |
case eCR_Phantom: |
---|
131 |
m_command_id=EFC_CMD_IO_CONFIG_GET_PHANTOM; |
---|
132 |
break; |
---|
133 |
default: |
---|
134 |
debugError("Invalid IOConfig get command: %d\n", m_reg); |
---|
135 |
return false; |
---|
136 |
} |
---|
137 |
} else { |
---|
138 |
switch (m_reg) { |
---|
139 |
case eCR_Mirror: |
---|
140 |
m_command_id=EFC_CMD_IO_CONFIG_SET_MIRROR; |
---|
141 |
break; |
---|
142 |
case eCR_DigitalMode: |
---|
143 |
m_command_id=EFC_CMD_IO_CONFIG_SET_DIGITAL_MODE; |
---|
144 |
break; |
---|
145 |
case eCR_Phantom: |
---|
146 |
m_command_id=EFC_CMD_IO_CONFIG_SET_PHANTOM; |
---|
147 |
break; |
---|
148 |
default: |
---|
149 |
debugError("Invalid IOConfig set command: %d\n", m_reg); |
---|
150 |
return false; |
---|
151 |
} |
---|
152 |
} |
---|
153 |
return true; |
---|
154 |
} |
---|
155 |
|
---|
156 |
void |
---|
157 |
EfcGenericIOConfigCmd::showEfcCmd() |
---|
158 |
{ |
---|
159 |
EfcCmd::showEfcCmd(); |
---|
160 |
debugOutput(DEBUG_LEVEL_NORMAL, "EFC IOCONFIG %s %s:\n", |
---|
161 |
(m_type==eCT_Get?"GET":"SET"), |
---|
162 |
eIOConfigRegisterToString(m_reg)); |
---|
163 |
debugOutput(DEBUG_LEVEL_NORMAL, " Value : %lu\n", m_value); |
---|
164 |
} |
---|
165 |
|
---|
166 |
// --- The specific commands |
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 |
} // namespace FireWorks |
---|