2016-02-22 16:58:13 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
2016-02-26 20:58:23 -08:00
|
|
|
#include <stdbool.h>
|
2016-02-22 16:58:13 -08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#define PACKET_DATA_LEN_MAX 14
|
|
|
|
|
struct packet {
|
2016-02-25 23:37:37 -08:00
|
|
|
const uint8_t *source_id;
|
2016-02-27 21:50:15 -08:00
|
|
|
enum packet_type {
|
2016-02-23 13:49:23 -08:00
|
|
|
PACKET_TYPE_NONE,
|
2016-02-27 21:50:15 -08:00
|
|
|
PACKET_TYPE_MODE_AC,
|
2016-02-23 13:49:23 -08:00
|
|
|
PACKET_TYPE_MODE_S_SHORT,
|
|
|
|
|
PACKET_TYPE_MODE_S_LONG,
|
2016-02-22 16:58:13 -08:00
|
|
|
} type;
|
2016-02-27 21:50:15 -08:00
|
|
|
#define NUM_TYPES 4
|
2016-02-22 16:58:13 -08:00
|
|
|
uint8_t payload[PACKET_DATA_LEN_MAX];
|
|
|
|
|
uint64_t mlat_timestamp;
|
|
|
|
|
uint32_t rssi;
|
|
|
|
|
};
|
|
|
|
|
extern char *packet_type_names[];
|
2016-02-27 21:50:15 -08:00
|
|
|
extern size_t packet_payload_len[];
|
|
|
|
|
|
|
|
|
|
#define PACKET_PAYLOAD_LEN_MAX 14
|
2016-02-22 16:58:13 -08:00
|
|
|
|
|
|
|
|
#define PACKET_MLAT_MHZ 120
|
|
|
|
|
// Use the signed max to avoid problems with some consumers; it's large enough to not matter.
|
|
|
|
|
#define PACKET_MLAT_MAX INT64_MAX
|
|
|
|
|
#define PACKET_RSSI_MAX UINT32_MAX
|
|
|
|
|
|
|
|
|
|
struct packet_mlat_state {
|
|
|
|
|
uint64_t timestamp_last;
|
|
|
|
|
uint64_t timestamp_generation;
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-26 14:55:43 -08:00
|
|
|
uint64_t __attribute__ ((warn_unused_result)) packet_mlat_timestamp_scale_in(uint64_t, uint64_t, uint16_t, struct packet_mlat_state *);
|
|
|
|
|
uint64_t __attribute__ ((warn_unused_result)) packet_mlat_timestamp_scale_out(uint64_t, uint64_t, uint16_t);
|
2016-02-22 16:58:13 -08:00
|
|
|
|
2016-02-26 14:55:43 -08:00
|
|
|
uint32_t __attribute__ ((warn_unused_result)) packet_rssi_scale_in(uint32_t, uint32_t);
|
|
|
|
|
uint32_t __attribute__ ((warn_unused_result)) packet_rssi_scale_out(uint32_t, uint32_t);
|
2016-02-22 16:58:13 -08:00
|
|
|
|
2016-02-26 14:55:43 -08:00
|
|
|
void packet_sanity_check(const struct packet *);
|
2016-02-26 20:58:23 -08:00
|
|
|
bool __attribute__ ((warn_unused_result)) packet_validate_id(const uint8_t *);
|