2016-02-15 20:01:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
2016-02-14 06:20:17 +00:00
|
|
|
#include <stdint.h>
|
2016-02-17 15:41:27 -08:00
|
|
|
#include <sys/epoll.h>
|
2016-02-14 06:20:17 +00:00
|
|
|
|
|
|
|
|
|
2016-02-15 20:01:48 +00:00
|
|
|
//////// peer
|
|
|
|
|
|
|
|
|
|
// All specific peer structs must be castable to this.
|
2016-02-17 08:05:18 +00:00
|
|
|
struct peer;
|
2016-02-17 15:41:27 -08:00
|
|
|
typedef void (*peer_event_handler)(struct peer *);
|
2016-02-15 20:01:48 +00:00
|
|
|
struct peer {
|
2016-02-17 08:05:18 +00:00
|
|
|
int fd;
|
|
|
|
|
peer_event_handler event_handler;
|
2016-02-15 20:01:48 +00:00
|
|
|
};
|
2016-02-17 15:41:27 -08:00
|
|
|
void peer_init();
|
|
|
|
|
void peer_epoll_add(struct peer *, uint32_t);
|
|
|
|
|
void peer_epoll_del(struct peer *);
|
|
|
|
|
void peer_loop();
|
2016-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
|
|
2016-02-14 20:35:43 +00:00
|
|
|
//////// packet
|
2016-02-14 06:20:17 +00:00
|
|
|
|
2016-02-14 22:26:34 +00:00
|
|
|
#define DATA_LEN_MAX 14
|
2016-02-14 06:20:17 +00:00
|
|
|
struct packet {
|
|
|
|
|
enum {
|
|
|
|
|
MODE_S_SHORT,
|
|
|
|
|
MODE_S_LONG,
|
|
|
|
|
} type;
|
2016-02-17 18:01:39 -08:00
|
|
|
#define NUM_TYPES 2
|
2016-02-16 19:26:30 +00:00
|
|
|
uint8_t payload[DATA_LEN_MAX];
|
2016-02-14 06:20:17 +00:00
|
|
|
uint64_t mlat_timestamp;
|
|
|
|
|
uint32_t rssi;
|
|
|
|
|
};
|
2016-02-17 08:30:32 +00:00
|
|
|
extern char *packet_type_names[];
|
2016-02-14 06:20:17 +00:00
|
|
|
|
|
|
|
|
|
2016-02-15 22:01:32 +00:00
|
|
|
//////// mlat
|
|
|
|
|
|
2016-02-16 02:28:05 +00:00
|
|
|
#define MLAT_MHZ 120
|
2016-02-17 00:21:28 +00:00
|
|
|
// Use the signed max to avoid problems with some consumers; it's large enough to not matter.
|
|
|
|
|
#define MLAT_MAX INT64_MAX
|
2016-02-16 02:28:05 +00:00
|
|
|
#define RSSI_MAX UINT32_MAX
|
|
|
|
|
|
2016-02-15 22:01:32 +00:00
|
|
|
struct mlat_state {
|
|
|
|
|
uint64_t timestamp_last;
|
|
|
|
|
uint64_t timestamp_generation;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint64_t mlat_timestamp_scale_in(uint64_t, uint64_t, uint16_t, struct mlat_state *);
|
2016-02-17 18:01:39 -08:00
|
|
|
uint64_t mlat_timestamp_scale_out(uint64_t, uint64_t, uint16_t);
|
2016-02-15 22:01:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//////// rssi
|
|
|
|
|
|
|
|
|
|
uint32_t rssi_scale_in(uint32_t, uint32_t);
|
2016-02-17 18:01:39 -08:00
|
|
|
uint32_t rssi_scale_out(uint32_t, uint32_t);
|