-
Notifications
You must be signed in to change notification settings - Fork 2
/
z_rtty_txrx.ino
120 lines (110 loc) · 3.26 KB
/
z_rtty_txrx.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
/* *****************************************************************************
* Main Routine - Receive or Transmit RTTY using either a Model 33 Teletype
* and/or an RS-232 Terminal (9600 8N1) attached to the TX/RX pins and/or
* a software terminal program (9600 8N1) using the Arduino USB port serial connection.
* *****************************************************************************/
#define SERBUFFSIZE 64
char ser_buff[SERBUFFSIZE];
uint8_t ser_buffhead = 0, ser_bufftail = 0;
bool got_esc = false;
// Read data from serial buffer
char serRead()
{
if (ser_buffhead == ser_bufftail)
return -1;
char achar = ser_buff[ser_buffhead];
ser_buffhead = (ser_buffhead + 1) % SERBUFFSIZE;
return achar;
}
// Return number of characters in serial buffer
uint8_t serBuffAvailable(){
return (ser_bufftail + SERBUFFSIZE - ser_buffhead) % SERBUFFSIZE;
}
bool checkMacro(char c){
if(macros == false) return false;
int num = (int)(c - '0');
if(int(c) == 27){
got_esc = true;
return true;
}
if(got_esc == true && num >= 0 && num <= 9){
sendMacro(num);
got_esc = false;
return true;
}
else{
got_esc = false;
return false;
}
}
void sendMacro(int num){
char mychar;
int c;
for(c = 0; c < MACRO_MAX_LEN; c++){
mychar = char(EEPROM[MACRO_START_ADDR + (num * MACRO_MAX_LEN) + c]);
if(mychar != '>' && mychar != '\0' && mychar != '*'){
sendMacroChar(mychar);
}
else if(mychar == '>'){ // CRLF
sendMacroChar('\r');
sendMacroChar('\n');
}
else if(mychar == '*' || mychar == '\0') break;
}
}
void sendMacroChar(char ch){
if(machine_type == 32)
rttySendChar(ch);
else // M33
ascii_rttySendChar(ch);
HostSerial.print(ch);
if(echo == true)
ttySendCharX(ch); // Special routine for echoing macros
}
// Main loop tx/rx routine
void doTxRx()
{
char rttych, ttych, ch;
uint8_t chars_available = 0;
if(machine_type == 32)
chars_available = rttyBuffAvailable();
else // M33
chars_available = ascii_rttyBuffAvailable();
// Received from RTTY
if(chars_available > 0){
if(machine_type == 32)
rttych = rttyRead();
else // M33
rttych = ascii_rttyRead();
// handle LF without CR and linewrap
ttyFilter(rttych);
}
// Typed on Teletype
if(ttyBuffAvailable() && tty_isSending == false && ascii_rtty_isSending == false){
ttych = ttyRead();
if(!checkMacro(ttych)){
HostSerial.print(ttych);
// Send to rtty.
if(machine_type == 32)
rttySendChar(ttych);
else // M33
ascii_rttySendChar(ttych);
}
}
// Typed on computer keyboard or host serial port attached device
if(HostSerial.available()){
ch = HostSerial.read();
if(isEscapeChar(ch)){
drawMainMenu();
return;
}
HostSerial.print(ch);
// Send to rtty.
if(machine_type == 32)
rttySendChar(ch);
else // M33
ascii_rttySendChar(ch);
// Send to teletype
ttySendChar(ch);
}
}