Exemplo n.º 1
0
        private void HandleUnsolicitedSystemEvent(byte[] B)
        {
            clsOL2SystemEvent MSG = new clsOL2SystemEvent(Controller.Connection, B);

            SystemStatusEventArgs eventargs = new SystemStatusEventArgs();

            if (MSG.SystemEvent >= 1 && MSG.SystemEvent <= 255)
            {
                eventargs.Type  = enuEventType.USER_MACRO_BUTTON;
                eventargs.Value = ((int)MSG.SystemEvent).ToString() + " " + Controller.Buttons[MSG.SystemEvent].Name;

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 768 && MSG.SystemEvent <= 771)
            {
                eventargs.Type = enuEventType.PHONE_;

                if (MSG.SystemEvent == 768)
                {
                    eventargs.Value            = "DEAD";
                    eventargs.SendNotification = true;
                }
                else if (MSG.SystemEvent == 769)
                {
                    eventargs.Value = "RING";
                }
                else if (MSG.SystemEvent == 770)
                {
                    eventargs.Value = "OFF HOOK";
                }
                else if (MSG.SystemEvent == 771)
                {
                    eventargs.Value = "ON HOOK";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 772 && MSG.SystemEvent <= 773)
            {
                eventargs.Type             = enuEventType.AC_POWER_;
                eventargs.SendNotification = true;

                if (MSG.SystemEvent == 772)
                {
                    eventargs.Value = "OFF";
                }
                else if (MSG.SystemEvent == 773)
                {
                    eventargs.Value = "RESTORED";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 774 && MSG.SystemEvent <= 775)
            {
                eventargs.Type             = enuEventType.BATTERY_;
                eventargs.SendNotification = true;

                if (MSG.SystemEvent == 774)
                {
                    eventargs.Value = "LOW";
                }
                else if (MSG.SystemEvent == 775)
                {
                    eventargs.Value = "OK";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 776 && MSG.SystemEvent <= 777)
            {
                eventargs.Type             = enuEventType.DCM_;
                eventargs.SendNotification = true;

                if (MSG.SystemEvent == 776)
                {
                    eventargs.Value = "TROUBLE";
                }
                else if (MSG.SystemEvent == 777)
                {
                    eventargs.Value = "OK";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 778 && MSG.SystemEvent <= 781)
            {
                eventargs.Type = enuEventType.ENERGY_COST_;

                if (MSG.SystemEvent == 778)
                {
                    eventargs.Value = "LOW";
                }
                else if (MSG.SystemEvent == 779)
                {
                    eventargs.Value = "MID";
                }
                else if (MSG.SystemEvent == 780)
                {
                    eventargs.Value = "HIGH";
                }
                else if (MSG.SystemEvent == 781)
                {
                    eventargs.Value = "CRITICAL";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 782 && MSG.SystemEvent <= 787)
            {
                eventargs.Type  = enuEventType.CAMERA;
                eventargs.Value = (MSG.SystemEvent - 781).ToString();

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 61440 && MSG.SystemEvent <= 64511)
            {
                eventargs.Type = enuEventType.SWITCH_PRESS;
                int state = (int)MSG.Data[1] - 240;
                int id    = (int)MSG.Data[2];

                eventargs.Value = "Unit: " + id + ", State: " + state;

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 64512 && MSG.SystemEvent <= 65535)
            {
                eventargs.Type = enuEventType.UPB_LINK;
                int state = (int)MSG.Data[1] - 252;
                int id    = (int)MSG.Data[2];

                eventargs.Value = "Link: " + id + ", State: " + state;

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (Global.verbose_unhandled)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < MSG.MessageLength; i++)
                {
                    sb.Append(MSG.Data[i].ToString() + " ");
                }
                log.Debug("Unhandled SystemEvent Raw: " + sb.ToString() + "Num: " + MSG.SystemEvent);

                int num = ((int)MSG.MessageLength - 1) / 2;
                for (int i = 0; i < num; i++)
                {
                    log.Debug("Unhandled SystemEvent: " +
                              (int)MSG.Data[(i * 2) + 1] + " " + (int)MSG.Data[(i * 2) + 2] + ": " +
                              Convert.ToString(MSG.Data[(i * 2) + 1], 2).PadLeft(8, '0') + " " + Convert.ToString(MSG.Data[(i * 2) + 2], 2).PadLeft(8, '0'));
                }
            }
        }
Exemplo n.º 2
0
        private void HandleUnsolicitedSystemEvent(byte[] B)
        {
            clsOL2SystemEvent MSG = new clsOL2SystemEvent(Controller.Connection, B);

            SystemStatusEventArgs eventargs = new SystemStatusEventArgs();

            if (MSG.SystemEvent >= 1 && MSG.SystemEvent <= 255)
            {
                eventargs.Type  = SystemEventType.Button;
                eventargs.Value = ((int)MSG.SystemEvent).ToString() + " " + Controller.Buttons[MSG.SystemEvent].Name;

                OnSystemStatus?.Invoke(this, eventargs);

                OnButtonStatus?.Invoke(this, new ButtonStatusEventArgs()
                {
                    ID     = MSG.SystemEvent,
                    Button = Controller.Buttons[MSG.SystemEvent]
                });
            }
            else if (MSG.SystemEvent >= (ushort)enuEventType.PHONE_LINE_DEAD &&
                     MSG.SystemEvent <= (ushort)enuEventType.PHONE_LINE_ON_HOOK)
            {
                eventargs.Type = SystemEventType.Phone;

                if (MSG.SystemEvent == (ushort)enuEventType.PHONE_)
                {
                    eventargs.Value            = "DEAD";
                    eventargs.Trouble          = true;
                    eventargs.SendNotification = true;
                }
                else if (MSG.SystemEvent == (ushort)enuEventType.PHONE_LINE_RING)
                {
                    eventargs.Value = "RING";
                }
                else if (MSG.SystemEvent == (ushort)enuEventType.PHONE_LINE_OFF_HOOK)
                {
                    eventargs.Value = "OFF HOOK";
                }
                else if (MSG.SystemEvent == (ushort)enuEventType.PHONE_LINE_ON_HOOK)
                {
                    eventargs.Value = "ON HOOK";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= (ushort)enuEventType.AC_POWER_OFF &&
                     MSG.SystemEvent <= (ushort)enuEventType.AC_POWER_RESTORED)
            {
                eventargs.Type             = SystemEventType.AC;
                eventargs.SendNotification = true;

                if (MSG.SystemEvent == (ushort)enuEventType.AC_POWER_OFF)
                {
                    eventargs.Value   = "OFF";
                    eventargs.Trouble = true;
                }
                else if (MSG.SystemEvent == (ushort)enuEventType.AC_POWER_RESTORED)
                {
                    eventargs.Value = "RESTORED";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= (ushort)enuEventType.BATTERY_LOW &&
                     MSG.SystemEvent <= (ushort)enuEventType.BATTERY_OK)
            {
                eventargs.Type             = SystemEventType.Battery;
                eventargs.SendNotification = true;

                if (MSG.SystemEvent == (ushort)enuEventType.BATTERY_LOW)
                {
                    eventargs.Value   = "LOW";
                    eventargs.Trouble = true;
                }
                else if (MSG.SystemEvent == (ushort)enuEventType.BATTERY_OK)
                {
                    eventargs.Value = "OK";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= (ushort)enuEventType.DCM_TROUBLE &&
                     MSG.SystemEvent <= (ushort)enuEventType.DCM_OK)
            {
                eventargs.Type = SystemEventType.DCM;

                eventargs.SendNotification = true;

                if (MSG.SystemEvent == (ushort)enuEventType.DCM_TROUBLE)
                {
                    eventargs.Value   = "TROUBLE";
                    eventargs.Trouble = true;
                }
                else if (MSG.SystemEvent == (ushort)enuEventType.DCM_OK)
                {
                    eventargs.Value = "OK";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= (ushort)enuEventType.ENERGY_COST_LOW &&
                     MSG.SystemEvent <= (ushort)enuEventType.ENERGY_COST_CRITICAL)
            {
                eventargs.Type = SystemEventType.EnergyCost;

                if (MSG.SystemEvent == (ushort)enuEventType.ENERGY_COST_LOW)
                {
                    eventargs.Value = "LOW";
                }
                else if (MSG.SystemEvent == (ushort)enuEventType.ENERGY_COST_MID)
                {
                    eventargs.Value = "MID";
                }
                else if (MSG.SystemEvent == (ushort)enuEventType.ENERGY_COST_HIGH)
                {
                    eventargs.Value = "HIGH";
                }
                else if (MSG.SystemEvent == (ushort)enuEventType.ENERGY_COST_CRITICAL)
                {
                    eventargs.Value = "CRITICAL";
                }

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 782 && MSG.SystemEvent <= 787)
            {
                eventargs.Type  = SystemEventType.Camera;
                eventargs.Value = (MSG.SystemEvent - 781).ToString();

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 61440 && MSG.SystemEvent <= 64511)
            {
                eventargs.Type = SystemEventType.SwitchPress;
                int state = MSG.Data[1] - 240;
                int id    = MSG.Data[2];

                eventargs.Value = "Unit: " + id + ", State: " + state;

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (MSG.SystemEvent >= 64512 && MSG.SystemEvent <= 65535)
            {
                eventargs.Type = SystemEventType.UPBLink;
                int state = MSG.Data[1] - 252;
                int id    = MSG.Data[2];

                eventargs.Value = "Link: " + id + ", State: " + state;

                OnSystemStatus?.Invoke(this, eventargs);
            }
            else if (Global.verbose_unhandled)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < MSG.MessageLength; i++)
                {
                    sb.Append(MSG.Data[i].ToString() + " ");
                }
                log.Debug("Unhandled SystemEvent Raw: {raw}, Num: {num}", sb.ToString(), MSG.SystemEvent);

                int num = (MSG.MessageLength - 1) / 2;
                for (int i = 0; i < num; i++)
                {
                    log.Debug("Unhandled SystemEvent: " +
                              (int)MSG.Data[(i * 2) + 1] + " " + (int)MSG.Data[(i * 2) + 2] + ": " +
                              Convert.ToString(MSG.Data[(i * 2) + 1], 2).PadLeft(8, '0') + " " + Convert.ToString(MSG.Data[(i * 2) + 2], 2).PadLeft(8, '0'));
                }
            }
        }