Browse Source

first in

display_support
Andreas Peters 2 years ago
parent
commit
d782a5cee3

+ 3
- 0
.gitignore View File

@@ -0,0 +1,3 @@
1
+.pioenvs
2
+.piolibdeps
3
+.vscode

+ 65
- 0
.travis.yml View File

@@ -0,0 +1,65 @@
1
+# Continuous Integration (CI) is the practice, in software
2
+# engineering, of merging all developer working copies with a shared mainline
3
+# several times a day < http://docs.platformio.org/page/ci/index.html >
4
+#
5
+# Documentation:
6
+#
7
+# * Travis CI Embedded Builds with PlatformIO
8
+#   < https://docs.travis-ci.com/user/integration/platformio/ >
9
+#
10
+# * PlatformIO integration with Travis CI
11
+#   < http://docs.platformio.org/page/ci/travis.html >
12
+#
13
+# * User Guide for `platformio ci` command
14
+#   < http://docs.platformio.org/page/userguide/cmd_ci.html >
15
+#
16
+#
17
+# Please choice one of the following templates (proposed below) and uncomment
18
+# it (remove "# " before each line) or use own configuration according to the
19
+# Travis CI documentation (see above).
20
+#
21
+
22
+
23
+#
24
+# Template #1: General project. Test it using existing `platformio.ini`.
25
+#
26
+
27
+# language: python
28
+# python:
29
+#     - "2.7"
30
+#
31
+# sudo: false
32
+# cache:
33
+#     directories:
34
+#         - "~/.platformio"
35
+#
36
+# install:
37
+#     - pip install -U platformio
38
+#
39
+# script:
40
+#     - platformio run
41
+
42
+
43
+#
44
+# Template #2: The project is intended to by used as a library with examples
45
+#
46
+
47
+# language: python
48
+# python:
49
+#     - "2.7"
50
+#
51
+# sudo: false
52
+# cache:
53
+#     directories:
54
+#         - "~/.platformio"
55
+#
56
+# env:
57
+#     - PLATFORMIO_CI_SRC=path/to/test/file.c
58
+#     - PLATFORMIO_CI_SRC=examples/file.ino
59
+#     - PLATFORMIO_CI_SRC=path/to/test/directory
60
+#
61
+# install:
62
+#     - pip install -U platformio
63
+#
64
+# script:
65
+#     - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

+ 475
- 0
lib/LibAPRS/AFSK.cpp View File

@@ -0,0 +1,475 @@
1
+#include <string.h>
2
+#include "AFSK.h"
3
+#include "Arduino.h"
4
+
5
+extern unsigned long custom_preamble;
6
+extern unsigned long custom_tail;
7
+extern int LibAPRS_vref;
8
+extern bool LibAPRS_open_squelch;
9
+
10
+bool hw_afsk_dac_isr = false;
11
+bool hw_5v_ref = false;
12
+Afsk *AFSK_modem;
13
+
14
+
15
+// Forward declerations
16
+int afsk_getchar(void);
17
+void afsk_putchar(char c);
18
+
19
+void AFSK_hw_refDetect(void) {
20
+    // This is manual for now
21
+    if (LibAPRS_vref == REF_5V) {
22
+        hw_5v_ref = true;
23
+    } else {
24
+        hw_5v_ref = false;
25
+    }
26
+}
27
+
28
+void AFSK_hw_init(void) {
29
+    // Set up ADC
30
+
31
+    AFSK_hw_refDetect();
32
+
33
+    TCCR1A = 0;                                    
34
+    TCCR1B = _BV(CS10) | _BV(WGM13) | _BV(WGM12);
35
+    ICR1 = (((CPU_FREQ+FREQUENCY_CORRECTION)) / 9600) - 1;
36
+
37
+    if (hw_5v_ref) {
38
+        ADMUX = _BV(REFS0) | 0;
39
+    } else {
40
+        ADMUX = 0;
41
+    }
42
+
43
+    ADC_DDR  &= ~_BV(0);
44
+    ADC_PORT &= ~_BV(0);
45
+    DIDR0 |= _BV(0);
46
+    ADCSRB =    _BV(ADTS2) |
47
+                _BV(ADTS1) |
48
+                _BV(ADTS0);  
49
+    ADCSRA =    _BV(ADEN) |
50
+                _BV(ADSC) |
51
+                _BV(ADATE)|
52
+                _BV(ADIE) |
53
+                _BV(ADPS2);
54
+
55
+    AFSK_DAC_INIT();
56
+    LED_TX_INIT();
57
+    LED_RX_INIT();
58
+}
59
+
60
+void AFSK_init(Afsk *afsk) {
61
+    // Allocate modem struct memory
62
+    memset(afsk, 0, sizeof(*afsk));
63
+    AFSK_modem = afsk;
64
+    // Set phase increment
65
+    afsk->phaseInc = MARK_INC;
66
+    // Initialise FIFO buffers
67
+    fifo_init(&afsk->delayFifo, (uint8_t *)afsk->delayBuf, sizeof(afsk->delayBuf));
68
+    fifo_init(&afsk->rxFifo, afsk->rxBuf, sizeof(afsk->rxBuf));
69
+    fifo_init(&afsk->txFifo, afsk->txBuf, sizeof(afsk->txBuf));
70
+
71
+    // Fill delay FIFO with zeroes
72
+    for (int i = 0; i<SAMPLESPERBIT / 2; i++) {
73
+        fifo_push(&afsk->delayFifo, 0);
74
+    }
75
+
76
+    AFSK_hw_init();
77
+
78
+}
79
+
80
+static void AFSK_txStart(Afsk *afsk) {
81
+    if (!afsk->sending) {
82
+        afsk->phaseInc = MARK_INC;
83
+        afsk->phaseAcc = 0;
84
+        afsk->bitstuffCount = 0;
85
+        afsk->sending = true;
86
+        LED_TX_ON();
87
+        afsk->preambleLength = DIV_ROUND(custom_preamble * BITRATE, 8000);
88
+        AFSK_DAC_IRQ_START();
89
+    }
90
+    ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
91
+      afsk->tailLength = DIV_ROUND(custom_tail * BITRATE, 8000);
92
+    }
93
+}
94
+
95
+void afsk_putchar(char c) {
96
+    AFSK_txStart(AFSK_modem);
97
+    while(fifo_isfull_locked(&AFSK_modem->txFifo)) { /* Wait */ }
98
+    fifo_push_locked(&AFSK_modem->txFifo, c);
99
+}
100
+
101
+int afsk_getchar(void) {
102
+    if (fifo_isempty_locked(&AFSK_modem->rxFifo)) {
103
+        return EOF;
104
+    } else {
105
+        return fifo_pop_locked(&AFSK_modem->rxFifo);
106
+    }
107
+}
108
+
109
+void AFSK_transmit(char *buffer, size_t size) {
110
+    fifo_flush(&AFSK_modem->txFifo);
111
+    int i = 0;
112
+    while (size--) {
113
+        afsk_putchar(buffer[i++]);
114
+    }
115
+}
116
+
117
+uint8_t AFSK_dac_isr(Afsk *afsk) {
118
+    if (afsk->sampleIndex == 0) {
119
+        if (afsk->txBit == 0) {
120
+            if (fifo_isempty(&afsk->txFifo) && afsk->tailLength == 0) {
121
+                AFSK_DAC_IRQ_STOP();
122
+                afsk->sending = false;
123
+                LED_TX_OFF();
124
+                return 0;
125
+            } else {
126
+                if (!afsk->bitStuff) afsk->bitstuffCount = 0;
127
+                afsk->bitStuff = true;
128
+                if (afsk->preambleLength == 0) {
129
+                    if (fifo_isempty(&afsk->txFifo)) {
130
+                        afsk->tailLength--;
131
+                        afsk->currentOutputByte = HDLC_FLAG;
132
+                    } else {
133
+                        afsk->currentOutputByte = fifo_pop(&afsk->txFifo);
134
+                    }
135
+                } else {
136
+                    afsk->preambleLength--;
137
+                    afsk->currentOutputByte = HDLC_FLAG;
138
+                }
139
+                if (afsk->currentOutputByte == AX25_ESC) {
140
+                    if (fifo_isempty(&afsk->txFifo)) {
141
+                        AFSK_DAC_IRQ_STOP();
142
+                        afsk->sending = false;
143
+                        LED_TX_OFF();
144
+                        return 0;
145
+                    } else {
146
+                        afsk->currentOutputByte = fifo_pop(&afsk->txFifo);
147
+                    }
148
+                } else if (afsk->currentOutputByte == HDLC_FLAG || afsk->currentOutputByte == HDLC_RESET) {
149
+                    afsk->bitStuff = false;
150
+                }
151
+            }
152
+            afsk->txBit = 0x01;
153
+        }
154
+
155
+        if (afsk->bitStuff && afsk->bitstuffCount >= BIT_STUFF_LEN) {
156
+            afsk->bitstuffCount = 0;
157
+            afsk->phaseInc = SWITCH_TONE(afsk->phaseInc);
158
+        } else {
159
+            if (afsk->currentOutputByte & afsk->txBit) {
160
+                afsk->bitstuffCount++;
161
+            } else {
162
+                afsk->bitstuffCount = 0;
163
+                afsk->phaseInc = SWITCH_TONE(afsk->phaseInc);
164
+            }
165
+            afsk->txBit <<= 1;
166
+        }
167
+
168
+        afsk->sampleIndex = SAMPLESPERBIT;
169
+    }
170
+
171
+    afsk->phaseAcc += afsk->phaseInc;
172
+    afsk->phaseAcc %= SIN_LEN;
173
+    afsk->sampleIndex--;
174
+
175
+    return sinSample(afsk->phaseAcc);
176
+}
177
+
178
+static bool hdlcParse(Hdlc *hdlc, bool bit, FIFOBuffer *fifo) {
179
+    // Initialise a return value. We start with the
180
+    // assumption that all is going to end well :)
181
+    bool ret = true;
182
+
183
+    // Bitshift our byte of demodulated bits to
184
+    // the left by one bit, to make room for the
185
+    // next incoming bit
186
+    hdlc->demodulatedBits <<= 1;
187
+    // And then put the newest bit from the 
188
+    // demodulator into the byte.
189
+    hdlc->demodulatedBits |= bit ? 1 : 0;
190
+
191
+    // Now we'll look at the last 8 received bits, and
192
+    // check if we have received a HDLC flag (01111110)
193
+    if (hdlc->demodulatedBits == HDLC_FLAG) {
194
+        // If we have, check that our output buffer is
195
+        // not full.
196
+        if (!fifo_isfull(fifo)) {
197
+            // If it isn't, we'll push the HDLC_FLAG into
198
+            // the buffer and indicate that we are now
199
+            // receiving data. For bling we also turn
200
+            // on the RX LED.
201
+            fifo_push(fifo, HDLC_FLAG);
202
+            hdlc->receiving = true;
203
+            if(!LibAPRS_open_squelch) {
204
+                LED_RX_ON();
205
+            }
206
+        } else {
207
+            // If the buffer is full, we have a problem
208
+            // and abort by setting the return value to     
209
+            // false and stopping the here.
210
+            
211
+            ret = false;
212
+            hdlc->receiving = false;
213
+            LED_RX_OFF();
214
+        }
215
+
216
+        // Everytime we receive a HDLC_FLAG, we reset the
217
+        // storage for our current incoming byte and bit
218
+        // position in that byte. This effectively
219
+        // synchronises our parsing to  the start and end
220
+        // of the received bytes.
221
+        hdlc->currentByte = 0;
222
+        hdlc->bitIndex = 0;
223
+        return ret;
224
+    }
225
+
226
+    // Check if we have received a RESET flag (01111111)
227
+    // In this comparison we also detect when no transmission
228
+    // (or silence) is taking place, and the demodulator
229
+    // returns an endless stream of zeroes. Due to the NRZ
230
+    // coding, the actual bits send to this function will
231
+    // be an endless stream of ones, which this AND operation
232
+    // will also detect.
233
+    if ((hdlc->demodulatedBits & HDLC_RESET) == HDLC_RESET) {
234
+        // If we have, something probably went wrong at the
235
+        // transmitting end, and we abort the reception.
236
+        hdlc->receiving = false;
237
+        LED_RX_OFF();
238
+        return ret;
239
+    }
240
+
241
+    // If we have not yet seen a HDLC_FLAG indicating that
242
+    // a transmission is actually taking place, don't bother
243
+    // with anything.
244
+    if (!hdlc->receiving)
245
+        return ret;
246
+
247
+    // First check if what we are seeing is a stuffed bit.
248
+    // Since the different HDLC control characters like
249
+    // HDLC_FLAG, HDLC_RESET and such could also occur in
250
+    // a normal data stream, we employ a method known as
251
+    // "bit stuffing". All control characters have more than
252
+    // 5 ones in a row, so if the transmitting party detects
253
+    // this sequence in the _data_ to be transmitted, it inserts
254
+    // a zero to avoid the receiving party interpreting it as
255
+    // a control character. Therefore, if we detect such a
256
+    // "stuffed bit", we simply ignore it and wait for the
257
+    // next bit to come in.
258
+    // 
259
+    // We do the detection by applying an AND bit-mask to the
260
+    // stream of demodulated bits. This mask is 00111111 (0x3f)
261
+    // if the result of the operation is 00111110 (0x3e), we
262
+    // have detected a stuffed bit.
263
+    if ((hdlc->demodulatedBits & 0x3f) == 0x3e)
264
+        return ret;
265
+
266
+    // If we have an actual 1 bit, push this to the current byte
267
+    // If it's a zero, we don't need to do anything, since the
268
+    // bit is initialized to zero when we bitshifted earlier.
269
+    if (hdlc->demodulatedBits & 0x01)
270
+        hdlc->currentByte |= 0x80;
271
+
272
+    // Increment the bitIndex and check if we have a complete byte
273
+    if (++hdlc->bitIndex >= 8) {
274
+        // If we have a HDLC control character, put a AX.25 escape
275
+        // in the received data. We know we need to do this,
276
+        // because at this point we must have already seen a HDLC
277
+        // flag, meaning that this control character is the result
278
+        // of a bitstuffed byte that is equal to said control
279
+        // character, but is actually part of the data stream.
280
+        // By inserting the escape character, we tell the protocol
281
+        // layer that this is not an actual control character, but
282
+        // data.
283
+        if ((hdlc->currentByte == HDLC_FLAG ||
284
+             hdlc->currentByte == HDLC_RESET ||
285
+             hdlc->currentByte == AX25_ESC)) {
286
+            // We also need to check that our received data buffer
287
+            // is not full before putting more data in
288
+            if (!fifo_isfull(fifo)) {
289
+                fifo_push(fifo, AX25_ESC);
290
+            } else {
291
+                // If it is, abort and return false
292
+                hdlc->receiving = false;
293
+                LED_RX_OFF();
294
+                ret = false;
295
+            }
296
+        }
297
+
298
+        // Push the actual byte to the received data FIFO,
299
+        // if it isn't full.
300
+        if (!fifo_isfull(fifo)) {
301
+            fifo_push(fifo, hdlc->currentByte);
302
+        } else {
303
+            // If it is, well, you know by now!
304
+            hdlc->receiving = false;
305
+            LED_RX_OFF();
306
+            ret = false;
307
+        }
308
+
309
+        // Wipe received byte and reset bit index to 0
310
+        hdlc->currentByte = 0;
311
+        hdlc->bitIndex = 0;
312
+
313
+    } else {
314
+        // We don't have a full byte yet, bitshift the byte
315
+        // to make room for the next bit
316
+        hdlc->currentByte >>= 1;
317
+    }
318
+
319
+    //digitalWrite(13, LOW);
320
+    return ret;
321
+}
322
+
323
+
324
+void AFSK_adc_isr(Afsk *afsk, int8_t currentSample) {
325
+    // To determine the received frequency, and thereby
326
+    // the bit of the sample, we multiply the sample by
327
+    // a sample delayed by (samples per bit / 2).
328
+    // We then lowpass-filter the samples with a
329
+    // Chebyshev filter. The lowpass filtering serves
330
+    // to "smooth out" the variations in the samples.
331
+
332
+    afsk->iirX[0] = afsk->iirX[1];
333
+    afsk->iirX[1] = ((int8_t)fifo_pop(&afsk->delayFifo) * currentSample) >> 2;
334
+
335
+    afsk->iirY[0] = afsk->iirY[1];
336
+    
337
+    afsk->iirY[1] = afsk->iirX[0] + afsk->iirX[1] + (afsk->iirY[0] >> 1); // Chebyshev filter
338
+
339
+
340
+    // We put the sampled bit in a delay-line:
341
+    // First we bitshift everything 1 left
342
+    afsk->sampledBits <<= 1;
343
+    // And then add the sampled bit to our delay line
344
+    afsk->sampledBits |= (afsk->iirY[1] > 0) ? 1 : 0;
345
+
346
+    // Put the current raw sample in the delay FIFO
347
+    fifo_push(&afsk->delayFifo, currentSample);
348
+
349
+    // We need to check whether there is a signal transition.
350
+    // If there is, we can recalibrate the phase of our 
351
+    // sampler to stay in sync with the transmitter. A bit of
352
+    // explanation is required to understand how this works.
353
+    // Since we have PHASE_MAX/PHASE_BITS = 8 samples per bit,
354
+    // we employ a phase counter (currentPhase), that increments
355
+    // by PHASE_BITS everytime a sample is captured. When this
356
+    // counter reaches PHASE_MAX, it wraps around by modulus
357
+    // PHASE_MAX. We then look at the last three samples we
358
+    // captured and determine if the bit was a one or a zero.
359
+    //
360
+    // This gives us a "window" looking into the stream of
361
+    // samples coming from the ADC. Sort of like this:
362
+    //
363
+    //   Past                                      Future
364
+    //       0000000011111111000000001111111100000000
365
+    //                   |________|
366
+    //                       ||     
367
+    //                     Window
368
+    //
369
+    // Every time we detect a signal transition, we adjust
370
+    // where this window is positioned little. How much we
371
+    // adjust it is defined by PHASE_INC. If our current phase
372
+    // phase counter value is less than half of PHASE_MAX (ie, 
373
+    // the window size) when a signal transition is detected,
374
+    // add PHASE_INC to our phase counter, effectively moving
375
+    // the window a little bit backward (to the left in the
376
+    // illustration), inversely, if the phase counter is greater
377
+    // than half of PHASE_MAX, we move it forward a little.
378
+    // This way, our "window" is constantly seeking to position
379
+    // it's center at the bit transitions. Thus, we synchronise
380
+    // our timing to the transmitter, even if it's timing is
381
+    // a little off compared to our own.
382
+    if (SIGNAL_TRANSITIONED(afsk->sampledBits)) {
383
+        if (afsk->currentPhase < PHASE_THRESHOLD) {
384
+            afsk->currentPhase += PHASE_INC;
385
+        } else {
386
+            afsk->currentPhase -= PHASE_INC;
387
+        }
388
+    }
389
+
390
+    // We increment our phase counter
391
+    afsk->currentPhase += PHASE_BITS;
392
+
393
+    // Check if we have reached the end of
394
+    // our sampling window.
395
+    if (afsk->currentPhase >= PHASE_MAX) {
396
+        // If we have, wrap around our phase
397
+        // counter by modulus
398
+        afsk->currentPhase %= PHASE_MAX;
399
+
400
+        // Bitshift to make room for the next
401
+        // bit in our stream of demodulated bits
402
+        afsk->actualBits <<= 1;
403
+
404
+        // We determine the actual bit value by reading
405
+        // the last 3 sampled bits. If there is three or
406
+        // more 1's, we will assume that the transmitter
407
+        // sent us a one, otherwise we assume a zero
408
+        uint8_t bits = afsk->sampledBits & 0x07;
409
+        if (bits == 0x07 || // 111
410
+            bits == 0x06 || // 110
411
+            bits == 0x05 || // 101
412
+            bits == 0x03    // 011
413
+            ) {
414
+            afsk->actualBits |= 1;
415
+        }
416
+
417
+         //// Alternative using five bits ////////////////
418
+         // uint8_t bits = afsk->sampledBits & 0x0f;
419
+         // uint8_t c = 0;
420
+         // c += bits & BV(1);
421
+         // c += bits & BV(2);
422
+         // c += bits & BV(3);
423
+         // c += bits & BV(4);
424
+         // c += bits & BV(5);
425
+         // if (c >= 3) afsk->actualBits |= 1;
426
+        /////////////////////////////////////////////////
427
+
428
+        // Now we can pass the actual bit to the HDLC parser.
429
+        // We are using NRZ coding, so if 2 consecutive bits
430
+        // have the same value, we have a 1, otherwise a 0.
431
+        // We use the TRANSITION_FOUND function to determine this.
432
+        //
433
+        // This is smart in combination with bit stuffing,
434
+        // since it ensures a transmitter will never send more
435
+        // than five consecutive 1's. When sending consecutive
436
+        // ones, the signal stays at the same level, and if
437
+        // this happens for longer periods of time, we would
438
+        // not be able to synchronize our phase to the transmitter
439
+        // and would start experiencing "bit slip".
440
+        //
441
+        // By combining bit-stuffing with NRZ coding, we ensure
442
+        // that the signal will regularly make transitions
443
+        // that we can use to synchronize our phase.
444
+        //
445
+        // We also check the return of the Link Control parser
446
+        // to check if an error occured.
447
+
448
+        if (!hdlcParse(&afsk->hdlc, !TRANSITION_FOUND(afsk->actualBits), &afsk->rxFifo)) {
449
+            afsk->status |= 1;
450
+            if (fifo_isfull(&afsk->rxFifo)) {
451
+                fifo_flush(&afsk->rxFifo);
452
+                afsk->status = 0;
453
+            }
454
+        }
455
+    }
456
+
457
+}
458
+
459
+extern void APRS_poll();
460
+uint8_t poll_timer = 0;
461
+ISR(ADC_vect) {
462
+    TIFR1 = _BV(ICF1);
463
+    AFSK_adc_isr(AFSK_modem, ((int16_t)((ADC) >> 2) - 128));
464
+    if (hw_afsk_dac_isr) {
465
+        DAC_PORT = (AFSK_dac_isr(AFSK_modem) & 0xF0) | _BV(3); 
466
+    } else {
467
+        DAC_PORT = 128;
468
+    }
469
+
470
+    poll_timer++;
471
+    if (poll_timer > 3) {
472
+        poll_timer = 0;
473
+        APRS_poll();
474
+    }
475
+}

+ 138
- 0
lib/LibAPRS/AFSK.h View File

@@ -0,0 +1,138 @@
1
+#ifndef AFSK_H
2
+#define AFSK_H
3
+
4
+#include "device.h"
5
+#include <stdint.h>
6
+#include <stdbool.h>
7
+#include <stdio.h>
8
+#include <avr/pgmspace.h>
9
+#include "FIFO.h"
10
+#include "HDLC.h"
11
+
12
+#define SIN_LEN 512
13
+static const uint8_t sin_table[] PROGMEM =
14
+{
15
+    128, 129, 131, 132, 134, 135, 137, 138, 140, 142, 143, 145, 146, 148, 149, 151,
16
+    152, 154, 155, 157, 158, 160, 162, 163, 165, 166, 167, 169, 170, 172, 173, 175,
17
+    176, 178, 179, 181, 182, 183, 185, 186, 188, 189, 190, 192, 193, 194, 196, 197,
18
+    198, 200, 201, 202, 203, 205, 206, 207, 208, 210, 211, 212, 213, 214, 215, 217,
19
+    218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233,
20
+    234, 234, 235, 236, 237, 238, 238, 239, 240, 241, 241, 242, 243, 243, 244, 245,
21
+    245, 246, 246, 247, 248, 248, 249, 249, 250, 250, 250, 251, 251, 252, 252, 252,
22
+    253, 253, 253, 253, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255,
23
+};
24
+
25
+inline static uint8_t sinSample(uint16_t i) {
26
+    uint16_t newI = i % (SIN_LEN/2);
27
+    newI = (newI >= (SIN_LEN/4)) ? (SIN_LEN/2 - newI -1) : newI;
28
+    uint8_t sine = pgm_read_byte(&sin_table[newI]);
29
+    return (i >= (SIN_LEN/2)) ? (255 - sine) : sine;
30
+}
31
+
32
+
33
+#define SWITCH_TONE(inc)  (((inc) == MARK_INC) ? SPACE_INC : MARK_INC)
34
+#define BITS_DIFFER(bits1, bits2) (((bits1)^(bits2)) & 0x01)
35
+#define DUAL_XOR(bits1, bits2) ((((bits1)^(bits2)) & 0x03) == 0x03)
36
+#define SIGNAL_TRANSITIONED(bits) DUAL_XOR((bits), (bits) >> 2)
37
+#define TRANSITION_FOUND(bits) BITS_DIFFER((bits), (bits) >> 1)
38
+
39
+#define CPU_FREQ F_CPU
40
+
41
+#define CONFIG_AFSK_RX_BUFLEN 64
42
+#define CONFIG_AFSK_TX_BUFLEN 64   
43
+#define CONFIG_AFSK_RXTIMEOUT 0
44
+#define CONFIG_AFSK_PREAMBLE_LEN 150UL
45
+#define CONFIG_AFSK_TRAILER_LEN 50UL
46
+#define SAMPLERATE 9600
47
+#define BITRATE    1200
48
+#define SAMPLESPERBIT (SAMPLERATE / BITRATE)
49
+#define BIT_STUFF_LEN 5
50
+#define MARK_FREQ  1200
51
+#define SPACE_FREQ 2200
52
+#define PHASE_BITS   8                              // How much to increment phase counter each sample
53
+#define PHASE_INC    1                              // Nudge by an eigth of a sample each adjustment
54
+#define PHASE_MAX    (SAMPLESPERBIT * PHASE_BITS)   // Resolution of our phase counter = 64
55
+#define PHASE_THRESHOLD  (PHASE_MAX / 2)            // Target transition point of our phase window
56
+
57
+
58
+typedef struct Hdlc
59
+{
60
+    uint8_t demodulatedBits;
61
+    uint8_t bitIndex;
62
+    uint8_t currentByte;
63
+    bool receiving;
64
+} Hdlc;
65
+
66
+typedef struct Afsk
67
+{
68
+    // Stream access to modem
69
+    FILE fd;
70
+
71
+    // General values
72
+    Hdlc hdlc;                              // We need a link control structure
73
+    uint16_t preambleLength;                // Length of sync preamble
74
+    uint16_t tailLength;                    // Length of transmission tail
75
+
76
+    // Modulation values
77
+    uint8_t sampleIndex;                    // Current sample index for outgoing bit 
78
+    uint8_t currentOutputByte;              // Current byte to be modulated
79
+    uint8_t txBit;                          // Mask of current modulated bit
80
+    bool bitStuff;                          // Whether bitstuffing is allowed
81
+
82
+    uint8_t bitstuffCount;                  // Counter for bit-stuffing
83
+
84
+    uint16_t phaseAcc;                      // Phase accumulator
85
+    uint16_t phaseInc;                      // Phase increment per sample
86
+
87
+    FIFOBuffer txFifo;                      // FIFO for transmit data
88
+    uint8_t txBuf[CONFIG_AFSK_TX_BUFLEN];   // Actial data storage for said FIFO
89
+
90
+    volatile bool sending;                  // Set when modem is sending
91
+
92
+    // Demodulation values
93
+    FIFOBuffer delayFifo;                   // Delayed FIFO for frequency discrimination
94
+    int8_t delayBuf[SAMPLESPERBIT / 2 + 1]; // Actual data storage for said FIFO
95
+
96
+    FIFOBuffer rxFifo;                      // FIFO for received data
97
+    uint8_t rxBuf[CONFIG_AFSK_RX_BUFLEN];   // Actual data storage for said FIFO
98
+
99
+    int16_t iirX[2];                        // IIR Filter X cells
100
+    int16_t iirY[2];                        // IIR Filter Y cells
101
+
102
+    uint8_t sampledBits;                    // Bits sampled by the demodulator (at ADC speed)
103
+    int8_t currentPhase;                    // Current phase of the demodulator
104
+    uint8_t actualBits;                     // Actual found bits at correct bitrate
105
+
106
+    volatile int status;                    // Status of the modem, 0 means OK
107
+
108
+} Afsk;
109
+
110
+#define DIV_ROUND(dividend, divisor)  (((dividend) + (divisor) / 2) / (divisor))
111
+#define MARK_INC   (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)MARK_FREQ, CONFIG_AFSK_DAC_SAMPLERATE))
112
+#define SPACE_INC  (uint16_t)(DIV_ROUND(SIN_LEN * (uint32_t)SPACE_FREQ, CONFIG_AFSK_DAC_SAMPLERATE))
113
+
114
+#define AFSK_DAC_IRQ_START()   do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = true; } while (0)
115
+#define AFSK_DAC_IRQ_STOP()    do { extern bool hw_afsk_dac_isr; hw_afsk_dac_isr = false; } while (0)
116
+#define AFSK_DAC_INIT()        do { DAC_DDR |= 0xF8; } while (0)
117
+
118
+// Here's some macros for controlling the RX/TX LEDs
119
+// THE _INIT() functions writes to the DDRB register
120
+// to configure the pins as output pins, and the _ON()
121
+// and _OFF() functions writes to the PORT registers
122
+// to turn the pins on or off.
123
+#define LED_TX_INIT() do { LED_DDR |= _BV(1); } while (0)
124
+#define LED_TX_ON()   do { LED_PORT |= _BV(1); } while (0)
125
+#define LED_TX_OFF()  do { LED_PORT &= ~_BV(1); } while (0)
126
+
127
+#define LED_RX_INIT() do { LED_DDR |= _BV(2); } while (0)
128
+#define LED_RX_ON()   do { LED_PORT |= _BV(2); } while (0)
129
+#define LED_RX_OFF()  do { LED_PORT &= ~_BV(2); } while (0)
130
+
131
+void AFSK_init(Afsk *afsk);
132
+void AFSK_transmit(char *buffer, size_t size);
133
+void AFSK_poll(Afsk *afsk);
134
+
135
+void afsk_putchar(char c);
136
+int afsk_getchar(void);
137
+
138
+#endif

+ 164
- 0
lib/LibAPRS/AX25.cpp View File

@@ -0,0 +1,164 @@
1
+// Based on work by Francesco Sacchi
2
+
3
+#include "Arduino.h"
4
+#include <string.h>
5
+#include <ctype.h>
6
+#include "AX25.h"
7
+#include "HDLC.h"
8
+#include "CRC-CCIT.h"
9
+#include "AFSK.h"
10
+
11
+#define countof(a) sizeof(a)/sizeof(a[0])
12
+#define MIN(a,b) ({ typeof(a) _a = (a); typeof(b) _b = (b); ((typeof(_a))((_a < _b) ? _a : _b)); })
13
+#define DECODE_CALL(buf, addr) for (unsigned i = 0; i < sizeof((addr))-CALL_OVERSPACE; i++) { char c = (*(buf)++ >> 1); (addr)[i] = (c == ' ') ? '\x0' : c; }
14
+#define AX25_SET_REPEATED(msg, idx, val) do { if (val) { (msg)->rpt_flags |= _BV(idx); } else { (msg)->rpt_flags &= ~_BV(idx) ; } } while(0)
15
+
16
+extern int LibAPRS_vref;
17
+extern bool LibAPRS_open_squelch;
18
+
19
+void ax25_init(AX25Ctx *ctx, ax25_callback_t hook) {
20
+    memset(ctx, 0, sizeof(*ctx));
21
+    ctx->hook = hook;
22
+    ctx->crc_in = ctx->crc_out = CRC_CCIT_INIT_VAL;
23
+}
24
+
25
+static void ax25_decode(AX25Ctx *ctx) {
26
+    AX25Msg msg;
27
+    uint8_t *buf = ctx->buf;
28
+
29
+    DECODE_CALL(buf, msg.dst.call);
30
+    msg.dst.ssid = (*buf++ >> 1) & 0x0F;
31
+    msg.dst.call[6] = 0;
32
+
33
+    DECODE_CALL(buf, msg.src.call);
34
+    msg.src.ssid = (*buf >> 1) & 0x0F;
35
+    msg.src.call[6] = 0;
36
+
37
+    for (msg.rpt_count = 0; !(*buf++ & 0x01) && (msg.rpt_count < countof(msg.rpt_list)); msg.rpt_count++) {
38
+        DECODE_CALL(buf, msg.rpt_list[msg.rpt_count].call);
39
+        msg.rpt_list[msg.rpt_count].ssid = (*buf >> 1) & 0x0F;
40
+        AX25_SET_REPEATED(&msg, msg.rpt_count, (*buf & 0x80));
41
+    }
42
+
43
+    msg.ctrl = *buf++;
44
+    if (msg.ctrl != AX25_CTRL_UI) { return; }
45
+
46
+    msg.pid = *buf++;
47
+    if (msg.pid != AX25_PID_NOLAYER3) { return; }
48
+
49
+    msg.len = ctx->frame_len - 2 - (buf - ctx->buf);
50
+    msg.info = buf;
51
+
52
+    if (ctx->hook) {
53
+        cli();
54
+        ctx->hook(&msg);
55
+        sei();
56
+    }   
57
+
58
+}
59
+
60
+void ax25_poll(AX25Ctx *ctx) {
61
+    int c;
62
+
63
+    while ((c = afsk_getchar()) != EOF) {
64
+        if (!ctx->escape && c == HDLC_FLAG) {
65
+            if (ctx->frame_len >= AX25_MIN_FRAME_LEN) {
66
+                if (ctx->crc_in == AX25_CRC_CORRECT) {
67
+                    if(LibAPRS_open_squelch) {
68
+                        LED_RX_ON();
69
+                    }
70
+                    ax25_decode(ctx);
71
+                }
72
+            }
73
+            ctx->sync = true;
74
+            ctx->crc_in = CRC_CCIT_INIT_VAL;
75
+            ctx->frame_len = 0;
76
+            continue;
77
+        }
78
+
79
+        if (!ctx->escape && c == HDLC_RESET) {
80
+            ctx->sync = false;
81
+            continue;
82
+        }
83
+
84
+        if (!ctx->escape && c == AX25_ESC) {
85
+            ctx->escape = true;
86
+            continue;
87
+        }
88
+
89
+        if (ctx->sync) {
90
+            if (ctx->frame_len < AX25_MAX_FRAME_LEN) {
91
+                ctx->buf[ctx->frame_len++] = c;
92
+                ctx->crc_in = update_crc_ccit(c, ctx->crc_in);
93
+            } else {
94
+                ctx->sync = false;
95
+            }
96
+        }
97
+        ctx->escape = false;
98
+    }
99
+}
100
+
101
+static void ax25_putchar(AX25Ctx *ctx, uint8_t c)
102
+{
103
+    if (c == HDLC_FLAG || c == HDLC_RESET || c == AX25_ESC) afsk_putchar(AX25_ESC);
104
+    ctx->crc_out = update_crc_ccit(c, ctx->crc_out);
105
+    afsk_putchar(c);
106
+}
107
+
108
+void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len) {
109
+    ctx->crc_out = CRC_CCIT_INIT_VAL;
110
+    afsk_putchar(HDLC_FLAG);
111
+    const uint8_t *buf = (const uint8_t *)_buf;
112
+    while (len--) ax25_putchar(ctx, *buf++);
113
+
114
+    uint8_t crcl = (ctx->crc_out & 0xff) ^ 0xff;
115
+    uint8_t crch = (ctx->crc_out >> 8) ^ 0xff;
116
+    ax25_putchar(ctx, crcl);
117
+    ax25_putchar(ctx, crch);
118
+
119
+    afsk_putchar(HDLC_FLAG);
120
+}
121
+
122
+static void ax25_sendCall(AX25Ctx *ctx, const AX25Call *addr, bool last){
123
+    unsigned len = MIN((sizeof(addr->call) - CALL_OVERSPACE), strlen(addr->call));
124
+
125
+    for (unsigned i = 0; i < len; i++) {
126
+        uint8_t c = addr->call[i];
127
+        c = toupper(c);
128
+        ax25_putchar(ctx, c << 1);
129
+    }
130
+
131
+    if (len < (sizeof(addr->call) - CALL_OVERSPACE)) {
132
+        for (unsigned i = 0; i < (sizeof(addr->call) - CALL_OVERSPACE) - len; i++) {
133
+            ax25_putchar(ctx, ' ' << 1);
134
+        }
135
+    }
136
+
137
+    uint8_t ssid = 0x60 | (addr->ssid << 1) | (last ? 0x01 : 0);
138
+    ax25_putchar(ctx, ssid);
139
+}
140
+
141
+void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len) {
142
+    const uint8_t *buf = (const uint8_t *)_buf;
143
+
144
+    ctx->crc_out = CRC_CCIT_INIT_VAL;
145
+    afsk_putchar(HDLC_FLAG);
146
+
147
+    for (size_t i = 0; i < path_len; i++) {
148
+        ax25_sendCall(ctx, &path[i], (i == path_len - 1));
149
+    }
150
+
151
+    ax25_putchar(ctx, AX25_CTRL_UI);
152
+    ax25_putchar(ctx, AX25_PID_NOLAYER3);
153
+
154
+    while (len--) {
155
+        ax25_putchar(ctx, *buf++);
156
+    }
157
+
158
+    uint8_t crcl = (ctx->crc_out & 0xff) ^ 0xff;
159
+    uint8_t crch = (ctx->crc_out >> 8) ^ 0xff;
160
+    ax25_putchar(ctx, crcl);
161
+    ax25_putchar(ctx, crch);
162
+
163
+    afsk_putchar(HDLC_FLAG);
164
+}

+ 70
- 0
lib/LibAPRS/AX25.h View File

@@ -0,0 +1,70 @@
1
+#ifndef PROTOCOL_AX25_H
2
+#define PROTOCOL_AX25_H
3
+
4
+#include <stdio.h>
5
+#include <stdbool.h>
6
+#include "device.h"
7
+
8
+#define AX25_MIN_FRAME_LEN 18
9
+#ifndef CUSTOM_FRAME_SIZE
10
+    #define AX25_MAX_FRAME_LEN 330
11
+#else
12
+    #define AX25_MAX_FRAME_LEN CUSTOM_FRAME_SIZE
13
+#endif
14
+
15
+#define AX25_CRC_CORRECT  0xF0B8
16
+
17
+#define AX25_CTRL_UI      0x03
18
+#define AX25_PID_NOLAYER3 0xF0
19
+
20
+struct AX25Ctx;     // Forward declarations
21
+struct AX25Msg;
22
+
23
+typedef void (*ax25_callback_t)(struct AX25Msg *msg);
24
+
25
+typedef struct AX25Ctx {
26
+    uint8_t buf[AX25_MAX_FRAME_LEN];
27
+    FILE *ch;
28
+    size_t frame_len;
29
+    uint16_t crc_in;
30
+    uint16_t crc_out;
31
+    ax25_callback_t hook;
32
+    bool sync;
33
+    bool escape;
34
+} AX25Ctx;
35
+
36
+
37
+#define AX25_CALL(str, id) {.call = (str), .ssid = (id) }
38
+#define AX25_MAX_RPT 8
39
+#define AX25_REPEATED(msg, n) ((msg)->rpt_flags & BV(n))
40
+
41
+#define CALL_OVERSPACE 1
42
+
43
+typedef struct AX25Call {
44
+    char call[6+CALL_OVERSPACE];
45
+    //char STRING_TERMINATION = 0;
46
+    uint8_t ssid;
47
+} AX25Call;
48
+
49
+typedef struct AX25Msg {
50
+    AX25Call src;
51
+    AX25Call dst;
52
+    AX25Call rpt_list[AX25_MAX_RPT];
53
+    uint8_t  rpt_count;
54
+    uint8_t  rpt_flags;
55
+    uint16_t ctrl;
56
+    uint8_t  pid;
57
+    const uint8_t *info;
58
+    size_t len;
59
+} AX25Msg;
60
+
61
+void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len);
62
+#define ax25_send(ctx, dst, src, buf, len) ax25_sendVia(ctx, ({static AX25Call __path[]={dst, src}; __path;}), 2, buf, len)
63
+
64
+
65
+
66
+void ax25_poll(AX25Ctx *ctx);
67
+void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len);
68
+void ax25_init(AX25Ctx *ctx, ax25_callback_t hook);
69
+
70
+#endif

+ 36
- 0
lib/LibAPRS/CRC-CCIT.c View File

@@ -0,0 +1,36 @@
1
+#include "CRC-CCIT.h"
2
+
3
+const uint16_t crc_ccit_table[256] PROGMEM = {
4
+    0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
5
+    0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
6
+    0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
7
+    0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
8
+    0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd,
9
+    0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5,
10
+    0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c,
11
+    0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974,
12
+    0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb,
13
+    0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3,
14
+    0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a,
15
+    0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72,
16
+    0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9,
17
+    0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1,
18
+    0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738,
19
+    0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70,
20
+    0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7,
21
+    0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff,
22
+    0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036,
23
+    0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e,
24
+    0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5,
25
+    0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd,
26
+    0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134,
27
+    0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c,
28
+    0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3,
29
+    0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb,
30
+    0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232,
31
+    0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a,
32
+    0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1,
33
+    0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9,
34
+    0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330,
35
+    0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78,
36
+};

+ 18
- 0
lib/LibAPRS/CRC-CCIT.h View File

@@ -0,0 +1,18 @@
1
+// CRC-CCIT Implementation based on work by Francesco Sacchi
2
+
3
+#ifndef CRC_CCIT_H
4
+#define CRC_CCIT_H
5
+
6
+#include <stdint.h>
7
+#include <avr/pgmspace.h>
8
+
9
+#define CRC_CCIT_INIT_VAL ((uint16_t)0xFFFF)
10
+
11
+extern const uint16_t crc_ccit_table[256];
12
+
13
+inline uint16_t update_crc_ccit(uint8_t c, uint16_t prev_crc) {
14
+    return (prev_crc >> 8) ^ pgm_read_word(&crc_ccit_table[(prev_crc ^ c) & 0xff]);
15
+}
16
+
17
+
18
+#endif

+ 85
- 0
lib/LibAPRS/FIFO.h View File

@@ -0,0 +1,85 @@
1
+#ifndef UTIL_FIFO_H
2
+#define UTIL_FIFO_H
3
+
4
+#include <stddef.h>
5
+#include <util/atomic.h>
6
+
7
+typedef struct FIFOBuffer
8
+{
9
+  unsigned char *begin;
10
+  unsigned char *end;
11
+  unsigned char * volatile head;
12
+  unsigned char * volatile tail;
13
+} FIFOBuffer;
14
+
15
+inline bool fifo_isempty(const FIFOBuffer *f) {
16
+  return f->head == f->tail;
17
+}
18
+
19
+inline bool fifo_isfull(const FIFOBuffer *f) {
20
+  return ((f->head == f->begin) && (f->tail == f->end)) || (f->tail == f->head - 1);
21
+}
22
+
23
+inline void fifo_push(FIFOBuffer *f, unsigned char c) {
24
+  *(f->tail) = c;
25
+  
26
+  if (f->tail == f->end) {
27
+    f->tail = f->begin;
28
+  } else {
29
+    f->tail++;
30
+  }
31
+}
32
+
33
+inline unsigned char fifo_pop(FIFOBuffer *f) {
34
+  if(f->head == f->end) {
35
+    f->head = f->begin;
36
+    return *(f->end);
37
+  } else {
38
+    return *(f->head++);
39
+  }
40
+}
41
+
42
+inline void fifo_flush(FIFOBuffer *f) {
43
+  f->head = f->tail;
44
+}
45
+
46
+inline bool fifo_isempty_locked(const FIFOBuffer *f) {
47
+  bool result;
48
+  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
49
+    result = fifo_isempty(f);
50
+  }
51
+  return result;
52
+}
53
+
54
+inline bool fifo_isfull_locked(const FIFOBuffer *f) {
55
+  bool result;
56
+  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
57
+    result = fifo_isfull(f);
58
+  }
59
+  return result;
60
+}
61
+
62
+inline void fifo_push_locked(FIFOBuffer *f, unsigned char c) {
63
+  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
64
+    fifo_push(f, c);
65
+  }
66
+}
67
+
68
+inline unsigned char fifo_pop_locked(FIFOBuffer *f) {
69
+  unsigned char c;
70
+  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
71
+    c = fifo_pop(f);
72
+  }
73
+  return c;
74
+}
75
+
76
+inline void fifo_init(FIFOBuffer *f, unsigned char *buffer, size_t size) {
77
+  f->head = f->tail = f->begin = buffer;
78
+  f->end = buffer + size -1;
79
+}
80
+
81
+inline size_t fifo_len(FIFOBuffer *f) {
82
+  return f->end - f->begin;
83
+}
84
+
85
+#endif

+ 8
- 0
lib/LibAPRS/HDLC.h View File

@@ -0,0 +1,8 @@
1
+#ifndef PROTOCOL_HDLC_H
2
+#define PROTOCOL_HDLC_H
3
+
4
+#define HDLC_FLAG  0x7E
5
+#define HDLC_RESET 0x7F
6
+#define AX25_ESC   0x1B
7
+
8
+#endif

+ 677
- 0
lib/LibAPRS/LICENSE View File

@@ -0,0 +1,677 @@
1
+(This project uses BertOS for some functionality. BertOS is licensed under GPLv2. Please see http://www.bertos.org for details. All files in the "bertos" directory originates from BertOS.)
2
+
3
+GNU GENERAL PUBLIC LICENSE
4
+                       Version 3, 29 June 2007
5
+
6
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
7
+ Everyone is permitted to copy and distribute verbatim copies
8
+ of this license document, but changing it is not allowed.
9
+
10
+                            Preamble
11
+
12
+  The GNU General Public License is a free, copyleft license for
13
+software and other kinds of works.
14
+
15
+  The licenses for most software and other practical works are designed
16
+to take away your freedom to share and change the works.  By contrast,
17
+the GNU General Public License is intended to guarantee your freedom to
18
+share and change all versions of a program--to make sure it remains free
19
+software for all its users.  We, the Free Software Foundation, use the
20
+GNU General Public License for most of our software; it applies also to
21
+any other work released this way by its authors.  You can apply it to
22
+your programs, too.
23
+
24
+  When we speak of free software, we are referring to freedom, not
25
+price.  Our General Public Licenses are designed to make sure that you
26
+have the freedom to distribute copies of free software (and charge for
27
+them if you wish), that you receive source code or can get it if you
28
+want it, that you can change the software or use pieces of it in new
29
+free programs, and that you know you can do these things.
30
+
31
+  To protect your rights, we need to prevent others from denying you
32
+these rights or asking you to surrender the rights.  Therefore, you have
33
+certain responsibilities if you distribute copies of the software, or if
34
+you modify it: responsibilities to respect the freedom of others.
35
+
36
+  For example, if you distribute copies of such a program, whether
37
+gratis or for a fee, you must pass on to the recipients the same
38
+freedoms that you received.  You must make sure that they, too, receive
39
+or can get the source code.  And you must show them these terms so they
40
+know their rights.
41
+
42
+  Developers that use the GNU GPL protect your rights with two steps:
43
+(1) assert copyright on the software, and (2) offer you this License
44
+giving you legal permission to copy, distribute and/or modify it.
45
+
46
+  For the developers' and authors' protection, the GPL clearly explains
47
+that there is no warranty for this free software.  For both users' and
48
+authors' sake, the GPL requires that modified versions be marked as
49
+changed, so that their problems will not be attributed erroneously to
50
+authors of previous versions.
51
+
52
+  Some devices are designed to deny users access to install or run
53
+modified versions of the software inside them, although the manufacturer
54
+can do so.  This is fundamentally incompatible with the aim of
55
+protecting users' freedom to change the software.  The systematic
56
+pattern of such abuse occurs in the area of products for individuals to
57
+use, which is precisely where it is most unacceptable.  Therefore, we
58
+have designed this version of the GPL to prohibit the practice for those
59
+products.  If such problems arise substantially in other domains, we
60
+stand ready to extend this provision to those domains in future versions
61
+of the GPL, as needed to protect the freedom of users.
62
+
63
+  Finally, every program is threatened constantly by software patents.
64
+States should not allow patents to restrict development and use of
65
+software on general-purpose computers, but in those that do, we wish to
66
+avoid the special danger that patents applied to a free program could
67
+make it effectively proprietary.  To prevent this, the GPL assures that
68
+patents cannot be used to render the program non-free.
69
+
70
+  The precise terms and conditions for copying, distribution and
71
+modification follow.
72
+
73
+                       TERMS AND CONDITIONS
74
+
75
+  0. Definitions.
76
+
77
+  "This License" refers to version 3 of the GNU General Public License.
78
+
79
+  "Copyright" also means copyright-like laws that apply to other kinds of
80
+works, such as semiconductor masks.
81
+
82
+  "The Program" refers to any copyrightable work licensed under this
83
+License.  Each licensee is addressed as "you".  "Licensees" and
84
+"recipients" may be individuals or organizations.
85
+
86
+  To "modify" a work means to copy from or adapt all or part of the work
87
+in a fashion requiring copyright permission, other than the making of an
88
+exact copy.  The resulting work is called a "modified version" of the
89
+earlier work or a work "based on" the earlier work.
90
+
91
+  A "covered work" means either the unmodified Program or a work based
92
+on the Program.
93
+
94
+  To "propagate" a work means to do anything with it that, without
95
+permission, would make you directly or secondarily liable for
96
+infringement under applicable copyright law, except executing it on a
97
+computer or modifying a private copy.  Propagation includes copying,
98
+distribution (with or without modification), making available to the
99
+public, and in some countries other activities as well.
100
+
101
+  To "convey" a work means any kind of propagation that enables other
102
+parties to make or receive copies.  Mere interaction with a user through
103
+a computer network, with no transfer of a copy, is not conveying.
104
+
105
+  An interactive user interface displays "Appropriate Legal Notices"
106
+to the extent that it includes a convenient and prominently visible
107
+feature that (1) displays an appropriate copyright notice, and (2)
108
+tells the user that there is no warranty for the work (except to the
109
+extent that warranties are provided), that licensees may convey the
110
+work under this License, and how to view a copy of this License.  If
111
+the interface presents a list of user commands or options, such as a
112
+menu, a prominent item in the list meets this criterion.
113
+
114
+  1. Source Code.
115
+
116
+  The "source code" for a work means the preferred form of the work
117
+for making modifications to it.  "Object code" means any non-source
118
+form of a work.
119
+
120
+  A "Standard Interface" means an interface that either is an official
121
+standard defined by a recognized standards body, or, in the case of
122
+interfaces specified for a particular programming language, one that
123
+is widely used among developers working in that language.
124
+
125
+  The "System Libraries" of an executable work include anything, other
126
+than the work as a whole, that (a) is included in the normal form of
127
+packaging a Major Component, but which is not part of that Major
128
+Component, and (b) serves only to enable use of the work with that
129
+Major Component, or to implement a Standard Interface for which an
130
+implementation is available to the public in source code form.  A
131
+"Major Component", in this context, means a major essential component
132
+(kernel, window system, and so on) of the specific operating system
133
+(if any) on which the executable work runs, or a compiler used to
134
+produce the work, or an object code interpreter used to run it.
135
+
136
+  The "Corresponding Source" for a work in object code form means all
137
+the source code needed to generate, install, and (for an executable
138
+work) run the object code and to modify the work, including scripts to
139
+control those activities.  However, it does not include the work's
140
+System Libraries, or general-purpose tools or generally available free
141
+programs which are used unmodified in performing those activities but
142
+which are not part of the work.  For example, Corresponding Source
143
+includes interface definition files associated with source files for
144
+the work, and the source code for shared libraries and dynamically
145
+linked subprograms that the work is specifically designed to require,
146
+such as by intimate data communication or control flow between those
147
+subprograms and other parts of the work.
148
+
149
+  The Corresponding Source need not include anything that users
150
+can regenerate automatically from other parts of the Corresponding
151
+Source.
152
+
153
+  The Corresponding Source for a work in source code form is that
154
+same work.
155
+
156
+  2. Basic Permissions.
157
+
158
+  All rights granted under this License are granted for the term of
159
+copyright on the Program, and are irrevocable provided the stated
160
+conditions are met.  This License explicitly affirms your unlimited
161
+permission to run the unmodified Program.  The output from running a
162
+covered work is covered by this License only if the output, given its
163
+content, constitutes a covered work.  This License acknowledges your
164
+rights of fair use or other equivalent, as provided by copyright law.
165
+
166
+  You may make, run and propagate covered works that you do not
167
+convey, without conditions so long as your license otherwise remains
168
+in force.  You may convey covered works to others for the sole purpose
169
+of having them make modifications exclusively for you, or provide you
170
+with facilities for running those works, provided that you comply with
171
+the terms of this License in conveying all material for which you do
172
+not control copyright.  Those thus making or running the covered works
173
+for you must do so exclusively on your behalf, under your direction
174
+and control, on terms that prohibit them from making any copies of
175
+your copyrighted material outside their relationship with you.
176
+
177
+  Conveying under any other circumstances is permitted solely under
178
+the conditions stated below.  Sublicensing is not allowed; section 10
179
+makes it unnecessary.
180
+
181
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
182
+
183
+  No covered work shall be deemed part of an effective technological
184
+measure under any applicable law fulfilling obligations under article
185
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
186
+similar laws prohibiting or restricting circumvention of such
187
+measures.
188
+
189
+  When you convey a covered work, you waive any legal power to forbid
190
+circumvention of technological measures to the extent such circumvention
191
+is effected by exercising rights under this License with respect to
192
+the covered work, and you disclaim any intention to limit operation or
193
+modification of the work as a means of enforcing, against the work's
194
+users, your or third parties' legal rights to forbid circumvention of
195
+technological measures.
196
+
197
+  4. Conveying Verbatim Copies.
198
+
199
+  You may convey verbatim copies of the Program's source code as you
200
+receive it, in any medium, provided that you conspicuously and
201
+appropriately publish on each copy an appropriate copyright notice;
202
+keep intact all notices stating that this License and any
203
+non-permissive terms added in accord with section 7 apply to the code;
204
+keep intact all notices of the absence of any warranty; and give all
205
+recipients a copy of this License along with the Program.
206
+
207
+  You may charge any price or no price for each copy that you convey,
208
+and you may offer support or warranty protection for a fee.
209
+
210
+  5. Conveying Modified Source Versions.
211
+
212
+  You may convey a work based on the Program, or the modifications to
213
+produce it from the Program, in the form of source code under the
214
+terms of section 4, provided that you also meet all of these conditions:
215
+
216
+    a) The work must carry prominent notices stating that you modified
217
+    it, and giving a relevant date.
218
+
219
+    b) The work must carry prominent notices stating that it is
220
+    released under this License and any conditions added under section
221
+    7.  This requirement modifies the requirement in section 4 to
222
+    "keep intact all notices".
223
+
224
+    c) You must license the entire work, as a whole, under this
225
+    License to anyone who comes into possession of a copy.  This
226
+    License will therefore apply, along with any applicable section 7
227
+    additional terms, to the whole of the work, and all its parts,
228
+    regardless of how they are packaged.  This License gives no
229
+    permission to license the work in any other way, but it does not
230
+    invalidate such permission if you have separately received it.
231
+
232
+    d) If the work has interactive user interfaces, each must display
233
+    Appropriate Legal Notices; however, if the Program has interactive
234
+    interfaces that do not display Appropriate Legal Notices, your
235
+    work need not make them do so.
236
+
237
+  A compilation of a covered work with other separate and independent
238
+works, which are not by their nature extensions of the covered work,
239
+and which are not combined with it such as to form a larger program,
240
+in or on a volume of a storage or distribution medium, is called an
241
+"aggregate" if the compilation and its resulting copyright are not
242
+used to limit the access or legal rights of the compilation's users
243
+beyond what the individual works permit.  Inclusion of a covered work
244
+in an aggregate does not cause this License to apply to the other
245
+parts of the aggregate.
246
+
247
+  6. Conveying Non-Source Forms.
248
+
249
+  You may convey a covered work in object code form under the terms
250
+of sections 4 and 5, provided that you also convey the
251
+machine-readable Corresponding Source under the terms of this License,
252
+in one of these ways:
253
+
254
+    a) Convey the object code in, or embodied in, a physical product
255
+    (including a physical distribution medium), accompanied by the
256
+    Corresponding Source fixed on a durable physical medium
257
+    customarily used for software interchange.
258
+
259
+    b) Convey the object code in, or embodied in, a physical product
260
+    (including a physical distribution medium), accompanied by a
261
+    written offer, valid for at least three years and valid for as
262
+    long as you offer spare parts or customer support for that product
263
+    model, to give anyone who possesses the object code either (1) a
264
+    copy of the Corresponding Source for all the software in the
265
+    product that is covered by this License, on a durable physical
266
+    medium customarily used for software interchange, for a price no
267
+    more than your reasonable cost of physically performing this
268
+    conveying of source, or (2) access to copy the
269
+    Corresponding Source from a network server at no charge.
270
+
271
+    c) Convey individual copies of the object code with a copy of the
272
+    written offer to provide the Corresponding Source.  This
273
+    alternative is allowed only occasionally and noncommercially, and
274
+    only if you received the object code with such an offer, in accord
275
+    with subsection 6b.
276
+
277
+    d) Convey the object code by offering access from a designated
278
+    place (gratis or for a charge), and offer equivalent access to the
279
+    Corresponding Source in the same way through the same place at no
280
+    further charge.  You need not require recipients to copy the
281
+    Corresponding Source along with the object code.  If the place to
282
+    copy the object code is a network server, the Corresponding Source
283
+    may be on a different server (operated by you or a third party)
284
+    that supports equivalent copying facilities, provided you maintain
285
+    clear directions next to the object code saying where to find the
286
+    Corresponding Source.  Regardless of what server hosts the
287
+    Corresponding Source, you remain obligated to ensure that it is
288
+    available for as long as needed to satisfy these requirements.
289
+
290
+    e) Convey the object code using peer-to-peer transmission, provided
291
+    you inform other peers where the object code and Corresponding
292
+    Source of the work are being offered to the general public at no
293
+    charge under subsection 6d.
294
+
295
+  A separable portion of the object code, whose source code is excluded
296
+from the Corresponding Source as a System Library, need not be
297
+included in conveying the object code work.
298
+
299
+  A "User Product" is either (1) a "consumer product", which means any
300
+tangible personal property which is normally used for personal, family,
301
+or household purposes, or (2) anything designed or sold for incorporation
302
+into a dwelling.  In determining whether a product is a consumer product,
303
+doubtful cases shall be resolved in favor of coverage.  For a particular
304
+product received by a particular user, "normally used" refers to a
305
+typical or common use of that class of product, regardless of the status
306
+of the particular user or of the way in which the particular user
307
+actually uses, or expects or is expected to use, the product.  A product
308
+is a consumer product regardless of whether the product has substantial
309
+commercial, industrial or non-consumer uses, unless such uses represent
310
+the only significant mode of use of the product.
311
+
312
+  "Installation Information" for a User Product means any methods,
313
+procedures, authorization keys, or other information required to install
314
+and execute modified versions of a covered work in that User Product from
315
+a modified version of its Corresponding Source.  The information must
316
+suffice to ensure that the continued functioning of the modified object
317
+code is in no case prevented or interfered with solely because
318
+modification has been made.
319
+
320
+  If you convey an object code work under this section in, or with, or
321
+specifically for use in, a User Product, and the conveying occurs as
322
+part of a transaction in which the right of possession and use of the
323
+User Product is transferred to the recipient in perpetuity or for a
324
+fixed term (regardless of how the transaction is characterized), the
325
+Corresponding Source conveyed under this section must be accompanied
326
+by the Installation Information.  But this requirement does not apply
327
+if neither you nor any third party retains the ability to install
328
+modified object code on the User Product (for example, the work has
329
+been installed in ROM).
330
+
331
+  The requirement to provide Installation Information does not include a
332
+requirement to continue to provide support service, warranty, or updates
333
+for a work that has been modified or installed by the recipient, or for
334
+the User Product in which it has been modified or installed.  Access to a
335
+network may be denied when the modification itself materially and
336
+adversely affects the operation of the network or violates the rules and
337
+protocols for communication across the network.
338
+
339
+  Corresponding Source conveyed, and Installation Information provided,
340
+in accord with this section must be in a format that is publicly
341
+documented (and with an implementation available to the public in
342
+source code form), and must require no special password or key for
343
+unpacking, reading or copying.
344
+
345
+  7. Additional Terms.
346
+
347
+  "Additional permissions" are terms that supplement the terms of this
348
+License by making exceptions from one or more of its conditions.
349
+Additional permissions that are applicable to the entire Program shall
350
+be treated as though they were included in this License, to the extent
351
+that they are valid under applicable law.  If additional permissions
352
+apply only to part of the Program, that part may be used separately
353
+under those permissions, but the entire Program remains governed by
354
+this License without regard to the additional permissions.
355
+
356
+  When you convey a copy of a covered work, you may at your option
357
+remove any additional permissions from that copy, or from any part of
358
+it.  (Additional permissions may be written to require their own
359
+removal in certain cases when you modify the work.)  You may place
360
+additional permissions on material, added by you to a covered work,
361
+for which you have or can give appropriate copyright permission.
362
+
363
+  Notwithstanding any other provision of this License, for material you
364
+add to a covered work, you may (if authorized by the copyright holders of
365
+that material) supplement the terms of this License with terms:
366
+
367
+    a) Disclaiming warranty or limiting liability differently from the
368
+    terms of sections 15 and 16 of this License; or
369
+
370
+    b) Requiring preservation of specified reasonable legal notices or
371
+    author attributions in that material or in the Appropriate Legal
372
+    Notices displayed by works containing it; or
373
+
374
+    c) Prohibiting misrepresentation of the origin of that material, or
375
+    requiring that modified versions of such material be marked in
376
+    reasonable ways as different from the original version; or
377
+
378
+    d) Limiting the use for publicity purposes of names of licensors or
379
+    authors of the material; or
380
+
381
+    e) Declining to grant rights under trademark law for use of some
382
+    trade names, trademarks, or service marks; or
383
+
384
+    f) Requiring indemnification of licensors and authors of that
385
+    material by anyone who conveys the material (or modified versions of
386
+    it) with contractual assumptions of liability to the recipient, for
387
+    any liability that these contractual assumptions directly impose on
388
+    those licensors and authors.
389
+
390
+  All other non-permissive additional terms are considered "further
391
+restrictions" within the meaning of section 10.  If the Program as you
392
+received it, or any part of it, contains a notice stating that it is
393
+governed by this License along with a term that is a further
394
+restriction, you may remove that term.  If a license document contains
395
+a further restriction but permits relicensing or conveying under this
396
+License, you may add to a covered work material governed by the terms
397
+of that license document, provided that the further restriction does
398
+not survive such relicensing or conveying.
399
+
400
+  If you add terms to a covered work in accord with this section, you
401
+must place, in the relevant source files, a statement of the
402
+additional terms that apply to those files, or a notice indicating
403
+where to find the applicable terms.
404
+
405
+  Additional terms, permissive or non-permissive, may be stated in the
406
+form of a separately written license, or stated as exceptions;
407
+the above requirements apply either way.
408
+
409
+  8. Termination.
410
+
411
+  You may not propagate or modify a covered work except as expressly
412
+provided under this License.  Any attempt otherwise to propagate or
413
+modify it is void, and will automatically terminate your rights under
414
+this License (including any patent licenses granted under the third
415
+paragraph of section 11).
416
+
417
+  However, if you cease all violation of this License, then your
418
+license from a particular copyright holder is reinstated (a)
419
+provisionally, unless and until the copyright holder explicitly and
420
+finally terminates your license, and (b) permanently, if the copyright
421
+holder fails to notify you of the violation by some reasonable means
422
+prior to 60 days after the cessation.
423
+
424
+  Moreover, your license from a particular copyright holder is
425
+reinstated permanently if the copyright holder notifies you of the
426
+violation by some reasonable means, this is the first time you have
427
+received notice of violation of this License (for any work) from that
428
+copyright holder, and you cure the violation prior to 30 days after
429
+your receipt of the notice.
430
+
431
+  Termination of your rights under this section does not terminate the
432
+licenses of parties who have received copies or rights from you under
433
+this License.  If your rights have been terminated and not permanently
434
+reinstated, you do not qualify to receive new licenses for the same
435
+material under section 10.
436
+
437
+  9. Acceptance Not Required for Having Copies.
438
+
439
+  You are not required to accept this License in order to receive or
440
+run a copy of the Program.  Ancillary propagation of a covered work
441
+occurring solely as a consequence of using peer-to-peer transmission
442
+to receive a copy likewise does not require acceptance.  However,
443
+nothing other than this License grants you permission to propagate or
444
+modify any covered work.  These actions infringe copyright if you do
445
+not accept this License.  Therefore, by modifying or propagating a
446
+covered work, you indicate your acceptance of this License to do so.
447
+
448
+  10. Automatic Licensing of Downstream Recipients.
449
+
450
+  Each time you convey a covered work, the recipient automatically
451
+receives a license from the original licensors, to run, modify and
452
+propagate that work, subject to this License.  You are not responsible
453
+for enforcing compliance by third parties with this License.
454
+
455
+  An "entity transaction" is a transaction transferring control of an
456
+organization, or substantially all assets of one, or subdividing an
457
+organization, or merging organizations.  If propagation of a covered
458
+work results from an entity transaction, each party to that
459
+transaction who receives a copy of the work also receives whatever
460
+licenses to the work the party's predecessor in interest had or could
461
+give under the previous paragraph, plus a right to possession of the
462
+Corresponding Source of the work from the predecessor in interest, if
463
+the predecessor has it or can get it with reasonable efforts.
464
+
465
+  You may not impose any further restrictions on the exercise of the
466
+rights granted or affirmed under this License.  For example, you may
467
+not impose a license fee, royalty, or other charge for exercise of
468
+rights granted under this License, and you may not initiate litigation
469
+(including a cross-claim or counterclaim in a lawsuit) alleging that
470
+any patent claim is infringed by making, using, selling, offering for
471
+sale, or importing the Program or any portion of it.
472
+
473
+  11. Patents.
474
+
475
+  A "contributor" is a copyright holder who authorizes use under this
476
+License of the Program or a work on which the Program is based.  The
477
+work thus licensed is called the contributor's "contributor version".
478
+
479
+  A contributor's "essential patent claims" are all patent claims
480
+owned or controlled by the contributor, whether already acquired or
481
+hereafter acquired, that would be infringed by some manner, permitted
482
+by this License, of making, using, or selling its contributor version,
483
+but do not include claims that would be infringed only as a
484
+consequence of further modification of the contributor version.  For
485
+purposes of this definition, "control" includes the right to grant
486
+patent sublicenses in a manner consistent with the requirements of
487
+this License.
488
+
489
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
490
+patent license under the contributor's essential patent claims, to
491
+make, use, sell, offer for sale, import and otherwise run, modify and
492
+propagate the contents of its contributor version.
493
+
494
+  In the following three paragraphs, a "patent license" is any express
495
+agreement or commitment, however denominated, not to enforce a patent
496
+(such as an express permission to practice a patent or covenant not to
497
+sue for patent infringement).  To "grant" such a patent license to a
498
+party means to make such an agreement or commitment not to enforce a
499
+patent against the party.
500
+
501
+  If you convey a covered work, knowingly relying on a patent license,
502
+and the Corresponding Source of the work is not available for anyone
503
+to copy, free of charge and under the terms of this License, through a
504
+publicly available network server or other readily accessible means,
505
+then you must either (1) cause the Corresponding Source to be so
506
+available, or (2) arrange to deprive yourself of the benefit of the
507
+patent license for this particular work, or (3) arrange, in a manner
508
+consistent with the requirements of this License, to extend the patent
509
+license to downstream recipients.  "Knowingly relying" means you have
510
+actual knowledge that, but for the patent license, your conveying the
511
+covered work in a country, or your recipient's use of the covered work
512
+in a country, would infringe one or more identifiable patents in that
513
+country that you have reason to believe are valid.
514
+
515
+  If, pursuant to or in connection with a single transaction or
516
+arrangement, you convey, or propagate by procuring conveyance of, a
517
+covered work, and grant a patent license to some of the parties
518
+receiving the covered work authorizing them to use, propagate, modify
519
+or convey a specific copy of the covered work, then the patent license
520
+you grant is automatically extended to all recipients of the covered
521
+work and works based on it.
522
+
523
+  A patent license is "discriminatory" if it does not include within
524
+the scope of its coverage, prohibits the exercise of, or is
525
+conditioned on the non-exercise of one or more of the rights that are
526
+specifically granted under this License.  You may not convey a covered
527
+work if you are a party to an arrangement with a third party that is
528
+in the business of distributing software, under which you make payment
529
+to the third party based on the extent of your activity of conveying
530
+the work, and under which the third party grants, to any of the
531
+parties who would receive the covered work from you, a discriminatory
532
+patent license (a) in connection with copies of the covered work
533
+conveyed by you (or copies made from those copies), or (b) primarily
534
+for and in connection with specific products or compilations that
535
+contain the covered work, unless you entered into that arrangement,
536
+or that patent license was granted, prior to 28 March 2007.
537
+
538
+  Nothing in this License shall be construed as excluding or limiting
539
+any implied license or other defenses to infringement that may
540
+otherwise be available to you under applicable patent law.
541
+
542
+  12. No Surrender of Others' Freedom.
543
+
544
+  If conditions are imposed on you (whether by court order, agreement or
545
+otherwise) that contradict the conditions of this License, they do not
546
+excuse you from the conditions of this License.  If you cannot convey a
547
+covered work so as to satisfy simultaneously your obligations under this
548
+License and any other pertinent obligations, then as a consequence you may
549
+not convey it at all.  For example, if you agree to terms that obligate you
550
+to collect a royalty for further conveying from those to whom you convey
551
+the Program, the only way you could satisfy both those terms and this
552
+License would be to refrain entirely from conveying the Program.
553
+
554
+  13. Use with the GNU Affero General Public License.
555
+
556
+  Notwithstanding any other provision of this License, you have
557
+permission to link or combine any covered work with a work licensed
558
+under version 3 of the GNU Affero General Public License into a single
559
+combined work, and to convey the resulting work.  The terms of this
560
+License will continue to apply to the part which is the covered work,
561
+but the special requirements of the GNU Affero General Public License,
562
+section 13, concerning interaction through a network will apply to the
563
+combination as such.
564
+
565
+  14. Revised Versions of this License.
566
+
567
+  The Free Software Foundation may publish revised and/or new versions of
568
+the GNU General Public License from time to time.  Such new versions will
569
+be similar in spirit to the present version, but may differ in detail to
570
+address new problems or concerns.
571
+
572
+  Each version is given a distinguishing version number.  If the
573
+Program specifies that a certain numbered version of the GNU General
574
+Public License "or any later version" applies to it, you have the
575
+option of following the terms and conditions either of that numbered
576
+version or of any later version published by the Free Software
577
+Foundation.  If the Program does not specify a version number of the
578
+GNU General Public License, you may choose any version ever published
579
+by the Free Software Foundation.
580
+
581
+  If the Program specifies that a proxy can decide which future
582
+versions of the GNU General Public License can be used, that proxy's
583
+public statement of acceptance of a version permanently authorizes you
584
+to choose that version for the Program.
585
+
586
+  Later license versions may give you additional or different
587
+permissions.  However, no additional obligations are imposed on any
588
+author or copyright holder as a result of your choosing to follow a
589
+later version.
590
+
591
+  15. Disclaimer of Warranty.
592
+
593
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
594
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
595
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
596
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
597
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
598
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
599
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
600
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
601
+
602
+  16. Limitation of Liability.
603
+
604
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
605
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
606
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
607
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
608
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
609
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
610
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
611
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
612
+SUCH DAMAGES.
613
+
614
+  17. Interpretation of Sections 15 and 16.
615
+
616
+  If the disclaimer of warranty and limitation of liability provided
617
+above cannot be given local legal effect according to their terms,
618
+reviewing courts shall apply local law that most closely approximates
619
+an absolute waiver of all civil liability in connection with the
620
+Program, unless a warranty or assumption of liability accompanies a
621
+copy of the Program in return for a fee.
622
+
623
+                     END OF TERMS AND CONDITIONS
624
+
625
+            How to Apply These Terms to Your New Programs
626
+
627
+  If you develop a new program, and you want it to be of the greatest
628
+possible use to the public, the best way to achieve this is to make it
629
+free software which everyone can redistribute and change under these terms.
630
+
631
+  To do so, attach the following notices to the program.  It is safest
632
+to attach them to the start of each source file to most effectively
633
+state the exclusion of warranty; and each file should have at least
634
+the "copyright" line and a pointer to where the full notice is found.
635
+
636
+    {one line to give the program's name and a brief idea of what it does.}
637
+    Copyright (C) {year}  {name of author}
638
+
639
+    This program is free software: you can redistribute it and/or modify
640
+    it under the terms of the GNU General Public License as published by
641
+    the Free Software Foundation, either version 3 of the License, or
642
+    (at your option) any later version.
643
+
644
+    This program is distributed in the hope that it will be useful,
645
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
646
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
647
+    GNU General Public License for more details.
648
+
649
+    You should have received a copy of the GNU General Public License
650
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
651
+
652
+Also add information on how to contact you by electronic and paper mail.
653
+
654
+  If the program does terminal interaction, make it output a short
655
+notice like this when it starts in an interactive mode:
656
+
657
+    {project}  Copyright (C) {year}  {fullname}
658
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
659
+    This is free software, and you are welcome to redistribute it
660
+    under certain conditions; type `show c' for details.
661
+
662
+The hypothetical commands `show w' and `show c' should show the appropriate
663
+parts of the General Public License.  Of course, your program's commands
664
+might be different; for a GUI interface, you would use an "about box".
665
+
666
+  You should also get your employer (if you work as a programmer) or school,
667
+if any, to sign a "copyright disclaimer" for the program, if necessary.
668
+For more information on this, and how to apply and follow the GNU GPL, see
669
+<http://www.gnu.org/licenses/>.
670
+
671
+  The GNU General Public License does not permit incorporating your program
672
+into proprietary programs.  If your program is a subroutine library, you
673
+may consider it more useful to permit linking proprietary applications with
674
+the library.  If this is what you want to do, use the GNU Lesser General
675
+Public License instead of this License.  But first, please read
676
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
677
+

+ 348
- 0
lib/LibAPRS/LibAPRS.cpp View File

@@ -0,0 +1,348 @@
1
+#include "Arduino.h"
2
+#include "AFSK.h"
3
+#include "AX25.h"
4
+
5
+Afsk modem;
6
+AX25Ctx AX25;
7
+extern void aprs_msg_callback(struct AX25Msg *msg);
8
+#define countof(a) sizeof(a)/sizeof(a[0])
9
+
10
+int LibAPRS_vref = REF_3V3;
11
+bool LibAPRS_open_squelch = false;
12
+
13
+unsigned long custom_preamble = 350UL;
14
+unsigned long custom_tail = 50UL;
15
+
16
+AX25Call src;
17
+AX25Call dst;
18
+AX25Call path1;
19
+AX25Call path2;
20
+
21
+char CALL[7] = "NOCALL";
22
+int CALL_SSID = 0;
23
+char DST[7] = "APZMDM";
24
+int DST_SSID = 0;
25
+char PATH1[7] = "WIDE1";
26
+int PATH1_SSID = 1;
27
+char PATH2[7] = "WIDE2";
28
+int PATH2_SSID = 2;
29
+
30
+AX25Call path[4];
31
+
32
+// Location packet assembly fields
33
+char latitude[9];
34
+char longtitude[10];
35
+char symbolTable = '/';
36
+char symbol = 'n';
37
+
38
+uint8_t power = 10;
39
+uint8_t height = 10;
40
+uint8_t gain = 10;
41
+uint8_t directivity = 10;
42
+/////////////////////////
43
+
44
+// Message packet assembly fields
45
+char message_recip[7];
46
+int message_recip_ssid = -1;
47
+
48
+int message_seq = 0;
49
+char lastMessage[67];
50
+size_t lastMessageLen;
51
+bool message_autoAck = false;
52
+/////////////////////////
53
+
54
+void APRS_init(int reference, bool open_squelch) {
55
+    LibAPRS_vref = reference;
56
+    LibAPRS_open_squelch = open_squelch;
57
+
58
+    AFSK_init(&modem);
59
+    ax25_init(&AX25, aprs_msg_callback);
60
+}
61
+
62
+void APRS_poll(void) {
63
+    ax25_poll(&AX25);
64
+}
65
+
66
+void APRS_setCallsign(char *call, int ssid) {
67
+    memset(CALL, 0, 7);
68
+    int i = 0;
69
+    while (i < 6 && call[i] != 0) {
70
+        CALL[i] = call[i];
71
+        i++;
72
+    }
73
+    CALL_SSID = ssid;
74
+}
75
+
76
+void APRS_setDestination(char *call, int ssid) {
77
+    memset(DST, 0, 7);
78
+    int i = 0;
79
+    while (i < 6 && call[i] != 0) {
80
+        DST[i] = call[i];
81
+        i++;
82
+    }
83
+    DST_SSID = ssid;
84
+}
85
+
86
+void APRS_setPath1(char *call, int ssid) {
87
+    memset(PATH1, 0, 7);
88
+    int i = 0;
89
+    while (i < 6 && call[i] != 0) {
90
+        PATH1[i] = call[i];
91
+        i++;
92
+    }
93
+    PATH1_SSID = ssid;
94
+}
95
+
96
+void APRS_setPath2(char *call, int ssid) {
97
+    memset(PATH2, 0, 7);
98
+    int i = 0;
99
+    while (i < 6 && call[i] != 0) {
100
+        PATH2[i] = call[i];
101
+        i++;
102
+    }
103
+    PATH2_SSID = ssid;
104
+}
105
+
106
+void APRS_setMessageDestination(char *call, int ssid) {
107
+    memset(message_recip, 0, 7);
108
+    int i = 0;
109
+    while (i < 6 && call[i] != 0) {
110
+        message_recip[i] = call[i];
111
+        i++;
112
+    }
113
+    message_recip_ssid = ssid;
114
+}
115
+
116
+void APRS_setPreamble(unsigned long pre) {
117
+    custom_preamble = pre;
118
+}
119
+
120
+void APRS_setTail(unsigned long tail) {
121
+    custom_tail = tail;
122
+}
123
+
124
+void APRS_useAlternateSymbolTable(bool use) {
125
+    if (use) {
126
+        symbolTable = '\\';
127
+    } else {
128
+        symbolTable = '/';
129
+    }
130
+}
131
+
132
+void APRS_setSymbol(char sym) {
133
+    symbol = sym;
134
+}
135
+
136
+void APRS_setLat(char *lat) {
137
+    memset(latitude, 0, 9);
138
+    int i = 0;
139
+    while (i < 8 && lat[i] != 0) {
140
+        latitude[i] = lat[i];
141
+        i++;
142
+    }
143
+}
144
+
145
+void APRS_setLon(char *lon) {
146
+    memset(longtitude, 0, 10);
147
+    int i = 0;
148
+    while (i < 9 && lon[i] != 0) {
149
+        longtitude[i] = lon[i];
150
+        i++;
151
+    }
152
+}
153
+
154
+void APRS_setPower(int s) {
155
+    if (s >= 0 && s < 10) {
156
+        power = s;
157
+    }
158
+}
159
+
160
+void APRS_setHeight(int s) {
161
+    if (s >= 0 && s < 10) {
162
+        height = s;
163
+    }
164
+}
165
+
166
+void APRS_setGain(int s) {
167
+    if (s >= 0 && s < 10) {
168
+        gain = s;
169
+    }
170
+}
171
+
172
+void APRS_setDirectivity(int s) {
173
+    if (s >= 0 && s < 10) {
174
+        directivity = s;
175
+    }
176
+}
177
+
178
+void APRS_printSettings() {
179
+    Serial.println(F("LibAPRS Settings:"));
180
+    Serial.print(F("Callsign:     ")); Serial.print(CALL); Serial.print(F("-")); Serial.println(CALL_SSID);
181
+    Serial.print(F("Destination:  ")); Serial.print(DST); Serial.print(F("-")); Serial.println(DST_SSID);
182
+    Serial.print(F("Path1:        ")); Serial.print(PATH1); Serial.print(F("-")); Serial.println(PATH1_SSID);
183
+    Serial.print(F("Path2:        ")); Serial.print(PATH2); Serial.print(F("-")); Serial.println(PATH2_SSID);
184
+    Serial.print(F("Message dst:  ")); if (message_recip[0] == 0) { Serial.println(F("N/A")); } else { Serial.print(message_recip); Serial.print(F("-")); Serial.println(message_recip_ssid); }
185
+    Serial.print(F("TX Preamble:  ")); Serial.println(custom_preamble);
186
+    Serial.print(F("TX Tail:      ")); Serial.println(custom_tail);
187
+    Serial.print(F("Symbol table: ")); if (symbolTable = '/') { Serial.println(F("Normal")); } else { Serial.println(F("Alternate")); }
188
+    Serial.print(F("Symbol:       ")); Serial.println(symbol);
189
+    Serial.print(F("Power:        ")); if (power < 10) { Serial.println(power); } else { Serial.println(F("N/A")); }
190
+    Serial.print(F("Height:       ")); if (height < 10) { Serial.println(height); } else { Serial.println(F("N/A")); }
191
+    Serial.print(F("Gain:         ")); if (gain < 10) { Serial.println(gain); } else { Serial.println(F("N/A")); }
192
+    Serial.print(F("Directivity:  ")); if (directivity < 10) { Serial.println(directivity); } else { Serial.println(F("N/A")); }
193
+    Serial.print(F("Latitude:     ")); if (latitude[0] != 0) { Serial.println(latitude); } else { Serial.println(F("N/A")); }
194
+    Serial.print(F("Longtitude:   ")); if (longtitude[0] != 0) { Serial.println(longtitude); } else { Serial.println(F("N/A")); }
195
+}
196
+
197
+void APRS_sendPkt(void *_buffer, size_t length) {
198
+
199
+    uint8_t *buffer = (uint8_t *)_buffer;
200
+
201
+    memcpy(dst.call, DST, 6);
202
+    dst.ssid = DST_SSID;
203
+
204
+    memcpy(src.call, CALL, 6);
205
+    src.ssid = CALL_SSID;
206
+
207
+    memcpy(path1.call, PATH1, 6);
208
+    path1.ssid = PATH1_SSID;
209
+
210
+    memcpy(path2.call, PATH2, 6);
211
+    path2.ssid = PATH2_SSID;
212
+
213
+    path[0] = dst;
214
+    path[1] = src;
215
+    path[2] = path1;
216
+    path[3] = path2;
217
+
218
+    ax25_sendVia(&AX25, path, countof(path), buffer, length);
219
+}
220
+
221
+// Dynamic RAM usage of this function is 30 bytes
222
+void APRS_sendLoc(void *_buffer, size_t length) {
223
+    size_t payloadLength = 20+length;
224
+    bool usePHG = false;
225
+    if (power < 10 && height < 10 && gain < 10 && directivity < 9) {
226
+        usePHG = true;
227
+        payloadLength += 7;
228
+    }
229
+    uint8_t *packet = (uint8_t*)malloc(payloadLength);
230
+    uint8_t *ptr = packet;
231
+    packet[0] = '=';
232
+    packet[9] = symbolTable;
233
+    packet[19] = symbol;
234
+    ptr++;
235
+    memcpy(ptr, latitude, 8);
236
+    ptr += 9;
237
+    memcpy(ptr, longtitude, 9);
238
+    ptr += 10;
239
+    if (usePHG) {
240
+        packet[20] = 'P';
241
+        packet[21] = 'H';
242
+        packet[22] = 'G';
243
+        packet[23] = power+48;
244
+        packet[24] = height+48;
245
+        packet[25] = gain+48;
246
+        packet[26] = directivity+48;
247
+        ptr+=7;
248
+    }
249
+    if (length > 0) {
250
+        uint8_t *buffer = (uint8_t *)_buffer;
251
+        memcpy(ptr, buffer, length);
252
+    }
253
+
254
+    APRS_sendPkt(packet, payloadLength);
255
+    free(packet);
256
+}
257
+
258
+// Dynamic RAM usage of this function is 18 bytes
259
+void APRS_sendMsg(void *_buffer, size_t length) {
260
+    if (length > 67) length = 67;
261
+    size_t payloadLength = 11+length+4;
262
+
263
+    uint8_t *packet = (uint8_t*)malloc(payloadLength);
264
+    uint8_t *ptr = packet;
265
+    packet[0] = ':';
266
+    int callSize = 6;
267
+    int count = 0;
268
+    while (callSize--) {
269
+        if (message_recip[count] != 0) {
270
+            packet[1+count] = message_recip[count];
271
+            count++;
272
+        }
273
+    }
274
+    if (message_recip_ssid != -1) {
275
+        packet[1+count] = '-'; count++;
276
+        if (message_recip_ssid < 10) {
277
+            packet[1+count] = message_recip_ssid+48; count++;
278
+        } else {
279
+            packet[1+count] = 49; count++;
280
+            packet[1+count] = message_recip_ssid-10+48; count++;
281
+        }
282
+    }
283
+    while (count < 9) {
284
+        packet[1+count] = ' '; count++;
285
+    }
286
+    packet[1+count] = ':';
287
+    ptr += 11;
288
+    if (length > 0) {
289
+        uint8_t *buffer = (uint8_t *)_buffer;
290
+        memcpy(ptr, buffer, length);
291
+        memcpy(lastMessage, buffer, length);
292
+        lastMessageLen = length;
293
+    }
294
+
295
+    message_seq++;
296
+    if (message_seq > 999) message_seq = 0;
297
+
298
+    packet[11+length] = '{';
299
+    int n = message_seq % 10;
300
+    int d = ((message_seq % 100) - n)/10;
301
+    int h = (message_seq - d - n) / 100;
302
+
303
+    packet[12+length] = h+48;
304
+    packet[13+length] = d+48;
305
+    packet[14+length] = n+48;
306
+    
307
+    APRS_sendPkt(packet, payloadLength);
308
+    free(packet);
309
+}
310
+
311
+void APRS_msgRetry() {
312
+    message_seq--;
313
+    APRS_sendMsg(lastMessage, lastMessageLen);
314
+}
315
+
316
+// For getting free memory, from:
317
+// http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1213583720/15
318
+
319
+extern unsigned int __heap_start;
320
+extern void *__brkval;
321
+
322
+struct __freelist {
323
+  size_t sz;
324
+  struct __freelist *nx;
325
+};
326
+
327
+extern struct __freelist *__flp;
328
+
329
+int freeListSize() {
330
+  struct __freelist* current;
331
+  int total = 0;
332
+  for (current = __flp; current; current = current->nx) {
333
+    total += 2; /* Add two bytes for the memory block's header  */
334
+    total += (int) current->sz;
335
+  }
336
+  return total;
337
+}
338
+
339
+int freeMemory() {
340
+  int free_memory;
341
+  if ((int)__brkval == 0) {
342
+    free_memory = ((int)&free_memory) - ((int)&__heap_start);
343
+  } else {
344
+    free_memory = ((int)&free_memory) - ((int)__brkval);
345
+    free_memory += freeListSize();
346
+  }
347
+  return free_memory;
348
+}

+ 39
- 0
lib/LibAPRS/LibAPRS.h View File

@@ -0,0 +1,39 @@
1
+#include "Arduino.h"
2
+#include <stdint.h>
3
+#include <stdbool.h>
4
+
5
+#include "FIFO.h"
6
+#include "CRC-CCIT.h"
7
+#include "HDLC.h"
8
+#include "AFSK.h"
9
+#include "AX25.h"
10
+
11
+void APRS_init(int reference, bool open_squelch);
12
+void APRS_poll(void);
13
+
14
+void APRS_setCallsign(char *call, int ssid);
15
+void APRS_setDestination(char *call, int ssid);
16
+void APRS_setMessageDestination(char *call, int ssid);
17
+void APRS_setPath1(char *call, int ssid);
18
+void APRS_setPath2(char *call, int ssid);
19
+
20
+void APRS_setPreamble(unsigned long pre);
21
+void APRS_setTail(unsigned long tail);
22
+void APRS_useAlternateSymbolTable(bool use);
23
+void APRS_setSymbol(char sym);
24
+
25
+void APRS_setLat(char *lat);
26
+void APRS_setLon(char *lon);
27
+void APRS_setPower(int s);
28
+void APRS_setHeight(int s);
29
+void APRS_setGain(int s);
30
+void APRS_setDirectivity(int s);
31
+
32
+void APRS_sendPkt(void *_buffer, size_t length);
33
+void APRS_sendLoc(void *_buffer, size_t length);
34
+void APRS_sendMsg(void *_buffer, size_t length);
35
+void APRS_msgRetry();
36
+
37
+void APRS_printSettings();
38
+
39
+int freeMemory();

+ 32
- 0
lib/LibAPRS/README.md View File

@@ -0,0 +1,32 @@
1
+LibAPRS
2
+==========
3
+
4
+LibAPRS is an Arduino IDE library that makes it easy to send and receive APRS packets with a [MicroModem](http://unsigned.io/micromodem)-compatible modem.
5
+
6
+You can buy a complete modem from [my shop](http://unsigned.io/shop), or you can build one yourself pretty easily. Take a look at the documentation in the [MicroModem](https://github.com/markqvist/MicroModem) repository for information and getting started guides!
7
+
8
+See the example included in the library for info on how to use it!
9
+
10
+## Some features
11
+
12
+- Send and receive AX.25 APRS packets
13
+- Full modulation and demodulation in software
14
+- Easy configuration of callsign and path settings
15
+- Easily process incoming packets
16
+- Shorthand functions for sending location updates and messages, so you don't need to manually create the packets
17
+- Ability to send raw packets
18
+- Support for settings APRS symbols
19
+- Support for power/height/gain info in location updates
20
+- Can run with open squelch
21
+
22
+## Installation
23
+
24
+Place the "LibAPRS" folder (the one in the same folder as this readme file) inside your Arduino "libraries" folder. That's all!
25
+
26
+## Getting started
27
+
28
+You should read through the "Basic_usage" example included with the library. It contains an explanation of all the functions and a basic sketch to get you up and running with sending and receiving packets.
29
+
30
+## Got bugs?
31
+
32
+This library is very early, and being actively developed all the time. This means you should expect to find bugs. If you do, please report them here, so I can fix them! It also means I might have to make changes that will break code, and that you will have to rewrite your sketch. If you don't think that sounds good, wait a little while for a stable release of the library :)

+ 6
- 0
lib/LibAPRS/constants.h View File

@@ -0,0 +1,6 @@
1
+#define m328p  0x01
2
+#define m1284p 0x02
3
+#define m644p  0x03
4
+
5
+#define REF_3V3 0x01
6
+#define REF_5V  0x02

+ 32
- 0
lib/LibAPRS/device.h View File

@@ -0,0 +1,32 @@
1
+#include "constants.h"
2
+
3
+#ifndef DEVICE_CONFIGURATION
4
+#define DEVICE_CONFIGURATION
5
+
6
+// CPU settings
7
+#ifndef TARGET_CPU
8
+    #define TARGET_CPU m328p
9
+#endif
10
+
11
+#ifndef F_CPU
12
+    #define F_CPU 16000000
13
+#endif
14
+
15
+#ifndef FREQUENCY_CORRECTION
16
+    #define FREQUENCY_CORRECTION 0
17
+#endif
18
+
19
+// Sampling & timer setup
20
+#define CONFIG_AFSK_DAC_SAMPLERATE 9600
21
+
22
+// Port settings
23
+#if TARGET_CPU == m328p
24
+    #define DAC_PORT PORTD
25
+    #define DAC_DDR  DDRD
26
+    #define LED_PORT PORTB
27
+    #define LED_DDR  DDRB
28
+    #define ADC_PORT PORTC
29
+    #define ADC_DDR  DDRC
30
+#endif
31
+
32
+#endif

+ 177
- 0
lib/LibAPRS/examples/Basic_usage/Basic_usage.ino View File

@@ -0,0 +1,177 @@
1
+// Include LibAPRS
2
+#include <LibAPRS.h>
3
+
4
+// You must define what reference voltage the ADC
5
+// of your device is running at. If you bought a
6
+// MicroModem from unsigned.io, it will be running
7
+// at 3.3v if the "hw rev" is greater than 2.0.
8
+// This is the most common. If you build your own
9
+// modem, you should know this value yourself :)
10
+#define ADC_REFERENCE REF_3V3
11
+// OR
12
+//#define ADC_REFERENCE REF_5V
13
+
14
+// You can also define whether your modem will be
15
+// running with an open squelch radio:
16
+#define OPEN_SQUELCH false
17
+
18
+// You always need to include this function. It will
19
+// get called by the library every time a packet is
20
+// received, so you can process incoming packets.
21
+//
22
+// If you are only interested in receiving, you should
23
+// just leave this function empty.
24
+// 
25
+// IMPORTANT! This function is called from within an
26
+// interrupt. That means that you should only do things
27
+// here that are FAST. Don't print out info directly
28
+// from this function, instead set a flag and print it
29
+// from your main loop, like this:
30
+
31
+boolean gotPacket = false;
32
+AX25Msg incomingPacket;
33
+uint8_t *packetData;
34
+void aprs_msg_callback(struct AX25Msg *msg) {
35
+  // If we already have a packet waiting to be
36
+  // processed, we must drop the new one.
37
+  if (!gotPacket) {
38
+    // Set flag to indicate we got a packet
39
+    gotPacket = true;
40
+
41
+    // The memory referenced as *msg is volatile
42
+    // and we need to copy all the data to a
43
+    // local variable for later processing.
44
+    memcpy(&incomingPacket, msg, sizeof(AX25Msg));
45
+
46
+    // We need to allocate a new buffer for the
47
+    // data payload of the packet. First we check
48
+    // if there is enough free RAM.
49
+    if (freeMemory() > msg->len) {
50
+      packetData = (uint8_t*)malloc(msg->len);
51
+      memcpy(packetData, msg->info, msg->len);
52
+      incomingPacket.info = packetData;
53
+    } else {
54
+      // We did not have enough free RAM to receive
55
+      // this packet, so we drop it.
56
+      gotPacket = false;
57
+    }
58
+  }
59
+}
60
+
61
+void setup() {
62
+  // Set up serial port
63
+  Serial.begin(115200);
64
+  
65
+  // Initialise APRS library - This starts the modem
66
+  APRS_init(ADC_REFERENCE, OPEN_SQUELCH);
67
+  
68
+  // You must at a minimum configure your callsign and SSID
69
+  APRS_setCallsign("NOCALL", 1);
70
+  
71
+  // You don't need to set the destination identifier, but
72
+  // if you want to, this is how you do it:
73
+  // APRS_setDestination("APZMDM", 0);
74
+  
75
+  // Path parameters are set to sensible values by
76
+  // default, but this is how you can configure them:
77
+  // APRS_setPath1("WIDE1", 1);
78
+  // APRS_setPath2("WIDE2", 2);
79
+  
80
+  // You can define preamble and tail like this:
81
+  // APRS_setPreamble(350);
82
+  // APRS_setTail(50);
83
+  
84
+  // You can use the normal or alternate symbol table:
85
+  // APRS_useAlternateSymbolTable(false);
86
+  
87
+  // And set what symbol you want to use:
88
+  // APRS_setSymbol('n');
89
+  
90
+  // We can print out all the settings
91
+  APRS_printSettings();
92
+  Serial.print(F("Free RAM:     ")); Serial.println(freeMemory());
93
+}
94
+
95
+void locationUpdateExample() {
96
+  // Let's first set our latitude and longtitude.
97
+  // These should be in NMEA format!
98
+  APRS_setLat("5530.80N");
99
+  APRS_setLon("01143.89E");
100
+  
101
+  // We can optionally set power/height/gain/directivity
102
+  // information. These functions accept ranges
103
+  // from 0 to 10, directivity 0 to 9.
104
+  // See this site for a calculator:
105
+  // http://www.aprsfl.net/phgr.php
106
+  // LibAPRS will only add PHG info if all four variables
107
+  // are defined!
108
+  APRS_setPower(2);
109
+  APRS_setHeight(4);
110
+  APRS_setGain(7);
111
+  APRS_setDirectivity(0);
112
+  
113
+  // We'll define a comment string
114
+  char *comment = "LibAPRS location update";
115
+    
116
+  // And send the update
117
+  APRS_sendLoc(comment, strlen(comment));
118
+  
119
+}
120
+
121
+void messageExample() {
122
+  // We first need to set the message recipient
123
+  APRS_setMessageDestination("AA3BBB", 0);
124
+  
125
+  // And define a string to send
126
+  char *message = "Hi there! This is a message.";
127
+  APRS_sendMsg(message, strlen(message));
128
+  
129
+}
130
+
131
+// Here's a function to process incoming packets
132
+// Remember to call this function often, so you
133
+// won't miss any packets due to one already
134
+// waiting to be processed
135
+void processPacket() {
136
+  if (gotPacket) {
137
+    gotPacket = false;
138
+    
139
+    Serial.print(F("Received APRS packet. SRC: "));
140
+    Serial.print(incomingPacket.src.call);
141
+    Serial.print(F("-"));
142
+    Serial.print(incomingPacket.src.ssid);
143
+    Serial.print(F(". DST: "));
144
+    Serial.print(incomingPacket.dst.call);
145
+    Serial.print(F("-"));
146
+    Serial.print(incomingPacket.dst.ssid);
147
+    Serial.print(F(". Data: "));
148
+
149
+    for (int i = 0; i < incomingPacket.len; i++) {
150
+      Serial.write(incomingPacket.info[i]);
151
+    }
152
+    Serial.println("");
153
+
154
+    // Remeber to free memory for our buffer!
155
+    free(packetData);
156
+
157
+    // You can print out the amount of free
158
+    // RAM to check you don't have any memory
159
+    // leaks
160
+    // Serial.print(F("Free RAM: ")); Serial.println(freeMemory());
161
+  }
162
+}
163
+
164
+boolean whichExample = false;
165
+void loop() {
166
+  
167
+  delay(1000);
168
+  if (whichExample) {
169
+    locationUpdateExample();
170
+  } else {
171
+    messageExample();
172
+  }
173
+  whichExample ^= true;
174
+
175
+  delay(500);
176
+  processPacket();
177
+}

+ 429
- 0
lib/TinyGPS/TinyGPS.cpp View File

@@ -0,0 +1,429 @@
1
+/*
2
+TinyGPS - a small GPS library for Arduino providing basic NMEA parsing
3
+Based on work by and "distance_to" and "course_to" courtesy of Maarten Lamers.
4
+Suggestion to add satellites(), course_to(), and cardinal(), by Matt Monson.
5
+Precision improvements suggested by Wayne Holder.
6
+Copyright (C) 2008-2013 Mikal Hart
7
+All rights reserved.
8
+
9
+This library is free software; you can redistribute it and/or
10
+modify it under the terms of the GNU Lesser General Public
11
+License as published by the Free Software Foundation; either
12
+version 2.1 of the License, or (at your option) any later version.
13
+
14
+This library is distributed in the hope that it will be useful,
15
+but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
+Lesser General Public License for more details.
18
+
19
+You should have received a copy of the GNU Lesser General Public
20
+License along with this library; if not, write to the Free Software
21
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
+*/
23
+
24
+#include "TinyGPS.h"
25
+
26
+#define _GPRMC_TERM   "GPRMC"
27
+#define _GPGGA_TERM   "GPGGA"
28
+
29
+TinyGPS::TinyGPS()
30
+  :  _time(GPS_INVALID_TIME)
31
+  ,  _date(GPS_INVALID_DATE)
32
+  ,  _latitude(GPS_INVALID_ANGLE)
33
+  ,  _longitude(GPS_INVALID_ANGLE)
34
+  ,  _altitude(GPS_INVALID_ALTITUDE)
35
+  ,  _speed(GPS_INVALID_SPEED)
36
+  ,  _course(GPS_INVALID_ANGLE)
37
+  ,  _hdop(GPS_INVALID_HDOP)
38
+  ,  _numsats(GPS_INVALID_SATELLITES)
39
+  ,  _last_time_fix(GPS_INVALID_FIX_TIME)
40
+  ,  _last_position_fix(GPS_INVALID_FIX_TIME)
41
+  ,  _parity(0)
42
+  ,  _is_checksum_term(false)
43
+  ,  _sentence_type(_GPS_SENTENCE_OTHER)
44
+  ,  _term_number(0)
45
+  ,  _term_offset(0)
46
+  ,  _gps_data_good(false)
47
+#ifndef _GPS_NO_STATS
48
+  ,  _encoded_characters(0)
49
+  ,  _good_sentences(0)
50
+  ,  _failed_checksum(0)
51
+#endif
52
+{
53
+  _term[0] = '\0';
54
+}
55
+
56
+//
57
+// public methods
58
+//
59
+
60
+bool TinyGPS::encode(char c)
61
+{
62
+  bool valid_sentence = false;
63
+
64
+#ifndef _GPS_NO_STATS
65
+  ++_encoded_characters;
66
+#endif
67
+  switch(c)
68
+  {
69
+  case ',': // term terminators
70
+    _parity ^= c;
71
+  case '\r':
72
+  case '\n':
73
+  case '*':
74
+    if (_term_offset < sizeof(_term))
75
+    {
76
+      _term[_term_offset] = 0;
77
+      valid_sentence = term_complete();
78
+    }
79
+    ++_term_number;
80
+    _term_offset = 0;
81
+    _is_checksum_term = c == '*';
82
+    return valid_sentence;
83
+
84
+  case '$': // sentence begin
85
+    _term_number = _term_offset = 0;
86
+    _parity = 0;
87
+    _sentence_type = _GPS_SENTENCE_OTHER;
88
+    _is_checksum_term = false;
89
+    _gps_data_good = false;
90
+    return valid_sentence;
91
+  }
92
+
93
+  // ordinary characters
94
+  if (_term_offset < sizeof(_term) - 1)
95
+    _term[_term_offset++] = c;
96
+  if (!_is_checksum_term)
97
+    _parity ^= c;
98
+
99
+  return valid_sentence;
100
+}
101
+
102
+#ifndef _GPS_NO_STATS
103
+void TinyGPS::stats(unsigned long *chars, unsigned short *sentences, unsigned short *failed_cs)
104
+{
105
+  if (chars) *chars = _encoded_characters;
106
+  if (sentences) *sentences = _good_sentences;
107
+  if (failed_cs) *failed_cs = _failed_checksum;
108
+}
109
+#endif
110
+
111
+//
112
+// internal utilities
113
+//
114
+int TinyGPS::from_hex(char a) 
115
+{
116
+  if (a >= 'A' && a <= 'F')
117
+    return a - 'A' + 10;
118
+  else if (a >= 'a' && a <= 'f')
119
+    return a - 'a' + 10;
120
+  else
121
+    return a - '0';
122
+}
123
+
124
+unsigned long TinyGPS::parse_decimal()
125
+{
126
+  char *p = _term;
127
+  bool isneg = *p == '-';
128
+  if (isneg) ++p;
129
+  unsigned long ret = 100UL * gpsatol(p);
130
+  while (gpsisdigit(*p)) ++p;
131
+  if (*p == '.')
132
+  {
133
+    if (gpsisdigit(p[1]))
134
+    {
135
+      ret += 10 * (p[1] - '0');
136
+      if (gpsisdigit(p[2]))
137
+        ret += p[2] - '0';
138
+    }
139
+  }
140
+  return isneg ? -ret : ret;
141
+}
142
+
143
+// Parse a string in the form ddmm.mmmmmmm...
144
+unsigned long TinyGPS::parse_degrees()
145
+{
146
+  char *p;
147
+  unsigned long left_of_decimal = gpsatol(_term);
148
+  unsigned long hundred1000ths_of_minute = (left_of_decimal % 100UL) * 100000UL;
149
+  for (p=_term; gpsisdigit(*p); ++p);
150
+  if (*p == '.')
151
+  {
152
+    unsigned long mult = 10000;
153
+    while (gpsisdigit(*++p))
154
+    {
155
+      hundred1000ths_of_minute += mult * (*p - '0');
156
+      mult /= 10;
157
+    }
158
+  }
159
+  return (left_of_decimal / 100) * 1000000 + (hundred1000ths_of_minute + 3) / 6;
160
+}
161
+
162
+#define COMBINE(sentence_type, term_number) (((unsigned)(sentence_type) << 5) | term_number)
163
+
164
+// Processes a just-completed term
165
+// Returns true if new sentence has just passed checksum test and is validated
166
+bool TinyGPS::term_complete()
167
+{
168
+  if (_is_checksum_term)
169
+  {
170
+    byte checksum = 16 * from_hex(_term[0]) + from_hex(_term[1]);
171
+    if (checksum == _parity)
172
+    {
173
+      if (_gps_data_good)
174
+      {
175
+#ifndef _GPS_NO_STATS
176
+        ++_good_sentences;
177
+#endif
178
+        _last_time_fix = _new_time_fix;
179
+        _last_position_fix = _new_position_fix;
180
+
181
+        switch(_sentence_type)
182
+        {
183
+        case _GPS_SENTENCE_GPRMC:
184
+          _time      = _new_time;
185
+          _date      = _new_date;
186
+          _latitude  = _new_latitude;
187
+          _longitude = _new_longitude;
188
+          _speed     = _new_speed;
189
+          _course    = _new_course;
190
+          break;
191
+        case _GPS_SENTENCE_GPGGA:
192
+          _altitude  = _new_altitude;
193
+          _time      = _new_time;
194
+          _latitude  = _new_latitude;
195
+          _longitude = _ne