Example #1
0
        public CommandResult Handle(UpdateBuzzerCommand command)
        {
            CommandResult result = new CommandResult();

            ObjectId buzzerId = new ObjectId();

            if (!ObjectId.TryParse(command.BuzzerId, out buzzerId))
            {
                AddNotification(nameof(command.BuzzerId), ENotifications.InvalidFormat);
            }

            if (Valid)
            {
                Buzzer buzzer = _buzzerRepository.Get(buzzerId);

                if (buzzer == null && _buzzerRepository.Valid)
                {
                    AddNotification(nameof(command.BuzzerId), ENotifications.NotFound);
                }

                if (Valid)
                {
                    PinPort pinPort = null;

                    if (command.PinPort != null)
                    {
                        pinPort = new PinPort(command.PinPort);
                    }

                    buzzer.Update(command.Description, pinPort);

                    if (buzzer.Valid)
                    {
                        _buzzerRepository.Update(buzzer);

                        if (_buzzerRepository.Valid)
                        {
                            result = new CommandResult(HttpStatusCode.OK);
                        }
                    }

                    else
                    {
                        result = new CommandResult(HttpStatusCode.BadRequest, buzzer.Notifications);
                    }
                }

                else
                {
                    result = new CommandResult(HttpStatusCode.BadRequest, Notifications);
                }
            }

            else
            {
                result = new CommandResult(HttpStatusCode.BadRequest, Notifications);
            }

            return(result);
        }
        private byte[] DeviceConfigDimmable()
        {
            List <byte> result = new List <byte>();

            result.Add(0x00);

            PinPort dimmableZero = ProductConfiguration.GetDimmerPassZeroPinPort(this._node.Shield);

            if (dimmableZero != null)
            {
                result.Add(dimmableZero.GetPinPortNumber());
            }
            else
            {
                result.Add(0x00); //TODO: If not exits. Value default??
            }
            foreach (HomeDevice item in _node.HomeDevices)
            {
                if (item is Dimmable)
                {
                    //pointerOperation
                    _operationDictionary.Add((ushort)(_tempMemory.Count + result.Count), item.Operations.ToArray());
                    result.Add(0x00);
                    result.Add(0x00);
                    result.Add((byte)item.Operations.Count);

                    //ConfigList
                    result[0]++;
                    result.AddRange(((ushort)item.Id).UshortToByte(_baseConfiguration.LittleEndian));
                    result.Add(item.Connector.GetPinPort()[0].GetPinPortNumber());
                }
            }
            return(result.ToArray());
        }
Example #3
0
        public CommandResult Handle(UpdateLightCommand command)
        {
            CommandResult result = new CommandResult();

            ObjectId lightId = new ObjectId();

            if (!ObjectId.TryParse(command.LightId, out lightId))
            {
                AddNotification(nameof(command.LightId), ENotifications.InvalidFormat);
            }

            if (Valid)
            {
                Light light = _lightRepository.Get(lightId);

                if (light == null && _lightRepository.Valid)
                {
                    AddNotification(nameof(command.LightId), ENotifications.NotFound);
                }

                if (Valid)
                {
                    PinPort pinPort = null;

                    if (command.PinPort != null)
                    {
                        pinPort = new PinPort(command.PinPort);
                    }

                    light.Update(command.Description, pinPort);

                    if (light.Valid)
                    {
                        _lightRepository.Update(light);

                        if (_lightRepository.Valid)
                        {
                            result = new CommandResult(HttpStatusCode.OK);
                        }
                    }

                    else
                    {
                        result = new CommandResult(HttpStatusCode.BadRequest, light.Notifications);
                    }
                }

                else
                {
                    result = new CommandResult(HttpStatusCode.BadRequest, Notifications);
                }
            }

            else
            {
                result = new CommandResult(HttpStatusCode.BadRequest, Notifications);
            }

            return(result);
        }
Example #4
0
        public void Update(string description = null, PinPort pinPort = null)
        {
            Description = description ?? Description;
            PinPort     = pinPort ?? PinPort;

            Validate();
        }
Example #5
0
        public CommandResult Handle(UpdateSensorCommand command)
        {
            CommandResult result = new CommandResult();

            ObjectId sensorId = new ObjectId();

            if (!ObjectId.TryParse(command.SensorId, out sensorId))
            {
                AddNotification(nameof(command.SensorId), ENotifications.InvalidFormat);
            }

            if (Valid)
            {
                Sensor sensor = _sensorRepository.Get(sensorId);

                if (sensor == null && _sensorRepository.Valid)
                {
                    AddNotification(nameof(command.SensorId), ENotifications.NotFound);
                }

                if (Valid)
                {
                    PinPort pinPort = null;

                    if (command.PinPort != null)
                    {
                        pinPort = new PinPort(command.PinPort);
                    }

                    sensor.Update(command.Description, pinPort, command.Type);

                    if (sensor.Valid)
                    {
                        _sensorRepository.Update(sensor);

                        if (_sensorRepository.Valid)
                        {
                            result = new CommandResult(HttpStatusCode.OK);
                        }
                    }

                    else
                    {
                        result = new CommandResult(HttpStatusCode.BadRequest, sensor.Notifications);
                    }
                }

                else
                {
                    result = new CommandResult(HttpStatusCode.BadRequest, Notifications);
                }
            }

            else
            {
                result = new CommandResult(HttpStatusCode.BadRequest, Notifications);
            }

            return(result);
        }
        private Byte[] TableEventList()
        {
            List <Byte> result  = new List <Byte>();
            UInt16      pointer = 0;
            PinPort     p       = null;

            for (byte i = 0; i < ShieldNode.ShieldBase.NumPorts; i++)
            {
                for (byte j = 0; j < ShieldNode.ShieldBase.NumPins; j++)
                {
                    result.AddRange(pointer.Uint16ToByte(ShieldNode.ShieldBase.LittleEndian));
                    p = ShieldNode.GetPinPort(i, j);
                    if (p != null)
                    {
                        pointer += SizePinEvents(p);
                    }
                }
            }

            //direccion lista de eventos de tiempo
            result.AddRange(pointer.Uint16ToByte(ShieldNode.ShieldBase.LittleEndian));

            //direccion restricciones temporales de los eventos de puertos OJO!!!
            result.Add(0x00);
            result.Add(0x00);

            //direccion region libre
            result.Add(0x00);
            result.Add(0x00);

            return(result.ToArray());
        }
Example #7
0
        public void Update(string description = null, PinPort pinPort = null, ESensorType?type = null)
        {
            Description = description ?? Description;
            PinPort     = pinPort ?? PinPort;
            Type        = type ?? Type;

            Validate();
        }
        /// <returns>If not exist, null</returns>
        public static Connector GetConnector(this Node node, PinPort pinPort)
        {
            if (!node.GetPinPortList().Contains(pinPort))
            {
                return(null);
            }

            return(node.Connectors.FirstOrDefault(connector => connector.GetPinPort().Contains(pinPort)));
        }
        private Byte[] PinIOConfig(Byte port)
        {
            //Si no esta definido suponemos Entrada digital
            Byte[]  result = new Byte[5];
            PinPort p      = null;

            //Input:0 - Output:1, default=0
            result[0] = 0x00;
            for (byte i = 0; i < ShieldNode.ShieldBase.NumPins; i++)
            {
                p = ShieldNode.GetPinPort(port, i);
                if (p != null && p.Output == true)
                {
                    result[0] = (byte)(result[0] | (0x01 << i));
                }
            }

            //Analog:0 - Digital:1 default: 1
            result[1] = 0xFF;
            for (byte i = 0; i < ShieldNode.ShieldBase.NumPins; i++)
            {
                p = ShieldNode.GetPinPort(port, i);
                if (p != null && p.Digital == false)
                {
                    result[1] = (byte)(result[1] & ~(0x01 << i));
                }
            }

            //Input:0 - Output:1, default=0
            result[2] = 0x00;
            for (byte i = 0; i < ShieldNode.ShieldBase.NumPins; i++)
            {
                p = ShieldNode.GetPinPort(port, i);
                if (p != null && p.DefaultValueD == true)
                {
                    result[2] = (byte)(result[2] | (0x01 << i));
                }
            }

            //ChangetypeD None:00 Rising:10, Fall:01, Both:11
            UInt16 ctd = 0x00; //change type digital

            for (byte i = 0; i < ShieldNode.ShieldBase.NumPins; i++)
            {
                p = ShieldNode.GetPinPort(port, i);
                if (p != null)
                {
                    ctd = (byte)(ctd | ((byte)p.changeTypeD) << (i * 2));
                }
            }

            result[3] = ctd.Uint16ToByte(ShieldNode.ShieldBase.LittleEndian)[0];
            result[4] = ctd.Uint16ToByte(ShieldNode.ShieldBase.LittleEndian)[1];

            return(result);
        }
        private UInt16 SizePinEvents(PinPort pin)
        {
            UInt16 size = 0;

            foreach (BasicEvent pe in pin.PinEvents)
            {
                size += (UInt16)ToBinaryEvent(pe.Event, true).Length;
            }
            return(size);
        }
Example #11
0
        public CreateEntityCommandResult Handle(CreateBuzzerCommand command)
        {
            CreateEntityCommandResult result = new CreateEntityCommandResult();

            ObjectId roomId;

            if (!ObjectId.TryParse(command.RoomId, out roomId))
            {
                AddNotification(nameof(roomId), ENotifications.InvalidFormat);
            }

            if (Valid)
            {
                PinPort pinPort = new PinPort(command.PinPort);
                Buzzer  buzzer  = new Buzzer(command.Description, pinPort, roomId);

                if (buzzer.Valid)
                {
                    if (_roomRepository.Get(roomId) == null)
                    {
                        AddNotification(nameof(command.RoomId), ENotifications.NotFound);
                    }

                    if (Valid)
                    {
                        _buzzerRepository.Create(buzzer);

                        if (_buzzerRepository.Valid)
                        {
                            result = new CreateEntityCommandResult(HttpStatusCode.OK).Build <Buzzer, CreateEntityCommandResult>(buzzer);
                        }
                    }

                    else
                    {
                        result = new CreateEntityCommandResult(HttpStatusCode.BadRequest, Notifications);
                    }
                }

                else
                {
                    result = new CreateEntityCommandResult(HttpStatusCode.BadRequest, buzzer.Notifications);
                }
            }

            else
            {
                result = new CreateEntityCommandResult(HttpStatusCode.BadRequest, Notifications);
            }

            return(result);
        }
Example #12
0
        public CreateEntityCommandResult Handle(CreateLightCommand command)
        {
            CreateEntityCommandResult result = new CreateEntityCommandResult();

            ObjectId roomId;

            if (!ObjectId.TryParse(command.RoomId, out roomId))
            {
                AddNotification(nameof(roomId), ENotifications.InvalidFormat);
            }

            if (Valid)
            {
                PinPort pinPort = new PinPort(command.PinPort);
                Light   light   = new Light(command.Description, pinPort, roomId);

                if (light.Valid)
                {
                    if (_roomRepository.Get(roomId) == null)
                    {
                        AddNotification(nameof(command.RoomId), ENotifications.NotFound);
                    }

                    if (Valid)
                    {
                        _lightRepository.Create(light);

                        if (_lightRepository.Valid)
                        {
                            result = new CreateEntityCommandResult(HttpStatusCode.OK).Build <Light, CreateEntityCommandResult>(light);
                        }
                    }

                    else
                    {
                        result = new CreateEntityCommandResult(HttpStatusCode.BadRequest, Notifications);
                    }
                }

                else
                {
                    result = new CreateEntityCommandResult(HttpStatusCode.BadRequest, light.Notifications);
                }
            }

            else
            {
                result = new CreateEntityCommandResult(HttpStatusCode.BadRequest, Notifications);
            }

            return(result);
        }
        private Byte[] AnalogInputsConfig()
        {
            List <Byte> result = new List <Byte>();
            PinPort     p      = null;

            foreach (String pin in ShieldNode.ShieldBase.AnalogPorts)
            {
                p = ShieldNode.GetPinPort(pin[0], Byte.Parse(pin[1].ToString()));
                if (p != null)
                {
                    //Analog Input To Binary
                    result.Add(p.Increment);
                    result.Add(p.Threshold);
                }
                else
                {
                    result.Add(0x00); //Increment
                    result.Add(0x00); //Threshold
                }
            }

            return(result.ToArray());
        }
Example #14
0
 public SwitchBuzzerQuery(PinPort pinPort, bool state)
 {
     PinPort = pinPort;
     State   = state;
 }
Example #15
0
        public async Task <bool> Read(PinPort pinPort)
        {
            ARESTDefaultResponse response = await Send <ARESTDefaultResponse>(HttpMethod.Get, $"/ports?params={pinPort.Value}");

            return(response.Return_Value != 0);
        }
Example #16
0
        public Light(string description, PinPort pinPort, ObjectId roomId)
        {
            RoomId = roomId;

            Update(description, pinPort);
        }
Example #17
0
 public SwitchLightQuery(PinPort pinPort, bool state)
 {
     PinPort = pinPort;
     State   = state;
 }
Example #18
0
        public Sensor(string description, PinPort pinPort, ESensorType type, ObjectId roomId)
        {
            RoomId = roomId;

            Update(description, pinPort, type);
        }
Example #19
0
 public GetSensorValueQuery(PinPort pinPort, ESensorType type)
 {
     PinPort = pinPort;
     Type    = type;
 }