diff --git a/bundles/org.connectorio.addons.binding.fatek/docs/examples/fatek/fatek.things b/bundles/org.connectorio.addons.binding.fatek/docs/examples/fatek/fatek.things index 9b434d52..d3fdf0af 100644 --- a/bundles/org.connectorio.addons.binding.fatek/docs/examples/fatek/fatek.things +++ b/bundles/org.connectorio.addons.binding.fatek/docs/examples/fatek/fatek.things @@ -13,6 +13,12 @@ Bridge co7io-fatek:tcp:my-connection "My PLC#1" [ Type discrete : S1 [ register="S", index=1 ] Type discrete : T1 [ register="T", index=1 ] Type discrete : C1 [ register="C", index=1 ] + + Type data16 : R1x16 [ register="R", index=1 ] + Type data32 : R1x32 [ register="DR", index=1 ] + + Type rollershutter16 : rollx16 [ register="R", index=1, startRegister="M", startIndex=1, stopRegister="M", stopIndex=2 ] + Type rollershutter32 : rollx32 [ register="DR", index=1, startRegister="M", startIndex=1, stopRegister="M", stopIndex=2 ] } } diff --git a/bundles/org.connectorio.addons.binding.fatek/docs/examples/fatek/fatek.yaml b/bundles/org.connectorio.addons.binding.fatek/docs/examples/fatek/fatek.yaml index e624aefb..688e090d 100644 --- a/bundles/org.connectorio.addons.binding.fatek/docs/examples/fatek/fatek.yaml +++ b/bundles/org.connectorio.addons.binding.fatek/docs/examples/fatek/fatek.yaml @@ -43,3 +43,31 @@ things: configuration: index: 1 register: "C" + - id: "R1x16" + type: "data16" + configuration: + index: 1 + register: "R" + - id: "R1x32" + type: "data32" + configuration: + index: 1 + register: "DR" + - id: "rollx16" + type: "rollershutter16" + configuration: + stopIndex: 2 + startIndex: 1 + stopRegister: "M" + index: 1 + startRegister: "M" + register: "R" + - id: "rollx32" + type: "rollershutter32" + configuration: + stopIndex: 2 + startIndex: 1 + stopRegister: "M" + index: 1 + startRegister: "M" + register: "DR" diff --git a/bundles/org.connectorio.addons.binding.fatek/docs/fatek/descriptors/channel-types.adoc b/bundles/org.connectorio.addons.binding.fatek/docs/fatek/descriptors/channel-types.adoc index b15acca1..4fb41e2b 100644 --- a/bundles/org.connectorio.addons.binding.fatek/docs/fatek/descriptors/channel-types.adoc +++ b/bundles/org.connectorio.addons.binding.fatek/docs/fatek/descriptors/channel-types.adoc @@ -11,6 +11,42 @@ <> +| co7io-fatek:data16 +| Data register (16 bit) +| Data register of connected PLC encoded using 16 bit registers. + +<> + +| co7io-fatek:data32 +| Data register (32 bit) +| Data register of connected PLC encoded using 32 bit registers. + +<> + +| co7io-fatek:rollershutter16 +| Rollershutter (16-bit) +| Data register for position will use 16 bit registers. + +<> + +| co7io-fatek:rollershutter32 +| Rollershutter (32-bit) +| Data register for position will use 32 bit registers. + +<> + +| co7io-fatek:color16 +| Color (16-bit) +| Data register for position will use 16 bit registers. + +<> + +| co7io-fatek:color32 +| Color (32-bit) +| Data register for position will use 32 bit registers. + +<> + |=== @@ -25,8 +61,8 @@ Below table contain configuration parameters which can be assigned to channels o | register | TEXT -| Register symbol -| Symbol (kind) of register to read +| Register +| Type of discrete register to read or write. | index | INTEGER @@ -41,4 +77,255 @@ Below table contain configuration parameters which can be assigned to channels o |=== +[[co7io-fatek:data16]] +== Configuration of `co7io-fatek:data16` + +Below table contain configuration parameters which can be assigned to channels of type `co7io-fatek:data16`. + +[width="100%",caption="Channel type data16 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| register +| TEXT +| Register +| Type of data register to read or write. + +| index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| unsigned +| BOOLEAN +| Unsigned +| Values retrieved from and written to device assume unsigned representation. + +|=== + + +[[co7io-fatek:data32]] +== Configuration of `co7io-fatek:data32` + +Below table contain configuration parameters which can be assigned to channels of type `co7io-fatek:data32`. + +[width="100%",caption="Channel type data32 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| register +| TEXT +| Register +| Type of data register to read or write. + +| index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| unsigned +| BOOLEAN +| Unsigned +| Values retrieved from and written to device assume unsigned representation. Does not apply if floating option is set. + +| floating +| BOOLEAN +| floating point +| Indicate that read/write value is a floating point number. Overrides unsigned flag. + +|=== + + +[[co7io-fatek:rollershutter16]] +== Configuration of `co7io-fatek:rollershutter16` + +Below table contain configuration parameters which can be assigned to channels of type `co7io-fatek:rollershutter16`. + +[width="100%",caption="Channel type rollershutter16 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| register +| TEXT +| Register +| Data register used to retrieve position of roller shutter. + +| index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| unsigned +| BOOLEAN +| Unsigned +| Values retrieved from and written to device assume unsigned representation. Does not apply if floating option is set. + +| floating +| BOOLEAN +| floating point +| Indicate that read/write value is a floating point number. Overrides unsigned flag. + +| startRegister +| TEXT +| Register +| Type of discrete register to write UP command. + +| startIndex +| INTEGER +| Register index +| Index of register used to write data. + +| startInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +| stopRegister +| TEXT +| Register +| Type of discrete register to write DOWN command. + +| stopIndex +| INTEGER +| Register index +| Index of register used to retrieve data. + +| stopInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +|=== + + +[[co7io-fatek:rollershutter32]] +== Configuration of `co7io-fatek:rollershutter32` + +Below table contain configuration parameters which can be assigned to channels of type `co7io-fatek:rollershutter32`. + +[width="100%",caption="Channel type rollershutter32 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| register +| TEXT +| Register +| Data register used to retrieve position of roller shutter. + +| index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| unsigned +| BOOLEAN +| Unsigned +| Values retrieved from and written to device assume unsigned representation. Does not apply if floating option is set. + +| floating +| BOOLEAN +| floating point +| Indicate that read/write value is a floating point number. Overrides unsigned flag. + +| startRegister +| TEXT +| Register +| Type of discrete register to write UP command. + +| startIndex +| INTEGER +| Register index +| Index of register used to write data. + +| startInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +| stopRegister +| TEXT +| Register +| Type of discrete register to write DOWN command. + +| stopIndex +| INTEGER +| Register index +| Index of register used to retrieve data. + +| stopInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +|=== + + +[[co7io-fatek:color16]] +== Configuration of `co7io-fatek:color16` + +Below table contain configuration parameters which can be assigned to channels of type `co7io-fatek:color16`. + +[width="100%",caption="Channel type color16 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| color1register +| TEXT +| Color 1 register +| Data register used to retrieve or write Red or Hue part of color information. + +| color1index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| color2register +| TEXT +| Color 2 register +| Data register used to retrieve or write Green or Saturation part of color information. + +| color2index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| color3register +| TEXT +| Color 2 register +| Data register used to retrieve or write Blue or Brightness part of color information. + +| color3index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| rgb +| BOOLEAN +| RGB mode +| Write and interpret read data as RGB code instead of HSB. + +| switcherRegister +| TEXT +| Register +| Type of discrete register to write ON or OFF command. + +| switcherIndex +| INTEGER +| Register index +| Index of register used to write data. + +| switcherInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +|=== + + +[[co7io-fatek:color32]] +== Configuration of `co7io-fatek:color32` + +Below table contain configuration parameters which can be assigned to channels of type `co7io-fatek:color32`. + + diff --git a/bundles/org.connectorio.addons.binding.fatek/docs/fatek/descriptors/config-descriptions.adoc b/bundles/org.connectorio.addons.binding.fatek/docs/fatek/descriptors/config-descriptions.adoc index 420e0aa1..39c7f706 100644 --- a/bundles/org.connectorio.addons.binding.fatek/docs/fatek/descriptors/config-descriptions.adoc +++ b/bundles/org.connectorio.addons.binding.fatek/docs/fatek/descriptors/config-descriptions.adoc @@ -2,6 +2,34 @@ = Config descriptions +[[channel-type:co7io-fatek:data32]] +== Config `channel-type:co7io-fatek:data32` +[width="100%",caption="channel-type:co7io-fatek:data32 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| register +| TEXT +| Register +| Type of data register to read or write. + +| index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| unsigned +| BOOLEAN +| Unsigned +| Values retrieved from and written to device assume unsigned representation. Does not apply if floating option is set. + +| floating +| BOOLEAN +| floating point +| Indicate that read/write value is a floating point number. Overrides unsigned flag. + +|=== + [[thing-type:co7io-fatek:tcp]] == Config `thing-type:co7io-fatek:tcp` [width="100%",caption="thing-type:co7io-fatek:tcp configuration",cols="1,1,1,2"] @@ -94,8 +122,8 @@ | register | TEXT -| Register symbol -| Symbol (kind) of register to read +| Register +| Type of discrete register to read or write. | index | INTEGER @@ -109,4 +137,201 @@ |=== +[[channel-type:co7io-fatek:rollershutter32]] +== Config `channel-type:co7io-fatek:rollershutter32` +[width="100%",caption="channel-type:co7io-fatek:rollershutter32 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| register +| TEXT +| Register +| Data register used to retrieve position of roller shutter. + +| index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| unsigned +| BOOLEAN +| Unsigned +| Values retrieved from and written to device assume unsigned representation. Does not apply if floating option is set. + +| floating +| BOOLEAN +| floating point +| Indicate that read/write value is a floating point number. Overrides unsigned flag. + +| startRegister +| TEXT +| Register +| Type of discrete register to write UP command. + +| startIndex +| INTEGER +| Register index +| Index of register used to write data. + +| startInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +| stopRegister +| TEXT +| Register +| Type of discrete register to write DOWN command. + +| stopIndex +| INTEGER +| Register index +| Index of register used to retrieve data. + +| stopInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +|=== + +[[channel-type:co7io-fatek:data16]] +== Config `channel-type:co7io-fatek:data16` +[width="100%",caption="channel-type:co7io-fatek:data16 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| register +| TEXT +| Register +| Type of data register to read or write. + +| index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| unsigned +| BOOLEAN +| Unsigned +| Values retrieved from and written to device assume unsigned representation. + +|=== + +[[channel-type:co7io-fatek:rollershutter16]] +== Config `channel-type:co7io-fatek:rollershutter16` +[width="100%",caption="channel-type:co7io-fatek:rollershutter16 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| register +| TEXT +| Register +| Data register used to retrieve position of roller shutter. + +| index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| unsigned +| BOOLEAN +| Unsigned +| Values retrieved from and written to device assume unsigned representation. Does not apply if floating option is set. + +| floating +| BOOLEAN +| floating point +| Indicate that read/write value is a floating point number. Overrides unsigned flag. + +| startRegister +| TEXT +| Register +| Type of discrete register to write UP command. + +| startIndex +| INTEGER +| Register index +| Index of register used to write data. + +| startInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +| stopRegister +| TEXT +| Register +| Type of discrete register to write DOWN command. + +| stopIndex +| INTEGER +| Register index +| Index of register used to retrieve data. + +| stopInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +|=== + +[[channel-type:co7io-fatek:color16]] +== Config `channel-type:co7io-fatek:color16` +[width="100%",caption="channel-type:co7io-fatek:color16 configuration",cols="1,1,1,2"] +|=== +|Name | Type | Label ^|Description + +| color1register +| TEXT +| Color 1 register +| Data register used to retrieve or write Red or Hue part of color information. + +| color1index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| color2register +| TEXT +| Color 2 register +| Data register used to retrieve or write Green or Saturation part of color information. + +| color2index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| color3register +| TEXT +| Color 2 register +| Data register used to retrieve or write Blue or Brightness part of color information. + +| color3index +| INTEGER +| Register index +| Index of register used to retrieve data. + +| rgb +| BOOLEAN +| RGB mode +| Write and interpret read data as RGB code instead of HSB. + +| switcherRegister +| TEXT +| Register +| Type of discrete register to write ON or OFF command. + +| switcherIndex +| INTEGER +| Register index +| Index of register used to write data. + +| switcherInvert +| BOOLEAN +| Invert +| Invert logical representation of related register (0->1, 1->0). + +|=== + diff --git a/bundles/org.connectorio.addons.binding.fatek/docs/fatek/fatek.adoc b/bundles/org.connectorio.addons.binding.fatek/docs/fatek/fatek.adoc index 484d6eca..b47facfb 100644 --- a/bundles/org.connectorio.addons.binding.fatek/docs/fatek/fatek.adoc +++ b/bundles/org.connectorio.addons.binding.fatek/docs/fatek/fatek.adoc @@ -57,8 +57,44 @@ There are several kinds of addresses defined by protocol. | `S` | Step relay | `ON` and `OFF` (`OnOffType`) | `T` | Timer contact | `ON` and `OFF` (`OnOffType`) | `C` | Counter contact | `ON` and `OFF` (`OnOffType`) + +| `R` | Data register (16 bit) | `Number` (INT16/UINT16) +| `D` | Data register (16 bit) | `Number` (INT16/UINT16) +| `F` | File register (16 bit) | `Number` (INT16/UINT16) + +| `DR` | Data Register (32 bit) | `Number` (INT32/UINT32) or `Float` +| `DD` | Data Register (32 bit) | `Number` (INT32/UINT32) or `Float` +| `DF` | File register (32 bit) | `Number` (INT32/UINT32) + +| `RT` | Timer register (16 bit) | `Number` (INT16/UINT16) +| `RC` | Counter register (16 bit) | `Number` (INT16/UINT16) +| `DRT` | Timer register (32 bit) | `Number` (INT32/UINT32) or `Float` +| `DRC` | Counter register (32 bit) | `Number` (INT32/UINT32) or `Float` + +| `WX` | Input discrete data register (16 bit) | `Number` (INT16/UINT16) +| `WY` | Output relay data register (16 bit) | `Number` (INT16/UINT16) +| `WM` | Internal relay data register (16 bit) | `Number` (INT16/UINT16) +| `WS` | Step relay data register (16 bit) | `Number` (INT16/UINT16) +| `WT` | Timer discrete data register (16 bit) | `Number` (INT16/UINT16) +| `WC` | Counter discrete data register (16 bit) | `Number` (INT16/UINT16) + +| `DWX` | Input discrete data register (32 bit) | `Number` (INT32/UINT32) or `Float` +| `DWY` | Output relay data register (32 bit) | `Number` (INT32/UINT32) or `Float` +| `DWM` | Internal relay data register (32 bit) | `Number` (INT32/UINT32) or `Float` +| `DWS` | Step relay data register (32 bit) | `Number` (INT32/UINT32) or `Float` +| `DWT` | Timer discrete data register (32 bit) | `Number` (INT32/UINT32) or `Float` +| `DWC` | Counter discrete data register (32 bit) | `Number` (INT32/UINT32) or `Float` + |=== +The discrete inputs might be commendable (outputs, relays) or read only (input, contact). +Binding does not verify read/write access. +For data registers (`R`, `D`, `F` etc.) encoding of contained data might vary. +In principle - all registers of 16 bit length will be read and written using integer representation. +Larger values might be interpreted as integer or floating point number. +In order to use floating point representation use `data32` channel with `floating=true` option. +The unsinged representation is always forced for `data16` and `data32` channels using `unsinged=true` option. + == Textual configuration Below is example of a text configuration which you can use as a started. diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/FatekBindingConstants.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/FatekBindingConstants.java index a8215350..ad8b043e 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/FatekBindingConstants.java +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/FatekBindingConstants.java @@ -41,6 +41,12 @@ public interface FatekBindingConstants extends BaseBindingConstants { // common dynamic channel types ChannelTypeUID CHANNEL_TYPE_DISCRETE = new ChannelTypeUID(BINDING_ID, "discrete"); + ChannelTypeUID CHANNEL_TYPE_DATA16 = new ChannelTypeUID(BINDING_ID, "data16"); + ChannelTypeUID CHANNEL_TYPE_DATA32 = new ChannelTypeUID(BINDING_ID, "data32"); + ChannelTypeUID CHANNEL_TYPE_ROLLERSHUTTER16 = new ChannelTypeUID(BINDING_ID, "rollershutter16"); + ChannelTypeUID CHANNEL_TYPE_ROLLERSHUTTER32 = new ChannelTypeUID(BINDING_ID, "rollershutter32"); + ChannelTypeUID CHANNEL_TYPE_COLOR16 = new ChannelTypeUID(BINDING_ID, "color16"); + ChannelTypeUID CHANNEL_TYPE_COLOR32 = new ChannelTypeUID(BINDING_ID, "color32"); } diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/BaseChannelConfig.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/BaseChannelConfig.java new file mode 100644 index 00000000..83f7eb22 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/BaseChannelConfig.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.config.channel; + +import org.simplify4u.jfatek.registers.RegName; + +public abstract class BaseChannelConfig implements RegisterConfig { + + public int index; + + public RegName register; + + public BaseChannelConfig() {} + public BaseChannelConfig(RegName register, int index) { + this.register = register; + this.index = index; + } + + @Override + public RegName getRegister() { + return register; + } + + @Override + public int getIndex() { + return index; + } + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/binary/DiscreteChannelConfig.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/binary/DiscreteChannelConfig.java index f58cf326..f4b397be 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/binary/DiscreteChannelConfig.java +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/binary/DiscreteChannelConfig.java @@ -17,24 +17,17 @@ */ package org.connectorio.addons.binding.fatek.config.channel.binary; -import org.connectorio.addons.binding.fatek.config.channel.RegisterConfig; +import org.connectorio.addons.binding.fatek.config.channel.BaseChannelConfig; import org.simplify4u.jfatek.registers.RegName; -public class DiscreteChannelConfig implements RegisterConfig { +public class DiscreteChannelConfig extends BaseChannelConfig { - public int index; - - public RegName register; public boolean invert; - @Override - public RegName getRegister() { - return register; - } - - @Override - public int getIndex() { - return index; + public DiscreteChannelConfig() {} + public DiscreteChannelConfig(RegName register, int index, boolean invert) { + super(register, index); + this.invert = invert; } } diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/color/ColorChannelConfig.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/color/ColorChannelConfig.java new file mode 100644 index 00000000..d9f38abe --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/color/ColorChannelConfig.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.config.channel.color; + +import org.connectorio.addons.binding.fatek.config.channel.data.DataChannelConfig; +import org.simplify4u.jfatek.registers.RegName; + +public class ColorChannelConfig extends DataChannelConfig { + + // RGB color control mode + public boolean rgb = false; + + public RegName color1register; + public int color1index; + + public RegName color2register; + public int color2index; + + public RegName color3register; + public int color3index; + + // optional + public RegName switcherRegister; + public int switcherIndex; + public boolean switcherInvert; + + // increase decrease step - optional + public int step; + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/data/Data32ChannelConfig.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/data/Data32ChannelConfig.java new file mode 100644 index 00000000..9455154a --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/data/Data32ChannelConfig.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.config.channel.data; + +public class Data32ChannelConfig extends DataChannelConfig { + + public boolean floating; + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/data/DataChannelConfig.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/data/DataChannelConfig.java new file mode 100644 index 00000000..85e88d79 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/data/DataChannelConfig.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.config.channel.data; + +import org.connectorio.addons.binding.fatek.config.channel.BaseChannelConfig; +import org.simplify4u.jfatek.registers.RegName; + +public class DataChannelConfig extends BaseChannelConfig { + + public boolean unsigned; + + public DataChannelConfig() {} + + public DataChannelConfig(RegName register, int index) { + this.register = register; + this.index = index; + } + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/rollershutter/RollerShutter32ChannelConfig.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/rollershutter/RollerShutter32ChannelConfig.java new file mode 100644 index 00000000..bf7ef82d --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/rollershutter/RollerShutter32ChannelConfig.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.config.channel.rollershutter; + +import org.connectorio.addons.binding.fatek.config.channel.data.Data32ChannelConfig; +import org.simplify4u.jfatek.registers.RegName; + +public class RollerShutter32ChannelConfig extends Data32ChannelConfig { + + public RegName startRegister; + public int startIndex; + public boolean startInvert; + + public RegName stopRegister; + public int stopIndex; + public boolean stopInvert; + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/rollershutter/RollerShutterChannelConfig.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/rollershutter/RollerShutterChannelConfig.java new file mode 100644 index 00000000..9c61c909 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/config/channel/rollershutter/RollerShutterChannelConfig.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.config.channel.rollershutter; + +import org.connectorio.addons.binding.fatek.config.channel.data.DataChannelConfig; +import org.simplify4u.jfatek.registers.RegName; + +public class RollerShutterChannelConfig extends DataChannelConfig { + + public int startIndex; + public RegName startRegister; + public boolean startInvert; + + public int stopIndex; + public RegName stopRegister; + public boolean stopInvert; + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/RegisterParser.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/RegisterParser.java new file mode 100644 index 00000000..5900c95e --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/RegisterParser.java @@ -0,0 +1,89 @@ +package org.connectorio.addons.binding.fatek.internal; + +import static org.simplify4u.jfatek.registers.DisReg.*; +import static org.simplify4u.jfatek.registers.DataReg.*; + +import org.connectorio.addons.binding.fatek.config.channel.RegisterConfig; +import org.simplify4u.jfatek.registers.DataReg; +import org.simplify4u.jfatek.registers.DisReg; + +public class RegisterParser { + + public static DisReg parseDiscrete(RegisterConfig config) { + switch (config.getRegister()) { + case X: + return X(config.getIndex()); + case Y: + return Y(config.getIndex()); + case M: + return M(config.getIndex()); + case S: + return S(config.getIndex()); + case T: + return T(config.getIndex()); + case C: + return C(config.getIndex()); + default: + throw new IllegalArgumentException("Unsupported register kind " + config.getRegister()); + } + } + + public static DataReg parseData16(RegisterConfig config) { + switch (config.getRegister()) { + case R: + return R(config.getIndex()); + case D: + return D(config.getIndex()); + case F: + return F(config.getIndex()); + case RT: + return RT(config.getIndex()); + case RC: + return RC(config.getIndex()); + case WX: + return WX(config.getIndex()); + case WY: + return WY(config.getIndex()); + case WM: + return WM(config.getIndex()); + case WS: + return WS(config.getIndex()); + case WT: + return WT(config.getIndex()); + case WC: + return WC(config.getIndex()); + default: + throw new IllegalArgumentException("Unsupported register kind " + config.getRegister()); + } + } + + public static DataReg parseData32(RegisterConfig config) { + switch (config.getRegister()) { + case DR: + return DR(config.getIndex()); + case DD: + return DD(config.getIndex()); + case DF: + return DF(config.getIndex()); + case DRT: + return DRT(config.getIndex()); + case DRC: + return DRC(config.getIndex()); + case DWX: + return DWX(config.getIndex()); + case DWY: + return DWY(config.getIndex()); + case DWM: + return DWM(config.getIndex()); + case DWS: + return DWS(config.getIndex()); + case DWT: + return DWT(config.getIndex()); + case DWC: + return DWC(config.getIndex()); + default: + throw new IllegalArgumentException("Unsupported register kind " + config.getRegister()); + } + } + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/BinaryChannelHandler.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/BinaryChannelHandler.java index 9528e2b5..782f894e 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/BinaryChannelHandler.java +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/BinaryChannelHandler.java @@ -17,15 +17,15 @@ */ package org.connectorio.addons.binding.fatek.internal.channel; -import static org.simplify4u.jfatek.registers.DisReg.*; - -import org.connectorio.addons.binding.fatek.config.channel.binary.DiscreteChannelConfig; -import org.openhab.core.library.types.OnOffType; -import org.openhab.core.library.types.OpenClosedType; +import java.util.Collections; +import java.util.List; +import org.connectorio.addons.binding.fatek.internal.channel.converter.Converter; import org.openhab.core.thing.Channel; import org.openhab.core.thing.ChannelUID; import org.openhab.core.types.Command; import org.openhab.core.types.State; +import org.simplify4u.jfatek.FatekCommand; +import org.simplify4u.jfatek.FatekWriteDiscreteCmd; import org.simplify4u.jfatek.registers.DisReg; import org.simplify4u.jfatek.registers.Reg; import org.simplify4u.jfatek.registers.RegValue; @@ -33,39 +33,18 @@ public class BinaryChannelHandler implements FatekChannelHandler { private final DisReg register; + private final Converter converter; private final ChannelUID channel; - private final boolean invert; - public BinaryChannelHandler(Channel channel, DiscreteChannelConfig config) { + public BinaryChannelHandler(Channel channel, DisReg register, Converter converter) { this.channel = channel.getUID(); - this.invert = config.invert; - switch (config.getRegister()) { - case X: - this.register = X(config.getIndex()); - break; - case Y: - this.register = Y(config.getIndex()); - break; - case M: - this.register = M(config.getIndex()); - break; - case S: - this.register = S(config.getIndex()); - break; - case T: - this.register = T(config.getIndex()); - break; - case C: - this.register = C(config.getIndex()); - break; - default: - throw new IllegalArgumentException("Unsupported register kind " + config.getRegister()); - } + this.register = register; + this.converter = converter; } @Override - public Reg register() { - return register; + public List registers() { + return Collections.singletonList(register); } @Override @@ -74,21 +53,17 @@ public ChannelUID channel() { } @Override - public RegValue prepareWrite(Command command) { - boolean value; - if (command instanceof OpenClosedType) { - value = OpenClosedType.CLOSED == command; - } else { - value = OnOffType.ON == command; + public FatekCommand prepareWrite(Command command) { + RegValue value = converter.toValue(command); + if (value != null) { + return new FatekWriteDiscreteCmd(null, register, value.boolValue()); } - - return RegValue.getForReg(register, !invert ? !value : value); + return null; } @Override - public State state(RegValue value) { - boolean status = invert ? !value.boolValue() : value.boolValue(); - return status ? OnOffType.ON : OnOffType.OFF; + public State state(List value) { + return converter.toState(value.get(0)); } } diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/ColorChannelHandler.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/ColorChannelHandler.java new file mode 100644 index 00000000..b5ca4645 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/ColorChannelHandler.java @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.internal.channel; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicReference; +import org.connectorio.addons.binding.fatek.config.channel.color.ColorChannelConfig; +import org.connectorio.addons.binding.fatek.internal.channel.converter.ColorConverter; +import org.connectorio.addons.binding.fatek.internal.channel.converter.Converter; +import org.openhab.core.library.types.HSBType; +import org.openhab.core.library.types.IncreaseDecreaseType; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.PercentType; +import org.openhab.core.thing.Channel; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.simplify4u.jfatek.FatekCommand; +import org.simplify4u.jfatek.FatekWriteDiscreteCmd; +import org.simplify4u.jfatek.FatekWriteMixDataCmd; +import org.simplify4u.jfatek.registers.DataReg; +import org.simplify4u.jfatek.registers.DisReg; +import org.simplify4u.jfatek.registers.Reg; +import org.simplify4u.jfatek.registers.RegValue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ColorChannelHandler implements FatekChannelHandler { + + private final Logger logger = LoggerFactory.getLogger(ColorChannelHandler.class); + + private final ChannelUID channel; + private final ColorChannelConfig config; + private final DataReg color1; + private final DataReg color2; + private final DataReg color3; + private final DisReg switcher; + private final ColorConverter converter; + private final Converter switcherConverter; + + // a volatile state + private AtomicReference state = new AtomicReference<>(); + + public ColorChannelHandler(Channel channel, ColorChannelConfig config, DataReg color1, DataReg color2, DataReg color3, + ColorConverter converter, DisReg switcher, Converter switcherConverter) { + this.channel = channel.getUID(); + this.config = config; + this.color1 = color1; + this.color2 = color2; + this.color3 = color3; + this.switcher = switcher; + this.converter = converter; + this.switcherConverter = switcherConverter; + } + + @Override + public List registers() { + return Arrays.asList(color1, color2, color3); + } + + @Override + public ChannelUID channel() { + return channel; + } + + @Override + public FatekCommand prepareWrite(Command command) { + if (command instanceof IncreaseDecreaseType) { + if (state.get() == null) { + return null; + } + + HSBType hsb = state.get(); + if (IncreaseDecreaseType.INCREASE.equals(command)) { + int brightness = Math.min(hsb.getBrightness().intValue() + config.step, 100); + return colorCommand(new HSBType(hsb.getHue(), hsb.getSaturation(), new PercentType(brightness))); + } else if (IncreaseDecreaseType.DECREASE.equals(command)) { + int brightness = Math.max(hsb.getBrightness().intValue() - config.step, 0); + return colorCommand(new HSBType(hsb.getHue(), hsb.getSaturation(), new PercentType(brightness))); + } else { + return null; + } + } else if (command instanceof OnOffType) { + RegValue value = switcherConverter.toValue(command); + if (value != null) { + return new FatekWriteDiscreteCmd(null, switcher, value.boolValue()); + } + return null; + } else if (command instanceof HSBType) { + return colorCommand((HSBType) command); + } + + logger.warn("Unsupported command {} received by color channel {}", command, channel); + return null; + } + + private FatekCommand colorCommand(HSBType hsbType) { + List value = converter.toValue(hsbType); + if (value != null) { + return new FatekWriteMixDataCmd(null, Map.of( + color1, value.get(0), + color2, value.get(1), + color3, value.get(2) + )); + } + return null; + } + + @Override + public State state(List value) { + State convertedState = converter.toState(value.get(0), value.get(1), value.get(2)); + if (convertedState instanceof HSBType) { + // retain last read value of color state + state.set((HSBType) convertedState); + } + return convertedState; + } + + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/DataChannelHandler.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/DataChannelHandler.java new file mode 100644 index 00000000..2a9d51e7 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/DataChannelHandler.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.internal.channel; + +import java.util.Collections; +import java.util.List; +import org.connectorio.addons.binding.fatek.internal.channel.converter.Converter; +import org.openhab.core.thing.Channel; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.simplify4u.jfatek.FatekCommand; +import org.simplify4u.jfatek.FatekPLC; +import org.simplify4u.jfatek.FatekWriteDataCmd; +import org.simplify4u.jfatek.registers.DataReg; +import org.simplify4u.jfatek.registers.Reg; +import org.simplify4u.jfatek.registers.RegValue; +import org.simplify4u.jfatek.registers.RegValueData; + +public class DataChannelHandler implements FatekChannelHandler { + + private final ChannelUID channel; + private final DataReg register; + private final Converter converter; + + public DataChannelHandler(Channel channel, DataReg register, Converter converter) { + this.channel = channel.getUID(); + this.register = register; + this.converter = converter; + } + + @Override + public List registers() { + return Collections.singletonList(register); + } + + @Override + public ChannelUID channel() { + return channel; + } + + @Override + public FatekCommand prepareWrite(Command command) { + RegValue value = converter.toValue(command); + if (value instanceof RegValueData) { + return new FatekWriteDataCmd((FatekPLC) null, register, (RegValueData) value); + } + return null; + } + + @Override + public State state(List value) { + return converter.toState(value.get(0)); + } + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/DefaultChannelHandlerFactory.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/DefaultChannelHandlerFactory.java index 339cd178..a19e83a5 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/DefaultChannelHandlerFactory.java +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/DefaultChannelHandlerFactory.java @@ -19,7 +19,20 @@ import org.connectorio.addons.binding.fatek.FatekBindingConstants; import org.connectorio.addons.binding.fatek.config.channel.binary.DiscreteChannelConfig; +import org.connectorio.addons.binding.fatek.config.channel.color.ColorChannelConfig; +import org.connectorio.addons.binding.fatek.config.channel.data.Data32ChannelConfig; +import org.connectorio.addons.binding.fatek.config.channel.data.DataChannelConfig; +import org.connectorio.addons.binding.fatek.config.channel.rollershutter.RollerShutter32ChannelConfig; +import org.connectorio.addons.binding.fatek.config.channel.rollershutter.RollerShutterChannelConfig; +import org.connectorio.addons.binding.fatek.internal.RegisterParser; +import org.connectorio.addons.binding.fatek.internal.channel.converter.ColorConverter; +import org.connectorio.addons.binding.fatek.internal.channel.converter.Converter; +import org.connectorio.addons.binding.fatek.internal.channel.converter.Data16Converter; +import org.connectorio.addons.binding.fatek.internal.channel.converter.Data32Converter; +import org.connectorio.addons.binding.fatek.internal.channel.converter.DiscreteConverter; import org.openhab.core.thing.Channel; +import org.simplify4u.jfatek.registers.DataReg; +import org.simplify4u.jfatek.registers.DisReg; public class DefaultChannelHandlerFactory implements FatekChannelHandlerFactory { @@ -27,9 +40,70 @@ public class DefaultChannelHandlerFactory implements FatekChannelHandlerFactory public FatekChannelHandler create(Channel channel) { if (FatekBindingConstants.CHANNEL_TYPE_DISCRETE.equals(channel.getChannelTypeUID())) { DiscreteChannelConfig config = channel.getConfiguration().as(DiscreteChannelConfig.class); - return new BinaryChannelHandler(channel, config); + return new BinaryChannelHandler(channel, RegisterParser.parseDiscrete(config), new DiscreteConverter(config)); + } + if (FatekBindingConstants.CHANNEL_TYPE_DATA16.equals(channel.getChannelTypeUID())) { + DataChannelConfig config = channel.getConfiguration().as(DataChannelConfig.class); + return new DataChannelHandler(channel, RegisterParser.parseData16(config), new Data16Converter(config)); + } + if (FatekBindingConstants.CHANNEL_TYPE_DATA32.equals(channel.getChannelTypeUID())) { + Data32ChannelConfig config = channel.getConfiguration().as(Data32ChannelConfig.class); + return new DataChannelHandler(channel, RegisterParser.parseData32(config), new Data32Converter(config)); + } + if (FatekBindingConstants.CHANNEL_TYPE_ROLLERSHUTTER16.equals(channel.getChannelTypeUID())) { + RollerShutterChannelConfig config = channel.getConfiguration().as(RollerShutterChannelConfig.class); + DiscreteChannelConfig startCfg = new DiscreteChannelConfig(config.startRegister, config.startIndex, config.startInvert); + DiscreteChannelConfig stopCfg = new DiscreteChannelConfig(config.stopRegister, config.stopIndex, config.stopInvert); + return new RollerShutterChannelHandler(channel, RegisterParser.parseData16(config), + RegisterParser.parseDiscrete(startCfg), + RegisterParser.parseDiscrete(startCfg), + new Data16Converter(config), + new DiscreteConverter(startCfg), + new DiscreteConverter(stopCfg) + ); + } + if (FatekBindingConstants.CHANNEL_TYPE_ROLLERSHUTTER32.equals(channel.getChannelTypeUID())) { + RollerShutter32ChannelConfig config = channel.getConfiguration().as(RollerShutter32ChannelConfig.class); + DiscreteChannelConfig startCfg = new DiscreteChannelConfig(config.startRegister, config.startIndex, config.startInvert); + DiscreteChannelConfig stopCfg = new DiscreteChannelConfig(config.stopRegister, config.stopIndex, config.stopInvert); + return new RollerShutterChannelHandler(channel, RegisterParser.parseData16(config), + RegisterParser.parseDiscrete(startCfg), + RegisterParser.parseDiscrete(startCfg), + new Data32Converter(config), + new DiscreteConverter(startCfg), + new DiscreteConverter(stopCfg) + ); + } + if (FatekBindingConstants.CHANNEL_TYPE_COLOR16.equals(channel.getChannelTypeUID())) { + ColorChannelConfig config = channel.getConfiguration().as(ColorChannelConfig.class); + DataReg color1cfg = RegisterParser.parseData16(new DataChannelConfig(config.color1register, config.color1index)); + DataReg color2cfg = RegisterParser.parseData16(new DataChannelConfig(config.color2register, config.color2index)); + DataReg color3cfg = RegisterParser.parseData16(new DataChannelConfig(config.color3register, config.color3index)); + return createColorHandler(channel, config, color1cfg, color2cfg, color3cfg); + } + if (FatekBindingConstants.CHANNEL_TYPE_COLOR32.equals(channel.getChannelTypeUID())) { + ColorChannelConfig config = channel.getConfiguration().as(ColorChannelConfig.class); + DataReg color1cfg = RegisterParser.parseData32(new DataChannelConfig(config.color1register, config.color1index)); + DataReg color2cfg = RegisterParser.parseData32(new DataChannelConfig(config.color2register, config.color2index)); + DataReg color3cfg = RegisterParser.parseData32(new DataChannelConfig(config.color3register, config.color3index)); + return createColorHandler(channel, config, color1cfg, color2cfg, color3cfg); } return null; } + private FatekChannelHandler createColorHandler(Channel channel, ColorChannelConfig config, DataReg color1, DataReg color2, DataReg color3) { + DisReg switcher = null; + Converter switcherConverter = null; + if (config.switcherRegister != null && config.switcherIndex != 0) { + DiscreteChannelConfig switchCfg = new DiscreteChannelConfig(config.switcherRegister, config.switcherIndex, config.switcherInvert); + switcher = RegisterParser.parseDiscrete(switchCfg); + switcherConverter = new DiscreteConverter(switchCfg); + } + return new ColorChannelHandler(channel, config, + color1, color2, color3, + new ColorConverter(color1, color2, color3, config.rgb), + switcher, switcherConverter + ); + } + } diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/FatekChannelHandler.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/FatekChannelHandler.java index e9719b9e..24e85de6 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/FatekChannelHandler.java +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/FatekChannelHandler.java @@ -17,21 +17,23 @@ */ package org.connectorio.addons.binding.fatek.internal.channel; +import java.util.List; import org.openhab.core.thing.ChannelUID; import org.openhab.core.types.Command; import org.openhab.core.types.State; +import org.simplify4u.jfatek.FatekCommand; import org.simplify4u.jfatek.registers.Reg; import org.simplify4u.jfatek.registers.RegValue; public interface FatekChannelHandler { // identification - Reg register(); + List registers(); ChannelUID channel(); // write - RegValue prepareWrite(Command command); + FatekCommand prepareWrite(Command command); // fetch - State state(RegValue value); + State state(List value); } diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/FatekChannelHandlerFactory.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/FatekChannelHandlerFactory.java index 30ca6eb9..f14437a3 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/FatekChannelHandlerFactory.java +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/FatekChannelHandlerFactory.java @@ -22,4 +22,5 @@ public interface FatekChannelHandlerFactory { FatekChannelHandler create(Channel channel); + } diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/RollerShutterChannelHandler.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/RollerShutterChannelHandler.java new file mode 100644 index 00000000..b0ea4573 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/RollerShutterChannelHandler.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.internal.channel; + +import java.util.Collections; +import java.util.List; +import java.util.Map; +import org.connectorio.addons.binding.fatek.internal.channel.converter.Converter; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.StopMoveType; +import org.openhab.core.library.types.UpDownType; +import org.openhab.core.thing.Channel; +import org.openhab.core.thing.ChannelUID; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.simplify4u.jfatek.FatekCommand; +import org.simplify4u.jfatek.FatekWriteDataCmd; +import org.simplify4u.jfatek.FatekWriteMixDataCmd; +import org.simplify4u.jfatek.registers.DataReg; +import org.simplify4u.jfatek.registers.DisReg; +import org.simplify4u.jfatek.registers.Reg; +import org.simplify4u.jfatek.registers.RegValue; +import org.simplify4u.jfatek.registers.RegValueData; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RollerShutterChannelHandler implements FatekChannelHandler { + + private final Logger logger = LoggerFactory.getLogger(RollerShutterChannelHandler.class); + + private final ChannelUID channel; + private final DataReg register; + private final DisReg startReg; + private final DisReg stopReg; + private final Converter positionConverter; + private final Converter startConverter; + private final Converter stopConverter; + + public RollerShutterChannelHandler(Channel channel, DataReg register, DisReg startReg, DisReg stopReg, + Converter positionConverter, Converter startConverter, Converter stopConverter) { + this.channel = channel.getUID(); + this.register = register; + this.startReg = startReg; + this.stopReg = stopReg; + this.positionConverter = positionConverter; + this.startConverter = startConverter; + this.stopConverter = stopConverter; + } + + @Override + public List registers() { + return Collections.singletonList(register); + } + + @Override + public ChannelUID channel() { + return channel; + } + + @Override + public FatekCommand prepareWrite(Command command) { + RegValue positionValue = positionConverter.toValue(command); + if (positionValue instanceof RegValueData) { + return new FatekWriteDataCmd(null, register, (RegValueData) positionValue); + } + + if (UpDownType.UP.equals(command)) { + RegValue start = startConverter.toValue(OnOffType.ON); + RegValue stop = stopConverter.toValue(OnOffType.OFF); + return new FatekWriteMixDataCmd(null, Map.of( + startReg, start, + stopReg, stop + )); + } else if (UpDownType.DOWN.equals(command)) { + RegValue start = startConverter.toValue(OnOffType.OFF); + RegValue stop = stopConverter.toValue(OnOffType.ON); + return new FatekWriteMixDataCmd(null, Map.of( + startReg, start, + stopReg, stop + )); + } else if (StopMoveType.STOP.equals(command)) { + RegValue start = startConverter.toValue(OnOffType.OFF); + RegValue stop = stopConverter.toValue(OnOffType.OFF); + return new FatekWriteMixDataCmd(null, Map.of( + startReg, start, + stopReg, stop + )); + } + + logger.warn("Unsupported command {} received by rollershutter channel {}", command, channel); + + return null; + } + + @Override + public State state(List value) { + return positionConverter.toState(value.get(0)); + } + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/ColorConverter.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/ColorConverter.java new file mode 100644 index 00000000..75593ed6 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/ColorConverter.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.internal.channel.converter; + +import java.util.Arrays; +import java.util.List; +import org.openhab.core.library.types.DecimalType; +import org.openhab.core.library.types.HSBType; +import org.openhab.core.library.types.PercentType; +import org.openhab.core.types.State; +import org.simplify4u.jfatek.registers.Reg; +import org.simplify4u.jfatek.registers.RegValue; + +public class ColorConverter { + + private final Reg color1; + private final Reg color2; + private final Reg color3; + private final boolean rgb; + + public ColorConverter(Reg color1, Reg color2, Reg color3, boolean rgb) { + this.color1 = color1; + this.color2 = color2; + this.color3 = color3; + this.rgb = rgb; + } + + public List toValue(HSBType command) { + if (rgb) { + PercentType[] rgb = command.toRGB(); + return Arrays.asList( + RegValue.getForReg(color1, rgb[0].toBigDecimal().intValue()), + RegValue.getForReg(color2, rgb[1].toBigDecimal().intValue()), + RegValue.getForReg(color3, rgb[2].toBigDecimal().intValue()) + ); + } + return Arrays.asList( + RegValue.getForReg(color1, command.getHue().intValue()), + RegValue.getForReg(color2, command.getSaturation().intValue()), + RegValue.getForReg(color3, command.getBrightness().intValue()) + ); + } + + public State toState(RegValue value1, RegValue value2, RegValue value3) { + if (rgb) { + return HSBType.fromRGB( + Math.min(value1.intValueUnsigned(), 255), + Math.min(value2.intValueUnsigned(), 255), + Math.min(value3.intValueUnsigned(), 255) + ); + } + return new HSBType( + new DecimalType(Math.min(value1.intValueUnsigned(), 360)), + new PercentType(Math.min(value2.intValueUnsigned(), 100)), + new PercentType(Math.min(value3.intValueUnsigned(), 100)) + ); + } +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/Converter.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/Converter.java new file mode 100644 index 00000000..be7a334b --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/Converter.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.internal.channel.converter; + +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.simplify4u.jfatek.registers.RegValue; + +public interface Converter { + + RegValue toValue(Command command); + + State toState(RegValue value); + +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/Data16Converter.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/Data16Converter.java new file mode 100644 index 00000000..974e941c --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/Data16Converter.java @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.internal.channel.converter; + +import java.math.BigInteger; +import org.connectorio.addons.binding.fatek.config.channel.data.Data32ChannelConfig; +import org.connectorio.addons.binding.fatek.config.channel.data.DataChannelConfig; +import org.openhab.core.library.types.DecimalType; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.simplify4u.jfatek.registers.RegValue; +import org.simplify4u.jfatek.registers.RegValue32; + +public class Data16Converter implements Converter { + + private final DataChannelConfig config; + + public Data16Converter(DataChannelConfig config) { + this.config = config; + } + + @Override + public RegValue toValue(Command command) { + if (!(command instanceof DecimalType)) { + return null; + } + + DecimalType decimalType = (DecimalType) command; + long longValue = decimalType.toBigDecimal().longValue(); + return new RegValue32(config.unsigned ? BigInteger.valueOf(longValue).longValue() : longValue); + } + + @Override + public State toState(RegValue value) { + return new DecimalType(config.unsigned ? value.longValueUnsigned() : value.longValue()); + } +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/Data32Converter.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/Data32Converter.java new file mode 100644 index 00000000..2a6d12be --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/Data32Converter.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.internal.channel.converter; + +import java.math.BigInteger; +import org.connectorio.addons.binding.fatek.config.channel.binary.DiscreteChannelConfig; +import org.connectorio.addons.binding.fatek.config.channel.data.Data32ChannelConfig; +import org.openhab.core.library.types.DecimalType; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.OpenClosedType; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.simplify4u.jfatek.registers.RegValue; +import org.simplify4u.jfatek.registers.RegValue32; +import org.simplify4u.jfatek.registers.RegValueDis; + +public class Data32Converter implements Converter { + + private final Data32ChannelConfig config; + + public Data32Converter(Data32ChannelConfig config) { + this.config = config; + } + + @Override + public RegValue toValue(Command command) { + if (!(command instanceof DecimalType)) { + return null; + } + + DecimalType decimalType = (DecimalType) command; + if (config.floating) { + return new RegValue32(Float.floatToIntBits(decimalType.toBigDecimal().floatValue())); + } + + long longValue = decimalType.toBigDecimal().longValue(); + return new RegValue32(config.unsigned ? BigInteger.valueOf(longValue).longValue() : longValue); + } + + @Override + public State toState(RegValue value) { + if (config.floating) { + return new DecimalType(value.floatValue()); + } + + return new DecimalType(config.unsigned ? value.longValueUnsigned() : value.longValue()); + } +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/DiscreteConverter.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/DiscreteConverter.java new file mode 100644 index 00000000..832611e5 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/channel/converter/DiscreteConverter.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2024-2024 ConnectorIO Sp. z o.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.connectorio.addons.binding.fatek.internal.channel.converter; + +import org.connectorio.addons.binding.fatek.config.channel.binary.DiscreteChannelConfig; +import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.OpenClosedType; +import org.openhab.core.types.Command; +import org.openhab.core.types.State; +import org.simplify4u.jfatek.registers.RegValue; +import org.simplify4u.jfatek.registers.RegValueDis; + +public class DiscreteConverter implements Converter { + + private final DiscreteChannelConfig config; + + public DiscreteConverter(DiscreteChannelConfig config) { + this.config = config; + } + + @Override + public RegValue toValue(Command command) { + boolean value; + if (command instanceof OpenClosedType) { + value = OpenClosedType.CLOSED == command; + } else { + value = OnOffType.ON == command; + } + + if (value) { + return config.invert ? RegValueDis.FALSE : RegValueDis.TRUE; + } + return config.invert ? RegValueDis.TRUE : RegValueDis.FALSE; + } + + @Override + public State toState(RegValue value) { + boolean status = config.invert ? !value.boolValue() : value.boolValue(); + return status ? OnOffType.ON : OnOffType.OFF; + } +} diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/handler/FatekPlcThingHandler.java b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/handler/FatekPlcThingHandler.java index 5fdf3b93..bd05d8dd 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/handler/FatekPlcThingHandler.java +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/java/org/connectorio/addons/binding/fatek/internal/handler/FatekPlcThingHandler.java @@ -17,8 +17,12 @@ */ package org.connectorio.addons.binding.fatek.internal.handler; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; @@ -37,11 +41,9 @@ import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.types.Command; import org.openhab.core.types.State; +import org.openhab.core.types.Type; +import org.simplify4u.jfatek.FatekCommand; import org.simplify4u.jfatek.FatekReadMixDataCmd; -import org.simplify4u.jfatek.FatekWriteDataCmd; -import org.simplify4u.jfatek.FatekWriteDiscreteCmd; -import org.simplify4u.jfatek.registers.DataReg; -import org.simplify4u.jfatek.registers.DisReg; import org.simplify4u.jfatek.registers.Reg; import org.simplify4u.jfatek.registers.RegValue; import org.slf4j.Logger; @@ -91,7 +93,9 @@ public void initialize() { FatekChannelHandler handler = channelHandlerFactory.create(channel); if (handler != null) { handlerMap.put(channel.getUID(), handler); - registerMap.put(handler.register(), handler); + for (Reg register : handler.registers()) { + registerMap.put(register, handler); + } } } Long interval = getThingConfig().map(cfg -> cfg.refreshInterval) @@ -107,33 +111,30 @@ public void initialize() { public void handleCommand(ChannelUID channelUID, Command command) { if (handlerMap.containsKey(channelUID)) { FatekChannelHandler handler = handlerMap.get(channelUID); - Reg register = handler.register(); - if (register instanceof DataReg) { - FatekWriteDataCmd cmd = new FatekWriteDataCmd(null, (DataReg) register); - RegValue value = handler.prepareWrite(command); - if (value != null) { - cmd.addValue(value.longValue()); - connection.execute(stationNumber, cmd).whenComplete((r, e) -> { - if (e != null) { - logger.error("Could not write value {} to register {}", command, register, e); - return; - } - logger.debug("Successful write of value {} mapped from {} for channel {}", value, command, register); - }); - } - } else if (register instanceof DisReg) { - RegValue value = handler.prepareWrite(command); - if (value != null) { - FatekWriteDiscreteCmd cmd = new FatekWriteDiscreteCmd(null, (DisReg) register, value.boolValue()); - connection.execute(stationNumber, cmd).whenComplete((r, e) -> { - if (e != null) { - logger.error("Could not write value {} to register {}", command, register, e); - return; - } - logger.debug("Successful write of value {} mapped from {} for channel {}", value, command, register); - }); - } + FatekCommand cmd = handler.prepareWrite(command); + if (cmd == null) { + logger.warn("Could not map command {} from channel {} to value supported by PLC. Ignoring this write.", command, channelUID); + return; } + + write(channelUID, command, cmd); + } + } + + private void write(ChannelUID channel, Command command, FatekCommand cmd) { + connection.execute(stationNumber, cmd).whenComplete((r, e) -> { + if (e != null) { + logger.error("Could not signal channel {} with command {} by fatek command {}", channel, command, cmd, e); + return; + } + logger.debug("Successful write of channel {} with command {} annd fatek command {}", channel, command, cmd); + update(channel, command); + }); + } + + private void update(ChannelUID channelUID, Type value) { + if (value instanceof State) { + getCallback().stateUpdated(channelUID, (State) value); } } @@ -152,18 +153,32 @@ protected Long getDefaultPollingInterval() { @Override public void run() { - connection.execute(stationNumber, new FatekReadMixDataCmd(null, registerMap.keySet())).whenComplete((r, e) -> { - if (e != null) { - logger.warn("Failed to retrieve data", e); + connection.execute(stationNumber, new FatekReadMixDataCmd(null, registerMap.keySet())).whenComplete((result, error) -> { + if (error != null) { + logger.warn("Failed to retrieve data", error); return; } - for (Entry entry : r.entrySet()) { - FatekChannelHandler handler = registerMap.get(entry.getKey()); - State state = handler.state(entry.getValue()); + callChannelHandlers(result); + }); + } + + private void callChannelHandlers(Map result) { + Set called = new HashSet<>(); + for (Entry entry : result.entrySet()) { + FatekChannelHandler handler = registerMap.get(entry.getKey()); + if (!called.contains(handler)) { + // handler have not been called yet, lets collect its registers and let it parse data + List values = new ArrayList<>(); + for (Reg register : handler.registers()) { + values.add(result.get(register)); + } + // convert values to OH state + State state = handler.state(values); if (state != null) { - getCallback().stateUpdated(handler.channel(), state); + update(handler.channel(), state); } + called.add(handler); } - }); + } } } diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/binary-channel-config.xml b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/binary-channel-config.xml index 58880bc0..74e12a87 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/binary-channel-config.xml +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/binary-channel-config.xml @@ -23,14 +23,11 @@ - - Symbol (kind) of register to read + + Type of discrete register to read or write. - diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/color16-channel-config.xml b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/color16-channel-config.xml new file mode 100644 index 00000000..0b6c0be6 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/color16-channel-config.xml @@ -0,0 +1,142 @@ + + + + + + + + Additional settings used for switching target source. + + + + + + Data register used to retrieve or write Red or Hue part of color information. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + + + Data register used to retrieve or write Green or Saturation part of color information. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + + + Data register used to retrieve or write Blue or Brightness part of color information. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + + Write and interpret read data as RGB code instead of HSB. + false + + + + + + Type of discrete register to write ON or OFF command. + + + + + + + + + + + + Index of register used to write data. + 0 + + + + Invert logical representation of related register (0->1, 1->0). + false + + + + diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/color32-channel-config.xml b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/color32-channel-config.xml new file mode 100644 index 00000000..cccb4e3a --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/color32-channel-config.xml @@ -0,0 +1,142 @@ + + + + + + + + Additional settings used for switching target source. + + + + + + Data register used to retrieve or write Red or Hue part of color information. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + + + Data register used to retrieve or write Green or Saturation part of color information. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + + + Data register used to retrieve or write Blue or Brightness part of color information. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + + Write and interpret read data as RGB code instead of HSB. + false + + + + + + Type of discrete register to write ON or OFF command. + + + + + + + + + + + + Index of register used to write data. + 0 + + + + Invert logical representation of related register (0->1, 1->0). + false + + + + diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/data16-channel-config.xml b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/data16-channel-config.xml new file mode 100644 index 00000000..7f36fa59 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/data16-channel-config.xml @@ -0,0 +1,57 @@ + + + + + + + + Type of data register to read or write. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + Values retrieved from and written to device assume unsigned representation. + false + + + + diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/data32-channel-config.xml b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/data32-channel-config.xml new file mode 100644 index 00000000..a4ba1c0e --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/data32-channel-config.xml @@ -0,0 +1,62 @@ + + + + + + + + Type of data register to read or write. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + Values retrieved from and written to device assume unsigned representation. Does not apply if floating option is set. + false + + + + Indicate that read/write value is a floating point number. Overrides unsigned flag. + false + + + + diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/rollershutter16-channel-config.xml b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/rollershutter16-channel-config.xml new file mode 100644 index 00000000..fffde168 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/rollershutter16-channel-config.xml @@ -0,0 +1,120 @@ + + + + + + + + Settings for discrete register used for sending start command. + + + + Settings for discrete register used for sending stop command. + + + + + Data register used to retrieve position of roller shutter. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + Values retrieved from and written to device assume unsigned representation. Does not apply if floating option is set. + false + + + + Indicate that read/write value is a floating point number. Overrides unsigned flag. + false + + + + + + Type of discrete register to write UP command. + + + + + + + + + + + + Index of register used to write data. + 0 + + + + Invert logical representation of related register (0->1, 1->0). + false + + + + + + Type of discrete register to write DOWN command. + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + Invert logical representation of related register (0->1, 1->0). + false + + + + + diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/rollershutter32-channel-config.xml b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/rollershutter32-channel-config.xml new file mode 100644 index 00000000..098750c3 --- /dev/null +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/config/rollershutter32-channel-config.xml @@ -0,0 +1,120 @@ + + + + + + + + Settings for discrete register used for sending start command. + + + + Settings for discrete register used for sending stop command. + + + + + Data register used to retrieve position of roller shutter. + + + + + + + + + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + Values retrieved from and written to device assume unsigned representation. Does not apply if floating option is set. + false + + + + Indicate that read/write value is a floating point number. Overrides unsigned flag. + false + + + + + + Type of discrete register to write UP command. + + + + + + + + + + + + Index of register used to write data. + 0 + + + + Invert logical representation of related register (0->1, 1->0). + false + + + + + + Type of discrete register to write DOWN command. + + + + + + + + + + + + Index of register used to retrieve data. + 0 + + + + Invert logical representation of related register (0->1, 1->0). + false + + + + + diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/thing/channels.xml b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/thing/channels.xml index 0bb7999e..f580517f 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/thing/channels.xml +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/thing/channels.xml @@ -21,7 +21,6 @@ xmlns:thing="https://openhab.org/schemas/thing-description/v1.0.0" xsi:schemaLocation="https://openhab.org/schemas/thing-description/v1.0.0 https://openhab.org/schemas/thing-description-1.0.0.xsd"> - Switch @@ -29,4 +28,43 @@ + + Number + + Data register of connected PLC encoded using 16 bit registers. + + + + Number + + Data register of connected PLC encoded using 32 bit registers. + + + + + Rollershutter + + Data register for position will use 16 bit registers. + + + + Rollershutter + + Data register for position will use 32 bit registers. + + + + + Color + + Data register for position will use 16 bit registers. + + + + Color + + Data register for position will use 32 bit registers. + + + \ No newline at end of file diff --git a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/thing/thing.xml b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/thing/thing.xml index 2cff4232..4016efd5 100644 --- a/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/thing/thing.xml +++ b/bundles/org.connectorio.addons.binding.fatek/src/main/resources/OH-INF/thing/thing.xml @@ -23,7 +23,7 @@ https://openhab.org/schemas/thing-description-1.0.0.xsd "> - +