You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by Christofer Dutz <ch...@c-ware.de> on 2022/11/24 07:39:14 UTC

Working on DataIo and Temporal types

Hi all,

for those of you who haven’t already looked into how we do the parsing of raw protocol payload to PlcValues:

['"IEC61131_BOOL"' BOOL
    [reserved uint 7 '0x00']
    [simple   bit    value]
]


  *   The case condition decides when a case is executed (obviously) (in above example … the dataProtocolId equals the string “IEC61131_BOOL”)
  *   In contrast to the other types, the Name of the type decides which type of PlcValue will be created (In above example, we’ll create a PlcBOOL)
  *   For most types, the conversion is trivial and simply the variable named “value” will be used to initialize the PlcValue

Now with temporal types, it gets a lot messier:

From S7:
['"IEC61131_DATE_AND_TIME"' DATE_AND_TIME
    [simple uint 16 year]
    [simple uint 8  month]
    [simple uint 8  day]
    [simple uint 8  dayOfWeek]
    [simple uint 8  hour]
    [simple uint 8  minutes]
    [simple uint 8  seconds]
    [simple uint 32 nanos]
]

Here we simply not only recognize “value” but also all of the above special variables and depending on which are available, we choose different constructors for the PlcValue.
Now I will be extending these with a number of new ones as iIt seems every protocol sort of defines them differently … some as “ms since epoch”, some “nanosecond since epoch”, some use some completely different reference-date (1900-01-01).
With some we could probably live with general “millisecondsSinceEpoch” and do the offset by using a virtual field that adds or subtracts a constant value … so something like this:

From ADS:

['DATE_AND_TIME' DATE_AND_TIME
    [simple uint 32 secondsSinceEpoch]
]

If some driver would have a different base, this would become:

['DATE_AND_TIME' DATE_AND_TIME
    [simple uint 32 mySecondsSinceSomething]

    [virtual uint 32 secondsSinceEpoch `mySecondsSinceSomething + {seconds between epoch and “something”}`]
]

Just thought I’d share this … Java is already quite mature with this respect … go still needs a bit of love here.

Chris