using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Linq;
using Crestron;
using Crestron.Logos.SplusLibrary;
using Crestron.Logos.SplusObjects;
using Crestron.SimplSharp;

namespace UserModule_BLUSTREAM
{
    public class UserModuleClass_BLUSTREAM : SplusObject
    {
        static CCriticalSection g_criticalSection = new CCriticalSection();
        
        
        
        Crestron.Logos.SplusObjects.BufferInput TOMODULE__DOLLAR__;
        Crestron.Logos.SplusObjects.DigitalOutput POWER_ON_FB;
        Crestron.Logos.SplusObjects.DigitalOutput POWER_OFF_FB;
        Crestron.Logos.SplusObjects.DigitalOutput IR_ON_FB;
        Crestron.Logos.SplusObjects.DigitalOutput IR_OFF_FB;
        Crestron.Logos.SplusObjects.DigitalOutput KEY_ON_FB;
        Crestron.Logos.SplusObjects.DigitalOutput KEY_OFF_FB;
        Crestron.Logos.SplusObjects.DigitalOutput DBG_ON_FB;
        Crestron.Logos.SplusObjects.DigitalOutput DBG_OFF_FB;
        Crestron.Logos.SplusObjects.DigitalOutput BEEP_ON_FB;
        Crestron.Logos.SplusObjects.DigitalOutput BEEP_OFF_FB;
        Crestron.Logos.SplusObjects.DigitalOutput LCD_ON_FB;
        Crestron.Logos.SplusObjects.DigitalOutput LCD_OFF_FB;
        InOutArray<Crestron.Logos.SplusObjects.AnalogOutput> OUTPUT;
        object TOMODULE__DOLLAR___OnChange_0 ( Object __EventInfo__ )
        
            { 
            Crestron.Logos.SplusObjects.SignalEventArgs __SignalEventArg__ = (Crestron.Logos.SplusObjects.SignalEventArgs)__EventInfo__;
            try
            {
                SplusExecutionContext __context__ = SplusThreadStartCode(__SignalEventArg__);
                ushort OUTPUT_FB = 0;
                ushort INPUT_FB = 0;
                ushort MYSTATUS = 0;
                
                CrestronString MYSTR;
                CrestronString MYDUMMY;
                MYSTR  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 70, this );
                MYDUMMY  = new CrestronString( Crestron.Logos.SplusObjects.CrestronStringEncoding.eEncodingASCII, 5, this );
                
                
                __context__.SourceCodeLine = 106;
                while ( Functions.TestForTrue  ( ( 1)  ) ) 
                    { 
                    __context__.SourceCodeLine = 108;
                    MYSTR  .UpdateValue ( Functions.Gather ( "\u000D\u000A" , TOMODULE__DOLLAR__ )  ) ; 
                    __context__.SourceCodeLine = 111;
                    if ( Functions.TestForTrue  ( ( Functions.BoolToInt ( Functions.Find( "Set output" , MYSTR ) > 0 ))  ) ) 
                        { 
                        __context__.SourceCodeLine = 113;
                        MYDUMMY  .UpdateValue ( Functions.Remove ( "output" , MYSTR , 1)  ) ; 
                        __context__.SourceCodeLine = 114;
                        OUTPUT_FB = (ushort) ( Functions.Atoi( MYSTR ) ) ; 
                        __context__.SourceCodeLine = 115;
                        if ( Functions.TestForTrue  ( ( Functions.BoolToInt ( Functions.Find( "input" , MYSTR , 1 ) > 0 ))  ) ) 
                            { 
                            __context__.SourceCodeLine = 117;
                            MYDUMMY  .UpdateValue ( Functions.Remove ( "input" , MYSTR , 1)  ) ; 
                            __context__.SourceCodeLine = 118;
                            INPUT_FB = (ushort) ( Functions.Atoi( MYSTR ) ) ; 
                            __context__.SourceCodeLine = 119;
                            OUTPUT [ OUTPUT_FB]  .Value = (ushort) ( INPUT_FB ) ; 
                            } 
                        
                        } 
                    
                    else 
                        {
                        __context__.SourceCodeLine = 124;
                        if ( Functions.TestForTrue  ( ( Functions.BoolToInt ( Functions.Find( "Set system power OFF" , MYSTR ) > 0 ))  ) ) 
                            { 
                            __context__.SourceCodeLine = 126;
                            POWER_ON_FB  .Value = (ushort) ( 0 ) ; 
                            __context__.SourceCodeLine = 127;
                            POWER_OFF_FB  .Value = (ushort) ( 1 ) ; 
                            } 
                        
                        else 
                            {
                            __context__.SourceCodeLine = 132;
                            if ( Functions.TestForTrue  ( ( Functions.BoolToInt ( Functions.Find( "Set system power ON" , MYSTR ) > 0 ))  ) ) 
                                { 
                                __context__.SourceCodeLine = 134;
                                POWER_OFF_FB  .Value = (ushort) ( 0 ) ; 
                                __context__.SourceCodeLine = 135;
                                POWER_ON_FB  .Value = (ushort) ( 1 ) ; 
                                } 
                            
                            else 
                                {
                                __context__.SourceCodeLine = 138;
                                if ( Functions.TestForTrue  ( ( Functions.BoolToInt ( Functions.Find( "OutputPort" , MYSTR ) > 0 ))  ) ) 
                                    { 
                                    __context__.SourceCodeLine = 140;
                                    MYSTATUS = (ushort) ( 1 ) ; 
                                    } 
                                
                                else 
                                    {
                                    __context__.SourceCodeLine = 144;
                                    if ( Functions.TestForTrue  ( ( Functions.BoolToInt ( (Functions.TestForTrue ( Functions.BoolToInt ( Functions.Find( "Power" , MYSTR ) > 0 ) ) && Functions.TestForTrue ( Functions.BoolToInt ( Functions.Find( "IR" , MYSTR ) > 0 ) )) ))  ) ) 
                                        { 
                                        __context__.SourceCodeLine = 146;
                                        MYSTATUS = (ushort) ( 2 ) ; 
                                        } 
                                    
                                    else 
                                        {
                                        __context__.SourceCodeLine = 150;
                                        if ( Functions.TestForTrue  ( ( Functions.BoolToInt ( Functions.Find( "====" , MYSTR ) > 0 ))  ) ) 
                                            { 
                                            __context__.SourceCodeLine = 153;
                                            MYSTATUS = (ushort) ( 0 ) ; 
                                            } 
                                        
                                        else 
                                            {
                                            __context__.SourceCodeLine = 156;
                                            if ( Functions.TestForTrue  ( ( Functions.BoolToInt (MYSTATUS == 1))  ) ) 
                                                { 
                                                __context__.SourceCodeLine = 159;
                                                OUTPUT_FB = (ushort) ( Functions.Atoi( MYSTR ) ) ; 
                                                __context__.SourceCodeLine = 160;
                                                MYDUMMY  .UpdateValue ( Functions.Remove ( 2, MYSTR )  ) ; 
                                                __context__.SourceCodeLine = 161;
                                                INPUT_FB = (ushort) ( Functions.Atoi( MYSTR ) ) ; 
                                                __context__.SourceCodeLine = 162;
                                                OUTPUT [ OUTPUT_FB]  .Value = (ushort) ( INPUT_FB ) ; 
                                                __context__.SourceCodeLine = 163;
                                                Functions.ProcessLogic ( ) ; 
                                                } 
                                            
                                            else 
                                                {
                                                __context__.SourceCodeLine = 166;
                                                if ( Functions.TestForTrue  ( ( Functions.BoolToInt (MYSTATUS == 2))  ) ) 
                                                    { 
                                                    __context__.SourceCodeLine = 171;
                                                    if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "OF"))  ) ) 
                                                        { 
                                                        __context__.SourceCodeLine = 173;
                                                        POWER_ON_FB  .Value = (ushort) ( 0 ) ; 
                                                        __context__.SourceCodeLine = 174;
                                                        POWER_OFF_FB  .Value = (ushort) ( 1 ) ; 
                                                        } 
                                                    
                                                    else 
                                                        {
                                                        __context__.SourceCodeLine = 177;
                                                        if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "ON"))  ) ) 
                                                            { 
                                                            __context__.SourceCodeLine = 179;
                                                            POWER_OFF_FB  .Value = (ushort) ( 0 ) ; 
                                                            __context__.SourceCodeLine = 180;
                                                            POWER_ON_FB  .Value = (ushort) ( 1 ) ; 
                                                            } 
                                                        
                                                        }
                                                    
                                                    __context__.SourceCodeLine = 184;
                                                    MYDUMMY  .UpdateValue ( Functions.Remove ( "\u0009" , MYSTR )  ) ; 
                                                    __context__.SourceCodeLine = 185;
                                                    if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "OF"))  ) ) 
                                                        { 
                                                        __context__.SourceCodeLine = 188;
                                                        IR_ON_FB  .Value = (ushort) ( 0 ) ; 
                                                        __context__.SourceCodeLine = 189;
                                                        IR_OFF_FB  .Value = (ushort) ( 1 ) ; 
                                                        } 
                                                    
                                                    else 
                                                        {
                                                        __context__.SourceCodeLine = 192;
                                                        if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "ON"))  ) ) 
                                                            { 
                                                            __context__.SourceCodeLine = 195;
                                                            IR_OFF_FB  .Value = (ushort) ( 0 ) ; 
                                                            __context__.SourceCodeLine = 196;
                                                            IR_ON_FB  .Value = (ushort) ( 1 ) ; 
                                                            } 
                                                        
                                                        }
                                                    
                                                    __context__.SourceCodeLine = 200;
                                                    MYDUMMY  .UpdateValue ( Functions.Remove ( "\u0009" , MYSTR )  ) ; 
                                                    __context__.SourceCodeLine = 201;
                                                    if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "OF"))  ) ) 
                                                        { 
                                                        __context__.SourceCodeLine = 204;
                                                        KEY_ON_FB  .Value = (ushort) ( 0 ) ; 
                                                        __context__.SourceCodeLine = 205;
                                                        KEY_OFF_FB  .Value = (ushort) ( 1 ) ; 
                                                        } 
                                                    
                                                    else 
                                                        {
                                                        __context__.SourceCodeLine = 208;
                                                        if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "ON"))  ) ) 
                                                            { 
                                                            __context__.SourceCodeLine = 211;
                                                            KEY_OFF_FB  .Value = (ushort) ( 0 ) ; 
                                                            __context__.SourceCodeLine = 212;
                                                            KEY_ON_FB  .Value = (ushort) ( 1 ) ; 
                                                            } 
                                                        
                                                        }
                                                    
                                                    __context__.SourceCodeLine = 216;
                                                    MYDUMMY  .UpdateValue ( Functions.Remove ( "\u0009" , MYSTR )  ) ; 
                                                    __context__.SourceCodeLine = 217;
                                                    if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "OF"))  ) ) 
                                                        { 
                                                        __context__.SourceCodeLine = 220;
                                                        DBG_ON_FB  .Value = (ushort) ( 0 ) ; 
                                                        __context__.SourceCodeLine = 221;
                                                        DBG_OFF_FB  .Value = (ushort) ( 1 ) ; 
                                                        } 
                                                    
                                                    else 
                                                        {
                                                        __context__.SourceCodeLine = 224;
                                                        if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "ON"))  ) ) 
                                                            { 
                                                            __context__.SourceCodeLine = 227;
                                                            DBG_OFF_FB  .Value = (ushort) ( 0 ) ; 
                                                            __context__.SourceCodeLine = 228;
                                                            DBG_ON_FB  .Value = (ushort) ( 1 ) ; 
                                                            } 
                                                        
                                                        }
                                                    
                                                    __context__.SourceCodeLine = 232;
                                                    MYDUMMY  .UpdateValue ( Functions.Remove ( "\u0009" , MYSTR )  ) ; 
                                                    __context__.SourceCodeLine = 233;
                                                    if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "OF"))  ) ) 
                                                        { 
                                                        __context__.SourceCodeLine = 236;
                                                        BEEP_ON_FB  .Value = (ushort) ( 0 ) ; 
                                                        __context__.SourceCodeLine = 237;
                                                        BEEP_OFF_FB  .Value = (ushort) ( 1 ) ; 
                                                        } 
                                                    
                                                    else 
                                                        {
                                                        __context__.SourceCodeLine = 240;
                                                        if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "ON"))  ) ) 
                                                            { 
                                                            __context__.SourceCodeLine = 243;
                                                            BEEP_OFF_FB  .Value = (ushort) ( 0 ) ; 
                                                            __context__.SourceCodeLine = 244;
                                                            BEEP_ON_FB  .Value = (ushort) ( 1 ) ; 
                                                            } 
                                                        
                                                        }
                                                    
                                                    __context__.SourceCodeLine = 248;
                                                    MYDUMMY  .UpdateValue ( Functions.Remove ( "\u0009" , MYSTR )  ) ; 
                                                    __context__.SourceCodeLine = 249;
                                                    if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "OF"))  ) ) 
                                                        { 
                                                        __context__.SourceCodeLine = 252;
                                                        LCD_ON_FB  .Value = (ushort) ( 0 ) ; 
                                                        __context__.SourceCodeLine = 253;
                                                        LCD_OFF_FB  .Value = (ushort) ( 1 ) ; 
                                                        } 
                                                    
                                                    else 
                                                        {
                                                        __context__.SourceCodeLine = 256;
                                                        if ( Functions.TestForTrue  ( ( Functions.BoolToInt (Functions.Left( MYSTR , (int)( 2 ) ) == "ON"))  ) ) 
                                                            { 
                                                            __context__.SourceCodeLine = 259;
                                                            LCD_OFF_FB  .Value = (ushort) ( 0 ) ; 
                                                            __context__.SourceCodeLine = 260;
                                                            LCD_ON_FB  .Value = (ushort) ( 1 ) ; 
                                                            } 
                                                        
                                                        }
                                                    
                                                    } 
                                                
                                                }
                                            
                                            }
                                        
                                        }
                                    
                                    }
                                
                                }
                            
                            }
                        
                        }
                    
                    __context__.SourceCodeLine = 106;
                    } 
                
                
                
            }
            catch(Exception e) { ObjectCatchHandler(e); }
            finally { ObjectFinallyHandler( __SignalEventArg__ ); }
            return this;
            
        }
        
    public override object FunctionMain (  object __obj__ ) 
        { 
        try
        {
            SplusExecutionContext __context__ = SplusFunctionMainStartCode();
            
            
            
        }
        catch(Exception e) { ObjectCatchHandler(e); }
        finally { ObjectFinallyHandler(); }
        return __obj__;
        }
        
    
    public override void LogosSplusInitialize()
    {
        SocketInfo __socketinfo__ = new SocketInfo( 1, this );
        InitialParametersClass.ResolveHostName = __socketinfo__.ResolveHostName;
        _SplusNVRAM = new SplusNVRAM( this );
        
        POWER_ON_FB = new Crestron.Logos.SplusObjects.DigitalOutput( POWER_ON_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( POWER_ON_FB__DigitalOutput__, POWER_ON_FB );
        
        POWER_OFF_FB = new Crestron.Logos.SplusObjects.DigitalOutput( POWER_OFF_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( POWER_OFF_FB__DigitalOutput__, POWER_OFF_FB );
        
        IR_ON_FB = new Crestron.Logos.SplusObjects.DigitalOutput( IR_ON_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( IR_ON_FB__DigitalOutput__, IR_ON_FB );
        
        IR_OFF_FB = new Crestron.Logos.SplusObjects.DigitalOutput( IR_OFF_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( IR_OFF_FB__DigitalOutput__, IR_OFF_FB );
        
        KEY_ON_FB = new Crestron.Logos.SplusObjects.DigitalOutput( KEY_ON_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( KEY_ON_FB__DigitalOutput__, KEY_ON_FB );
        
        KEY_OFF_FB = new Crestron.Logos.SplusObjects.DigitalOutput( KEY_OFF_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( KEY_OFF_FB__DigitalOutput__, KEY_OFF_FB );
        
        DBG_ON_FB = new Crestron.Logos.SplusObjects.DigitalOutput( DBG_ON_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( DBG_ON_FB__DigitalOutput__, DBG_ON_FB );
        
        DBG_OFF_FB = new Crestron.Logos.SplusObjects.DigitalOutput( DBG_OFF_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( DBG_OFF_FB__DigitalOutput__, DBG_OFF_FB );
        
        BEEP_ON_FB = new Crestron.Logos.SplusObjects.DigitalOutput( BEEP_ON_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( BEEP_ON_FB__DigitalOutput__, BEEP_ON_FB );
        
        BEEP_OFF_FB = new Crestron.Logos.SplusObjects.DigitalOutput( BEEP_OFF_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( BEEP_OFF_FB__DigitalOutput__, BEEP_OFF_FB );
        
        LCD_ON_FB = new Crestron.Logos.SplusObjects.DigitalOutput( LCD_ON_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( LCD_ON_FB__DigitalOutput__, LCD_ON_FB );
        
        LCD_OFF_FB = new Crestron.Logos.SplusObjects.DigitalOutput( LCD_OFF_FB__DigitalOutput__, this );
        m_DigitalOutputList.Add( LCD_OFF_FB__DigitalOutput__, LCD_OFF_FB );
        
        OUTPUT = new InOutArray<AnalogOutput>( 8, this );
        for( uint i = 0; i < 8; i++ )
        {
            OUTPUT[i+1] = new Crestron.Logos.SplusObjects.AnalogOutput( OUTPUT__AnalogSerialOutput__ + i, this );
            m_AnalogOutputList.Add( OUTPUT__AnalogSerialOutput__ + i, OUTPUT[i+1] );
        }
        
        TOMODULE__DOLLAR__ = new Crestron.Logos.SplusObjects.BufferInput( TOMODULE__DOLLAR____AnalogSerialInput__, 600, this );
        m_StringInputList.Add( TOMODULE__DOLLAR____AnalogSerialInput__, TOMODULE__DOLLAR__ );
        
        
        TOMODULE__DOLLAR__.OnSerialChange.Add( new InputChangeHandlerWrapper( TOMODULE__DOLLAR___OnChange_0, true ) );
        
        _SplusNVRAM.PopulateCustomAttributeList( true );
        
        NVRAM = _SplusNVRAM;
        
    }
    
    public override void LogosSimplSharpInitialize()
    {
        
        
    }
    
    public UserModuleClass_BLUSTREAM ( string InstanceName, string ReferenceID, Crestron.Logos.SplusObjects.CrestronStringEncoding nEncodingType ) : base( InstanceName, ReferenceID, nEncodingType ) {}
    
    
    
    
    const uint TOMODULE__DOLLAR____AnalogSerialInput__ = 0;
    const uint POWER_ON_FB__DigitalOutput__ = 0;
    const uint POWER_OFF_FB__DigitalOutput__ = 1;
    const uint IR_ON_FB__DigitalOutput__ = 2;
    const uint IR_OFF_FB__DigitalOutput__ = 3;
    const uint KEY_ON_FB__DigitalOutput__ = 4;
    const uint KEY_OFF_FB__DigitalOutput__ = 5;
    const uint DBG_ON_FB__DigitalOutput__ = 6;
    const uint DBG_OFF_FB__DigitalOutput__ = 7;
    const uint BEEP_ON_FB__DigitalOutput__ = 8;
    const uint BEEP_OFF_FB__DigitalOutput__ = 9;
    const uint LCD_ON_FB__DigitalOutput__ = 10;
    const uint LCD_OFF_FB__DigitalOutput__ = 11;
    const uint OUTPUT__AnalogSerialOutput__ = 0;
    
    [SplusStructAttribute(-1, true, false)]
    public class SplusNVRAM : SplusStructureBase
    {
    
        public SplusNVRAM( SplusObject __caller__ ) : base( __caller__ ) {}
        
        
    }
    
    SplusNVRAM _SplusNVRAM = null;
    
    public class __CEvent__ : CEvent
    {
        public __CEvent__() {}
        public void Close() { base.Close(); }
        public int Reset() { return base.Reset() ? 1 : 0; }
        public int Set() { return base.Set() ? 1 : 0; }
        public int Wait( int timeOutInMs ) { return base.Wait( timeOutInMs ) ? 1 : 0; }
    }
    public class __CMutex__ : CMutex
    {
        public __CMutex__() {}
        public void Close() { base.Close(); }
        public void ReleaseMutex() { base.ReleaseMutex(); }
        public int WaitForMutex() { return base.WaitForMutex() ? 1 : 0; }
    }
     public int IsNull( object obj ){ return (obj == null) ? 1 : 0; }
}


}
