Some initial APRS parsing code

git-svn-id: http://repo.ham.fi/svn/aprsc/trunk@7 3ce903b1-3385-4e86-93cd-f9a4a239f7ac
This commit is contained in:
Heikki Hannikainen 2008-02-28 07:11:21 +00:00
parent 078b44eb70
commit 14baa31eba
2 changed files with 94 additions and 5 deletions

View File

@ -74,6 +74,18 @@ struct pbuf_t *pbuf_get_real(struct pbuf_t **pool, struct pbuf_t **global_pool,
/* ok, return the first buffer from the pool */
pb = *pool;
*pool = pb->next;
/* zero some fields */
pb->next = NULL;
pb->flags = 0;
pb->packettype = 0;
pb->t = 0;
pb->packet_len = 0;
pb->srccall_end = NULL;
pb->dstcall_end = NULL;
pb->info_start = NULL;
pb->lat = pb->lng = 0;
return pb;
}
@ -212,12 +224,8 @@ int incoming_handler(struct worker_t *self, struct client_t *c, char *s, int len
if (!(pb = pbuf_get(self, len+2)))
return 0;
/* fill the buffer */
/* fill the buffer (it's zeroed by pbuf_get) */
pb->t = now;
pb->packettype = 0;
pb->flags = 0;
pb->lat = 0;
pb->lng = 0;
pb->packet_len = len+2;
memcpy(pb->data, s, len);

View File

@ -2,8 +2,89 @@
#include "parse_aprs.h"
#include "hlog.h"
int parse_aprs_mice(struct pbuf_t *pb)
{
return 0;
}
int parse_aprs_compressed(struct pbuf_t *pb, char *body, const char *body_end)
{
return 0;
}
int parse_aprs_uncompressed(struct pbuf_t *pb, char *body, const char *body_end)
{
return 0;
}
/*
* Try to parse an APRS packet.
* Returns 1 if position was parsed successfully,
* 0 if parsing failed.
*/
int parse_aprs(struct worker_t *self, struct pbuf_t *pb)
{
char packettype, poschar;
int paclen;
char *body;
char *body_end = pb->data + pb->packet_len - 2;
if (!pb->info_start)
return 0;
/* the following parsing logic has been translated from Ham::APRS::FAP
* Perl module to C
*/
/* length of the info field: length of the packet - length of header - CRLF */
paclen = pb->packet_len - (pb->info_start - pb->data) - 2;
/* Check the first character of the packet and determine the packet type */
packettype = *pb->info_start;
/* failed parsing */
fprintf(stderr, "parse_aprs (%d):\n", paclen);
fwrite(pb->info_start, paclen, 1, stderr);
fprintf(stderr, "\n");
if (packettype == 0x27 || packettype == 0x60) {
/* could be mic-e, minimum body length 9 chars */
if (paclen >= 9)
return parse_aprs_mice(pb);
} else if (packettype == '!' || packettype == '=' || packettype == '/'
|| packettype == '@') {
/* body is right after the packet type character */
body = pb->info_start + 1;
/* check that we won't run over right away */
if (body_end - body < 10)
return -1;
/* Normal or compressed location packet, with or without
* timestamp, with or without messaging capability
*
* ! and / have messaging, / and @ have a prepended timestamp
*/
if (packettype == '/' || packettype == '@') {
/* With a prepended timestamp, jump over it. */
body += 7;
}
poschar = *body;
if (poschar == '/' || poschar == '\\' || (poschar >= 0x41 && poschar <= 0x5A)
|| (poschar >= 0x61 && poschar <= 0x6A)) { /* [\/\\A-Za-j] */
/* compressed position packet */
if (body_end - body >= 13) {
return parse_aprs_compressed(pb, body, body_end);
}
return 0;
} else if (poschar >= 0x30 && poschar <= 0x39) { /* [0-9] */
/* normal uncompressed position */
if (body_end - body >= 19) {
return parse_aprs_uncompressed(pb, body, body_end);
}
return 0;
}
}
return 0;
}