From c1847bdd4facbd48359690d584accc65fbc13ab8 Mon Sep 17 00:00:00 2001 From: Sophia Papagiannaki Date: Tue, 12 May 2020 11:09:42 +0200 Subject: added firmware upgrade function --- o3000.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'o3000.c') diff --git a/o3000.c b/o3000.c index dd99f97..c68baf7 100644 --- a/o3000.c +++ b/o3000.c @@ -868,6 +868,33 @@ int __stdcall o3000_send_xml(int id, const char *msg, int msg_len) { } +/** + * Do firmware update of the device + * + * @param data pointer to firmware update data + * @param data_len update package lenght in bytes + * @return 0 on success, -1 on failure + */ +int __stdcall o3000_firmware_update(unsigned char *data, int data_len) { + + int ret; + + // paranoia checks + if(data == NULL) { + return -1; + } + + + if(data_len <= 0) { + return -1; + } + + // checking whether all connection are closed + ret = firmware_update(data, data_len); + return ret; +} + + /** * Disconnect a currently claimed USB connection. * Use this function if the driver is connected to an USB device. The o3000_connect() function-call is blocking now. -- cgit v1.2.1 From bf0831b3e877ec53f223b73c1de5f6028f24a885 Mon Sep 17 00:00:00 2001 From: Sophia Papagiannaki Date: Tue, 19 May 2020 18:30:53 +0200 Subject: Version 2.1.0 Implemented firmware update. --- o3000.c | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'o3000.c') diff --git a/o3000.c b/o3000.c index c68baf7..1ea9f77 100644 --- a/o3000.c +++ b/o3000.c @@ -240,6 +240,7 @@ or a transfer may contain several frames. #include "o3000_private.h" #include "o3000.h" #include "o3000_xfer_handler.h" +#include "o3000_upgrade.h" #define CAM_IN_EP (1 | LIBUSB_ENDPOINT_IN) ///< endpoint for video data @@ -867,30 +868,57 @@ int __stdcall o3000_send_xml(int id, const char *msg, int msg_len) { return (send_xml(session, msg, msg_len)); } +/** + * Check whether all connections are closed. + * + * @return 0 if all sessions are closed, error code otherwise defined at @ref o3000.h. + */ +static int check_sessions(void) { + int i; + + for(i = 0; i < MAX_NUM_SESSION; i++) { + if(session_table[i] != NULL) { + break; + } + } + if (i < MAX_NUM_SESSION) { + printf("%s: Session %d is still open\n", __func__, i); + return O3000_ERROR_SESSION_STILL_OPEN; + } + return 0; +} /** * Do firmware update of the device * * @param data pointer to firmware update data - * @param data_len update package lenght in bytes - * @return 0 on success, -1 on failure + * @param data_len firmware update data lenght in bytes + * @return 0 on success, error code on failure defined at @ref o3000.h. */ int __stdcall o3000_firmware_update(unsigned char *data, int data_len) { - - int ret; + + int ret = 0; // paranoia checks if(data == NULL) { - return -1; + ret = O3000_ERROR_NOT_VALID_ARGUMENT; + printf("%s: Data pointer is NULL. error: %d\n", __func__, ret); + return ret; } - - if(data_len <= 0) { - return -1; + ret = O3000_ERROR_NOT_VALID_ARGUMENT; + printf("%s: Length of data is negative. error: %d\n", __func__, ret); + return ret; } - // checking whether all connection are closed + // checking whether all connections are closed + if ((ret = check_sessions())) { + printf("%s: Cannot proceed to firmware update: error %d\n", __func__, ret); + return ret; + } + ret = firmware_update(data, data_len); + return ret; } -- cgit v1.2.1 From 8da9dcf4f2387aa7f9c0aad28a87a04de98f3000 Mon Sep 17 00:00:00 2001 From: Sophia Papagiannaki Date: Mon, 15 Jun 2020 15:37:35 +0200 Subject: Modified some debug/error messages. --- o3000.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'o3000.c') diff --git a/o3000.c b/o3000.c index 1ea9f77..37c0ab7 100644 --- a/o3000.c +++ b/o3000.c @@ -882,7 +882,7 @@ static int check_sessions(void) { } } if (i < MAX_NUM_SESSION) { - printf("%s: Session %d is still open\n", __func__, i); + printf("%s: Session %d is still open.\n", __func__, i); return O3000_ERROR_SESSION_STILL_OPEN; } return 0; @@ -902,18 +902,18 @@ int __stdcall o3000_firmware_update(unsigned char *data, int data_len) { // paranoia checks if(data == NULL) { ret = O3000_ERROR_NOT_VALID_ARGUMENT; - printf("%s: Data pointer is NULL. error: %d\n", __func__, ret); + printf("%s: Data pointer is NULL. error code: %d.\n", __func__, ret); return ret; } if(data_len <= 0) { ret = O3000_ERROR_NOT_VALID_ARGUMENT; - printf("%s: Length of data is negative. error: %d\n", __func__, ret); + printf("%s: Length of data is negative. error code: %d.\n", __func__, ret); return ret; } // checking whether all connections are closed if ((ret = check_sessions())) { - printf("%s: Cannot proceed to firmware update: error %d\n", __func__, ret); + printf("%s: Cannot proceed to firmware update: error code: %d.\n", __func__, ret); return ret; } -- cgit v1.2.1 From 8ad61ce3a1ac60f62d792c26831a7413ab573d79 Mon Sep 17 00:00:00 2001 From: "sophia.papagiannaki" Date: Tue, 28 Jul 2020 15:12:47 +0200 Subject: Working copy for testing on Windows. --- o3000.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'o3000.c') diff --git a/o3000.c b/o3000.c index 37c0ab7..12c5ff1 100644 --- a/o3000.c +++ b/o3000.c @@ -869,23 +869,25 @@ int __stdcall o3000_send_xml(int id, const char *msg, int msg_len) { } /** - * Check whether all connections are closed. + * Get the number of open sessions. * - * @return 0 if all sessions are closed, error code otherwise defined at @ref o3000.h. + * @return number of open sessions */ -static int check_sessions(void) { - int i; +static int get_num_open_sessions(void) { + int i, num_sessions = 0; for(i = 0; i < MAX_NUM_SESSION; i++) { if(session_table[i] != NULL) { - break; + num_sessions ++; } } - if (i < MAX_NUM_SESSION) { - printf("%s: Session %d is still open.\n", __func__, i); - return O3000_ERROR_SESSION_STILL_OPEN; - } - return 0; + return num_sessions; + +// if (i < MAX_NUM_SESSION) { +// printf("%s: Session %d is still open.\n", __func__, i); +// return O3000_ERROR_SESSION_STILL_OPEN; +// } +// return 0; } /** @@ -897,7 +899,7 @@ static int check_sessions(void) { */ int __stdcall o3000_firmware_update(unsigned char *data, int data_len) { - int ret = 0; + int ret = 0, num_sessions; // paranoia checks if(data == NULL) { @@ -912,7 +914,9 @@ int __stdcall o3000_firmware_update(unsigned char *data, int data_len) { } // checking whether all connections are closed - if ((ret = check_sessions())) { + num_sessions = get_num_open_sessions(); + if (num_sessions > 0) { + ret = O3000_ERROR_SESSION_STILL_OPEN; printf("%s: Cannot proceed to firmware update: error code: %d.\n", __func__, ret); return ret; } -- cgit v1.2.1 From cd386dac7875843caa54be2190cf6dd4923db50a Mon Sep 17 00:00:00 2001 From: "sophia.papagiannaki" Date: Wed, 29 Jul 2020 14:08:26 +0200 Subject: Deleted comment lines. --- o3000.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'o3000.c') diff --git a/o3000.c b/o3000.c index 12c5ff1..cd4a928 100644 --- a/o3000.c +++ b/o3000.c @@ -882,12 +882,6 @@ static int get_num_open_sessions(void) { } } return num_sessions; - -// if (i < MAX_NUM_SESSION) { -// printf("%s: Session %d is still open.\n", __func__, i); -// return O3000_ERROR_SESSION_STILL_OPEN; -// } -// return 0; } /** @@ -951,7 +945,7 @@ int __stdcall o3000_disconnect(int id) { o3000_log(session, O3000_LOG_WARNING, "%s: driver is not connected!\n", __func__); return O3000_ERROR_DRV_NOT_CONNECTED; } - + o3000_log(session, O3000_LOG_DEBUG, "%s: disconnect USB device (release interface)\n", __func__); session->cleanup_transfers = TRUE; session->disconnect_dev = TRUE; @@ -965,6 +959,7 @@ int __stdcall o3000_disconnect(int id) { else if(retval != 0) { o3000_log(session, O3000_LOG_ERROR, "%s: releasing interface failed (code %d)\n", __func__, retval); } + return retval; } @@ -1092,7 +1087,7 @@ int __stdcall o3000_connect(int id, int device_nr, char *config_msg, int config_ o3000_log(session, O3000_LOG_ERROR, "%s: sending configuration string failed (code %d)\n", __func__, ret); } } - + /* * Finally enter main-loop */ -- cgit v1.2.1 From 6e04d6e2cc094aae7122627a96b35fb76038a17e Mon Sep 17 00:00:00 2001 From: Patrick Roth Date: Fri, 9 Oct 2020 13:24:58 +0200 Subject: update --> upgrade , more checks added Use firmware upgrade instead of update. The firmware update function does more sanity checks. --- o3000.c | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'o3000.c') diff --git a/o3000.c b/o3000.c index cd4a928..f53bce2 100644 --- a/o3000.c +++ b/o3000.c @@ -885,38 +885,59 @@ static int get_num_open_sessions(void) { } /** - * Do firmware update of the device + * Do firmware upgrade of connected camera device. * - * @param data pointer to firmware update data + * Make sure, that all O-3000 sessions are closed before calling this + * function. Further, only one camera must be connected to the host system. + * Otherwise the update process will fail. + * + * @param data pointer to firmware update data binary * @param data_len firmware update data lenght in bytes * @return 0 on success, error code on failure defined at @ref o3000.h. */ -int __stdcall o3000_firmware_update(unsigned char *data, int data_len) { +int __stdcall o3000_firmware_upgrade(unsigned char *data, int data_len) { - int ret = 0, num_sessions; + int ret , num_sessions, num_cam; // paranoia checks if(data == NULL) { - ret = O3000_ERROR_NOT_VALID_ARGUMENT; - printf("%s: Data pointer is NULL. error code: %d.\n", __func__, ret); - return ret; + printf("%s: Firmware binary not defined!\n", __func__); + return O3000_ERROR_NOT_VALID_ARGUMENT; } if(data_len <= 0) { - ret = O3000_ERROR_NOT_VALID_ARGUMENT; - printf("%s: Length of data is negative. error code: %d.\n", __func__, ret); - return ret; + printf("%s: Invalid firmware binary length of %d bytes!\n", __func__, data_len); + return O3000_ERROR_NOT_VALID_ARGUMENT; } - // checking whether all connections are closed + // checking whether all camera sessions are closed num_sessions = get_num_open_sessions(); if (num_sessions > 0) { - ret = O3000_ERROR_SESSION_STILL_OPEN; - printf("%s: Cannot proceed to firmware update: error code: %d.\n", __func__, ret); - return ret; + printf("%s: There're still %d camera session(s) opened. Close all session to perform firmware upgrade.\n", __func__, num_sessions); + return O3000_ERROR_SESSION_STILL_OPEN; } - ret = firmware_update(data, data_len); + // checking whether only one camera is connected to the system + num_cam = o3000_get_num_cam(); + if(num_cam < 0) { + // forward error + printf("%s: Getting number of connected cameras failed with error code %d\n", __func__, num_cam); + return num_cam; + } + if(num_cam == 0) { + // no camera connected to the system + printf("%s: No camera connected to the host system.\n", __func__); + return O3000_ERROR_NODEV; + } + if(num_cam > 1) { + printf("%s: %d cameras connected to the host system. Make sure only one camera is connected.\n", __func__, num_cam); + return O3000_ERROR_OTHER; + } + // At this point only one camera is connected and all sessions are closed. Perform upgrade now. + ret = firmware_upgrade(data, data_len); + if(ret != 0) { + printf("%s: Firmware upgrade failed with error code %d.\n", __func__, ret); + } return ret; } -- cgit v1.2.1