Browse Source

Add FPRS messaging.

master
Jeroen Vreeken 3 years ago
parent
commit
d6591287a0
4 changed files with 140 additions and 0 deletions
  1. +2
    -0
      eth_ar.c
  2. +8
    -0
      eth_ar/fprs.h
  3. +33
    -0
      fprs.c
  4. +97
    -0
      fprs2aprs.c

+ 2
- 0
eth_ar.c View File

@ -91,6 +91,8 @@ int eth_ar_callssid2mac(uint8_t mac[6], char *callsign, bool multicast)
break;
if (callsign[i] == 0)
break;
if (callsign[i] == ' ')
break;
call[i] = callsign[i];
}
call[i] = 0;


+ 8
- 0
eth_ar/fprs.h View File

@ -91,6 +91,10 @@ enum fprs_type {
FPRS_DMLSTREAM = 21, /* DML stream name (variable length) */
FPRS_DMLASSOC = 22, /* DML stream name (variable length) */
FPRS_MESSAGE = 32, /* Message text */
FPRS_MESSAGEID = 33, /* Message ID */
FPRS_MESSAGEACK = 34, /* Message acknowledge */
};
char *fprs_type2str(enum fprs_type);
@ -134,11 +138,15 @@ int fprs_frame_add_objectname(struct fprs_frame *, char *);
int fprs_frame_add_comment(struct fprs_frame *, char *);
int fprs_frame_add_dmlassoc(struct fprs_frame *, char *);
int fprs_frame_add_dmlstream(struct fprs_frame *, char *);
int fprs_frame_add_message(struct fprs_frame *frame, uint8_t *data, size_t size);
int fprs_frame_add_messageid(struct fprs_frame *frame, uint8_t *data, size_t size);
/* Conversion of a fprs frame to aprs ASCII format */
int fprs2aprs(char *aprs, size_t *aprs_len, struct fprs_frame *frame, uint8_t *callsign, char *gate_call);
int fprs2aprs_login(char *loginline, size_t *loginline_len, char *call);
/* Conversion of aprs packet (in APRS-IS format) to fprs */
struct fprs_frame *aprs2fprs(char *aprs);
#ifdef __cplusplus
}


+ 33
- 0
fprs.c View File

@ -375,6 +375,33 @@ int fprs_frame_add_dmlstream(struct fprs_frame *frame, char *name)
return fprs_frame_add_string(frame, FPRS_DMLSTREAM, name);
}
int fprs_frame_add_message(struct fprs_frame *frame, uint8_t *data, size_t size)
{
struct fprs_element *element;
element = fprs_frame_element_add(frame, FPRS_MESSAGE, size);
if (!element)
return -1;
memcpy(fprs_element_data(element), data, size);
return 0;
}
int fprs_frame_add_messageid(struct fprs_frame *frame, uint8_t *data, size_t size)
{
struct fprs_element *element;
element = fprs_frame_element_add(frame, FPRS_MESSAGEID, size);
if (!element)
return -1;
memcpy(fprs_element_data(element), data, size);
return 0;
}
#define FPRS_LON_SCALE 134217728
#define FPRS_LON_MAX 134217727
#define FPRS_LON_MIN -134217728
@ -659,6 +686,12 @@ char *fprs_type2str(enum fprs_type type)
return "FPRS_DMLSTREAM";
case FPRS_DMLASSOC:
return "FPRS_DMLASSOC";
case FPRS_MESSAGE:
return "FPRS_MESSAGE";
case FPRS_MESSAGEID:
return "FPRS_MESSAGEID";
case FPRS_MESSAGEACK:
return "FPRS_MESSAGEACK";
default:
return "FPRS_UNKNOWN";
}


+ 97
- 0
fprs2aprs.c View File

@ -25,9 +25,102 @@
#include <ctype.h>
#include <time.h>
struct fprs_frame *aprs2fprs(char *aprs)
{
int i;
/* skip comments */
if (aprs[0] == '#')
return NULL;
struct fprs_frame *frame = fprs_frame_create();
for (i = 0; i < strlen(aprs); i++) {
if (i > 9)
goto err_nocall;
if (aprs[i] == '>') {
char from_call[10];
memcpy(from_call, aprs, i);
from_call[i] = 0;
uint8_t from_ar[6];
printf("call: %s\n", from_call);
if (eth_ar_callssid2mac(from_ar, from_call, false))
goto err_ar;
fprs_frame_add_callsign(frame, from_ar);
break;
}
}
for (i++; i < strlen(aprs); i++) {
if (aprs[i] == ':') {
i++;
break;
}
}
if (i >= strlen(aprs)-1)
goto err_nopayload;
int payloadlen = strlen(aprs) - i;
if (payloadlen > 10 &&
aprs[i] == ':' &&
aprs[i+10] == ':') {
char dest_call[10];
memcpy(dest_call, aprs+i+1, 9);
dest_call[9] = 0;
uint8_t dest_ar[6];
printf("to : %s\n", dest_call);
if (eth_ar_callssid2mac(dest_ar, dest_call, false))
goto err_ar_dest;
fprs_frame_add_destination(frame, dest_ar);
int msg_start = i + 11;
for (i = msg_start; i < strlen(aprs); i++) {
if (aprs[i] == '{')
break;
}
int msg_end = i;
int msg_len = (msg_end - msg_start);
printf("MSG len: %d\n", msg_len);
if (!memcmp(aprs + msg_start, "ack", 3)) {
fprs_frame_add_messageid(frame,
(uint8_t *)aprs + msg_start + 3, msg_len - 3);
printf("ACK size: %d\n", msg_len - 3);
} else if (!memcmp(aprs + msg_start, "rej", 3)) {
/* No reject yet */
} else {
if (fprs_frame_add_message(frame,
(uint8_t *)aprs + msg_start, msg_len))
goto err_msg;
if (aprs[msg_end] == '{') {
int id_size = (strlen(aprs) - msg_end) -1;
printf("ID size: %d\n", id_size);
fprs_frame_add_messageid(frame,
(uint8_t *)aprs +msg_end + 1, id_size);
}
}
}
return frame;
err_msg:
err_ar_dest:
err_nopayload:
err_ar:
err_nocall:
fprs_frame_destroy(frame);
return NULL;
}
int fprs2aprs(char *aprs, size_t *aprs_len, struct fprs_frame *frame, uint8_t *callsign, char *gate_call)
{
uint8_t origin[6] = { 0 };
bool have_origin = false;
double lat, lon;
bool pos_fixed = true;
bool have_position = false;
@ -48,6 +141,7 @@ int fprs2aprs(char *aprs, size_t *aprs_len, struct fprs_frame *frame, uint8_t *c
if (callsign) {
memcpy(origin, callsign, 6);
have_origin = true;
}
struct fprs_element *element = NULL;
@ -59,6 +153,7 @@ int fprs2aprs(char *aprs, size_t *aprs_len, struct fprs_frame *frame, uint8_t *c
return -1;
case FPRS_CALLSIGN:
memcpy(origin, fprs_element_data(element), 6);
have_origin = true;
break;
case FPRS_POSITION:
fprs_position_dec(&lon, &lat, &pos_fixed, fprs_element_data(element));
@ -114,6 +209,8 @@ int fprs2aprs(char *aprs, size_t *aprs_len, struct fprs_frame *frame, uint8_t *c
break;
}
}
if (!have_origin)
return -1;
if (!have_position && !have_dmlstream && !have_dmlassoc)
return -1;


Loading…
Cancel
Save