aboutsummaryrefslogtreecommitdiffstats
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
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 '')
-rw-r--r--o3000.c51
-rw-r--r--o3000.h2
-rw-r--r--o3000_upgrade.c10
-rw-r--r--o3000_upgrade.h2
4 files changed, 42 insertions, 23 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;
}
diff --git a/o3000.h b/o3000.h
index ac2127e..17aa6a5 100644
--- a/o3000.h
+++ b/o3000.h
@@ -92,7 +92,7 @@ int __stdcall o3000_disconnect(int id);
int __stdcall o3000_send_xml(int id, const char *msg, int msg_len);
-int __stdcall o3000_firmware_update(unsigned char *data, int data_len);
+int __stdcall o3000_firmware_upgrade(unsigned char *data, int data_len);
#if defined(__cplusplus) || defined(c_plusplus)
} // extern "C"
diff --git a/o3000_upgrade.c b/o3000_upgrade.c
index 176be03..9e461e8 100644
--- a/o3000_upgrade.c
+++ b/o3000_upgrade.c
@@ -426,15 +426,13 @@ static enum cam_mode_t wait_for_bootloader_mode() {
}
/**
- * Do firmware update of the device.
- *
- * Note: Parameters are already checked in o3000_firmware_update.
- *
- * @param data pointer to firmware update data
+ * Do firmware upgrade of the device.
+ *
+ * @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
*/
-int firmware_update(unsigned char *data, int data_len) {
+int firmware_upgrade(unsigned char *data, int data_len) {
enum cam_mode_t cam_mode = CM_UNKNOWN;
diff --git a/o3000_upgrade.h b/o3000_upgrade.h
index aa898fa..b88d38c 100644
--- a/o3000_upgrade.h
+++ b/o3000_upgrade.h
@@ -28,6 +28,6 @@
#ifndef __O3000_UPGRADE_H
#define __O3000_UPGRADE_H
-int firmware_update(unsigned char *data, int data_len);
+int firmware_upgrade(unsigned char *data, int data_len);
#endif