diff options
author | Marc Schink <jaylink-dev@marcschink.de> | 2017-03-06 20:17:57 +0100 |
---|---|---|
committer | Marc Schink <jaylink-dev@marcschink.de> | 2017-03-09 16:59:33 +0100 |
commit | f8022ab9e76da186889fcbb98e1675a80c90b258 (patch) | |
tree | 1ecae50cbc9655b0ccd2686ada5a93dc946af65b /libjaylink/device.c | |
parent | 486776f98a7f8fb70a9154272439f3ab92645b51 (diff) | |
download | libjaylink-f8022ab9e76da186889fcbb98e1675a80c90b258.zip libjaylink-f8022ab9e76da186889fcbb98e1675a80c90b258.tar.gz libjaylink-f8022ab9e76da186889fcbb98e1675a80c90b258.tar.bz2 |
device: Add function to retrieve counter values
Signed-off-by: Marc Schink <jaylink-dev@marcschink.de>
Diffstat (limited to 'libjaylink/device.c')
-rw-r--r-- | libjaylink/device.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/libjaylink/device.c b/libjaylink/device.c index 8b4ad16..e14a304 100644 --- a/libjaylink/device.c +++ b/libjaylink/device.c @@ -43,6 +43,7 @@ #define CMD_GET_HW_STATUS 0x07 #define CMD_REGISTER 0x09 #define CMD_GET_HW_INFO 0xc1 +#define CMD_GET_COUNTERS 0xc2 #define CMD_GET_FREE_MEMORY 0xd4 #define CMD_GET_CAPS 0xe8 #define CMD_GET_EXT_CAPS 0xed @@ -615,6 +616,85 @@ JAYLINK_API int jaylink_get_hardware_info(struct jaylink_device_handle *devh, } /** + * Retrieve the counter values of a device. + * + * @note This function must only be used if the device has the + * #JAYLINK_DEV_CAP_GET_COUNTERS capability. + * + * @param[in,out] devh Device handle. + * @param[in] mask A bit field where each set bit represents a counter value to + * request. See #jaylink_counter for a description of the + * counters and their bit positions. + * @param[out] values Array to store the counter values on success. Its content + * is undefined on failure. The array must be large enough + * to contain at least as many elements as bits set in @p + * mask. + * + * @retval JAYLINK_OK Success. + * @retval JAYLINK_ERR_ARG Invalid arguments. + * @retval JAYLINK_ERR_TIMEOUT A timeout occurred. + * @retval JAYLINK_ERR_IO Input/output error. + * @retval JAYLINK_ERR Other error conditions. + * + * @since 0.2.0 + */ +JAYLINK_API int jaylink_get_counters(struct jaylink_device_handle *devh, + uint32_t mask, uint32_t *values) +{ + int ret; + struct jaylink_context *ctx; + uint8_t buf[5]; + unsigned int i; + unsigned int num; + unsigned int length; + + if (!devh || !mask || !values) + return JAYLINK_ERR_ARG; + + ctx = devh->dev->ctx; + num = 0; + + for (i = 0; i < 32; i++) { + if (mask & (1 << i)) + num++; + } + + length = num * sizeof(uint32_t); + ret = transport_start_write_read(devh, 5, length, true); + + if (ret != JAYLINK_OK) { + log_err(ctx, "transport_start_write_read() failed: %s.", + jaylink_strerror(ret)); + return ret; + } + + buf[0] = CMD_GET_COUNTERS; + buffer_set_u32(buf, mask, 1); + + ret = transport_write(devh, buf, 5); + + if (ret != JAYLINK_OK) { + log_err(ctx, "transport_write() failed: %s.", + jaylink_strerror(ret)); + return ret; + } + + ret = transport_read(devh, (uint8_t *)values, length); + + if (ret != JAYLINK_OK) { + log_err(ctx, "transport_read() failed: %s.", + jaylink_strerror(ret)); + return ret; + } + + for (i = 0; i < num; i++) + values[i] = buffer_get_u32((uint8_t *)values, + i * sizeof(uint32_t)); + + return JAYLINK_OK; +} + +/** * Retrieve the hardware version of a device. * * @note This function must only be used if the device has the |