Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Floating Point

Floating Point

Scheduled Pinned Locked Moved Development
floating point
41 Posts 4 Posters 21.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • YveauxY Offline
    YveauxY Offline
    Yveaux
    Mod
    wrote on last edited by
    #10

    I would also like you to think about a fixed point format (http://en.wikipedia.org/wiki/Fixed-point_arithmetic).
    A lot of sensor values can be represented in e.g. 8.8 or even 16.16. Think of e.g. temperatures (range -127..+127 is usually sufficient and I've yet to see an affordable sensor reporting in more than 256 steps per degree ), humidity (0..100%, 256 steps/degree), battery level (0..100%) etc.
    Fixed point arithmetic requires very little resources compared to floating point and has no trouble converting between different architectures (apart from endianness).
    For full efficiency sensor libraries should also support this format, as it doesn't make much sense to have a sensor library report in floating point and convert this to fixed point by MySensors.
    A good Arduino-style fixed point library would help IMHO. Did a quick google on the subject, but didn't find much (apart from https://code.google.com/p/libfixmath/)

    I think support for real floating point values should still be possible, but this could be an interesting addition.

    What do you think?

    http://yveaux.blogspot.nl

    Z hekH 2 Replies Last reply
    0
    • Z Zeph

      The Raspberry Pi definitely does use IEEE 754 floating point.

      I'm not certain about the byte order, but that should be easy to test.

      union test_t {
         float f;
         uint8_t b[4];
      } myUnion;
      
      myUnion.f = 3.14159265;
      for(int i = 0; i < 4; i++) {
          Serial.print(myUnion.b[i], HEX);
          Serial.print(" ");
      }
      Serial.println();
      

      Swap out a printf on the Rpi

      (Note: I am not assuming that an architecture which is little endian for integers must be little endian for floats - tho it usually is)

      JohnJ Offline
      JohnJ Offline
      John
      Plugin Developer
      wrote on last edited by
      #11

      @Zeph
      -mlittle-endian
      Generate code for a processor running in little-endian mode. This is the default for all standard configurations.
      -mbig-endian
      Generate code for a processor running in big-endian mode; the default is to compile code for a little-endian processor.

      At: https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html

      In my Java app (but then again on the PI is also default little-endian) The below is default used with Arduino based connected devices and on purpose hinted little-endian, just in case.

      public static float byteArrayToFloat(byte[] bytes) {   // Byte to float conversion
          return ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getFloat();   
      }
      

      My Domotica project: http://www.pidome.org

      1 Reply Last reply
      0
      • YveauxY Yveaux

        I would also like you to think about a fixed point format (http://en.wikipedia.org/wiki/Fixed-point_arithmetic).
        A lot of sensor values can be represented in e.g. 8.8 or even 16.16. Think of e.g. temperatures (range -127..+127 is usually sufficient and I've yet to see an affordable sensor reporting in more than 256 steps per degree ), humidity (0..100%, 256 steps/degree), battery level (0..100%) etc.
        Fixed point arithmetic requires very little resources compared to floating point and has no trouble converting between different architectures (apart from endianness).
        For full efficiency sensor libraries should also support this format, as it doesn't make much sense to have a sensor library report in floating point and convert this to fixed point by MySensors.
        A good Arduino-style fixed point library would help IMHO. Did a quick google on the subject, but didn't find much (apart from https://code.google.com/p/libfixmath/)

        I think support for real floating point values should still be possible, but this could be an interesting addition.

        What do you think?

        Z Offline
        Z Offline
        Zeph
        Hero Member
        wrote on last edited by Zeph
        #12

        @hek
        @Yveaux said:

        I would also like you to think about a fixed point format

        See my suggestion above about defining an optional scaling factor for each variable, as we can define a precision for each floating variable now.

        Simple decade scaling: integer factors of ten, using the same configured integer that would define precision for floats.

        or

        Flexible scaling: configure a floating point factor by which the integer OTA value would be multiplied to give real world units.

        So a temperature of 29.7 could be sent as a 16 bit integer 297 with the gateway knowing (from configuratiion) that it must be multiplied by 0.1 before being converted to a string. Either approach could handle that.

        The flexible version could also handles things like angles that are reported in degrees, or 0..1023 or radians or whatever, with the full accuracy of the sensor.


        I think you are suggesting that we adopt one or more standard fixed point formats as additional OTA variable formats (as well as supporting the math function in the node library). I can certainly see value in that, as well. Like floating point, you would need to configure a precision when converting to decimal values (since 0.1 is not an accurate binary fraction in fixed point either). So 29.7 degrees would be encoded as 29*256 + ((256 * 7) / 10). = 7603, and converted to a float that would be 29.69921875. If like a float this fixed point value was configured with one digit of decimal accuracy, we'd get the 29.7 value again.


        Either of these might sometimes let a node avoid the floating point libraries entirely in many cases, even when it wants to report non-integer values.

        Could be handy if we ever get ATtiny nodes.

        1 Reply Last reply
        0
        • YveauxY Yveaux

          I would also like you to think about a fixed point format (http://en.wikipedia.org/wiki/Fixed-point_arithmetic).
          A lot of sensor values can be represented in e.g. 8.8 or even 16.16. Think of e.g. temperatures (range -127..+127 is usually sufficient and I've yet to see an affordable sensor reporting in more than 256 steps per degree ), humidity (0..100%, 256 steps/degree), battery level (0..100%) etc.
          Fixed point arithmetic requires very little resources compared to floating point and has no trouble converting between different architectures (apart from endianness).
          For full efficiency sensor libraries should also support this format, as it doesn't make much sense to have a sensor library report in floating point and convert this to fixed point by MySensors.
          A good Arduino-style fixed point library would help IMHO. Did a quick google on the subject, but didn't find much (apart from https://code.google.com/p/libfixmath/)

          I think support for real floating point values should still be possible, but this could be an interesting addition.

          What do you think?

          hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #13

          @Yveaux said:

          http://en.wikipedia.org/wiki/Fixed-point_arithmetic

          Yep, would also be a good addition. Floating points is really crazy inefficient to use on an Arduino.
          I will look at sending floats binary now... my secret knock sensor will have to wait :(.
          Does anyone want to help on the fixed point stuff?

          YveauxY 1 Reply Last reply
          0
          • hekH hek

            @Yveaux said:

            http://en.wikipedia.org/wiki/Fixed-point_arithmetic

            Yep, would also be a good addition. Floating points is really crazy inefficient to use on an Arduino.
            I will look at sending floats binary now... my secret knock sensor will have to wait :(.
            Does anyone want to help on the fixed point stuff?

            YveauxY Offline
            YveauxY Offline
            Yveaux
            Mod
            wrote on last edited by
            #14

            @hek said:

            Does anyone want to help on the fixed point stuff?

            I can try to put some skeleton together to get the interface right, as this is probably the hardest part.

            http://yveaux.blogspot.nl

            hekH 1 Reply Last reply
            0
            • YveauxY Yveaux

              @hek said:

              Does anyone want to help on the fixed point stuff?

              I can try to put some skeleton together to get the interface right, as this is probably the hardest part.

              hekH Offline
              hekH Offline
              hek
              Admin
              wrote on last edited by
              #15

              @Yveaux said:

              I can try to put some skeleton together to get the interface right, as this is probably the hardest part.

              Super.

              1 Reply Last reply
              0
              • Z Offline
                Z Offline
                Zeph
                Hero Member
                wrote on last edited by Zeph
                #16

                @hek @Yveaux
                Let me see if I am understanding.

                The payload types would be enhanced.

                typedef enum {
                    P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM
                } payload;
                

                to add an 8:8 and/or 16:16 fixed point formats, eg: P_FIX8P8 or P_FIX16P16. I'm guessing only signed fixed point, no unsigned?

                And to add a 4 byte binary floating point P_FLOAT32?

                One small suggestion: put P_CUSTOM first, so its numeric code doesn't change when you add additional formats. Or if it's too late for that, we can skip over P_CUSTOM for these new formats.

                And also the payload setters:

                MyMessage& set(const char* value);
                MyMessage& set(uint8_t value);
                MyMessage& set(double value, uint8_t decimals);
                MyMessage& set(unsigned long value);
                MyMessage& set(long value);
                MyMessage& set(unsigned int value);
                MyMessage& set(int value);
                

                would be enhanced to support these types.

                MyMessage& set(double value, uint8_t decimals);
                

                could be unchanged as seen by the user even if the underlying OTA representation became binary. But we might add something like:

                MyMessage& set(fix8p8 value, uint8_t: decimals);
                MyMessage& set(fix16p16 value, uint8_t: decimals);
                

                (the decimals parameter is needed for this like for floats, as described earlier)

                This implies creating new C++ types, in this example "fix8p8", which is basically a int16_t with an implicit radix point in the middle.

                Adding is simple. Multiply of fix8p8 is easy because you can use a long as temp before renormalizing, but multiply of fix16p16 gets trickier, of course.


                Another discussion to have before it's set in stone...

                Adding fixed point support both OTA and within library code has value, so I'm not against it. Getting the library right and educating users is going to be some work, tho. I use fixed point math fairly often, but it definitely has some gotchas that we are biting off.

                The concept of having a scaling factor (see a few messages back) may be an easier step to implement and educate. It's an easy concept: every integer step represents X units, so the integer value must be multiplied by the scaling factor to get the real value in units. Default = 1.0 with both the same, as now.

                The simplest version just scales by factors of 10, and could be implemented by adding a second integer to the set() function. In this version to send -12.5 you use set(-125,1), or to send 0.14 you use set(14,2). This can be interpreted into a string without even using floating point math, you just adjust where to insert a decimal point in a printed integer.

                (The slightly more complex version would use an arbitrary floating point factor as the scale, so you could use 0.1 or 3.56 or whatever).

                (Aside: from the viewpoint of the gateway, the fixed point enhancement is equivalent to having a fixed scaling factor of 2*-8 or 2^-16)

                These enhancements are not mutually exclusive, but I would think that one of the scaled integer version might be easier to implement and understand as a first step.

                hekH 1 Reply Last reply
                0
                • YveauxY Offline
                  YveauxY Offline
                  Yveaux
                  Mod
                  wrote on last edited by
                  #17

                  @Zeph said:

                  (the decimals parameter is needed for this like for floats, as described earlier)

                  I don't see why the decimals parameter is needed. Currently it is used for the amount of decimals converted to textual presentation. This is not required for fixed point presentation (unless you want a scaling factor).
                  IMHO scaling just complicates things too much -- you also need to exchange the scaling factor with the gateway.

                  This implies creating new C++ types, in this example "fix8p8", which is basically a int16_t with an implicit radix point in the middle.

                  Adding is simple. Multiply of fix8p8 is easy because you can use a long as temp before renormalizing, but multiply of fix16p16 gets trickier, of course.

                  My idea is to just wrap the new types in a class library, which allows for easy conversion and maths with these new fixedpt types.

                  Getting the library right and educating users is going to be some work, tho. I use fixed point math fairly often, but it definitely has some gotchas that we are biting off.

                  The library should shield regular users from the internals and pitfalls of fixed point. Most sketches just get a value from a sensor library and pass it on to MySensors, without modifying the value.
                  As part of this exercise we also have to modify these libraries which return their values in float-format, as it doesn't make sense to keeps floats in partly...

                  http://yveaux.blogspot.nl

                  Z 1 Reply Last reply
                  0
                  • Z Zeph

                    @hek @Yveaux
                    Let me see if I am understanding.

                    The payload types would be enhanced.

                    typedef enum {
                        P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM
                    } payload;
                    

                    to add an 8:8 and/or 16:16 fixed point formats, eg: P_FIX8P8 or P_FIX16P16. I'm guessing only signed fixed point, no unsigned?

                    And to add a 4 byte binary floating point P_FLOAT32?

                    One small suggestion: put P_CUSTOM first, so its numeric code doesn't change when you add additional formats. Or if it's too late for that, we can skip over P_CUSTOM for these new formats.

                    And also the payload setters:

                    MyMessage& set(const char* value);
                    MyMessage& set(uint8_t value);
                    MyMessage& set(double value, uint8_t decimals);
                    MyMessage& set(unsigned long value);
                    MyMessage& set(long value);
                    MyMessage& set(unsigned int value);
                    MyMessage& set(int value);
                    

                    would be enhanced to support these types.

                    MyMessage& set(double value, uint8_t decimals);
                    

                    could be unchanged as seen by the user even if the underlying OTA representation became binary. But we might add something like:

                    MyMessage& set(fix8p8 value, uint8_t: decimals);
                    MyMessage& set(fix16p16 value, uint8_t: decimals);
                    

                    (the decimals parameter is needed for this like for floats, as described earlier)

                    This implies creating new C++ types, in this example "fix8p8", which is basically a int16_t with an implicit radix point in the middle.

                    Adding is simple. Multiply of fix8p8 is easy because you can use a long as temp before renormalizing, but multiply of fix16p16 gets trickier, of course.


                    Another discussion to have before it's set in stone...

                    Adding fixed point support both OTA and within library code has value, so I'm not against it. Getting the library right and educating users is going to be some work, tho. I use fixed point math fairly often, but it definitely has some gotchas that we are biting off.

                    The concept of having a scaling factor (see a few messages back) may be an easier step to implement and educate. It's an easy concept: every integer step represents X units, so the integer value must be multiplied by the scaling factor to get the real value in units. Default = 1.0 with both the same, as now.

                    The simplest version just scales by factors of 10, and could be implemented by adding a second integer to the set() function. In this version to send -12.5 you use set(-125,1), or to send 0.14 you use set(14,2). This can be interpreted into a string without even using floating point math, you just adjust where to insert a decimal point in a printed integer.

                    (The slightly more complex version would use an arbitrary floating point factor as the scale, so you could use 0.1 or 3.56 or whatever).

                    (Aside: from the viewpoint of the gateway, the fixed point enhancement is equivalent to having a fixed scaling factor of 2*-8 or 2^-16)

                    These enhancements are not mutually exclusive, but I would think that one of the scaled integer version might be easier to implement and understand as a first step.

                    hekH Offline
                    hekH Offline
                    hek
                    Admin
                    wrote on last edited by
                    #18

                    @Zeph said:

                    The payload types would be enhanced.

                    typedef enum {
                        P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM
                    } payload;
                    

                    Darn, just realized we only got 3 bits to describe payload type. We need another one to fit the new ones.

                    MyMessage& set(double value, uint8_t decimals);
                    

                    Shouldn't this be set(float, uint8_t). Wouldn't it be confusing to have double-argument when only sending 32-bit float?

                    YveauxY JohnJ Z 3 Replies Last reply
                    0
                    • hekH hek

                      @Zeph said:

                      The payload types would be enhanced.

                      typedef enum {
                          P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM
                      } payload;
                      

                      Darn, just realized we only got 3 bits to describe payload type. We need another one to fit the new ones.

                      MyMessage& set(double value, uint8_t decimals);
                      

                      Shouldn't this be set(float, uint8_t). Wouldn't it be confusing to have double-argument when only sending 32-bit float?

                      YveauxY Offline
                      YveauxY Offline
                      Yveaux
                      Mod
                      wrote on last edited by Yveaux
                      #19

                      @hek

                      P_INT16, P_UINT16, P_LONG32, P_ULONG32

                      Do you really need the unsigned versions UINT16 and UINT32 ?
                      I would say stick to the signed ones -- this frees 2 values for float and fixed point.

                      http://yveaux.blogspot.nl

                      1 Reply Last reply
                      0
                      • hekH hek

                        @Zeph said:

                        The payload types would be enhanced.

                        typedef enum {
                            P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM
                        } payload;
                        

                        Darn, just realized we only got 3 bits to describe payload type. We need another one to fit the new ones.

                        MyMessage& set(double value, uint8_t decimals);
                        

                        Shouldn't this be set(float, uint8_t). Wouldn't it be confusing to have double-argument when only sending 32-bit float?

                        JohnJ Offline
                        JohnJ Offline
                        John
                        Plugin Developer
                        wrote on last edited by
                        #20

                        @hek

                        Shouldn't this be set(float, uint8_t). Wouldn't it be confusing to have double-argument when only sending 32-bit float?

                        Also the Atmega based boards do not support double, well they do in naming but are float precisions

                        My Domotica project: http://www.pidome.org

                        YveauxY 1 Reply Last reply
                        0
                        • JohnJ John

                          @hek

                          Shouldn't this be set(float, uint8_t). Wouldn't it be confusing to have double-argument when only sending 32-bit float?

                          Also the Atmega based boards do not support double, well they do in naming but are float precisions

                          YveauxY Offline
                          YveauxY Offline
                          Yveaux
                          Mod
                          wrote on last edited by
                          #21

                          @John then let's call them float, for clarity

                          http://yveaux.blogspot.nl

                          JohnJ 1 Reply Last reply
                          0
                          • YveauxY Yveaux

                            @John then let's call them float, for clarity

                            JohnJ Offline
                            JohnJ Offline
                            John
                            Plugin Developer
                            wrote on last edited by
                            #22

                            @Yveaux said:

                            then let's call them float, for clarity

                            Agree

                            My Domotica project: http://www.pidome.org

                            1 Reply Last reply
                            0
                            • hekH Offline
                              hekH Offline
                              hek
                              Admin
                              wrote on last edited by hek
                              #23

                              Just pushed the float changes.

                              To free up some bits in header for the new fixed point types (and simplify things) I'm considering reducing the commandTypes to just 3 values (SET, REQ, INTERNAL) the rest (PRESENTATION, STREAM) will be moved to be INTERNAL messages.
                              I could make serial interface unaffected by this change. But I'd rather remove it there as well.

                              @Yveaux . Regarding remove the unsigned variant (e.g. ULONG). It is actually good to keep this. As there actually are some sensors reporting large numbers like meter-ticks which can be huge.

                              YveauxY JohnJ 2 Replies Last reply
                              0
                              • hekH hek

                                Just pushed the float changes.

                                To free up some bits in header for the new fixed point types (and simplify things) I'm considering reducing the commandTypes to just 3 values (SET, REQ, INTERNAL) the rest (PRESENTATION, STREAM) will be moved to be INTERNAL messages.
                                I could make serial interface unaffected by this change. But I'd rather remove it there as well.

                                @Yveaux . Regarding remove the unsigned variant (e.g. ULONG). It is actually good to keep this. As there actually are some sensors reporting large numbers like meter-ticks which can be huge.

                                YveauxY Offline
                                YveauxY Offline
                                Yveaux
                                Mod
                                wrote on last edited by
                                #24

                                @hek Maybe not for 1.4, but you should consider removing a lot of the data from the header and leave only the routing info & message type in.
                                Depending on message type you then get a 'nested' header which tells you about the message-type specifics.
                                This also will help in the struggle to store data format types, for which you've now reserved 3 bits. They are always sent, also when there's no SET/GET data present in the message. Then you simply reserve e.g. a byte which will go a long way...

                                http://yveaux.blogspot.nl

                                hekH 1 Reply Last reply
                                0
                                • YveauxY Yveaux

                                  @hek Maybe not for 1.4, but you should consider removing a lot of the data from the header and leave only the routing info & message type in.
                                  Depending on message type you then get a 'nested' header which tells you about the message-type specifics.
                                  This also will help in the struggle to store data format types, for which you've now reserved 3 bits. They are always sent, also when there's no SET/GET data present in the message. Then you simply reserve e.g. a byte which will go a long way...

                                  hekH Offline
                                  hekH Offline
                                  hek
                                  Admin
                                  wrote on last edited by
                                  #25

                                  @Yveaux said:

                                  This also will help in the struggle to store data format types, for which you've now reserved 3 bits. They are always sent, also when there's no SET/GET data present in the message. Then you simply reserve e.g. a byte which will go a long way...

                                  Darn... you are so right..

                                  YveauxY 1 Reply Last reply
                                  0
                                  • hekH hek

                                    @Yveaux said:

                                    This also will help in the struggle to store data format types, for which you've now reserved 3 bits. They are always sent, also when there's no SET/GET data present in the message. Then you simply reserve e.g. a byte which will go a long way...

                                    Darn... you are so right..

                                    YveauxY Offline
                                    YveauxY Offline
                                    Yveaux
                                    Mod
                                    wrote on last edited by
                                    #26

                                    @hek Hey, its my job ;-)

                                    http://yveaux.blogspot.nl

                                    1 Reply Last reply
                                    0
                                    • YveauxY Yveaux

                                      @Zeph said:

                                      (the decimals parameter is needed for this like for floats, as described earlier)

                                      I don't see why the decimals parameter is needed. Currently it is used for the amount of decimals converted to textual presentation. This is not required for fixed point presentation (unless you want a scaling factor).
                                      IMHO scaling just complicates things too much -- you also need to exchange the scaling factor with the gateway.

                                      This implies creating new C++ types, in this example "fix8p8", which is basically a int16_t with an implicit radix point in the middle.

                                      Adding is simple. Multiply of fix8p8 is easy because you can use a long as temp before renormalizing, but multiply of fix16p16 gets trickier, of course.

                                      My idea is to just wrap the new types in a class library, which allows for easy conversion and maths with these new fixedpt types.

                                      Getting the library right and educating users is going to be some work, tho. I use fixed point math fairly often, but it definitely has some gotchas that we are biting off.

                                      The library should shield regular users from the internals and pitfalls of fixed point. Most sketches just get a value from a sensor library and pass it on to MySensors, without modifying the value.
                                      As part of this exercise we also have to modify these libraries which return their values in float-format, as it doesn't make sense to keeps floats in partly...

                                      Z Offline
                                      Z Offline
                                      Zeph
                                      Hero Member
                                      wrote on last edited by
                                      #27

                                      @Yveaux said:

                                      @Zeph said:

                                      (the decimals parameter is needed for this like for floats, as described earlier)

                                      I don't see why the decimals parameter is needed. Currently it is used for the amount of decimals converted to textual presentation.

                                      I was think of when packets are converted to the comma separated textual representation for the API.

                                      Convert 25.7 degrees to fixed point at the node, then at the gateway convert the fixed point it to a text string, and you'll see what I mean. It's not for the scaling option.

                                      IMHO scaling just complicates things too much -- you also need to exchange the scaling factor with the gateway.

                                      There are tradeoffs either way. In the current architecture, to support scaling you'd need to at least tell the gateway the scaling factor as part of the one-time presentation configuration. (Alternately, the gateway could retrieve the scaling factor along with type and name from local configuration, rather than receiving all of those OTA, but that's another discussion)

                                      Beyond that there's no need for new libraries, and it's easy to explain.

                                      However, I understand that you are excited by the fixed point functionality (which could be useful for more than just OTA encoding). I don't want to discourage that exploration. I look forward to some examples of encoding at the node end, and decoding at the gateway end, for some sensors like the DHT-22 or 18B20.

                                      This implies creating new C++ types, in this example "fix8p8", which is basically a int16_t with an implicit radix point in the middle.

                                      Adding is simple. Multiply of fix8p8 is easy because you can use a long as temp before renormalizing, but multiply of fix16p16 gets trickier, of course.

                                      My idea is to just wrap the new types in a class library, which allows for easy conversion and maths with these new fixedpt types.

                                      Yes, that was what I was guessing. Go for it!

                                      As part of this exercise we also have to modify these libraries which return their values in float-format, as it doesn't make sense to keeps floats in partly...

                                      Agreed. It would be nice if we rarely needed to even link the floating point library in nodes. (And it would make an ATtiny based node more feasible someday).

                                      YveauxY 1 Reply Last reply
                                      0
                                      • hekH hek

                                        @Zeph said:

                                        The payload types would be enhanced.

                                        typedef enum {
                                            P_STRING, P_BYTE, P_INT16, P_UINT16, P_LONG32, P_ULONG32, P_CUSTOM
                                        } payload;
                                        

                                        Darn, just realized we only got 3 bits to describe payload type. We need another one to fit the new ones.

                                        MyMessage& set(double value, uint8_t decimals);
                                        

                                        Shouldn't this be set(float, uint8_t). Wouldn't it be confusing to have double-argument when only sending 32-bit float?

                                        Z Offline
                                        Z Offline
                                        Zeph
                                        Hero Member
                                        wrote on last edited by
                                        #28

                                        @hek said:

                                         MyMessage& set(double value, uint8_t decimals);
                                        

                                        Shouldn't this be set(float, uint8_t). Wouldn't it be confusing to have double-argument when only sending 32-bit float?

                                        I was quoting an excerpt of the current system. I would tend to agree with changing that to float, just for clarity of intent, even though they are the same in GCC for the AVR

                                        1 Reply Last reply
                                        0
                                        • Z Zeph

                                          @Yveaux said:

                                          @Zeph said:

                                          (the decimals parameter is needed for this like for floats, as described earlier)

                                          I don't see why the decimals parameter is needed. Currently it is used for the amount of decimals converted to textual presentation.

                                          I was think of when packets are converted to the comma separated textual representation for the API.

                                          Convert 25.7 degrees to fixed point at the node, then at the gateway convert the fixed point it to a text string, and you'll see what I mean. It's not for the scaling option.

                                          IMHO scaling just complicates things too much -- you also need to exchange the scaling factor with the gateway.

                                          There are tradeoffs either way. In the current architecture, to support scaling you'd need to at least tell the gateway the scaling factor as part of the one-time presentation configuration. (Alternately, the gateway could retrieve the scaling factor along with type and name from local configuration, rather than receiving all of those OTA, but that's another discussion)

                                          Beyond that there's no need for new libraries, and it's easy to explain.

                                          However, I understand that you are excited by the fixed point functionality (which could be useful for more than just OTA encoding). I don't want to discourage that exploration. I look forward to some examples of encoding at the node end, and decoding at the gateway end, for some sensors like the DHT-22 or 18B20.

                                          This implies creating new C++ types, in this example "fix8p8", which is basically a int16_t with an implicit radix point in the middle.

                                          Adding is simple. Multiply of fix8p8 is easy because you can use a long as temp before renormalizing, but multiply of fix16p16 gets trickier, of course.

                                          My idea is to just wrap the new types in a class library, which allows for easy conversion and maths with these new fixedpt types.

                                          Yes, that was what I was guessing. Go for it!

                                          As part of this exercise we also have to modify these libraries which return their values in float-format, as it doesn't make sense to keeps floats in partly...

                                          Agreed. It would be nice if we rarely needed to even link the floating point library in nodes. (And it would make an ATtiny based node more feasible someday).

                                          YveauxY Offline
                                          YveauxY Offline
                                          Yveaux
                                          Mod
                                          wrote on last edited by
                                          #29

                                          @Zeph said:

                                          to support scaling you'd need to at least tell the gateway the scaling factor as part of the one-time presentation configuration

                                          This method (and the same holds for the decimals-parameter) seems attrictive, but has a few drawbacks:

                                          • The presentation message currently has no 'guaranteed' delivery; we would need to change that as without this info the gateway cannot interpret the incoming data
                                          • It also has to be sent to the sensor (actuator actually) nodes from the gateway when data goes the other way. No 'presentation' mechanism from gateway to sensor currently exists.
                                          • It places an administration burden on the gateway, and possibly on actuators

                                          Beyond that there's no need for new libraries, and it's easy to explain.

                                          Possibly, but when you start mixing up values with different scaling factors or want to do (simple) maths on them the story changes completely...

                                          http://yveaux.blogspot.nl

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          13

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular