Skip to content

Commit 06a0b4c

Browse files
committed
wip
1 parent ec0c62e commit 06a0b4c

File tree

8 files changed

+75
-92
lines changed

8 files changed

+75
-92
lines changed

src/callinput.c

-8
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
#include "nicebox.h" // Includes curses.h
6161
#include "note.h"
6262
#include "printcall.h"
63-
#include "qrb.h"
6463
#include "qtcvars.h" // Includes globalvars.h
6564
#include "qtcwin.h"
6665
#include "rtty.h"
@@ -714,13 +713,6 @@ int callinput(void) {
714713
break;
715714
}
716715

717-
// Ctrl-D (^D), rotate antenna "d"irection.
718-
case CTRL_D: {
719-
rotate_to_qrb();
720-
721-
break;
722-
}
723-
724716
// Ctrl-F (^F), change frequency dialog.
725717
case CTRL_F: {
726718
change_freq();

src/keyer.c

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "keystroke_names.h"
3636
#include "netkeyer.h"
3737
#include "nicebox.h" // Includes curses.h
38+
#include "qrb.h"
3839
#include "sendbuf.h"
3940
#include "speedupndown.h"
4041
#include "stoptx.h"
@@ -163,6 +164,13 @@ int handle_common_key(int key) {
163164
break;
164165
}
165166

167+
// Ctrl-D (^D), rotate antenna "d"irection.
168+
case CTRL_D: {
169+
rotate_to_qrb();
170+
171+
break;
172+
}
173+
166174
// Alt-0 to Alt-9 (M-0...M-9), send CW/Digimode messages 15-24.
167175
case 128+'0' ... 128+'9': {
168176
int index = key - (128 + '0') + CQ_TU_MSG + 1;

src/main.c

+10-8
Original file line numberDiff line numberDiff line change
@@ -357,16 +357,13 @@ int rig_comm_error = 0;
357357
int rig_comm_success = 0;
358358

359359
/*-------------------------------------rotctl-------------------------------*/
360-
bool rot_control = false;
361-
int myrot_model = 0; /* unset */
360+
bool rot_control;
361+
int myrot_model; /* unset */
362362
char rotconf[80];
363363
ROT *my_rot; /* handle to rotator (instance) */
364364
pthread_mutex_t tlf_rot_mutex = PTHREAD_MUTEX_INITIALIZER;
365-
int rot_serial_rate = 2400;
365+
int rot_serial_rate;
366366
char *rotportname;
367-
int rotnumber = 0;
368-
int rot_comm_error = 0;
369-
int rot_comm_success = 0;
370367

371368
/*----------------------------------fldigi---------------------------------*/
372369
char fldigi_url[50] = "http://localhost:7362/RPC2";
@@ -677,6 +674,11 @@ static void init_variables() {
677674
rig_mode_sync = true;
678675
use_bandoutput = false;
679676

677+
/* rotctl */
678+
rot_control = false;
679+
myrot_model = 0; /* unset */
680+
rot_serial_rate = 2400;
681+
680682
lan_active = false;
681683
thisnode = 'A';
682684
lan_port = 6788;
@@ -842,8 +844,8 @@ static void hamlib_rot_init() {
842844
endwin();
843845
exit(1);
844846
}
845-
trx_control = false;
846-
trx_control_disabled = true;
847+
rot_control = false;
848+
rot_control_disabled = true;
847849
showmsg("Disabling rotator control!");
848850
sleep(1);
849851
}

src/qrb.c

+48-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "err_utils.h"
2323
#include "getctydata.h"
2424
#include "globalvars.h"
25-
#include "startmsg.h"
25+
#include "showmsg.h"
2626
#include "qrb.h"
2727

2828
static int parse_rotconf();
@@ -99,28 +99,63 @@ int init_tlf_rot(void) {
9999
return 0;
100100
}
101101

102+
double get_rotator_bearing() {
103+
int retcode;
104+
azimuth_t azimuth;
105+
elevation_t elevation; /* ignored */
106+
107+
if (! rot_control)
108+
return 0.0;
109+
110+
pthread_mutex_lock(&tlf_rot_mutex);
111+
retcode = rot_get_position(my_rot, &azimuth, &elevation);
112+
pthread_mutex_unlock(&tlf_rot_mutex);
113+
114+
if (retcode != RIG_OK) {
115+
TLF_LOG_WARN("Rotator get position error: %s", rigerror(retcode));
116+
}
117+
118+
return azimuth;
119+
}
120+
102121
void rotate_to_qrb() {
103122
double bearing;
104123
double range;
105124
int retcode; /* generic return code from functions */
106125
int pfx_index = getctydata_pfx(current_qso.call);
107-
108126
prefix_data *pfx = prefix_by_index(pfx_index);
109127

110-
if (pfx->dxcc_ctynr > 0) {
128+
if (! rot_control)
129+
return;
111130

112-
if (pfx_index != my.countrynr && 0 == get_qrb(&range, &bearing)) {
131+
if (pfx->dxcc_ctynr <= 0)
132+
return; /* unknown country */
133+
if (pfx->dxcc_ctynr == my.countrynr)
134+
return; /* rotating to own country does not make much sense */
113135

114-
pthread_mutex_lock(&tlf_rot_mutex);
115-
retcode = rot_set_position(my_rot, bearing, 0.0); // azimuth, elevation
116-
pthread_mutex_unlock(&tlf_rot_mutex);
136+
if (get_qrb(&range, &bearing) == RIG_OK) {
137+
pthread_mutex_lock(&tlf_rot_mutex);
138+
retcode = rot_set_position(my_rot, bearing, 0.0); // azimuth, elevation
139+
pthread_mutex_unlock(&tlf_rot_mutex);
117140

118-
if (retcode != RIG_OK) {
119-
TLF_LOG_WARN("Problem with setting rotator position: %s", rigerror(retcode));
120-
} else {
121-
showmsg("Rotator set position ok!");
122-
}
123-
}
141+
if (retcode != RIG_OK) {
142+
TLF_LOG_WARN("Problem with setting rotator position: %s", rigerror(retcode));
143+
}
144+
}
145+
}
146+
147+
void stop_rotator() {
148+
int retcode;
149+
150+
if (! rot_control)
151+
return;
152+
153+
pthread_mutex_lock(&tlf_rot_mutex);
154+
retcode = rot_stop(my_rot);
155+
pthread_mutex_unlock(&tlf_rot_mutex);
156+
157+
if (retcode != RIG_OK) {
158+
TLF_LOG_WARN("Rotator stop error: %s", rigerror(retcode));
124159
}
125160
}
126161

src/qrb.h

+2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ int get_qrb(double *range, double *bearing);
2929
bool get_qrb_for_locator(const char *locator, double *range, double *bearing);
3030

3131
int init_tlf_rot(void);
32+
double get_rotator_bearing();
3233
void rotate_to_qrb();
34+
void stop_rotator();
3335
void close_tlf_rot(ROT *my_rot);
3436

3537
#endif /* end of include guard: QRB_H */

src/stoptx.c

+3
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@
2929
#include "globalvars.h"
3030
#include "hamlib_keyer.h"
3131
#include "netkeyer.h"
32+
#include "qrb.h"
3233
#include "tlf.h"
3334
#include "tlf_curses.h"
3435

3536
#include "fldigixmlrpc.h"
3637

3738
int stoptx(void) {
39+
/* whenever TX is stopped, stop rotator as well */
40+
stop_rotator();
3841

3942
if (digikeyer == FLDIGI && trxmode == DIGIMODE) {
4043
fldigi_to_rx();

test/test_rules.c

-63
This file was deleted.

tlf.1.in

+4
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,10 @@ or abort sending by pressing the
11781178
key.
11791179
.
11801180
.TP
1181+
.B Ctrl-D
1182+
Rotate antenna towards the country of the current call ("direction"), if a rotator is configured.
1183+
.
1184+
.TP
11811185
.B Ctrl-E
11821186
End modem capture for RTTY mode in QTC window (started with
11831187
.BR Ctrl-S ).

0 commit comments

Comments
 (0)