libCATS
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
packet.h File Reference

Packet handling; the core of the library. More...

#include "whisker.h"
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

Go to the source code of this file.

Classes

struct  cats_packet_t
 CATS packet structure. More...
 

Macros

#define CATS_MAX_PKT_LEN   8191
 

Typedefs

typedef struct cats_packet_t cats_packet_t
 CATS packet structure.
 

Functions

int cats_packet_prepare (cats_packet_t **pkt)
 Initialize a cats_packet_t pointer.
 
int cats_packet_destroy (cats_packet_t **pkt)
 Deinitialize a packet.
 
uint16_t cats_packet_semi_encode (const cats_packet_t *pkt, uint8_t *out)
 Semi-encode a CATS packet; only pass through the Whisker and CRC portion of the CATS pipeline. Used for FELINET and radio interfacing.
 
uint16_t cats_packet_encode (const cats_packet_t *pkt, uint8_t *out)
 Encode a CATS packet.
 
int cats_packet_semi_decode (cats_packet_t *pkt, uint8_t *buf, size_t buf_len)
 Decode a semi-encoded CATS packet.
 
int cats_packet_decode (cats_packet_t *pkt, uint8_t *buf, size_t buf_len)
 Decode a CATS packet.
 
int cats_packet_add_identification (cats_packet_t *pkt, const char *callsign, uint8_t ssid, uint16_t icon)
 Add an identification whisker to a packet.
 
int cats_packet_add_comment (cats_packet_t *pkt, const char *comment)
 Add a comment whisker to a packet.
 
int cats_packet_add_gps (cats_packet_t *pkt, double lat, double lon, float alt, uint8_t error, uint8_t heading, float speed)
 Add a GPS whisker to a packet.
 
int cats_packet_add_route (cats_packet_t *pkt, cats_route_whisker_t route)
 Add a route whisker to a packet.
 
int cats_packet_add_destination (cats_packet_t *pkt, const char *callsign, uint8_t ssid, uint8_t ack)
 Add a destination whisker to a packet.
 
int cats_packet_add_simplex (cats_packet_t *pkt, uint32_t frequency, cats_modulation_t modulation, uint8_t power)
 Add a simplex whisker to a packet.
 
int cats_packet_add_repeater (cats_packet_t *pkt, uint32_t up, uint32_t down, cats_modulation_t modulation, uint32_t tone, uint8_t power, double lat, double lon, const char *name)
 Add a repeater whisker to a packet.
 
int cats_packet_add_nodeinfo (cats_packet_t *pkt, cats_nodeinfo_whisker_t info)
 Add a nodeinfo whisker to a packet.
 
int cats_packet_add_arbitrary (cats_packet_t *pkt, const uint8_t *data, size_t len)
 Add arbitrary data to a packet.
 
int cats_packet_add_whisker_data (cats_packet_t *pkt, cats_whisker_type_t type, const cats_whisker_data_t *whisker_data, int len)
 Add raw whisker data to a packet.
 
int cats_packet_add_whisker (cats_packet_t *pkt, const cats_whisker_t *whisker)
 Add a whisker to a packet.
 
int cats_packet_add_timestamp (cats_packet_t *pkt, uint64_t timestamp)
 Add a timestamp to a packet.
 
int cats_packet_get_identification (const cats_packet_t *pkt, cats_ident_whisker_t **out)
 Get the identification whisker from a packet.
 
int cats_packet_get_comment (const cats_packet_t *pkt, char *out)
 Get the comment whisker from a packet.
 
int cats_packet_get_gps (const cats_packet_t *pkt, cats_gps_whisker_t **out)
 Get the GPS whisker from a packet.
 
int cats_packet_get_route (const cats_packet_t *pkt, cats_route_whisker_t **out)
 Get the route whisker from a packet.
 
int cats_packet_get_destination (const cats_packet_t *pkt, cats_destination_whisker_t ***out)
 Get the destination whisker from a packet.
 
int cats_packet_get_simplex (const cats_packet_t *pkt, cats_simplex_whisker_t ***out)
 Get the simplex whisker from a packet.
 
int cats_packet_get_repeater (const cats_packet_t *pkt, cats_repeater_whisker_t ***out)
 Get the repeater whisker from a packet.
 
int cats_packet_get_arbitrary (const cats_packet_t *pkt, cats_whisker_t ***out)
 Get arbitrary whiskers from a packet.
 
uint64_t cats_packet_get_timestamp (const cats_packet_t *pkt)
 Get the timestamp from a packet.
 
int cats_packet_get_nodeinfo (const cats_packet_t *pkt, cats_nodeinfo_whisker_t **out)
 Get the nodeinfo whisker from a packet.
 
int cats_packet_find_whiskers (const cats_packet_t *pkt, cats_whisker_type_t type, cats_whisker_t ***out)
 Find whiskers of a certain type in a packet.
 
bool cats_packet_should_digipeat (const cats_packet_t *pkt, const char *callsign, uint16_t ssid)
 Check if a packet should be digipeated.
 

Detailed Description

Packet handling; the core of the library.

Typedef Documentation

◆ cats_packet_t

typedef struct cats_packet_t cats_packet_t

CATS packet structure.

Note
Must be initialized and deinitialized using cats_packet_prepare and cats_packet_destroy

Function Documentation

◆ cats_packet_add_arbitrary()

int cats_packet_add_arbitrary ( cats_packet_t * pkt,
const uint8_t * data,
size_t len )

Add arbitrary data to a packet.

Parameters
pktPacket to add whisker to
dataData
lenLength of data
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_comment()

int cats_packet_add_comment ( cats_packet_t * pkt,
const char * comment )

Add a comment whisker to a packet.

Parameters
pktPacket to add whisker to
commentComment
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_destination()

int cats_packet_add_destination ( cats_packet_t * pkt,
const char * callsign,
uint8_t ssid,
uint8_t ack )

Add a destination whisker to a packet.

Parameters
pktPacket to add whisker to
callsignCallsign
ssidSSID
ackAcknowledgement
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_gps()

int cats_packet_add_gps ( cats_packet_t * pkt,
double lat,
double lon,
float alt,
uint8_t error,
uint8_t heading,
float speed )

Add a GPS whisker to a packet.

Parameters
pktPacket to add whisker to
latLatitude
lonLongitude
altAltitude
errorError
headingHeading
speedSpeed
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_identification()

int cats_packet_add_identification ( cats_packet_t * pkt,
const char * callsign,
uint8_t ssid,
uint16_t icon )

Add an identification whisker to a packet.

Parameters
pktPacket to add whisker to
callsignCallsign
ssidSSID
iconIcon
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_nodeinfo()

int cats_packet_add_nodeinfo ( cats_packet_t * pkt,
cats_nodeinfo_whisker_t info )

Add a nodeinfo whisker to a packet.

Parameters
pktPacket to add whisker to
infoNodeinfo
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_repeater()

int cats_packet_add_repeater ( cats_packet_t * pkt,
uint32_t up,
uint32_t down,
cats_modulation_t modulation,
uint32_t tone,
uint8_t power,
double lat,
double lon,
const char * name )

Add a repeater whisker to a packet.

Parameters
pktPacket to add whisker to
upUplink frequency
downDownlink frequency
modulationModulation
toneTone
powerPower
latLatitude
lonLongitude
nameName
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_route()

int cats_packet_add_route ( cats_packet_t * pkt,
cats_route_whisker_t route )

Add a route whisker to a packet.

Parameters
pktPacket to add whisker to
routeRoute
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_simplex()

int cats_packet_add_simplex ( cats_packet_t * pkt,
uint32_t frequency,
cats_modulation_t modulation,
uint8_t power )

Add a simplex whisker to a packet.

Parameters
pktPacket to add whisker to
frequencyFrequency
modulationModulation
powerPower
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_timestamp()

int cats_packet_add_timestamp ( cats_packet_t * pkt,
uint64_t timestamp )

Add a timestamp to a packet.

Parameters
pktPacket to add whisker to
timestampTimestamp
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_add_whisker()

int cats_packet_add_whisker ( cats_packet_t * pkt,
const cats_whisker_t * whisker )

Add a whisker to a packet.

Parameters
pktPacket to add whisker to
whiskerWhisker to add
Returns
CATS_SUCCESS on success, CATS_FAIL on failure
Note
Data is copied from the whisker into the packet, it is safe to free the whisker after calling this function

◆ cats_packet_add_whisker_data()

int cats_packet_add_whisker_data ( cats_packet_t * pkt,
cats_whisker_type_t type,
const cats_whisker_data_t * whisker_data,
int len )

Add raw whisker data to a packet.

Parameters
pktPacket to add whisker to
typeWhisker type
whisker_dataWhisker data
lenLength of whisker data
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_decode()

int cats_packet_decode ( cats_packet_t * pkt,
uint8_t * buf,
size_t buf_len )

Decode a CATS packet.

Parameters
pktPacket to decode into
bufInput buffer
buf_lenLength of input buffer
Returns
CATS_SUCCESS on success, CATS_FAIL on failure
Note
pkt MUST be prepared before calling this function

◆ cats_packet_destroy()

int cats_packet_destroy ( cats_packet_t ** pkt)

Deinitialize a packet.

Note
NEVER call free() directly on a cats_packet_t pointer, this can result in memory leaks due to whiskers not being properly deallocated.
Always use this function to free a cats_packet_t pointer

◆ cats_packet_encode()

uint16_t cats_packet_encode ( const cats_packet_t * pkt,
uint8_t * out )

Encode a CATS packet.

Parameters
outOutput buffer
Returns
Length of data written to out

◆ cats_packet_find_whiskers()

int cats_packet_find_whiskers ( const cats_packet_t * pkt,
cats_whisker_type_t type,
cats_whisker_t *** out )

Find whiskers of a certain type in a packet.

Parameters
pktPacket to search
typeWhisker type to search for
outOutput array of whiskers
Returns
Number of whiskers found

◆ cats_packet_get_arbitrary()

int cats_packet_get_arbitrary ( const cats_packet_t * pkt,
cats_whisker_t *** out )

Get arbitrary whiskers from a packet.

Parameters
pktPacket to get whisker from
outOutput whisker
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_get_comment()

int cats_packet_get_comment ( const cats_packet_t * pkt,
char * out )

Get the comment whisker from a packet.

Parameters
pktPacket to get whisker from
outOutput comment
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_get_destination()

int cats_packet_get_destination ( const cats_packet_t * pkt,
cats_destination_whisker_t *** out )

Get the destination whisker from a packet.

Parameters
pktPacket to get whisker from
outOutput whisker
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_get_gps()

int cats_packet_get_gps ( const cats_packet_t * pkt,
cats_gps_whisker_t ** out )

Get the GPS whisker from a packet.

Parameters
pktPacket to get whisker from
outOutput whisker
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_get_identification()

int cats_packet_get_identification ( const cats_packet_t * pkt,
cats_ident_whisker_t ** out )

Get the identification whisker from a packet.

Parameters
pktPacket to get whisker from
outOutput whisker
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_get_nodeinfo()

int cats_packet_get_nodeinfo ( const cats_packet_t * pkt,
cats_nodeinfo_whisker_t ** out )

Get the nodeinfo whisker from a packet.

Parameters
pktPacket to get whisker from
outOutput whisker
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_get_repeater()

int cats_packet_get_repeater ( const cats_packet_t * pkt,
cats_repeater_whisker_t *** out )

Get the repeater whisker from a packet.

Parameters
pktPacket to get whisker from
outOutput whisker
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_get_route()

int cats_packet_get_route ( const cats_packet_t * pkt,
cats_route_whisker_t ** out )

Get the route whisker from a packet.

Parameters
pktPacket to get whisker from
outOutput whisker
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_get_simplex()

int cats_packet_get_simplex ( const cats_packet_t * pkt,
cats_simplex_whisker_t *** out )

Get the simplex whisker from a packet.

Parameters
pktPacket to get whisker from
outOutput whisker
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_get_timestamp()

uint64_t cats_packet_get_timestamp ( const cats_packet_t * pkt)

Get the timestamp from a packet.

Parameters
pktPacket to get whisker from
outOutput timestamp
Returns
CATS_SUCCESS on success, CATS_FAIL on failure

◆ cats_packet_prepare()

int cats_packet_prepare ( cats_packet_t ** pkt)

Initialize a cats_packet_t pointer.

Returns
CATS_SUCCESS on success, CATS_FAIL on failure
Note
Must be called before any functions using cats_packet_t
pkt MUST NOT already be allocated, otherwise it will leak memory

◆ cats_packet_semi_decode()

int cats_packet_semi_decode ( cats_packet_t * pkt,
uint8_t * buf,
size_t buf_len )

Decode a semi-encoded CATS packet.

Parameters
pktPacket to decode into
bufInput buffer
buf_lenLength of input buffer
Returns
CATS_SUCCESS on success, CATS_FAIL on failure
Note
pkt MUST be prepared before calling this function

◆ cats_packet_semi_encode()

uint16_t cats_packet_semi_encode ( const cats_packet_t * pkt,
uint8_t * out )

Semi-encode a CATS packet; only pass through the Whisker and CRC portion of the CATS pipeline. Used for FELINET and radio interfacing.

Parameters
outOutput buffer
Returns
Length of data written to out

◆ cats_packet_should_digipeat()

bool cats_packet_should_digipeat ( const cats_packet_t * pkt,
const char * callsign,
uint16_t ssid )

Check if a packet should be digipeated.

Parameters
pktPacket to check
callsignLocal Callsign
ssidLocal SSID
Returns
true if the packet should be digipeated, false otherwise