diff options
author | Patrick Roth <roth@stettbacher.ch> | 2021-07-09 07:23:25 +0200 |
---|---|---|
committer | Patrick Roth <roth@stettbacher.ch> | 2021-07-09 07:23:25 +0200 |
commit | ed2c49b25964da760117c04fe94d02d92ad03cd6 (patch) | |
tree | 0be99a4bf80cf4efb5004766308eb7f5eb15e179 /o3000.c | |
parent | Refine comments regarding the relation of o3000_connect(), o3000_disconnect()... (diff) | |
parent | update --> upgrade , more checks added (diff) | |
download | o3000-driver-ed2c49b25964da760117c04fe94d02d92ad03cd6.tar.gz o3000-driver-ed2c49b25964da760117c04fe94d02d92ad03cd6.zip |
Firmware upgrade
See merge request o-3000/driver!1
Diffstat (limited to '')
-rw-r--r-- | o3000.c | 79 |
1 files changed, 77 insertions, 2 deletions
@@ -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,6 +868,79 @@ int __stdcall o3000_send_xml(int id, const char *msg, int msg_len) { return (send_xml(session, msg, msg_len)); } +/** + * Get the number of open sessions. + * + * @return number of open sessions + */ +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) { + num_sessions ++; + } + } + return num_sessions; +} + +/** + * Do firmware upgrade of connected camera device. + * + * 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_upgrade(unsigned char *data, int data_len) { + + int ret , num_sessions, num_cam; + + // paranoia checks + if(data == NULL) { + printf("%s: Firmware binary not defined!\n", __func__); + return O3000_ERROR_NOT_VALID_ARGUMENT; + } + if(data_len <= 0) { + printf("%s: Invalid firmware binary length of %d bytes!\n", __func__, data_len); + return O3000_ERROR_NOT_VALID_ARGUMENT; + } + + // checking whether all camera sessions are closed + num_sessions = get_num_open_sessions(); + if (num_sessions > 0) { + 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; + } + + // 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; +} + /** * Disconnect a currently claimed USB connection. @@ -892,7 +966,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; @@ -906,6 +980,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; } @@ -1033,7 +1108,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 */ |