Fix up example programs somewhat
This commit is contained in:
parent
b3c85c891e
commit
f03d99c2a7
3 changed files with 102 additions and 11 deletions
|
@ -13,7 +13,7 @@ HEADERS = kiss.h ax25.h ax25/if.h ax25/macros.h ax25/proto.h \
|
|||
OBJS = kiss.o ax25.o if.o address.o frame.o list.o hash.o dict.o \
|
||||
test.o
|
||||
|
||||
PROGRAM = test
|
||||
EXAMPLES = test decode
|
||||
|
||||
AR = $(CROSS)ar
|
||||
RANLIB = $(CROSS)ranlib
|
||||
|
@ -23,10 +23,10 @@ LN = /bin/ln
|
|||
RMDIR = /bin/rmdir
|
||||
INSTALL = /usr/bin/install
|
||||
|
||||
all: $(PROGRAM)
|
||||
all: $(EXAMPLES)
|
||||
|
||||
$(PROGRAM): $(OBJS)
|
||||
$(CC) $(LDFLAGS) $(OBJS) -o $(PROGRAM)
|
||||
$(EXAMPLES): %: %.c $(OBJS)
|
||||
$(CC) $(LDFLAGS) $(OBJS) -o $@
|
||||
|
||||
$(OBJS): %.o: %.c $(HEADERS_BUILD)
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
|
93
src/decode.c
Normal file
93
src/decode.c
Normal file
|
@ -0,0 +1,93 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <patty/kiss.h>
|
||||
#include <patty/ax25.h>
|
||||
|
||||
static void usage(int argc, char **argv, const char *message, ...) {
|
||||
if (message) {
|
||||
va_list args;
|
||||
|
||||
va_start(args, message);
|
||||
vfprintf(stderr, message, args);
|
||||
fprintf(stderr, "\n");
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s kiss.cap\n", argv[0]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static int callsign_fprint(FILE *stream, const patty_ax25_address *address) {
|
||||
fprintf(stream, "%s", address->callsign);
|
||||
|
||||
if (address->ssid) {
|
||||
fprintf(stream, "/%d", address->ssid);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int address_fprint(FILE *stream, const patty_ax25_frame *frame) {
|
||||
int i;
|
||||
|
||||
callsign_fprint(stream, &frame->src);
|
||||
fprintf(stream, " > ");
|
||||
callsign_fprint(stream, &frame->dest);
|
||||
|
||||
for (i=0; i<frame->hops; i++) {
|
||||
fprintf(stream, " < ");
|
||||
callsign_fprint(stream, &frame->repeaters[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
patty_kiss_tnc *tnc;
|
||||
ssize_t len;
|
||||
void *data;
|
||||
int port;
|
||||
|
||||
if (argc != 2) {
|
||||
usage(argc, argv, "No TNC device provided");
|
||||
}
|
||||
|
||||
if ((tnc = patty_kiss_tnc_open(argv[1], 330)) == NULL) {
|
||||
perror("Unable to open TNC");
|
||||
|
||||
exit(127);
|
||||
}
|
||||
|
||||
while ((len = patty_kiss_tnc_recv(tnc, &data, &port)) > 0) {
|
||||
patty_ax25_frame frame;
|
||||
|
||||
if (patty_ax25_frame_decode(&frame, data, len) < 0) {
|
||||
perror("Unable to decode frame");
|
||||
|
||||
exit(127);
|
||||
}
|
||||
|
||||
address_fprint(stderr, &frame);
|
||||
|
||||
if (frame.type == PATTY_AX25_FRAME_INFO) {
|
||||
fprintf(stderr, " poll %d", PATTY_AX25_CONTROL_POLL(frame.control));
|
||||
fprintf(stderr, " ns %d", PATTY_AX25_CONTROL_SEQ_SEND(frame.control));
|
||||
fprintf(stderr, " nr %d", PATTY_AX25_CONTROL_SEQ_RECV(frame.control));
|
||||
}
|
||||
|
||||
if (frame.payload) {
|
||||
fprintf(stderr, " proto %02x", frame.proto);
|
||||
}
|
||||
|
||||
fprintf(stderr, " %ld bytes\n", len);
|
||||
}
|
||||
|
||||
patty_kiss_tnc_close(tnc);
|
||||
|
||||
return 0;
|
||||
}
|
12
src/test.c
12
src/test.c
|
@ -17,7 +17,7 @@ static void usage(int argc, char **argv, const char *message, ...) {
|
|||
va_end(args);
|
||||
}
|
||||
|
||||
fprintf(stderr, "usage: %s kiss.cap\n", argv[0]);
|
||||
fprintf(stderr, "usage: %s device\n", argv[0]);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
@ -35,10 +35,11 @@ int iface_callback(patty_ax25_if *iface, void *ctx) {
|
|||
int main(int argc, char **argv) {
|
||||
patty_ax25 ax25;
|
||||
patty_ax25_if *iface;
|
||||
patty_ax25_event ev;
|
||||
|
||||
if (argc != 2) {
|
||||
if (argc < 2) {
|
||||
usage(argc, argv, "No TNC device provided");
|
||||
} else if (argc > 2) {
|
||||
usage(argc, argv, NULL);
|
||||
}
|
||||
|
||||
if (patty_ax25_init(&ax25) < 0) {
|
||||
|
@ -65,10 +66,7 @@ int main(int argc, char **argv) {
|
|||
exit(127);
|
||||
}
|
||||
|
||||
if (patty_ax25_next_event(&ax25, &ev) >= 0) {
|
||||
printf("Got event %d on fd %d\n",
|
||||
ev.type, ev.fd);
|
||||
}
|
||||
patty_ax25_each_if(&ax25, iface_callback, NULL);
|
||||
|
||||
patty_ax25_stop(&ax25);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue