From: <an...@us...> - 2008-01-07 00:18:45
|
Revision: 1215 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1215&view=rev Author: and-81 Date: 2008-01-06 16:18:43 -0800 (Sun, 06 Jan 2008) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/Common/IrssUtils/IrssLog.cs trunk/plugins/IR Server Suite/Common/MPUtils/MPCommon.cs trunk/plugins/IR Server Suite/IR Server Plugins/Ads Tech PTV-335 Receiver/AdsTechPTV335Receiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/Girder Plugin/Config.cs trunk/plugins/IR Server Suite/IR Server Plugins/Girder Plugin/GirderPluginWrapper.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs Modified: trunk/plugins/IR Server Suite/Common/IrssUtils/IrssLog.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/IrssLog.cs 2008-01-06 15:20:57 UTC (rev 1214) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/IrssLog.cs 2008-01-07 00:18:43 UTC (rev 1215) @@ -13,6 +13,15 @@ public static class IrssLog { + #region Constants + + /// <summary> + /// File extension for log file backups. + /// </summary> + public const string ExtensionBackupFile = ".bak"; + + #endregion Constants + #region Enumerations /// <summary> @@ -81,7 +90,7 @@ { try { - string backup = Path.ChangeExtension(fileName, ".bak"); + string backup = Path.ChangeExtension(fileName, ExtensionBackupFile); if (File.Exists(backup)) File.Delete(backup); @@ -105,8 +114,11 @@ _streamWriter = new StreamWriter(fileName, false); _streamWriter.AutoFlush = true; - string message = DateTime.Now.ToString() + ":\tLog Opened"; + string message = String.Format("{0:yyyy-MM-dd HH:mm:ss.ffffff} - Log Opened", DateTime.Now); _streamWriter.WriteLine(message); +#if TRACE + Trace.WriteLine(message); +#endif } #if TRACE catch (Exception ex) @@ -133,7 +145,7 @@ { if (File.Exists(fileName) && File.GetCreationTime(fileName).Ticks < DateTime.Now.Subtract(TimeSpan.FromDays(7)).Ticks) { - string backup = Path.ChangeExtension(fileName, ".bak"); + string backup = Path.ChangeExtension(fileName, ExtensionBackupFile); if (File.Exists(backup)) File.Delete(backup); @@ -157,8 +169,11 @@ _streamWriter = new StreamWriter(fileName, true); _streamWriter.AutoFlush = true; - string message = DateTime.Now.ToString() + ":\tLog Opened"; + string message = String.Format("{0:yyyy-MM-dd HH:mm:ss.ffffff} - Log Opened", DateTime.Now); _streamWriter.WriteLine(message); +#if TRACE + Trace.WriteLine(message); +#endif } #if TRACE catch (Exception ex) @@ -183,9 +198,12 @@ try { - string message = DateTime.Now.ToString() + ":\tLog Closed"; + string message = String.Format("{0:yyyy-MM-dd HH:mm:ss.ffffff} - Log Closed", DateTime.Now); _streamWriter.WriteLine(message); _streamWriter.WriteLine(); +#if TRACE + Trace.WriteLine(message); +#endif } #if TRACE catch (Exception ex) Modified: trunk/plugins/IR Server Suite/Common/MPUtils/MPCommon.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/MPUtils/MPCommon.cs 2008-01-06 15:20:57 UTC (rev 1214) +++ trunk/plugins/IR Server Suite/Common/MPUtils/MPCommon.cs 2008-01-07 00:18:43 UTC (rev 1215) @@ -55,7 +55,7 @@ dlgNotify.SetHeading(heading); dlgNotify.SetText(text); dlgNotify.TimeOut = timeout; - dlgNotify.DoModal(GUIWindowManager.ActiveWindow); + dlgNotify.DoModal(GUIWindowManager.ActiveWindow); // TODO: Put this on a separate thread to allow caller to continue? } /// <summary> Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Ads Tech PTV-335 Receiver/AdsTechPTV335Receiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Ads Tech PTV-335 Receiver/AdsTechPTV335Receiver.cs 2008-01-06 15:20:57 UTC (rev 1214) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Ads Tech PTV-335 Receiver/AdsTechPTV335Receiver.cs 2008-01-07 00:18:43 UTC (rev 1215) @@ -18,7 +18,7 @@ // int __cdecl ADS335RCP_GetKey(unsigned char &) [DllImport("ADS_335_RCPLIB.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?ADS335RCP_GetKey@@YAHAAE@Z")] - static extern int GetKey(ref byte key); + static extern int GetKey(out byte key); //int __cdecl ADS335RCP_Init(void) [DllImport("ADS_335_RCPLIB.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "?ADS335RCP_Init@@YAHXZ")] @@ -32,7 +32,7 @@ #region Consatnts - const int PacketTimeout = 100; + const int PacketTimeout = 200; #endregion Constants @@ -168,12 +168,12 @@ void ReadThread() { - byte key = 0; + byte key; int retVal; while (_processReadThread) { - retVal = GetKey(ref key); + retVal = GetKey(out key); if (retVal == 0) Thread.Sleep(PacketTimeout); Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Girder Plugin/Config.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Girder Plugin/Config.cs 2008-01-06 15:20:57 UTC (rev 1214) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Girder Plugin/Config.cs 2008-01-07 00:18:43 UTC (rev 1215) @@ -38,24 +38,31 @@ if (String.IsNullOrEmpty(textBoxPluginFile.Text)) return; - GirderPluginWrapper pluginWrapper = new GirderPluginWrapper(textBoxPluginFile.Text); + try + { + GirderPluginWrapper pluginWrapper = new GirderPluginWrapper(textBoxPluginFile.Text); - pluginWrapper.GirOpen(); + pluginWrapper.GirOpen(); - if (!pluginWrapper.CanConfigure) - { - MessageBox.Show(this, "No configuration available", "Girder Plugin Configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); + if (!pluginWrapper.CanConfigure) + { + MessageBox.Show(this, "No configuration available", "Girder Plugin Configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + pluginWrapper.GirCommandGui(); + + MessageBox.Show(this, "Press OK after the Girder plugin configuration is complete", "Girder Plugin Configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + pluginWrapper.GirClose(); + + pluginWrapper.Dispose(); } - else + catch (Exception ex) { - pluginWrapper.GirCommandGui(); - - MessageBox.Show(this, "Press OK after the Girder plugin configuration is complete", "Girder Plugin Configuration", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } - - pluginWrapper.GirClose(); - - pluginWrapper.Dispose(); } private void buttonFind_Click(object sender, EventArgs e) @@ -64,18 +71,25 @@ if (openFileDialog.ShowDialog(this) == DialogResult.OK) { - GirderPluginWrapper pluginWrapper = new GirderPluginWrapper(openFileDialog.FileName); + try + { + GirderPluginWrapper pluginWrapper = new GirderPluginWrapper(openFileDialog.FileName); - pluginWrapper.GirOpen(); + pluginWrapper.GirOpen(); - string message = String.Format("{0}\n{1}\n\nUse this plugin?", pluginWrapper.GirName, pluginWrapper.GirDescription); + string message = String.Format("{0}\n{1}\n\nUse this plugin?", pluginWrapper.GirName, pluginWrapper.GirDescription); - if (MessageBox.Show(this, message, openFileDialog.FileName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - textBoxPluginFile.Text = openFileDialog.FileName; + if (MessageBox.Show(this, message, openFileDialog.FileName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + textBoxPluginFile.Text = openFileDialog.FileName; - pluginWrapper.GirClose(); + pluginWrapper.GirClose(); - pluginWrapper.Dispose(); + pluginWrapper.Dispose(); + } + catch (Exception ex) + { + MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Girder Plugin/GirderPluginWrapper.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Girder Plugin/GirderPluginWrapper.cs 2008-01-06 15:20:57 UTC (rev 1214) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Girder Plugin/GirderPluginWrapper.cs 2008-01-07 00:18:43 UTC (rev 1215) @@ -875,7 +875,7 @@ { _pluginDll = LoadLibrary(girderPluginFile); if (_pluginDll == IntPtr.Zero) - throw new ApplicationException(String.Format("Failed to load girder plugin ({0})", girderPluginFile)); + throw new ApplicationException(String.Format("Failed to load girder plugin dll ({0})", girderPluginFile)); try { Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs 2008-01-06 15:20:57 UTC (rev 1214) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs 2008-01-07 00:18:43 UTC (rev 1215) @@ -85,6 +85,8 @@ #region Constants + const int TimingResolution = 50; // In microseconds. + const double ClockFrequency = 2412460.0; // Vendor ID's for SMK and Topseed devices. @@ -197,21 +199,16 @@ // Initialize device ... WriteSync(StartPacket); - Thread.Sleep(PacketTimeout); - SetTimeout(PacketTimeout); - SetInputPort(InputPort.Receive); - - - // Testing some commands (what do these get back?) that MCE sends, but I don't know what they mean + // Testing some commands that MCE sends, but I don't know what they mean (what do these get back?) WriteSync(new byte[] { 0xFF, 0x0B }); - Thread.Sleep(PacketTimeout); WriteSync(new byte[] { 0x9F, 0x05 }); - Thread.Sleep(PacketTimeout); WriteSync(new byte[] { 0x9F, 0x0D }); - Thread.Sleep(PacketTimeout); + Thread.Sleep(4 * PacketTimeout); + + SetTimeout(PacketTimeout); + SetInputPort(InputPort.Receive); - _notifyWindow.Create(); _notifyWindow.RegisterDeviceArrival(); _notifyWindow.RegisterDeviceRemoval(_eHomeHandle.DangerousGetHandle()); @@ -270,7 +267,6 @@ #endif WriteSync(StopPacket); - Thread.Sleep(PacketTimeout); StopReadThread(); CloseDevice(); @@ -374,30 +370,18 @@ DebugDump(code.TimingData); #endif - byte[] portPacket; - switch (_deviceType) - { - case DeviceType.Microsoft: portPacket = MicrosoftPorts[port]; break; - case DeviceType.SmkTopseed: portPacket = SmkTopseedPorts[port]; break; - default: - throw new ApplicationException("Invalid device type"); - } - // Reset device (hopefully this will stop the blaster from stalling) //WriteSync(ResetPacket); //Thread.Sleep(PacketTimeout); - // Set port - WriteSync(portPacket); + SetOutputPort(port); + SetCarrierFrequency(code.Carrier); - // Set carrier frequency - WriteSync(CarrierPacket(code)); - // Send packet WriteSync(DataPacket(code)); // Force a delay between blasts (hopefully solves back-to-back blast errors) ... - Thread.Sleep(PacketTimeout); + //Thread.Sleep(PacketTimeout); } #endregion Driver overrides @@ -405,35 +389,6 @@ #region Implementation /// <summary> - /// Create a device data packet to set the Carrier frequency. - /// </summary> - /// <param name="code">IrCode to get carrier frequency from.</param> - /// <returns>Raw device data.</returns> - static byte[] CarrierPacket(IrCode code) - { - byte[] carrierPacket = new byte[SetCarrierFreqPacket.Length]; - SetCarrierFreqPacket.CopyTo(carrierPacket, 0); - - if (code.Carrier == IrCode.CarrierFrequencyDCMode) - return carrierPacket; - - int carrier = code.Carrier; - - if (code.Carrier == IrCode.CarrierFrequencyUnknown) - { - carrier = IrCode.CarrierFrequencyDefault; -#if DEBUG - DebugWriteLine("CarrierPacket(): No carrier frequency specificied, using default ({0})", carrier); -#endif - } - - carrierPacket[2] = 0x80; - carrierPacket[3] = (byte)Math.Round(ClockFrequency / carrier); - - return carrierPacket; - } - - /// <summary> /// Converts an IrCode into raw data for the device. /// </summary> /// <param name="code">IrCode to convert.</param> @@ -453,12 +408,12 @@ for (int index = 0; index < code.TimingData.Length; index++) { double time = (double)code.TimingData[index]; - - byte duration = (byte)Math.Abs(Math.Round(time / 50)); + + byte duration = (byte)Math.Abs(Math.Round(time / TimingResolution)); bool pulse = (time > 0); #if DEBUG - DebugWrite("{0}{1}, ", pulse ? '+' : '-', duration * 50); + DebugWrite("{0}{1}, ", pulse ? '+' : '-', duration * TimingResolution); #endif while (duration > 0x7F) @@ -506,7 +461,7 @@ byte[] timeoutPacket = new byte[SetTimeoutPacket.Length]; SetTimeoutPacket.CopyTo(timeoutPacket, 0); - int timeoutSamples = 20 * timeout; // 20 * timeout in milliseconds = timeout as multiple of 50 microseconds + int timeoutSamples = 1000 * timeout / TimingResolution; // Timeout as a multiple of the timing resolution timeoutPacket[2] = (byte)(timeoutSamples >> 8); timeoutPacket[3] = (byte)(timeoutSamples & 0xFF); @@ -515,7 +470,7 @@ } /// <summary> - /// Set the IR receiver input port. + /// Sets the IR receiver input port. /// </summary> /// <param name="port">The input port.</param> void SetInputPort(InputPort port) @@ -529,6 +484,56 @@ } /// <summary> + /// Sets the IR blaster port. + /// </summary> + /// <param name="port">The output port.</param> + void SetOutputPort(int port) + { + byte[] portPacket; + switch (_deviceType) + { + case DeviceType.Microsoft: portPacket = MicrosoftPorts[port]; break; + case DeviceType.SmkTopseed: portPacket = SmkTopseedPorts[port]; break; + default: + throw new ApplicationException("Invalid device type"); + } + + WriteSync(portPacket); + } + + /// <summary> + /// Sets the IR output carrier frequency. + /// </summary> + /// <param name="carrier">The IR carrier frequency.</param> + void SetCarrierFrequency(int carrier) + { + if (carrier == IrCode.CarrierFrequencyUnknown) + { + carrier = IrCode.CarrierFrequencyDefault; +#if DEBUG + DebugWriteLine("SetCarrierFrequency(): No carrier frequency specificied, using default ({0})", carrier); +#endif + } +#if DEBUG + else + { + DebugWriteLine("SetCarrierFrequency({0})", carrier); + } +#endif + + byte[] carrierPacket = new byte[SetCarrierFreqPacket.Length]; + SetCarrierFreqPacket.CopyTo(carrierPacket, 0); + + if (carrier != IrCode.CarrierFrequencyDCMode) + { + carrierPacket[2] = 0x80; + carrierPacket[3] = (byte)Math.Round(ClockFrequency / carrier); + } + + WriteSync(carrierPacket); + } + + /// <summary> /// Start the device read thread. /// </summary> void StartReadThread() @@ -675,7 +680,7 @@ while (true) { - int handle = WaitHandle.WaitAny(waitHandles, PacketTimeout + 50, false); + int handle = WaitHandle.WaitAny(waitHandles, 2 * PacketTimeout, false); if (handle == ErrorWaitTimeout) continue; @@ -703,12 +708,89 @@ int[] timingData = null; if (_decodeCarry != 0 || packetBytes[0] >= 0x81 && packetBytes[0] <= 0x8F) + { timingData = GetTimingDataFromPacket(packetBytes); + } #if DEBUG else { DebugWriteLine("Received data:"); DebugDump(packetBytes); + + int indexOf9F = Array.IndexOf(packetBytes, (byte)0x9F); + while (indexOf9F != -1) + { + + if (packetBytes.Length > indexOf9F + 3 && packetBytes[indexOf9F + 1] == 0x04) // 9F 04 XX XX - IR Sample Period + { + byte b1 = packetBytes[indexOf9F + 2]; + byte b2 = packetBytes[indexOf9F + 3]; + + int irPeriod = ((b1 * 256) + b2); + DebugWriteLine("IR Sample Period: {0}", irPeriod); + } + + if (packetBytes.Length > indexOf9F + 3 && packetBytes[indexOf9F + 1] == 0x0C) // 9F 0C XX XX - Timeout + { + byte b1 = packetBytes[indexOf9F + 2]; + byte b2 = packetBytes[indexOf9F + 3]; + + int timeout = ((b1 * 256) + b2); + DebugWriteLine("IR Timeout Period: {0}", TimingResolution * timeout / 1000); + } + + if (packetBytes.Length > indexOf9F + 2 && packetBytes[indexOf9F + 1] == 0x14) // 9F 14 XX - Port + { + byte b1 = packetBytes[indexOf9F + 2]; + + DebugWriteLine("IR Input Port: {0}", b1); + } + + + if (packetBytes.Length > indexOf9F + 1) + { + indexOf9F = Array.IndexOf(packetBytes, (byte)0x9F, indexOf9F + 1); + } + else + { + break; + } + } + + double firmware = 0.0; + + int indexOfFF = Array.IndexOf(packetBytes, (byte)0xFF); + while (indexOfFF != -1) + { + + if (packetBytes.Length > indexOfFF + 2 && packetBytes[indexOfFF + 1] == 0x0B) // 9F 0B XX - Firmware x.x00 + { + byte b1 = packetBytes[indexOfFF + 2]; + + firmware += (b1 >> 4) + (0.1 * (b1 & 0x0F)); + DebugWriteLine("Firmware: {0}", firmware); + } + + if (packetBytes.Length > indexOfFF + 2 && packetBytes[indexOfFF + 1] == 0x1B) // 9F 1B XX - Firmware 0.0xx + { + byte b1 = packetBytes[indexOfFF + 2]; + + firmware += (0.01 * (b1 >> 4)) + (0.001 * (b1 & 0x0F)); + DebugWriteLine("Firmware: {0}", firmware); + } + + + if (packetBytes.Length > indexOfFF + 1) + { + indexOfFF = Array.IndexOf(packetBytes, (byte)0xFF, indexOfFF + 1); + } + else + { + break; + } + } + + } #endif @@ -861,6 +943,8 @@ if (!getOverlapped && lastError != ErrorSuccess) throw new Win32Exception(lastError); + + Thread.Sleep(PacketTimeout); } catch { @@ -944,7 +1028,7 @@ if ((curByte & 0x7F) != 0x7F) { - timingData.Add(len * 50); + timingData.Add(len * TimingResolution); len = 0; } } @@ -953,7 +1037,7 @@ } if (len != 0) - timingData.Add(len * 50); + timingData.Add(len * TimingResolution); #if DEBUG DebugWriteLine("Received:"); Modified: trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs =================================================================== --- trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs 2008-01-06 15:20:57 UTC (rev 1214) +++ trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MPControlPlugin.cs 2008-01-07 00:18:43 UTC (rev 1215) @@ -865,7 +865,7 @@ string setName = MultiMaps[_multiMappingSet]; if (LogVerbose) - Log.Debug("MPControlPlugin: Multi-Mapping has changed to \"{0}\"", setName); + Log.Info("MPControlPlugin: Multi-Mapping has cycled to \"{0}\"", setName); MPCommon.ShowNotifyDialog("Multi-Mapping", setName, 2); } @@ -885,7 +885,7 @@ for (int index = 0; index < MultiMaps.Length; index++) { - if (MultiMaps[index].Equals(multiMapping, StringComparison.OrdinalIgnoreCase)) + if (MultiMaps[index].Equals(multiMapping, StringComparison.CurrentCultureIgnoreCase)) { _multiMappingSet = index; @@ -896,10 +896,11 @@ Log.Info("MPControlPlugin: Multi-Mapping has changed to \"{0}\"", setName); MPCommon.ShowNotifyDialog("Multi-Mapping", setName, 2); - return; } } + + Log.Warn("MPControlPlugin: Could not find Multi-Mapping \"{0}\"", multiMapping); } /// <summary> @@ -1302,6 +1303,14 @@ string ejectCommand = command.Substring(Common.CmdPrefixEject.Length); Common.ProcessEjectCommand(ejectCommand); } + else if (command.StartsWith(Common.CmdPrefixMultiMap, StringComparison.OrdinalIgnoreCase)) + { + string multiMapping = command.Substring(Common.CmdPrefixMultiMap.Length); + if (_inConfiguration) + MessageBox.Show(multiMapping, "Change multi-mapping", MessageBoxButtons.OK, MessageBoxIcon.Information); + else + ChangeMultiMapping(multiMapping); + } else if (command.StartsWith(Common.CmdPrefixPopup, StringComparison.OrdinalIgnoreCase)) { string[] commands = Common.SplitPopupCommand(command.Substring(Common.CmdPrefixPopup.Length)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |