X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fnet%2Fax25.h;h=dd439445465495b37357bff42766af1281bbe39b;hb=05bb26937d55b1b2ddc58e089cb8880708b3e526;hp=da56b28b5c1b9e30aecd1109c3fb0d41e554483c;hpb=aef5ae9c57a34a342c7a6c83ece45ee77483ef0d;p=bertos.git diff --git a/bertos/net/ax25.h b/bertos/net/ax25.h index da56b28b..dd439445 100644 --- a/bertos/net/ax25.h +++ b/bertos/net/ax25.h @@ -34,7 +34,6 @@ * For now, only UI frames without any Layer 3 protocol are handled. * This however is enough to send/receive APRS packets. * - * \version $Id$ * \author Francesco Sacchi * * $WIZ$ module_name = "ax25" @@ -49,7 +48,7 @@ #include "cfg/cfg_ax25.h" #include -#include +#include /** * Maximum size of a AX25 frame. @@ -96,17 +95,22 @@ typedef struct AX25Call } AX25Call; /** - * Create an AX25Call structure on the fly and return its pointer. + * Create an AX25Call structure on the fly. * \param str callsign, can be 6 characters or shorter. * \param id ssid associated with the callsign. */ -#define AX25_CALL(str, id) ({ static const AX25Call _call = { .call = (str), .ssid = (id) }; &_call; }) +#define AX25_CALL(str, id) {.call = (str), .ssid = (id) } /** * Maximum number of Repeaters in a AX25 message. */ #define AX25_MAX_RPT 8 +/* + * Has to be lesser than 8 in order to fit in one byte + * change AX25Msg.rpt_flags if you need more repeaters. + */ +STATIC_ASSERT(AX25_MAX_RPT <= 8); /** * AX25 Message. @@ -119,6 +123,8 @@ typedef struct AX25Msg #if CONFIG_AX25_RPT_LST AX25Call rpt_lst[AX25_MAX_RPT]; ///< List of repeaters uint8_t rpt_cnt; ///< Number of repeaters in this message + uint8_t rpt_flags; ///< Has-been-repeated flags for each repeater (bit-mapped) + #define AX25_REPEATED(msg, idx) ((msg)->rpt_flags & BV(idx)) #endif uint16_t ctrl; ///< AX25 control field uint8_t pid; ///< AX25 PID field @@ -126,6 +132,7 @@ typedef struct AX25Msg size_t len; ///< Payload length } AX25Msg; + #define AX25_CTRL_UI 0x03 #define AX25_PID_NOLAYER3 0xF0 @@ -141,11 +148,46 @@ typedef struct AX25Msg /* \} */ +/** + * Declare an AX25 path. + * \param dst the destination callsign for the path, \see AX25_CALL + * for a handy way to create a callsign on the fly. + * \param src the source callsign for the path, \see AX25_CALL + * for a handy way to create a callsign on the fly. + * + * Additional optional callsigns can be specified at the end of this macro + * in order to add repeater callsigns or specific unproto paths. + * + * This macro can be used to simply path array declaration. + * Should be used in this way: + * \code + * AX25Call path[] = AX25_PATH(AX25_CALL("abcdef", 0), AX25_CALL("ghjklm", 0), AX25_CALL("wide1", 1), AX25_CALL("wide2", 2)); + * \endcode + * + * The declared path can then be passed to ax25_sendVia(). + */ +#define AX25_PATH(dst, src, ...) { dst, src, ## __VA_ARGS__ } void ax25_poll(AX25Ctx *ctx); -void ax25_send(AX25Ctx *ctx, const AX25Call *dst, const AX25Call *src, const void *_buf, size_t len); +void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len); + +/** + * Send an AX25 frame on the channel. + * \param ctx AX25 context to operate on. + * \param dst the destination callsign for the frame, \see AX25_CALL + * for a handy way to create a callsign on the fly. + * \param src the source callsign for the frame, \see AX25_CALL + * for a handy way to create a callsign on the fly. + * \param buf payload buffer. + * \param len length of the payload. + * + * \see ax25_sendVia() if you want to send a frame with a specific path. + */ +#define ax25_send(ctx, dst, src, buf, len) ax25_sendVia(ctx, ({static AX25Call __path[]={dst, src}; __path;}), 2, buf, len) void ax25_init(AX25Ctx *ctx, KFile *channel, ax25_callback_t hook); +void ax25_print(KFile *ch, const AX25Msg *msg); + int ax25_testSetup(void); int ax25_testTearDown(void); int ax25_testRun(void);