diff options
author | Andrew Duggan <aduggan@synaptics.com> | 2017-03-27 20:30:07 -0700 |
---|---|---|
committer | Andrew Duggan <aduggan@synaptics.com> | 2017-03-30 09:37:58 -0700 |
commit | 3781959e23f79fec610e87cfbc3a43c6b24ea7ba (patch) | |
tree | 72472b4556d85635ae23648e670588f72a4354dd | |
parent | f1abc1116e2adeb14de3439c347c2e9a78428f19 (diff) | |
download | rmi4utils-3781959e23f79fec610e87cfbc3a43c6b24ea7ba.tar.gz |
Consolidate utility functions into the rmidevice library
-rw-r--r-- | f54test/testutil.cpp | 28 | ||||
-rw-r--r-- | f54test/testutil.h | 1 | ||||
-rw-r--r-- | rmi4update/firmware_image.cpp | 1 | ||||
-rw-r--r-- | rmi4update/updateutil.cpp | 26 | ||||
-rw-r--r-- | rmi4update/updateutil.h | 4 | ||||
-rw-r--r-- | rmidevice/Android.mk | 4 | ||||
-rw-r--r-- | rmidevice/Makefile | 2 | ||||
-rw-r--r-- | rmidevice/rmidevice.cpp | 41 | ||||
-rw-r--r-- | rmidevice/rmidevice.h | 3 | ||||
-rw-r--r-- | rmidevice/util.cpp | 70 |
10 files changed, 79 insertions, 101 deletions
diff --git a/f54test/testutil.cpp b/f54test/testutil.cpp index 6de56b1..a49307c 100644 --- a/f54test/testutil.cpp +++ b/f54test/testutil.cpp @@ -41,30 +41,4 @@ const char *test_error_str[] = { const char * test_err_to_string(int err) { return test_error_str[err]; -} - -unsigned long extract_long(const unsigned char *data) -{ - return (unsigned long)data [0] - + (unsigned long)data [1] * 0x100 - + (unsigned long)data [2] * 0x10000 - + (unsigned long)data [3] * 0x1000000; -} - -unsigned short extract_short(const unsigned char *data) -{ - return (unsigned long)data [0] - + (unsigned long)data [1] * 0x100; -} - -const char * StripPath(const char * path, ssize_t size) -{ - int i; - const char * str; - - for (i = size - 1, str = &path[size - 1]; i > 0; --i, --str) - if (path[i - 1] == '/') - break; - - return str; -} +}
\ No newline at end of file diff --git a/f54test/testutil.h b/f54test/testutil.h index 3004299..d7c1433 100644 --- a/f54test/testutil.h +++ b/f54test/testutil.h @@ -41,6 +41,5 @@ const char * test_err_to_string(int err); unsigned long extract_long(const unsigned char *data); unsigned short extract_short(const unsigned char *data); -const char * StripPath(const char * path, ssize_t size); #endif // _TESTUTIL_H_ diff --git a/rmi4update/firmware_image.cpp b/rmi4update/firmware_image.cpp index ea97812..f1eec2a 100644 --- a/rmi4update/firmware_image.cpp +++ b/rmi4update/firmware_image.cpp @@ -21,6 +21,7 @@ #include <stdint.h> #include <stdlib.h> +#include "rmidevice.h" #include "firmware_image.h" using namespace std; diff --git a/rmi4update/updateutil.cpp b/rmi4update/updateutil.cpp index df070a6..1d654cd 100644 --- a/rmi4update/updateutil.cpp +++ b/rmi4update/updateutil.cpp @@ -57,29 +57,3 @@ const char * update_err_to_string(int err) { return update_error_str[err]; } - -unsigned long extract_long(const unsigned char *data) -{ - return (unsigned long)data [0] - + (unsigned long)data [1] * 0x100 - + (unsigned long)data [2] * 0x10000 - + (unsigned long)data [3] * 0x1000000; -} - -unsigned short extract_short(const unsigned char *data) -{ - return (unsigned long)data [0] - + (unsigned long)data [1] * 0x100; -} - -const char * StripPath(const char * path, ssize_t size) -{ - int i; - const char * str; - - for (i = size - 1, str = &path[size - 1]; i > 0; --i, --str) - if (path[i - 1] == '/') - break; - - return str; -}
\ No newline at end of file diff --git a/rmi4update/updateutil.h b/rmi4update/updateutil.h index 6907781..59f1a08 100644 --- a/rmi4update/updateutil.h +++ b/rmi4update/updateutil.h @@ -54,8 +54,4 @@ enum update_error { const char * update_err_to_string(int err); -unsigned long extract_long(const unsigned char *data); -unsigned short extract_short(const unsigned char *data); -const char * StripPath(const char * path, ssize_t size); - #endif // _UPDATEUTIL_H_
\ No newline at end of file diff --git a/rmidevice/Android.mk b/rmidevice/Android.mk index 8e23065..4f49535 100644 --- a/rmidevice/Android.mk +++ b/rmidevice/Android.mk @@ -2,7 +2,7 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := rmidevice -LOCAL_SRC_FILES := rmifunction.cpp rmidevice.cpp hiddevice.cpp +LOCAL_SRC_FILES := rmifunction.cpp rmidevice.cpp hiddevice.cpp util.cpp LOCAL_CPPFLAGS := -Wall -include $(BUILD_STATIC_LIBRARY)
\ No newline at end of file +include $(BUILD_STATIC_LIBRARY) diff --git a/rmidevice/Makefile b/rmidevice/Makefile index 35aec55..d9f32cc 100644 --- a/rmidevice/Makefile +++ b/rmidevice/Makefile @@ -3,7 +3,7 @@ AR ?= ar RANLIB ?= ranlib CPPFLAGS += -I../include -I./include CXXFLAGS += -fPIC -Wall -RMIDEVICESRC = rmifunction.cpp rmidevice.cpp hiddevice.cpp +RMIDEVICESRC = rmifunction.cpp rmidevice.cpp hiddevice.cpp util.cpp RMIDEVICEOBJ = $(RMIDEVICESRC:.cpp=.o) LIBNAME = librmidevice.so STATIC_LIBNAME = librmidevice.a diff --git a/rmidevice/rmidevice.cpp b/rmidevice/rmidevice.cpp index 668301c..15335f9 100644 --- a/rmidevice/rmidevice.cpp +++ b/rmidevice/rmidevice.cpp @@ -345,43 +345,4 @@ bool RMIDevice::InBootloader() return !!(status & 0x40); } return true; -} - -long long diff_time(struct timespec *start, struct timespec *end) -{ - long long diff; - diff = (end->tv_sec - start->tv_sec) * 1000 * 1000; - diff += (end->tv_nsec - start->tv_nsec) / 1000; - return diff; -} - -int Sleep(int ms) -{ - struct timespec ts; - struct timespec rem; - - ts.tv_sec = ms / 1000; - ts.tv_nsec = (ms % 1000) * 1000 * 1000; - for (;;) { - if (nanosleep(&ts, &rem) == 0) { - break; - } else { - if (errno == EINTR) { - ts = rem; - continue; - } - return -1; - } - } - return 0; -} - -void print_buffer(const unsigned char *buf, unsigned int len) -{ - for (unsigned int i = 0; i < len; ++i) { - fprintf(stdout, "0x%02X ", buf[i]); - if (i % 8 == 7) - fprintf(stdout, "\n"); - } - fprintf(stdout, "\n"); -} +}
\ No newline at end of file diff --git a/rmidevice/rmidevice.h b/rmidevice/rmidevice.h index 7959801..bd91eeb 100644 --- a/rmidevice/rmidevice.h +++ b/rmidevice/rmidevice.h @@ -121,4 +121,7 @@ protected: long long diff_time(struct timespec *start, struct timespec *end); int Sleep(int ms); void print_buffer(const unsigned char *buf, unsigned int len); +unsigned long extract_long(const unsigned char *data); +unsigned short extract_short(const unsigned char *data); +const char * StripPath(const char * path, ssize_t size); #endif /* _RMIDEVICE_H_ */ diff --git a/rmidevice/util.cpp b/rmidevice/util.cpp new file mode 100644 index 0000000..64b1c1c --- /dev/null +++ b/rmidevice/util.cpp @@ -0,0 +1,70 @@ +#include <stdio.h> +#include <sys/types.h> +#include <errno.h> +#include <time.h> + +long long diff_time(struct timespec *start, struct timespec *end) +{ + long long diff; + diff = (end->tv_sec - start->tv_sec) * 1000 * 1000; + diff += (end->tv_nsec - start->tv_nsec) / 1000; + return diff; +} + +int Sleep(int ms) +{ + struct timespec ts; + struct timespec rem; + + ts.tv_sec = ms / 1000; + ts.tv_nsec = (ms % 1000) * 1000 * 1000; + for (;;) { + if (nanosleep(&ts, &rem) == 0) { + break; + } else { + if (errno == EINTR) { + ts = rem; + continue; + } + return -1; + } + } + return 0; +} + +void print_buffer(const unsigned char *buf, unsigned int len) +{ + for (unsigned int i = 0; i < len; ++i) { + fprintf(stdout, "0x%02X ", buf[i]); + if (i % 8 == 7) + fprintf(stdout, "\n"); + } + fprintf(stdout, "\n"); +} + + +const char * StripPath(const char * path, ssize_t size) +{ + int i; + const char * str; + + for (i = size - 1, str = &path[size - 1]; i > 0; --i, --str) + if (path[i - 1] == '/') + break; + + return str; +} + +unsigned long extract_long(const unsigned char *data) +{ + return (unsigned long)data [0] + + (unsigned long)data [1] * 0x100 + + (unsigned long)data [2] * 0x10000 + + (unsigned long)data [3] * 0x1000000; +} + +unsigned short extract_short(const unsigned char *data) +{ + return (unsigned long)data [0] + + (unsigned long)data [1] * 0x100; +}
\ No newline at end of file |