-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathmain.c
executable file
·122 lines (99 loc) · 2.95 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright Mark Qvist / unsigned.io
// https://unsigned.io/microaprs
//
// Licensed under GPL-3.0. For full info,
// read the LICENSE file.
#include <stdbool.h>
#include <avr/io.h>
#include "device.h"
#include "util/FIFO.h"
#include "util/time.h"
#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
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
void init(void) {
sei();
AFSK_init(&modem);
ax25_init(&AX25, &modem, &modem.fd, ax25_callback);
serial_init(&serial);
stdout = &serial.uart0;
stdin = &serial.uart0;
#if SERIAL_PROTOCOL == PROTOCOL_KISS
kiss_init(&AX25, &modem, &serial);
#endif
#if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL
ss_init(&AX25);
#endif
}
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);
}
}
#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);
}