-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArabell300.ino
135 lines (116 loc) · 2.96 KB
/
Arabell300.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
Arabell300 - Arduino Bell 103 and ITU V.21 modem
Copyright (C) 2018 Costin STROIE <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "afsk.h"
#include "hayes.h"
// Persistent modem configuration
CFG_t cfg;
// The modem and all its related runtime configuration
AFSK afsk;
// The AT-Hayes command interface
HAYES hayes(&cfg, &afsk);
/**
ADC Interrupt vector, called for each sample
*/
ISR(ADC_vect) {
// Clear the Interrupt Flag Register
TIFR1 = _BV(ICF1);
#ifndef DEBUG
// Hadle TX/RX
afsk.doTXRX();
#endif
}
/**
Main Arduino setup function
*/
void setup() {
// Serial port configuration
#ifdef DEBUG_EE
Serial.begin(115200);
e2hex();
#else
Serial.begin(300);
#endif
// Define and configure the modem
afsk.init(BELL103, &cfg);
// All LEDs on
afsk.setLeds(ON);
// Banner
hayes.banner();
// All LEDs off
delay(1000);
afsk.setLeds(OFF);
}
/**
Main Arduino loop
*/
void loop() {
// Check the serial port and handle data
uint8_t sioResult = afsk.doSIO();
if (sioResult == 255) hayes.doSIO();
else if (sioResult != 254) hayes.doSIO(sioResult);
#ifdef DEBUG_RX_LVL
static uint32_t next = millis();
if (millis() > next) {
Serial.println(afsk.inLevel);
next += 8 * 1000 / 300;
}
#endif
#ifdef DEBUG
afsk.simFeed();
afsk.simPrint();
#endif
}
#ifdef DEBUG_EE
void e2hex() {
char buf[16];
char val[4];
uint8_t data;
// Start with a new line
Serial.print("\r\n");
// All EEPROM bytes
for (uint16_t addr = 0; addr <= E2END;) {
// Init the buffer
memset(buf, 0, 16);
// Use the buffer to display the address
sprintf_P(buf, PSTR("%04X: "), addr);
Serial.print(buf);
// Iterate over bytes, 2 sets of 8 bytes
for (uint8_t set = 0; set < 2; set++) {
for (uint8_t byt = 0; byt < 8; byt++) {
// Read EEPROM
data = EEPROM.read(addr);
// Prepare and print the hex dump
sprintf_P(val, PSTR("%02X "), data);
Serial.print(val);
// Prepare the ASCII dump
if (data < 32 or data > 127)
data = '.';
buf[addr & 0x0F] = data;
// Increment the address
addr++;
}
// Print a separator
Serial.write(' ');
}
// Print the ASCII column
for (uint8_t idx = 0; idx < 16; idx++) {
Serial.write(buf[idx]);
}
// New line
Serial.print("\r\n");
}
}
#endif