|
22 | 22 | #include "err_utils.h" |
23 | 23 | #include "getctydata.h" |
24 | 24 | #include "globalvars.h" |
25 | | -#include "startmsg.h" |
| 25 | +#include "showmsg.h" |
26 | 26 | #include "qrb.h" |
27 | 27 |
|
28 | 28 | static int parse_rotconf(); |
@@ -99,28 +99,63 @@ int init_tlf_rot(void) { |
99 | 99 | return 0; |
100 | 100 | } |
101 | 101 |
|
| 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 | + |
102 | 121 | void rotate_to_qrb() { |
103 | 122 | double bearing; |
104 | 123 | double range; |
105 | 124 | int retcode; /* generic return code from functions */ |
106 | 125 | int pfx_index = getctydata_pfx(current_qso.call); |
107 | | - |
108 | 126 | prefix_data *pfx = prefix_by_index(pfx_index); |
109 | 127 |
|
110 | | - if (pfx->dxcc_ctynr > 0) { |
| 128 | + if (! rot_control) |
| 129 | + return; |
111 | 130 |
|
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 */ |
113 | 135 |
|
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); |
117 | 140 |
|
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)); |
124 | 159 | } |
125 | 160 | } |
126 | 161 |
|
|
0 commit comments