You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@plc4x.apache.org by GitBox <gi...@apache.org> on 2020/09/23 11:39:59 UTC
[GitHub] [plc4x] hutcheb opened a new pull request #191: Implement WriteBuffer float, double and BigInteger functions
hutcheb opened a new pull request #191:
URL: https://github.com/apache/plc4x/pull/191
Initial commit, hasn't been tested at all.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [plc4x] hutcheb commented on pull request #191: Implement WriteBuffer float, double and BigInteger functions
Posted by GitBox <gi...@apache.org>.
hutcheb commented on pull request #191:
URL: https://github.com/apache/plc4x/pull/191#issuecomment-699621155
Little Endian BigInteger functions havn't been tested.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [plc4x] chrisdutz commented on a change in pull request #191: Implement WriteBuffer float, double and BigInteger functions
Posted by GitBox <gi...@apache.org>.
chrisdutz commented on a change in pull request #191:
URL: https://github.com/apache/plc4x/pull/191#discussion_r494808810
##########
File path: plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/utils/KnxHelper.java
##########
@@ -46,9 +46,16 @@ public static void f16toBytes(WriteBuffer io, Object param) {
boolean negative = value < 0;
final int exponent = Math.getExponent(value);
final double mantissa = value / Math.pow(2, exponent);
+ //io.writeBit(negative);
+ //io.writeInt(4, exponent);
+ //io.writeDouble(11, Math.getExponent(mantissa), mantissa); //Don't think this works BH
+
+ String mantissaString = Double.toString(mantissa);
+ int mantissaInteger = Integer.parseInt(mantissaString.substring(mantissaString.indexOf('.')));
Review comment:
What's the String conversion for? I think in this case a simple double-to-int-cast should do the trick ....
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [plc4x] hutcheb commented on a change in pull request #191: Implement WriteBuffer float, double and BigInteger functions
Posted by GitBox <gi...@apache.org>.
hutcheb commented on a change in pull request #191:
URL: https://github.com/apache/plc4x/pull/191#discussion_r494920825
##########
File path: plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/utils/KnxHelper.java
##########
@@ -46,9 +46,16 @@ public static void f16toBytes(WriteBuffer io, Object param) {
boolean negative = value < 0;
final int exponent = Math.getExponent(value);
final double mantissa = value / Math.pow(2, exponent);
+ //io.writeBit(negative);
+ //io.writeInt(4, exponent);
+ //io.writeDouble(11, Math.getExponent(mantissa), mantissa); //Don't think this works BH
+
+ String mantissaString = Double.toString(mantissa);
+ int mantissaInteger = Integer.parseInt(mantissaString.substring(mantissaString.indexOf('.')));
Review comment:
The string conversion is to get the digits after the decimal place of the mantissa as part of writing a 16-bit float.
(In my head the mantissa is always going to have a one before the decimal place which can be discarded)
The digits after are then converted to an integer to be written as the manitssa part.
I haven't tested this part of it, it has a slight chance of working for most cases but not all. I'll create a 16-bit floating point PlcValue at some point and test it with Modbus and then move it over to the KNX protocol as a custom PlcValue.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [plc4x] chrisdutz commented on a change in pull request #191: Implement WriteBuffer float, double and BigInteger functions
Posted by GitBox <gi...@apache.org>.
chrisdutz commented on a change in pull request #191:
URL: https://github.com/apache/plc4x/pull/191#discussion_r494808810
##########
File path: plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/utils/KnxHelper.java
##########
@@ -46,9 +46,16 @@ public static void f16toBytes(WriteBuffer io, Object param) {
boolean negative = value < 0;
final int exponent = Math.getExponent(value);
final double mantissa = value / Math.pow(2, exponent);
+ //io.writeBit(negative);
+ //io.writeInt(4, exponent);
+ //io.writeDouble(11, Math.getExponent(mantissa), mantissa); //Don't think this works BH
+
+ String mantissaString = Double.toString(mantissa);
+ int mantissaInteger = Integer.parseInt(mantissaString.substring(mantissaString.indexOf('.')));
Review comment:
What's the String conversion for? I think in this case a simple double-to-int-cast should do the trick ....
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [plc4x] hutcheb commented on a change in pull request #191: Implement WriteBuffer float, double and BigInteger functions
Posted by GitBox <gi...@apache.org>.
hutcheb commented on a change in pull request #191:
URL: https://github.com/apache/plc4x/pull/191#discussion_r494920825
##########
File path: plc4j/drivers/knxnetip/src/main/java/org/apache/plc4x/java/knxnetip/utils/KnxHelper.java
##########
@@ -46,9 +46,16 @@ public static void f16toBytes(WriteBuffer io, Object param) {
boolean negative = value < 0;
final int exponent = Math.getExponent(value);
final double mantissa = value / Math.pow(2, exponent);
+ //io.writeBit(negative);
+ //io.writeInt(4, exponent);
+ //io.writeDouble(11, Math.getExponent(mantissa), mantissa); //Don't think this works BH
+
+ String mantissaString = Double.toString(mantissa);
+ int mantissaInteger = Integer.parseInt(mantissaString.substring(mantissaString.indexOf('.')));
Review comment:
The string conversion is to get the digits after the decimal place of the mantissa as part of writing a 16-bit float.
(In my head the mantissa is always going to have a one before the decimal place which can be discarded)
The digits after are then converted to an integer to be written as the manitssa part.
I haven't tested this part of it, it has a slight chance of working for most cases but not all. I'll create a 16-bit floating point PlcValue at some point and test it with Modbus and then move it over to the KNX protocol as a custom PlcValue.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [plc4x] hutcheb closed pull request #191: Implement WriteBuffer float, double and BigInteger functions
Posted by GitBox <gi...@apache.org>.
hutcheb closed pull request #191:
URL: https://github.com/apache/plc4x/pull/191
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org