aboutsummaryrefslogtreecommitdiffstats
path: root/o3000.c
diff options
context:
space:
mode:
authorPatrick Roth <roth@stettbacher.ch>2020-10-09 13:24:58 +0200
committerPatrick Roth <roth@stettbacher.ch>2020-10-09 13:24:58 +0200
commit6e04d6e2cc094aae7122627a96b35fb76038a17e (patch)
tree73e39de03aada04e2c6a87336b3bc9574945be04 /o3000.c
parentDeleted comment lines. (diff)
downloado3000-driver-6e04d6e2cc094aae7122627a96b35fb76038a17e.tar.gz
o3000-driver-6e04d6e2cc094aae7122627a96b35fb76038a17e.zip
update --> upgrade , more checks added
Use firmware upgrade instead of update. The firmware update function does more sanity checks.
Diffstat (limited to 'o3000.c')
-rw-r--r--o3000.c51
1 files changed, 36 insertions, 15 deletions
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;
}