Esempio n. 1
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. 2
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));
            }
        }