1 /*
2 * Tlf - contest logging program for amateur radio operators
3 * Copyright (C) 2013 Ervin Hegedüs - HA2OS <airween@gmail.com>
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 Log received or sent QTC lines to disk, clear the qtc list
22
23 ------------------------------------------------------------------------*/
24
25
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "lancode.h"
30 #include "qtc_log.h"
31 #include "qtcutil.h"
32 #include "qtcvars.h" // Includes globalvars.h
33 #include "tlf_curses.h"
34
35 extern int trx_control;
36 extern freq_t freq;
37
log_recv_qtc_to_disk(int qsonr)38 int log_recv_qtc_to_disk(int qsonr) {
39
40 int i;
41 struct read_qtc_t qtc_line;
42
43 for (i = 0; i < 10; i++) {
44
45 if (strlen(qtcreclist.qtclines[i].time) == 4 &&
46 strlen(qtcreclist.qtclines[i].callsign) > 0 &&
47 strlen(qtcreclist.qtclines[i].serial) > 0) { // all fields are filled
48
49 qtc_line.direction = RECV;
50 strcpy(qtc_line.band, band[bandinx]);
51 if (trxmode == CWMODE) {
52 strcpy(qtc_line.mode, "CW ");
53 } else if (trxmode == SSBMODE) {
54 strcpy(qtc_line.mode, "PH ");
55 } else {
56 strcpy(qtc_line.mode, "DIG");
57 }
58
59 strncpy(qtc_line.date, qtcreclist.qtclines[i].receivedtime, 9);
60 qtc_line.date[9] = '\0';
61 strncpy(qtc_line.time, qtcreclist.qtclines[i].receivedtime + 10, 5);
62 qtc_line.time[5] = '\0';
63
64 qtc_line.qsonr = qsonr;
65
66 strcpy(qtc_line.call, qtcreclist.callsign);
67
68 qtc_line.qtchead_serial = qtcreclist.serial;
69 qtc_line.qtchead_count = qtcreclist.count;
70 strcpy(qtc_line.qtc_time, qtcreclist.qtclines[i].time);
71 qtc_line.qtc_time[4] = '\0';
72 strcpy(qtc_line.qtc_call, qtcreclist.qtclines[i].callsign);
73 qtc_line.qtc_call[strlen(qtcreclist.qtclines[i].callsign)] = '\0';
74 qtc_line.qtc_serial = atoi(qtcreclist.qtclines[i].serial);
75
76 if (trx_control == 1) {
77 qtc_line.freq = freq;
78 } else {
79 qtc_line.freq = 0;
80 }
81
82 qtc_line.callpos = 0;
83 make_qtc_logline(qtc_line, QTC_RECV_LOG);
84
85 }
86 }
87
88 /* clear all line infos */
89 for (i = 0; i < 10; i++) {
90 qtcreclist.qtclines[i].time[0] = '\0';
91 qtcreclist.qtclines[i].callsign[0] = '\0';
92 qtcreclist.qtclines[i].serial[0] = '\0';
93 qtcreclist.qtclines[i].status = 0;
94 qtcreclist.qtclines[i].confirmed = 0;
95 qtcreclist.qtclines[i].receivedtime[0] = '\0';
96 }
97 for (i = 0; i < QTC_RY_LINE_NR; i++) {
98 qtc_ry_lines[i].content[0] = '\0';
99 qtc_ry_lines[i].attr = 0;
100 }
101 qtc_ry_currline = 0;
102 qtc_ry_copied = 0;
103
104 /* clear record list */
105 qtcreclist.count = 0;
106 qtcreclist.serial = 0;
107 qtcreclist.confirmed = 0;
108 qtcreclist.sentcfmall = 0;
109 qtcreclist.callsign[0] = '\0';
110
111 return (0);
112 }
113
114
log_sent_qtc_to_disk(int qsonr)115 int log_sent_qtc_to_disk(int qsonr) {
116
117 int i;
118 char *tempstrp;
119 struct read_qtc_t qtc_line;
120
121 for (i = 0; i < 10; i++) {
122 if (qtclist.qtclines[i].saved == 0 && qtclist.qtclines[i].flag == 1
123 && qtclist.qtclines[i].sent == 1) { // not saved and marked for sent
124
125 qtc_line.direction = SEND;
126 strcpy(qtc_line.band, band[bandinx]);
127 if (trxmode == CWMODE) {
128 strcpy(qtc_line.mode, "CW ");
129 } else if (trxmode == SSBMODE) {
130 strcpy(qtc_line.mode, "PH ");
131 } else {
132 strcpy(qtc_line.mode, "DIG");
133 }
134
135 strncpy(qtc_line.date, qtclist.qtclines[i].senttime, 9);
136 qtc_line.date[9] = '\0';
137 strncpy(qtc_line.time, qtclist.qtclines[i].senttime + 10, 5);
138 qtc_line.time[5] = '\0';
139
140 qtc_line.qsonr = qsonr;
141
142 strcpy(qtc_line.call, qtclist.callsign);
143
144 qtc_line.qtchead_serial = qtclist.serial;
145 qtc_line.qtchead_count = qtclist.count;
146
147 strcpy(qtc_line.qtcstr, qtclist.qtclines[i].qtc);
148 tempstrp = strtok(qtc_line.qtcstr, " ");
149 if (tempstrp != NULL) {
150 strcpy(qtc_line.qtc_time, tempstrp);
151 } else {
152 strcpy(qtc_line.qtc_time, "----");
153 }
154
155 tempstrp = strtok(NULL, " ");
156 g_strchomp(tempstrp);
157 if (tempstrp != NULL) {
158 strcpy(qtc_line.qtc_call, tempstrp);
159 } else {
160 strcpy(qtc_line.qtc_call, "-------------");
161 }
162
163 tempstrp = strtok(NULL, " ");
164 g_strchomp(tempstrp);
165 if (tempstrp != NULL) {
166 qtc_line.qtc_serial = atoi(tempstrp);
167 } else {
168 qtc_line.qtc_serial = 0;
169 }
170
171 qtc_line.callpos = qtclist.qtclines[i].qsoline + 1;
172
173 if (trx_control == 1) {
174 qtc_line.freq = freq;
175 } else {
176 qtc_line.freq = 0;
177 }
178
179 make_qtc_logline(qtc_line, QTC_SENT_LOG);
180
181 }
182 }
183
184 for (i = 0; i < 10; i++) {
185 qtclist.qtclines[i].qtc[0] = '\0';
186 qtclist.qtclines[i].flag = 0;
187 qtclist.qtclines[i].saved = 0;
188 qtclist.qtclines[i].sent = 0;
189 qtclist.qtclines[i].senttime[0] = '\0';
190 }
191
192 qtclist.count = 0;
193 qtclist.marked = 0;
194 qtclist.totalsent = 0;
195
196 return (0);
197 }
198
199
200 /* common code to store sent or received QTC's */
store_qtc(char * loglineptr,int direction,char * filename)201 void store_qtc(char *loglineptr, int direction, char *filename) {
202
203 FILE *fp;
204 char callsign[15];
205 char temps[15];
206 int tempi;
207
208 if ((fp = fopen(filename, "a")) == NULL) {
209 fprintf(stdout, "Error opening file: %s\n", filename);
210 endwin();
211 exit(1);
212 }
213 fputs(loglineptr, fp);
214 fclose(fp);
215
216 total++;
217 if (direction == SEND) {
218 /* find maximum sent QTC block serial */
219 g_strlcpy(temps, loglineptr + 50, 5); // get serial of qtc block
220 tempi = atoi(temps);
221 if (tempi > nr_qtcsent) {
222 nr_qtcsent = tempi;
223 }
224
225 /* mark corresponding qso line as used for QTC */
226 g_strlcpy(temps, loglineptr + 12, 5); // qso nr in qso list
227 tempi = atoi(temps) - 1;
228 qsoflags_for_qtc[tempi] = 1;
229
230 /* find first unused QSO number for QTCs */
231 if (tempi == next_qtc_qso && tempi < MAX_QSOS) {
232 while (qsoflags_for_qtc[tempi++] == 1) {
233 if (tempi == MAX_QSOS)
234 break;
235 next_qtc_qso = tempi;
236 }
237 }
238 }
239 /* remember callsign, build number of sent or received QTC's */
240 parse_qtcline(loglineptr, callsign, direction);
241 qtc_inc(callsign, direction);
242 }
243
make_qtc_logline(struct read_qtc_t qtc_line,char * fname)244 void make_qtc_logline(struct read_qtc_t qtc_line, char *fname) {
245
246 char nodemark = ' ';
247 char qtclogline[120];
248 char padding[2] = " ";
249
250 if (lan_active == 1) {
251 nodemark = thisnode;
252 }
253
254 memset(qtclogline, '\0', 120);
255
256 if (qtc_line.qtc_serial >= 1000) {
257 padding[0] = '\0';
258 }
259
260 if (qtc_line.direction == RECV) {
261 sprintf(qtclogline,
262 "%s%s %04d %s %s %c %-14s %04d %04d %s %-15s%s%03d %7.1f\n", qtc_line.band,
263 qtc_line.mode, qtc_line.qsonr,
264 qtc_line.date, qtc_line.time, nodemark, qtc_line.call, qtc_line.qtchead_serial,
265 qtc_line.qtchead_count,
266 qtc_line.qtc_time, qtc_line.qtc_call, padding, qtc_line.qtc_serial,
267 qtc_line.freq / 1000.0);
268 store_qtc(qtclogline, qtc_line.direction, fname);
269 if (lan_active == 1) {
270 send_lan_message(QTCRENTRY, qtclogline);
271 }
272 }
273 if (qtc_line.direction == SEND) {
274 sprintf(qtclogline,
275 "%s%s %04d %04d %s %s %c %-14s %04d %04d %s %-14s%s%03d %7.1f\n",
276 qtc_line.band, qtc_line.mode, qtc_line.qsonr,
277 qtc_line.callpos, qtc_line.date, qtc_line.time, nodemark, qtc_line.call,
278 qtc_line.qtchead_serial, qtc_line.qtchead_count,
279 qtc_line.qtc_time, qtc_line.qtc_call, padding, qtc_line.qtc_serial,
280 qtc_line.freq / 1000.0);
281 store_qtc(qtclogline, qtc_line.direction, fname);
282 if (lan_active == 1) {
283 send_lan_message(QTCSENTRY, qtclogline);
284 }
285 }
286 }
287
288
289