Esempio n. 1
0
        /// <summary>
        /// Converts from KNX Data Point Type.
        /// </summary>
        /// <returns>Converted object from KNX Data Point Type.</returns>
        /// <param name="type">Type.</param>
        /// <param name="data">Data.</param>
        public object ConvertFromDpt(string type, object data)
        {
            object result;

            if (data.GetType() == typeof(String))
            {
                result = knxClient.FromDataPoint(type, (String)data);
            }
            else
            {
                result = knxClient.FromDataPoint(type, (byte[])data);
            }
            return(result);
        }
Esempio n. 2
0
 private static void Event(string address, string state)
 {
     if (Temperatures.Contains(address))
     {
         var temp = (float)_connection.FromDataPoint("9.001", state);
         Console.WriteLine("New Event: TEMPERATURE device " + address + " has status (" + state + ")" + temp);
     }
     else if (Lights.Contains(address))
     {
         Console.WriteLine("New Event: LIGHT device " + address + " has status (" + state + ")" + state);
     }
     else
     {
         Console.WriteLine("New Event: device " + address + " has status " + state);
     }
 }
Esempio n. 3
0
        private void Event(string address, string state)
        {
            var module = _modules.Find(m => m.Address.Equals(address.Replace("/", ".")));

            if (module != null)
            {
                switch (module.ModuleType)
                {
                case ModuleTypes.Light:
                    OnInterfacePropertyChanged(module.Domain, module.Address, "KNX Interface", "Status.Level", state);
                    break;

                case ModuleTypes.Dimmer:
                    OnInterfacePropertyChanged(module.Domain, module.Address, "KNX Interface", "Status.Level", _connection.FromDataPoint("3.008", state));
                    break;

                case ModuleTypes.Temperature:
                    OnInterfacePropertyChanged(module.Domain, module.Address, "KNX Interface", "Sensor.Temperature", _connection.FromDataPoint("9.001", state));
                    break;

                case ModuleTypes.Sensor:
                    OnInterfacePropertyChanged(module.Domain, module.Address, "KNX Interface", "Sensor.Level", _connection.FromDataPoint("9.001", state));
                    break;
                }
            }
        }
Esempio n. 4
0
        private static void Print(string address, byte[] state)
        {
            string description;

            if (Switches.TryGetValue(address, out description))
            {
                var functionalToggle = Category1_SingleBit.parseSingleBit(state[0]);
                Console.WriteLine("[ON/OFF] {0} ({1})", description, functionalToggle.Exists() ? functionalToggle.Value.Text : "N/A");
            }
            else if (Toggles.TryGetValue(address, out description))
            {
                var functionalToggle = Category1_SingleBit.parseSingleBit(state[0]);
                Console.WriteLine("[TRUE/FALSE] {0} ({1})", description, functionalToggle.Exists() ? functionalToggle.Value.Text : "N/A");
            }
            else if (Percentages.TryGetValue(address, out description))
            {
                var functionalPercentage = Category5_Scaling.parseScaling(0, 100, state[0]);
                Console.WriteLine("[PERCENTAGE] {0} ({1} %)", description, functionalPercentage);
            }
            else if (Duration.TryGetValue(address, out description))
            {
                var functionalDuration = Category7_2ByteUnsignedValue.parseTwoByteUnsigned(1, state[0], state[1]);
                Console.WriteLine("[DURATION] {0} ({1} h)", description, functionalDuration);
            }
            else if (Current.TryGetValue(address, out description))
            {
                var functionalCurrent = Category7_2ByteUnsignedValue.parseTwoByteUnsigned(1, state[0], state[1]);
                Console.WriteLine("[ENERGY] {0} ({1} mA)", description, functionalCurrent);
            }
            else if (Temperatures.TryGetValue(address, out description))
            {
                var temp           = _connection.FromDataPoint("9.001", state); // (decimal)
                var functionalTemp = Category9_2ByteFloatValue.parseTwoByteFloat(state[0], state[1]);
                Console.WriteLine("[TEMP] {0} (C#: {1} °C) (F#: {2} °C)", description, temp, functionalTemp);
            }
            else if (LightStrength.TryGetValue(address, out description))
            {
                var functionalLightStrength = Category9_2ByteFloatValue.parseTwoByteFloat(state[0], state[1]);
                Console.WriteLine("[LUX] {0} ({1} Lux)", description, functionalLightStrength);
            }
            else if (Times.TryGetValue(address, out description))
            {
                var functionalTime = Category10_Time.parseTime(state[0], state[1], state[2]);
                Console.WriteLine("[TIME] {0} ({1}, {2})", description, functionalTime.Item1.Exists() ? functionalTime.Item1.Value.Text : string.Empty, functionalTime.Item2.ToString("c"));
            }
            else if (EnergyWattHour.TryGetValue(address, out description))
            {
                var wattHour           = _connection.FromDataPoint("13.010", state); // (int)
                var functionalWattHour = Category13_4ByteSignedValue.parseFourByteSigned(state[0], state[1], state[2], state[3]);
                Console.WriteLine("[ENERGY] {0} (C#: {1} Wh) (F#: {2} Wh)", description, wattHour, functionalWattHour);
            }
            else if (Dates.TryGetValue(address, out description))
            {
                var date           = (DateTime)_connection.FromDataPoint("11.001", state); // (DateTime)
                var functionalDate = Category11_Date.parseDate(state[0], state[1], state[2]);
                Console.WriteLine("[DATE] {0} (C#: {1}) (F#: {2})", description, date.ToString("dd/MM/yyyy"), functionalDate.ToString("dd/MM/yyyy"));
            }
            else if (Speed.TryGetValue(address, out description))
            {
                var speed           = _connection.FromDataPoint("9.005", state); // (decimal)
                var functionalSpeed = Category9_2ByteFloatValue.parseTwoByteFloat(state[0], state[1]);
                Console.WriteLine("[SPEED] {0} (C#: {1} m/s) (F#: {2} m/s)", description, speed, functionalSpeed);
            }
            else
            {
                _logFile.WriteLine("{0} - {1}", address, BitConverter.ToString(state));
            }
        }
Esempio n. 5
0
        private static void Event(string address, string state)
        {
            if (address.Equals("4/0/6") || address.Equals("5/1/1") || address.Equals("5/1/4") || address.Equals("5/1/10") || address.Equals("5/1/11"))
            {
                Console.WriteLine("New Event: device " + address + " has status (" + state + ") --> " + _connection.FromDataPoint("9.001", state));
            }
            else
            {
                var data = string.Empty;

                if (state.Length == 1)
                {
                    data = ((byte)state[0]).ToString();
                }
                else
                {
                    var bytes = new byte[state.Length];
                    for (var i = 0; i < state.Length; i++)
                    {
                        bytes[i] = Convert.ToByte(state[i]);
                    }

                    data = state.Aggregate(data, (current, t) => current + t.ToString());
                }

                Console.WriteLine("New Event: device " + address + " has status (" + state + ") --> " + data);
            }
        }
Esempio n. 6
0
        private void LogValue(KnxGroupWithStateDto knxGroup, string state, bool isEvent)
        {
            string stringFormat = string.Empty;

            if (!knxGroup.DPT.HasValue)
            {
                stringFormat = string.Format("New {0}: knxGroup {1} has state {2}", isEvent ? "Event" : "Status", knxGroup.Address, state);
            }
            else
            {
                switch (knxGroup.DPT.Value)
                {
                case KnxDPTEnum.PERCENTAGE:
                    decimal perc = (decimal)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.PERCENTAGE], state);
                    knxGroup.State = (double)perc;
                    stringFormat   = string.Format("knxGroup {0}, perc: {1}", knxGroup.Name, perc);
                    break;

                case KnxDPTEnum.TEMPERATURE:
                    decimal temp = (decimal)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.TEMPERATURE], state);
                    knxGroup.State = (double)temp;
                    stringFormat   = string.Format("knxGroup {0}, temp: {1}", knxGroup.Name, temp);
                    break;

                case KnxDPTEnum.SWITCH:
                    bool switchVal = (bool)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.SWITCH], state);
                    knxGroup.State = switchVal ? 1 : 0;
                    stringFormat   = string.Format("knxGroup {0}, switch: {1}", knxGroup.Name, switchVal ? "on" : "off");
                    break;

                case KnxDPTEnum.BOOLEAN:
                    bool booleanVal = (bool)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.SWITCH], state);
                    knxGroup.State = booleanVal ? 1 : 0;
                    stringFormat   = string.Format("knxGroup {0}, boolean: {1}", knxGroup.Name, booleanVal);
                    break;

                case KnxDPTEnum.UP_DOWN:
                    bool upDownVal = (bool)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.UP_DOWN], state);
                    knxGroup.State = upDownVal ? 1 : 0;
                    stringFormat   = string.Format("knxGroup {0}, upDown: {1}", knxGroup.Name, upDownVal ? "down" : "up");
                    break;

                case KnxDPTEnum.OPEN_CLOSE:
                    bool openCloseVal = (bool)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.OPEN_CLOSE], state);
                    knxGroup.State = openCloseVal ? 1 : 0;
                    stringFormat   = string.Format("knxGroup {0}, openClose: {1}", knxGroup.Name, openCloseVal ? "opened" : "closed");
                    break;

                case KnxDPTEnum.COUNTER_PULSES:
                    int counterPulsesVal = (int)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.COUNTER_PULSES], state);
                    knxGroup.State = (double)counterPulsesVal;
                    stringFormat   = string.Format("knxGroup {0}, counterPulsesVal: {1}", knxGroup.Name, counterPulsesVal);
                    break;

                case KnxDPTEnum.DIMMING_CONTROL:
                    int step = (int)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.DIMMING_CONTROL], state);
                    knxGroup.State = (double)step;
                    stringFormat   = string.Format("knxGroup {0}, step: {1}", knxGroup.Name, step);
                    break;

                case KnxDPTEnum.HVAC:
                    int hvac = (int)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.HVAC], state);
                    knxGroup.State = hvac;
                    switch (hvac)
                    {
                    case 0:
                        stringFormat = string.Format("knxGroup {0}, hvac: Auto", knxGroup.Name);
                        break;

                    case 1:
                        stringFormat = string.Format("knxGroup {0}, hvac: Comfort", knxGroup.Name);
                        break;

                    case 2:
                        stringFormat = string.Format("knxGroup {0}, hvac: Standby", knxGroup.Name);
                        break;

                    case 3:
                        stringFormat = string.Format("knxGroup {0}, hvac: Economy", knxGroup.Name);
                        break;

                    case 4:
                        stringFormat = string.Format("knxGroup {0}, hvac: Building Protection", knxGroup.Name);
                        break;

                    default:
                        stringFormat = string.Format("knxGroup {0}, hvac: {1}", knxGroup.Name, hvac);
                        break;
                    }
                    break;

                case KnxDPTEnum.HEAT_COOL:
                    bool heatCoolVal = (bool)_connection.FromDataPoint(KnxDPT.KnxDPTs[KnxDPTEnum.HEAT_COOL], state);
                    knxGroup.State = heatCoolVal ? 1 : 0;
                    stringFormat   = string.Format("knxGroup {0}, openClose: {1}", knxGroup.Name, heatCoolVal ? "heating" : "cooling");
                    break;

                default:
                    stringFormat = string.Format("New {0}: knxGroup {1} has state {2}", isEvent ? "Event" : "Status", knxGroup.Address, state);
                    break;
                }
            }
            _logger.LogInformation(stringFormat);
            Console.Out.WriteLine(stringFormat);
        }
Esempio n. 7
0
        private static void Event(object sender, KnxEventArgs args)
        {
            if (!(args.DestinationAddress is KnxGroupAddress address))
            {
                return;
            }

            var state = args.State;

            if (address.Equals("1/2/1") || address.Equals("1/2/2"))
            {
                Console.WriteLine("New Event: device " + address + " has status (" + state + ") --> " + _connection.FromDataPoint("9.001", state));
            }
            else if (
                address.Equals("1/2/3") ||
                address.Equals("1/2/4") ||
                address.Equals("1/2/5") ||
                address.Equals("1/2/5") ||
                address.Equals("1/2/6") ||
                address.Equals("1/2/7") ||
                address.Equals("1/2/8") ||
                address.Equals("1/2/9") ||
                address.Equals("1/2/10") ||
                address.Equals("1/2/11") ||
                address.Equals("1/2/12") ||
                address.Equals("1/2/13") ||
                address.Equals("1/2/14") ||
                address.Equals("1/2/15") ||
                address.Equals("1/2/16") ||
                address.Equals("1/2/17") ||
                address.Equals("1/2/18"))
            {
                var data = string.Empty;

                if (state.Length == 1)
                {
                    data = state[0].ToString();
                }
                else
                {
                    var bytes = new byte[state.Length];
                    for (var i = 0; i < state.Length; i++)
                    {
                        bytes[i] = Convert.ToByte(state[i]);
                    }

                    data = state.Aggregate(data, (current, t) => current + t.ToString());
                }

                Console.WriteLine("New Event: device " + address + " has status (" + state + ") --> " + data);
            }
        }
Esempio n. 8
0
        private static void Print(KnxConnection connection, KnxAddress knxAddress, byte[] state)
        {
            const int categoryWidth    = 15;
            const int descriptionWidth = -60;

            var address = knxAddress.ToString();

            if (Switches.TryGetValue(address, out var description))
            {
                var functionalToggle = Category1_SingleBit.parseSingleBit(state[0]);
                Console.WriteLine($"{"[ON/OFF]", categoryWidth} {description, descriptionWidth} ({(functionalToggle.Exists() ? functionalToggle.Value.Text : "N/A")})");
            }
            else if (Toggles.TryGetValue(address, out description))
            {
                var functionalToggle = Category1_SingleBit.parseSingleBit(state[0]);
                Console.WriteLine($"{"[TRUE/FALSE]", categoryWidth} {description, descriptionWidth} ({(functionalToggle.Exists() ? functionalToggle.Value.Text : "N/A")})");
            }
            else if (Percentages.TryGetValue(address, out description))
            {
                var functionalPercentage = Category5_Scaling.parseScaling(0, 100, state[0]);
                Console.WriteLine($"{"[PERCENTAGE]", categoryWidth} {description, descriptionWidth} ({functionalPercentage} %)");
            }
            else if (Duration.TryGetValue(address, out description))
            {
                var functionalDuration = Category7_2ByteUnsignedValue.parseTwoByteUnsigned(1, state[0], state[1]);
                Console.WriteLine($"{"[DURATION]", categoryWidth} {description, descriptionWidth} ({functionalDuration} h)");
            }
            else if (Current.TryGetValue(address, out description))
            {
                var functionalCurrent = Category7_2ByteUnsignedValue.parseTwoByteUnsigned(1, state[0], state[1]);
                Console.WriteLine($"{"[ENERGY]", categoryWidth} {description, descriptionWidth} ({functionalCurrent} mA)");
            }
            else if (Temperatures.TryGetValue(address, out description))
            {
                var temp           = connection.FromDataPoint("9.001", state); // (decimal)
                var functionalTemp = Category9_2ByteFloatValue.parseTwoByteFloat(state[0], state[1]);
                Console.WriteLine($"{"[TEMP]", categoryWidth} {description, descriptionWidth} (C#: {temp} °C) (F#: {functionalTemp} °C)");
            }
            else if (LightStrength.TryGetValue(address, out description))
            {
                var functionalLightStrength = Category9_2ByteFloatValue.parseTwoByteFloat(state[0], state[1]);
                Console.WriteLine($"{"[LUX]", categoryWidth} {description, descriptionWidth} ({functionalLightStrength} Lux)");
            }
            else if (Times.TryGetValue(address, out description))
            {
                var functionalTime = Category10_Time.parseTime(state[0], state[1], state[2]);
                Console.WriteLine($"{"[TIME]", categoryWidth} {description, descriptionWidth} ({(functionalTime.Item1.Exists() ? functionalTime.Item1.Value.Text : string.Empty)}, {functionalTime.Item2:c})");
            }
            else if (EnergyWattHour.TryGetValue(address, out description))
            {
                var wattHour           = connection.FromDataPoint("13.010", state); // (int)
                var functionalWattHour = Category13_4ByteSignedValue.parseFourByteSigned(state[0], state[1], state[2], state[3]);
                Console.WriteLine($"{"[ENERGY]", categoryWidth} {description, descriptionWidth} (C#: {wattHour} Wh) (F#: {functionalWattHour} Wh)");
            }
            else if (Dates.TryGetValue(address, out description))
            {
                var date           = (DateTime)connection.FromDataPoint("11.001", state); // (DateTime)
                var functionalDate = Category11_Date.parseDate(state[0], state[1], state[2]);
                Console.WriteLine($"{"[DATE]", categoryWidth} {description, descriptionWidth} (C#: {date:dd/MM/yyyy}) (F#: {functionalDate:dd/MM/yyyy})");
            }
            else if (Speed.TryGetValue(address, out description))
            {
                var speed           = connection.FromDataPoint("9.005", state); // (decimal)
                var functionalSpeed = Category9_2ByteFloatValue.parseTwoByteFloat(state[0], state[1]);
                Console.WriteLine($"{"[SPEED]",categoryWidth} {description, descriptionWidth} (C#: {speed} m/s) (F#: {functionalSpeed} m/s)");
            }
            else
            {
                _logFile.WriteLine("{0} - {1}", address, BitConverter.ToString(state));
            }
        }