You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/11/22 01:17:12 UTC

[13/27] incubator-mynewt-core git commit: cbor; floating point support optional.

cbor; floating point support optional.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/948b380a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/948b380a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/948b380a

Branch: refs/heads/develop
Commit: 948b380ab3e9f7dd4f2baa36d7d239bef1bc262e
Parents: 6e25f3f
Author: Marko Kiiskila <ma...@runtime.io>
Authored: Wed Nov 16 16:58:24 2016 -0800
Committer: Marko Kiiskila <ma...@runtime.io>
Committed: Mon Nov 21 17:15:48 2016 -0800

----------------------------------------------------------------------
 encoding/cborattr/pkg.yml           |  2 ++
 encoding/cborattr/src/cborattr.c    | 10 ++++++++++
 encoding/tinycbor/pkg.yml           |  1 +
 encoding/tinycbor/src/cborencoder.c |  2 ++
 encoding/tinycbor/src/cborpretty.c  |  5 +++--
 encoding/tinycbor/src/cbortojson.c  |  5 ++++-
 6 files changed, 22 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/cborattr/pkg.yml
----------------------------------------------------------------------
diff --git a/encoding/cborattr/pkg.yml b/encoding/cborattr/pkg.yml
index 541ab23..01f5982 100644
--- a/encoding/cborattr/pkg.yml
+++ b/encoding/cborattr/pkg.yml
@@ -25,3 +25,5 @@ pkg.keywords:
 
 pkg.deps:
     - "encoding/tinycbor"
+
+pkg.cflags.float_user: -DFLOAT_SUPPORT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/cborattr/src/cborattr.c
----------------------------------------------------------------------
diff --git a/encoding/cborattr/src/cborattr.c b/encoding/cborattr/src/cborattr.c
index 4d04248..a7ca9c0 100644
--- a/encoding/cborattr/src/cborattr.c
+++ b/encoding/cborattr/src/cborattr.c
@@ -46,6 +46,7 @@ valid_attr_type(CborType ct, CborAttrType at) {
             if (ct == CborBooleanType) {
                 return 1;
             }
+#if FLOAT_SUPPORT
         case CborAttrFloatType:
             if (ct == CborFloatType) {
                 return 1;
@@ -56,6 +57,7 @@ valid_attr_type(CborType ct, CborAttrType at) {
                 return 1;
             }
             break;
+#endif
         case CborAttrArrayType:
             if (ct == CborArrayType) {
                 return 1;
@@ -66,6 +68,8 @@ valid_attr_type(CborType ct, CborAttrType at) {
                 return 1;
             }
             break;
+        default:
+            break;
     }
     return 0;
 }
@@ -89,12 +93,14 @@ cbor_target_address(const struct cbor_attr_t *cursor,
         case CborAttrUnsignedIntegerType:
             targetaddr = (char *)&cursor->addr.uinteger[offset];
             break;
+#if FLOAT_SUPPORT
         case CborAttrFloatType:
             targetaddr = (char *)&cursor->addr.fval[offset];
             break;
         case CborAttrDoubleType:
             targetaddr = (char *)&cursor->addr.real[offset];
             break;
+#endif
         case CborAttrByteStringType:
             targetaddr = (char *) cursor->addr.bytestring.data;
             break;
@@ -145,12 +151,14 @@ cbor_internal_read_object(CborValue *root_value,
                     case CborAttrBooleanType:
                         memcpy(lptr, &cursor->dflt.boolean, sizeof(bool));
                         break;
+#if FLOAT_SUPPORT
                     case CborAttrFloatType:
                         memcpy(lptr, &cursor->dflt.fval, sizeof(float));
                         break;
                     case CborAttrDoubleType:
                         memcpy(lptr, &cursor->dflt.real, sizeof(double));
                         break;
+#endif
                     default:
                         break;
                 }
@@ -215,12 +223,14 @@ cbor_internal_read_object(CborValue *root_value,
                 case CborAttrUnsignedIntegerType:
                     g_err |= cbor_value_get_uint64(&cur_value, (long long unsigned int *) lptr);
                     break;
+#if FLOAT_SUPPORT
                 case CborAttrFloatType:
                     g_err |= cbor_value_get_float(&cur_value, (float *) lptr);
                     break;
                 case CborAttrDoubleType:
                     g_err |= cbor_value_get_double(&cur_value, (double *) lptr);
                     break;
+#endif
                 case CborAttrByteStringType:
                 {
                     size_t len = cursor->len;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/tinycbor/pkg.yml
----------------------------------------------------------------------
diff --git a/encoding/tinycbor/pkg.yml b/encoding/tinycbor/pkg.yml
index acd66c0..f969de8 100644
--- a/encoding/tinycbor/pkg.yml
+++ b/encoding/tinycbor/pkg.yml
@@ -24,3 +24,4 @@ pkg.homepage: "http://mynewt.apache.org/"
 pkg.keywords:
 
 pkg.cflags: -DWITHOUT_OPEN_MEMSTREAM -I../include/tinycbor
+pkg.cflags.float_user: -DFLOAT_SUPPORT

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/tinycbor/src/cborencoder.c
----------------------------------------------------------------------
diff --git a/encoding/tinycbor/src/cborencoder.c b/encoding/tinycbor/src/cborencoder.c
index b510662..0bf81b4 100644
--- a/encoding/tinycbor/src/cborencoder.c
+++ b/encoding/tinycbor/src/cborencoder.c
@@ -334,6 +334,7 @@ CborError cbor_encode_simple_value(CborEncoder *encoder, uint8_t value)
     return encode_number(encoder, value, SimpleTypesType << MajorTypeShift);
 }
 
+#if FLOAT_SUPPORT
 /**
  * Appends the floating-point value of type \a fpType and pointed to by \a
  * value to the CBOR stream provided by \a encoder. The value of \a fpType must
@@ -361,6 +362,7 @@ CborError cbor_encode_floating_point(CborEncoder *encoder, CborType fpType, cons
     ++encoder->added;
     return append_to_buffer(encoder, buf, size + 1);
 }
+#endif
 
 /**
  * Appends the CBOR tag \a tag to the CBOR stream provided by \a encoder.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/tinycbor/src/cborpretty.c
----------------------------------------------------------------------
diff --git a/encoding/tinycbor/src/cborpretty.c b/encoding/tinycbor/src/cborpretty.c
index 3587703..b4335a7 100644
--- a/encoding/tinycbor/src/cborpretty.c
+++ b/encoding/tinycbor/src/cborpretty.c
@@ -392,7 +392,7 @@ static CborError value_to_pretty(FILE *out, CborValue *it)
             return CborErrorIO;
         break;
     }
-
+#if FLOAT_SUPPORT
     case CborDoubleType: {
         const char *suffix;
         double val;
@@ -430,8 +430,9 @@ static CborError value_to_pretty(FILE *out, CborValue *it)
             return CborErrorIO;
         break;
     }
-
+#endif
     case CborInvalidType:
+    default:
         if (fprintf(out, "invalid") < 0)
             return CborErrorIO;
         return CborErrorUnknownType;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/948b380a/encoding/tinycbor/src/cbortojson.c
----------------------------------------------------------------------
diff --git a/encoding/tinycbor/src/cbortojson.c b/encoding/tinycbor/src/cbortojson.c
index 5efa486..b8e116f 100644
--- a/encoding/tinycbor/src/cbortojson.c
+++ b/encoding/tinycbor/src/cbortojson.c
@@ -594,7 +594,7 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
             return CborErrorIO;
         break;
     }
-
+#if FLOAT_SUPPORT
     case CborDoubleType: {
         double val;
         if (false) {
@@ -634,8 +634,10 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
         }
         break;
     }
+#endif
 
     case CborInvalidType:
+    default:
         return CborErrorUnknownType;
     }
 
@@ -643,6 +645,7 @@ static CborError value_to_json(FILE *out, CborValue *it, int flags, CborType typ
 }
 
 /**
+
  * \enum CborToJsonFlags
  * The CborToJsonFlags enum contains flags that control the conversion of CBOR to JSON.
  *