SimpleSerial configurable preamble and tail.

This commit is contained in:
Mark Qvist 2014-11-10 12:06:37 +01:00
parent 86f7f0fc00
commit 9ebbe4f1c6
6 changed files with 1794 additions and 1715 deletions

View File

@ -13,10 +13,8 @@
#include <struct/fifobuf.h> // FIFO buffer implementation from BertOS #include <struct/fifobuf.h> // FIFO buffer implementation from BertOS
#include <string.h> // String operations, primarily used for memset function #include <string.h> // String operations, primarily used for memset function
#if SERIAL_PROTOCOL == PROTOCOL_KISS extern unsigned long custom_preamble;
extern unsigned long kiss_preamble; extern unsigned long custom_tail;
extern unsigned long kiss_tail;
#endif
////////////////////////////////////////////////////// //////////////////////////////////////////////////////
// Definitions and some useful macros // // Definitions and some useful macros //
@ -453,22 +451,18 @@ static void afsk_txStart(Afsk *afsk) {
LED_TX_ON(); LED_TX_ON();
// We also need to calculate how many HDLC_FLAG // We also need to calculate how many HDLC_FLAG
// bytes we need to send in preamble // bytes we need to send in preamble
#if SERIAL_PROTOCOL == PROTOCOL_KISS afsk->preambleLength = DIV_ROUND(custom_preamble * BITRATE, 8000);
afsk->preambleLength = DIV_ROUND(kiss_preamble * BITRATE, 8000); //afsk->preambleLength = DIV_ROUND(CONFIG_AFSK_PREAMBLE_LEN * BITRATE, 8000);
#else
afsk->preambleLength = DIV_ROUND(CONFIG_AFSK_PREAMBLE_LEN * BITRATE, 8000);
#endif
AFSK_DAC_IRQ_START(); AFSK_DAC_IRQ_START();
} }
// We make the same calculation for the tail length, // We make the same calculation for the tail length,
// but this needs to be atomic, since the txStart // but this needs to be atomic, since the txStart
// function could potentially be called while we // function could potentially be called while we
// are already transmitting. // are already transmitting.
#if SERIAL_PROTOCOL == PROTOCOL_KISS
ATOMIC(afsk->tailLength = DIV_ROUND(kiss_tail * BITRATE, 8000)); ATOMIC(afsk->tailLength = DIV_ROUND(custom_tail * BITRATE, 8000));
#else //ATOMIC(afsk->tailLength = DIV_ROUND(CONFIG_AFSK_TRAILER_LEN * BITRATE, 8000));
ATOMIC(afsk->tailLength = DIV_ROUND(CONFIG_AFSK_TRAILER_LEN * BITRATE, 8000));
#endif
} }
// This is the DAC ISR, called at sampling rate whenever the DAC IRQ is on. // This is the DAC ISR, called at sampling rate whenever the DAC IRQ is on.

View File

@ -13,8 +13,8 @@ size_t frame_len;
bool IN_FRAME; bool IN_FRAME;
bool ESCAPE; bool ESCAPE;
uint8_t command = CMD_UNKNOWN; uint8_t command = CMD_UNKNOWN;
unsigned long kiss_preamble = CONFIG_AFSK_PREAMBLE_LEN; unsigned long custom_preamble = CONFIG_AFSK_PREAMBLE_LEN;
unsigned long kiss_tail = CONFIG_AFSK_TRAILER_LEN; unsigned long custom_tail = CONFIG_AFSK_TRAILER_LEN;
void kiss_init(AX25Ctx *ax25, Serial *ser) { void kiss_init(AX25Ctx *ax25, Serial *ser) {
ax25ctx = ax25; ax25ctx = ax25;
@ -72,9 +72,9 @@ void kiss_serialCallback(uint8_t sbyte) {
serialBuffer[frame_len++] = sbyte; serialBuffer[frame_len++] = sbyte;
} }
} else if (command == CMD_TXDELAY) { } else if (command == CMD_TXDELAY) {
kiss_preamble = sbyte * 10UL; custom_preamble = sbyte * 10UL;
} else if (command == CMD_TXTAIL) { } else if (command == CMD_TXTAIL) {
kiss_tail = sbyte * 10; custom_tail = sbyte * 10;
} }
} }

View File

@ -58,6 +58,8 @@ uint8_t EEMEM nvDIRECTIVITY;
uint8_t EEMEM nvSYMBOL_TABLE; uint8_t EEMEM nvSYMBOL_TABLE;
uint8_t EEMEM nvSYMBOL; uint8_t EEMEM nvSYMBOL;
uint8_t EEMEM nvAUTOACK; uint8_t EEMEM nvAUTOACK;
int EEMEM nvPREAMBLE;
int EEMEM nvTAIL;
// Location packet assembly fields // Location packet assembly fields
char latitude[8]; char latitude[8];
@ -81,6 +83,9 @@ size_t lastMessageLen;
bool message_autoAck = false; bool message_autoAck = false;
///////////////////////// /////////////////////////
extern unsigned long custom_preamble;
extern unsigned long custom_tail;
void ss_init(AX25Ctx *ax25) { void ss_init(AX25Ctx *ax25) {
ax25ctx = ax25; ax25ctx = ax25;
ss_loadSettings(); ss_loadSettings();
@ -130,6 +135,9 @@ void ss_loadSettings(void) {
symbolTable = eeprom_read_byte((void*)&nvSYMBOL_TABLE); symbolTable = eeprom_read_byte((void*)&nvSYMBOL_TABLE);
symbol = eeprom_read_byte((void*)&nvSYMBOL); symbol = eeprom_read_byte((void*)&nvSYMBOL);
message_autoAck = eeprom_read_byte((void*)&nvAUTOACK); message_autoAck = eeprom_read_byte((void*)&nvAUTOACK);
custom_preamble = eeprom_read_word((void*)&nvPREAMBLE);
custom_tail = eeprom_read_word((void*)&nvTAIL);
if (VERBOSE && SS_INIT) kprintf("Configuration loaded\n"); if (VERBOSE && SS_INIT) kprintf("Configuration loaded\n");
} else { } else {
@ -166,6 +174,9 @@ void ss_saveSettings(void) {
eeprom_update_byte((void*)&nvSYMBOL, symbol); eeprom_update_byte((void*)&nvSYMBOL, symbol);
eeprom_update_byte((void*)&nvAUTOACK, message_autoAck); eeprom_update_byte((void*)&nvAUTOACK, message_autoAck);
eeprom_update_word((void*)&nvPREAMBLE, custom_preamble);
eeprom_update_word((void*)&nvTAIL, custom_tail);
eeprom_update_byte((void*)&nvMagicByte, NV_MAGIC_BYTE); eeprom_update_byte((void*)&nvMagicByte, NV_MAGIC_BYTE);
if (VERBOSE) kprintf("Configuration saved\n"); if (VERBOSE) kprintf("Configuration saved\n");
@ -554,7 +565,6 @@ void ss_serialCallback(void *_buffer, size_t length, Serial *ser, AX25Ctx *ctx)
if (!VERBOSE && !SILENT) kprintf("1\n"); if (!VERBOSE && !SILENT) kprintf("1\n");
} }
} else if (buffer[0] == 'm' && length > 1) { } else if (buffer[0] == 'm' && length > 1) {
buffer++; length--; buffer++; length--;
if (buffer[0] == 'c' && length > 1) { if (buffer[0] == 'c' && length > 1) {
@ -614,7 +624,27 @@ void ss_serialCallback(void *_buffer, size_t length, Serial *ser, AX25Ctx *ctx)
} }
} }
} else { } else if (buffer[0] == 'w' && length >= 2) {
char str[4]; buffer++;
memcpy(str, buffer, length-1);
int preamble = atoi(str);
if (preamble >= 0 && preamble <= 9999) {
custom_preamble = preamble;
kprintf("Preamble set to %dms\n", custom_preamble);
} else {
kprintf("Error: Invalid value for preamble\n");
}
} else if (buffer[0] == 'W' && length >= 2) {
char str[4]; buffer++;
memcpy(str, buffer, length-1);
int tail = atoi(str);
if (tail >= 0 && tail <= 9999) {
custom_tail = tail;
kprintf("TX Tail set to %dms\n", custom_tail);
} else {
kprintf("Error: Invalid value for TX tail\n");
}
} else {
if (VERBOSE) kprintf("Error: Invalid command\n"); if (VERBOSE) kprintf("Error: Invalid command\n");
if (!VERBOSE && !SILENT) kprintf("0\n"); if (!VERBOSE && !SILENT) kprintf("0\n");
} }
@ -761,6 +791,8 @@ void ss_printSettings(void) {
if (symbolTable == '\\') kprintf("Symbol table: alternate\n"); if (symbolTable == '\\') kprintf("Symbol table: alternate\n");
if (symbolTable == '/') kprintf("Symbol table: standard\n"); if (symbolTable == '/') kprintf("Symbol table: standard\n");
kprintf("Symbol: %c\n", symbol); kprintf("Symbol: %c\n", symbol);
kprintf("TX Preamble: %d\n", custom_preamble);
kprintf("TX Tail: %d\n", custom_tail);
} }
#if ENABLE_HELP #if ENABLE_HELP

View File

@ -1,2 +1,2 @@
#define VERS_BUILD 2341 #define VERS_BUILD 2364
#define VERS_HOST "shard" #define VERS_HOST "shard"

Binary file not shown.

File diff suppressed because it is too large Load Diff