Date: | 2012-06-21 21:17:47 (8 years 7 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 8eca4c99c74a195272740ee944affd783734fff5 |
Message: | fw/sample.c: fix logic in handler() and filter incomplete samples An incomplete sample would be an X value followed by another X value, or Y followed by Y. Not entirely sure why this happens in the first place, but it does happen. |
Files: |
fw/sample.c (2 diffs) |
Change Details
fw/sample.c | ||
---|---|---|
23 | 23 | #include "proto.h" |
24 | 24 | #include "dispatch.h" |
25 | 25 | |
26 | #include "io.h" | |
26 | 27 | |
27 | 28 | /* @@@ keep it small for now - we're running out of RAM :-( */ |
28 | 29 | //#define MAX_PACKET 120 /* <- MAX_PSDU -3 (hdr) -2 (CRC) */ |
29 | #define MAX_PACKET 60 /* <- MAX_PSDU -3 (hdr) -2 (CRC) */ | |
30 | #define MAX_PACKET 50 /* <- MAX_PSDU -3 (hdr) -2 (CRC) */ | |
30 | 31 | |
31 | 32 | static uint8_t buf[MAX_PACKET+3] = { SAMPLES, 0, 0 }; |
32 | 33 | static uint16_t *p; |
34 | static bool expect_x; | |
33 | 35 | |
34 | 36 | |
35 | 37 | static void handler(bool x, uint16_t v) |
36 | 38 | { |
37 | bool first; | |
38 | 39 | uint32_t t; |
39 | 40 | |
40 | first = p == (uint16_t *) (buf+3); | |
41 | if (first && !x) | |
41 | if (x != expect_x) | |
42 | 42 | return; |
43 | t = uptime(); | |
44 | if (first) | |
43 | t = 0; //uptime_irq(); | |
44 | if (p == (uint16_t *) (buf+3)) | |
45 | 45 | *p++ = t >> 16; |
46 | 46 | *p++ = t; |
47 | 47 | *p++ = v; |
48 | expect_x = !expect_x; | |
49 | ||
48 | 50 | if (x) |
49 | 51 | return; |
50 | 52 | if ((uint8_t *) (p+4) <= buf+MAX_PACKET) |
51 | 53 | return; |
54 | ||
52 | 55 | rf_send(buf, (uint8_t *) p-buf); |
56 | buf[1]++; | |
53 | 57 | p = (uint16_t *) (buf+3); |
54 | 58 | } |
55 | 59 | |
... | ... | |
61 | 65 | cli(); |
62 | 66 | sample = handler; |
63 | 67 | p = (uint16_t *) (buf+3); |
68 | expect_x = 1; | |
64 | 69 | sei(); |
65 | 70 | } else { |
66 | 71 | cli(); |
Branches:
master
tornado-v1