33 #define CMD_EMUCOM 0xee 35 #define EMUCOM_CMD_READ 0x00 36 #define EMUCOM_CMD_WRITE 0x01 39 #define EMUCOM_ERR 0x80000000 42 #define EMUCOM_ERR_NOT_SUPPORTED 0x80000001 53 #define EMUCOM_ERR_NOT_AVAILABLE 0x81000000 59 #define EMUCOM_AVAILABLE_BYTES_MASK 0x00ffffff 101 if (!devh || !buffer || !length)
108 log_err(ctx,
"transport_start_write_read() failed: %s.",
114 buf[1] = EMUCOM_CMD_READ;
122 log_err(ctx,
"transport_write() failed: %s.",
130 log_err(ctx,
"transport_read() failed: %s.",
137 if (tmp == EMUCOM_ERR_NOT_SUPPORTED)
140 if ((tmp & ~EMUCOM_AVAILABLE_BYTES_MASK) == EMUCOM_ERR_NOT_AVAILABLE) {
141 *length = tmp & EMUCOM_AVAILABLE_BYTES_MASK;
145 if (tmp & EMUCOM_ERR) {
146 log_err(ctx,
"Failed to read from channel 0x%x: 0x%x.",
152 log_err(ctx,
"Requested at most %u bytes but device " 153 "returned %u bytes.", *length, tmp);
165 log_err(ctx,
"transport_start_read() failed: %s.",
173 log_err(ctx,
"transport_read() failed: %s.",
207 uint32_t channel,
const uint8_t *
buffer, uint32_t *
length)
214 if (!devh || !buffer || !length)
224 log_err(ctx,
"transport_start_write() failed: %s.",
230 buf[1] = EMUCOM_CMD_WRITE;
238 log_err(ctx,
"transport_write() failed: %s.",
246 log_err(ctx,
"transport_start_write_read() failed: %s.",
254 log_err(ctx,
"transport_write() failed: %s.",
262 log_err(ctx,
"transport_read() failed: %s.",
269 if (tmp == EMUCOM_ERR_NOT_SUPPORTED)
272 if (tmp & EMUCOM_ERR) {
273 log_err(ctx,
"Failed to write to channel 0x%x: 0x%x.",
279 log_err(ctx,
"Only %u bytes were supposed to be written, but " 280 "the device reported %u written bytes.", *length, tmp);
JAYLINK_PRIV int transport_read(struct jaylink_device_handle *devh, uint8_t *buffer, size_t length)
Read data from a device.
JAYLINK_API int jaylink_emucom_read(struct jaylink_device_handle *devh, uint32_t channel, uint8_t *buffer, uint32_t *length)
Read from an EMUCOM channel.
JAYLINK_PRIV void log_err(const struct jaylink_context *ctx, const char *format,...)
JAYLINK_PRIV uint32_t buffer_get_u32(const uint8_t *buffer, size_t offset)
Read a 32-bit unsigned integer value from a buffer.
Opaque structure representing a libjaylink context.
Internal libjaylink header file.
struct jaylink_context * ctx
libjaylink context.
JAYLINK_PRIV int transport_start_read(struct jaylink_device_handle *devh, size_t length)
Start a read operation for a device.
Opaque structure representing a handle of a device.
JAYLINK_PRIV int transport_start_write(struct jaylink_device_handle *devh, size_t length, bool has_command)
Start a write operation for a device.
Public libjaylink header file to be used by applications.
Device: entity not available.
JAYLINK_API const char * jaylink_strerror(int error_code)
Return a human-readable description of a libjaylink error code.
static struct jaylink_device_handle * devh
#define JAYLINK_API
Macro to mark public libjaylink API symbol.
JAYLINK_API int jaylink_emucom_write(struct jaylink_device_handle *devh, uint32_t channel, const uint8_t *buffer, uint32_t *length)
Write to an EMUCOM channel.
Device: operation not supported.
struct jaylink_device * dev
Device instance.
JAYLINK_PRIV int transport_start_write_read(struct jaylink_device_handle *devh, size_t write_length, size_t read_length, bool has_command)
Start a write and read operation for a device.
Device: unspecified error.
JAYLINK_PRIV int transport_write(struct jaylink_device_handle *devh, const uint8_t *buffer, size_t length)
Write data to a device.
JAYLINK_PRIV void buffer_set_u32(uint8_t *buffer, uint32_t value, size_t offset)
Write a 32-bit unsigned integer value to a buffer.