public void SendUpdate(MemoryFloat mem)
 {
     if (filter.Apply(mem))
     {
         client.Publish("in/" + transformer.NameToOpenHAB(mem.Name) + "/state", Encoding.ASCII.GetBytes(transformer.FloatToState(mem)));
     }
 }
        public float Luminosidade_OutSide()
        {
            //update dos registros
            MemoryMap.Instance.Update();

            MemoryFloat luminosidade = MemoryMap.Instance.GetFloat(138, MemoryType.Input);

            return(luminosidade.Value);
        }
        public string FloatToState(MemoryFloat mem)
        {
            float value = mem.Value;

            if (mem.Name.Contains("Openness"))
            {
                value *= homeioToOpenhabRate;
            }
            return(value.ToString());
        }
        public DadosTermostato Termostato_A()
        {
            //update dos registros
            MemoryMap.Instance.Update();

            MemoryFloat temperatura = MemoryMap.Instance.GetFloat(1, MemoryType.Input);
            MemoryFloat setPoint    = MemoryMap.Instance.GetFloat(2, MemoryType.Input);
            MemoryBit   estado      = MemoryMap.Instance.GetBit(9, MemoryType.Output);

            return(new DadosTermostato(temperatura.Value, setPoint.Value, estado.Value));
        }
Ejemplo n.º 5
0
        //In this sample we are reading the living room thermostat value. The data is sampled each second 10 times.
        static void Main(string[] args)
        {
            //We are using a MemoryFloat which we get from the MemoryMap.
            //You can find all the memory addresses at the Home I/O Memory Address document.
            MemoryFloat livingRoomThermostat = MemoryMap.Instance.GetFloat(1, MemoryType.Input);

            for (int i = 0; i < 10; i++)
            {
                //We must call the Update method each time we want to access the latest value.
                MemoryMap.Instance.Update();

                Console.WriteLine("Temperature Sample #" + i + " = " + livingRoomThermostat.Value);

                Thread.Sleep(1000);
            }

            //When we no longer need the MemoryMap we should call the Dispose method to release all the allocated resources.
            MemoryMap.Instance.Dispose();

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }
 public bool Apply(MemoryFloat mem)
 {
     if (mem.Name.Contains("Brightness Sensor"))
     {
         float value;
         if (lastSentValue.TryGetValue(mem, out value))
         {
             if (Math.Abs(value - mem.Value) < 0.1 || ((Math.Abs(value - mem.Value) / value) < 0.1 && !mem.Name.Contains("O - Brightness Sensor")))
             {
                 return(false);
             }
             else
             {
                 lastSentValue[mem] = mem.Value;
             }
         }
         else
         {
             lastSentValue.Add(mem, mem.Value);
         }
     }
     else if (mem.Name.Contains("Room Temperature"))
     {
         float value;
         if (lastSentValue.TryGetValue(mem, out value))
         {
             if (Math.Abs(value - mem.Value) < 0.1)
             {
                 return(false);
             }
             else
             {
                 lastSentValue[mem] = mem.Value;
             }
         }
         else
         {
             lastSentValue.Add(mem, mem.Value);
         }
     }
     else if (mem.Name.Contains("Roller Shades") && mem.Name.Contains("Openness"))
     {
         float value;
         if (lastSentValue.TryGetValue(mem, out value))
         {
             if (mem.Value > 1 && mem.Value < 9 && Math.Abs(value - mem.Value) < 0.5)
             {
                 return(false);
             }
             else if (mem.Value != 0 && mem.Value != 10 && Math.Abs(value - mem.Value) < 0.2)
             {
                 return(false);
             }
             else
             {
                 lastSentValue[mem] = mem.Value;
             }
         }
         else
         {
             lastSentValue.Add(mem, mem.Value);
         }
     }
     else if (mem.Name.Contains("Time Scale"))
     {
         float value;
         if (lastSentValue.TryGetValue(mem, out value))
         {
             if (value == mem.Value)
             {
                 return(false);
             }
             else if (value < mem.Value && mem.Value != 1 && mem.Value != 50 && mem.Value != 500 && mem.Value != 5000)
             {
                 if ((Math.Abs(value - mem.Value) < 0.5 || Math.Abs((value / mem.Value) - mem.Value) < 0.05))
                 {
                     return(false);
                 }
             }
             else
             {
                 lastSentValue[mem] = mem.Value;
             }
         }
         else
         {
             lastSentValue.Add(mem, mem.Value);
         }
     }
     return(true);
 }
Ejemplo n.º 7
0
        public DadosMemory Get(int milisegundosIntervalo = 100)
        {
            bool datacorrect = false;

            do
            {
                //update dos registros
                MemoryMap.Instance.Update();
                //verificacao de validacao de dados vindos do simulador
                if (MemoryMap.Instance.UpdateElapsedTime == 0)
                {
                    continue;
                }
                else
                {
                    datacorrect = true;
                }

                //dados memory
                MemoryDateTime datahora = MemoryMap.Instance.GetDateTime(65, MemoryType.Memory);
                _dateTimeHouse = datahora.Value;

                if (_last_dm == null || _last_dm.dmDateTime.DataHora.AddMilliseconds(milisegundosIntervalo) <= DateTimeHouse)
                {
                    MemoryFloat latitude    = MemoryMap.Instance.GetFloat(130, MemoryType.Memory);
                    MemoryFloat longitude   = MemoryMap.Instance.GetFloat(131, MemoryType.Memory);
                    MemoryFloat temperatura = MemoryMap.Instance.GetFloat(132, MemoryType.Memory);
                    MemoryFloat humidade    = MemoryMap.Instance.GetFloat(133, MemoryType.Memory);
                    MemoryFloat tempmin     = MemoryMap.Instance.GetFloat(134, MemoryType.Memory);
                    MemoryFloat tempmax     = MemoryMap.Instance.GetFloat(135, MemoryType.Memory);
                    MemoryFloat dewpoint    = MemoryMap.Instance.GetFloat(136, MemoryType.Memory);
                    MemoryFloat windms      = MemoryMap.Instance.GetFloat(137, MemoryType.Memory);
                    MemoryFloat cloudiness  = MemoryMap.Instance.GetFloat(138, MemoryType.Memory);

                    MemoryFloat energiaatual = MemoryMap.Instance.GetFloat(141, MemoryType.Memory);

                    MemoryFloat tempA = MemoryMap.Instance.GetFloat(150, MemoryType.Memory);
                    MemoryFloat tempB = MemoryMap.Instance.GetFloat(151, MemoryType.Memory);
                    MemoryFloat tempC = MemoryMap.Instance.GetFloat(152, MemoryType.Memory);
                    MemoryFloat tempD = MemoryMap.Instance.GetFloat(153, MemoryType.Memory);
                    MemoryFloat tempE = MemoryMap.Instance.GetFloat(154, MemoryType.Memory);
                    MemoryFloat tempF = MemoryMap.Instance.GetFloat(155, MemoryType.Memory);
                    MemoryFloat tempG = MemoryMap.Instance.GetFloat(156, MemoryType.Memory);
                    MemoryFloat tempH = MemoryMap.Instance.GetFloat(157, MemoryType.Memory);
                    MemoryFloat tempI = MemoryMap.Instance.GetFloat(158, MemoryType.Memory);
                    MemoryFloat tempJ = MemoryMap.Instance.GetFloat(159, MemoryType.Memory);
                    MemoryFloat tempK = MemoryMap.Instance.GetFloat(160, MemoryType.Memory);
                    MemoryFloat tempL = MemoryMap.Instance.GetFloat(161, MemoryType.Memory);
                    MemoryFloat tempM = MemoryMap.Instance.GetFloat(162, MemoryType.Memory);
                    MemoryFloat tempN = MemoryMap.Instance.GetFloat(163, MemoryType.Memory);

                    DadosMemoryDateTime    m_datetime    = FactoryDateTime.UpdateValueDateTime(datahora.Value);
                    DadosMemoryClima       m_clima       = FactoryClima.UpdateValueClima(latitude.Value, longitude.Value, temperatura.Value, humidade.Value, tempmin.Value, tempmax.Value, dewpoint.Value, windms.Value, cloudiness.Value);
                    DadosMemoryEnergia     m_energia     = FactoryEnergia.UpdateValueEnergia(energiaatual.Value);
                    DadosMemoryTemperatura m_temperatura = FactoryTemperatura.UpdateValueTemperatura(tempA.Value, tempB.Value, tempC.Value, tempD.Value, tempE.Value, tempF.Value, tempG.Value, tempH.Value, tempI.Value, tempJ.Value, tempK.Value, tempL.Value, tempM.Value, tempN.Value);

                    DadosMemory dm = new DadosMemory(m_datetime, m_clima, m_energia, m_temperatura);
                    _last_dm = dm;
                    return(dm);
                }
            }while (datacorrect == false);
            return(_last_dm);
        }
Ejemplo n.º 8
0
        public static float ReadFloatMemory(int memory)
        {
            MemoryFloat HomeMemory = MemoryMap.Instance.GetFloat(memory, MemoryType.Memory);

            return(HomeMemory.Value);
        }
Ejemplo n.º 9
0
        public static float ReadFloatOutput(int input)
        {
            MemoryFloat HomeInput = MemoryMap.Instance.GetFloat(input, MemoryType.Output);

            return(HomeInput.Value);
        }