mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-01 09:24:05 +02:00
fw/diag.c: fix and improve DIAG function
- we didn't send ACKs for the authentication packets - take multiple samples (4) - add 100 ms delay to let the battery voltage settle
This commit is contained in:
parent
f5b85a464e
commit
43686321a7
32
fw/diag.c
32
fw/diag.c
@ -16,6 +16,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
#define F_CPU 8000000UL
|
||||||
|
#include <util/delay.h>
|
||||||
|
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
@ -33,17 +35,22 @@ static bool failed;
|
|||||||
|
|
||||||
static void do_diag(void)
|
static void do_diag(void)
|
||||||
{
|
{
|
||||||
uint8_t pkg[7] = { DIAG_ACK, 0, 0, };
|
uint8_t pkg[3+4*DIAG_SAMPLES] = { DIAG_ACK, 4, 0, };
|
||||||
|
uint8_t *p = pkg+3;
|
||||||
uint16_t v;
|
uint16_t v;
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
cli();
|
cli();
|
||||||
set_line(localize_line(tmp[0], tmp[1]));
|
set_line(localize_line(tmp[0], tmp[1]));
|
||||||
v = measure_ref(1);
|
_delay_ms(100);
|
||||||
pkg[3] = v;
|
for (i = 0; i != DIAG_SAMPLES; i++) {
|
||||||
pkg[4] = v >> 8;
|
v = measure_ref(1);
|
||||||
v = measure_ref(0);
|
*p++ = v;
|
||||||
pkg[5] = v;
|
*p++ = v >> 8;
|
||||||
pkg[6] = v >> 8;
|
v = measure_ref(0);
|
||||||
|
*p++ = v;
|
||||||
|
*p++ = v >> 8;
|
||||||
|
}
|
||||||
set_line(localize_line(0, 0));
|
set_line(localize_line(0, 0));
|
||||||
sei();
|
sei();
|
||||||
rf_send(pkg, sizeof(pkg));
|
rf_send(pkg, sizeof(pkg));
|
||||||
@ -63,13 +70,12 @@ static bool diag_more(uint8_t seq, uint8_t limit, const uint8_t *payload)
|
|||||||
case 0:
|
case 0:
|
||||||
if (!hash_eq(payload, PAYLOAD, PAYLOAD))
|
if (!hash_eq(payload, PAYLOAD, PAYLOAD))
|
||||||
failed = 1;
|
failed = 1;
|
||||||
if (failed)
|
if (!failed)
|
||||||
return 0;
|
do_diag();
|
||||||
do_diag();
|
/* do_diag sends the ACK, not the dispatcher */
|
||||||
break;
|
return 0;
|
||||||
}
|
}
|
||||||
/* do_diag sends the ACK, not the dispatcher */
|
return 1;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +39,8 @@ enum pck_type {
|
|||||||
|
|
||||||
#define MAX_LINES 80
|
#define MAX_LINES 80
|
||||||
|
|
||||||
|
#define DIAG_SAMPLES 4
|
||||||
|
|
||||||
#define XA_HIGH_DEFAULT 850
|
#define XA_HIGH_DEFAULT 850
|
||||||
#define XA_LOW_DEFAULT 170
|
#define XA_LOW_DEFAULT 170
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user