aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Schink <jaylink-dev@marcschink.de>2016-11-11 15:57:09 +0100
committerMarc Schink <jaylink-dev@marcschink.de>2016-11-15 12:33:59 +0100
commit8713c3e9a9c7a0324aae7a62a74083bca759c8a9 (patch)
treed835b4ecd48a141a5759ce194e5e0302670f4b27
parent3e5f9baf54fe88d9dd8c28ca0a7b6ab3d9f9e1e3 (diff)
downloadlibjaylink-8713c3e9a9c7a0324aae7a62a74083bca759c8a9.zip
libjaylink-8713c3e9a9c7a0324aae7a62a74083bca759c8a9.tar.gz
libjaylink-8713c3e9a9c7a0324aae7a62a74083bca759c8a9.tar.bz2
Improve error handling in jaylink_swo_get_speeds()
Cover all possible error codes which may be returned by a device. Signed-off-by: Marc Schink <jaylink-dev@marcschink.de>
-rw-r--r--libjaylink/swo.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/libjaylink/swo.c b/libjaylink/swo.c
index 79d08d9..572be5a 100644
--- a/libjaylink/swo.c
+++ b/libjaylink/swo.c
@@ -41,6 +41,8 @@
#define SWO_PARAM_BAUDRATE 0x02
#define SWO_PARAM_READ_SIZE 0x03
#define SWO_PARAM_BUFFER_SIZE 0x04
+
+#define SWO_ERR 0x80000000
/** @endcond */
/**
@@ -346,6 +348,7 @@ JAYLINK_API int jaylink_swo_get_speeds(struct jaylink_device_handle *devh,
int ret;
struct jaylink_context *ctx;
uint8_t buf[24];
+ uint32_t tmp;
uint32_t length;
if (!devh || !speed)
@@ -388,13 +391,15 @@ JAYLINK_API int jaylink_swo_get_speeds(struct jaylink_device_handle *devh,
return ret;
}
- length = buffer_get_u32(buf, 0);
+ tmp = buffer_get_u32(buf, 0);
- if (length == 0xffffffff) {
+ if (tmp & SWO_ERR) {
log_err(ctx, "Failed to retrieve speed information.");
return JAYLINK_ERR_DEV;
}
+ length = tmp;
+
if (length != 28) {
log_err(ctx, "Unexpected number of bytes received: %u.",
length);