示例#1
0
        public void ParseCrestronString(Connection c, byte[] b1)
        {
            //OnDebug(eDebugEventType.Info, "ParseCrestron: " + StringHelper.CreateHexPrintableString(b1));
            //string s1 = Encoding.GetEncoding("ISO-8859-1").GetString(b1);
            CrestronDevice dev  = uis.Find(x => x.connections.Contains(c));
            Byte           ipid = dev != null ? dev.id : uis[0].id;

            switch (b1[0])
            {
            case 0x00: { OnDebug(eDebugEventType.Info, "Ack"); break; }

            case 0x01: { SignOn(c, b1, 8); break; }

            case 0x02: { OnDebug(eDebugEventType.Info, "Connection accepted" + dev == null ? " IPID " + dev.id : ""); break; }

            case 0x04: { OnDebug(eDebugEventType.Info, "Connection refused" + dev == null ? " IPID " + dev.id : ""); break; }

            case 0x05: { ParseJoinEvent(c, b1); break; }

            case 0x0A: { SignOn(c, b1, 4); break; }

            case 0x0D: { Send(c, "\x0E\x00\x02\x00\x00"); break; } //OnDebug(eDebugEventType.Info, "Ping");

            case 0x0E: { break; }                                  //OnDebug(eDebugEventType.Info, "Pong");

            case 0x0F: { OnDebug(eDebugEventType.Info, "Query"); break; }

            case 0x12: { ParseSerialUnicodeEvent(c, b1); break; }

            default: { OnDebug(eDebugEventType.Info, "ParseCrestron Unknown: " + StringHelper.CreateHexPrintableString(b1)); break; }
            }
        }
示例#2
0
 public PulseData(CrestronDevice device, byte id, ushort idx, bool state)
 {
     this.device = device;
     this.id     = id;
     this.idx    = idx;
     this.state  = state;
 }
示例#3
0
        public void SendSerialSmartObject(CrestronDevice device, byte id, ushort idx, string val)
        {
            setOutputSigState(device, id, idx, val);
            byte[] bLen1 = { (byte)(val.Length + 15) };
            byte[] bLen2 = { (byte)(val.Length + 11) };
            byte[] bLen3 = { (byte)(val.Length + 4) };
            byte[] bId   = { (byte)(id) };
            byte[] bVal  = StringHelper.GetBytes(val);
            byte[] bIdx  = { (byte)((idx) / 0x100), (byte)((idx) % 0x100) };
            string sIdx  = StringHelper.GetString(bIdx);
            string str   = "\x12\x00"
                           + StringHelper.GetString(bLen1)
                           + "\x00\x00\x00"
                           + StringHelper.GetString(bLen2)
                           + "\x39\x00\x00\x00"
                           + StringHelper.GetString(bId)
                           + "\x00"
                           + StringHelper.GetString(bLen3)
                           + "\x34"
                           + sIdx
                           + "\x03"
                           + StringHelper.GetString(bVal);

            //Debug("SendSerialSmartObject: " + StringHelper.CreateHexPrintableString(str));
            Send(device, str);
        }
示例#4
0
 public AnalogSmartObjectEventArgs(CrestronDevice device, byte id, ushort join, ushort val)
 {
     this.device = device;
     this.id     = id;
     this.join   = join;
     this.val    = val;
 }
示例#5
0
 public DigitalSmartObjectEventArgs(CrestronDevice device, byte id, ushort join, bool val)
 {
     this.device = device;
     this.id     = id;
     this.join   = join;
     this.val    = val;
 }
示例#6
0
        public void SendSerialUnicode(CrestronDevice device, ushort idx, string val)
        {
            var sig = device.serialOutputs.Find(x => x.pos == idx);

            if (sig == null)
            {
                device.serialOutputs.Add(new Serial(idx, val));
            }
            else
            {
                sig.value = val;
            }

            //\x12\x00\x0A\x00\x00\x00\x06\x34\x00\x00\x07\x31\x00 // "1"
            //\x12\x00\x0C\x00\x00\x00\x08\x34\x00\x00\x07\x31\x00\x31\x00\x31\x00 // "111"
            byte[] b1  = { (byte)(val.Length + 9) };
            byte[] b2  = { (byte)(val.Length + 5) };
            byte[] b3  = { (byte)((idx - 1) / 0x100), (byte)((idx - 1) % 0x100) };
            byte[] b4  = StringHelper.GetBytes(val);
            string str = "\x12\x00"
                         + StringHelper.GetString(b1)
                         + "\x00\x00\x00"
                         + StringHelper.GetString(b2)
                         + "\x34"
                         + StringHelper.GetString(b3)
                         + "\x07"
                         + StringHelper.GetString(b4);

            Send(device, str);
        }
示例#7
0
 public SerialSmartObjectEventArgs(CrestronDevice device, byte id, ushort join, string val)
 {
     this.device = device;
     this.id     = id;
     this.join   = join;
     this.val    = val;
 }
示例#8
0
 public void ShowConfirmSub(CrestronDevice device, string title, string msg)
 {
     CurrentConfirm = title;
     parent.SendSerial(device, SER_CONFIRM_TITLE, FormatText(CurrentConfirm, FONT_SIZE_INSTRUCT, GetColour(COLOUR_INSTRUCT)));
     parent.SendSerial(device, SER_CONFIRM_MSG, FormatText(msg, FONT_SIZE_INSTRUCT, GetColour(COLOUR_INSTRUCT)));
     parent.SendDigital(device, DIG_SUB_CONFIRM, true);
 }
示例#9
0
        public void ParseSerialUnicodeEvent(Connection c, byte[] b1)
        {
            OnDebug(eDebugEventType.Info, "ParseCrestron Serial unicode: " + StringHelper.CreateHexPrintableString(b1));
            CrestronDevice dev = uis.Find(x => x.connections.Contains(c));
            //\x12\x00\x0A\x00\x00\x00\x06\x34\x00\x00\x07\x31\x00 // "1"
            //\x12\x00\x0C\x00\x00\x00\x08\x34\x00\x00\x07\x31\x00\x31\x00\x31\x00 // "111"
            //String str = "";
            //for (int i=11; i<b1.Length; i+=2)
            //    str = str + StringHelper.GetString(b1, i, 1);
            ushort idx = 0;
            String str = String.Empty;

            switch (b1[7])
            {
            case 0x39:     // smart object
                idx = (ushort)(b1[8] * 0x100 + b1[9] + 1);
                byte id = (byte)(b1[10] * 0x100 + b1[11] + 1);
                str = Encoding.GetEncoding("ISO-8859-1").GetString(b1, 18, b1.Length - 18);
                SerialSmartObjectEventIn(dev, id, idx, str);
                break;

            default:
                idx = (ushort)(b1[8] * 0x100 + b1[9] + 1);
                str = Encoding.GetEncoding("ISO-8859-1").GetString(b1, 11, b1.Length - 11);
                SerialEventIn(dev, idx, str);
                break;
            }
            ;
        }
示例#10
0
        public void DeviceSignIn(CrestronDevice device)
        {
            OnDebug(eDebugEventType.Info, "Sign on IPID: " + device.id.ToString());
            string sMsg_ = "\x02\x00\x04\x00\x00\x00\x03"; // accept connection

            Send(device, sMsg_);
            uiHandler.DeviceSignIn(device);
        }
示例#11
0
 public override void DeviceSignIn(CrestronDevice currentDevice)
 {
     OnDebug(eDebugEventType.Info, "DeviceSignIn, ID:{0}", currentDevice.id.ToString());
     for (byte idx = 1; idx < 5; idx++)
     {
         SetSmartObjectVisible(currentDevice, SG_DYNAMIC_BTN_LIST, idx, true);
         //SetSmartObjectVisible(currentDevice, SG_DYNAMIC_ICON_LIST, idx, true);
     }
 }
示例#12
0
        public override void SendAcceptMessage(Connection c)
        {
            CrestronDevice dev = uis.Find(x => x.connections.Contains(c));
            string         s   = dev == null ? "": " IPID " + dev.id.ToString();

            OnDebug(eDebugEventType.Info, "SendAcceptMessage" + s);
            string sMsg_ = "\x0F\x00\x01\x02"; // accept connection

            Send(c, sMsg_);
        }
示例#13
0
 public override void SerialEventIn(CrestronDevice currentDevice, ushort idx, string val)
 {
     OnDebug(eDebugEventType.Info, "SerialEventIn, join:{0}, val:{1}", idx.ToString(), val);
     switch (idx)
     {
     case SER_INPUT:
         OnSetSerial(currentDevice, SER_VALUE, val.ToString());
         break;
     }
 }
示例#14
0
 public void Send(CrestronDevice dev, byte[] msg)
 {
     //OnDebug(eDebugEventType.Info, "SendSocket: " + StringHelper.CreateHexPrintableString(b));
     foreach (Connection cl in dev.connections)
     {
         if (cl.ClientSocket.Connected)
         {
             cl.ClientSocket.Send(msg);
         }
     }
 }
示例#15
0
        private CrestronJoins getSmartObject(CrestronDevice device, byte id)
        {
            var so = device.smartObjects.Find(x => x.id == id);

            if (so == null)
            {
                so = new CrestronJoins(id);
                device.smartObjects.Add(so);
            }
            return(so);
        }
示例#16
0
        public void PulseDigitalSmartObject(CrestronDevice device, byte id, ushort idx, int msec)
        {
            SendDigitalSmartObject(device, id, (byte)idx, false);
            var pulseData = new PulseData(device, id, idx, true);

            System.Threading.Timer pulseTimer = null;
            pulseTimer = new Timer((pulseCallback) =>
            {
                SendDigitalSmartObject(pulseData.device, pulseData.id, pulseData.idx, pulseData.state);
                pulseTimer.Dispose();
            }, pulseData, msec, msec);
        }
示例#17
0
        public override void DigitalSmartObjectEventIn(CrestronDevice device, byte id, ushort idx, bool val)
        {
            switch (id)
            {
            case SMART_KEYPAD: DigitalKeypadEventIn(device, id, idx, val); break;

            case SMART_TOPMENU: DigitalTopMenuEventIn(device, id, idx, val); break;

            //case SMART_LIST: // smart ser idx starts at \x0A
            default: DigitalMainMenuEventIn(device, id, idx, val); break;
            }
        }
示例#18
0
 private void SetCurrentPage(CrestronDevice device, Dictionary <byte, string> l, string title, string msg)
 {
     SetTitle(device, title);
     CurrentList = l;
     //OnSetDigital(device, DIG_LIST_VISIBLE, true);
     OnSetAnalogSmartObject(device, SMART_LIST, SMART_IDX_SET_LIST_SIZE, (ushort)CurrentList.Count); // set list size
     SetInstruct(device, msg);
     foreach (var o in CurrentList)
     {
         OnSetSerialSmartObject(device, SMART_LIST, o.Key, StringHelper.FormatTextForUi(o.Value, FONT_SIZE_LIST, StringHelper.GetColour(COLOUR_LIST)));
     }
     OnPulseDigital(device, PAGE_MAIN, 20);
 }
示例#19
0
 public void SetCurrentPage(CrestronDevice device, Dictionary <byte, string> l, string title, string msg)
 {
     SetTitle(device, title);
     CurrentList = l;
     parent.SendDigital(device, DIG_LIST_VISIBLE, true);
     parent.SendAnalogueSmartObject(device, SMART_LIST, SMART_IDX_SET_LIST_SIZE, (ushort)CurrentList.Count); // set list size
     SetInstruct(device, msg);
     foreach (var o in CurrentList)
     {
         parent.SendSerialSmartObject(device, SMART_LIST, o.Key, FormatText(o.Value, FONT_SIZE_LIST, GetColour(COLOUR_LIST)));
     }
     parent.PulseDigital(device, PAGE_MAIN, 20);
 }
示例#20
0
        public void ToggleDigital(CrestronDevice device, ushort idx)
        {
            if (device.digitalOutputs.Where(x => x.pos == idx).Count() == 0)
            {
                device.digitalOutputs.Add(new Digital(idx, false));
            }
            IEnumerable <Digital> query = device.digitalOutputs.Where(x => x.pos == idx);

            foreach (Digital d in query)
            {
                SendDigital(device, idx, !d.value);
            }
        }
示例#21
0
        public override void AnalogEventIn(CrestronDevice currentDevice, ushort idx, ushort val)
        {
            OnDebug(eDebugEventType.Info, "AnalogEventIn, join:{0}, val:{1}", idx.ToString(), val.ToString());
            switch (idx)
            {
            case ANA_BAR_GRAPH:
                OnSetAnalog(currentDevice, idx, val);
                OnSetSerial(currentDevice, SER_VALUE, val.ToString());
                break;

            case ANA_RANDOM:
                OnSetAnalog(currentDevice, ANA_BAR_GRAPH, val);
                break;
            }
        }
示例#22
0
        private void setInputSigState(CrestronDevice device, byte id, ushort idx, ushort val)
        {
            CrestronJoins joins = id > 0 ? getSmartObject(device, id) : device;
            var           sig   = joins.analogInputs.Find(x => x.pos == idx);

            if (sig == null)
            {
                sig = new Analog(idx, val);
                joins.analogInputs.Add(sig);
            }
            else
            {
                sig.value = val;
            }
        }
示例#23
0
        private void setOutputSigState(CrestronDevice device, byte id, ushort idx, bool val)
        {
            CrestronJoins joins = id > 0 ? getSmartObject(device, id) : device;
            var           sig   = joins.digitalOutputs.Find(x => x.pos == idx);

            if (sig == null)
            {
                sig = new Digital(idx, val);
                joins.digitalOutputs.Add(sig);
            }
            else
            {
                sig.value = val;
            }
        }
示例#24
0
        public void SendAnalogSmartObject(CrestronDevice device, byte id, ushort idx, ushort val)
        {
            setOutputSigState(device, id, idx, val);
            // \x05\x00\x0E\x00\x00\x0B\x38\x00\x00\x00\x03\x05\x14\x00\x03\x00\x03 // id 3 analog setNumItems(idx 3) val 3
            // \x05\x00\x0E\x00\x00\x0B\x38\x00\x00\x00\x05\x05\x14\x00\x0a\x00\x09 // id 5 analog setItem1IconAna(idx 11) val 9
            byte[] b1     = { (byte)id };
            ushort NewIdx = (ushort)StringHelper.SetBit(idx - 1, 15, tempBool);

            byte[] b2  = { (byte)idx };
            byte[] b3  = { (byte)(val / 0x100), (byte)(val % 0x100) };
            string str = "\x05\x00\x0E\x00\x00\x0B\x38\x00\x00\x00"
                         + StringHelper.GetString(b1)
                         + "\x05\x14\x00"
                         + StringHelper.GetString(b2)
                         + StringHelper.GetString(b3);

            Send(device, str);
        }
示例#25
0
 private void StartCleaning(CrestronDevice device)
 {
     //parent.Debug("StartCleaning");
     if (cleanCurrentMinutes < 1)
     {
         cleanCurrentMinutes = cleanTotalMinutes;
         OnSetDigital(device, DIG_SUB_CONFIRM, false);
         OnSetDigital(device, DIG_SUB_CLEAN_COUNT, true);
         OnSetAnalog(device, ANA_CLEAN_TIME, cleanCurrentMinutes);
         while (cleanCurrentMinutes > 0)
         {
             Thread.Sleep(1000);
             cleanCurrentMinutes--;
             OnSetAnalog(device, ANA_CLEAN_TIME, cleanCurrentMinutes);
         }
         OnSetDigital(device, DIG_SUB_CLEAN_COUNT, false);
     }
 }
示例#26
0
        public void SendDigitalSmartObject(CrestronDevice device, byte id, ushort idx, bool val)
        {
            setOutputSigState(device, id, idx, val);
            tempBool = !tempBool;
            // \x05\x00\x0C\x00\x00\x09\x38\x00\x00\x00\x03\x03\x27\x00\x00 // id 3, press 1
            // \x05\x00\x0C\x00\x00\x09\x38\x00\x00\x00\x03\x03\x27\x01\x80 // id 3, release 2
            byte[] b1     = { (byte)id };
            ushort NewIdx = (ushort)StringHelper.SetBit(idx - 1, 15, tempBool);

            byte[] b2  = { (byte)(NewIdx % 0x100), (byte)(NewIdx / 0x100) };
            string str = "\x05\x00\x0C\x00\x00\x09\x38\x00\x00\x00"
                         + StringHelper.GetString(b1)
                         + "\x03\x00" //"\x03\x27"
                         + StringHelper.GetString(b2);

            //OnDebug(eDebugEventType.Info, "SendDigitalSmartObject: " + StringHelper.CreateHexPrintableString(str));
            Send(device, str);
        }
示例#27
0
        public void SendDigital(CrestronDevice device, ushort idx, bool val)
        {
            setOutputSigState(device, 0, idx, val);
            ushort NewIdx = (ushort)StringHelper.SetBit(idx - 1, 15, !val);

            byte[] b   = { (byte)(NewIdx % 0x100), (byte)(NewIdx / 0x100) };
            string str = "\x05\x00\x06\x00\x00\x03\x00" + StringHelper.GetString(b);

            Send(device, str);
            //Debug("SendDigital: " + StringHelper.CreateHexPrintableString(str));
            // local feedback
            if (device.digitalOutputs.Where(x => x.pos == idx).Count() == 0)
            {
                device.digitalOutputs.Add(new Digital(idx, false));
            }
            Digital d = device.digitalOutputs.Find(x => x.pos == idx);

            d.value = val;
        }
示例#28
0
        public void ToggleDigitalSmartObject(CrestronDevice device, byte id, ushort idx)
        {
            OnDebug(eDebugEventType.Info, "ToggleDigitalSmartObject:{0}:{1} ", id, idx);
            CrestronJoins smartObject = device.smartObjects.Find(x => x.id == id);

            if (smartObject == null)
            {
                smartObject = new CrestronJoins(id);
                device.smartObjects.Add(smartObject);
            }
            Digital dig = smartObject.digitalOutputs.Find(x => x.pos == idx);

            if (dig == null)
            {
                dig = new Digital(idx, false);
                device.smartObjects.Add(smartObject);
            }
            SendDigitalSmartObject(device, id, idx, !dig.value);
        }
示例#29
0
        public CrestronDevice RegisterConnection(Connection c, byte ipid)
        {
            CrestronDevice dev = uis.Find(x => x.connections.Contains(c));

            if (dev != null) // look for existing connections
            {
                dev.id = ipid;
            }
            else if (uis.Exists(x => x.id.Equals(ipid))) // look for existing ui
            {
                dev = uis.Find(x => x.id.Equals(ipid));
                dev.connections.Add(c);
            }
            else // create new ui
            {
                dev = new CrestronDevice(ipid, this);
                dev.connections.Add(c);
                uis.Add(dev);
            }
            return(dev);
        }
示例#30
0
        private void DigitalTopMenuEventIn(CrestronDevice device, byte id, ushort idx, bool val)
        {
            if (val) // press
            {
                switch (idx)
                {
                case MENU_SEL_1: break;

                case MENU_SEL_ADMIN:
                    SetCurrentPage(device, AdminModes, "Admin", "Select an admin function");
                    break;

                case MENU_SEL_LOGOUT:
                    OnPulseDigital(device, PAGE_LOGIN, 20);
                    break;

                case MENU_SEL_SHUTDOWN:
                    OnPulseDigital(device, PAGE_LOGIN, 20);
                    break;
                }
            }
        }