mirror of
https://github.com/markqvist/OpenModem.git
synced 2025-05-16 13:22:29 -04:00
Improved data carrier detection
This commit is contained in:
parent
01c629a6fd
commit
b7ffba0e92
6 changed files with 35 additions and 7 deletions
|
@ -12,11 +12,13 @@
|
|||
#define DECODE_CALL(buf, addr) for (unsigned i = 0; i < sizeof((addr)); i++) { char c = (*(buf)++ >> 1); (addr)[i] = (c == ' ') ? '\x0' : c; }
|
||||
#define AX25_SET_REPEATED(msg, idx, val) do { if (val) { (msg)->rpt_flags |= _BV(idx); } else { (msg)->rpt_flags &= ~_BV(idx) ; } } while(0)
|
||||
|
||||
void ax25_init(AX25Ctx *ctx, FILE *channel, ax25_callback_t hook) {
|
||||
void ax25_init(AX25Ctx *ctx, Afsk *modem, FILE *channel, ax25_callback_t hook) {
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
ctx->ch = channel;
|
||||
ctx->modem = modem;
|
||||
ctx->hook = hook;
|
||||
ctx->crc_in = ctx->crc_out = CRC_CCIT_INIT_VAL;
|
||||
ctx->ready_for_data = true;
|
||||
}
|
||||
|
||||
static void ax25_decode(AX25Ctx *ctx) {
|
||||
|
@ -93,6 +95,7 @@ void ax25_poll(AX25Ctx *ctx) {
|
|||
}
|
||||
ctx->escape = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void ax25_putchar(AX25Ctx *ctx, uint8_t c)
|
||||
|
@ -103,6 +106,7 @@ static void ax25_putchar(AX25Ctx *ctx, uint8_t c)
|
|||
}
|
||||
|
||||
void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len) {
|
||||
ctx->ready_for_data = false;
|
||||
ctx->crc_out = CRC_CCIT_INIT_VAL;
|
||||
fputc(HDLC_FLAG, ctx->ch);
|
||||
const uint8_t *buf = (const uint8_t *)_buf;
|
||||
|
@ -115,6 +119,7 @@ void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len) {
|
|||
|
||||
fputc(HDLC_FLAG, ctx->ch);
|
||||
|
||||
ctx->ready_for_data = true;
|
||||
}
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "device.h"
|
||||
#include "hardware/AFSK.h"
|
||||
|
||||
#define AX25_MIN_FRAME_LEN 18
|
||||
#ifndef CUSTOM_FRAME_SIZE
|
||||
|
@ -30,6 +31,7 @@ struct AX25Msg;
|
|||
|
||||
typedef struct AX25Ctx {
|
||||
uint8_t buf[AX25_MAX_FRAME_LEN];
|
||||
Afsk *modem;
|
||||
FILE *ch;
|
||||
size_t frame_len;
|
||||
uint16_t crc_in;
|
||||
|
@ -37,6 +39,7 @@ typedef struct AX25Ctx {
|
|||
ax25_callback_t hook;
|
||||
bool sync;
|
||||
bool escape;
|
||||
bool ready_for_data;
|
||||
} AX25Ctx;
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
|
||||
|
@ -68,6 +71,6 @@ typedef struct AX25Ctx {
|
|||
|
||||
void ax25_poll(AX25Ctx *ctx);
|
||||
void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len);
|
||||
void ax25_init(AX25Ctx *ctx, FILE *channel, ax25_callback_t hook);
|
||||
void ax25_init(AX25Ctx *ctx, Afsk *modem, FILE *channel, ax25_callback_t hook);
|
||||
|
||||
#endif
|
|
@ -80,8 +80,7 @@ void kiss_csma(AX25Ctx *ctx, uint8_t *buf, size_t len) {
|
|||
}
|
||||
|
||||
if (FLOWCONTROL) {
|
||||
while (channel->sending_data) { /* Wait */ }
|
||||
|
||||
while (!ctx->ready_for_data) { /* Wait */ }
|
||||
fputc(FEND, &serial->uart0);
|
||||
fputc(CMD_READY, &serial->uart0);
|
||||
fputc(0x01, &serial->uart0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue