aboutsummaryrefslogtreecommitdiffstats
path: root/o3000.c
diff options
context:
space:
mode:
authorPatrick Roth <roth@stettbacher.ch>2021-07-09 07:23:25 +0200
committerPatrick Roth <roth@stettbacher.ch>2021-07-09 07:23:25 +0200
commited2c49b25964da760117c04fe94d02d92ad03cd6 (patch)
tree0be99a4bf80cf4efb5004766308eb7f5eb15e179 /o3000.c
parentRefine comments regarding the relation of o3000_connect(), o3000_disconnect()... (diff)
parentupdate --> upgrade , more checks added (diff)
downloado3000-driver-master.tar.gz
o3000-driver-master.zip
Merge branch 'firmware_upgrade' into 'master'HEADmaster
Firmware upgrade See merge request o-3000/driver!1
Diffstat (limited to 'o3000.c')
-rw-r--r--o3000.c79
1 files changed, 77 insertions, 2 deletions
diff --git a/o3000.c b/o3000.c
index b8ede08..3558a8b 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,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
*/