|
16 | 16 | ## Private function |
17 | 17 | ## @end deftypefn |
18 | 18 |
|
19 | | -function [dataOut, errcode] = __recvResponse__ (obj, libid, cmd, timeout) |
| 19 | +function [dataOut, errcode] = __recvResponse__ (dev, libid, cmd, timeout, debug) |
20 | 20 |
|
21 | 21 | dataOut = []; |
22 | 22 | errcode = 0; |
23 | 23 |
|
24 | | - set(obj.connected, "timeout", timeout*10); |
| 24 | + set(dev, "timeout", timeout*10); |
25 | 25 |
|
26 | 26 | # TODO: current serial doesnt have a way to know if any data is awaiting |
27 | 27 | # so try read what we need first without waiting ? |
28 | 28 |
|
29 | 29 | # read in initial part |
30 | | - [tmpdataOut, tmpdataSize] = fread (obj.connected, 4); |
31 | | - if (obj.debug) |
| 30 | + [tmpdataOut, tmpdataSize] = fread (dev, 4); |
| 31 | + if (debug) |
32 | 32 | printf("<< "); printf("%d ", tmpdataOut); printf("\n"); |
33 | 33 | endif |
34 | 34 | if tmpdataSize < 4 |
|
39 | 39 | dataOut = "Malformed packet header"; |
40 | 40 | elseif (tmpdataOut(3) == 254) |
41 | 41 | # got a wait for response value - length is expected to be 0 |
42 | | - if (obj.debug) |
| 42 | + if (debug) |
43 | 43 | printf("* wait for response\n"); |
44 | 44 | endif |
45 | 45 |
|
46 | | - set(obj.connected, "timeout", -1); |
| 46 | + set(dev, "timeout", -1); |
47 | 47 |
|
48 | | - [tmpdataOut, tmpdataSize] = fread (obj.connected, 4); |
49 | | - if (obj.debug) |
| 48 | + [tmpdataOut, tmpdataSize] = fread (dev, 4); |
| 49 | + if (debug) |
50 | 50 | printf("<< "); printf("%d ", tmpdataOut); printf("\n"); |
51 | 51 | endif |
52 | 52 | if tmpdataSize < 4 |
|
61 | 61 | if(errcode == 0) |
62 | 62 | expectlen = tmpdataOut(4); |
63 | 63 | if expectlen > 0 |
64 | | - [dataOut, tmpdataSize] = fread (obj.connected, expectlen); |
65 | | - if (obj.debug) |
| 64 | + [dataOut, tmpdataSize] = fread (dev, expectlen); |
| 65 | + if (debug) |
66 | 66 | printf("<< "); printf("%d ", dataOut); printf("\n"); |
67 | 67 | endif |
68 | 68 | else |
|
81 | 81 | endif |
82 | 82 | elseif tmpdataOut(3) == 253 |
83 | 83 | # valid but was a debug message |
84 | | - if obj.debug |
| 84 | + if debug |
85 | 85 | s = char(dataOut); |
86 | 86 | printf("DEBUG: %s\n", s); |
87 | 87 | endif |
88 | 88 |
|
89 | | - [dataOut, errcode] = __recvResponse__ (obj, libid, cmd, timeout); |
| 89 | + [dataOut, errcode] = __recvResponse__ (dev, libid, cmd, timeout, debug); |
90 | 90 | else |
91 | 91 | errcode = 0; |
92 | 92 | # all is good |
|
0 commit comments