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