mirror of
git://projects.qi-hardware.com/antorcha.git
synced 2024-11-01 09:09:23 +02:00
properly implement "ping" and invoke it with antorcha -P
This commit is contained in:
parent
823fdcfcb1
commit
ea2cd37c04
@ -14,7 +14,9 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "version.h"
|
||||||
#include "rf.h"
|
#include "rf.h"
|
||||||
#include "proto.h"
|
#include "proto.h"
|
||||||
#include "dispatch.h"
|
#include "dispatch.h"
|
||||||
@ -36,11 +38,27 @@ static void send_ack(const uint8_t *buf)
|
|||||||
|
|
||||||
static bool answer_ping(const uint8_t *buf)
|
static bool answer_ping(const uint8_t *buf)
|
||||||
{
|
{
|
||||||
uint8_t pong[] = { PONG, 0, 0 };
|
char num[6]; /* let's hope we won't need more than 9999 versions */
|
||||||
|
char *num_end = num+sizeof(num);
|
||||||
|
int date_len = strlen(build_date);
|
||||||
|
int num_len;
|
||||||
|
uint8_t pong[3] = { PONG, 0, 0 };
|
||||||
|
uint8_t tmp[3+6+date_len+1];
|
||||||
|
char *s;
|
||||||
|
int n;
|
||||||
|
|
||||||
if (buf[1])
|
if (buf[1])
|
||||||
return 0;
|
return 0;
|
||||||
rf_send(pong, sizeof(pong));
|
s = num_end-1;
|
||||||
|
*s = ' ';
|
||||||
|
for (n = build_number; n; n /= 10)
|
||||||
|
*--s = '0'+n % 10;
|
||||||
|
*--s = '#';
|
||||||
|
num_len = num_end-s;
|
||||||
|
memcpy(tmp, pong, 3);
|
||||||
|
memcpy(tmp+3, s, num_len);
|
||||||
|
memcpy(tmp+3+num_len, build_date, date_len);
|
||||||
|
rf_send(tmp, 3+num_len+date_len);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
MAIN = antorcha
|
MAIN = antorcha
|
||||||
|
|
||||||
CFLAGS = -g -I../fw -I../../ben-wpan/tools/include \
|
CFLAGS = -g -I../fw -I../../ben-wpan/tools/include \
|
||||||
-I../../ben-wpan/atusb/fw/include
|
-I../../ben-wpan/atusb/fw/include \
|
||||||
|
-Wall
|
||||||
LDLIBS = -L../../ben-wpan/tools/lib -latrf -lusb
|
LDLIBS = -L../../ben-wpan/tools/lib -latrf -lusb
|
||||||
|
|
||||||
OBJS = antorcha.o hash.o
|
OBJS = antorcha.o hash.o
|
||||||
|
@ -84,21 +84,6 @@ static int rf_recv(struct atrf_dsc *dsc, void *buf, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void ping(struct atrf_dsc *dsc)
|
|
||||||
{
|
|
||||||
uint8_t ping[] = { 0 /*PING*/, 0, 0 };
|
|
||||||
uint8_t buf[100];
|
|
||||||
int got, i;
|
|
||||||
|
|
||||||
rf_send(dsc, ping, sizeof(ping));
|
|
||||||
got = rf_recv(dsc, buf, sizeof(buf));
|
|
||||||
printf("%d:", got);
|
|
||||||
for (i = 0; i != got; i++)
|
|
||||||
printf(" %02x", buf[i]);
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void packet_noack(struct atrf_dsc *dsc,
|
static void packet_noack(struct atrf_dsc *dsc,
|
||||||
uint8_t type, uint8_t seq, uint8_t last, const void *payload, int len)
|
uint8_t type, uint8_t seq, uint8_t last, const void *payload, int len)
|
||||||
{
|
{
|
||||||
@ -141,6 +126,29 @@ static void packet(struct atrf_dsc *dsc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----- Ping -------------------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
|
static void ping(struct atrf_dsc *dsc)
|
||||||
|
{
|
||||||
|
uint8_t ping[] = { PING, 0, 0 };
|
||||||
|
uint8_t buf[100];
|
||||||
|
int got, i;
|
||||||
|
|
||||||
|
rf_send(dsc, ping, sizeof(ping));
|
||||||
|
got = rf_recv(dsc, buf, sizeof(buf));
|
||||||
|
if (!got)
|
||||||
|
return;
|
||||||
|
printf("%d: ", got);
|
||||||
|
for (i = 3; i != got; i++)
|
||||||
|
printf("%c", buf[i] >= ' ' && buf[i] <= '~' ? buf[i] : '?');
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----- Firmware upload --------------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
static const uint8_t unlock_secret[PAYLOAD] = {
|
static const uint8_t unlock_secret[PAYLOAD] = {
|
||||||
#include "unlock-secret.inc"
|
#include "unlock-secret.inc"
|
||||||
};
|
};
|
||||||
@ -194,9 +202,14 @@ static void firmware(struct atrf_dsc *dsc, const char *name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ----- Command-line processing ------------------------------------------- */
|
||||||
|
|
||||||
|
|
||||||
static void usage(const char *name)
|
static void usage(const char *name)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s -F firmware_file\n", name);
|
fprintf(stderr,
|
||||||
|
"usage: %s -F firmware_file\n"
|
||||||
|
"%6s %s -P\n", name, "", name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,21 +217,27 @@ static void usage(const char *name)
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *fw = NULL;
|
const char *fw = NULL;
|
||||||
|
int do_ping = 0;
|
||||||
struct atrf_dsc *dsc;
|
struct atrf_dsc *dsc;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "F:")) != EOF)
|
while ((c = getopt(argc, argv, "F:P")) != EOF)
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'F':
|
case 'F':
|
||||||
fw = optarg;
|
fw = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'P':
|
||||||
|
do_ping = 1;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (do_ping && fw)
|
||||||
|
usage(*argv);
|
||||||
if (argc != optind)
|
if (argc != optind)
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
if (!fw)
|
if (!do_ping && !fw)
|
||||||
usage(*argv);
|
usage(*argv);
|
||||||
|
|
||||||
dsc = atrf_open(NULL);
|
dsc = atrf_open(NULL);
|
||||||
@ -226,6 +245,8 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
rf_init(dsc, 8, 15);
|
rf_init(dsc, 8, 15);
|
||||||
|
if (do_ping)
|
||||||
|
ping(dsc);
|
||||||
if (fw)
|
if (fw)
|
||||||
firmware(dsc, fw);
|
firmware(dsc, fw);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user