]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2016 danselmi <da@da> | |
5 | * | |
6 | * This program is free software: you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation, either version 3 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include <config.h> | |
21 | ||
22 | #ifdef _WIN32 | |
23 | #define _WIN32_WINNT 0x0501 | |
24 | #include <winsock2.h> | |
25 | #include <ws2tcpip.h> | |
26 | #endif | |
27 | ||
28 | #include <string.h> | |
29 | #include <unistd.h> | |
30 | ||
31 | #ifndef _WIN32 | |
32 | #include <sys/socket.h> | |
33 | #include <netinet/in.h> | |
34 | #include <arpa/inet.h> | |
35 | #include <netdb.h> | |
36 | #endif | |
37 | ||
38 | #include <errno.h> | |
39 | #include "protocol.h" | |
40 | ||
41 | #include <sys/ioctl.h> | |
42 | ||
43 | #define BUFFER_SIZE 4 | |
44 | ||
45 | /* Top-level command opcodes */ | |
46 | #define CMD_SET_TRIGGER 0x00 | |
47 | #define CMD_CFG_TRIGGER 0xF0 | |
48 | #define CMD_CFG_LA 0x0F | |
49 | #define CMD_START 0xFE | |
50 | #define CMD_RESET 0xEE | |
51 | ||
52 | #define CMD_GET_BUS_WIDTHS 0xAA | |
53 | #define CMD_GET_LA_ID 0xBB | |
54 | #define CMD_ESCAPE 0x55 | |
55 | ||
56 | /* Trigger subfunction command opcodes */ | |
57 | #define CMD_TRIG_MASKS 0xF1 | |
58 | #define CMD_TRIG_MASK 0xF3 | |
59 | #define CMD_TRIG_VALUE 0xF7 | |
60 | ||
61 | #define CMD_TRIG_MASKS_LAST 0xF9 | |
62 | #define CMD_TRIG_MASK_LAST 0xFB | |
63 | #define CMD_TRIG_VALUE_LAST 0xFF | |
64 | ||
65 | #define CMD_TRIG_SELECT_EDGE_MASK 0xF5 | |
66 | #define CMD_TRIG_SET_EDGE_MASK 0xF6 | |
67 | ||
68 | /* LA subfunction command opcodes */ | |
69 | #define CMD_LA_DELAY 0x1F | |
70 | ||
71 | SR_PRIV int data_available(struct ipdbg_org_la_tcp *tcp) | |
72 | { | |
73 | #ifdef __WIN32__ | |
74 | ioctlsocket(tcp->socket, FIONREAD, &bytes_available); | |
75 | #else | |
76 | int status; | |
77 | ||
78 | if (ioctl(tcp->socket, FIONREAD, &status) < 0) { // TIOCMGET | |
79 | sr_err("FIONREAD failed: %s\n", strerror(errno)); | |
80 | return 0; | |
81 | } | |
82 | ||
83 | return (status < 1) ? 0 : 1; | |
84 | #endif // __WIN32__ | |
85 | } | |
86 | ||
87 | SR_PRIV struct ipdbg_org_la_tcp *ipdbg_org_la_tcp_new(void) | |
88 | { | |
89 | struct ipdbg_org_la_tcp *tcp; | |
90 | ||
91 | tcp = g_malloc0(sizeof(struct ipdbg_org_la_tcp)); | |
92 | ||
93 | tcp->address = NULL; | |
94 | tcp->port = NULL; | |
95 | tcp->socket = -1; | |
96 | ||
97 | return tcp; | |
98 | } | |
99 | ||
100 | SR_PRIV void ipdbg_org_la_tcp_free(struct ipdbg_org_la_tcp *tcp) | |
101 | { | |
102 | g_free(tcp->address); | |
103 | g_free(tcp->port); | |
104 | } | |
105 | ||
106 | SR_PRIV int ipdbg_org_la_tcp_open(struct ipdbg_org_la_tcp *tcp) | |
107 | { | |
108 | struct addrinfo hints; | |
109 | struct addrinfo *results, *res; | |
110 | int err; | |
111 | ||
112 | memset(&hints, 0, sizeof(hints)); | |
113 | hints.ai_family = AF_UNSPEC; | |
114 | hints.ai_socktype = SOCK_STREAM; | |
115 | hints.ai_protocol = IPPROTO_TCP; | |
116 | ||
117 | err = getaddrinfo(tcp->address, tcp->port, &hints, &results); | |
118 | ||
119 | if (err) { | |
120 | sr_err("Address lookup failed: %s:%s: %s", tcp->address, | |
121 | tcp->port, gai_strerror(err)); | |
122 | return SR_ERR; | |
123 | } | |
124 | ||
125 | for (res = results; res; res = res->ai_next) { | |
126 | if ((tcp->socket = socket(res->ai_family, res->ai_socktype, | |
127 | res->ai_protocol)) < 0) | |
128 | continue; | |
129 | if (connect(tcp->socket, res->ai_addr, res->ai_addrlen) != 0) { | |
130 | close(tcp->socket); | |
131 | tcp->socket = -1; | |
132 | continue; | |
133 | } | |
134 | break; | |
135 | } | |
136 | ||
137 | freeaddrinfo(results); | |
138 | ||
139 | if (tcp->socket < 0) { | |
140 | sr_err("Failed to connect to %s:%s: %s", tcp->address, tcp->port, | |
141 | g_strerror(errno)); | |
142 | return SR_ERR; | |
143 | } | |
144 | ||
145 | return SR_OK; | |
146 | } | |
147 | ||
148 | SR_PRIV int ipdbg_org_la_tcp_close(struct ipdbg_org_la_tcp *tcp) | |
149 | { | |
150 | int ret = SR_OK; | |
151 | ||
152 | if (close(tcp->socket) < 0) | |
153 | ret = SR_ERR; | |
154 | ||
155 | tcp->socket = -1; | |
156 | ||
157 | return ret; | |
158 | } | |
159 | ||
160 | SR_PRIV int ipdbg_org_la_tcp_send(struct ipdbg_org_la_tcp *tcp, | |
161 | const uint8_t *buf, size_t len) | |
162 | { | |
163 | int out; | |
164 | out = send(tcp->socket, (char*)buf, len, 0); | |
165 | ||
166 | if (out < 0) { | |
167 | sr_err("Send error: %s", g_strerror(errno)); | |
168 | return SR_ERR; | |
169 | } | |
170 | ||
171 | if (out < (int)len) | |
172 | sr_dbg("Only sent %d/%d bytes of data.", out, (int)len); | |
173 | ||
174 | return SR_OK; | |
175 | } | |
176 | ||
177 | SR_PRIV int ipdbg_org_la_tcp_receive_blocking(struct ipdbg_org_la_tcp *tcp, | |
178 | uint8_t *buf, int bufsize) | |
179 | { | |
180 | int received = 0; | |
181 | ||
182 | while (received < bufsize) { | |
183 | if (ipdbg_org_la_tcp_receive(tcp, buf) > 0) { | |
184 | buf++; | |
185 | received++; | |
186 | } | |
187 | } | |
188 | ||
189 | return received; | |
190 | } | |
191 | ||
192 | SR_PRIV int ipdbg_org_la_tcp_receive(struct ipdbg_org_la_tcp *tcp, | |
193 | uint8_t *buf) | |
194 | { | |
195 | int received = 0; | |
196 | ||
197 | if (data_available(tcp)) { | |
198 | while (received < 1) { | |
199 | int len = recv(tcp->socket, buf, 1, 0); | |
200 | ||
201 | if (len < 0) { | |
202 | sr_err("Receive error: %s", g_strerror(errno)); | |
203 | return SR_ERR; | |
204 | } else | |
205 | received += len; | |
206 | } | |
207 | ||
208 | return received; | |
209 | } else | |
210 | return -1; | |
211 | } | |
212 | ||
213 | SR_PRIV int ipdbg_org_la_convert_trigger(const struct sr_dev_inst *sdi) | |
214 | { | |
215 | struct ipdbg_org_la_dev_context *devc; | |
216 | struct sr_trigger *trigger; | |
217 | struct sr_trigger_stage *stage; | |
218 | struct sr_trigger_match *match; | |
219 | const GSList *l, *m; | |
220 | ||
221 | devc = sdi->priv; | |
222 | ||
223 | devc->num_stages = 0; | |
224 | devc->num_transfers = 0; | |
225 | devc->raw_sample_buf = NULL; | |
226 | ||
227 | for (uint64_t i = 0; i < devc->DATA_WIDTH_BYTES; i++) { | |
228 | devc->trigger_mask[i] = 0; | |
229 | devc->trigger_value[i] = 0; | |
230 | devc->trigger_mask_last[i] = 0; | |
231 | devc->trigger_value_last[i] = 0; | |
232 | devc->trigger_edge_mask[i] = 0; | |
233 | } | |
234 | ||
235 | if (!(trigger = sr_session_trigger_get(sdi->session))) | |
236 | return SR_OK; | |
237 | ||
238 | for (l = trigger->stages; l; l = l->next) { | |
239 | stage = l->data; | |
240 | for (m = stage->matches; m; m = m->next) { | |
241 | match = m->data; | |
242 | int byte_idx = match->channel->index / 8; | |
243 | uint8_t match_bit = 1 << (match->channel->index % 8); | |
244 | ||
245 | if (!match->channel->enabled) | |
246 | /* Ignore disabled channels with a trigger. */ | |
247 | continue; | |
248 | ||
249 | if (match->match == SR_TRIGGER_ONE) { | |
250 | devc->trigger_value[byte_idx] |= match_bit; | |
251 | devc->trigger_mask[byte_idx] |= match_bit; | |
252 | devc->trigger_mask_last[byte_idx] &= ~match_bit; | |
253 | devc->trigger_edge_mask[byte_idx] &= ~match_bit; | |
254 | } else if (match->match == SR_TRIGGER_ZERO) { | |
255 | devc->trigger_value[byte_idx] &= ~match_bit; | |
256 | devc->trigger_mask[byte_idx] |= match_bit; | |
257 | devc->trigger_mask_last[byte_idx] &= ~match_bit; | |
258 | devc->trigger_edge_mask[byte_idx] &= ~match_bit; | |
259 | } else if (match->match == SR_TRIGGER_RISING) { | |
260 | devc->trigger_value[byte_idx] |= match_bit; | |
261 | devc->trigger_value_last[byte_idx] &= | |
262 | ~match_bit; | |
263 | devc->trigger_mask[byte_idx] |= match_bit; | |
264 | devc->trigger_mask_last[byte_idx] |= match_bit; | |
265 | devc->trigger_edge_mask[byte_idx] &= ~match_bit; | |
266 | } else if (match->match == SR_TRIGGER_FALLING) { | |
267 | devc->trigger_value[byte_idx] &= ~match_bit; | |
268 | devc->trigger_value_last[byte_idx] |= match_bit; | |
269 | devc->trigger_mask[byte_idx] |= match_bit; | |
270 | devc->trigger_mask_last[byte_idx] |= match_bit; | |
271 | devc->trigger_edge_mask[byte_idx] &= ~match_bit; | |
272 | } else if (match->match == SR_TRIGGER_EDGE) { | |
273 | devc->trigger_mask[byte_idx] &= ~match_bit; | |
274 | devc->trigger_mask_last[byte_idx] &= ~match_bit; | |
275 | devc->trigger_edge_mask[byte_idx] |= match_bit; | |
276 | } | |
277 | } | |
278 | } | |
279 | ||
280 | return SR_OK; | |
281 | } | |
282 | ||
283 | SR_PRIV int ipdbg_org_la_receive_data(int fd, int revents, void *cb_data) | |
284 | { | |
285 | const struct sr_dev_inst *sdi; | |
286 | struct ipdbg_org_la_dev_context *devc; | |
287 | ||
288 | (void)fd; | |
289 | (void)revents; | |
290 | ||
291 | sdi = (const struct sr_dev_inst *)cb_data; | |
292 | if (!sdi) | |
293 | return FALSE; | |
294 | ||
295 | if (!(devc = sdi->priv)) | |
296 | return FALSE; | |
297 | ||
298 | struct ipdbg_org_la_tcp *tcp = sdi->conn; | |
299 | struct sr_datafeed_packet packet; | |
300 | struct sr_datafeed_logic logic; | |
301 | ||
302 | if (!devc->raw_sample_buf) { | |
303 | devc->raw_sample_buf = | |
304 | g_try_malloc(devc->limit_samples * devc->DATA_WIDTH_BYTES); | |
305 | if (!devc->raw_sample_buf) { | |
306 | sr_warn("Sample buffer malloc failed."); | |
307 | return FALSE; | |
308 | } | |
309 | } | |
310 | ||
311 | if (devc->num_transfers < | |
312 | (devc->limit_samples_max * devc->DATA_WIDTH_BYTES)) { | |
313 | uint8_t byte; | |
314 | ||
315 | if (ipdbg_org_la_tcp_receive(tcp, &byte) == 1) { | |
316 | if (devc->num_transfers < | |
317 | (devc->limit_samples * devc->DATA_WIDTH_BYTES)) | |
318 | devc->raw_sample_buf[devc->num_transfers] = byte; | |
319 | ||
320 | devc->num_transfers++; | |
321 | } | |
322 | } else { | |
323 | if (devc->delay_value > 0) { | |
324 | /* There are pre-trigger samples, send those first. */ | |
325 | packet.type = SR_DF_LOGIC; | |
326 | packet.payload = &logic; | |
327 | logic.length = devc->delay_value * devc->DATA_WIDTH_BYTES; | |
328 | logic.unitsize = devc->DATA_WIDTH_BYTES; | |
329 | logic.data = devc->raw_sample_buf; | |
330 | sr_session_send(cb_data, &packet); | |
331 | } | |
332 | ||
333 | /* Send the trigger. */ | |
334 | packet.type = SR_DF_TRIGGER; | |
335 | sr_session_send(cb_data, &packet); | |
336 | ||
337 | /* Send post-trigger samples. */ | |
338 | packet.type = SR_DF_LOGIC; | |
339 | packet.payload = &logic; | |
340 | logic.length = (devc->limit_samples - devc->delay_value) * | |
341 | devc->DATA_WIDTH_BYTES; | |
342 | logic.unitsize = devc->DATA_WIDTH_BYTES; | |
343 | logic.data = devc->raw_sample_buf + | |
344 | (devc->delay_value * devc->DATA_WIDTH_BYTES); | |
345 | sr_session_send(cb_data, &packet); | |
346 | ||
347 | g_free(devc->raw_sample_buf); | |
348 | devc->raw_sample_buf = NULL; | |
349 | ||
350 | ipdbg_org_la_abort_acquisition(sdi); | |
351 | } | |
352 | ||
353 | return TRUE; | |
354 | } | |
355 | ||
356 | SR_PRIV int ipdbg_org_la_send_delay(struct ipdbg_org_la_dev_context *devc, | |
357 | struct ipdbg_org_la_tcp *tcp) | |
358 | { | |
359 | devc->delay_value = (devc->limit_samples / 100.0) * devc->capture_ratio; | |
360 | ||
361 | uint8_t buf; | |
362 | buf = CMD_CFG_LA; | |
363 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
364 | buf = CMD_LA_DELAY; | |
365 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
366 | ||
367 | uint8_t delay_buf[4] = { devc->delay_value & 0x000000ff, | |
368 | (devc->delay_value >> 8) & 0x000000ff, | |
369 | (devc->delay_value >> 16) & 0x000000ff, | |
370 | (devc->delay_value >> 24) & 0x000000ff | |
371 | }; | |
372 | ||
373 | for (uint64_t i = 0; i < devc->ADDR_WIDTH_BYTES; i++) | |
374 | send_escaping(tcp, &(delay_buf[devc->ADDR_WIDTH_BYTES - 1 - i]), 1); | |
375 | ||
376 | return SR_OK; | |
377 | } | |
378 | ||
379 | SR_PRIV int ipdbg_org_la_send_trigger(struct ipdbg_org_la_dev_context *devc, | |
380 | struct ipdbg_org_la_tcp *tcp) | |
381 | { | |
382 | uint8_t buf; | |
383 | ||
384 | /* Mask */ | |
385 | buf = CMD_CFG_TRIGGER; | |
386 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
387 | buf = CMD_TRIG_MASKS; | |
388 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
389 | buf = CMD_TRIG_MASK; | |
390 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
391 | ||
392 | for (size_t i = 0; i < devc->DATA_WIDTH_BYTES; i++) | |
393 | send_escaping(tcp, | |
394 | devc->trigger_mask + devc->DATA_WIDTH_BYTES - 1 - i, 1); | |
395 | ||
396 | /* Value */ | |
397 | buf = CMD_CFG_TRIGGER; | |
398 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
399 | buf = CMD_TRIG_MASKS; | |
400 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
401 | buf = CMD_TRIG_VALUE; | |
402 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
403 | ||
404 | for (size_t i = 0; i < devc->DATA_WIDTH_BYTES; i++) | |
405 | send_escaping(tcp, | |
406 | devc->trigger_value + devc->DATA_WIDTH_BYTES - 1 - i, 1); | |
407 | ||
408 | /* Mask_last */ | |
409 | buf = CMD_CFG_TRIGGER; | |
410 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
411 | buf = CMD_TRIG_MASKS_LAST; | |
412 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
413 | buf = CMD_TRIG_MASK_LAST; | |
414 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
415 | ||
416 | for (size_t i = 0; i < devc->DATA_WIDTH_BYTES; i++) | |
417 | send_escaping(tcp, | |
418 | devc->trigger_mask_last + devc->DATA_WIDTH_BYTES - 1 - i, 1); | |
419 | ||
420 | /* Value_last */ | |
421 | buf = CMD_CFG_TRIGGER; | |
422 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
423 | buf = CMD_TRIG_MASKS_LAST; | |
424 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
425 | buf = CMD_TRIG_VALUE_LAST; | |
426 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
427 | ||
428 | for (size_t i = 0; i < devc->DATA_WIDTH_BYTES; i++) | |
429 | send_escaping(tcp, | |
430 | devc->trigger_value_last + devc->DATA_WIDTH_BYTES - 1 - i, 1); | |
431 | ||
432 | /* Edge_mask */ | |
433 | buf = CMD_CFG_TRIGGER; | |
434 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
435 | buf = CMD_TRIG_SELECT_EDGE_MASK; | |
436 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
437 | buf = CMD_TRIG_SET_EDGE_MASK; | |
438 | ipdbg_org_la_tcp_send(tcp, &buf, 1); | |
439 | ||
440 | for (size_t i = 0; i < devc->DATA_WIDTH_BYTES; i++) | |
441 | send_escaping(tcp, | |
442 | devc->trigger_edge_mask + devc->DATA_WIDTH_BYTES - 1 - i, 1); | |
443 | ||
444 | return SR_OK; | |
445 | } | |
446 | ||
447 | SR_PRIV int send_escaping(struct ipdbg_org_la_tcp *tcp, uint8_t *dataToSend, | |
448 | uint32_t length) | |
449 | { | |
450 | uint8_t escape = CMD_ESCAPE; | |
451 | ||
452 | while (length--) { | |
453 | uint8_t payload = *dataToSend++; | |
454 | ||
455 | if (payload == (uint8_t) CMD_RESET) | |
456 | if (ipdbg_org_la_tcp_send(tcp, &escape, 1) != SR_OK) | |
457 | sr_warn("Couldn't send escape"); | |
458 | ||
459 | if (payload == (uint8_t) CMD_ESCAPE) | |
460 | if (ipdbg_org_la_tcp_send(tcp, &escape, 1) != SR_OK) | |
461 | sr_warn("Couldn't send escape"); | |
462 | ||
463 | if (ipdbg_org_la_tcp_send(tcp, &payload, 1) != SR_OK) | |
464 | sr_warn("Couldn't send data"); | |
465 | } | |
466 | ||
467 | return SR_OK; | |
468 | } | |
469 | ||
470 | SR_PRIV void ipdbg_org_la_get_addrwidth_and_datawidth( | |
471 | struct ipdbg_org_la_tcp *tcp, struct ipdbg_org_la_dev_context *devc) | |
472 | { | |
473 | uint8_t buf[8]; | |
474 | uint8_t read_cmd = CMD_GET_BUS_WIDTHS; | |
475 | ||
476 | if (ipdbg_org_la_tcp_send(tcp, &read_cmd, 1) != SR_OK) | |
477 | sr_warn("Can't send read command"); | |
478 | ||
479 | if (ipdbg_org_la_tcp_receive_blocking(tcp, buf, 8) != 8) | |
480 | sr_warn("Can't get address and data width from device"); | |
481 | ||
482 | devc->DATA_WIDTH = buf[0] & 0x000000FF; | |
483 | devc->DATA_WIDTH |= (buf[1] << 8) & 0x0000FF00; | |
484 | devc->DATA_WIDTH |= (buf[2] << 16) & 0x00FF0000; | |
485 | devc->DATA_WIDTH |= (buf[3] << 24) & 0xFF000000; | |
486 | ||
487 | devc->ADDR_WIDTH = buf[4] & 0x000000FF; | |
488 | devc->ADDR_WIDTH |= (buf[5] << 8) & 0x0000FF00; | |
489 | devc->ADDR_WIDTH |= (buf[6] << 16) & 0x00FF0000; | |
490 | devc->ADDR_WIDTH |= (buf[7] << 24) & 0xFF000000; | |
491 | ||
492 | uint8_t HOST_WORD_SIZE = 8; | |
493 | ||
494 | devc->DATA_WIDTH_BYTES = | |
495 | (devc->DATA_WIDTH + HOST_WORD_SIZE - 1) / HOST_WORD_SIZE; | |
496 | devc->ADDR_WIDTH_BYTES = | |
497 | (devc->ADDR_WIDTH + HOST_WORD_SIZE - 1) / HOST_WORD_SIZE; | |
498 | ||
499 | devc->limit_samples_max = (0x01 << devc->ADDR_WIDTH); | |
500 | devc->limit_samples = devc->limit_samples_max; | |
501 | ||
502 | devc->trigger_mask = g_malloc0(devc->DATA_WIDTH_BYTES); | |
503 | devc->trigger_value = g_malloc0(devc->DATA_WIDTH_BYTES); | |
504 | devc->trigger_mask_last = g_malloc0(devc->DATA_WIDTH_BYTES); | |
505 | devc->trigger_value_last = g_malloc0(devc->DATA_WIDTH_BYTES); | |
506 | devc->trigger_edge_mask = g_malloc0(devc->DATA_WIDTH_BYTES); | |
507 | } | |
508 | ||
509 | SR_PRIV struct ipdbg_org_la_dev_context *ipdbg_org_la_dev_new(void) | |
510 | { | |
511 | struct ipdbg_org_la_dev_context *devc; | |
512 | ||
513 | devc = g_malloc0(sizeof(struct ipdbg_org_la_dev_context)); | |
514 | devc->capture_ratio = 50; | |
515 | ||
516 | return devc; | |
517 | } | |
518 | ||
519 | SR_PRIV int ipdbg_org_la_send_reset(struct ipdbg_org_la_tcp *tcp) | |
520 | { | |
521 | uint8_t buf = CMD_RESET; | |
522 | if (ipdbg_org_la_tcp_send(tcp, &buf, 1) != SR_OK) | |
523 | sr_warn("Couldn't send reset"); | |
524 | ||
525 | return SR_OK; | |
526 | } | |
527 | ||
528 | SR_PRIV int ipdbg_org_la_request_id(struct ipdbg_org_la_tcp *tcp) | |
529 | { | |
530 | uint8_t buf = CMD_GET_LA_ID; | |
531 | if (ipdbg_org_la_tcp_send(tcp, &buf, 1) != SR_OK) | |
532 | sr_warn("Couldn't send ID request"); | |
533 | ||
534 | char id[4]; | |
535 | if (ipdbg_org_la_tcp_receive_blocking(tcp, (uint8_t *) id, 4) != 4) | |
536 | sr_warn("Couldn't read device ID"); | |
537 | ||
538 | if (strncmp(id, "IDBG", 4)) { | |
539 | sr_err("Invalid device ID: expected 'IDBG', got '%c%c%c%c'.", | |
540 | id[0], id[1], id[2], id[3]); | |
541 | return SR_ERR; | |
542 | } | |
543 | ||
544 | return SR_OK; | |
545 | } | |
546 | ||
547 | SR_PRIV void ipdbg_org_la_abort_acquisition(const struct sr_dev_inst *sdi) | |
548 | { | |
549 | struct ipdbg_org_la_tcp *tcp = sdi->conn; | |
550 | ||
551 | sr_session_source_remove(sdi->session, tcp->socket); | |
552 | ||
553 | std_session_send_df_end(sdi); | |
554 | } | |
555 | ||
556 | SR_PRIV int ipdbg_org_la_send_start(struct ipdbg_org_la_tcp *tcp) | |
557 | { | |
558 | uint8_t buf = CMD_START; | |
559 | ||
560 | if (ipdbg_org_la_tcp_send(tcp, &buf, 1) != SR_OK) | |
561 | sr_warn("Couldn't send start"); | |
562 | ||
563 | return SR_OK; | |
564 | } |