1.1 --- a/Server/CecClient.cs Mon Aug 22 13:20:54 2016 +0200
1.2 +++ b/Server/CecClient.cs Thu Aug 25 00:42:09 2016 +0200
1.3 @@ -34,6 +34,7 @@
1.4 using System.Text;
1.5 using CecSharp;
1.6 using System.Threading;
1.7 +using System.Diagnostics;
1.8
1.9 namespace Cec
1.10 {
1.11 @@ -98,7 +99,7 @@
1.12
1.13 if (Static != null)
1.14 {
1.15 - Console.WriteLine("WARNING: CEC client static already exists");
1.16 + Trace.WriteLine("WARNING: CEC client static already exists");
1.17 }
1.18 else
1.19 {
1.20 @@ -106,8 +107,8 @@
1.21 }
1.22
1.23
1.24 - //Console.WriteLine("CEC Parser created - libCEC version " + Lib.VersionToString(Config.ServerVersion));
1.25 - Console.WriteLine("INFO: CEC Parser created - libCEC version " + Config.ServerVersion);
1.26 + //Trace.WriteLine("CEC Parser created - libCEC version " + Lib.VersionToString(Config.ServerVersion));
1.27 + Trace.WriteLine("INFO: CEC Parser created - libCEC version " + Config.ServerVersion);
1.28 }
1.29
1.30
1.31 @@ -125,7 +126,7 @@
1.32 log += " " + data.Data;
1.33 }
1.34
1.35 - Console.WriteLine(log);
1.36 + Trace.WriteLine(log);
1.37
1.38 Close();
1.39 //Try reconnect
1.40 @@ -140,7 +141,7 @@
1.41 /// <returns></returns>
1.42 public override int ReceiveMenuStateChange(CecMenuState newVal)
1.43 {
1.44 - Console.WriteLine("CEC menu state changed to: " + iLib.ToString(newVal));
1.45 + Trace.WriteLine("CEC menu state changed to: " + iLib.ToString(newVal));
1.46 return 1;
1.47 }
1.48
1.49 @@ -151,13 +152,13 @@
1.50 /// <param name="activated"></param>
1.51 public override void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
1.52 {
1.53 - Console.WriteLine("CEC source activated: " + iLib.ToString(logicalAddress) + "/" + activated.ToString() );
1.54 + Trace.WriteLine("CEC source activated: " + iLib.ToString(logicalAddress) + "/" + activated.ToString() );
1.55 return;
1.56 }
1.57
1.58 public override int ReceiveCommand(CecCommand command)
1.59 {
1.60 - Console.WriteLine(string.Format("CEC command '{5}' from {0} to {1} - Ack: {2} Eom: {3} OpcodeSet: {4} Timeout: {6}",
1.61 + Trace.WriteLine(string.Format("CEC command '{5}' from {0} to {1} - Ack: {2} Eom: {3} OpcodeSet: {4} Timeout: {6}",
1.62 iLib.ToString(command.Initiator),
1.63 iLib.ToString(command.Destination),
1.64 command.Ack.ToString(),
1.65 @@ -171,7 +172,7 @@
1.66
1.67 public override int ReceiveKeypress(CecKeypress key)
1.68 {
1.69 - Console.WriteLine(string.Format("CEC keypress: {0} Duration:{1} Empty: {2}",
1.70 + Trace.WriteLine(string.Format("CEC keypress: {0} Duration:{1} Empty: {2}",
1.71 key.Keycode.ToString(), key.Duration.ToString(), key.Empty.ToString()));
1.72 return 1;
1.73 }
1.74 @@ -207,7 +208,7 @@
1.75 break;
1.76 }
1.77 string strLog = string.Format("{0} {1} {2}", strLevel, message.Time, message.Message);
1.78 - Console.WriteLine(strLog);
1.79 + Trace.WriteLine(strLog);
1.80
1.81 }
1.82 return 1;
1.83 @@ -228,7 +229,7 @@
1.84 }
1.85 else
1.86 {
1.87 - Console.WriteLine("CEC did not find any adapters");
1.88 + Trace.WriteLine("CEC did not find any adapters");
1.89 }
1.90
1.91 return iConnected;
1.92 @@ -280,7 +281,7 @@
1.93 break;
1.94
1.95 default:
1.96 - Console.WriteLine(i.ToString());
1.97 + Trace.WriteLine(i.ToString());
1.98 Thread.Sleep(1000);
1.99 iLib.SendKeypress(CecLogicalAddress.Tv, (CecUserControlCode)i, true);
1.100
1.101 @@ -343,7 +344,7 @@
1.102 scanRes += "===================" + "\n";
1.103 }
1.104
1.105 - Console.Write(scanRes);
1.106 + Trace.Write(scanRes);
1.107 }
1.108
1.109 public void ListAdapters()
1.110 @@ -351,214 +352,9 @@
1.111 int iAdapter = 0;
1.112 foreach (CecAdapter adapter in iLib.FindAdapters(string.Empty))
1.113 {
1.114 - Console.WriteLine("Adapter: " + iAdapter++);
1.115 - Console.WriteLine("Path: " + adapter.Path);
1.116 - Console.WriteLine("Com port: " + adapter.ComPort);
1.117 - }
1.118 - }
1.119 -
1.120 - void ShowConsoleHelp()
1.121 - {
1.122 - Console.WriteLine(
1.123 - "================================================================================" + Environment.NewLine +
1.124 - "Available commands:" + Environment.NewLine +
1.125 - Environment.NewLine +
1.126 - "[tx] {bytes} transfer bytes over the CEC line." + Environment.NewLine +
1.127 - "[txn] {bytes} transfer bytes but don't wait for transmission ACK." + Environment.NewLine +
1.128 - "[on] {address} power on the device with the given logical address." + Environment.NewLine +
1.129 - "[standby] {address} put the device with the given address in standby mode." + Environment.NewLine +
1.130 - "[la] {logical_address} change the logical address of the CEC adapter." + Environment.NewLine +
1.131 - "[pa] {physical_address} change the physical address of the CEC adapter." + Environment.NewLine +
1.132 - "[osd] {addr} {string} set OSD message on the specified device." + Environment.NewLine +
1.133 - "[ver] {addr} get the CEC version of the specified device." + Environment.NewLine +
1.134 - "[ven] {addr} get the vendor ID of the specified device." + Environment.NewLine +
1.135 - "[lang] {addr} get the menu language of the specified device." + Environment.NewLine +
1.136 - "[pow] {addr} get the power status of the specified device." + Environment.NewLine +
1.137 - "[poll] {addr} poll the specified device." + Environment.NewLine +
1.138 - "[scan] scan the CEC bus and display device info" + Environment.NewLine +
1.139 - "[mon] {1|0} enable or disable CEC bus monitoring." + Environment.NewLine +
1.140 - "[log] {1 - 31} change the log level. see cectypes.h for values." + Environment.NewLine +
1.141 - "[ping] send a ping command to the CEC adapter." + Environment.NewLine +
1.142 - "[bl] to let the adapter enter the bootloader, to upgrade" + Environment.NewLine +
1.143 - " the flash rom." + Environment.NewLine +
1.144 - "[r] reconnect to the CEC adapter." + Environment.NewLine +
1.145 - "[h] or [help] show this help." + Environment.NewLine +
1.146 - "[q] or [quit] to quit the CEC test client and switch off all" + Environment.NewLine +
1.147 - " connected CEC devices." + Environment.NewLine +
1.148 - "================================================================================");
1.149 - }
1.150 -
1.151 - public void MainLoop()
1.152 - {
1.153 - bool bContinue = true;
1.154 - string command;
1.155 - while (bContinue)
1.156 - {
1.157 - Console.WriteLine("waiting for input");
1.158 -
1.159 - command = Console.ReadLine();
1.160 - if (command != null && command.Length == 0)
1.161 - continue;
1.162 - string[] splitCommand = command.Split(' ');
1.163 - if (splitCommand[0] == "tx" || splitCommand[0] == "txn")
1.164 - {
1.165 - CecCommand bytes = new CecCommand();
1.166 - for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++)
1.167 - {
1.168 - bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber));
1.169 - }
1.170 -
1.171 - if (command == "txn")
1.172 - bytes.TransmitTimeout = 0;
1.173 -
1.174 - iLib.Transmit(bytes);
1.175 - }
1.176 - else if (splitCommand[0] == "on")
1.177 - {
1.178 - if (splitCommand.Length > 1)
1.179 - iLib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
1.180 - else
1.181 - iLib.PowerOnDevices(CecLogicalAddress.Broadcast);
1.182 - }
1.183 - else if (splitCommand[0] == "standby")
1.184 - {
1.185 - if (splitCommand.Length > 1)
1.186 - iLib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
1.187 - else
1.188 - iLib.StandbyDevices(CecLogicalAddress.Broadcast);
1.189 - }
1.190 - else if (splitCommand[0] == "poll")
1.191 - {
1.192 - bool bSent = false;
1.193 - if (splitCommand.Length > 1)
1.194 - bSent = iLib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
1.195 - else
1.196 - bSent = iLib.PollDevice(CecLogicalAddress.Broadcast);
1.197 - if (bSent)
1.198 - Console.WriteLine("POLL message sent");
1.199 - else
1.200 - Console.WriteLine("POLL message not sent");
1.201 - }
1.202 - else if (splitCommand[0] == "la")
1.203 - {
1.204 - if (splitCommand.Length > 1)
1.205 - iLib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
1.206 - }
1.207 - else if (splitCommand[0] == "pa")
1.208 - {
1.209 - if (splitCommand.Length > 1)
1.210 - iLib.SetPhysicalAddress(ushort.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
1.211 - }
1.212 - else if (splitCommand[0] == "osd")
1.213 - {
1.214 - if (splitCommand.Length > 2)
1.215 - {
1.216 - StringBuilder osdString = new StringBuilder();
1.217 - for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++)
1.218 - {
1.219 - osdString.Append(splitCommand[iPtr]);
1.220 - if (iPtr != splitCommand.Length - 1)
1.221 - osdString.Append(" ");
1.222 - }
1.223 - iLib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString());
1.224 - }
1.225 - }
1.226 - else if (splitCommand[0] == "ping")
1.227 - {
1.228 - iLib.PingAdapter();
1.229 - }
1.230 - else if (splitCommand[0] == "mon")
1.231 - {
1.232 - bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false;
1.233 - iLib.SwitchMonitoring(enable);
1.234 - }
1.235 - else if (splitCommand[0] == "bl")
1.236 - {
1.237 - iLib.StartBootloader();
1.238 - }
1.239 - else if (splitCommand[0] == "lang")
1.240 - {
1.241 - if (splitCommand.Length > 1)
1.242 - {
1.243 - string language = iLib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
1.244 - Console.WriteLine("Menu language: " + language);
1.245 - }
1.246 - }
1.247 - else if (splitCommand[0] == "ven")
1.248 - {
1.249 - if (splitCommand.Length > 1)
1.250 - {
1.251 - CecVendorId vendor = iLib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
1.252 - Console.WriteLine("Vendor ID: " + iLib.ToString(vendor));
1.253 - }
1.254 - }
1.255 - else if (splitCommand[0] == "ver")
1.256 - {
1.257 - if (splitCommand.Length > 1)
1.258 - {
1.259 - CecVersion version = iLib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
1.260 - Console.WriteLine("CEC version: " + iLib.ToString(version));
1.261 - }
1.262 - }
1.263 - else if (splitCommand[0] == "pow")
1.264 - {
1.265 - if (splitCommand.Length > 1)
1.266 - {
1.267 - CecPowerStatus power = iLib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber));
1.268 - Console.WriteLine("power status: " + iLib.ToString(power));
1.269 - }
1.270 - }
1.271 - else if (splitCommand[0] == "r")
1.272 - {
1.273 - Console.WriteLine("closing the connection");
1.274 - iLib.Close();
1.275 -
1.276 - Console.WriteLine("opening a new connection");
1.277 - Open(10000);
1.278 -
1.279 - Console.WriteLine("setting active source");
1.280 - iLib.SetActiveSource(CecDeviceType.PlaybackDevice);
1.281 - }
1.282 - else if (splitCommand[0] == "scan")
1.283 - {
1.284 - StringBuilder output = new StringBuilder();
1.285 - output.AppendLine("CEC bus information");
1.286 - output.AppendLine("===================");
1.287 - CecLogicalAddresses addresses = iLib.GetActiveDevices();
1.288 - for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++)
1.289 - {
1.290 - CecLogicalAddress address = (CecLogicalAddress)iPtr;
1.291 - if (!addresses.IsSet(address))
1.292 - continue;
1.293 -
1.294 - CecVendorId iVendorId = iLib.GetDeviceVendorId(address);
1.295 - bool bActive = iLib.IsActiveDevice(address);
1.296 - ushort iPhysicalAddress = iLib.GetDevicePhysicalAddress(address);
1.297 - string strAddr = "todo: fixme"; //Lib.PhysicalAddressToString(iPhysicalAddress);
1.298 - CecVersion iCecVersion = iLib.GetDeviceCecVersion(address);
1.299 - CecPowerStatus power = iLib.GetDevicePowerStatus(address);
1.300 - string osdName = iLib.GetDeviceOSDName(address);
1.301 - string lang = iLib.GetDeviceMenuLanguage(address);
1.302 -
1.303 - output.AppendLine("device #" + iPtr + ": " + iLib.ToString(address));
1.304 - output.AppendLine("address: " + strAddr);
1.305 - output.AppendLine("active source: " + (bActive ? "yes" : "no"));
1.306 - output.AppendLine("vendor: " + iLib.ToString(iVendorId));
1.307 - output.AppendLine("osd string: " + osdName);
1.308 - output.AppendLine("CEC version: " + iLib.ToString(iCecVersion));
1.309 - output.AppendLine("power status: " + iLib.ToString(power));
1.310 - if (!string.IsNullOrEmpty(lang))
1.311 - output.AppendLine("language: " + lang);
1.312 - output.AppendLine("");
1.313 - }
1.314 - Console.WriteLine(output.ToString());
1.315 - }
1.316 - else if (splitCommand[0] == "h" || splitCommand[0] == "help")
1.317 - ShowConsoleHelp();
1.318 - else if (splitCommand[0] == "q" || splitCommand[0] == "quit")
1.319 - bContinue = false;
1.320 - else if (splitCommand[0] == "log" && splitCommand.Length > 1)
1.321 - LogLevel = int.Parse(splitCommand[1]);
1.322 + Trace.WriteLine("Adapter: " + iAdapter++);
1.323 + Trace.WriteLine("Path: " + adapter.Path);
1.324 + Trace.WriteLine("Com port: " + adapter.ComPort);
1.325 }
1.326 }
1.327