mirror of
https://github.com/markqvist/OpenModem.git
synced 2025-05-18 06:10:58 -04:00
Initial KISS support
This commit is contained in:
parent
9addf50a33
commit
6e3d8d9987
18 changed files with 1521 additions and 164 deletions
|
@ -0,0 +1,81 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <avr/eeprom.h>
|
||||
#define F_CPU 16000000UL
|
||||
#include <util/delay.h>
|
||||
#include <drv/timer.h> // Timer driver from BertOS
|
||||
#include "KISS.h"
|
||||
|
||||
static uint8_t serialBuffer[CONFIG_AX25_FRAME_BUF_LEN+1]; // Buffer for holding incoming serial data
|
||||
AX25Ctx *ax25ctx;
|
||||
Serial *serial;
|
||||
size_t frame_len;
|
||||
bool IN_FRAME;
|
||||
bool ESCAPE;
|
||||
uint8_t command = CMD_UNKNOWN;
|
||||
unsigned long kiss_preamble = CONFIG_AFSK_PREAMBLE_LEN;
|
||||
unsigned long kiss_tail = CONFIG_AFSK_TRAILER_LEN;
|
||||
|
||||
void kiss_init(AX25Ctx *ax25, Serial *ser) {
|
||||
ax25ctx = ax25;
|
||||
serial = ser;
|
||||
}
|
||||
|
||||
void kiss_messageCallback(AX25Ctx *ctx) {
|
||||
kfile_putc(FEND, &serial->fd);
|
||||
kfile_putc(0x00, &serial->fd);
|
||||
for (unsigned i = 0; i < ctx->frm_len; i++) {
|
||||
uint8_t b = ctx->buf[i];
|
||||
if (b == FEND) {
|
||||
kfile_putc(FESC, &serial->fd);
|
||||
kfile_putc(TFEND, &serial->fd);
|
||||
} else if (b == FESC) {
|
||||
kfile_putc(FESC, &serial->fd);
|
||||
kfile_putc(TFESC, &serial->fd);
|
||||
} else {
|
||||
kfile_putc(b, &serial->fd);
|
||||
}
|
||||
}
|
||||
kfile_putc(FEND, &serial->fd);
|
||||
}
|
||||
|
||||
void fon(void) {
|
||||
long ts = 300000;
|
||||
while (ts--) PORTB |= BV(2);
|
||||
}
|
||||
|
||||
|
||||
void kiss_serialCallback(uint8_t sbyte) {
|
||||
if (IN_FRAME && sbyte == FEND && command == CMD_DATA) {
|
||||
IN_FRAME = false;
|
||||
ax25_sendRaw(ax25ctx, serialBuffer, frame_len);
|
||||
} else if (sbyte == FEND) {
|
||||
IN_FRAME = true;
|
||||
command = CMD_UNKNOWN;
|
||||
frame_len = 0;
|
||||
} else if (IN_FRAME && frame_len < CONFIG_AX25_FRAME_BUF_LEN) {
|
||||
// Have a look at the command byte first
|
||||
if (frame_len == 0 && command == CMD_UNKNOWN) {
|
||||
// MicroModem supports only one HDLC port, so we
|
||||
// strip off the port nibble of the command byte
|
||||
sbyte = sbyte & 0x0F;
|
||||
command = sbyte;
|
||||
} else if (command == CMD_DATA) {
|
||||
if (sbyte == FESC) {
|
||||
ESCAPE = true;
|
||||
} else {
|
||||
if (ESCAPE) {
|
||||
if (sbyte == TFEND) sbyte = FEND;
|
||||
if (sbyte == TFESC) sbyte = FESC;
|
||||
ESCAPE = false;
|
||||
}
|
||||
serialBuffer[frame_len++] = sbyte;
|
||||
}
|
||||
} else if (command == CMD_TXDELAY) {
|
||||
kiss_preamble = sbyte * 10UL;
|
||||
} else if (command == CMD_TXTAIL) {
|
||||
kiss_tail = sbyte * 10;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,10 +1,27 @@
|
|||
#ifndef PROTOCOL_KISS
|
||||
#define PROTOCOL_KISS 0x02
|
||||
#ifndef _PROTOCOL_KISS
|
||||
#define _PROTOCOL_KISS 0x02
|
||||
|
||||
#define FEND 0xC0
|
||||
#define FESC 0xDB
|
||||
#define TFEND 0xDC
|
||||
#define TFESC 0xDD
|
||||
|
||||
#define CMD_UNKNOWN 0xFE
|
||||
#define CMD_DATA 0x00
|
||||
#define CMD_TXDELAY 0x01
|
||||
#define CMD_P 0x02
|
||||
#define CMD_SLOTTIME 0x03
|
||||
#define CMD_TXTAIL 0x04
|
||||
#define CMD_FULLDUPLEX 0x05
|
||||
#define CMD_SETHARDWARE 0x06
|
||||
#define CMD_RETURN 0xFF
|
||||
|
||||
#include <net/ax25.h>
|
||||
#include <drv/ser.h>
|
||||
|
||||
void kiss_init(AX25Ctx *ax25, Serial *ser);
|
||||
|
||||
void kiss_messageCallback(AX25Ctx *ctx);
|
||||
void kiss_serialCallback(uint8_t sbyte);
|
||||
void fon(void);
|
||||
#endif
|
|
@ -1,9 +1,8 @@
|
|||
#ifndef PROTOCOL_SIMPLE_SERIAL
|
||||
#ifndef _PROTOCOL_SIMPLE_SERIAL
|
||||
#define _PROTOCOL_SIMPLE_SERIAL 0x01
|
||||
#include <net/ax25.h>
|
||||
#include <drv/ser.h>
|
||||
|
||||
#define PROTOCOL_SIMPLE_SERIAL 0x01
|
||||
|
||||
#define DEFAULT_CALLSIGN "NOCALL"
|
||||
#define DEFAULT_DESTINATION_CALL "APZMDM"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue