2014-04-03 22:21:37 +02:00
|
|
|
|
|
|
|
#include <cpu/irq.h>
|
|
|
|
#include <cfg/debug.h>
|
|
|
|
|
2014-04-04 11:17:47 +02:00
|
|
|
#include "afsk.h" // Header for AFSK modem
|
|
|
|
#include "protocol/mp1.h" // Header for MP.1 protocol
|
2014-04-03 22:21:37 +02:00
|
|
|
|
|
|
|
#include <drv/ser.h>
|
|
|
|
#include <drv/timer.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
static Afsk afsk;
|
|
|
|
static Serial ser;
|
|
|
|
|
2014-04-04 11:17:47 +02:00
|
|
|
static MP1 mp1;
|
|
|
|
|
2014-04-03 22:21:37 +02:00
|
|
|
#define ADC_CH 0
|
|
|
|
|
2014-04-04 17:05:53 +02:00
|
|
|
#define TEST_PACKET "Test MP1 AFSK Packet! This one is longer and probably more prone to errors..."
|
|
|
|
|
|
|
|
static uint8_t serialBuffer[MP1_MAX_FRAME_LENGTH];
|
|
|
|
static int sbyte;
|
|
|
|
static uint8_t serialLen = 0;
|
|
|
|
static bool sertx = false;
|
2014-04-04 00:39:51 +02:00
|
|
|
|
2014-04-04 11:17:47 +02:00
|
|
|
static void mp1Callback(struct MP1Packet *packet) {
|
|
|
|
kfile_printf(&ser.fd, "%.*s\r\n", packet->dataLength, packet->data);
|
|
|
|
}
|
2014-04-04 00:39:51 +02:00
|
|
|
|
2014-04-03 22:21:37 +02:00
|
|
|
static void init(void)
|
|
|
|
{
|
|
|
|
IRQ_ENABLE;
|
|
|
|
kdbg_init();
|
2014-04-04 17:05:53 +02:00
|
|
|
kprintf("Init\n");
|
|
|
|
|
2014-04-03 22:21:37 +02:00
|
|
|
timer_init();
|
|
|
|
|
|
|
|
afsk_init(&afsk, ADC_CH, 0);
|
2014-04-04 11:17:47 +02:00
|
|
|
mp1Init(&mp1, &afsk.fd, mp1Callback);
|
|
|
|
|
2014-04-03 22:21:37 +02:00
|
|
|
ser_init(&ser, SER_UART0);
|
2014-04-04 17:05:53 +02:00
|
|
|
ser_setbaudrate(&ser, 57600);
|
|
|
|
//ser_settimeouts(&ser, 0, 0);
|
2014-04-03 22:21:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
init();
|
2014-04-04 00:39:51 +02:00
|
|
|
ticks_t start = timer_clock();
|
2014-04-04 17:05:53 +02:00
|
|
|
|
2014-04-03 22:21:37 +02:00
|
|
|
while (1)
|
|
|
|
{
|
2014-04-04 11:17:47 +02:00
|
|
|
mp1Poll(&mp1);
|
2014-04-04 00:39:51 +02:00
|
|
|
|
2014-04-04 17:05:53 +02:00
|
|
|
sbyte = ser_getchar_nowait(&ser);
|
|
|
|
if (sbyte != EOF) {
|
|
|
|
if (serialLen < MP1_MAX_FRAME_LENGTH && sbyte != 138) {
|
|
|
|
serialBuffer[serialLen] = sbyte;
|
|
|
|
serialLen++;
|
|
|
|
} else {
|
|
|
|
sertx = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sertx) {
|
|
|
|
mp1Send(&mp1, serialBuffer, serialLen);
|
|
|
|
sertx = false;
|
|
|
|
serialLen = 0;
|
|
|
|
}
|
|
|
|
|
2014-04-04 11:40:43 +02:00
|
|
|
// Periodically send test data
|
2014-04-04 17:05:53 +02:00
|
|
|
if (false && timer_clock() - start > ms_to_ticks(4000L))
|
2014-04-04 00:39:51 +02:00
|
|
|
{
|
|
|
|
start = timer_clock();
|
2014-04-04 11:40:43 +02:00
|
|
|
mp1Send(&mp1, TEST_PACKET, sizeof(TEST_PACKET));
|
2014-04-04 00:39:51 +02:00
|
|
|
}
|
2014-04-03 22:21:37 +02:00
|
|
|
}
|
|
|
|
return 0;
|
2014-04-03 22:41:49 +02:00
|
|
|
}
|