Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and refactor Channel Meta-Info (#1597)
The Channel Source and Target information introduced in #1595 was not working, because Read-Write-Channel information would always be considered a 'target' information. This Pull-Request refactors the information to a generic MetaInfo and allows explicit definition of different read- and write-registers for one Channel
- Loading branch information
1 parent
2e6d628
commit df89482
Showing
25 changed files
with
493 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
io.openems.edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/ChannelMetaInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.openems.edge.bridge.modbus.api; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Describes a Channel that has a read- or read-and-write-mapping to one Modbus | ||
* Register. | ||
*/ | ||
public class ChannelMetaInfo { | ||
|
||
/** | ||
* Holds the Address for Modbus Read Register. | ||
*/ | ||
protected final int address; | ||
|
||
public ChannelMetaInfo(int address) { | ||
this.address = address; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder b = new StringBuilder(); | ||
b.append("0x").append(Integer.toHexString(this.address)); | ||
return b.toString(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.address); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
ChannelMetaInfo other = (ChannelMetaInfo) obj; | ||
return this.address == other.address; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...edge.bridge.modbus/src/io/openems/edge/bridge/modbus/api/ChannelMetaInfoReadAndWrite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package io.openems.edge.bridge.modbus.api; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* Describes a Channel that has a read-and-write-mapping to two Modbus | ||
* Registers. | ||
*/ | ||
public class ChannelMetaInfoReadAndWrite extends ChannelMetaInfo { | ||
|
||
/** | ||
* Holds the Address for Modbus Write Register. | ||
*/ | ||
private final int writeAddress; | ||
|
||
public ChannelMetaInfoReadAndWrite(int readAddress, int writeAaddress) { | ||
super(readAddress); | ||
this.writeAddress = writeAaddress; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder b = new StringBuilder(); | ||
b.append("READ:0x").append(Integer.toHexString(this.address)); | ||
b.append(" | WRITE:0x").append(Integer.toHexString(this.writeAddress)); | ||
return b.toString(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(this.address, this.writeAddress); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
ChannelMetaInfoReadAndWrite other = (ChannelMetaInfoReadAndWrite) obj; | ||
return this.address == other.address && this.writeAddress == other.writeAddress; | ||
} | ||
|
||
} |
Oops, something went wrong.