Stephane@161
|
1 |
/*
|
Stephane@161
|
2 |
* This file is part of the libCEC(R) library.
|
Stephane@161
|
3 |
*
|
Stephane@161
|
4 |
* libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
|
Stephane@161
|
5 |
* libCEC(R) is an original work, containing original code.
|
Stephane@161
|
6 |
*
|
Stephane@161
|
7 |
* libCEC(R) is a trademark of Pulse-Eight Limited.
|
Stephane@161
|
8 |
*
|
Stephane@161
|
9 |
* This program is dual-licensed; you can redistribute it and/or modify
|
Stephane@161
|
10 |
* it under the terms of the GNU General Public License as published by
|
Stephane@161
|
11 |
* the Free Software Foundation; either version 2 of the License, or
|
Stephane@161
|
12 |
* (at your option) any later version.
|
Stephane@161
|
13 |
*
|
Stephane@161
|
14 |
* This program is distributed in the hope that it will be useful,
|
Stephane@161
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Stephane@161
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Stephane@161
|
17 |
* GNU General Public License for more details.
|
Stephane@161
|
18 |
*
|
Stephane@161
|
19 |
* You should have received a copy of the GNU General Public License
|
Stephane@161
|
20 |
* along with this program; if not, write to the Free Software
|
Stephane@161
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Stephane@161
|
22 |
*
|
Stephane@161
|
23 |
*
|
Stephane@161
|
24 |
* Alternatively, you can license this library under a commercial license,
|
Stephane@161
|
25 |
* please contact Pulse-Eight Licensing for more information.
|
Stephane@161
|
26 |
*
|
Stephane@161
|
27 |
* For more information contact:
|
Stephane@161
|
28 |
* Pulse-Eight Licensing <license@pulse-eight.com>
|
Stephane@161
|
29 |
* http://www.pulse-eight.com/
|
Stephane@161
|
30 |
* http://www.pulse-eight.net/
|
Stephane@161
|
31 |
*/
|
Stephane@161
|
32 |
|
Stephane@161
|
33 |
using System;
|
Stephane@161
|
34 |
using System.Text;
|
Stephane@161
|
35 |
using CecSharp;
|
Stephane@202
|
36 |
using System.Threading;
|
Stephane@161
|
37 |
|
Stephane@161
|
38 |
namespace Cec
|
Stephane@161
|
39 |
{
|
Stephane@161
|
40 |
class Client : CecCallbackMethods
|
Stephane@161
|
41 |
{
|
StephaneLenclud@167
|
42 |
/// <summary>
|
StephaneLenclud@206
|
43 |
/// Provide direct access to CEC library
|
StephaneLenclud@206
|
44 |
/// </summary>
|
StephaneLenclud@206
|
45 |
public LibCecSharp Lib
|
StephaneLenclud@206
|
46 |
{
|
StephaneLenclud@206
|
47 |
get
|
StephaneLenclud@206
|
48 |
{
|
StephaneLenclud@206
|
49 |
return iLib;
|
StephaneLenclud@206
|
50 |
}
|
StephaneLenclud@206
|
51 |
}
|
StephaneLenclud@206
|
52 |
|
StephaneLenclud@206
|
53 |
/// <summary>
|
StephaneLenclud@206
|
54 |
///
|
StephaneLenclud@206
|
55 |
/// </summary>
|
StephaneLenclud@206
|
56 |
public int LogLevel = (int)CecLogLevel.Notice;
|
StephaneLenclud@206
|
57 |
|
StephaneLenclud@206
|
58 |
/// <summary>
|
StephaneLenclud@206
|
59 |
///
|
StephaneLenclud@206
|
60 |
/// </summary>
|
StephaneLenclud@206
|
61 |
public bool FilterOutPollLogs = true;
|
StephaneLenclud@206
|
62 |
|
StephaneLenclud@206
|
63 |
/// <summary>
|
StephaneLenclud@206
|
64 |
///
|
StephaneLenclud@206
|
65 |
/// </summary>
|
StephaneLenclud@206
|
66 |
private LibCecSharp iLib;
|
StephaneLenclud@206
|
67 |
/// <summary>
|
StephaneLenclud@206
|
68 |
///
|
StephaneLenclud@206
|
69 |
/// </summary>
|
StephaneLenclud@206
|
70 |
private LibCECConfiguration Config;
|
StephaneLenclud@206
|
71 |
|
StephaneLenclud@206
|
72 |
/// <summary>
|
StephaneLenclud@206
|
73 |
///
|
StephaneLenclud@206
|
74 |
/// </summary>
|
StephaneLenclud@206
|
75 |
private bool iConnected;
|
StephaneLenclud@206
|
76 |
|
StephaneLenclud@206
|
77 |
/// <summary>
|
StephaneLenclud@167
|
78 |
///
|
StephaneLenclud@167
|
79 |
/// </summary>
|
StephaneLenclud@167
|
80 |
/// <param name="aDeviceName"></param>
|
StephaneLenclud@167
|
81 |
/// <param name="aHdmiPort"></param>
|
StephaneLenclud@206
|
82 |
public Client(string aDeviceName, byte aHdmiPort, CecDeviceType aDeviceType = CecDeviceType.PlaybackDevice)
|
Stephane@161
|
83 |
{
|
Stephane@161
|
84 |
Config = new LibCECConfiguration();
|
Stephane@203
|
85 |
Config.DeviceTypes.Types[0] = aDeviceType;
|
StephaneLenclud@167
|
86 |
Config.DeviceName = aDeviceName;
|
StephaneLenclud@167
|
87 |
Config.HDMIPort = aHdmiPort;
|
Stephane@161
|
88 |
//Config.ClientVersion = LibCECConfiguration.CurrentVersion;
|
Stephane@161
|
89 |
Config.SetCallbacks(this);
|
Stephane@161
|
90 |
|
StephaneLenclud@167
|
91 |
iLib = new LibCecSharp(Config);
|
StephaneLenclud@167
|
92 |
iLib.InitVideoStandalone();
|
Stephane@161
|
93 |
|
Stephane@161
|
94 |
//Console.WriteLine("CEC Parser created - libCEC version " + Lib.VersionToString(Config.ServerVersion));
|
Stephane@161
|
95 |
Console.WriteLine("CEC Parser created - libCEC version " + Config.ServerVersion);
|
Stephane@161
|
96 |
}
|
Stephane@161
|
97 |
|
Stephane@200
|
98 |
|
StephaneLenclud@201
|
99 |
/// <summary>
|
StephaneLenclud@201
|
100 |
///
|
StephaneLenclud@201
|
101 |
/// </summary>
|
StephaneLenclud@201
|
102 |
/// <param name="alert"></param>
|
StephaneLenclud@201
|
103 |
/// <param name="data"></param>
|
StephaneLenclud@201
|
104 |
/// <returns></returns>
|
Stephane@202
|
105 |
public override int ReceiveAlert(CecAlert alert, CecParameter data)
|
Stephane@200
|
106 |
{
|
StephaneLenclud@201
|
107 |
string log = "CEC alert: " + alert.ToString();
|
StephaneLenclud@201
|
108 |
if (data != null && data.Type == CecParameterType.ParameterTypeString)
|
StephaneLenclud@201
|
109 |
{
|
StephaneLenclud@201
|
110 |
log += " " + data.Data;
|
StephaneLenclud@201
|
111 |
}
|
StephaneLenclud@201
|
112 |
|
StephaneLenclud@201
|
113 |
Console.WriteLine(log);
|
StephaneLenclud@201
|
114 |
|
StephaneLenclud@201
|
115 |
Close();
|
StephaneLenclud@201
|
116 |
//Try reconnect
|
StephaneLenclud@201
|
117 |
Connect(1000);
|
Stephane@200
|
118 |
return 1;
|
Stephane@200
|
119 |
}
|
Stephane@200
|
120 |
|
StephaneLenclud@201
|
121 |
/// <summary>
|
StephaneLenclud@201
|
122 |
///
|
StephaneLenclud@201
|
123 |
/// </summary>
|
StephaneLenclud@201
|
124 |
/// <param name="newVal"></param>
|
StephaneLenclud@201
|
125 |
/// <returns></returns>
|
Stephane@202
|
126 |
public override int ReceiveMenuStateChange(CecMenuState newVal)
|
Stephane@200
|
127 |
{
|
StephaneLenclud@201
|
128 |
Console.WriteLine("CEC menu state changed to: " + iLib.ToString(newVal));
|
Stephane@200
|
129 |
return 1;
|
Stephane@200
|
130 |
}
|
Stephane@200
|
131 |
|
StephaneLenclud@201
|
132 |
/// <summary>
|
StephaneLenclud@201
|
133 |
///
|
StephaneLenclud@201
|
134 |
/// </summary>
|
StephaneLenclud@201
|
135 |
/// <param name="logicalAddress"></param>
|
StephaneLenclud@201
|
136 |
/// <param name="activated"></param>
|
Stephane@202
|
137 |
public override void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
|
Stephane@200
|
138 |
{
|
StephaneLenclud@201
|
139 |
Console.WriteLine("CEC source activated: " + iLib.ToString(logicalAddress) + "/" + activated.ToString() );
|
Stephane@200
|
140 |
return;
|
Stephane@200
|
141 |
}
|
Stephane@200
|
142 |
|
Stephane@161
|
143 |
public override int ReceiveCommand(CecCommand command)
|
Stephane@161
|
144 |
{
|
Stephane@207
|
145 |
Console.WriteLine(string.Format("CEC command '{5}' from {0} to {1} - Ack: {2} Eom: {3} OpcodeSet: {4} Timeout: {6}",
|
StephaneLenclud@201
|
146 |
iLib.ToString(command.Initiator),
|
StephaneLenclud@201
|
147 |
iLib.ToString(command.Destination),
|
StephaneLenclud@201
|
148 |
command.Ack.ToString(),
|
StephaneLenclud@201
|
149 |
command.Eom.ToString(),
|
StephaneLenclud@201
|
150 |
command.OpcodeSet.ToString(),
|
StephaneLenclud@201
|
151 |
iLib.ToString(command.Opcode),
|
StephaneLenclud@201
|
152 |
command.TransmitTimeout.ToString()
|
StephaneLenclud@201
|
153 |
));
|
Stephane@161
|
154 |
return 1;
|
Stephane@161
|
155 |
}
|
Stephane@161
|
156 |
|
Stephane@161
|
157 |
public override int ReceiveKeypress(CecKeypress key)
|
Stephane@161
|
158 |
{
|
StephaneLenclud@201
|
159 |
Console.WriteLine(string.Format("CEC keypress: {0} Duration:{1} Empty: {2}",
|
StephaneLenclud@201
|
160 |
key.Keycode.ToString(), key.Duration.ToString(), key.Empty.ToString()));
|
Stephane@161
|
161 |
return 1;
|
Stephane@161
|
162 |
}
|
Stephane@161
|
163 |
|
Stephane@161
|
164 |
public override int ReceiveLogMessage(CecLogMessage message)
|
Stephane@161
|
165 |
{
|
Stephane@161
|
166 |
if (((int)message.Level & LogLevel) == (int)message.Level)
|
Stephane@161
|
167 |
{
|
Stephane@161
|
168 |
string strLevel = "";
|
Stephane@161
|
169 |
switch (message.Level)
|
Stephane@161
|
170 |
{
|
Stephane@161
|
171 |
case CecLogLevel.Error:
|
Stephane@202
|
172 |
strLevel = "ERROR: ";
|
Stephane@161
|
173 |
break;
|
Stephane@161
|
174 |
case CecLogLevel.Warning:
|
Stephane@161
|
175 |
strLevel = "WARNING: ";
|
Stephane@161
|
176 |
break;
|
Stephane@161
|
177 |
case CecLogLevel.Notice:
|
Stephane@202
|
178 |
strLevel = "NOTICE: ";
|
Stephane@161
|
179 |
break;
|
Stephane@161
|
180 |
case CecLogLevel.Traffic:
|
Stephane@161
|
181 |
strLevel = "TRAFFIC: ";
|
Stephane@161
|
182 |
break;
|
Stephane@161
|
183 |
case CecLogLevel.Debug:
|
Stephane@202
|
184 |
strLevel = "DEBUG: ";
|
StephaneLenclud@206
|
185 |
if (message.Message.IndexOf("POLL") != -1 && FilterOutPollLogs)
|
StephaneLenclud@206
|
186 |
{
|
StephaneLenclud@206
|
187 |
//We have an option to prevent spamming with poll debug logs
|
StephaneLenclud@206
|
188 |
return 1;
|
StephaneLenclud@206
|
189 |
}
|
Stephane@161
|
190 |
break;
|
Stephane@161
|
191 |
default:
|
Stephane@161
|
192 |
break;
|
Stephane@161
|
193 |
}
|
Stephane@202
|
194 |
string strLog = string.Format("{0} {1} {2}", strLevel, message.Time, message.Message);
|
Stephane@161
|
195 |
Console.WriteLine(strLog);
|
StephaneLenclud@201
|
196 |
|
Stephane@161
|
197 |
}
|
Stephane@161
|
198 |
return 1;
|
Stephane@161
|
199 |
}
|
Stephane@161
|
200 |
|
Stephane@161
|
201 |
/// <summary>
|
Stephane@161
|
202 |
///
|
Stephane@161
|
203 |
/// </summary>
|
Stephane@161
|
204 |
/// <param name="timeout"></param>
|
Stephane@161
|
205 |
/// <returns></returns>
|
Stephane@161
|
206 |
public bool Connect(int timeout)
|
Stephane@161
|
207 |
{
|
StephaneLenclud@201
|
208 |
Close();
|
StephaneLenclud@167
|
209 |
CecAdapter[] adapters = iLib.FindAdapters(string.Empty);
|
Stephane@161
|
210 |
if (adapters.Length > 0)
|
StephaneLenclud@201
|
211 |
{
|
StephaneLenclud@201
|
212 |
Connect(adapters[0].ComPort, timeout);
|
StephaneLenclud@201
|
213 |
}
|
Stephane@161
|
214 |
else
|
Stephane@161
|
215 |
{
|
StephaneLenclud@201
|
216 |
Console.WriteLine("CEC did not find any adapters");
|
Stephane@161
|
217 |
}
|
StephaneLenclud@201
|
218 |
|
StephaneLenclud@201
|
219 |
return iConnected;
|
Stephane@161
|
220 |
}
|
Stephane@161
|
221 |
|
Stephane@161
|
222 |
public bool Connect(string port, int timeout)
|
Stephane@161
|
223 |
{
|
StephaneLenclud@201
|
224 |
Close();
|
StephaneLenclud@201
|
225 |
iConnected = iLib.Open(port, timeout);
|
StephaneLenclud@201
|
226 |
if (iConnected)
|
StephaneLenclud@201
|
227 |
{
|
StephaneLenclud@201
|
228 |
Scan();
|
Stephane@202
|
229 |
//TestSendKey();
|
StephaneLenclud@201
|
230 |
}
|
StephaneLenclud@201
|
231 |
return iConnected;
|
Stephane@161
|
232 |
}
|
Stephane@161
|
233 |
|
Stephane@161
|
234 |
public void Close()
|
StephaneLenclud@201
|
235 |
{
|
StephaneLenclud@167
|
236 |
iLib.Close();
|
StephaneLenclud@201
|
237 |
iConnected = false;
|
Stephane@161
|
238 |
}
|
Stephane@161
|
239 |
|
Stephane@202
|
240 |
|
Stephane@202
|
241 |
public void TestSendKey()
|
Stephane@202
|
242 |
{
|
Stephane@202
|
243 |
//SetupMenu: opens option menu
|
Stephane@202
|
244 |
//RootMenu: opens Android home menu
|
Stephane@202
|
245 |
//ContentsMenu: nop
|
Stephane@202
|
246 |
//FavoriteMenu: nop
|
Stephane@202
|
247 |
|
Stephane@202
|
248 |
//Philips TopMenu = 16
|
Stephane@202
|
249 |
//Philips PopupMenu = 17
|
Stephane@202
|
250 |
|
Stephane@202
|
251 |
//bool res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.DisplayInformation, true);
|
Stephane@202
|
252 |
//Thread.Sleep(3000); //Wait few seconds for menu to open
|
Stephane@202
|
253 |
//res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.SetupMenu, true);
|
Stephane@202
|
254 |
|
Stephane@202
|
255 |
for (int i = 0; i < 256; i++)
|
Stephane@202
|
256 |
{
|
Stephane@202
|
257 |
//Thread.Sleep(100);
|
Stephane@202
|
258 |
//res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true);
|
Stephane@202
|
259 |
//Thread.Sleep(100);
|
Stephane@202
|
260 |
switch ((CecUserControlCode)i)
|
Stephane@202
|
261 |
{
|
Stephane@202
|
262 |
case CecUserControlCode.Power:
|
Stephane@202
|
263 |
case CecUserControlCode.PowerOffFunction:
|
Stephane@202
|
264 |
case CecUserControlCode.PowerOnFunction:
|
Stephane@202
|
265 |
case CecUserControlCode.PowerToggleFunction:
|
Stephane@202
|
266 |
case CecUserControlCode.ElectronicProgramGuide:
|
Stephane@202
|
267 |
case CecUserControlCode.InputSelect:
|
Stephane@202
|
268 |
case CecUserControlCode.RootMenu:
|
Stephane@202
|
269 |
|
Stephane@202
|
270 |
break;
|
Stephane@202
|
271 |
|
Stephane@202
|
272 |
default:
|
Stephane@202
|
273 |
Console.WriteLine(i.ToString());
|
Stephane@202
|
274 |
Thread.Sleep(1000);
|
Stephane@202
|
275 |
iLib.SendKeypress(CecLogicalAddress.Tv, (CecUserControlCode)i, true);
|
Stephane@202
|
276 |
|
Stephane@202
|
277 |
break;
|
Stephane@202
|
278 |
|
Stephane@202
|
279 |
}
|
Stephane@202
|
280 |
|
Stephane@202
|
281 |
//
|
Stephane@202
|
282 |
}
|
Stephane@202
|
283 |
|
Stephane@202
|
284 |
|
Stephane@202
|
285 |
for (int i=0;i<7;i++)
|
Stephane@202
|
286 |
{
|
Stephane@202
|
287 |
//Thread.Sleep(100);
|
Stephane@202
|
288 |
//res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true);
|
Stephane@202
|
289 |
//Thread.Sleep(100);
|
Stephane@202
|
290 |
//res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Down, true);
|
Stephane@202
|
291 |
//
|
Stephane@202
|
292 |
}
|
Stephane@202
|
293 |
|
Stephane@202
|
294 |
//res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Select, true);
|
Stephane@202
|
295 |
|
Stephane@202
|
296 |
//res = iLib.SendKeypress(CecLogicalAddress.Tv, CecUserControlCode.Select, true);
|
Stephane@202
|
297 |
//res = iLib.SendKeyRelease(CecLogicalAddress.Tv, true);
|
Stephane@202
|
298 |
}
|
Stephane@202
|
299 |
|
StephaneLenclud@201
|
300 |
/// <summary>
|
StephaneLenclud@201
|
301 |
///
|
StephaneLenclud@201
|
302 |
/// </summary>
|
StephaneLenclud@201
|
303 |
public void Scan()
|
StephaneLenclud@201
|
304 |
{
|
Stephane@207
|
305 |
string scanRes = "";
|
Stephane@207
|
306 |
scanRes += "CEC bus information\n";
|
Stephane@207
|
307 |
scanRes += "===================\n";
|
StephaneLenclud@201
|
308 |
CecLogicalAddresses addresses = Lib.GetActiveDevices();
|
StephaneLenclud@201
|
309 |
for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++)
|
StephaneLenclud@201
|
310 |
{
|
StephaneLenclud@201
|
311 |
CecLogicalAddress address = (CecLogicalAddress) iPtr;
|
StephaneLenclud@201
|
312 |
if (!addresses.IsSet(address))
|
StephaneLenclud@201
|
313 |
continue;
|
StephaneLenclud@201
|
314 |
|
StephaneLenclud@201
|
315 |
CecVendorId iVendorId = Lib.GetDeviceVendorId(address);
|
StephaneLenclud@201
|
316 |
bool bActive = Lib.IsActiveDevice(address);
|
StephaneLenclud@201
|
317 |
ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address);
|
StephaneLenclud@201
|
318 |
string strAddr = Lib.PhysicalAddressToString(iPhysicalAddress);
|
StephaneLenclud@201
|
319 |
CecVersion iCecVersion = Lib.GetDeviceCecVersion(address);
|
StephaneLenclud@201
|
320 |
CecPowerStatus power = Lib.GetDevicePowerStatus(address);
|
StephaneLenclud@201
|
321 |
string osdName = Lib.GetDeviceOSDName(address);
|
StephaneLenclud@201
|
322 |
string lang = Lib.GetDeviceMenuLanguage(address);
|
StephaneLenclud@201
|
323 |
|
Stephane@207
|
324 |
scanRes += "device #" + iPtr + ": " + Lib.ToString(address) + "\n";
|
Stephane@207
|
325 |
scanRes += "address: " + strAddr + "\n";
|
Stephane@207
|
326 |
scanRes += "active source: " + (bActive ? "yes" : "no") + "\n";
|
Stephane@207
|
327 |
scanRes += "vendor: " + Lib.ToString(iVendorId) + "\n";
|
Stephane@207
|
328 |
scanRes += "osd string: " + osdName + "\n";
|
Stephane@207
|
329 |
scanRes += "CEC version: " + Lib.ToString(iCecVersion) + "\n";
|
Stephane@207
|
330 |
scanRes += "power status: " + Lib.ToString(power) + "\n";
|
StephaneLenclud@201
|
331 |
if (!string.IsNullOrEmpty(lang))
|
Stephane@207
|
332 |
scanRes += "language: " + lang + "\n";
|
Stephane@207
|
333 |
scanRes += "===================" + "\n";
|
StephaneLenclud@201
|
334 |
}
|
Stephane@207
|
335 |
|
Stephane@207
|
336 |
Console.Write(scanRes);
|
StephaneLenclud@201
|
337 |
}
|
StephaneLenclud@201
|
338 |
|
StephaneLenclud@201
|
339 |
public void ListAdapters()
|
Stephane@161
|
340 |
{
|
Stephane@161
|
341 |
int iAdapter = 0;
|
StephaneLenclud@167
|
342 |
foreach (CecAdapter adapter in iLib.FindAdapters(string.Empty))
|
Stephane@161
|
343 |
{
|
Stephane@161
|
344 |
Console.WriteLine("Adapter: " + iAdapter++);
|
Stephane@161
|
345 |
Console.WriteLine("Path: " + adapter.Path);
|
Stephane@161
|
346 |
Console.WriteLine("Com port: " + adapter.ComPort);
|
Stephane@161
|
347 |
}
|
Stephane@161
|
348 |
}
|
Stephane@161
|
349 |
|
Stephane@161
|
350 |
void ShowConsoleHelp()
|
Stephane@161
|
351 |
{
|
Stephane@161
|
352 |
Console.WriteLine(
|
Stephane@161
|
353 |
"================================================================================" + Environment.NewLine +
|
Stephane@161
|
354 |
"Available commands:" + Environment.NewLine +
|
Stephane@161
|
355 |
Environment.NewLine +
|
Stephane@161
|
356 |
"[tx] {bytes} transfer bytes over the CEC line." + Environment.NewLine +
|
Stephane@161
|
357 |
"[txn] {bytes} transfer bytes but don't wait for transmission ACK." + Environment.NewLine +
|
Stephane@161
|
358 |
"[on] {address} power on the device with the given logical address." + Environment.NewLine +
|
Stephane@161
|
359 |
"[standby] {address} put the device with the given address in standby mode." + Environment.NewLine +
|
Stephane@161
|
360 |
"[la] {logical_address} change the logical address of the CEC adapter." + Environment.NewLine +
|
Stephane@161
|
361 |
"[pa] {physical_address} change the physical address of the CEC adapter." + Environment.NewLine +
|
Stephane@161
|
362 |
"[osd] {addr} {string} set OSD message on the specified device." + Environment.NewLine +
|
Stephane@161
|
363 |
"[ver] {addr} get the CEC version of the specified device." + Environment.NewLine +
|
Stephane@161
|
364 |
"[ven] {addr} get the vendor ID of the specified device." + Environment.NewLine +
|
Stephane@161
|
365 |
"[lang] {addr} get the menu language of the specified device." + Environment.NewLine +
|
Stephane@161
|
366 |
"[pow] {addr} get the power status of the specified device." + Environment.NewLine +
|
Stephane@161
|
367 |
"[poll] {addr} poll the specified device." + Environment.NewLine +
|
Stephane@161
|
368 |
"[scan] scan the CEC bus and display device info" + Environment.NewLine +
|
Stephane@161
|
369 |
"[mon] {1|0} enable or disable CEC bus monitoring." + Environment.NewLine +
|
Stephane@161
|
370 |
"[log] {1 - 31} change the log level. see cectypes.h for values." + Environment.NewLine +
|
Stephane@161
|
371 |
"[ping] send a ping command to the CEC adapter." + Environment.NewLine +
|
Stephane@161
|
372 |
"[bl] to let the adapter enter the bootloader, to upgrade" + Environment.NewLine +
|
Stephane@161
|
373 |
" the flash rom." + Environment.NewLine +
|
Stephane@161
|
374 |
"[r] reconnect to the CEC adapter." + Environment.NewLine +
|
Stephane@161
|
375 |
"[h] or [help] show this help." + Environment.NewLine +
|
Stephane@161
|
376 |
"[q] or [quit] to quit the CEC test client and switch off all" + Environment.NewLine +
|
Stephane@161
|
377 |
" connected CEC devices." + Environment.NewLine +
|
Stephane@161
|
378 |
"================================================================================");
|
Stephane@161
|
379 |
}
|
Stephane@161
|
380 |
|
Stephane@161
|
381 |
public void MainLoop()
|
Stephane@161
|
382 |
{
|
Stephane@161
|
383 |
bool bContinue = true;
|
Stephane@161
|
384 |
string command;
|
Stephane@161
|
385 |
while (bContinue)
|
Stephane@161
|
386 |
{
|
Stephane@161
|
387 |
Console.WriteLine("waiting for input");
|
Stephane@161
|
388 |
|
Stephane@161
|
389 |
command = Console.ReadLine();
|
Stephane@161
|
390 |
if (command != null && command.Length == 0)
|
Stephane@161
|
391 |
continue;
|
Stephane@161
|
392 |
string[] splitCommand = command.Split(' ');
|
Stephane@161
|
393 |
if (splitCommand[0] == "tx" || splitCommand[0] == "txn")
|
Stephane@161
|
394 |
{
|
Stephane@161
|
395 |
CecCommand bytes = new CecCommand();
|
Stephane@161
|
396 |
for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++)
|
Stephane@161
|
397 |
{
|
Stephane@161
|
398 |
bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber));
|
Stephane@161
|
399 |
}
|
Stephane@161
|
400 |
|
Stephane@161
|
401 |
if (command == "txn")
|
Stephane@161
|
402 |
bytes.TransmitTimeout = 0;
|
Stephane@161
|
403 |
|
StephaneLenclud@167
|
404 |
iLib.Transmit(bytes);
|
Stephane@161
|
405 |
}
|
Stephane@161
|
406 |
else if (splitCommand[0] == "on")
|
Stephane@161
|
407 |
{
|
Stephane@161
|
408 |
if (splitCommand.Length > 1)
|
StephaneLenclud@167
|
409 |
iLib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
|
Stephane@161
|
410 |
else
|
StephaneLenclud@167
|
411 |
iLib.PowerOnDevices(CecLogicalAddress.Broadcast);
|
Stephane@161
|
412 |
}
|
Stephane@161
|
413 |
else if (splitCommand[0] == "standby")
|
Stephane@161
|
414 |
{
|
Stephane@161
|
415 |
if (splitCommand.Length > 1)
|
StephaneLenclud@167
|
416 |
iLib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
|
Stephane@161
|
417 |
else
|
StephaneLenclud@167
|
418 |
iLib.StandbyDevices(CecLogicalAddress.Broadcast);
|
Stephane@161
|
419 |
}
|
Stephane@161
|
420 |
else if (splitCommand[0] == "poll")
|
Stephane@161
|
421 |
{
|
Stephane@161
|
422 |
bool bSent = false;
|
Stephane@161
|
423 |
if (splitCommand.Length > 1)
|
StephaneLenclud@167
|
424 |
bSent = iLib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
|
Stephane@161
|
425 |
else
|
StephaneLenclud@167
|
426 |
bSent = iLib.PollDevice(CecLogicalAddress.Broadcast);
|
Stephane@161
|
427 |
if (bSent)
|
Stephane@161
|
428 |
Console.WriteLine("POLL message sent");
|
Stephane@161
|
429 |
else
|
Stephane@161
|
430 |
Console.WriteLine("POLL message not sent");
|
Stephane@161
|
431 |
}
|
Stephane@161
|
432 |
else if (splitCommand[0] == "la")
|
Stephane@161
|
433 |
{
|
Stephane@161
|
434 |
if (splitCommand.Length > 1)
|
StephaneLenclud@167
|
435 |
iLib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
|
Stephane@161
|
436 |
}
|
Stephane@161
|
437 |
else if (splitCommand[0] == "pa")
|
Stephane@161
|
438 |
{
|
Stephane@161
|
439 |
if (splitCommand.Length > 1)
|
StephaneLenclud@167
|
440 |
iLib.SetPhysicalAddress(ushort.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
|
Stephane@161
|
441 |
}
|
Stephane@161
|
442 |
else if (splitCommand[0] == "osd")
|
Stephane@161
|
443 |
{
|
Stephane@161
|
444 |
if (splitCommand.Length > 2)
|
Stephane@161
|
445 |
{
|
Stephane@161
|
446 |
StringBuilder osdString = new StringBuilder();
|
Stephane@161
|
447 |
for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++)
|
Stephane@161
|
448 |
{
|
Stephane@161
|
449 |
osdString.Append(splitCommand[iPtr]);
|
Stephane@161
|
450 |
if (iPtr != splitCommand.Length - 1)
|
Stephane@161
|
451 |
osdString.Append(" ");
|
Stephane@161
|
452 |
}
|
StephaneLenclud@167
|
453 |
iLib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString());
|
Stephane@161
|
454 |
}
|
Stephane@161
|
455 |
}
|
Stephane@161
|
456 |
else if (splitCommand[0] == "ping")
|
Stephane@161
|
457 |
{
|
StephaneLenclud@167
|
458 |
iLib.PingAdapter();
|
Stephane@161
|
459 |
}
|
Stephane@161
|
460 |
else if (splitCommand[0] == "mon")
|
Stephane@161
|
461 |
{
|
Stephane@161
|
462 |
bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false;
|
StephaneLenclud@167
|
463 |
iLib.SwitchMonitoring(enable);
|
Stephane@161
|
464 |
}
|
Stephane@161
|
465 |
else if (splitCommand[0] == "bl")
|
Stephane@161
|
466 |
{
|
StephaneLenclud@167
|
467 |
iLib.StartBootloader();
|
Stephane@161
|
468 |
}
|
Stephane@161
|
469 |
else if (splitCommand[0] == "lang")
|
Stephane@161
|
470 |
{
|
Stephane@161
|
471 |
if (splitCommand.Length > 1)
|
Stephane@161
|
472 |
{
|
StephaneLenclud@167
|
473 |
string language = iLib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
|
Stephane@161
|
474 |
Console.WriteLine("Menu language: " + language);
|
Stephane@161
|
475 |
}
|
Stephane@161
|
476 |
}
|
Stephane@161
|
477 |
else if (splitCommand[0] == "ven")
|
Stephane@161
|
478 |
{
|
Stephane@161
|
479 |
if (splitCommand.Length > 1)
|
Stephane@161
|
480 |
{
|
StephaneLenclud@167
|
481 |
CecVendorId vendor = iLib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
|
StephaneLenclud@167
|
482 |
Console.WriteLine("Vendor ID: " + iLib.ToString(vendor));
|
Stephane@161
|
483 |
}
|
Stephane@161
|
484 |
}
|
Stephane@161
|
485 |
else if (splitCommand[0] == "ver")
|
Stephane@161
|
486 |
{
|
Stephane@161
|
487 |
if (splitCommand.Length > 1)
|
Stephane@161
|
488 |
{
|
StephaneLenclud@167
|
489 |
CecVersion version = iLib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
|
StephaneLenclud@167
|
490 |
Console.WriteLine("CEC version: " + iLib.ToString(version));
|
Stephane@161
|
491 |
}
|
Stephane@161
|
492 |
}
|
Stephane@161
|
493 |
else if (splitCommand[0] == "pow")
|
Stephane@161
|
494 |
{
|
Stephane@161
|
495 |
if (splitCommand.Length > 1)
|
Stephane@161
|
496 |
{
|
StephaneLenclud@167
|
497 |
CecPowerStatus power = iLib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
|
StephaneLenclud@167
|
498 |
Console.WriteLine("power status: " + iLib.ToString(power));
|
Stephane@161
|
499 |
}
|
Stephane@161
|
500 |
}
|
Stephane@161
|
501 |
else if (splitCommand[0] == "r")
|
Stephane@161
|
502 |
{
|
Stephane@161
|
503 |
Console.WriteLine("closing the connection");
|
StephaneLenclud@167
|
504 |
iLib.Close();
|
Stephane@161
|
505 |
|
Stephane@161
|
506 |
Console.WriteLine("opening a new connection");
|
Stephane@161
|
507 |
Connect(10000);
|
Stephane@161
|
508 |
|
Stephane@161
|
509 |
Console.WriteLine("setting active source");
|
StephaneLenclud@167
|
510 |
iLib.SetActiveSource(CecDeviceType.PlaybackDevice);
|
Stephane@161
|
511 |
}
|
Stephane@161
|
512 |
else if (splitCommand[0] == "scan")
|
Stephane@161
|
513 |
{
|
Stephane@161
|
514 |
StringBuilder output = new StringBuilder();
|
Stephane@161
|
515 |
output.AppendLine("CEC bus information");
|
Stephane@161
|
516 |
output.AppendLine("===================");
|
StephaneLenclud@167
|
517 |
CecLogicalAddresses addresses = iLib.GetActiveDevices();
|
Stephane@161
|
518 |
for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++)
|
Stephane@161
|
519 |
{
|
Stephane@161
|
520 |
CecLogicalAddress address = (CecLogicalAddress)iPtr;
|
Stephane@161
|
521 |
if (!addresses.IsSet(address))
|
Stephane@161
|
522 |
continue;
|
Stephane@161
|
523 |
|
StephaneLenclud@167
|
524 |
CecVendorId iVendorId = iLib.GetDeviceVendorId(address);
|
StephaneLenclud@167
|
525 |
bool bActive = iLib.IsActiveDevice(address);
|
StephaneLenclud@167
|
526 |
ushort iPhysicalAddress = iLib.GetDevicePhysicalAddress(address);
|
Stephane@161
|
527 |
string strAddr = "todo: fixme"; //Lib.PhysicalAddressToString(iPhysicalAddress);
|
StephaneLenclud@167
|
528 |
CecVersion iCecVersion = iLib.GetDeviceCecVersion(address);
|
StephaneLenclud@167
|
529 |
CecPowerStatus power = iLib.GetDevicePowerStatus(address);
|
StephaneLenclud@167
|
530 |
string osdName = iLib.GetDeviceOSDName(address);
|
StephaneLenclud@167
|
531 |
string lang = iLib.GetDeviceMenuLanguage(address);
|
Stephane@161
|
532 |
|
StephaneLenclud@167
|
533 |
output.AppendLine("device #" + iPtr + ": " + iLib.ToString(address));
|
Stephane@161
|
534 |
output.AppendLine("address: " + strAddr);
|
Stephane@161
|
535 |
output.AppendLine("active source: " + (bActive ? "yes" : "no"));
|
StephaneLenclud@167
|
536 |
output.AppendLine("vendor: " + iLib.ToString(iVendorId));
|
Stephane@161
|
537 |
output.AppendLine("osd string: " + osdName);
|
StephaneLenclud@167
|
538 |
output.AppendLine("CEC version: " + iLib.ToString(iCecVersion));
|
StephaneLenclud@167
|
539 |
output.AppendLine("power status: " + iLib.ToString(power));
|
Stephane@161
|
540 |
if (!string.IsNullOrEmpty(lang))
|
Stephane@161
|
541 |
output.AppendLine("language: " + lang);
|
Stephane@161
|
542 |
output.AppendLine("");
|
Stephane@161
|
543 |
}
|
Stephane@161
|
544 |
Console.WriteLine(output.ToString());
|
Stephane@161
|
545 |
}
|
Stephane@161
|
546 |
else if (splitCommand[0] == "h" || splitCommand[0] == "help")
|
Stephane@161
|
547 |
ShowConsoleHelp();
|
Stephane@161
|
548 |
else if (splitCommand[0] == "q" || splitCommand[0] == "quit")
|
Stephane@161
|
549 |
bContinue = false;
|
Stephane@161
|
550 |
else if (splitCommand[0] == "log" && splitCommand.Length > 1)
|
Stephane@161
|
551 |
LogLevel = int.Parse(splitCommand[1]);
|
Stephane@161
|
552 |
}
|
Stephane@161
|
553 |
}
|
Stephane@203
|
554 |
|
Stephane@161
|
555 |
|
Stephane@161
|
556 |
}
|
Stephane@161
|
557 |
}
|