1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-25 19:51:52 +02:00

tools/: add sampling mode (-S) with graphical output

This commit is contained in:
Werner Almesberger 2012-06-21 16:21:56 -03:00
parent 734e33cd19
commit 4eb1065dd7
4 changed files with 187 additions and 10 deletions

View File

@ -15,10 +15,12 @@ MAIN = antorcha
CFLAGS = -g -I../fw -I../../ben-wpan/tools/include \
-I../../ben-wpan/atusb/fw/include \
-Wall
LDLIBS = -L../../ben-wpan/tools/lib -latrf -lusb
-Wall \
$(shell sdl-config --cflags)
LDLIBS = -L../../ben-wpan/tools/lib -latrf -lusb \
$(shell sdl-config --libs) -lSDL_gfx
OBJS = antorcha.o hash.o
OBJS = antorcha.o hash.o plot.o
.PHONY: all update ping off

View File

@ -22,9 +22,11 @@
#include <atrf.h>
#include <misctxrx.h>
#include <hash.h>
#include <proto.h>
#include "hash.h"
#include "plot.h"
static int verbose = 1;
static int debug = 0;
@ -275,6 +277,52 @@ static void image(struct atrf_dsc *dsc, const char *name)
}
/* ----- Samples ----------------------------------------------------------- */
static void samples(struct atrf_dsc *dsc)
{
uint8_t buf[MAX_PSDU] = { 0, };
int got;
uint8_t *s;
int x, y;
buf[0] = 1;
packet(dsc, SAMPLE, 0, 0, buf, PAYLOAD);
plot_init();
while (1) {
got = rf_recv(dsc, buf, sizeof(buf));
if (got <= 3)
continue;
if (buf[0] != SAMPLES)
continue;
if (debug > 1) {
int i;
for (i = 0; i != got; i++)
fprintf(stderr, " %02x", buf[i]);
fprintf(stderr, "\n");
}
if (debug)
fprintf(stderr, "%d:", got);
s = buf+3+2;
while (s < buf+got-2) {
s += 2;
x = *s++;
x |= *s++ << 8;
s += 2;
y = *s++;
y |= *s++ << 8;
if (debug)
fprintf(stderr, "\t%d %d\n", x, y);
plot(x, y);
}
}
buf[0] = 0;
packet(dsc, SAMPLE, 0, 0, buf, PAYLOAD);
}
/* ----- Command-line processing ------------------------------------------- */
@ -284,7 +332,8 @@ static void usage(const char *name)
"usage: %s [-d] image_file\n"
"%6s %s [-d] -F firmware_file\n"
"%6s %s [-d] -P\n"
, name, "", name, "", name);
"%6s %s [-d] -S\n"
, name, "", name, "", name, "", name);
exit(1);
}
@ -292,14 +341,14 @@ static void usage(const char *name)
int main(int argc, char **argv)
{
const char *fw = NULL;
int do_ping = 0;
int do_ping = 0, do_sample = 0;
struct atrf_dsc *dsc;
int c;
while ((c = getopt(argc, argv, "dF:P")) != EOF)
while ((c = getopt(argc, argv, "dF:PS")) != EOF)
switch (c) {
case 'd':
debug = 1;
debug++;
break;
case 'F':
fw = optarg;
@ -307,13 +356,16 @@ int main(int argc, char **argv)
case 'P':
do_ping = 1;
break;
case 'S':
do_sample = 1;
break;
default:
usage(*argv);
}
if (do_ping && fw)
if (do_ping+do_sample+!!fw > 1)
usage(*argv);
if (do_ping || fw) {
if (do_ping || do_sample || fw) {
if (argc != optind)
usage(*argv);
} else {
@ -328,6 +380,8 @@ int main(int argc, char **argv)
rf_init(dsc, 8, 15);
if (do_ping)
ping(dsc);
else if (do_sample)
samples(dsc);
else if (fw)
firmware(dsc, fw);
else

101
tools/plot.c Normal file
View File

@ -0,0 +1,101 @@
/*
* tools/plot.c - Sample plot
*
* 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 <stdlib.h>
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#define XRES 1024
#define YRES 1024
#define RADIUS 3
#define OLD_RGBA 0xffffff20
#define NEW_RGBA 0xffffffff
static SDL_Surface *surf;
static int first = 1;
static int last_x, last_y;
static SDL_Surface *back;
static SDL_Rect back_rect = {
.x = 0,
.y = 0,
.w = 2*RADIUS+1,
.h = 2*RADIUS+1,
};
static SDL_Rect front_rect = {
.w = 2*RADIUS+1,
.h = 2*RADIUS+1,
};
void plot(int x, int y)
{
if (!first) {
SDL_BlitSurface(back, &back_rect, surf, &front_rect);
SDL_LockSurface(surf);
filledCircleColor(surf, last_x, last_y, RADIUS, OLD_RGBA);
SDL_UnlockSurface(surf);
}
front_rect.x = x;
front_rect.y = y;
x += RADIUS;
y += RADIUS;
SDL_BlitSurface(surf, &front_rect, back, &back_rect);
SDL_LockSurface(surf);
filledCircleColor(surf, x, y, RADIUS, NEW_RGBA);
SDL_UnlockSurface(surf);
if (!first)
SDL_UpdateRect(surf,
last_x-RADIUS, last_y-RADIUS, 2*RADIUS+1, 2*RADIUS+1);
SDL_UpdateRect(surf, x-RADIUS, y-RADIUS, 2*RADIUS+1, 2*RADIUS+1);
first = 0;
last_x = x;
last_y = y;
}
void plot_init(void)
{
const SDL_PixelFormat *f;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL_init: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
surf = SDL_SetVideoMode(XRES+2*RADIUS+1, YRES+2*RADIUS+1, 0,
SDL_SWSURFACE);
if (!surf) {
fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
exit(1);
}
f = surf->format;
back = SDL_CreateRGBSurface(SDL_SWSURFACE, 2*RADIUS+1, 2*RADIUS+1,
f->BitsPerPixel, f->Rmask, f->Gmask, f->Bmask, f->Amask);
if (!back) {
fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
exit(1);
}
}

20
tools/plot.h Normal file
View File

@ -0,0 +1,20 @@
/*
* tools/plot.h - Sample plot
*
* 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.
*/
#ifndef PLOT_H
#define PLOT_H
void plot(int x, int y);
void plot_init(void);
#endif /* !PLOT_H */