libftdi-git Archives

Subject: port libftdi to libusb-1.0 branch, get-library-version, updated. v0.17-271-g0220adf

From: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
To: libftdi-git@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sun, 25 Sep 2011 12:10:11 +0200 (CEST)
The branch, get-library-version has been updated
       via  0220adfa93f4baab153efbe71873551f0325a42f (commit)
      from  b9c1e31765740e24a34112a3df58e95646b2316b (commit)


- Log -----------------------------------------------------------------
commit 0220adfa93f4baab153efbe71873551f0325a42f
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date:   Sun Sep 25 12:08:55 2011 +0200

    Added API to get libftdi library version.
    
    Supports version number as integer, string
    and possible git snapshot revision.
    
    Based upon idea by Martin Zenzes.

-----------------------------------------------------------------------

Summary of changes:
 examples/simple.c  |    6 ++++++
 src/CMakeLists.txt |   14 ++++++++++++++
 src/ftdi.c         |   18 ++++++++++++++++++
 src/ftdi.h         |   19 +++++++++++++++++++
 4 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/examples/simple.c b/examples/simple.c
index 145e931..9fac121 100644
--- a/examples/simple.c
+++ b/examples/simple.c
@@ -13,12 +13,18 @@ int main(void)
 {
     int ret;
     struct ftdi_context ftdic;
+    struct ftdi_version_info version;
     if (ftdi_init(&ftdic) < 0)
     {
         fprintf(stderr, "ftdi_init failed\n");
         return EXIT_FAILURE;
     }
 
+    version = ftdi_get_library_version();
+    printf("Initialized libftdi %s (major: %d, minor: %d, micro: %d, snapshot 
ver: %s)\n",
+        version.version_str, version.major, version.minor, version.micro,
+        version.snapshot_str);
+
     if ((ret = ftdi_usb_open(&ftdic, 0x0403, 0x6001)) < 0)
     {
         fprintf(stderr, "unable to open ftdi device: %d (%s)\n", ret, 
ftdi_get_error_string(&ftdic));
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0816341..b7ae085 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -3,6 +3,20 @@ include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}
                      ${CMAKE_CURRENT_SOURCE_DIR}
                      )
 
+# Version information
+set(SNAPSHOT_VERSION "unknown")
+execute_process(COMMAND git describe
+                OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT
+                RESULT_VARIABLE GIT_DESCRIBE_RESULT
+                OUTPUT_STRIP_TRAILING_WHITESPACE
+                )
+if(${GIT_DESCRIBE_RESULT} STREQUAL 0)
+    set(SNAPSHOT_VERSION ${GIT_DESCRIBE_OUTPUT})
+endif(${GIT_DESCRIBE_RESULT} STREQUAL 0)
+message(STATUS "Detected git snapshot version: ${SNAPSHOT_VERSION}")
+
+configure_file(ftdi_version_i.h.in 
"${CMAKE_CURRENT_BINARY_DIR}/ftdi_version_i.h" @ONLY)
+
 # Targets
 set(c_sources     ftdi.c ftdi_stream.c)
 set(c_headers     ftdi.h)
diff --git a/src/ftdi.c b/src/ftdi.c
index fba5288..de5ded1 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -35,6 +35,7 @@
 #include <stdlib.h>
 
 #include "ftdi.h"
+#include "ftdi_version_i.h"
 
 #define ftdi_error_return(code, str) do {  \
         ftdi->error_str = str;             \
@@ -257,6 +258,23 @@ void ftdi_set_usbdev (struct ftdi_context *ftdi, 
libusb_device_handle *usb)
     ftdi->usb_dev = usb;
 }
 
+/**
+ * @brief Get libftdi library version
+ *
+ * @return ftdi_version_info Library version information
+ **/
+struct ftdi_version_info ftdi_get_library_version()
+{
+    struct ftdi_version_info ver;
+
+    ver.major = FTDI_MAJOR_VERSION;
+    ver.minor = FTDI_MINOR_VERSION;
+    ver.micro = FTDI_MICRO_VERSION;
+    ver.version_str = FTDI_VERSION_STRING;
+    ver.snapshot_str = FTDI_SNAPSHOT_VERSION;
+
+    return ver;
+}
 
 /**
     Finds all ftdi devices with given VID:PID on the usb bus. Creates a new
diff --git a/src/ftdi.h b/src/ftdi.h
index 4e3880e..759e61b 100644
--- a/src/ftdi.h
+++ b/src/ftdi.h
@@ -498,6 +498,23 @@ typedef struct
 typedef int (FTDIStreamCallback)(uint8_t *buffer, int length,
                                  FTDIProgressInfo *progress, void *userdata);
 
+/**
+ * Provide libftdi version information
+ * major: Library major version
+ * minor: Library minor version
+ * micro: Currently unused, ight get used for hotfixes.
+ * version_str: Version as (static) string
+ * snapshot_str: Git snapshot version if known. Otherwise "unknown" or empty 
string.
+*/
+struct ftdi_version_info
+{
+    int major;
+    int minor;
+    int micro;
+    const char *version_str;
+    const char *snapshot_str;
+};
+
 
 #ifdef __cplusplus
 extern "C"
@@ -512,6 +529,8 @@ extern "C"
     void ftdi_free(struct ftdi_context *ftdi);
     void ftdi_set_usbdev (struct ftdi_context *ftdi, struct 
libusb_device_handle *usbdev);
 
+    struct ftdi_version_info ftdi_get_library_version();
+
     int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list 
**devlist,
                           int vendor, int product);
     void ftdi_list_free(struct ftdi_device_list **devlist);


hooks/post-receive
-- 
port libftdi to libusb-1.0

--
libftdi-git - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread
  • port libftdi to libusb-1.0 branch, get-library-version, updated. v0.17-271-g0220adf, libftdi-git <=