From: <an...@us...> - 2007-09-02 17:14:47
|
Revision: 883 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=883&view=rev Author: and-81 Date: 2007-09-02 10:14:46 -0700 (Sun, 02 Sep 2007) Log Message: ----------- Removed Paths: ------------- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IRDecoder.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrDecoder.cs Deleted: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IRDecoder.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IRDecoder.cs 2007-09-02 17:09:43 UTC (rev 882) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IRDecoder.cs 2007-09-02 17:14:46 UTC (rev 883) @@ -1,1413 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace MicrosoftMceTransceiver -{ - - #region Enumerations - - /// <summary> - /// Protocol of IR Code. - /// </summary> - public enum IRProtocol - { - None, - //ITT, - JVC, - NEC, - //NRC17, - RC5, - RC6, - RCA, - //RCMM, - RECS80, - //Sharp, - SIRC, - //XSAT, - } - - #endregion Enumerations - - #region Delegates - - public delegate void RemoteCallback(IRProtocol codeType, uint keyCode); - public delegate void KeyboardCallback(uint keyCode, uint modifiers); - public delegate void MouseCallback(int deltaX, int deltaY, bool rightButton, bool leftButton); - - #endregion Delegates - - /// <summary> - /// Used for decoding received IR codes. - /// </summary> - public static class IRDecoder - { - - #region Constants - - public const uint PulseBit = 0x01000000; - public const uint PulseMask = 0x00FFFFFF; - - //const UInt16 ToggleBitMce = 0x8000; - const UInt16 ToggleMaskMce = 0x7FFF; - const UInt16 CustomerMce = 0x800F; - - const UInt16 ToggleMaskRC5 = 0xF7FF; - const UInt16 ToggleMaskRC5X = 0xFFFF; - - const uint PrefixRC6 = 0x000FC950; - const uint PrefixRC6A = 0x000FCA90; - - const uint MceMouse = 1; - const uint MceKeyboard = 4; - - #endregion Constants - - #region Members - - //static bool _processITT = true; - static bool _processJVC = true; - static bool _processNEC = true; - //static bool _processNRC17 = true; - static bool _processRC5 = true; - static bool _processRC6 = true; - static bool _processRCA = true; - //static bool _processRCMM = true; - static bool _processRECS80 = true; - //static bool _processSharp = true; - static bool _processSIRC = true; - //static bool _processXSAT = true; - - static bool _processMCE = true; - - #endregion Members - - #region Properties - - public static bool ProcessJVC - { - get { return _processJVC; } - set { _processJVC = value; } - } - public static bool ProcessNEC - { - get { return _processNEC; } - set { _processNEC = value; } - } - public static bool ProcessRC5 - { - get { return _processRC5; } - set { _processRC5 = value; } - } - public static bool ProcessRC6 - { - get { return _processRC6; } - set { _processRC6 = value; } - } - public static bool ProcessRCA - { - get { return _processRCA; } - set { _processRCA = value; } - } - public static bool ProcessRECS80 - { - get { return _processRECS80; } - set { _processRECS80 = value; } - } - public static bool ProcessSIRC - { - get { return _processSIRC; } - set { _processSIRC = value; } - } - - public static bool ProcessMCE - { - get { return _processMCE; } - set { _processMCE = value; } - } - - #endregion Properties - - #region Detection Data - - static RemoteDetectionData JVC_Data = null; - static RemoteDetectionData NEC_Data = null; - static RemoteDetectionData RC5_Data = null; - static RemoteDetectionData RC6_Data = null; - static RemoteDetectionData RCA_Data = null; - static RemoteDetectionData RECS80_Data = null; - static RemoteDetectionData SIRC_Data = null; - - static MceDetectionData MCE_Data = null; - - #endregion Detection Data - - #region Methods - - /// <summary> - /// Decode timing data to discover IR Protocol and button code. - /// </summary> - /// <param name="timingData">Input timing data.</param> - /// <param name="remoteCallback">Method to call when Remote button decoded.</param> - /// <param name="keyboardCallback">Method to call when Keyboard event decoded.</param> - /// <param name="mouseCallback">Method to call when Mouse event decoded.</param> - public static void DecodeIR(uint[] timingData, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) - { -// if (_processITT) DetectITT(timingData, remoteCallback); - if (_processJVC) DetectJVC(timingData, remoteCallback); - if (_processNEC) DetectNEC(timingData, remoteCallback); -// if (_processNRC17) DetectNRC17(timingData, remoteCallback); - if (_processRC5) DetectRC5(timingData, remoteCallback); - if (_processRC6) DetectRC6(timingData, remoteCallback); - if (_processRCA) DetectRCA(timingData, remoteCallback); -// if (_processRCMM) DetectRCMM(timingData, remoteCallback); - if (_processRECS80) DetectRECS80(timingData, remoteCallback); -// if (_processSharp) DetectSharp(timingData, remoteCallback); - if (_processSIRC) DetectSIRC(timingData, remoteCallback); // 15 Bit -// if (_processXSAT) DetectXSAT(timingData, remoteCallback); - - if (_processMCE) - DetectMCE(timingData, keyboardCallback, mouseCallback); - } - - static void DetectJVC(uint[] timingData, RemoteCallback remoteCallback) - { - if (JVC_Data == null || timingData == null) - JVC_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - uint duration = timingData[i] & PulseMask; - bool pulse = ((timingData[i] & PulseBit) != 0); - bool ignored = true; - - switch (JVC_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("JVC HeaderPulse"); - - if (pulse && duration >= 8200 && duration <= 8600) - { - JVC_Data.State = RemoteDetectionState.HeaderSpace; - ignored = false; - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("JVC HeaderSpace"); - - if (!pulse && duration >= 4000 && duration <= 4400) - { - JVC_Data.State = RemoteDetectionState.Data; - JVC_Data.HalfBit = 0; - JVC_Data.Bit = 0; - JVC_Data.Code = 0; - ignored = false; - } - break; - #endregion HeaderSpace - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("JVC Data"); - - if (pulse && duration >= 350 && duration <= 750) - { - JVC_Data.HalfBit = 1; - ignored = false; - } - else if (!pulse && duration >= 250 && duration <= 650 && JVC_Data.HalfBit == 1) - { - JVC_Data.Code <<= 1; - JVC_Data.Bit++; - JVC_Data.HalfBit = 0; - ignored = false; - } - else if (!pulse && duration >= 1450 && duration <= 1850 && JVC_Data.HalfBit == 1) - { - JVC_Data.Code <<= 1; - JVC_Data.Code |= 1; - JVC_Data.Bit++; - JVC_Data.HalfBit = 0; - ignored = false; - } - else - { - //Console.WriteLine("JVC Error"); - } - - if (JVC_Data.Bit == 16) - { - remoteCallback(IRProtocol.JVC, JVC_Data.Code); - JVC_Data.State = RemoteDetectionState.Leading; - } - break; - #endregion Data - - #region Leading - case RemoteDetectionState.Leading: - //Console.WriteLine("JVC Leading"); - - if (pulse && duration >= 350 && duration <= 750) - { - JVC_Data = new RemoteDetectionData(); - JVC_Data.State = RemoteDetectionState.Data; - ignored = false; - } - break; - #endregion Leading - - } - - if (ignored && (JVC_Data.State != RemoteDetectionState.HeaderPulse)) - JVC_Data = new RemoteDetectionData(); - } - } - static void DetectNEC(uint[] timingData, RemoteCallback remoteCallback) - { - if (NEC_Data == null || timingData == null) - NEC_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - uint duration = timingData[i] & PulseMask; - bool pulse = ((timingData[i] & PulseBit) != 0); - bool ignored = true; - - switch (NEC_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("NEC HeaderPulse"); - - if (pulse && duration >= 8800 && duration <= 9200) - { - NEC_Data.State = RemoteDetectionState.HeaderSpace; - ignored = false; - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("NEC HeaderSpace"); - - if (!pulse && duration >= 4300 && duration <= 4700) - { - NEC_Data.State = RemoteDetectionState.Data; - NEC_Data.HalfBit = 0; - NEC_Data.Bit = 0; - NEC_Data.Code = 0; - ignored = false; - } - else if (!pulse && duration >= 2050 && duration <= 2450) // For Repeats - { - remoteCallback(IRProtocol.NEC, NEC_Data.Code); - NEC_Data.State = RemoteDetectionState.HeaderPulse; - ignored = false; - } - - break; - #endregion HeaderSpace - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("NEC Data"); - - if (pulse && duration >= 350 && duration <= 750) - { - NEC_Data.HalfBit = 1; - ignored = false; - } - else if (!pulse && duration >= 250 && duration <= 650 && NEC_Data.HalfBit == 1) - { - NEC_Data.Code <<= 1; - NEC_Data.Bit++; - NEC_Data.HalfBit = 0; - ignored = false; - } - else if (!pulse && duration >= 1550 && duration <= 1950 && NEC_Data.HalfBit == 1) - { - NEC_Data.Code <<= 1; - NEC_Data.Code |= 1; - NEC_Data.Bit++; - NEC_Data.HalfBit = 0; - ignored = false; - } - else - { - //Console.WriteLine("NEC Error"); - } - - if (NEC_Data.Bit == 32) - { - remoteCallback(IRProtocol.NEC, NEC_Data.Code); - NEC_Data.State = RemoteDetectionState.HeaderPulse; - } - break; - #endregion Data - - } - - if (ignored && (NEC_Data.State != RemoteDetectionState.HeaderPulse)) - NEC_Data = new RemoteDetectionData(); - } - } - static void DetectRC5(uint[] timingData, RemoteCallback remoteCallback) - { - if (RC5_Data == null || timingData == null) - RC5_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - uint duration = timingData[i] & PulseMask; - bool pulse = ((timingData[i] & PulseBit) != 0); - bool ignored = true; - - switch (RC5_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("RC5 HeaderPulse"); - - if (pulse) - { - if ((duration >= 750) && (duration <= 1100)) - { - RC5_Data.State = RemoteDetectionState.HeaderSpace; - RC5_Data.Bit = 13; - RC5_Data.Code = (uint)1 << RC5_Data.Bit; - ignored = false; - } - else if ((duration >= 1500) && (duration <= 2000)) - { - RC5_Data.State = RemoteDetectionState.Data; - RC5_Data.Bit = 13; - RC5_Data.Code = (uint)1 << RC5_Data.Bit; - RC5_Data.HalfBit = 0; - ignored = false; - } - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("RC5 HeaderSpace"); - - if (!pulse && (duration >= 750) && (duration <= 1000)) - { - RC5_Data.State = RemoteDetectionState.Data; - RC5_Data.HalfBit = 0; - ignored = false; - } - break; - #endregion HeaderSpace - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("RC5 Data"); - - if (RC5_Data.HalfBit == 0) - { - if (pulse) - { - if (((duration >= 750) && (duration <= 1100)) || ((duration >= 1500) && (duration <= 2000))) - { - RC5_Data.HalfBit = (byte)((duration >= 1500) ? 0 : 1); - RC5_Data.Bit--; - RC5_Data.Code |= (uint)1 << RC5_Data.Bit; - ignored = false; - - if ((RC5_Data.Bit == 0) || ((RC5_Data.Bit == 1) && (duration >= 1500))) - RC5_Data.State = RemoteDetectionState.KeyCode; - } - else - { - //Console.WriteLine("RC5 Error {0} on bit {1}", duration, bit); - } - } - else - { - if (((duration >= 750) && (duration <= 1100)) || ((duration >= 1500) && (duration <= 2000))) - { - RC5_Data.HalfBit = (byte)((duration >= 1500) ? 0 : 1); - RC5_Data.Bit--; - ignored = false; - - if (RC5_Data.Bit == 0) - RC5_Data.State = RemoteDetectionState.KeyCode; - } - else if ((RC5_Data.Bit == 7) && (((duration >= 4300) && (duration <= 4700)) || ((duration >= 5200) && (duration <= 5600)))) - { - ignored = false; - RC5_Data.HalfBit = (byte)((duration >= 5200) ? 0 : 1); - RC5_Data.Code <<= 6; - RC5_Data.Bit += 5; - } - else - { - //Console.WriteLine("RC5 Space Error {0} on bit {1}", duration, bit); - } - } - break; - } - - if ((duration >= 750) && (duration <= 1100)) - { - RC5_Data.HalfBit = 0; - ignored = false; - - if ((RC5_Data.Bit == 1) && pulse) - RC5_Data.State = RemoteDetectionState.KeyCode; - } - else if ((RC5_Data.Bit == 7) && (((duration >= 3400) && (duration <= 3800)) || ((duration >= 4300) && (duration <= 4700)))) - { - RC5_Data.HalfBit = (byte)((duration >= 4300) ? 0 : 1); - RC5_Data.Code <<= 6; - RC5_Data.Bit += 6; - ignored = false; - } - else - { - //Console.WriteLine("RC5 Duration Error {0} on bit {1}", duration, bit); - } - break; - #endregion Data - - #region Leading - case RemoteDetectionState.Leading: - //Console.WriteLine("RC5 Leading"); - - if (pulse) - break; - - if (duration > 10000) - { - RC5_Data.State = RemoteDetectionState.HeaderPulse; - ignored = false; - } - break; - #endregion Leading - - } - - if (RC5_Data.State == RemoteDetectionState.KeyCode) - { - if (RC5_Data.Code > 0xFFFF) - RC5_Data.Code &= ToggleMaskRC5X; - else - RC5_Data.Code &= ToggleMaskRC5; - - remoteCallback(IRProtocol.RC5, RC5_Data.Code); - - RC5_Data.State = RemoteDetectionState.HeaderPulse; - } - - if (ignored && (RC5_Data.State != RemoteDetectionState.Leading) && (RC5_Data.State != RemoteDetectionState.HeaderPulse)) - RC5_Data.State = RemoteDetectionState.HeaderPulse; - } - - } - static void DetectRC6(uint[] timingData, RemoteCallback remoteCallback) - { - if (RC6_Data == null || timingData == null) - RC6_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - uint duration = timingData[i] & PulseMask; - bool pulse = ((timingData[i] & PulseBit) != 0); - bool ignored = true; - - switch (RC6_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("RC6 HeaderPulse"); - - if (pulse && (duration >= 2600) && (duration <= 3300)) - { - RC6_Data.State = RemoteDetectionState.HeaderSpace; - RC6_Data.Header = 0x000FC000; - RC6_Data.Bit = 14; - RC6_Data.HalfBit = 0; - RC6_Data.Code = 0; - RC6_Data.LongPulse = false; - RC6_Data.LongSpace = false; - ignored = false; - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("RC6 HeaderSpace"); - - if (!pulse && (duration >= 750) && (duration <= 1000)) - { - RC6_Data.State = RemoteDetectionState.PreData; - RC6_Data.Bit -= 2; - ignored = false; - } - break; - #endregion HeaderSpace - - #region PreData - case RemoteDetectionState.PreData: - //Console.WriteLine("RC6 PreData"); - - if (pulse) - { - if ((duration >= 350) && (duration <= 600)) - { - ignored = false; - if (RC6_Data.Bit != 0) RC6_Data.Header |= (uint)(1 << --RC6_Data.Bit); - } - else if ((duration >= 750) && (duration <= 1000)) - { - ignored = false; - if (RC6_Data.Bit != 0) RC6_Data.Header |= (uint)(1 << --RC6_Data.Bit); - if (RC6_Data.Bit != 0) RC6_Data.Header |= (uint)(1 << --RC6_Data.Bit); - } - else if ((duration >= 1200) && (duration <= 1600)) - { - ignored = false; - if (RC6_Data.Bit != 0) RC6_Data.Header |= (uint)(1 << --RC6_Data.Bit); - if (RC6_Data.Bit != 0) RC6_Data.Header |= (uint)(1 << --RC6_Data.Bit); - if (RC6_Data.Bit != 0) RC6_Data.Header |= (uint)(1 << --RC6_Data.Bit); - else - { - RC6_Data.HalfBit = 1; - RC6_Data.LongPulse = true; - } - } - else - { - //Console.WriteLine(string.Format("RC6 Error Bit {0} {1} {2}", bit, pulse ? "Pulse" : "Space", duration)); - } - } - else - { - if ((duration >= 300) && (duration <= 600)) - { - RC6_Data.Bit--; - ignored = false; - } - else if ((duration >= 750) && (duration <= 1000)) - { - ignored = false; - if (RC6_Data.Bit > 2) - RC6_Data.Bit -= 2; - else - RC6_Data.Bit = 0; - } - else if ((duration >= 1200) && (duration <= 1600)) - { - ignored = false; - if (RC6_Data.Bit >= 3) - { - RC6_Data.Bit -= 3; - } - else - { - RC6_Data.HalfBit = 1; - RC6_Data.LongPulse = true; - RC6_Data.Bit = 0; - } - } - else - { - //Console.WriteLine(string.Format("RC6 Error Bit {0} {1} {2}", bit, pulse ? "Pulse" : "Space", duration)); - } - } - - if ((ignored == false) && (RC6_Data.Bit == 0)) - { - if ((RC6_Data.Header & 0xFFFFFFF0) == PrefixRC6) - { - RC6_Data.Bit = 16; - } - else if ((RC6_Data.Header & 0xFFFFFFF0) == PrefixRC6A) - { - RC6_Data.Bit = 32; - } - else - { - ignored = true; - break; - } - - RC6_Data.State = RemoteDetectionState.Data; - } - break; - #endregion PreData - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("RC6 Data"); - - if ((RC6_Data.HalfBit % 2) == 0) - { - if (pulse && (duration >= 350) && (duration <= 600)) - { - ignored = false; - RC6_Data.LongPulse = true; - RC6_Data.HalfBit++; - - if (RC6_Data.Bit == 1) - RC6_Data.State = RemoteDetectionState.KeyCode; - } - else if (!pulse && (duration >= 300) && (duration <= 600)) - { - ignored = false; - RC6_Data.LongSpace = true; - RC6_Data.HalfBit++; - } - else - { - //Console.WriteLine(string.Format("RC6 Error Halfbit0 {0} {1}", pulse ? "Pulse" : "Space", duration)); - } - break; - } - - if (RC6_Data.LongPulse) - { - RC6_Data.LongPulse = false; - if (pulse) - { - //Console.WriteLine(string.Format("RC6 Error Pulse after LongPulse {0} {1}", pulse ? "Pulse" : "Space", duration)); - break; - } - - if ((duration >= 750) && (duration <= 1000)) - { - RC6_Data.Bit--; - RC6_Data.LongSpace = true; - RC6_Data.HalfBit += 2; - ignored = false; - } - else if ((duration >= 300) && (duration <= 600)) - { - RC6_Data.Bit--; - RC6_Data.HalfBit++; - ignored = false; - } - else - { - //Console.WriteLine(string.Format("RC6 Error Pulse LongPulse {0} {1}", pulse ? "Pulse" : "Space", duration)); - } - } - else if (RC6_Data.LongSpace) - { - RC6_Data.LongSpace = false; - - if (!pulse) - { - //Console.WriteLine(string.Format("RC6 Error Pulse after LongPulse {0} {1}", pulse ? "Pulse" : "Space", duration)); - break; - } - - if (RC6_Data.Bit == 32) - RC6_Data.Bit = 24; - - if ((duration >= 750) && (duration <= 1000)) - { - RC6_Data.Bit--; - RC6_Data.Code |= (uint)1 << RC6_Data.Bit; - RC6_Data.LongPulse = true; - RC6_Data.HalfBit += 2; - ignored = false; - - if (RC6_Data.Bit == 1) - RC6_Data.State = RemoteDetectionState.KeyCode; - } - else if ((duration >= 350) && (duration <= 600)) - { - RC6_Data.Bit--; - RC6_Data.Code |= (uint)1 << RC6_Data.Bit; - RC6_Data.HalfBit++; - ignored = false; - - if (RC6_Data.Bit == 0) - RC6_Data.State = RemoteDetectionState.KeyCode; - } - else - { - //Console.WriteLine(string.Format("RC6 Error LongPulse {0} {1}", pulse ? "Pulse" : "Space", duration)); - } - } - break; - #endregion Data - - } - - if (RC6_Data.State == RemoteDetectionState.KeyCode) - { - if ((~RC6_Data.Code >> 16) == CustomerMce) - RC6_Data.Code &= ToggleMaskMce; - - remoteCallback(IRProtocol.RC6, RC6_Data.Code); - - RC6_Data.State = RemoteDetectionState.HeaderPulse; - } - - if (ignored && (RC6_Data.State != RemoteDetectionState.HeaderPulse)) - RC6_Data.State = RemoteDetectionState.HeaderPulse; - } - - } - static void DetectRCA(uint[] timingData, RemoteCallback remoteCallback) - { - if (RCA_Data == null || timingData == null) - RCA_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - uint duration = timingData[i] & PulseMask; - bool pulse = ((timingData[i] & PulseBit) != 0); - bool ignored = true; - - switch (RCA_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("RCA HeaderPulse"); - - if (pulse && duration >= 3800 && duration <= 4200) - { - RCA_Data.State = RemoteDetectionState.HeaderSpace; - ignored = false; - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("RCA HeaderSpace"); - - if (!pulse && duration >= 3800 && duration <= 4200) - { - RCA_Data.State = RemoteDetectionState.Data; - RCA_Data.HalfBit = 0; - RCA_Data.Bit = 0; - RCA_Data.Code = 0; - ignored = false; - } - break; - #endregion HeaderSpace - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("RCA Data"); - - if (pulse && duration >= 300 && duration <= 700) - { - RCA_Data.HalfBit = 1; - ignored = false; - } - else if (!pulse && duration >= 800 && duration <= 1250 && RCA_Data.HalfBit == 1) - { - RCA_Data.Code <<= 1; - RCA_Data.Bit++; - RCA_Data.HalfBit = 0; - ignored = false; - } - else if (!pulse && duration >= 1800 && duration <= 2200 && RCA_Data.HalfBit == 1) - { - RCA_Data.Code <<= 1; - RCA_Data.Code |= 1; - RCA_Data.Bit++; - RCA_Data.HalfBit = 0; - ignored = false; - } - else - { - //Console.WriteLine("RCA Error"); - } - - if (RCA_Data.Bit == 12) - { - remoteCallback(IRProtocol.RCA, RCA_Data.Code); - RCA_Data.State = RemoteDetectionState.HeaderPulse; - } - break; - #endregion Data - - } - - if (ignored && (RCA_Data.State != RemoteDetectionState.HeaderPulse)) - RCA_Data.State = RemoteDetectionState.HeaderPulse; - } - } - static void DetectRECS80(uint[] timingData, RemoteCallback remoteCallback) - { - if (RECS80_Data == null || timingData == null) - RECS80_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - uint duration = timingData[i] & PulseMask; - bool pulse = ((timingData[i] & PulseBit) != 0); - bool ignored = true; - - switch (RECS80_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("RECS80 HeaderPulse"); - - if (pulse && (duration >= 3300) && (duration <= 4100)) - { - RECS80_Data.State = RemoteDetectionState.HeaderSpace; - ignored = false; - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("RECS80 HeaderSpace"); - - if (!pulse && (duration >= 1400) && (duration <= 1800)) - { - RECS80_Data.State = RemoteDetectionState.Data; - RECS80_Data.HalfBit = 0; - RECS80_Data.Bit = 48; - RECS80_Data.Header = 0; - RECS80_Data.Code = 0; - ignored = false; - } - break; - #endregion HeaderSpace - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("RECS80 Data"); - - if ((RECS80_Data.HalfBit % 2) == 0) - { - if (!pulse) - break; - - if ((duration >= 350) && (duration <= 600)) - { - RECS80_Data.HalfBit = 1; - RECS80_Data.Bit--; - ignored = false; - } - break; - } - else - { - if (pulse) - break; - - if ((duration >= 400) && (duration <= 750)) - { - RECS80_Data.HalfBit = 0; - ignored = false; - } - else if ((duration >= 1100) && (duration <= 1500)) - { - RECS80_Data.HalfBit = 0; - if (RECS80_Data.Bit > 15) - RECS80_Data.Header |= (uint)(1 << (RECS80_Data.Bit - 16)); - else - RECS80_Data.Code |= (uint)(1 << RECS80_Data.Bit); - ignored = false; - } - else - { - break; - } - - if (RECS80_Data.Bit == 0) - { - RECS80_Data.Code &= 0x0000FFFF; - remoteCallback(IRProtocol.RECS80, RECS80_Data.Code); - - RECS80_Data.State = RemoteDetectionState.HeaderPulse; - } - } - break; - #endregion Data - - } - - if (ignored && (RECS80_Data.State != RemoteDetectionState.HeaderPulse)) - RECS80_Data.State = RemoteDetectionState.HeaderPulse; - } - } - static void DetectSIRC(uint[] timingData, RemoteCallback remoteCallback) - { - if (SIRC_Data == null || timingData == null) - SIRC_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - uint duration = timingData[i] & PulseMask; - bool pulse = ((timingData[i] & PulseBit) != 0); - bool ignored = true; - - switch (SIRC_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("SIRC HeaderPulse"); - - if (pulse && duration >= 2200 && duration <= 2600) - { - SIRC_Data.State = RemoteDetectionState.HeaderSpace; - ignored = false; - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("SIRC HeaderSpace"); - - if (!pulse && duration >= 400 && duration <= 800) - { - SIRC_Data.State = RemoteDetectionState.Data; - SIRC_Data.Bit = 0; - SIRC_Data.Code = 0; - ignored = false; - } - break; - #endregion HeaderSpace - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("SIRC Data"); - - if (pulse && duration >= 400 && duration <= 800) - { - SIRC_Data.Code <<= 1; - SIRC_Data.Bit++; - ignored = false; - } - else if (pulse && duration >= 1000 && duration <= 1400) - { - SIRC_Data.Code <<= 1; - SIRC_Data.Code |= 1; - SIRC_Data.Bit++; - ignored = false; - } - else if (!pulse && duration >= 400 && duration <= 800) - { - ignored = false; - } - else - { - //Console.WriteLine("SIRC Error"); - } - - if (SIRC_Data.Bit == 15) - { - remoteCallback(IRProtocol.SIRC, SIRC_Data.Code); - SIRC_Data.State = RemoteDetectionState.HeaderPulse; - } - break; - #endregion Data - - } - - if (ignored && (SIRC_Data.State != RemoteDetectionState.HeaderPulse)) - SIRC_Data.State = RemoteDetectionState.HeaderPulse; - } - - } - - //static uint biggest = 0; - //static uint smallest = 1000000; - - static void DetectMCE(uint[] timingData, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) - { - // Mouse: 0 0001 xxxxxxxxxxxxxxxxxxxxxxxxxxxxx - // Keyboard: 0 0100 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - - const int HalfBit_None = 0; - const int HalfBit_Zero = 1; - const int HalfBit_One = 2; - - if (MCE_Data == null || timingData == null) - MCE_Data = new MceDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - uint duration = timingData[i] & PulseMask; - bool pulse = ((timingData[i] & PulseBit) != 0); - - #region Working data ... - if (MCE_Data.State != MceKeyboardDetectState.Header) - { - switch (MCE_Data.HalfBit) - { - case HalfBit_None: - if (duration >= 100 && duration <= 450) - MCE_Data.HalfBit = (pulse ? 2 : 1); - else if (duration >= 500 && duration <= 800) - { - //Console.WriteLine("Bad bit sequence double {0}", pulse); - MCE_Data.HalfBit = (pulse ? 2 : 1); - //MCE_Data = new MceDetectionData(); - return; - } - else - { - // Over Length duration (Treat as a Zero bit) - //Console.WriteLine("Bad duration {0}", duration); - MCE_Data.Working <<= 1; - MCE_Data.Bit--; - } - break; - - case HalfBit_Zero: - if (duration >= 100 && duration <= 450) - { - if (pulse) - { - MCE_Data.Working <<= 1; - MCE_Data.Bit--; - MCE_Data.HalfBit = 0; - } - else - { - //Console.WriteLine("Bad bit sequence 00"); - MCE_Data = new MceDetectionData(); - //return; - } - } - else if (duration >= 500 && duration <= 800) - { - if (pulse) - { - MCE_Data.Working <<= 1; - MCE_Data.Bit--; - MCE_Data.HalfBit = 2; - } - else - { - //Console.WriteLine("Bad bit sequence 00 0"); - MCE_Data = new MceDetectionData(); - //return; - } - } - else - { - //Console.WriteLine("Bad duration {0}", duration); - if (MCE_Data.Bit == 1) - { - MCE_Data.Working <<= 1; - //MceKeyboard_Data.Working |= 1; - MCE_Data.Bit--; - MCE_Data.HalfBit = 0; - //i--; - } - else - MCE_Data = new MceDetectionData(); - //return; - } - break; - - case HalfBit_One: - if (duration >= 100 && duration <= 450) - { - if (!pulse) - { - MCE_Data.Working <<= 1; - MCE_Data.Working |= 1; - MCE_Data.Bit--; - MCE_Data.HalfBit = 0; - } - else - { - //Console.WriteLine("Bad bit sequence 11"); - MCE_Data = new MceDetectionData(); - //return; - } - } - else if (duration >= 500 && duration <= 800) - { - if (!pulse) - { - MCE_Data.Working <<= 1; - MCE_Data.Working |= 1; - MCE_Data.Bit--; - MCE_Data.HalfBit = 1; - } - else - { - //Console.WriteLine("Bad bit sequence 11 1"); - MCE_Data = new MceDetectionData(); - //return; - } - } - else - { - //Console.WriteLine("Bad duration {0}", duration); - if (MCE_Data.Bit == 1) - { - MCE_Data.Working <<= 1; - MCE_Data.Working |= 1; - MCE_Data.Bit--; - MCE_Data.HalfBit = 0; - //i--; - } - else - MCE_Data = new MceDetectionData(); - //return; - } - break; - } - } - #endregion Working data ... - - switch (MCE_Data.State) - { - - #region Header - case MceKeyboardDetectState.Header: - //Console.WriteLine("KB Header"); - - if (pulse && (duration >= 2600) && (duration <= 3300)) - { - MCE_Data.State = MceKeyboardDetectState.CodeType; - MCE_Data.Type = 0; - MCE_Data.Bit = 5; - MCE_Data.Working = 0; - } - break; - #endregion Header - - #region CodeType - case MceKeyboardDetectState.CodeType: - //Console.WriteLine("KB CodeType"); - - if (MCE_Data.Bit == 0) - { - MCE_Data.Type = MCE_Data.Working; - - if (MCE_Data.Type == MceKeyboard) - { - MCE_Data.State = MceKeyboardDetectState.KeyboardIgnore; - MCE_Data.Bit = 16; - MCE_Data.Working = 0; - } - else if (MCE_Data.Type == MceMouse) - { - MCE_Data.State = MceKeyboardDetectState.MouseIgnore; - MCE_Data.Bit = 8; - MCE_Data.Working = 0; - } - else - { - //Console.WriteLine("KB: Invalid Type {0}", MceKeyboard_Data.Type); - return; - } - } - - break; - #endregion CodeType - - - #region Keyboard - - #region KeyboardIgnore - case MceKeyboardDetectState.KeyboardIgnore: - //Console.WriteLine("KB KeyboardIgnore"); - - if (MCE_Data.Bit == 0) - { - MCE_Data.State = MceKeyboardDetectState.KeyCode; - MCE_Data.Bit = 8; - MCE_Data.Working = 0; - } - break; - #endregion KeyboardIgnore - - #region KeyCode - case MceKeyboardDetectState.KeyCode: - //Console.WriteLine("KB KeyCode"); - - if (MCE_Data.Bit == 0) - { - MCE_Data.KeyCode = MCE_Data.Working; - - MCE_Data.State = MceKeyboardDetectState.Modifiers; - MCE_Data.Bit = 8; - MCE_Data.Working = 0; - } - break; - #endregion KeyCode - - #region Modifiers - case MceKeyboardDetectState.Modifiers: - //Console.WriteLine("KB Modifiers"); - - if (MCE_Data.Bit == 0) - { - MCE_Data.Modifiers = MCE_Data.Working; - - keyboardCallback(MCE_Data.KeyCode, MCE_Data.Modifiers); - - MCE_Data = new MceDetectionData(); - } - break; - #endregion Modifiers - - #endregion Keyboard - - #region Mouse - - #region MouseIgnore - case MceKeyboardDetectState.MouseIgnore: - //Console.WriteLine("KB MouseIgnore"); - - if (MCE_Data.Bit == 0) - { - MCE_Data.State = MceKeyboardDetectState.DeltaY; - MCE_Data.Bit = 7; - MCE_Data.Working = 0; - } - break; - #endregion MouseIgnore - - #region DeltaY - case MceKeyboardDetectState.DeltaY: - //Console.WriteLine("KB DeltaY"); - - if (MCE_Data.Bit == 0) - { - //Console.WriteLine("KB DeltaY Set"); - MCE_Data.DeltaY = ScaleMouseDelta(MCE_Data.Working); - - MCE_Data.State = MceKeyboardDetectState.DeltaX; - MCE_Data.Bit = 7; - MCE_Data.Working = 0; - } - break; - #endregion DeltaY - - #region DeltaX - case MceKeyboardDetectState.DeltaX: - //Console.WriteLine("KB DeltaX"); - - if (MCE_Data.Bit == 0) - { - //Console.WriteLine("KB DeltaX Set"); - MCE_Data.DeltaX = ScaleMouseDelta(MCE_Data.Working); - - MCE_Data.State = MceKeyboardDetectState.Right; - MCE_Data.Bit = 1; - MCE_Data.Working = 0; - } - break; - #endregion DeltaX - - #region Right - case MceKeyboardDetectState.Right: - //Console.WriteLine("KB Right"); - - if (MCE_Data.Bit == 0) - { - //Console.WriteLine("KB Right Set"); - MCE_Data.Right = (MCE_Data.Working == 1); - - MCE_Data.State = MceKeyboardDetectState.Left; - MCE_Data.Bit = 1; - MCE_Data.Working = 0; - } - break; - #endregion Right - - #region Left - case MceKeyboardDetectState.Left: - //Console.WriteLine("KB Left"); - - if (MCE_Data.Bit == 0) - { - //Console.WriteLine("KB Left Set"); - MCE_Data.Left = (MCE_Data.Working == 1); - - MCE_Data.State = MceKeyboardDetectState.Checksum; - MCE_Data.Bit = 5; - MCE_Data.Working = 0; - } - break; - #endregion Left - - #region Checksum - case MceKeyboardDetectState.Checksum: - //Console.WriteLine("KB Checksum"); - - if (MCE_Data.Bit == 0) - { - //Console.WriteLine("KB Checksum Set"); - mouseCallback(MCE_Data.DeltaX, MCE_Data.DeltaY, MCE_Data.Right, MCE_Data.Left); - - MCE_Data = new MceDetectionData(); - } - break; - #endregion Checksum - - #endregion Mouse - - } - - if (MCE_Data.Bit < 0) - MCE_Data = new MceDetectionData(); - - } - } - - static int ScaleMouseDelta(uint delta) - { - int scaledDelta = (int)delta; - if (delta >= 0x62) - scaledDelta -= 0x80; - - return scaledDelta; - } - - #endregion Methods - - } - -} Deleted: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrDecoder.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrDecoder.cs 2007-09-02 17:09:43 UTC (rev 882) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrDecoder.cs 2007-09-02 17:14:46 UTC (rev 883) @@ -1,1353 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace MicrosoftMceTransceiver -{ - - #region Enumerations - - /// <summary> - /// Protocol of IR Code. - /// </summary> - public enum IRProtocol - { - None, - //ITT, - JVC, - NEC, - //NRC17, - RC5, - RC6, - RCA, - //RCMM, - RECS80, - //Sharp, - SIRC, - //XSAT, - } - - #endregion Enumerations - - #region Delegates - - public delegate void RemoteCallback(IRProtocol codeType, uint keyCode); - public delegate void KeyboardCallback(uint keyCode, uint modifiers); - public delegate void MouseCallback(int deltaX, int deltaY, bool rightButton, bool leftButton); - - #endregion Delegates - - /// <summary> - /// Used for decoding received IR codes. - /// </summary> - public static class IrDecoder - { - - #region Constants - - //public const uint PulseBit = 0x01000000; - //public const uint PulseMask = 0x00FFFFFF; - - //const UInt16 ToggleBitMce = 0x8000; - const UInt16 ToggleMaskMce = 0x7FFF; - const UInt16 CustomerMce = 0x800F; - - const UInt16 ToggleMaskRC5 = 0xF7FF; - const UInt16 ToggleMaskRC5X = 0xFFFF; - - const uint PrefixRC6 = 0x000FC950; - const uint PrefixRC6A = 0x000FCA90; - - const uint MceMouse = 1; - const uint MceKeyboard = 4; - - #endregion Constants - - #region Detection Data - - static RemoteDetectionData JVC_Data = null; - static RemoteDetectionData NEC_Data = null; - static RemoteDetectionData RC5_Data = null; - static RemoteDetectionData RC6_Data = null; - static RemoteDetectionData RCA_Data = null; - static RemoteDetectionData RECS80_Data = null; - static RemoteDetectionData SIRC_Data = null; - - static MceDetectionData MCE_Data = null; - - #endregion Detection Data - - #region Methods - - /// <summary> - /// Decode timing data to discover IR Protocol and button code. - /// </summary> - /// <param name="timingData">Input timing data.</param> - /// <param name="remoteCallback">Method to call when Remote button decoded.</param> - /// <param name="keyboardCallback">Method to call when Keyboard event decoded.</param> - /// <param name="mouseCallback">Method to call when Mouse event decoded.</param> - public static void DecodeIR(int[] timingData, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) - { -// DetectITT(timingData, remoteCallback); - DetectJVC(timingData, remoteCallback); - DetectNEC(timingData, remoteCallback); -// DetectNRC17(timingData, remoteCallback); - DetectRC5(timingData, remoteCallback); - DetectRC6(timingData, remoteCallback); - DetectRCA(timingData, remoteCallback); -// DetectRCMM(timingData, remoteCallback); - DetectRECS80(timingData, remoteCallback); -// DetectSharp(timingData, remoteCallback); - DetectSIRC(timingData, remoteCallback); // 15 Bit -// DetectXSAT(timingData, remoteCallback); - - DetectMCE(timingData, keyboardCallback, mouseCallback); - } - - static void DetectJVC(int[] timingData, RemoteCallback remoteCallback) - { - if (JVC_Data == null || timingData == null) - JVC_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - int duration = Math.Abs(timingData[i]); - bool pulse = (timingData[i] > 0); - bool ignored = true; - - switch (JVC_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("JVC HeaderPulse"); - - if (pulse && duration >= 8200 && duration <= 8600) - { - JVC_Data.State = RemoteDetectionState.HeaderSpace; - ignored = false; - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("JVC HeaderSpace"); - - if (!pulse && duration >= 4000 && duration <= 4400) - { - JVC_Data.State = RemoteDetectionState.Data; - JVC_Data.HalfBit = 0; - JVC_Data.Bit = 0; - JVC_Data.Code = 0; - ignored = false; - } - break; - #endregion HeaderSpace - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("JVC Data"); - - if (pulse && duration >= 350 && duration <= 750) - { - JVC_Data.HalfBit = 1; - ignored = false; - } - else if (!pulse && duration >= 250 && duration <= 650 && JVC_Data.HalfBit == 1) - { - JVC_Data.Code <<= 1; - JVC_Data.Bit++; - JVC_Data.HalfBit = 0; - ignored = false; - } - else if (!pulse && duration >= 1450 && duration <= 1850 && JVC_Data.HalfBit == 1) - { - JVC_Data.Code <<= 1; - JVC_Data.Code |= 1; - JVC_Data.Bit++; - JVC_Data.HalfBit = 0; - ignored = false; - } - else - { - //Console.WriteLine("JVC Error"); - } - - if (JVC_Data.Bit == 16) - { - remoteCallback(IRProtocol.JVC, JVC_Data.Code); - JVC_Data.State = RemoteDetectionState.Leading; - } - break; - #endregion Data - - #region Leading - case RemoteDetectionState.Leading: - //Console.WriteLine("JVC Leading"); - - if (pulse && duration >= 350 && duration <= 750) - { - JVC_Data = new RemoteDetectionData(); - JVC_Data.State = RemoteDetectionState.Data; - ignored = false; - } - break; - #endregion Leading - - } - - if (ignored && (JVC_Data.State != RemoteDetectionState.HeaderPulse)) - JVC_Data = new RemoteDetectionData(); - } - } - static void DetectNEC(int[] timingData, RemoteCallback remoteCallback) - { - if (NEC_Data == null || timingData == null) - NEC_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - int duration = Math.Abs(timingData[i]); - bool pulse = (timingData[i] > 0); - bool ignored = true; - - switch (NEC_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("NEC HeaderPulse"); - - if (pulse && duration >= 8800 && duration <= 9200) - { - NEC_Data.State = RemoteDetectionState.HeaderSpace; - ignored = false; - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("NEC HeaderSpace"); - - if (!pulse && duration >= 4300 && duration <= 4700) - { - NEC_Data.State = RemoteDetectionState.Data; - NEC_Data.HalfBit = 0; - NEC_Data.Bit = 0; - NEC_Data.Code = 0; - ignored = false; - } - else if (!pulse && duration >= 2050 && duration <= 2450) // For Repeats - { - remoteCallback(IRProtocol.NEC, NEC_Data.Code); - NEC_Data.State = RemoteDetectionState.HeaderPulse; - ignored = false; - } - - break; - #endregion HeaderSpace - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("NEC Data"); - - if (pulse && duration >= 350 && duration <= 750) - { - NEC_Data.HalfBit = 1; - ignored = false; - } - else if (!pulse && duration >= 250 && duration <= 650 && NEC_Data.HalfBit == 1) - { - NEC_Data.Code <<= 1; - NEC_Data.Bit++; - NEC_Data.HalfBit = 0; - ignored = false; - } - else if (!pulse && duration >= 1550 && duration <= 1950 && NEC_Data.HalfBit == 1) - { - NEC_Data.Code <<= 1; - NEC_Data.Code |= 1; - NEC_Data.Bit++; - NEC_Data.HalfBit = 0; - ignored = false; - } - else - { - //Console.WriteLine("NEC Error"); - } - - if (NEC_Data.Bit == 32) - { - remoteCallback(IRProtocol.NEC, NEC_Data.Code); - NEC_Data.State = RemoteDetectionState.HeaderPulse; - } - break; - #endregion Data - - } - - if (ignored && (NEC_Data.State != RemoteDetectionState.HeaderPulse)) - NEC_Data = new RemoteDetectionData(); - } - } - static void DetectRC5(int[] timingData, RemoteCallback remoteCallback) - { - if (RC5_Data == null || timingData == null) - RC5_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - int duration = Math.Abs(timingData[i]); - bool pulse = (timingData[i] > 0); - bool ignored = true; - - switch (RC5_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("RC5 HeaderPulse"); - - if (pulse) - { - if ((duration >= 750) && (duration <= 1100)) - { - RC5_Data.State = RemoteDetectionState.HeaderSpace; - RC5_Data.Bit = 13; - RC5_Data.Code = (uint)1 << RC5_Data.Bit; - ignored = false; - } - else if ((duration >= 1500) && (duration <= 2000)) - { - RC5_Data.State = RemoteDetectionState.Data; - RC5_Data.Bit = 13; - RC5_Data.Code = (uint)1 << RC5_Data.Bit; - RC5_Data.HalfBit = 0; - ignored = false; - } - } - break; - #endregion HeaderPulse - - #region HeaderSpace - case RemoteDetectionState.HeaderSpace: - //Console.WriteLine("RC5 HeaderSpace"); - - if (!pulse && (duration >= 750) && (duration <= 1000)) - { - RC5_Data.State = RemoteDetectionState.Data; - RC5_Data.HalfBit = 0; - ignored = false; - } - break; - #endregion HeaderSpace - - #region Data - case RemoteDetectionState.Data: - //Console.WriteLine("RC5 Data"); - - if (RC5_Data.HalfBit == 0) - { - if (pulse) - { - if (((duration >= 750) && (duration <= 1100)) || ((duration >= 1500) && (duration <= 2000))) - { - RC5_Data.HalfBit = (byte)((duration >= 1500) ? 0 : 1); - RC5_Data.Bit--; - RC5_Data.Code |= (uint)1 << RC5_Data.Bit; - ignored = false; - - if ((RC5_Data.Bit == 0) || ((RC5_Data.Bit == 1) && (duration >= 1500))) - RC5_Data.State = RemoteDetectionState.KeyCode; - } - else - { - //Console.WriteLine("RC5 Error {0} on bit {1}", duration, bit); - } - } - else - { - if (((duration >= 750) && (duration <= 1100)) || ((duration >= 1500) && (duration <= 2000))) - { - RC5_Data.HalfBit = (byte)((duration >= 1500) ? 0 : 1); - RC5_Data.Bit--; - ignored = false; - - if (RC5_Data.Bit == 0) - RC5_Data.State = RemoteDetectionState.KeyCode; - } - else if ((RC5_Data.Bit == 7) && (((duration >= 4300) && (duration <= 4700)) || ((duration >= 5200) && (duration <= 5600)))) - { - ignored = false; - RC5_Data.HalfBit = (byte)((duration >= 5200) ? 0 : 1); - RC5_Data.Code <<= 6; - RC5_Data.Bit += 5; - } - else - { - //Console.WriteLine("RC5 Space Error {0} on bit {1}", duration, bit); - } - } - break; - } - - if ((duration >= 750) && (duration <= 1100)) - { - RC5_Data.HalfBit = 0; - ignored = false; - - if ((RC5_Data.Bit == 1) && pulse) - RC5_Data.State = RemoteDetectionState.KeyCode; - } - else if ((RC5_Data.Bit == 7) && (((duration >= 3400) && (duration <= 3800)) || ((duration >= 4300) && (duration <= 4700)))) - { - RC5_Data.HalfBit = (byte)((duration >= 4300) ? 0 : 1); - RC5_Data.Code <<= 6; - RC5_Data.Bit += 6; - ignored = false; - } - else - { - //Console.WriteLine("RC5 Duration Error {0} on bit {1}", duration, bit); - } - break; - #endregion Data - - #region Leading - case RemoteDetectionState.Leading: - //Console.WriteLine("RC5 Leading"); - - if (pulse) - break; - - if (duration > 10000) - { - RC5_Data.State = RemoteDetectionState.HeaderPulse; - ignored = false; - } - break; - #endregion Leading - - } - - if (RC5_Data.State == RemoteDetectionState.KeyCode) - { - if (RC5_Data.Code > 0xFFFF) - RC5_Data.Code &= ToggleMaskRC5X; - else - RC5_Data.Code &= ToggleMaskRC5; - - remoteCallback(IRProtocol.RC5, RC5_Data.Code); - - RC5_Data.State = RemoteDetectionState.HeaderPulse; - } - - if (ignored && (RC5_Data.State != RemoteDetectionState.Leading) && (RC5_Data.State != RemoteDetectionState.HeaderPulse)) - RC5_Data.State = RemoteDetectionState.HeaderPulse; - } - - } - static void DetectRC6(int[] timingData, RemoteCallback remoteCallback) - { - if (RC6_Data == null || timingData == null) - RC6_Data = new RemoteDetectionData(); - - if (timingData == null) - return; - - for (int i = 0; i < timingData.Length; i++) - { - int duration = Math.Abs(timingData[i]); - bool pulse = (timingData[i] > 0); - bool ignored = true; - - switch (RC6_Data.State) - { - - #region HeaderPulse - case RemoteDetectionState.HeaderPulse: - //Console.WriteLine("RC6 HeaderPulse"); - - if (pulse && (duration >= 2600) && (duration <= 3300)) - { - RC6_Data.State = RemoteDetectionState.HeaderSpace; - RC6_Data.Header = 0x000FC000; - RC6_Data.Bit = 14; - RC6_Data.HalfBit = 0; - RC6_Data.Code = 0; - RC6_Data.LongPulse = false; - RC6_Data... [truncated message content] |
From: <an...@us...> - 2007-09-05 17:23:57
|
Revision: 895 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=895&view=rev Author: and-81 Date: 2007-09-05 10:23:54 -0700 (Wed, 05 Sep 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Driver.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrCode.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrDecoder.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Microsoft MCE Transceiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/MicrosoftMceTransceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Pronto.cs Added Paths: ----------- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Driver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Driver.cs 2007-09-05 13:05:02 UTC (rev 894) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Driver.cs 2007-09-05 17:23:54 UTC (rev 895) @@ -11,6 +11,9 @@ namespace MicrosoftMceTransceiver { + /// <summary> + /// Base class for the different MCE device driver access classes. + /// </summary> public abstract class Driver { @@ -111,7 +114,8 @@ struct DeviceInterfaceDetailData { public int Size; - [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string DevicePath; + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] + public string DevicePath; } #endregion Structures @@ -196,12 +200,28 @@ #region Abstract Methods + /// <summary> + /// Start using the device. + /// </summary> public abstract void Start(); + /// <summary> + /// Stop access to the device. + /// </summary> public abstract void Stop(); - + // TODO: Change learn interface to return LearnStatus + /// <summary> + /// Learn an IR Command. + /// </summary> + /// <param name="learnTimeout">How long to wait before aborting learn.</param> + /// <returns>Newly learned IR Command.</returns> public abstract IrCode Learn(int learnTimeout); + /// <summary> + /// Send an IR Command. + /// </summary> + /// <param name="code">IR code data to send.</param> + /// <param name="port">IR port to send to.</param> public abstract void Send(IrCode code, uint port); #endregion Abstract Methods Added: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs (rev 0) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs 2007-09-05 17:23:54 UTC (rev 895) @@ -0,0 +1,759 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Runtime.InteropServices; +using System.ServiceProcess; +using System.Text; +using System.Threading; + +using Microsoft.Win32.SafeHandles; + +namespace MicrosoftMceTransceiver +{ + + public class DriverReplacement : Driver + { + + #region Interop + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool GetOverlappedResult( + SafeFileHandle handle, + ref NativeOverlapped overlapped, + out int bytesTransferred, + bool wait); + + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] + static extern SafeFileHandle CreateFile( + [MarshalAs(UnmanagedType.LPTStr)] string fileName, + [MarshalAs(UnmanagedType.U4)] FileAccessTypes fileAccess, + [MarshalAs(UnmanagedType.U4)] FileShares fileShare, + IntPtr securityAttributes, + [MarshalAs(UnmanagedType.U4)] CreationDisposition creationDisposition, + [MarshalAs(UnmanagedType.U4)] FileAttributes flags, + IntPtr templateFile); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool ReadFile( + SafeFileHandle handle, + IntPtr buffer, + int bytesToRead, + out int bytesRead, + ref NativeOverlapped overlapped); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool WriteFile( + SafeFileHandle handle, + byte[] buffer, + int bytesToWrite, + out int bytesWritten, + ref NativeOverlapped overlapped); + + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool CancelIo( + SafeFileHandle handle); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool CloseHandle( + SafeFileHandle handle); + + #endregion Interop + + #region Enumerations + + /// <summary> + /// Type of device in use. + /// This is used to determine the blaster port selection method. + /// </summary> + enum DeviceType + { + /// <summary> + /// Device is a first party Microsoft MCE transceiver. + /// </summary> + Microsoft = 0, + /// <summary> + /// Device is an third party SMK or Topseed MCE transceiver. + /// </summary> + SmkTopseed = 1, + } + + /// <summary> + /// Device input port. + /// </summary> + enum InputPort + { + Receive = 0, + Learning = 1, + } + + /// <summary> + /// Read Thread Mode. + /// </summary> + enum ReadThreadMode + { + Receiving, + Learning, + LearningDone, + LearningFailed, + Stop, + } + + #endregion Enumerations + + #region Constants + + // Vendor ID's for SMK and Topseed devices. + const string VidSMK = "vid_1784"; + const string VidTopseed = "vid_0609"; + + // Device variables + const int DeviceBufferSize = 100; + const int PacketTimeout = 100; + const int WriteSyncTimeout = 5000; + + // Microsoft Port Packets + static readonly byte[][] MicrosoftPorts = new byte[][] + { + new byte[] { 0x9F, 0x08, 0x06 }, // Both + new byte[] { 0x9F, 0x08, 0x04 }, // 1 + new byte[] { 0x9F, 0x08, 0x02 }, // 2 + }; + + // SMK or Topseed Port Packets + static readonly byte[][] SmkTopseedPorts = new byte[][] + { + new byte[] { 0x9F, 0x08, 0x00 }, // Both + new byte[] { 0x9F, 0x08, 0x01 }, // 1 + new byte[] { 0x9F, 0x08, 0x02 }, // 2 + }; + + // Start and Stop Packets + static readonly byte[] StartPacket = { 0x00, 0xFF, 0xAA }; + static readonly byte[] StopPacket = { 0xFF, 0xBB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + + // Misc Packets + static readonly byte[] SetCarrierFreqPacket = { 0x9F, 0x06, 0x01, 0x80 }; + static readonly byte[] SetInputPortPacket = { 0x9F, 0x14, 0x00 }; + static readonly byte[] SetTimeoutPacket = { 0x9F, 0x0C, 0x00, 0x00 }; + + #endregion Constants + + #region Variables + + NotifyWindow _notifyWindow; + + SafeFileHandle _readHandle; + SafeFileHandle _writeHandle; + + Thread _readThread; + ReadThreadMode _readThreadMode; + ManualResetEvent _stopReadThread; + + IrCode _learningCode; + + DeviceType _deviceType = DeviceType.Microsoft; + + //StreamWriter _debugFile; + + #endregion Variables + + #region Constructor + + public DriverReplacement(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) + : base(deviceGuid, devicePath, remoteCallback, keyboardCallback, mouseCallback) + { + if (devicePath.IndexOf(VidSMK, StringComparison.InvariantCultureIgnoreCase) != -1 || devicePath.IndexOf(VidTopseed, StringComparison.InvariantCultureIgnoreCase) != -1) + _deviceType = DeviceType.SmkTopseed; + else + _deviceType = DeviceType.Microsoft; + } + + #endregion Constructor + + #region Driver overrides + + public override void Start() + { + //_debugFile = new StreamWriter("\\DriverReplacement.log", false); + //_debugFile.AutoFlush = true; + + _notifyWindow = new NotifyWindow(); + _notifyWindow.Class = _deviceGuid; + + int lastError; + + _readHandle = CreateFile(_devicePath + "\\Pipe01", FileAccessTypes.GenericRead, FileShares.None, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Overlapped, IntPtr.Zero); + lastError = Marshal.GetLastWin32Error(); + if (_readHandle.IsInvalid) + throw new Win32Exception(lastError); + + _writeHandle = CreateFile(_devicePath + "\\Pipe00", FileAccessTypes.GenericWrite, FileShares.None, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Overlapped, IntPtr.Zero); + lastError = Marshal.GetLastWin32Error(); + if (_writeHandle.IsInvalid) + throw new Win32Exception(lastError); + + // Initialize device ... + WriteSync(StartPacket); + SetTimeout(PacketTimeout); + SetInputPort(InputPort.Receive); + + StartReadThread(); + + _notifyWindow.Create(); + _notifyWindow.DeviceArrival += new DeviceEventHandler(OnDeviceArrival); + _notifyWindow.DeviceRemoval += new DeviceEventHandler(OnDeviceRemoval); + _notifyWindow.RegisterDeviceRemoval(_readHandle.DangerousGetHandle()); + } + + public override void Stop() + { + WriteSync(StopPacket); + + OnDeviceRemoval(); + + CloseDevice(); + + //_debugFile.Close(); + } + + public override IrCode Learn(int learnTimeout) + { + //_debugFile.WriteLine("Start Learn"); + + _learningCode = new IrCode(); + + SetInputPort(InputPort.Learning); + + int learnStartTick = Environment.TickCount; + _readThreadMode = ReadThreadMode.Learning; + + // Wait for the learning to finish ... + while (_readThreadMode == ReadThreadMode.Learning && Environment.TickCount < learnStartTick + learnTimeout) + Thread.Sleep(100); + + //_debugFile.WriteLine("End Learn"); + + ReadThreadMode modeWas = _readThreadMode; + + _readThreadMode = ReadThreadMode.Receiving; + SetInputPort(InputPort.Receive); + + switch (modeWas) + { + case ReadThreadMode.Learning: + // Timeout. + return null; + + case ReadThreadMode.LearningFailed: + // Failure. + return null; + + case ReadThreadMode.LearningDone: + //_debugFile.WriteLine(_learningCode.ToByteArray()); + + if (_learningCode.FinalizeData()) + return _learningCode; // Success. + else + return null; // Failure. + + default: + return null; + } + } + + public override void Send(IrCode code, uint port) + { + //_debugFile.WriteLine("Send"); + + byte[] portPacket; + switch (_deviceType) + { + case DeviceType.Microsoft: portPacket = MicrosoftPorts[port]; break; + case DeviceType.SmkTopseed: portPacket = SmkTopseedPorts[port]; break; + default: + throw new Exception("Invalid device type"); + } + + //Dump(code.ToByteArray()); + + // Set port + WriteSync(portPacket); + + // Set carrier frequency + WriteSync(CarrierPacket(code)); + + // Send packet + WriteSync(DataPacket(code)); + } + + #endregion Driver overrides + + #region Implementation + + byte[] CarrierPacket(IrCode code) + { + byte[] carrierPacket = new byte[SetCarrierFreqPacket.Length]; + SetCarrierFreqPacket.CopyTo(carrierPacket, 0); + + if (code.Carrier == IrCode.CarrierFrequencyUnknown || code.Carrier == IrCode.CarrierFrequencyDCMode) + return carrierPacket; + + for (int scaler = 1; scaler <= 4; scaler++) + { + int divisor = (10000000 >> (2 * scaler)) / code.Carrier; + + if (divisor <= 0xFF) + { + carrierPacket[2] = (byte)scaler; + carrierPacket[3] = (byte)divisor; + break; + } + } + + return carrierPacket; + } + + byte[] DataPacket(IrCode code) + { + if (code.TimingData.Length == 0) + return null; + + // Construct data bytes into "packet" ... + List<byte> packet = new List<byte>(); + + for (int index = 0; index < code.TimingData.Length; index++) + { + double time = (double)code.TimingData[index]; + + byte duration = (byte)Math.Abs(Math.Round(time / 50)); + bool pulse = (time > 0); + + while (duration > 0x7F) + { + packet.Add((byte)(pulse ? 0xFF : 0x7F)); + + duration -= 0x7F; + } + + packet.Add((byte)(pulse ? 0x80 | duration : duration)); + } + + // Insert byte count markers into packet data bytes ... + int subpackets = (int)Math.Ceiling(packet.Count / (double)4); + + byte[] output = new byte[packet.Count + subpackets + 1]; + + int outputPos = 0; + + for (int packetPos = 0; packetPos < packet.Count; ) + { + byte copyCount = (byte)(packet.Count - packetPos < 4 ? packet.Count - packetPos : 0x04); + + output[outputPos++] = (byte)(0x80 | copyCount); + + for (int index = 0; index < copyCount; index++) + output[outputPos++] = packet[packetPos++]; + } + + output[outputPos] = 0x80; + + return output; + } + + /// <summary> + /// Set the receive buffer timeout. + /// </summary> + /// <param name="timeout">Packet timeout (in milliseconds).</param> + void SetTimeout(int timeout) + { + byte[] timeoutPacket = new byte[SetTimeoutPacket.Length]; + SetTimeoutPacket.CopyTo(timeoutPacket, 0); + + int timeoutSamples = 20 * timeout; + + timeoutPacket[2] = (byte)(timeoutSamples >> 8); + timeoutPacket[3] = (byte)(timeoutSamples % 256); + + WriteSync(timeoutPacket); + } + + void SetInputPort(InputPort port) + { + byte[] inputPortPacket = new byte[SetInputPortPacket.Length]; + SetInputPortPacket.CopyTo(inputPortPacket, 0); + + inputPortPacket[2] = (byte)(port + 1); + + WriteSync(inputPortPacket); + } + + void StartReadThread() + { + _stopReadThread = new ManualResetEvent(false); + _readThreadMode = ReadThreadMode.Receiving; + + _readThread = new Thread(new ThreadStart(ReadThread)); + _readThread.IsBackground = true; + _readThread.Name = "IR Server Microsoft MCE Transceiver Read"; + _readThread.Start(); + } + + void StopReadThread() + { + if (_readThread != null) + { + _readThreadMode = ReadThreadMode.Stop; + _stopReadThread.Set(); + + //_readThread.Abort(); + + if (Thread.CurrentThread != _readThread) + _readThread.Join(); + + _readThread = null; + } + } + + void CloseDevice() + { + if (_readHandle != null) + CloseHandle(_readHandle); + + if (_writeHandle != null) + CloseHandle(_writeHandle); + } + + void OnDeviceArrival() + { + _notifyWindow.UnregisterDeviceArrival(); + + StartReadThread(); + + _notifyWindow.RegisterDeviceRemoval(_readHandle.DangerousGetHandle()); + } + void OnDeviceRemoval() + { + _notifyWindow.UnregisterDeviceRemoval(); + _notifyWindow.RegisterDeviceArrival(); + + StopReadThread(); + } + + void ReadThread() + { + int bytesRead; + TimeSpan sinceLastPacket; + DateTime lastPacketTime = DateTime.Now; + + byte[] packetBytes; + + int lastError; + + NativeOverlapped lpOverlapped = new NativeOverlapped(); + lpOverlapped.InternalLow = IntPtr.Zero; + lpOverlapped.InternalHigh = IntPtr.Zero; + lpOverlapped.OffsetLow = 0; + lpOverlapped.OffsetHigh = 0; + + WaitHandle waitHandle = new ManualResetEvent(false); + SafeHandle safeWaitHandle = waitHandle.SafeWaitHandle; + WaitHandle[] waitHandles = new WaitHandle[] { waitHandle, _stopReadThread }; + + bool success = false; + safeWaitHandle.DangerousAddRef(ref success); + if (!success) + return; + + IntPtr deviceBufferPtr = IntPtr.Zero; + + try + { + deviceBufferPtr = Marshal.AllocHGlobal(DeviceBufferSize); + + while (_readThreadMode != ReadThreadMode.Stop) + { + bytesRead = 0; + + lpOverlapped.EventHandle = safeWaitHandle.DangerousGetHandle(); + + bool readDevice = ReadFile(_readHandle, deviceBufferPtr, DeviceBufferSize, out bytesRead, ref lpOverlapped); + lastError = Marshal.GetLastWin32Error(); + + if (!readDevice) + { + if (lastError != Win32ErrorCodes.ERROR_SUCCESS && lastError != Win32ErrorCodes.ERROR_IO_PENDING) + throw new Win32Exception(lastError); + + while (true) + { + int handle = WaitHandle.WaitAny(waitHandles, PacketTimeout + 50, false); + + if (handle == Win32ErrorCodes.WAIT_TIMEOUT) + continue; + else if (handle == 0) + break; + else if (handle == 1) + throw new Exception("Stop Read Thread"); + else + throw new Exception("Invalid wait handle return"); + } + + bool getOverlapped = GetOverlappedResult(_readHandle, ref lpOverlapped, out bytesRead, true); + lastError = Marshal.GetLastWin32Error(); + + if (!getOverlapped) + { + if (lastError != Win32ErrorCodes.ERROR_SUCCESS) + throw new Win32Exception(lastError); + } + } + + if (bytesRead == 0) + continue; + + sinceLastPacket = DateTime.Now.Subtract(lastPacketTime); + if (sinceLastPacket.TotalMilliseconds >= PacketTimeout) + IrDecoder.DecodeIR(null, null, null, null); + + lastPacketTime = DateTime.Now; + + packetBytes = new byte[bytesRead]; + Marshal.Copy(deviceBufferPtr, packetBytes, 0, bytesRead); + + //Dump(packetBytes); + + int[] timingData; + + switch (_readThreadMode) + { + case ReadThreadMode.Receiving: + { + if (packetBytes[0] >= 0x81 && packetBytes[0] <= 0x8F) + { + timingData = GetTimingDataFromPacket(packetBytes); + if (timingData == null) + break; + + IrDecoder.DecodeIR(timingData, _remoteCallback, _keyboardCallback, _mouseCallback); + } + break; + } + + case ReadThreadMode.Learning: + { + timingData = GetTimingDataFromPacket(packetBytes); + if (timingData == null) + { + if (_learningCode.TimingData.Length > 0) + { + _learningCode = null; + _readThreadMode = ReadThreadMode.LearningFailed; + } + break; + } + + _learningCode.AddTimingData(timingData); + + // 9F 01 02 9F 15 00 BE 80 + int indexOf9F = Array.IndexOf(packetBytes, (byte)0x9F); + while (indexOf9F != -1) + { + if (packetBytes.Length > indexOf9F + 3 && packetBytes[indexOf9F + 1] == 0x15) + { + byte b1 = packetBytes[indexOf9F + 2]; + byte b2 = packetBytes[indexOf9F + 3]; + + int onTime, onCount; + GetIrCodeLengths(_learningCode, out onTime, out onCount); + + double carrierCount = ((b1 * 256) + b2); + + if (carrierCount / onCount < 2) + { + _learningCode.Carrier = IrCode.CarrierFrequencyDCMode; + } + else + { + double carrier = (double)1000000 * carrierCount / onTime; + + if (carrier > 32000) + _learningCode.Carrier = (int)(carrier + 0.05 * carrier - 32000 / 48000); + else + _learningCode.Carrier = (int)carrier; + } + + //_debugFile.WriteLine(String.Format("Carrier Freq ({0:X2}, {1:X2}): {2}", b1, b2, _learningCode.Carrier)); + + _readThreadMode = ReadThreadMode.LearningDone; + break; + } + + if (packetBytes.Length > indexOf9F + 1) + indexOf9F = Array.IndexOf(packetBytes, (byte)0x9F, indexOf9F + 1); + else + { + _readThreadMode = ReadThreadMode.LearningFailed; + break; + } + } + + break; + } + } + + } + } + catch + { + CancelIo(_readHandle); + } + finally + { + if (deviceBufferPtr != IntPtr.Zero) + Marshal.FreeHGlobal(deviceBufferPtr); + + safeWaitHandle.DangerousRelease(); + waitHandle.Close(); + } + } + /* + void Dump(byte[] data) + { + _debugFile.WriteLine("Dump"); + foreach (byte d in data) + _debugFile.Write(String.Format("{0:X2} ", d)); + _debugFile.WriteLine(); + } + */ + void WriteSync(byte[] data) + { + NativeOverlapped lpOverlapped = new NativeOverlapped(); + lpOverlapped.InternalLow = IntPtr.Zero; + lpOverlapped.InternalHigh = IntPtr.Zero; + lpOverlapped.OffsetLow = 0; + lpOverlapped.OffsetHigh = 0; + + int bytesWritten = 0; + + int lastError; + + WaitHandle waitHandle = new ManualResetEvent(false); + SafeHandle safeWaitHandle = waitHandle.SafeWaitHandle; + WaitHandle[] waitHandles = new WaitHandle[] { waitHandle }; + + bool success = false; + safeWaitHandle.DangerousAddRef(ref success); + if (!success) + return; + + try + { + lpOverlapped.EventHandle = safeWaitHandle.DangerousGetHandle(); + + bool writeDevice = WriteFile(_writeHandle, data, data.Length, out bytesWritten, ref lpOverlapped); + lastError = Marshal.GetLastWin32Error(); + + if (!writeDevice) + { + if (lastError != Win32ErrorCodes.ERROR_SUCCESS && lastError != Win32ErrorCodes.ERROR_IO_PENDING) + throw new Win32Exception(lastError); + + int handle = WaitHandle.WaitAny(waitHandles, WriteSyncTimeout, false); + + if (handle == Win32ErrorCodes.WAIT_TIMEOUT) + throw new Exception("Timeout trying to write data to device"); + else if (handle != 0) + throw new Exception("Invalid wait handle return"); + + bool getOverlapped = GetOverlappedResult(_writeHandle, ref lpOverlapped, out bytesWritten, true); + lastError = Marshal.GetLastWin32Error(); + + if (!getOverlapped) + { + if (lastError != Win32ErrorCodes.ERROR_SUCCESS) + throw new Win32Exception(lastError); + } + } + } + catch + { + CancelIo(_writeHandle); + throw; + } + finally + { + safeWaitHandle.DangerousRelease(); + waitHandle.Close(); + } + } + + int[] GetTimingDataFromPacket(byte[] packet) + { + List<int> timingData = new List<int>(); + + int len = 0; + + for (int index = 0; index < packet.Length; ) + { + byte curByte = packet[index]; + + if (curByte == 0x9F) + break; + + if (curByte < 0x81 || curByte > 0x8F) + return null; + + int bytes = curByte & 0x7F; + int j; + + for (j = index + 1; j < index + bytes + 1; j++) + { + curByte = packet[j]; + + if ((curByte & 0x80) != 0) + len += (int)(curByte & 0x7F); + else + len -= (int)curByte; + + if ((curByte & 0x7F) != 0x7F) + { + timingData.Add(len * 50); + len = 0; + } + } + + index = j; + } + + if (len != 0) + timingData.Add(len * 50); + + return timingData.ToArray(); + } + + void GetIrCodeLengths(IrCode code, out int onTime, out int onCount) + { + onTime = 0; + onCount = 0; + + foreach (int time in code.TimingData) + { + if (time > 0) + { + onTime += time; + onCount++; + } + } + } + + #endregion Implementation + + } + +} Added: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs (rev 0) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs 2007-09-05 17:23:54 UTC (rev 895) @@ -0,0 +1,860 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Runtime.InteropServices; +using System.ServiceProcess; +using System.Text; +using System.Threading; + +using Microsoft.Win32.SafeHandles; + +namespace MicrosoftMceTransceiver +{ + + public class DriverVista : Driver + { + + #region Constants + + // Device variables + const int DeviceBufferSize = 100; + const int PacketTimeout = 100; + const int WriteSyncTimeout = 5000; + + #endregion Constants + + #region Enumerations + + public enum IoCtrl : uint + { + StartReceive = 0x0F608028, + StopReceive = 0x0F60802C, + GetDetails = 0x0F604004, + GetBlasters = 0x0F604008, + Receive = 0x0F604022, + Transmit = 0x0F608015, + } + + /// <summary> + /// IR Device Capability Flags. + /// </summary> + [Flags] + public enum DeviceCapabilityFlags : uint + { + /// <summary> + /// Hardware supports legacy key signing. + /// </summary> + LegacySigning = 0x0001, + /// <summary> + /// Hardware has unique serial number. + /// </summary> + SerialNumber = 0x0002, + /// <summary> + /// Can hardware flash LED to identify receiver? + /// </summary> + FlashLed = 0x0004, + /// <summary> + /// Is this a legacy device? + /// </summary> + Legacy = 0x0008, + /// <summary> + /// Device can wake from S1. + /// </summary> + WakeS1 = 0x0010, + /// <summary> + /// Device can wake from S2. + /// </summary> + WakeS2 = 0x0020, + /// <summary> + /// Device can wake from S3. + /// </summary> + WakeS3 = 0x0040, + /// <summary> + /// Device can wake from S4. + /// </summary> + WakeS4 = 0x0080, + /// <summary> + /// Device can wake from S5. + /// </summary> + WakeS5 = 0x0100, + } + + [Flags] + public enum TransmitFlags : uint + { + /// <summary> + /// Pulse Mode. + /// </summary> + PulseMode = 0x01, + /// <summary> + /// DC Mode. + /// </summary> + DCMode = 0x02, + } + + /// <summary> + /// Read Thread Mode. + /// </summary> + enum ReadThreadMode + { + Receiving, + Learning, + LearningDone, + LearningFailed, + Stop, + } + + #endregion Enumerations + + #region Structures + + [StructLayout(LayoutKind.Sequential)] + public struct TransmitChunk + { + /// <summary> + /// Next chunk offset. + /// </summary> + public uint OffsetToNextChunk; + /// <summary> + /// Repeat count. + /// </summary> + public uint RepeatCount; + /// <summary> + /// Number of bytes. + /// </summary> + public uint ByteCount; + } + + [StructLayout(LayoutKind.Sequential)] + public struct TransmitParams + { + /// <summary> + /// Bitmask containing ports to transmit on. + /// </summary> + public uint TransmitPortMask; + /// <summary> + /// Carrier period. + /// </summary> + public uint CarrierPeriod; + /// <summary> + /// Transmit Flags. + /// </summary> + [MarshalAs(UnmanagedType.U4)] + public TransmitFlags Flags; + /// <summary> + /// Pulse Size. If Pulse Mode Flag set. + /// </summary> + public uint PulseSize; + } + + [StructLayout(LayoutKind.Sequential)] + public struct ReceiveParams + { + /// <summary> + /// Last packet in block? + /// </summary> + public uint DataEnd; + /// <summary> + /// Number of bytes in block. + /// </summary> + public uint ByteCount; + /// <summary> + /// Carrier frequency of IR received. + /// </summary> + public uint CarrierFrequency; + } + + [StructLayout(LayoutKind.Sequential)] + public struct StartReceiveParams + { + /// <summary> + /// Index of the receiver to use. + /// </summary> + public uint Receiver; + /// <summary> + /// Receive timeout, in milliseconds? + /// </summary> + public uint Timeout; + } + + [StructLayout(LayoutKind.Sequential)] + public struct DeviceCapabilities + { + /// <summary> + /// Protocol version. Currently must be 100 (1.0). + /// </summary> + public uint ProtocolVersion; + /// <summary> + /// Number of transmit ports \x96 0-32. + /// </summary> + public uint TransmitPorts; + /// <summary> + /// Number of receive ports \x96 0-32 (For beanbag, this is two (one for learning, one for normal). + /// </summary> + public uint ReceivePorts; + /// <summary> + /// Bitmask identifying which receivers are learning receivers \x96 low bit is the first receiver, second-low bit is the second receiver, etc ... + /// </summary> + public uint LearningMask; + /// <summary> + /// Device flags. + /// </summary> + [MarshalAs(UnmanagedType.U4)] + public DeviceCapabilityFlags DetailsFlags; + } + + #endregion Structures + + #region Interop + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool DeviceIoControl( + SafeFileHandle handle, + [MarshalAs(UnmanagedType.U4)] IoCtrl ioControlCode, + IntPtr inBuffer, int inBufferSize, + IntPtr outBuffer, int outBufferSize, + out int bytesReturned, + ref NativeOverlapped overlapped); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool DeviceIoControl( + SafeFileHandle handle, + [MarshalAs(UnmanagedType.U4)] IoCtrl ioControlCode, + IntPtr inBuffer, int inBufferSize, + IntPtr outBuffer, int outBufferSize, + out int bytesReturned, + IntPtr overlapped); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool GetOverlappedResult( + SafeFileHandle handle, + ref NativeOverlapped overlapped, + out int bytesTransferred, + bool wait); + + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] + static extern SafeFileHandle CreateFile( + [MarshalAs(UnmanagedType.LPTStr)] string fileName, + [MarshalAs(UnmanagedType.U4)] FileAccessTypes fileAccess, + [MarshalAs(UnmanagedType.U4)] FileShares fileShare, + IntPtr securityAttributes, + [MarshalAs(UnmanagedType.U4)] CreationDisposition creationDisposition, + [MarshalAs(UnmanagedType.U4)] FileAttributes flags, + IntPtr templateFile); + + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool CancelIo( + SafeFileHandle handle); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool CloseHandle( + SafeFileHandle handle); + + #endregion Interop + + #region Variables + + #region Device Details + + uint _numTxPorts = 0; + uint _numRxPorts = 0; + uint _learnPortMask = 0; + bool _legacyDevice = false; + bool _canFlashLed = false; + + bool[] _blasters; + + uint _receivePort = 0; + uint _learnPort = 0; + + #endregion Device Details + + NotifyWindow _notifyWindow; + + SafeFileHandle _eHomeHandle; + + Thread _readThread; + ReadThreadMode _readThreadMode; + + IrCode _learningCode; + + //StreamWriter _debugFile; + + #endregion Variables + + #region Constructor + + public DriverVista(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) + : base(deviceGuid, devicePath, remoteCallback, keyboardCallback, mouseCallback) + { + + } + + #endregion Constructor + + #region Device Control Functions + + void StartReceive(uint receivePort, uint timeout) + { + int bytesReturned; + + StartReceiveParams structure; + structure.Receiver = receivePort; + structure.Timeout = timeout; + + IntPtr structPtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure)); + + try + { + Marshal.StructureToPtr(structure, structPtr, false); + + IoControlSync(IoCtrl.StartReceive, structPtr, Marshal.SizeOf(structure), IntPtr.Zero, 0, out bytesReturned); + } + catch + { + throw; + } + finally + { + Marshal.FreeHGlobal(structPtr); + } + } + + void StopReceive() + { + int bytesReturned; + IoControlSync(IoCtrl.StopReceive, IntPtr.Zero, 0, IntPtr.Zero, 0, out bytesReturned); + } + + void GetDeviceCapabilities() + { + int bytesReturned; + + DeviceCapabilities structure = new DeviceCapabilities(); + + IntPtr structPtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure)); + + try + { + Marshal.StructureToPtr(structure, structPtr, false); + + IoControlSync(IoCtrl.GetDetails, IntPtr.Zero, 0, structPtr, Marshal.SizeOf(structure), out bytesReturned); + + structure = (DeviceCapabilities)Marshal.PtrToStructure(structPtr, typeof(DeviceCapabilities)); + } + catch + { + throw; + } + finally + { + Marshal.FreeHGlobal(structPtr); + } + + _numTxPorts = structure.TransmitPorts; + _numRxPorts = structure.ReceivePorts; + _learnPortMask = structure.LearningMask; + + int receivePort = FirstLowBit(_learnPortMask); + if (receivePort != -1) + _receivePort = (uint)receivePort; + + int learnPort = FirstHighBit(_learnPortMask); + if (learnPort != -1) + _learnPort = (uint)learnPort; + else + _learnPort = _receivePort; + + DeviceCapabilityFlags flags = structure.DetailsFlags; + _legacyDevice = (int)(flags & DeviceCapabilityFlags.Legacy) != 0; + _canFlashLed = (int)(flags & DeviceCapabilityFlags.FlashLed) != 0; + } + + void GetBlasters() + { + int bytesReturned; + + if (_numTxPorts == 0) + return; + + _blasters = new bool[_numTxPorts]; + for (int i = 0; i < _blasters.Length; i++) + _blasters[i] = false; + + uint data = 0; + + IntPtr pointerToData = Marshal.AllocHGlobal(sizeof(uint)); + + try + { + Marshal.StructureToPtr(data, pointerToData, false); + + IoControlSync(IoCtrl.GetBlasters, IntPtr.Zero, 0, pointerToData, sizeof(uint), out bytesReturned); + + data = (uint)Marshal.PtrToStructure(pointerToData, typeof(uint)); + } + catch + { + throw; + } + finally + { + Marshal.FreeHGlobal(pointerToData); + } + + for (int j = 0; j < _blasters.Length; j++) + _blasters[j] = ((data & (((int)1) << j)) != 0); + } + + void TransmitIR(byte[] irData, int carrier, uint transmitPortMask) + { + int bytesReturned; + + TransmitParams transmitParams = new TransmitParams(); + transmitParams.TransmitPortMask = transmitPortMask; + + if (carrier == IrCode.CarrierFrequencyUnknown) + carrier = IrCode.CarrierFrequencyDefault; + + if (IsPulseMode((uint)carrier)) + { + transmitParams.Flags = TransmitFlags.PulseMode; + transmitParams.PulseSize = (uint)carrier; + } + else + { + //transmitParams.Flags = TransmitFlags.DCMode; + transmitParams.CarrierPeriod = GetCarrierPeriod((uint)carrier); + } + + TransmitChunk transmitChunk = new TransmitChunk(); + transmitChunk.OffsetToNextChunk = 0; + transmitChunk.RepeatCount = 1; + transmitChunk.ByteCount = (uint)irData.Length; + + int bufferSize = irData.Length + Marshal.SizeOf(typeof(TransmitChunk)) + 8; + byte[] buffer = new byte[bufferSize]; + + byte[] rawTransmitChunk = RawSerialize(transmitChunk); + Array.Copy(rawTransmitChunk, buffer, rawTransmitChunk.Length); + + Array.Copy(irData, 0, buffer, rawTransmitChunk.Length, irData.Length); + + IntPtr structurePtr = Marshal.AllocHGlobal(Marshal.SizeOf(transmitParams)); + IntPtr bufferPtr = Marshal.AllocHGlobal(buffer.Length); + + try + { + Marshal.StructureToPtr(transmitParams, structurePtr, true); + + Marshal.Copy(buffer, 0, bufferPtr, buffer.Length); + + IoControlSync(IoCtrl.Transmit, structurePtr, Marshal.SizeOf(typeof(TransmitParams)), bufferPtr, bufferSize, out bytesReturned); + } + catch + { + throw; + } + finally + { + Marshal.FreeHGlobal(structurePtr); + Marshal.FreeHGlobal(bufferPtr); + } + } + + void IoControlSync(IoCtrl ioControlCode, IntPtr inBuffer, int inBufferSize, IntPtr outBuffer, int outBufferSize, out int bytesReturned) + { + NativeOverlapped overlapped; + overlapped.InternalLow = IntPtr.Zero; + overlapped.InternalHigh = IntPtr.Zero; + overlapped.OffsetLow = 0; + overlapped.OffsetHigh = 0; + + try + { + int lastError; + + using (WaitHandle waitHandle = new ManualResetEvent(false)) + { + overlapped.EventHandle = waitHandle.SafeWaitHandle.DangerousGetHandle(); + + if (!DeviceIoControl(_eHomeHandle, ioControlCode, inBuffer, inBufferSize, outBuffer, outBufferSize, out bytesReturned, ref overlapped)) + { + lastError = Marshal.GetLastWin32Error(); + if (lastError != Win32ErrorCodes.ERROR_IO_PENDING) + throw new Win32Exception(lastError); + + waitHandle.WaitOne(); + + if (!GetOverlappedResult(_eHomeHandle, ref overlapped, out bytesReturned, false)) + { + lastError = Marshal.GetLastWin32Error(); + throw new Win32Exception(lastError); + } + } + } + + } + catch + { + CancelIo(_eHomeHandle); + throw; + } + } + + #endregion Device Control Functions + + #region Driver overrides + + public override void Start() + { + //_debugFile = new StreamWriter("\\DriverVista.log", false); + //_debugFile.AutoFlush = true; + + _notifyWindow = new NotifyWindow(); + _notifyWindow.Class = _deviceGuid; + + _eHomeHandle = CreateFile(_devicePath, FileAccessTypes.GenericRead | FileAccessTypes.GenericWrite, FileShares.None, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Overlapped, IntPtr.Zero); + int lastError = Marshal.GetLastWin32Error(); + if (_eHomeHandle.IsInvalid) + throw new Win32Exception(lastError); + + GetAllDeviceInformation(); + + StartReceive(_receivePort, PacketTimeout); + + _readThreadMode = ReadThreadMode.Receiving; + + StartReadThread(); + + _notifyWindow.Create(); + _notifyWindow.DeviceArrival += new DeviceEventHandler(OnDeviceArrival); + _notifyWindow.DeviceRemoval += new DeviceEventHandler(OnDeviceRemoval); + _notifyWindow.RegisterDeviceRemoval(_eHomeHandle.DangerousGetHandle()); + } + public override void Stop() + { + OnDeviceRemoval(); + + CloseDevice(); + + //_debugFile.Close(); + } + + public override IrCode Learn(int learnTimeout) + { + //_debugFile.WriteLine("Learn"); + + StopReadThread(); + + _learningCode = new IrCode(); + + StartReceive(_learnPort, PacketTimeout); + + _readThreadMode = ReadThreadMode.Learning; + + StartReadThread(); + + int learnStartTick = Environment.TickCount; + + // Wait for the learning to finish ... + while (_readThreadMode == ReadThreadMode.Learning && Environment.TickCount < learnStartTick + learnTimeout) + Thread.Sleep(PacketTimeout); + + //_debugFile.WriteLine("End Learn"); + + ReadThreadMode modeWas = _readThreadMode; + + StopReadThread(); + + StartReceive(_receivePort, PacketTimeout); + + _readThreadMode = ReadThreadMode.Receiving; + + StartReadThread(); + + switch (modeWas) + { + case ReadThreadMode.Learning: + // Timeout. + return null; + + case ReadThreadMode.LearningFailed: + // Failure. + return null; + + case ReadThreadMode.LearningDone: + //_debugFile.WriteLine(_learningCode.ToByteArray()); + + if (_learningCode.FinalizeData()) + return _learningCode; // Success. + else + return null; // Failure. + + default: + return null; + } + } + + public override void Send(IrCode code, uint port) + { + byte[] data = DataPacket(code); + + TransmitIR(data, code.Carrier, port); + } + + #endregion Driver overrides + + #region Implementation + + byte[] DataPacket(IrCode code) + { + if (code.TimingData.Length == 0) + return null; + + byte[] data = new byte[code.TimingData.Length * 4]; + + int dataIndex = 0; + for (int timeIndex = 0; timeIndex < code.TimingData.Length; timeIndex++) + { + uint time = (uint)(50 * (int)Math.Round((double)code.TimingData[timeIndex] / 50)); + + for (int timeShift = 0; timeShift < 4; timeShift++) + { + data[dataIndex++] = (byte)(time & 0xFF); + time >>= 8; + } + } + + return data; + } + + void GetAllDeviceInformation() + { + GetDeviceCapabilities(); + GetBlasters(); + } + + void StartReadThread() + { + _readThread = new Thread(new ThreadStart(ReadThread)); + _readThread.IsBackground = true; + _readThread.Name = "IR Server Microsoft MCE Transceiver Read"; + _readThread.Start(); + } + void StopReadThread() + { + if (_readThread != null) + { + _readThreadMode = ReadThreadMode.Stop; + + _readThread.Abort(); + + if (Thread.CurrentThread != _readThread) + _readThread.Join(); + + _readThread = null; + } + } + + void CloseDevice() + { + if (_eHomeHandle != null) + CloseHandle(_eHomeHandle); + } + + void OnDeviceArrival() + { + _notifyWindow.UnregisterDeviceArrival(); + + StartReceive(_receivePort, PacketTimeout); + + _readThreadMode = ReadThreadMode.Receiving; + + StartReadThread(); + + _notifyWindow.RegisterDeviceRemoval(_eHomeHandle.DangerousGetHandle()); + } + void OnDeviceRemoval() + { + _notifyWindow.UnregisterDeviceRemoval(); + _notifyWindow.RegisterDeviceArrival(); + + StopReadThread(); + } + + void ReadThread() + { + int bytesRead; + TimeSpan sinceLastPacket; + DateTime lastPacketTime = DateTime.Now; + + IntPtr deviceBufferPtr = IntPtr.Zero; + IntPtr receiveParamsPtr = IntPtr.Zero; + + try + { + deviceBufferPtr = Marshal.AllocHGlobal(DeviceBufferSize); + + int receiveParamsSize = Marshal.SizeOf(typeof(ReceiveParams)) + DeviceBufferSize + 8; + receiveParamsPtr = Marshal.AllocHGlobal(receiveParamsSize); + + ReceiveParams receiveParams = new ReceiveParams(); + receiveParams.ByteCount = DeviceBufferSize; + Marshal.StructureToPtr(receiveParams, receiveParamsPtr, false); + + while (_readThreadMode != ReadThreadMode.Stop) + { + IoControlSync(IoCtrl.Receive, IntPtr.Zero, 0, receiveParamsPtr, receiveParamsSize, out bytesRead); + + if (bytesRead > Marshal.SizeOf(receiveParams)) + { + int dataSize = bytesRead; + + bytesRead -= Marshal.SizeOf(receiveParams); + + sinceLastPacket = DateTime.Now.Subtract(lastPacketTime); + if (sinceLastPacket.TotalMilliseconds >= PacketTimeout + 50) + IrDecoder.DecodeIR(null, null, null, null); + + lastPacketTime = DateTime.Now; + + byte[] packetBytes = new byte[bytesRead]; + byte[] dataBytes = new byte[dataSize]; + + Marshal.Copy(receiveParamsPtr, dataBytes, 0, dataSize); + Array.Copy(dataBytes, dataSize - bytesRead, packetBytes, 0, bytesRead); + + int[] timingData = GetTimingDataFromPacket(packetBytes); + + //_debugFile.WriteLine("Received:"); + //Dump(timingData); + + if (_readThreadMode == ReadThreadMode.Learning) + _learningCode.AddTimingData(timingData); + else + IrDecoder.DecodeIR(timingData, _remoteCallback, _keyboardCallback, _mouseCallback); + } + + // Determine carrier frequency when learning ... + if (_readThreadMode == ReadThreadMode.Learning && bytesRead >= Marshal.SizeOf(receiveParams)) + { + ReceiveParams receiveParams2 = (ReceiveParams)Marshal.PtrToStructure(receiveParamsPtr, typeof(ReceiveParams)); + + if (receiveParams2.DataEnd != 0 && receiveParams2.CarrierFrequency != 0) + { + _learningCode.Carrier = (int)receiveParams2.CarrierFrequency; + _readThreadMode = ReadThreadMode.LearningDone; + } + } + } + } + catch + { + CancelIo(_eHomeHandle); + } + finally + { + StopReceive(); + + if (deviceBufferPtr != IntPtr.Zero) + Marshal.FreeHGlobal(deviceBufferPtr); + + if (receiveParamsPtr != IntPtr.Zero) + Marshal.FreeHGlobal(receiveParamsPtr); + } + } + + #endregion Implementation + + #region Misc Methods + + static byte[] RawSerialize(object anything) + { + int rawSize = Marshal.SizeOf(anything); + byte[] rawData = new byte[rawSize]; + + GCHandle handle = GCHandle.Alloc(rawData, GCHandleType.Pinned); + IntPtr buffer = handle.AddrOfPinnedObject(); + + Marshal.StructureToPtr(anything, buffer, false); + + handle.Free(); + + return rawData; + } + + static byte ConvertBcdToByte(byte b) + { + return (byte)(((b >> 4) * 10) + (b & 15)); + } + + int FirstHighBit(uint mask) + { + for (int i = 0; i < 32; i++) + if ((mask & (1 << i)) != 0) + return i; + + return -1; + } + int FirstLowBit(uint mask) + { + for (int i = 0; i < 32; i++) + if ((mask & (1 << i)) == 0) + return i; + + return -1; + } + + static uint GetCarrierPeriod(uint carrier) + { + return (uint)(1000000 / carrier); + } + + static bool IsPulseMode(uint carrier) + { + if (carrier > 0 && carrier < 100) + return true; + + return false; + } + + static int[] GetTimingDataFromPacket(byte[] packetBytes) + { + int[] timingData = new int[packetBytes.Length / 4]; + + int timingDataIndex = 0; + + for (int index = 0; index < packetBytes.Length; index += 4) + timingData[timingDataIndex++] = + (int) + (packetBytes[index] + + (packetBytes[index + 1] << 8) + + (packetBytes[index + 2] << 16) + + (packetBytes[index + 3] << 24)); + + return timingData; + } + /* + void Dump(Array array) + { + foreach (object item in array) + { + _debugFile.Write(item); + _debugFile.Write(", "); + } + + _debugFile.WriteLine(); + } + */ + #endregion Misc Methods + + } + +} Added: 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 (rev 0) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs 2007-09-05 17:23:54 UTC (rev 895) @@ -0,0 +1,750 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Runtime.InteropServices; +using System.ServiceProcess; +using System.Text; +using System.Threading; + +using Microsoft.Win32.SafeHandles; + +namespace MicrosoftMceTransceiver +{ + + public class DriverXP : Driver + { + + #region Interop + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool GetOverlappedResult( + SafeFileHandle handle, + ref NativeOverlapped overlapped, + out int bytesTransferred, + bool wait); + + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] + static extern SafeFileHandle CreateFile( + [MarshalAs(UnmanagedType.LPTStr)] string fileName, + [MarshalAs(UnmanagedType.U4)] FileAccessTypes fileAccess, + [MarshalAs(UnmanagedType.U4)] FileShares fileShare, + IntPtr securityAttributes, + [MarshalAs(UnmanagedType.U4)] CreationDisposition creationDisposition, + [MarshalAs(UnmanagedType.U4)] FileAttributes flags, + IntPtr templateFile); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool ReadFile( + SafeFileHandle handle, + IntPtr buffer, + int bytesToRead, + out int bytesRead, + ref NativeOverlapped overlapped); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool WriteFile( + SafeFileHandle handle, + byte[] buffer, + int bytesToWrite, + out int bytesWritten, + ref NativeOverlapped overlapped); + + [DllImport("kernel32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool CancelIo( + SafeFileHandle handle); + + [DllImport("kernel32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool CloseHandle( + SafeFileHandle handle); + + #endregion Interop + + #region Enumerations + + /// <summary> + /// Type of device in use. + /// This is used to determine the blaster port selection method. + /// </summary> + enum DeviceType + { + /// <summary> + /// Device is a first party Microsoft MCE transceiver. + /// </summary> + Microsoft = 0, + /// <summary> + /// Device is an third party SMK or Topseed MCE transceiver. + /// </summary> + SmkTopseed = 1, + } + + /// <summary> + /// Device input port. + /// </summary> + enum InputPort + { + Receive = 0, + Learning = 1, + } + + /// <summary> + /// Read Thread Mode. + /// </summary> + enum ReadThreadMode + { + Receiving, + Learning, + LearningDone, + LearningFailed, + Stop, + } + + #endregion Enumerations + + #region Constants + + // Vendor ID's for SMK and Topseed devices. + const string VidSMK = "vid_1784"; + const string VidTopseed = "vid_0609"; + + // Device variables + const int DeviceBufferSize = 100; + const int PacketTimeout = 100; + const int WriteSyncTimeout = 5000; + + // Microsoft Port Packets + static readonly byte[][] MicrosoftPorts = new byte[][] + { + new byte[] { 0x9F, 0x08, 0x06 }, // Both + new byte[] { 0x9F, 0x08, 0x04 }, // 1 + new byte[] { 0x9F, 0x08, 0x02 }, // 2 + }; + + // SMK or Topseed Port Packets + static readonly byte[][] SmkTopseedPorts = new byte[][] + { + new byte[] { 0x9F, 0x08, 0x00 }, // Both + new byte[] { 0x9F, 0x08, 0x01 }, // 1 + new byte[] { 0x9F, 0x08, 0x02 }, // 2 + }; + + // Start and Stop Packets + static readonly byte[] StartPacket = { 0x00, 0xFF, 0xAA }; + static readonly byte[] StopPacket = { 0xFF, 0xBB, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + + // Misc Packets + static readonly byte[] SetCarrierFreqPacket = { 0x9F, 0x06, 0x01, 0x80 }; + static readonly byte[] SetInputPortPacket = { 0x9F, 0x14, 0x00 }; + static readonly byte[] SetTimeoutPacket = { 0x9F, 0x0C, 0x00, 0x00 }; + + #endregion Constants + + #region Variables + + NotifyWindow _notifyWindow; + + SafeFileHandle _eHomeHandle; + + Thread _readThread; + ReadThreadMode _readThreadMode; + ManualResetEvent _stopReadThread; + + IrCode _learningCode; + + DeviceType _deviceType = DeviceType.Microsoft; + + //StreamWriter _debugFile; + + #endregion Variables + + #region Constructor + + public DriverXP(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) + : base(deviceGuid, devicePath, remoteCallback, keyboardCallback, mouseCallback) + { + if (devicePath.IndexOf(VidSMK, StringComparison.InvariantCultureIgnoreCase) != -1 || devicePath.IndexOf(VidTopseed, StringComparison.InvariantCultureIgnoreCase) != -1) + _deviceType = DeviceType.SmkTopseed; + else + _deviceType = DeviceType.Microsoft; + } + + #endregion Constructor + + #region Driver overrides + + public override void Start() + { + //_debugFile = new StreamWriter("\\DriverXP.log", false); + //_debugFile.AutoFlush = true; + + _notifyWindow = new NotifyWindow(); + _notifyWindow.Class = _deviceGuid; + + int lastError; + + _eHomeHandle = CreateFile(_devicePath, FileAccessTypes.GenericRead | FileAccessTypes.GenericWrite, FileShares.None, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Overlapped, IntPtr.Zero); + lastError = Marshal.GetLastWin32Error(); + if (_eHomeHandle.IsInvalid) + throw new Win32Exception(lastError); + + // Initialize device ... + WriteSync(StartPacket); + SetTimeout(PacketTimeout); + SetInputPort(InputPort.Receive); + + StartReadThread(); + + _notifyWindow.Create(); + _notifyWindow.DeviceArrival += new DeviceEventHandler(OnDeviceArrival); + _notifyWindow.DeviceRemoval += new DeviceEventHandler(OnDeviceRemoval); + _notifyWindow.RegisterDeviceRemoval(_eHomeHandle.DangerousGetHandle()); + } + + public override void Stop() + { + WriteSync(StopPacket); + + OnDeviceRemoval(); + + CloseDevice(); + + //_debugFile.Close(); + } + + public override IrCode Learn(int learnTimeout) + { + //_debugFile.WriteLine("Start Learn"); + + _learningCode = new IrCode(); + + SetInputPort(InputPort.Learning); + + int learnStartTick = Environment.TickCount; + _readThreadMode = ReadThreadMode.Learning; + + // Wait for the learning to finish ... + while (_readThreadMode == ReadThreadMode.Learning && Environment.TickCount < learnStartTick + learnTimeout) + Thread.Sleep(100); + + //_debugFile.WriteLine("End Learn"); + + ReadThreadMode modeWas = _readThreadMode; + + _readThreadMode = ReadThreadMode.Receiving; + SetInputPort(InputPort.Receive); + + switch (modeWas) + { + case ReadThreadMode.Learning: + // Timeout. + return null; + + case ReadThreadMode.LearningFailed: + // Failure. + return null; + + case ReadThreadMode.LearningDone: + //_debugFile.WriteLine(_learningCode.ToByteArray()); + + if (_learningCode.FinalizeData()) + return _learningCode; // Success. + else + return null; // Failure. + + default: + return null; + } + } + + public override void Send(IrCode code, uint port) + { + //_debugFile.WriteLine("Send"); + + byte[] portPacket; + switch (_deviceType) + { + case DeviceType.Microsoft: portPacket = MicrosoftPorts[port]; break; + case DeviceType.SmkTopseed: portPacket = SmkTopseedPorts[port]; break; + default: + throw new Exception("Invalid device type"); + } + + //_debugFile.WriteLine(code.ToByteArray()); + + // Set port + WriteSync(portPacket); + + // Set carrier frequency + WriteSync(CarrierPacket(code)); + + // Send packet + WriteSync(DataPacket(code)); + } + + #endregion Driver overrides + + #region Implementation + + byte[] CarrierPacket(IrCode code) + { + byte[] carrierPacket = new byte[SetCarrierFreqPacket.Length]; + SetCarrierFreqPacket.CopyTo(carrierPacket, 0); + + if (code.Carrier == IrCode.CarrierFrequencyUnknown || code.Carrier == IrCode.CarrierFrequencyDCMode) + return carrierPacket; + + for (int scaler = 1; scaler <= 4; scaler++) + { + int divisor = (10000000 >> (2 * scaler)) / code.Carrier; + + if (divisor <= 0xFF) + { + carrierPacket[2] = (byte)scaler; + carrierPacket[3] = (byte)divisor; + break; + } + } + + return carrierPacket; + } + + byte[] DataPacket(IrCode code) + { + if (code.TimingData.Length == 0) + return null; + + // Construct data bytes into "packet" ... + List<byte> packet = new List<byte>(); + + for (int index = 0; index < code.TimingData.Length; index++) + { + double time = (double)code.TimingData[index]; + + byte duration = (byte)Math.Abs(Math.Round(time / 50)); + bool pulse = (time > 0); + + while (duration > 0x7F) + { + packet.Add((byte)(pulse ? 0xFF : 0x7F)); + + duration -= 0x7F; + } + + packet.Add((byte)(pulse ? 0x80 | duration : duration)); + } + + // Insert byte count markers into packet data bytes ... + int subpackets = (int)Math.Ceiling(packet.Count / (double)4); + + byte[] output = new byte[packet.Count + subpackets + 1]; + + int outputPos = 0; + + for (int packetPos = 0; packetPos < packet.Count; ) + { + byte copyCount = (byte)(packet.Count - packetPos < 4 ? packet.Count - packetPos : 0x04); + + output[outputPos++] = (byte)(0x80 | copyCount); + + for (int index = 0; index < copyCount; index++) + output[outputPos++] = packet[packetPos++]; + } + + output[outputPos] = 0x80; + + return output; + } + + /// <summary> + /// Set the receive buffer timeout. + /// </summary> + /// <param name="timeout">Packet timeout (in milliseconds).</param> + void SetTimeout(int timeout) + { + byte[] timeoutPacket = new byte[SetTimeoutPacket.Length]; + SetTimeoutPacket.CopyTo(timeoutPacket, 0); + + int timeoutSamples = 20 * timeout; + + timeoutPacket[2] = (byte)(timeoutSamples >> 8); + timeoutPacket[3] = (byte)(timeoutSamples % 256); + + WriteSync(timeoutPacket); + } + + void SetInputPort(InputPort port) + { + byte[] inputPortPacket = new byte[SetInputPortPacket.Length]; + SetInputPortPacket.CopyTo(inputPortPacket, 0); + + inputPortPacket[2] = (byte)(port + 1); + + WriteSync(inputPortPacket); + } + + void StartReadThread() + { + _stopReadThread = new ManualResetEvent(false); + _readThreadMode = ReadThreadMode.Receiving; + + _readThread = new Th... [truncated message content] |
From: <an...@us...> - 2007-09-06 16:53:27
|
Revision: 898 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=898&view=rev Author: and-81 Date: 2007-09-06 09:50:58 -0700 (Thu, 06 Sep 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Driver.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrCode.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Keyboard.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/MicrosoftMceTransceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/NotifyWindow.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Pronto.cs Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Driver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Driver.cs 2007-09-06 15:59:39 UTC (rev 897) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Driver.cs 2007-09-06 16:50:58 UTC (rev 898) @@ -20,7 +20,7 @@ #region Enumerations [Flags] - enum Digcfs + enum Digcfs : uint { None = 0x00, Default = 0x01, @@ -31,15 +31,24 @@ } [Flags] - public enum FileShares + protected enum CreateFileAccessTypes : uint { + GenericRead = 0x80000000, + GenericWrite = 0x40000000, + GenericExecute = 0x20000000, + GenericAll = 0x10000000, + } + + [Flags] + protected enum CreateFileShares : uint + { None = 0x00, Read = 0x01, Write = 0x02, Delete = 0x04, } - public enum CreationDisposition + protected enum CreateFileDisposition : uint { None = 0, New = 1, @@ -50,7 +59,7 @@ } [Flags] - public enum FileAttributes : uint + protected enum CreateFileAttributes : uint { Readonly = 0x00000001, Hidden = 0x00000002, @@ -79,15 +88,6 @@ FirstPipeInstance = 0x00080000, } - [Flags] - public enum FileAccessTypes : uint - { - GenericRead = 0x80000000, - GenericWrite = 0x40000000, - GenericExecute = 0x20000000, - GenericAll = 0x10000000, - } - #endregion Enumerations #region Structures @@ -185,9 +185,12 @@ #region Constructors - public Driver() { } - public Driver(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) + protected Driver() { } + protected Driver(Guid deviceGuid, string devicePath, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) { + if (String.IsNullOrEmpty(devicePath)) + throw new ArgumentException("Null or Empty device path supplied", "devicePath"); + _deviceGuid = deviceGuid; _devicePath = devicePath; Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs 2007-09-06 15:59:39 UTC (rev 897) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs 2007-09-06 16:50:58 UTC (rev 898) @@ -23,16 +23,16 @@ SafeFileHandle handle, ref NativeOverlapped overlapped, out int bytesTransferred, - bool wait); + [MarshalAs(UnmanagedType.Bool)] bool wait); [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern SafeFileHandle CreateFile( [MarshalAs(UnmanagedType.LPTStr)] string fileName, - [MarshalAs(UnmanagedType.U4)] FileAccessTypes fileAccess, - [MarshalAs(UnmanagedType.U4)] FileShares fileShare, + [MarshalAs(UnmanagedType.U4)] CreateFileAccessTypes fileAccess, + [MarshalAs(UnmanagedType.U4)] CreateFileShares fileShare, IntPtr securityAttributes, - [MarshalAs(UnmanagedType.U4)] CreationDisposition creationDisposition, - [MarshalAs(UnmanagedType.U4)] FileAttributes flags, + [MarshalAs(UnmanagedType.U4)] CreateFileDisposition creationDisposition, + [MarshalAs(UnmanagedType.U4)] CreateFileAttributes flags, IntPtr templateFile); [DllImport("kernel32.dll", SetLastError = true)] @@ -109,8 +109,8 @@ #region Constants // Vendor ID's for SMK and Topseed devices. - const string VidSMK = "vid_1784"; - const string VidTopseed = "vid_0609"; + const string VidSMK = "vid_1784"; + const string VidTopseed = "vid_0609"; // Device variables const int DeviceBufferSize = 100; @@ -188,12 +188,12 @@ int lastError; - _readHandle = CreateFile(_devicePath + "\\Pipe01", FileAccessTypes.GenericRead, FileShares.None, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Overlapped, IntPtr.Zero); + _readHandle = CreateFile(_devicePath + "\\Pipe01", CreateFileAccessTypes.GenericRead, CreateFileShares.None, IntPtr.Zero, CreateFileDisposition.OpenExisting, CreateFileAttributes.Overlapped, IntPtr.Zero); lastError = Marshal.GetLastWin32Error(); if (_readHandle.IsInvalid) throw new Win32Exception(lastError); - _writeHandle = CreateFile(_devicePath + "\\Pipe00", FileAccessTypes.GenericWrite, FileShares.None, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Overlapped, IntPtr.Zero); + _writeHandle = CreateFile(_devicePath + "\\Pipe00", CreateFileAccessTypes.GenericWrite, CreateFileShares.None, IntPtr.Zero, CreateFileDisposition.OpenExisting, CreateFileAttributes.Overlapped, IntPtr.Zero); lastError = Marshal.GetLastWin32Error(); if (_writeHandle.IsInvalid) throw new Win32Exception(lastError); @@ -296,7 +296,7 @@ #region Implementation - byte[] CarrierPacket(IrCode code) + static byte[] CarrierPacket(IrCode code) { byte[] carrierPacket = new byte[SetCarrierFreqPacket.Length]; SetCarrierFreqPacket.CopyTo(carrierPacket, 0); @@ -319,7 +319,7 @@ return carrierPacket; } - byte[] DataPacket(IrCode code) + static byte[] DataPacket(IrCode code) { if (code.TimingData.Length == 0) return null; @@ -518,7 +518,7 @@ continue; sinceLastPacket = DateTime.Now.Subtract(lastPacketTime); - if (sinceLastPacket.TotalMilliseconds >= PacketTimeout) + if (sinceLastPacket.TotalMilliseconds >= PacketTimeout + 50) IrDecoder.DecodeIR(null, null, null, null); lastPacketTime = DateTime.Now; @@ -609,7 +609,7 @@ } } - catch + catch (Exception) { CancelIo(_readHandle); } @@ -693,7 +693,7 @@ } } - int[] GetTimingDataFromPacket(byte[] packet) + static int[] GetTimingDataFromPacket(byte[] packet) { List<int> timingData = new List<int>(); @@ -737,7 +737,7 @@ return timingData.ToArray(); } - void GetIrCodeLengths(IrCode code, out int onTime, out int onCount) + static void GetIrCodeLengths(IrCode code, out int onTime, out int onCount) { onTime = 0; onCount = 0; Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs 2007-09-06 15:59:39 UTC (rev 897) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs 2007-09-06 16:50:58 UTC (rev 898) @@ -220,30 +220,20 @@ [DllImport("kernel32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] - static extern bool DeviceIoControl( - SafeFileHandle handle, - [MarshalAs(UnmanagedType.U4)] IoCtrl ioControlCode, - IntPtr inBuffer, int inBufferSize, - IntPtr outBuffer, int outBufferSize, - out int bytesReturned, - IntPtr overlapped); - - [DllImport("kernel32.dll", SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] static extern bool GetOverlappedResult( SafeFileHandle handle, ref NativeOverlapped overlapped, out int bytesTransferred, - bool wait); + [MarshalAs(UnmanagedType.Bool)] bool wait); [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern SafeFileHandle CreateFile( [MarshalAs(UnmanagedType.LPTStr)] string fileName, - [MarshalAs(UnmanagedType.U4)] FileAccessTypes fileAccess, - [MarshalAs(UnmanagedType.U4)] FileShares fileShare, + [MarshalAs(UnmanagedType.U4)] CreateFileAccessTypes fileAccess, + [MarshalAs(UnmanagedType.U4)] CreateFileShares fileShare, IntPtr securityAttributes, - [MarshalAs(UnmanagedType.U4)] CreationDisposition creationDisposition, - [MarshalAs(UnmanagedType.U4)] FileAttributes flags, + [MarshalAs(UnmanagedType.U4)] CreateFileDisposition creationDisposition, + [MarshalAs(UnmanagedType.U4)] CreateFileAttributes flags, IntPtr templateFile); [DllImport("kernel32.dll")] @@ -262,16 +252,16 @@ #region Device Details - uint _numTxPorts = 0; - uint _numRxPorts = 0; + uint _numTxPorts = 0; + //uint _numRxPorts = 0; uint _learnPortMask = 0; - bool _legacyDevice = false; - bool _canFlashLed = false; + //bool _legacyDevice = false; + //bool _canFlashLed = false; bool[] _blasters; - uint _receivePort = 0; - uint _learnPort = 0; + uint _receivePort = 0; + uint _learnPort = 0; #endregion Device Details @@ -358,7 +348,7 @@ } _numTxPorts = structure.TransmitPorts; - _numRxPorts = structure.ReceivePorts; + //_numRxPorts = structure.ReceivePorts; _learnPortMask = structure.LearningMask; int receivePort = FirstLowBit(_learnPortMask); @@ -371,9 +361,9 @@ else _learnPort = _receivePort; - DeviceCapabilityFlags flags = structure.DetailsFlags; - _legacyDevice = (int)(flags & DeviceCapabilityFlags.Legacy) != 0; - _canFlashLed = (int)(flags & DeviceCapabilityFlags.FlashLed) != 0; + //DeviceCapabilityFlags flags = structure.DetailsFlags; + //_legacyDevice = (int)(flags & DeviceCapabilityFlags.Legacy) != 0; + //_canFlashLed = (int)(flags & DeviceCapabilityFlags.FlashLed) != 0; } void GetBlasters() @@ -520,7 +510,7 @@ _notifyWindow = new NotifyWindow(); _notifyWindow.Class = _deviceGuid; - _eHomeHandle = CreateFile(_devicePath, FileAccessTypes.GenericRead | FileAccessTypes.GenericWrite, FileShares.None, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Overlapped, IntPtr.Zero); + _eHomeHandle = CreateFile(_devicePath, CreateFileAccessTypes.GenericRead | CreateFileAccessTypes.GenericWrite, CreateFileShares.None, IntPtr.Zero, CreateFileDisposition.OpenExisting, CreateFileAttributes.Overlapped, IntPtr.Zero); int lastError = Marshal.GetLastWin32Error(); if (_eHomeHandle.IsInvalid) throw new Win32Exception(lastError); @@ -613,7 +603,7 @@ #region Implementation - byte[] DataPacket(IrCode code) + static byte[] DataPacket(IrCode code) { if (code.TimingData.Length == 0) return null; @@ -755,7 +745,7 @@ } } } - catch + catch (Exception) { CancelIo(_eHomeHandle); } @@ -790,20 +780,15 @@ return rawData; } - static byte ConvertBcdToByte(byte b) + static int FirstHighBit(uint mask) { - return (byte)(((b >> 4) * 10) + (b & 15)); - } - - int FirstHighBit(uint mask) - { for (int i = 0; i < 32; i++) if ((mask & (1 << i)) != 0) return i; return -1; } - int FirstLowBit(uint mask) + static int FirstLowBit(uint mask) { for (int i = 0; i < 32; i++) if ((mask & (1 << i)) == 0) 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 2007-09-06 15:59:39 UTC (rev 897) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs 2007-09-06 16:50:58 UTC (rev 898) @@ -23,16 +23,16 @@ SafeFileHandle handle, ref NativeOverlapped overlapped, out int bytesTransferred, - bool wait); + [MarshalAs(UnmanagedType.Bool)] bool wait); [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] static extern SafeFileHandle CreateFile( [MarshalAs(UnmanagedType.LPTStr)] string fileName, - [MarshalAs(UnmanagedType.U4)] FileAccessTypes fileAccess, - [MarshalAs(UnmanagedType.U4)] FileShares fileShare, + [MarshalAs(UnmanagedType.U4)] CreateFileAccessTypes fileAccess, + [MarshalAs(UnmanagedType.U4)] CreateFileShares fileShare, IntPtr securityAttributes, - [MarshalAs(UnmanagedType.U4)] CreationDisposition creationDisposition, - [MarshalAs(UnmanagedType.U4)] FileAttributes flags, + [MarshalAs(UnmanagedType.U4)] CreateFileDisposition creationDisposition, + [MarshalAs(UnmanagedType.U4)] CreateFileAttributes flags, IntPtr templateFile); [DllImport("kernel32.dll", SetLastError = true)] @@ -109,8 +109,8 @@ #region Constants // Vendor ID's for SMK and Topseed devices. - const string VidSMK = "vid_1784"; - const string VidTopseed = "vid_0609"; + const string VidSMK = "vid_1784"; + const string VidTopseed = "vid_0609"; // Device variables const int DeviceBufferSize = 100; @@ -187,7 +187,7 @@ int lastError; - _eHomeHandle = CreateFile(_devicePath, FileAccessTypes.GenericRead | FileAccessTypes.GenericWrite, FileShares.None, IntPtr.Zero, CreationDisposition.OpenExisting, FileAttributes.Overlapped, IntPtr.Zero); + _eHomeHandle = CreateFile(_devicePath, CreateFileAccessTypes.GenericRead | CreateFileAccessTypes.GenericWrite, CreateFileShares.None, IntPtr.Zero, CreateFileDisposition.OpenExisting, CreateFileAttributes.Overlapped, IntPtr.Zero); lastError = Marshal.GetLastWin32Error(); if (_eHomeHandle.IsInvalid) throw new Win32Exception(lastError); @@ -274,7 +274,7 @@ throw new Exception("Invalid device type"); } - //_debugFile.WriteLine(code.ToByteArray()); + //Dump(code.ToByteArray()); // Set port WriteSync(portPacket); @@ -290,7 +290,7 @@ #region Implementation - byte[] CarrierPacket(IrCode code) + static byte[] CarrierPacket(IrCode code) { byte[] carrierPacket = new byte[SetCarrierFreqPacket.Length]; SetCarrierFreqPacket.CopyTo(carrierPacket, 0); @@ -313,7 +313,7 @@ return carrierPacket; } - byte[] DataPacket(IrCode code) + static byte[] DataPacket(IrCode code) { if (code.TimingData.Length == 0) return null; @@ -600,7 +600,7 @@ } } - catch + catch (Exception) { CancelIo(_eHomeHandle); } @@ -684,7 +684,7 @@ } } - int[] GetTimingDataFromPacket(byte[] packet) + static int[] GetTimingDataFromPacket(byte[] packet) { List<int> timingData = new List<int>(); @@ -728,7 +728,7 @@ return timingData.ToArray(); } - void GetIrCodeLengths(IrCode code, out int onTime, out int onCount) + static void GetIrCodeLengths(IrCode code, out int onTime, out int onCount) { onTime = 0; onCount = 0; Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrCode.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrCode.cs 2007-09-06 15:59:39 UTC (rev 897) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/IrCode.cs 2007-09-06 16:50:58 UTC (rev 898) @@ -108,8 +108,8 @@ /// <summary> /// Add timing data to this IR code. /// </summary> - /// <param name="addTimingData">Addition timing data.</param> - public void AddTimingData(int[] addTimingData) + /// <param name="timingData">Addition timing data.</param> + public void AddTimingData(int[] timingData) { List<int> newTimingData = new List<int>(); @@ -122,28 +122,25 @@ } else if (_timingData.Length == 0) { - _timingData = new int[addTimingData.Length]; - addTimingData.CopyTo(_timingData, 0); + _timingData = new int[timingData.Length]; + timingData.CopyTo(_timingData, 0); return; } - if (addTimingData.Length == 0 || index >= _timingData.Length) - { + if (timingData.Length == 0 || index >= _timingData.Length) return; - } - - if (Math.Sign(addTimingData[0]) == Math.Sign(_timingData[index])) + if (Math.Sign(timingData[0]) == Math.Sign(_timingData[index])) { - newTimingData.Add(_timingData[index] + addTimingData[0]); + newTimingData.Add(_timingData[index] + timingData[0]); - for (index = 1; index < addTimingData.Length; index++) - newTimingData.Add(addTimingData[index]); + for (index = 1; index < timingData.Length; index++) + newTimingData.Add(timingData[index]); } else { newTimingData.Add(_timingData[index]); - newTimingData.AddRange(addTimingData); + newTimingData.AddRange(timingData); } _timingData = newTimingData.ToArray(); Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Keyboard.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Keyboard.cs 2007-09-06 15:59:39 UTC (rev 897) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Keyboard.cs 2007-09-06 16:50:58 UTC (rev 898) @@ -28,146 +28,146 @@ /// </summary> public enum VKey { - None = 0, - VK_0 = 0x30, - VK_1 = 0x31, - VK_2 = 0x32, - VK_3 = 0x33, - VK_4 = 0x34, - VK_5 = 0x35, - VK_6 = 0x36, - VK_7 = 0x37, - VK_8 = 0x38, - VK_9 = 0x39, - VK_A = 0x41, - VK_B = 0x42, - VK_C = 0x43, - VK_D = 0x44, - VK_E = 0x45, - VK_F = 0x46, - VK_G = 0x47, - VK_H = 0x48, - VK_I = 0x49, - VK_J = 0x4A, - VK_K = 0x4B, - VK_L = 0x4C, - VK_M = 0x4D, - VK_N = 0x4E, - VK_O = 0x4F, - VK_P = 0x50, - VK_Q = 0x51, - VK_R = 0x52, - VK_S = 0x53, - VK_T = 0x54, - VK_U = 0x55, - VK_V = 0x56, - VK_W = 0x57, - VK_X = 0x58, - VK_Y = 0x59, - VK_Z = 0x5A, - VK_ADD = 0x6B, - VK_APPS = 0x5D, - VK_ATTN = 0xF6, - VK_BACK = 0x8, - VK_CANCEL = 0x3, - VK_CAPITAL = 0x14, - VK_CLEAR = 0xC, - VK_CONTROL = 0x11, - VK_CRSEL = 0xF7, - VK_DECIMAL = 0x6E, - VK_DELETE = 0x2E, - VK_DIVIDE = 0x6F, - VK_DOWN = 0x28, - VK_END = 0x23, - VK_EREOF = 0xF9, - VK_ESCAPE = 0x1B, - VK_EXECUTE = 0x2B, - VK_EXSEL = 0xF8, - VK_F1 = 0x70, - VK_F2 = 0x71, - VK_F3 = 0x72, - VK_F4 = 0x73, - VK_F5 = 0x74, - VK_F6 = 0x75, - VK_F7 = 0x76, - VK_F8 = 0x77, - VK_F9 = 0x78, - VK_F10 = 0x79, - VK_F11 = 0x7A, - VK_F12 = 0x7B, - VK_F13 = 0x7C, - VK_F14 = 0x7D, - VK_F15 = 0x7E, - VK_F16 = 0x7F, - VK_F17 = 0x80, - VK_F18 = 0x81, - VK_F19 = 0x82, - VK_F20 = 0x83, - VK_F21 = 0x84, - VK_F22 = 0x85, - VK_F23 = 0x86, - VK_F24 = 0x87, - VK_HELP = 0x2F, - VK_HOME = 0x24, - VK_INSERT = 0x2D, - VK_LBUTTON = 0x1, + None = 0, + VK_0 = 0x30, + VK_1 = 0x31, + VK_2 = 0x32, + VK_3 = 0x33, + VK_4 = 0x34, + VK_5 = 0x35, + VK_6 = 0x36, + VK_7 = 0x37, + VK_8 = 0x38, + VK_9 = 0x39, + VK_A = 0x41, + VK_B = 0x42, + VK_C = 0x43, + VK_D = 0x44, + VK_E = 0x45, + VK_F = 0x46, + VK_G = 0x47, + VK_H = 0x48, + VK_I = 0x49, + VK_J = 0x4A, + VK_K = 0x4B, + VK_L = 0x4C, + VK_M = 0x4D, + VK_N = 0x4E, + VK_O = 0x4F, + VK_P = 0x50, + VK_Q = 0x51, + VK_R = 0x52, + VK_S = 0x53, + VK_T = 0x54, + VK_U = 0x55, + VK_V = 0x56, + VK_W = 0x57, + VK_X = 0x58, + VK_Y = 0x59, + VK_Z = 0x5A, + VK_ADD = 0x6B, + VK_APPS = 0x5D, + VK_ATTN = 0xF6, + VK_BACK = 0x8, + VK_CANCEL = 0x3, + VK_CAPITAL = 0x14, + VK_CLEAR = 0xC, + VK_CONTROL = 0x11, + VK_CRSEL = 0xF7, + VK_DECIMAL = 0x6E, + VK_DELETE = 0x2E, + VK_DIVIDE = 0x6F, + VK_DOWN = 0x28, + VK_END = 0x23, + VK_EREOF = 0xF9, + VK_ESCAPE = 0x1B, + VK_EXECUTE = 0x2B, + VK_EXSEL = 0xF8, + VK_F1 = 0x70, + VK_F2 = 0x71, + VK_F3 = 0x72, + VK_F4 = 0x73, + VK_F5 = 0x74, + VK_F6 = 0x75, + VK_F7 = 0x76, + VK_F8 = 0x77, + VK_F9 = 0x78, + VK_F10 = 0x79, + VK_F11 = 0x7A, + VK_F12 = 0x7B, + VK_F13 = 0x7C, + VK_F14 = 0x7D, + VK_F15 = 0x7E, + VK_F16 = 0x7F, + VK_F17 = 0x80, + VK_F18 = 0x81, + VK_F19 = 0x82, + VK_F20 = 0x83, + VK_F21 = 0x84, + VK_F22 = 0x85, + VK_F23 = 0x86, + VK_F24 = 0x87, + VK_HELP = 0x2F, + VK_HOME = 0x24, + VK_INSERT = 0x2D, + VK_LBUTTON = 0x1, VK_LCONTROL = 0xA2, - VK_LEFT = 0x25, - VK_LMENU = 0xA4, - VK_LSHIFT = 0xA0, - VK_LWIN = 0x5B, - VK_MBUTTON = 0x4, - VK_MENU = 0x12, + VK_LEFT = 0x25, + VK_LMENU = 0xA4, + VK_LSHIFT = 0xA0, + VK_LWIN = 0x5B, + VK_MBUTTON = 0x4, + VK_MENU = 0x12, VK_MULTIPLY = 0x6A, - VK_NEXT = 0x22, - VK_NONAME = 0xFC, - VK_NUMLOCK = 0x90, - VK_NUMPAD0 = 0x60, - VK_NUMPAD1 = 0x61, - VK_NUMPAD2 = 0x62, - VK_NUMPAD3 = 0x63, - VK_NUMPAD4 = 0x64, - VK_NUMPAD5 = 0x65, - VK_NUMPAD6 = 0x66, - VK_NUMPAD7 = 0x67, - VK_NUMPAD8 = 0x68, - VK_NUMPAD9 = 0x69, - VK_OEM_1 = 0xBA, // ";:" - VK_OEM_2 = 0xBF, // "/?" - VK_OEM_3 = 0xC0, // "`~" for US - VK_OEM_4 = 0xDB, // "[{" for US - VK_OEM_5 = 0xDC, // "\|" for US - VK_OEM_6 = 0xDD, // "]}" for US - VK_OEM_7 = 0xDE, // "'"" for US - VK_OEM_102 = 0xE2, + VK_NEXT = 0x22, + VK_NONAME = 0xFC, + VK_NUMLOCK = 0x90, + VK_NUMPAD0 = 0x60, + VK_NUMPAD1 = 0x61, + VK_NUMPAD2 = 0x62, + VK_NUMPAD3 = 0x63, + VK_NUMPAD4 = 0x64, + VK_NUMPAD5 = 0x65, + VK_NUMPAD6 = 0x66, + VK_NUMPAD7 = 0x67, + VK_NUMPAD8 = 0x68, + VK_NUMPAD9 = 0x69, + VK_OEM_1 = 0xBA, // ";:" + VK_OEM_2 = 0xBF, // "/?" + VK_OEM_3 = 0xC0, // "`~" for US + VK_OEM_4 = 0xDB, // "[{" for US + VK_OEM_5 = 0xDC, // "\|" for US + VK_OEM_6 = 0xDD, // "]}" for US + VK_OEM_7 = 0xDE, // "'"" for US + VK_OEM_102 = 0xE2, VK_OEM_CLEAR = 0xFE, VK_OEM_COMMA = 0xBC, VK_OEM_MINUS = 0xBD, VK_OEM_PERIOD = 0xBE, VK_OEM_PLUS = 0xBB, // "+=" - VK_PA1 = 0xFD, - VK_PAUSE = 0x13, - VK_PLAY = 0xFA, - VK_PRINT = 0x2A, - VK_PRIOR = 0x21, + VK_PA1 = 0xFD, + VK_PAUSE = 0x13, + VK_PLAY = 0xFA, + VK_PRINT = 0x2A, + VK_PRIOR = 0x21, VK_PROCESSKEY = 0xE5, - VK_RBUTTON = 0x2, + VK_RBUTTON = 0x2, VK_RCONTROL = 0xA3, - VK_RETURN = 0xD, - VK_RIGHT = 0x27, - VK_RMENU = 0xA5, - VK_RSHIFT = 0xA1, - VK_RWIN = 0x5C, - VK_SCROLL = 0x91, - VK_SELECT = 0x29, + VK_RETURN = 0xD, + VK_RIGHT = 0x27, + VK_RMENU = 0xA5, + VK_RSHIFT = 0xA1, + VK_RWIN = 0x5C, + VK_SCROLL = 0x91, + VK_SELECT = 0x29, VK_SEPARATOR = 0x6C, - VK_SHIFT = 0x10, + VK_SHIFT = 0x10, VK_SNAPSHOT = 0x2C, - VK_SPACE = 0x20, + VK_SPACE = 0x20, VK_SUBTRACT = 0x6D, - VK_TAB = 0x9, - VK_UP = 0x26, - VK_ZOOM = 0xFB, + VK_TAB = 0x9, + VK_UP = 0x26, + VK_ZOOM = 0xFB, } /// <summary> @@ -176,11 +176,11 @@ [Flags] public enum KeyEvents { - KeyDown = 0, - ExtendedKey = 1, - KeyUp = 2, - Unicode = 4, - ScanCode = 8, + KeyDown = 0x00, + ExtendedKey = 0x01, + KeyUp = 0x02, + Unicode = 0x04, + ScanCode = 0x08, } #endregion Enumerations Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/MicrosoftMceTransceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/MicrosoftMceTransceiver.cs 2007-09-06 15:59:39 UTC (rev 897) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/MicrosoftMceTransceiver.cs 2007-09-06 16:50:58 UTC (rev 898) @@ -101,8 +101,6 @@ Mouse.MouseEvents _mouseButtons = Mouse.MouseEvents.None; - DateTime _lastPacketTime = DateTime.Now; - RemoteHandler _remoteHandler = null; KeyboardHandler _keyboardHandler = null; MouseHandler _mouseHandler = null; Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/NotifyWindow.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/NotifyWindow.cs 2007-09-06 15:59:39 UTC (rev 897) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/NotifyWindow.cs 2007-09-06 16:50:58 UTC (rev 898) @@ -68,7 +68,8 @@ [DllImport("kernel32")] [return: MarshalAs(UnmanagedType.Bool)] - static extern bool CancelIo(IntPtr handle); + static extern bool CancelIo( + IntPtr handle); #endregion Interop Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Pronto.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Pronto.cs 2007-09-06 15:59:39 UTC (rev 897) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Pronto.cs 2007-09-06 16:50:58 UTC (rev 898) @@ -78,33 +78,31 @@ /// </summary> /// <param name="fileName">File to write Pronto data to.</param> /// <param name="prontoData">Pronto data to write.</param> - /// <returns>Success.</returns> - public static bool WriteProntoFile(string fileName, ushort[] prontoData) + public static void WriteProntoFile(string fileName, ushort[] prontoData) { - try - { - StreamWriter file = new StreamWriter(fileName, false); + if (String.IsNullOrEmpty(fileName)) + throw new ArgumentException("Null or Empty filename provided.", "fileName"); - for (int index = 0; index < prontoData.Length; index++) - { - file.Write(String.Format("{0:X4}", prontoData[index])); - if (index != prontoData.Length - 1) - file.Write(' '); - } + if (prontoData == null || prontoData.Length == 0) + throw new ArgumentException("Null or Empty pronto data provided.", "prontoData"); - file.Flush(); - file.Close(); - } - catch + StreamWriter file = new StreamWriter(fileName, false); + + for (int index = 0; index < prontoData.Length; index++) { - return false; + file.Write(String.Format("{0:X4}", prontoData[index])); + if (index != prontoData.Length - 1) + file.Write(' '); } - return true; + file.Close(); } public static IrCode ConvertProntoDataToIrCode(ushort[] prontoData) { + if (prontoData == null || prontoData.Length == 0) + throw new ArgumentException("Null or Empty pronto data provided.", "prontoData"); + switch ((CodeType)prontoData[0]) { case CodeType.RawOscillated: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2008-03-16 12:25:28
|
Revision: 1471 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1471&view=rev Author: and-81 Date: 2008-03-16 05:25:27 -0700 (Sun, 16 Mar 2008) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs 2008-03-16 12:17:24 UTC (rev 1470) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs 2008-03-16 12:25:27 UTC (rev 1471) @@ -793,18 +793,20 @@ packetBytes = new byte[bytesRead]; Marshal.Copy(deviceBufferPtr, packetBytes, 0, bytesRead); +#if DEBUG + DebugWriteLine("Received data:"); + DebugDump(packetBytes); +#endif + int[] timingData = null; - if (_decodeCarry != 0 || packetBytes[0] >= 0x81 && packetBytes[0] <= 0x8F) + if (_decodeCarry != 0 || packetBytes[0] >= 0x81 && packetBytes[0] <= 0x9E) { timingData = GetTimingDataFromPacket(packetBytes); } #if DEBUG else { - DebugWriteLine("Received data:"); - DebugDump(packetBytes); - double firmware = 0.0; int indexOfFF = Array.IndexOf(packetBytes, (byte)0xFF); 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-03-16 12:17:24 UTC (rev 1470) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs 2008-03-16 12:25:27 UTC (rev 1471) @@ -771,18 +771,20 @@ packetBytes = new byte[bytesRead]; Marshal.Copy(deviceBufferPtr, packetBytes, 0, bytesRead); +#if DEBUG + DebugWriteLine("Received data:"); + DebugDump(packetBytes); +#endif + int[] timingData = null; - if (_decodeCarry != 0 || packetBytes[0] >= 0x81 && packetBytes[0] <= 0x8F) + if (_decodeCarry != 0 || packetBytes[0] >= 0x81 && packetBytes[0] <= 0x9E) { timingData = GetTimingDataFromPacket(packetBytes); } #if DEBUG else { - DebugWriteLine("Received data:"); - DebugDump(packetBytes); - double firmware = 0.0; int indexOfFF = Array.IndexOf(packetBytes, (byte)0xFF); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2008-03-21 16:06:27
|
Revision: 1494 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1494&view=rev Author: and-81 Date: 2008-03-21 09:06:23 -0700 (Fri, 21 Mar 2008) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs 2008-03-21 15:43:28 UTC (rev 1493) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs 2008-03-21 16:06:23 UTC (rev 1494) @@ -133,7 +133,7 @@ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - static readonly byte[] ResetPacket = { 0xFF, 0xFE }; + //static readonly byte[] ResetPacket = { 0xFF, 0xFE }; // Misc Packets static readonly byte[] SetCarrierFreqPacket = { 0x9F, 0x06, 0x01, 0x80 }; 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-03-21 15:43:28 UTC (rev 1493) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs 2008-03-21 16:06:23 UTC (rev 1494) @@ -133,7 +133,7 @@ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; - static readonly byte[] ResetPacket = { 0xFF, 0xEE }; + //static readonly byte[] ResetPacket = { 0xFF, 0xEE }; // Misc Packets static readonly byte[] SetCarrierFreqPacket = { 0x9F, 0x06, 0x01, 0x80 }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2008-04-12 15:47:03
|
Revision: 1636 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1636&view=rev Author: and-81 Date: 2008-04-12 08:46:56 -0700 (Sat, 12 Apr 2008) Log Message: ----------- Added more logging for MCE devices Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs 2008-04-12 11:43:48 UTC (rev 1635) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverReplacement.cs 2008-04-12 15:46:56 UTC (rev 1636) @@ -186,6 +186,8 @@ #if DEBUG DebugOpen("MicrosoftMceTransceiver_DriverReplacement.log"); DebugWriteLine("Start()"); + DebugWriteLine("Device Guid: {0}", _deviceGuid); + DebugWriteLine("Device Path: {0}", _devicePath); DebugWriteLine("Device Type: {0}", Enum.GetName(typeof(DeviceType), _deviceType)); #endif Modified: trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs 2008-04-12 11:43:48 UTC (rev 1635) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverVista.cs 2008-04-12 15:46:56 UTC (rev 1636) @@ -584,6 +584,8 @@ #if DEBUG DebugOpen("MicrosoftMceTransceiver_DriverVista.log"); DebugWriteLine("Start()"); + DebugWriteLine("Device Guid: {0}", _deviceGuid); + DebugWriteLine("Device Path: {0}", _devicePath); #endif _notifyWindow = new NotifyWindow(); 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-04-12 11:43:48 UTC (rev 1635) +++ trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/DriverXP.cs 2008-04-12 15:46:56 UTC (rev 1636) @@ -185,6 +185,8 @@ #if DEBUG DebugOpen("MicrosoftMceTransceiver_DriverXP.log"); DebugWriteLine("Start()"); + DebugWriteLine("Device Guid: {0}", _deviceGuid); + DebugWriteLine("Device Path: {0}", _devicePath); DebugWriteLine("Device Type: {0}", Enum.GetName(typeof(DeviceType), _deviceType)); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |