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_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::Cmd::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::Cmd::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 |
return result; |
---|
165 |
} |
---|
166 |
|
---|
167 |
void |
---|
168 |
EfcCmd::showEfcCmd() |
---|
169 |
{ |
---|
170 |
debugOutput(DEBUG_LEVEL_NORMAL, "EFC Length: %d\n", m_length); |
---|
171 |
debugOutput(DEBUG_LEVEL_NORMAL, "EFC Header:\n"); |
---|
172 |
debugOutput(DEBUG_LEVEL_NORMAL, " Version : 0x%08X\n", m_header.version); |
---|
173 |
debugOutput(DEBUG_LEVEL_NORMAL, " Sequence number : 0x%08X\n", m_header.seqnum); |
---|
174 |
debugOutput(DEBUG_LEVEL_NORMAL, " Category : 0x%08X\n", m_header.category); |
---|
175 |
debugOutput(DEBUG_LEVEL_NORMAL, " Command : 0x%08X\n", m_header.command); |
---|
176 |
debugOutput(DEBUG_LEVEL_NORMAL, " Return Value : 0x%08X\n", m_header.retval); |
---|
177 |
} |
---|
178 |
|
---|
179 |
void |
---|
180 |
EfcCmd::setVerboseLevel(int l) |
---|
181 |
{ |
---|
182 |
setDebugLevel(l); |
---|
183 |
} |
---|
184 |
|
---|
185 |
} // namespace FireWorks |
---|