OSDN Git Service

Winter cleanup: move iio type field decoding out of utils.c
authorPatrick Porlan <patrick.porlan@intel.com>
Mon, 15 Dec 2014 09:11:20 +0000 (10:11 +0100)
committerSuman, Viorel <viorel.suman@intel.com>
Tue, 16 Dec 2014 11:25:11 +0000 (11:25 +0000)
It's a very specialized function, which only makes sense in
the file where it's used. Let's not mix it with general
toolbox pieces.

Change-Id: I9915f380bd75394a4ea98a425a5fdcb0f287ebc6
Signed-off-by: Patrick Porlan <patrick.porlan@intel.com>
control.c
utils.c
utils.h

index 237e61a..12d118b 100644 (file)
--- a/control.c
+++ b/control.c
@@ -193,6 +193,39 @@ static void enable_iio_timestamp (int dev_num, int known_channels)
 }
 
 
+static int decode_type_spec (const char type_buf[MAX_TYPE_SPEC_LEN],
+                            struct datum_info_t *type_info)
+{
+       /* Return size in bytes for this type specification, or -1 in error */
+       char sign;
+       char endianness;
+       unsigned int realbits, storagebits, shift;
+       int tokens;
+
+       /* Valid specs: "le:u10/16>>0", "le:s16/32>>0" or "le:s32/32>>0" */
+
+       tokens = sscanf(type_buf, "%ce:%c%u/%u>>%u",
+                       &endianness, &sign, &realbits, &storagebits, &shift);
+
+       if     (tokens != 5 ||
+               (endianness != 'b' && endianness != 'l') ||
+               (sign != 'u' && sign != 's') ||
+               realbits > storagebits ||
+               (storagebits != 16 && storagebits != 32 && storagebits != 64)) {
+                       ALOGE("Invalid iio channel type spec: %s\n", type_buf);
+                       return -1;
+               }
+
+       type_info->endianness   =               endianness;
+       type_info->sign         =               sign;
+       type_info->realbits     =       (short) realbits;
+       type_info->storagebits  =       (short) storagebits;
+       type_info->shift        =       (short) shift;
+
+       return storagebits / 8;
+}
+
+
 void build_sensor_report_maps (int dev_num)
 {
        /*
diff --git a/utils.c b/utils.c
index f37f782..c41931f 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -225,39 +225,6 @@ int sysfs_read_float(const char path[PATH_MAX], float *value)
 }
 
 
-int decode_type_spec(  const char type_buf[MAX_TYPE_SPEC_LEN],
-                       struct datum_info_t *type_info)
-{
-       /* Return size in bytes for this type specification, or -1 in error */
-       char sign;
-       char endianness;
-       unsigned int realbits, storagebits, shift;
-       int tokens;
-
-       /* Valid specs: "le:u10/16>>0", "le:s16/32>>0" or "le:s32/32>>0" */
-
-       tokens = sscanf(type_buf, "%ce:%c%u/%u>>%u",
-                       &endianness, &sign, &realbits, &storagebits, &shift);
-
-       if     (tokens != 5 ||
-               (endianness != 'b' && endianness != 'l') ||
-               (sign != 'u' && sign != 's') ||
-               realbits > storagebits ||
-               (storagebits != 16 && storagebits != 32 && storagebits != 64)) {
-                       ALOGE("Invalid iio channel type spec: %s\n", type_buf);
-                       return -1;
-               }
-
-       type_info->endianness   =               endianness;
-       type_info->sign         =               sign;
-       type_info->realbits     =       (short) realbits;
-       type_info->storagebits  =       (short) storagebits;
-       type_info->shift        =       (short) shift;
-
-       return storagebits / 8;
-}
-
-
 int64_t get_timestamp_realtime (void)
 {
        struct timespec ts = {0};
diff --git a/utils.h b/utils.h
index 86e8bbb..d3da472 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -16,9 +16,6 @@ int   sysfs_write_str  (const char path[PATH_MAX], const char *buf);
 int    sysfs_read_float (const char path[PATH_MAX], float *value);
 int    sysfs_write_float(const char path[PATH_MAX], float value);
 
-int    decode_type_spec(const char type_buf[MAX_TYPE_SPEC_LEN],
-                        struct datum_info_t *type_info);
-
 void   set_timestamp   (struct timespec *out, int64_t target_ns);
 
 int64_t get_timestamp_boot     (void);