mirror of
https://github.com/markqvist/OpenModem.git
synced 2025-06-12 08:33:00 -04:00
Initial fork from MicroAPRS. Moved hardware definitions to m1284p. Implemented basic rx.
This commit is contained in:
parent
d03564928b
commit
3fb4c30604
16 changed files with 109 additions and 4574 deletions
99
main.c
99
main.c
|
@ -7,110 +7,41 @@
|
|||
#include "hardware/AFSK.h"
|
||||
#include "hardware/Serial.h"
|
||||
#include "protocol/AX25.h"
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_KISS
|
||||
#include "protocol/KISS.h"
|
||||
#endif
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
|
||||
#include "protocol/SimpleSerial.h"
|
||||
#endif
|
||||
#include "protocol/KISS.h"
|
||||
|
||||
Serial serial;
|
||||
Afsk modem;
|
||||
AX25Ctx AX25;
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_KISS
|
||||
static void ax25_callback(struct AX25Ctx *ctx) {
|
||||
kiss_messageCallback(ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
|
||||
static uint8_t serialBuffer[AX25_MAX_FRAME_LEN+1];
|
||||
static int sbyte;
|
||||
static size_t serialLen = 0;
|
||||
static bool sertx = false;
|
||||
|
||||
static void ax25_callback(struct AX25Msg *msg) {
|
||||
ss_messageCallback(msg);
|
||||
}
|
||||
#endif
|
||||
static void ax25_callback(struct AX25Ctx *ctx) {
|
||||
kiss_messageCallback(ctx);
|
||||
}
|
||||
|
||||
void init(void) {
|
||||
sei();
|
||||
|
||||
AFSK_init(&modem);
|
||||
ax25_init(&AX25, &modem, &modem.fd, ax25_callback);
|
||||
|
||||
// TODO: serial init was last before
|
||||
serial_init(&serial);
|
||||
stdout = &serial.uart0;
|
||||
stdin = &serial.uart0;
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_KISS
|
||||
kiss_init(&AX25, &modem, &serial);
|
||||
#endif
|
||||
AFSK_init(&modem);
|
||||
ax25_init(&AX25, &modem, &modem.fd, ax25_callback);
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
|
||||
ss_init(&AX25);
|
||||
#endif
|
||||
kiss_init(&AX25, &modem, &serial);
|
||||
}
|
||||
|
||||
int main (void) {
|
||||
init();
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_KISS
|
||||
while (true) {
|
||||
ax25_poll(&AX25);
|
||||
|
||||
if (serial_available(0)) {
|
||||
char sbyte = uart0_getchar_nowait();
|
||||
kiss_serialCallback(sbyte);
|
||||
}
|
||||
while (true) {
|
||||
ax25_poll(&AX25);
|
||||
|
||||
if (serial_available(0)) {
|
||||
char sbyte = uart0_getchar_nowait();
|
||||
kiss_serialCallback(sbyte);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
|
||||
ticks_t start = timer_clock();
|
||||
while (1) {
|
||||
ax25_poll(&AX25);
|
||||
|
||||
if (!sertx && serial_available(0)) {
|
||||
sbyte = uart0_getchar_nowait();
|
||||
|
||||
#if SERIAL_DEBUG
|
||||
if ((serialLen < AX25_MAX_FRAME_LEN) && (sbyte != 10)) {
|
||||
serialBuffer[serialLen] = sbyte;
|
||||
serialLen++;
|
||||
} else {
|
||||
sertx = true;
|
||||
}
|
||||
#else
|
||||
if (serialLen < AX25_MAX_FRAME_LEN-1) {
|
||||
serialBuffer[serialLen] = sbyte;
|
||||
serialLen++;
|
||||
} else {
|
||||
serialBuffer[serialLen] = sbyte;
|
||||
serialLen++;
|
||||
sertx = true;
|
||||
}
|
||||
|
||||
start = timer_clock();
|
||||
#endif
|
||||
} else {
|
||||
if (!SERIAL_DEBUG && serialLen > 0 && timer_clock() - start > ms_to_ticks(TX_MAXWAIT)) {
|
||||
sertx = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sertx) {
|
||||
ss_serialCallback(serialBuffer, serialLen, &AX25);
|
||||
sertx = false;
|
||||
serialLen = 0;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue