Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group Address as of ETS4 #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/KNXLib/KnxHelper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System;
using System.Linq;
using KNXLib.Exceptions;

namespace KNXLib
{
internal class KnxHelper
{
#region Address Processing
#region Address Processing
// +-----------------------------------------------+
// 16 bits | INDIVIDUAL ADDRESS |
// +-----------------------+-----------------------+
Expand All @@ -18,15 +18,16 @@ internal class KnxHelper
// +-----------+-----------+ Device Address |
// |(Area Adrs)|(Line Adrs)| |
// +-----------------------+-----------------------+

// -- up to ETS3 --------------------------------------------+
// +-----------------------------------------------+
// 16 bits | GROUP ADDRESS (3 level) |
// +-----------------------+-----------------------+
// | OCTET 0 (high byte) | OCTET 1 (low byte) |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// bits | 7| 6| 5| 4| 3| 2| 1| 0| 7| 6| 5| 4| 3| 2| 1| 0|
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | | Main Grp | Midd G | Sub Group |
// up to ETS3| | Main Grp | Midd G | Sub Group |
// as of ETS4| Main Grp | Midd G | Sub Group |
// +--+--------------------+-----------------------+

// +-----------------------------------------------+
Expand All @@ -36,8 +37,14 @@ internal class KnxHelper
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// bits | 7| 6| 5| 4| 3| 2| 1| 0| 7| 6| 5| 4| 3| 2| 1| 0|
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | | Main Grp | Sub Group |
// up to ETS3| | Main Grp | Sub Group |
// as of ETS4| Main Grp | Sub Group |
// +--+--------------------+-----------------------+
// These tables clearly show why ETS3 can only visualize 16 MaGs (0...15).
// The reason is that the MaGs are coded in 4 bits. As of ETS4,
// the entire range of usable GAs is doubled by using one more bit.
// The 15th bit increases the number of group addresses by 32768 entries (2^16 - 2^15).

public static bool IsAddressIndividual(string address)
{
return address.Contains('.');
Expand Down Expand Up @@ -68,8 +75,13 @@ private static string GetAddress(byte[] addr, char separator, bool threeLevelAdd
else
{
// 3 level individual or group
// up to ETS3
// address = group
// ? ((addr[0] & 0x7F) >> 3).ToString()
// : (addr[0] >> 4).ToString();
// as of ETS4
address = group
? ((addr[0] & 0x7F) >> 3).ToString()
? (addr[0] >> 3).ToString()
: (addr[0] >> 4).ToString();

address += separator;
Expand Down Expand Up @@ -118,7 +130,10 @@ public static byte[] GetAddress(string address)
if (!threeLevelAddressing)
{
var part = int.Parse(parts[0]);
if (part > 15)
// -- up to ETS3
// if (part > 15)
// -- as of ETS4
if (part > 31)
throw new InvalidKnxAddressException(address);

addr[0] = (byte)(part << 3);
Expand All @@ -136,7 +151,10 @@ public static byte[] GetAddress(string address)
else
{
var part = int.Parse(parts[0]);
if (part > 15)
// -- up to ETS3
// if (part > 15)
// -- as of ETS4
if (part > 31)
throw new InvalidKnxAddressException(address);

addr[0] = group
Expand Down Expand Up @@ -264,7 +282,7 @@ public static KnxDestinationAddressType GetKnxDestinationAddressType(byte contro
// +-----------------------------------------------------------------------++-------------....
public static string GetData(int dataLength, byte[] apdu)
{

switch (dataLength)
{
case 0:
Expand Down