mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-01 09:09:23 +02:00
fw/: add acceleration sensor sample protocol (untested)
This commit is contained in:
parent
7a0bc4cb9c
commit
f0e79b8dcc
26
doc/PROTOCOL
26
doc/PROTOCOL
@ -31,6 +31,12 @@ Protocol
|
||||
|
||||
9 n 0 Parameter ACK
|
||||
|
||||
10 0 0 Sample (64 bytes payload)
|
||||
|
||||
11 0 0 Sample ACK
|
||||
|
||||
13 n 0 Samples
|
||||
|
||||
Unlock, firmware, image, and parameter packets all have a fixed-size
|
||||
64 bytes payload. Pings and acknowledgements have no payload. Pongs
|
||||
may have a variable-size payload.
|
||||
@ -45,3 +51,23 @@ Image format
|
||||
|
||||
Two bytes per line. LSB of first byte is LED A1, MSB of last byte is B8.
|
||||
Unused lines must be set to zero.
|
||||
|
||||
|
||||
Sample format
|
||||
=============
|
||||
|
||||
Each sample packet has the following structure:
|
||||
|
||||
Offset Size
|
||||
0 2 Absolute time of X sample, high 16 bits
|
||||
2 8*N N samples
|
||||
|
||||
Where each sample is
|
||||
|
||||
Offset Size
|
||||
0 2 Absolute time of X sample, lower 16 bits
|
||||
2 2 X sample (0-1023)
|
||||
4 2 Absolute time of Y sample, lower 16 bits
|
||||
6 2 Y sample (0-1023)
|
||||
|
||||
Byte order TBD. (Defined by avr-gcc)
|
||||
|
@ -30,7 +30,7 @@ OBJCOPY = $(AVR_PREFIX)objcopy
|
||||
#OBJDUMP = $(AVR_PREFIX)objdump
|
||||
SIZE = $(AVR_PREFIX)size
|
||||
|
||||
OBJS = $(NAME).o accel.o dispatch.o hash.o image.o reset.o sweep.o \
|
||||
OBJS = $(NAME).o accel.o dispatch.o hash.o image.o reset.o sample.o sweep.o \
|
||||
$(COMMON_OBJS)
|
||||
BOOT_OBJS = boot.o flash.o fw.o $(COMMON_OBJS)
|
||||
COMMON_OBJS = rf.o spi.o
|
||||
|
@ -33,6 +33,7 @@ static struct sweep sweep = {
|
||||
static const struct handler *protos[] = {
|
||||
&image_handler,
|
||||
&reset_handler,
|
||||
&sample_handler,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -28,6 +28,7 @@ struct handler {
|
||||
|
||||
extern struct handler image_handler;
|
||||
extern struct handler reset_handler;
|
||||
extern struct handler sample_handler;
|
||||
|
||||
|
||||
bool dispatch(const uint8_t *buf, uint8_t len, const struct handler **protos);
|
||||
|
@ -28,6 +28,9 @@ enum pck_type {
|
||||
IMAGE_ACK = 7, /* image upload acknowledgement */
|
||||
PARAM = 8, /* parameter upload */
|
||||
PARAM_ACK = 9, /* parameter upload acknowledgement */
|
||||
SAMPLE = 10, /* start/stop sampling */
|
||||
SAMPLE_ACK = 11, /* start/stop sampling acknowledgement */
|
||||
SAMPLES = 13, /* samples */
|
||||
};
|
||||
|
||||
|
||||
|
82
fw/sample.c
Normal file
82
fw/sample.c
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* fw/sample.c - Acceleration sensor sample protocol
|
||||
*
|
||||
* Written 2012 by Werner Almesberger
|
||||
* Copyright 2012 Werner Almesberger
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#include "rf.h"
|
||||
#include "sweep.h"
|
||||
#include "accel.h"
|
||||
#include "proto.h"
|
||||
#include "dispatch.h"
|
||||
|
||||
|
||||
#define MAX_PACKET 120 /* <- MAX_PSDU -3 (hdr) -2 (CRC) */
|
||||
|
||||
static uint8_t buf[MAX_PACKET+3] = { SAMPLES, 0, 0 };
|
||||
static uint16_t *p;
|
||||
|
||||
|
||||
static void handler(bool x, uint16_t v)
|
||||
{
|
||||
bool first;
|
||||
uint32_t t;
|
||||
|
||||
first = p == (uint16_t *) (buf+3);
|
||||
if (first && !x)
|
||||
return;
|
||||
t = uptime();
|
||||
if (first)
|
||||
*p++ = t >> 16;
|
||||
*p++ = t;
|
||||
*p++ = v;
|
||||
if (x)
|
||||
return;
|
||||
if ((uint8_t *) (p+4) <= buf+MAX_PACKET)
|
||||
return;
|
||||
rf_send(buf, (uint8_t *) p-buf);
|
||||
p = (uint16_t *) (buf+3);
|
||||
}
|
||||
|
||||
|
||||
static bool sample_first(uint8_t limit, const uint8_t *payload)
|
||||
{
|
||||
if (payload[0]) {
|
||||
buf[1] = 0;
|
||||
cli();
|
||||
sample = handler;
|
||||
p = (uint16_t *) (buf+3);
|
||||
sei();
|
||||
} else {
|
||||
cli();
|
||||
sample = NULL;
|
||||
sei();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static bool sample_more(uint8_t seq, uint8_t limit, const uint8_t *payload)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct handler sample_handler = {
|
||||
.type = SAMPLE,
|
||||
.first = sample_first,
|
||||
.more = sample_more,
|
||||
};
|
Loading…
Reference in New Issue
Block a user