1 /*
2 * Tlf - contest logging program for amateur radio operators
3 * Copyright (C) 2001-2002-2003 Rein Couperus <pa0rct@amsat.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20 /* ------------------------------------------------------------
21 * AUTO_CQ
22 *
23 *--------------------------------------------------------------*/
24
25
26 #include <unistd.h>
27 #include <ctype.h>
28
29 #include "clear_display.h"
30 #include "cw_utils.h"
31 #include "globalvars.h"
32 #include "printcall.h"
33 #include "sendbuf.h"
34 #include "stoptx.h"
35 #include "tlf.h"
36 #include "tlf_curses.h"
37 #include "ui_utils.h"
38 #include "time_update.h"
39
40
41 int play_file(char *audiofile);
42
43 //
44 // get estimated CQ length in milliseconds
45 // returns 0 if can't be determined
46 //
get_autocq_time()47 static int get_autocq_time() {
48 if (trxmode != CWMODE) {
49 return 0; // unknown
50 }
51 const int cw_message_len = cw_message_length(message[11]);
52 return (int)(1200.0 / GetCWSpeed()) * cw_message_len;
53 }
54
55
auto_cq(void)56 int auto_cq(void) {
57 extern char message[][80];
58 extern int cqdelay;
59 extern cqmode_t cqmode;
60
61 #define NO_KEY -1
62
63 int key = NO_KEY;
64
65 const cqmode_t cqmode_save = cqmode;
66 cqmode = AUTO_CQ;
67 show_header_line();
68
69 const long message_time = get_autocq_time();
70
71 while (key == NO_KEY) {
72
73 send_standard_message(11);
74
75 mvprintw(12, 29, "");
76
77 attron(modify_attr(COLOR_PAIR(NORMCOLOR)));
78
79 // if length of message is known then wait until its end
80 // key press terminates auto CQ loop
81 if (message_time > 0) {
82 for (int j = 0; j < 10 && key == NO_KEY; j++) {
83 usleep(message_time * 100);
84 time_update();
85 const int inchar = key_poll();
86 if (inchar > 0) {
87 key = inchar;
88 }
89 }
90 }
91
92 // wait between calls
93 for (int delayval = cqdelay; delayval > 0 && key == NO_KEY; delayval--) {
94
95 mvprintw(12, 29, "Auto CQ %-2d ", delayval - 1);
96 refreshp();
97
98 usleep(500000); // 500 ms
99 time_update();
100
101 const int inchar = key_poll();
102 if (inchar > 0) {
103 key = inchar;
104 }
105 }
106
107 mvprintw(12, 29, spaces(13));
108 mvprintw(12, 29, "");
109 refreshp();
110 }
111
112 stoptx();
113
114 cqmode = cqmode_save;
115 show_header_line();
116
117 attron(modify_attr(COLOR_PAIR(NORMCOLOR)));
118
119 mvprintw(12, 29, spaces(13));
120 printcall();
121
122 return toupper(key);
123 }
124
125
126