2017-08-20 12:41:17 +00:00
|
|
|
#ifndef AX25_H_
|
|
|
|
#define AX25_H_
|
|
|
|
|
2023-04-10 19:12:21 +00:00
|
|
|
#include <ax25_config.h>
|
2017-08-20 12:41:17 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
2023-04-10 19:12:21 +00:00
|
|
|
#include "main_master_time.h"
|
|
|
|
|
2024-04-22 03:34:41 +00:00
|
|
|
#include "ax25_t.h"
|
2018-05-01 07:24:37 +00:00
|
|
|
#include "cfifo.h"
|
|
|
|
#include "afsk.h"
|
2017-08-20 12:41:17 +00:00
|
|
|
|
2018-05-01 07:24:37 +00:00
|
|
|
#include "macros.h"
|
2023-04-10 19:12:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Macro to wait for channel to be free
|
|
|
|
*/
|
|
|
|
#define WAIT_FOR_CHANNEL_FREE() \
|
|
|
|
ax25_ch_wait_start = main_get_master_time(); \
|
|
|
|
while (main_ax25.dcd == 1) { \
|
|
|
|
\
|
|
|
|
if (main_get_master_time() - ax25_ch_wait_start > \
|
|
|
|
CONFIG_AX25_MAX_WAIT_FOR_CH_FREE ) \
|
|
|
|
{ \
|
|
|
|
if (main_ax25.timeout_hook != 0) { \
|
|
|
|
main_ax25.timeout_hook(); \
|
|
|
|
} \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
} \
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum size of a AX25 frame.
|
|
|
|
*/
|
|
|
|
#define AX25_MIN_FRAME_LEN 18
|
|
|
|
|
|
|
|
/**
|
|
|
|
* CRC computation on correct AX25 packets should
|
|
|
|
* give this result (don't ask why).
|
|
|
|
*/
|
|
|
|
#define AX25_CRC_CORRECT 0xF0B8
|
|
|
|
|
|
|
|
#define AX25_CTRL_UI 0x03
|
|
|
|
#define AX25_PID_NOLAYER3 0xF0
|
|
|
|
|
|
|
|
#define HDLC_FLAG 0x7E
|
|
|
|
#define HDLC_RESET 0x7F
|
|
|
|
#define AX25_ESC 0x1B
|
|
|
|
|
|
|
|
|
|
|
|
struct AX25Msg; // fwd declaration
|
|
|
|
|
|
|
|
|
2023-04-10 19:12:21 +00:00
|
|
|
/**
|
2024-04-22 03:34:41 +00:00
|
|
|
* Create an AX25Call structure on the fly.
|
|
|
|
* \param str callsign, can be 6 characters or shorter.
|
|
|
|
* \param id ssid associated with the callsign.
|
2023-04-10 19:12:21 +00:00
|
|
|
*/
|
2024-04-22 03:34:41 +00:00
|
|
|
#define AX25_CALL(str, id) {.call = (str), .ssid = (id) }
|
|
|
|
#define AX25_PATH(dst, src, ...) { dst, src, ## __VA_ARGS__ }
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
typedef struct AX25Ctx
|
|
|
|
{
|
|
|
|
|
|
|
|
uint8_t buf[CONFIG_AX25_FRAME_BUF_LEN]; ///< buffer for received chars
|
|
|
|
Afsk *afsk;
|
|
|
|
|
|
|
|
uint16_t frm_len; ///< received frame length.
|
|
|
|
uint16_t crc_in; ///< CRC for current received frame
|
|
|
|
uint16_t crc_out; ///< CRC of current sent frame
|
|
|
|
|
|
|
|
ax25_callback_t hook; ///< Hook function to be called when a message is received
|
2023-04-10 19:12:21 +00:00
|
|
|
ax25_ch_free_timeout_callback_t timeout_hook; ///< callback hook to be called
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
bool raw;
|
|
|
|
bool sync; ///< True if we have received a HDLC flag.
|
|
|
|
bool escape; ///< True when we have to escape the following char.
|
|
|
|
uint8_t dcd_state;
|
|
|
|
bool dcd;
|
|
|
|
|
|
|
|
} AX25Ctx;
|
|
|
|
|
2019-03-18 20:12:05 +00:00
|
|
|
extern AX25Msg ax25_rxed_frame;
|
|
|
|
extern char ax25_new_msg_rx_flag;
|
2023-04-10 19:12:21 +00:00
|
|
|
|
|
|
|
extern uint32_t ax25_ch_wait_start;
|
2017-08-20 12:41:17 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*********************************************************************************************************************/
|
|
|
|
void ax25_poll(AX25Ctx *ctx);
|
|
|
|
/*********************************************************************************************************************/
|
|
|
|
|
|
|
|
/*********************************************************************************************************************/
|
|
|
|
void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, uint16_t path_len, const void *_buf, uint16_t len);
|
|
|
|
/*********************************************************************************************************************/
|
|
|
|
|
2019-05-05 07:48:51 +00:00
|
|
|
/*********************************************************************************************************************/
|
|
|
|
uint16_t ax25_sendVia_toBuffer(const AX25Call *path, uint16_t path_len, const void *payload, uint16_t payload_len, uint8_t* output_buf, uint16_t output_size);
|
|
|
|
/*********************************************************************************************************************/
|
|
|
|
|
2017-08-20 12:41:17 +00:00
|
|
|
/*********************************************************************************************************************/
|
|
|
|
void ax25_sendRaw(AX25Ctx *ctx, const void *_buf, uint16_t len);
|
|
|
|
/*********************************************************************************************************************/
|
|
|
|
|
|
|
|
/*********************************************************************************************************************/
|
2023-04-10 19:12:21 +00:00
|
|
|
void ax25_init(AX25Ctx *ctx, Afsk *afsk, bool raw, ax25_callback_t hook, ax25_ch_free_timeout_callback_t free_timeout);
|
2017-08-20 12:41:17 +00:00
|
|
|
/*********************************************************************************************************************/
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* AX25_H_ */
|