1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-25 20:57:31 +02:00

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.
This commit is contained in:
Werner Almesberger 2012-06-21 16:17:47 -03:00
parent 58e0dda95d
commit 8eca4c99c7

View File

@ -23,33 +23,37 @@
#include "proto.h" #include "proto.h"
#include "dispatch.h" #include "dispatch.h"
#include "io.h"
/* @@@ keep it small for now - we're running out of RAM :-( */ /* @@@ keep it small for now - we're running out of RAM :-( */
//#define MAX_PACKET 120 /* <- MAX_PSDU -3 (hdr) -2 (CRC) */ //#define MAX_PACKET 120 /* <- MAX_PSDU -3 (hdr) -2 (CRC) */
#define MAX_PACKET 60 /* <- MAX_PSDU -3 (hdr) -2 (CRC) */ #define MAX_PACKET 50 /* <- MAX_PSDU -3 (hdr) -2 (CRC) */
static uint8_t buf[MAX_PACKET+3] = { SAMPLES, 0, 0 }; static uint8_t buf[MAX_PACKET+3] = { SAMPLES, 0, 0 };
static uint16_t *p; static uint16_t *p;
static bool expect_x;
static void handler(bool x, uint16_t v) static void handler(bool x, uint16_t v)
{ {
bool first;
uint32_t t; uint32_t t;
first = p == (uint16_t *) (buf+3); if (x != expect_x)
if (first && !x)
return; return;
t = uptime(); t = 0; //uptime_irq();
if (first) if (p == (uint16_t *) (buf+3))
*p++ = t >> 16; *p++ = t >> 16;
*p++ = t; *p++ = t;
*p++ = v; *p++ = v;
expect_x = !expect_x;
if (x) if (x)
return; return;
if ((uint8_t *) (p+4) <= buf+MAX_PACKET) if ((uint8_t *) (p+4) <= buf+MAX_PACKET)
return; return;
rf_send(buf, (uint8_t *) p-buf); rf_send(buf, (uint8_t *) p-buf);
buf[1]++;
p = (uint16_t *) (buf+3); p = (uint16_t *) (buf+3);
} }
@ -61,6 +65,7 @@ static bool sample_first(uint8_t limit, const uint8_t *payload)
cli(); cli();
sample = handler; sample = handler;
p = (uint16_t *) (buf+3); p = (uint16_t *) (buf+3);
expect_x = 1;
sei(); sei();
} else { } else {
cli(); cli();