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/25 11:19:43 UTC

[GitHub] [plc4x] hutcheb commented on a change in pull request #191: Implement WriteBuffer float, double and BigInteger functions

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