39 #include "libsigrok-internal.h"
44 #define LOG_PREFIX "serial-victor"
47 #ifdef HAVE_SERIAL_COMM
56 #define VICTOR_DMM_PACKET_LENGTH 14
58 static const struct vid_pid_item vid_pid_items_victor[] = {
64 static uint8_t bit_reverse(uint8_t b)
66 static const uint8_t rev_nibble[] = {
67 0x00, 0x08, 0x04, 0x0c, 0x02, 0x0a, 0x06, 0x0e,
68 0x01, 0x09, 0x05, 0x0d, 0x03, 0x0b, 0x07, 0x0f,
71 return (rev_nibble[(b >> 4) & 0xf]) |
72 (rev_nibble[b & 0xf] << 4);
83 static int victor_unobfuscate(uint8_t *rx_buf,
size_t rx_len,
86 static const uint8_t obfuscation[VICTOR_DMM_PACKET_LENGTH] = {
87 'j',
'o',
'd',
'e',
'n',
'x',
'u',
'n',
'i',
'c',
'k',
'x',
'i',
'a',
89 static const uint8_t shuffle[VICTOR_DMM_PACKET_LENGTH] = {
90 6, 13, 5, 11, 2, 7, 9, 8, 3, 10, 12, 0, 4, 1
99 sr_spew(
"Received %zu bytes: %s.", rx_len, txt->str);
104 if (rx_len != VICTOR_DMM_PACKET_LENGTH) {
105 memcpy(ret_buf, rx_buf, rx_len);
111 for (idx = 0; is_zero && idx < VICTOR_DMM_PACKET_LENGTH; idx++) {
116 sr_dbg(
"Received all zeroes packet, discarding.");
124 for (idx = 0; idx < VICTOR_DMM_PACKET_LENGTH; idx++) {
125 to_idx = VICTOR_DMM_PACKET_LENGTH - 1 - shuffle[idx];
126 ret_buf[to_idx] = bit_reverse(rx_buf[idx] - obfuscation[idx]);
131 sr_spew(
"Deobfuscated: %s.", txt->str);
142 static int victor_read_bytes(
struct sr_serial_dev_inst *serial,
143 uint8_t *data,
int space,
unsigned int timeout)
145 uint8_t buf[VICTOR_DMM_PACKET_LENGTH];
148 if (space !=
sizeof(buf))
158 return victor_unobfuscate(buf, rc, data);
162 static int victor_write_bytes(
struct sr_serial_dev_inst *serial,
163 const uint8_t *data,
int size)
171 static struct ser_hid_chip_functions chip_victor = {
172 .chipname =
"victor",
173 .chipdesc =
"Victor DMM scrambler",
174 .vid_pid_items = vid_pid_items_victor,
175 .max_bytes_per_request = VICTOR_DMM_PACKET_LENGTH,
180 .set_params = std_dummy_set_params,
181 .read_bytes = victor_read_bytes,
182 .write_bytes = victor_write_bytes,
184 SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_victor = &chip_victor;
188 SR_PRIV struct ser_hid_chip_functions *ser_hid_chip_funcs_victor = NULL;
Output very noisy debug messages.
The public libsigrok header file to be used by frontends.
SR_PRIV GString * sr_hexdump_new(const uint8_t *data, const size_t len)
Convert a sequence of bytes to its textual representation ("hex dump").
SR_PRIV void sr_hexdump_free(GString *s)
Free a hex dump text that was created by sr_hexdump_new().
int sr_log_loglevel_get(void)
Get the libsigrok loglevel.
SR_PRIV int ser_hid_hidapi_get_data(struct sr_serial_dev_inst *serial, uint8_t ep, uint8_t *data, size_t len, int timeout)