You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2021/12/15 21:24:38 UTC
[plc4x] 04/09: - Implemented the BitString functionality ob BYTE, WORD, DWORD and LWORD
This is an automated email from the ASF dual-hosted git repository.
cdutz pushed a commit to branch feature/plc4net2
in repository https://gitbox.apache.org/repos/asf/plc4x.git
commit 1e474ccb03b0577be335c090c883a78353f192ca
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Thu Dec 3 15:06:22 2020 +0100
- Implemented the BitString functionality ob BYTE, WORD, DWORD and LWORD
---
sandbox/plc4net/spi/spi/model/values/PlcBYTE.cs | 27 ++++++++++++
sandbox/plc4net/spi/spi/model/values/PlcDWORD.cs | 39 +++++++++++++++++
sandbox/plc4net/spi/spi/model/values/PlcLWORD.cs | 55 ++++++++++++++++++++++++
sandbox/plc4net/spi/spi/model/values/PlcWORD.cs | 31 +++++++++++++
4 files changed, 152 insertions(+)
diff --git a/sandbox/plc4net/spi/spi/model/values/PlcBYTE.cs b/sandbox/plc4net/spi/spi/model/values/PlcBYTE.cs
index 5c3d26e..9351847 100644
--- a/sandbox/plc4net/spi/spi/model/values/PlcBYTE.cs
+++ b/sandbox/plc4net/spi/spi/model/values/PlcBYTE.cs
@@ -24,9 +24,36 @@ namespace org.apache.plc4net.spi.model.values
public class PlcBYTE : PlcBitString
{
private byte value;
+
public PlcBYTE(byte value)
{
this.value = value;
}
+
+ public new int GetBoolLength()
+ {
+ return 8;
+ }
+
+ public new bool GetBoolAt(int index)
+ {
+ if (index > 7)
+ {
+ return false;
+ }
+
+ return ((value >> index) & 1) == 1;
+ }
+
+ public new bool[] GetBoolArray()
+ {
+ return new[]
+ {
+ GetBoolAt(0), GetBoolAt(1),
+ GetBoolAt(2), GetBoolAt(3),
+ GetBoolAt(4), GetBoolAt(5),
+ GetBoolAt(6), GetBoolAt(7)
+ };
+ }
}
}
\ No newline at end of file
diff --git a/sandbox/plc4net/spi/spi/model/values/PlcDWORD.cs b/sandbox/plc4net/spi/spi/model/values/PlcDWORD.cs
index dad1973..3051771 100644
--- a/sandbox/plc4net/spi/spi/model/values/PlcDWORD.cs
+++ b/sandbox/plc4net/spi/spi/model/values/PlcDWORD.cs
@@ -29,5 +29,44 @@ namespace org.apache.plc4net.spi.model.values
{
this.value = value;
}
+
+ public new int GetBoolLength()
+ {
+ return 32;
+ }
+
+ public new bool GetBoolAt(int index)
+ {
+ if (index > 31)
+ {
+ return false;
+ }
+
+ return ((value >> index) & 1) == 1;
+ }
+
+ public new bool[] GetBoolArray()
+ {
+ return new[]
+ {
+ GetBoolAt(0), GetBoolAt(1),
+ GetBoolAt(2), GetBoolAt(3),
+ GetBoolAt(4), GetBoolAt(5),
+ GetBoolAt(6), GetBoolAt(7),
+ GetBoolAt(8), GetBoolAt(9),
+ GetBoolAt(10), GetBoolAt(11),
+ GetBoolAt(12), GetBoolAt(13),
+ GetBoolAt(14), GetBoolAt(15),
+ GetBoolAt(16), GetBoolAt(17),
+ GetBoolAt(18), GetBoolAt(19),
+ GetBoolAt(20), GetBoolAt(21),
+ GetBoolAt(22), GetBoolAt(23),
+ GetBoolAt(24), GetBoolAt(25),
+ GetBoolAt(26), GetBoolAt(27),
+ GetBoolAt(28), GetBoolAt(29),
+ GetBoolAt(30), GetBoolAt(31)
+ };
+ }
+
}
}
\ No newline at end of file
diff --git a/sandbox/plc4net/spi/spi/model/values/PlcLWORD.cs b/sandbox/plc4net/spi/spi/model/values/PlcLWORD.cs
index bfe68af..64d67f3 100644
--- a/sandbox/plc4net/spi/spi/model/values/PlcLWORD.cs
+++ b/sandbox/plc4net/spi/spi/model/values/PlcLWORD.cs
@@ -29,5 +29,60 @@ namespace org.apache.plc4net.spi.model.values
{
this.value = value;
}
+
+ public new int GetBoolLength()
+ {
+ return 64;
+ }
+
+ public new bool GetBoolAt(int index)
+ {
+ if (index > 63)
+ {
+ return false;
+ }
+
+ return ((value >> index) & 1) == 1;
+ }
+
+ public new bool[] GetBoolArray()
+ {
+ return new[]
+ {
+ GetBoolAt(0), GetBoolAt(1),
+ GetBoolAt(2), GetBoolAt(3),
+ GetBoolAt(4), GetBoolAt(5),
+ GetBoolAt(6), GetBoolAt(7),
+ GetBoolAt(8), GetBoolAt(9),
+ GetBoolAt(10), GetBoolAt(11),
+ GetBoolAt(12), GetBoolAt(13),
+ GetBoolAt(14), GetBoolAt(15),
+ GetBoolAt(16), GetBoolAt(17),
+ GetBoolAt(18), GetBoolAt(19),
+ GetBoolAt(20), GetBoolAt(21),
+ GetBoolAt(22), GetBoolAt(23),
+ GetBoolAt(24), GetBoolAt(25),
+ GetBoolAt(26), GetBoolAt(27),
+ GetBoolAt(28), GetBoolAt(29),
+ GetBoolAt(30), GetBoolAt(31),
+ GetBoolAt(32), GetBoolAt(33),
+ GetBoolAt(34), GetBoolAt(35),
+ GetBoolAt(36), GetBoolAt(37),
+ GetBoolAt(38), GetBoolAt(39),
+ GetBoolAt(40), GetBoolAt(41),
+ GetBoolAt(42), GetBoolAt(43),
+ GetBoolAt(44), GetBoolAt(45),
+ GetBoolAt(46), GetBoolAt(47),
+ GetBoolAt(48), GetBoolAt(49),
+ GetBoolAt(50), GetBoolAt(51),
+ GetBoolAt(52), GetBoolAt(53),
+ GetBoolAt(54), GetBoolAt(55),
+ GetBoolAt(56), GetBoolAt(57),
+ GetBoolAt(58), GetBoolAt(59),
+ GetBoolAt(60), GetBoolAt(61),
+ GetBoolAt(62), GetBoolAt(63)
+ };
+ }
+
}
}
\ No newline at end of file
diff --git a/sandbox/plc4net/spi/spi/model/values/PlcWORD.cs b/sandbox/plc4net/spi/spi/model/values/PlcWORD.cs
index 2af3b09..84e2b99 100644
--- a/sandbox/plc4net/spi/spi/model/values/PlcWORD.cs
+++ b/sandbox/plc4net/spi/spi/model/values/PlcWORD.cs
@@ -29,5 +29,36 @@ namespace org.apache.plc4net.spi.model.values
{
this.value = value;
}
+
+ public new int GetBoolLength()
+ {
+ return 16;
+ }
+
+ public new bool GetBoolAt(int index)
+ {
+ if (index > 15)
+ {
+ return false;
+ }
+
+ return ((value >> index) & 1) == 1;
+ }
+
+ public new bool[] GetBoolArray()
+ {
+ return new[]
+ {
+ GetBoolAt(0), GetBoolAt(1),
+ GetBoolAt(2), GetBoolAt(3),
+ GetBoolAt(4), GetBoolAt(5),
+ GetBoolAt(6), GetBoolAt(7),
+ GetBoolAt(8), GetBoolAt(9),
+ GetBoolAt(10), GetBoolAt(11),
+ GetBoolAt(12), GetBoolAt(13),
+ GetBoolAt(14), GetBoolAt(15)
+ };
+ }
+
}
}
\ No newline at end of file