Commit | Line | Data |
---|---|---|
e9de9629 LOK |
1 | /* |
2 | * This file is part of the libCEC(R) library. | |
3 | * | |
4 | * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. | |
5 | * libCEC(R) is an original work, containing original code. | |
6 | * | |
7 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
8 | * | |
9 | * This program is dual-licensed; 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 2 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, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 | * | |
23 | * | |
24 | * Alternatively, you can license this library under a commercial license, | |
25 | * please contact Pulse-Eight Licensing for more information. | |
26 | * | |
27 | * For more information contact: | |
28 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
29 | * http://www.pulse-eight.com/ | |
30 | * http://www.pulse-eight.net/ | |
31 | */ | |
32 | ||
33 | #include "CECCommandHandler.h" | |
387b6f6f LOK |
34 | #include "../CECBusDevice.h" |
35 | #include "../CECProcessor.h" | |
e9de9629 LOK |
36 | |
37 | using namespace CEC; | |
38 | ||
39 | CCECCommandHandler::CCECCommandHandler(CCECBusDevice *busDevice) | |
40 | { | |
41 | m_busDevice = busDevice; | |
42 | } | |
43 | ||
44 | bool CCECCommandHandler::HandleCommand(const cec_command &command) | |
45 | { | |
46 | bool bHandled(true); | |
47 | ||
48 | if (command.destination == m_busDevice->GetMyLogicalAddress()) | |
49 | { | |
50 | switch(command.opcode) | |
51 | { | |
52 | case CEC_OPCODE_GIVE_PHYSICAL_ADDRESS: | |
53 | HandleGivePhysicalAddress(command); | |
54 | break; | |
55 | case CEC_OPCODE_GIVE_OSD_NAME: | |
56 | HandleGiveOSDName(command); | |
57 | break; | |
58 | case CEC_OPCODE_GIVE_DEVICE_VENDOR_ID: | |
59 | HandleGiveDeviceVendorId(command); | |
60 | break; | |
61 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
62 | HandleDeviceVendorId(command); | |
63 | break; | |
64 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
65 | HandleDeviceVendorCommandWithId(command); | |
66 | break; | |
67 | case CEC_OPCODE_GIVE_DECK_STATUS: | |
68 | HandleGiveDeckStatus(command); | |
69 | break; | |
70 | case CEC_OPCODE_MENU_REQUEST: | |
71 | HandleMenuRequest(command); | |
72 | break; | |
73 | case CEC_OPCODE_GIVE_DEVICE_POWER_STATUS: | |
74 | HandleGiveDevicePowerStatus(command); | |
75 | break; | |
76 | case CEC_OPCODE_GET_CEC_VERSION: | |
77 | HandleGetCecVersion(command); | |
78 | break; | |
79 | case CEC_OPCODE_USER_CONTROL_PRESSED: | |
80 | HandleUserControlPressed(command); | |
81 | break; | |
82 | case CEC_OPCODE_USER_CONTROL_RELEASE: | |
83 | HandleUserControlRelease(command); | |
84 | break; | |
85 | default: | |
86 | UnhandledCommand(command); | |
87 | bHandled = false; | |
88 | break; | |
89 | } | |
90 | } | |
91 | else if (command.destination == CECDEVICE_BROADCAST) | |
92 | { | |
93 | CStdString strLog; | |
94 | switch (command.opcode) | |
95 | { | |
96 | case CEC_OPCODE_REQUEST_ACTIVE_SOURCE: | |
97 | HandleRequestActiveSource(command); | |
98 | break; | |
99 | case CEC_OPCODE_SET_STREAM_PATH: | |
100 | HandleSetStreamPath(command); | |
101 | break; | |
102 | case CEC_OPCODE_ROUTING_CHANGE: | |
103 | HandleRoutingChange(command); | |
104 | break; | |
105 | case CEC_OPCODE_DEVICE_VENDOR_ID: | |
106 | HandleDeviceVendorId(command); | |
107 | break; | |
108 | case CEC_OPCODE_VENDOR_COMMAND_WITH_ID: | |
109 | HandleDeviceVendorCommandWithId(command); | |
110 | break; | |
111 | default: | |
112 | UnhandledCommand(command); | |
113 | bHandled = false; | |
114 | break; | |
115 | } | |
116 | } | |
117 | else | |
118 | { | |
119 | CStdString strLog; | |
120 | strLog.Format("ignoring frame: destination: %u != %u", command.destination, (uint8_t)m_busDevice->GetMyLogicalAddress()); | |
121 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
122 | bHandled = false; | |
123 | } | |
124 | ||
125 | return bHandled; | |
126 | } | |
127 | ||
128 | bool CCECCommandHandler::HandleDeviceVendorCommandWithId(const cec_command &command) | |
129 | { | |
130 | m_busDevice->GetProcessor()->ParseVendorId(command.initiator, command.parameters); | |
131 | return true; | |
132 | } | |
133 | ||
134 | bool CCECCommandHandler::HandleDeviceVendorId(const cec_command &command) | |
135 | { | |
136 | m_busDevice->GetProcessor()->ParseVendorId(command.initiator, command.parameters); | |
137 | return true; | |
138 | } | |
139 | ||
140 | bool CCECCommandHandler::HandleGetCecVersion(const cec_command &command) | |
141 | { | |
142 | m_busDevice->GetProcessor()->ReportCECVersion(command.initiator); | |
143 | return true; | |
144 | } | |
145 | ||
146 | bool CCECCommandHandler::HandleGiveDeckStatus(const cec_command &command) | |
147 | { | |
148 | // need to support opcodes play and deck control before doing anything with this | |
149 | m_busDevice->GetProcessor()->TransmitAbort(command.initiator, CEC_OPCODE_GIVE_DECK_STATUS); | |
150 | return true; | |
151 | } | |
152 | ||
153 | bool CCECCommandHandler::HandleGiveDevicePowerStatus(const cec_command &command) | |
154 | { | |
155 | m_busDevice->GetProcessor()->ReportPowerState(command.initiator); | |
156 | return true; | |
157 | } | |
158 | ||
159 | bool CCECCommandHandler::HandleGiveDeviceVendorId(const cec_command &command) | |
160 | { | |
161 | m_busDevice->GetProcessor()->ReportVendorID(command.initiator); | |
162 | return true; | |
163 | } | |
164 | ||
165 | bool CCECCommandHandler::HandleGiveOSDName(const cec_command &command) | |
166 | { | |
167 | m_busDevice->GetProcessor()->ReportOSDName(command.initiator); | |
168 | return true; | |
169 | } | |
170 | ||
171 | bool CCECCommandHandler::HandleGivePhysicalAddress(const cec_command &command) | |
172 | { | |
173 | m_busDevice->GetProcessor()->ReportPhysicalAddress(); | |
174 | return true; | |
175 | } | |
176 | ||
177 | bool CCECCommandHandler::HandleMenuRequest(const cec_command &command) | |
178 | { | |
179 | if (command.parameters[0] == CEC_MENU_REQUEST_TYPE_QUERY) | |
180 | m_busDevice->GetProcessor()->ReportMenuState(command.initiator); | |
181 | return true; | |
182 | } | |
183 | ||
184 | bool CCECCommandHandler::HandleRequestActiveSource(const cec_command &command) | |
185 | { | |
186 | CStdString strLog; | |
187 | strLog.Format(">> %i requests active source", (uint8_t) command.initiator); | |
188 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
189 | m_busDevice->GetProcessor()->BroadcastActiveSource(); | |
190 | return true; | |
191 | } | |
192 | ||
193 | bool CCECCommandHandler::HandleRoutingChange(const cec_command &command) | |
194 | { | |
195 | if (command.parameters.size == 4) | |
196 | { | |
197 | uint16_t iOldAddress = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
198 | uint16_t iNewAddress = ((uint16_t)command.parameters[2] << 8) | ((uint16_t)command.parameters[3]); | |
199 | CStdString strLog; | |
200 | strLog.Format(">> %i changed physical address from %04x to %04x", command.initiator, iOldAddress, iNewAddress); | |
201 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
202 | ||
203 | m_busDevice->GetProcessor()->AddCommand(command); | |
204 | } | |
205 | return true; | |
206 | } | |
207 | ||
208 | bool CCECCommandHandler::HandleSetStreamPath(const cec_command &command) | |
209 | { | |
210 | if (command.parameters.size >= 2) | |
211 | { | |
212 | int streamaddr = ((uint16_t)command.parameters[0] << 8) | ((uint16_t)command.parameters[1]); | |
213 | CStdString strLog; | |
214 | strLog.Format(">> %i requests stream path from physical address %04x", command.initiator, streamaddr); | |
215 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
216 | if (streamaddr == m_busDevice->GetMyPhysicalAddress()) | |
217 | m_busDevice->GetProcessor()->BroadcastActiveSource(); | |
218 | } | |
219 | return true; | |
220 | } | |
221 | ||
222 | bool CCECCommandHandler::HandleUserControlPressed(const cec_command &command) | |
223 | { | |
224 | if (command.parameters.size > 0) | |
225 | { | |
226 | m_busDevice->GetProcessor()->AddKey(); | |
227 | ||
228 | if (command.parameters[0] <= CEC_USER_CONTROL_CODE_MAX) | |
229 | { | |
230 | CStdString strLog; | |
231 | strLog.Format("key pressed: %1x", command.parameters[0]); | |
232 | m_busDevice->AddLog(CEC_LOG_DEBUG, strLog.c_str()); | |
233 | ||
234 | m_busDevice->GetProcessor()->SetCurrentButton((cec_user_control_code) command.parameters[0]); | |
235 | } | |
236 | } | |
237 | return true; | |
238 | } | |
239 | ||
240 | bool CCECCommandHandler::HandleUserControlRelease(const cec_command &command) | |
241 | { | |
242 | m_busDevice->GetProcessor()->AddKey(); | |
243 | return true; | |
244 | } | |
245 | ||
246 | void CCECCommandHandler::UnhandledCommand(const cec_command &command) | |
247 | { | |
248 | m_busDevice->GetProcessor()->AddCommand(command);; | |
249 | } |