175 |
return (rigmode); |
return (rigmode); |
176 |
} |
} |
177 |
|
|
178 |
/* Retrieve frequency, mode, signal strength and power with hamlib commands. |
static void hamlib_error(gint code) |
|
* In case of a timeout we return immediately, we would otherwise |
|
|
* block the user interface. We use 4 hamlib commands, which each have 200ms |
|
|
* timeout. The timer which calls get_riginfo does this every 350 ms. |
|
|
* Also, we never get info from a rig one after another, state.hlcounter counts |
|
|
* the number of hamlib commands and each command is invoked seperately |
|
|
* when this function is called. This is needed to let hamlib recover from errors. |
|
|
*/ |
|
|
gint |
|
|
poll_riginfo (void) |
|
179 |
{ |
{ |
180 |
gint retcode, strength, spoint, i, status, smax = 1; |
gchar *message; |
181 |
freq_t freq; |
|
182 |
|
message = g_strdup_printf (_("Hamlib error %d: %s"), code, |
183 |
|
rigerror (code)); |
184 |
|
update_statusbar (message); |
185 |
|
g_free (message); |
186 |
|
} |
187 |
|
|
188 |
|
/* get power level from the rig */ |
189 |
|
void get_powerlevel(void) |
190 |
|
{ |
191 |
|
gint retcode, status; |
192 |
|
value_t val; |
193 |
|
|
194 |
|
retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &val); |
195 |
|
if (retcode == RIG_OK) |
196 |
|
{ |
197 |
|
status = rig_power2mW (myrig, &state.rigpower, val.f, state.rigfrequency, |
198 |
|
state.rigmode); |
199 |
|
} |
200 |
|
else if (retcode != -RIG_ENAVAIL) |
201 |
|
hamlib_error(retcode); |
202 |
|
} |
203 |
|
|
204 |
|
/* get mode */ |
205 |
|
void get_mode(void) |
206 |
|
{ |
207 |
|
gint retcode; |
208 |
rmode_t rmode; |
rmode_t rmode; |
209 |
pbwidth_t width; |
pbwidth_t width; |
210 |
ptt_t ptt; |
|
211 |
value_t val; |
retcode = rig_get_mode (myrig, RIG_VFO_CURR, &rmode, &width); |
212 |
|
if (retcode == RIG_OK) |
213 |
|
{ |
214 |
|
state.rigmode = rmode; |
215 |
|
} |
216 |
|
else if (retcode != -RIG_ENAVAIL) |
217 |
|
hamlib_error(retcode); |
218 |
|
} |
219 |
|
|
220 |
|
/* get freq */ |
221 |
|
void get_frequency(void) |
222 |
|
{ |
223 |
|
gint retcode; |
224 |
|
freq_t freq; |
225 |
GString *digits = g_string_new (""); |
GString *digits = g_string_new (""); |
226 |
GtkWidget *frequencylabel; |
GtkWidget *frequencylabel; |
|
gchar *message; |
|
227 |
|
|
228 |
/* get freq */ |
retcode = rig_get_freq (myrig, RIG_VFO_CURR, &freq); |
229 |
|
if (retcode == RIG_OK) |
230 |
|
{ |
231 |
|
state.rigfrequency = freq; |
232 |
|
if ((preferences.hamlib == 2) || (preferences.hamlib == 4)) |
233 |
|
{ |
234 |
|
if (preferences.round == 0) |
235 |
|
g_string_printf (digits, "%Ld", freq); |
236 |
|
else |
237 |
|
g_string_printf (digits, "%Ld", (long long) rintl (freq / |
238 |
|
pow (10, preferences. round))); |
239 |
|
g_string_insert_c (digits, (digits->len) - 6 + preferences.round, |
240 |
|
'.'); |
241 |
|
g_strstrip (digits->str); |
242 |
|
g_strdelimit (digits->str, " ", '0'); |
243 |
|
digits = g_string_append (digits, " MHz"); |
244 |
|
frequencylabel = lookup_widget (mainwindow, "frequencylabel"); |
245 |
|
gtk_label_set_text (GTK_LABEL (frequencylabel), digits->str); |
246 |
|
g_string_free (digits, TRUE); |
247 |
|
} |
248 |
|
} |
249 |
|
else if (retcode != -RIG_ENAVAIL) |
250 |
|
hamlib_error(retcode); |
251 |
|
} |
252 |
|
|
253 |
|
/* are we transmitting or receiving ? */ |
254 |
|
void get_ptt(void) |
255 |
|
{ |
256 |
|
gint retcode; |
257 |
|
ptt_t ptt; |
258 |
|
|
259 |
|
retcode = rig_get_ptt (myrig, RIG_VFO_CURR, &ptt); |
260 |
|
if (retcode == RIG_OK) |
261 |
|
{ |
262 |
|
if (ptt == RIG_PTT_OFF) |
263 |
|
state.tx = FALSE; |
264 |
|
else |
265 |
|
state.tx = TRUE; |
266 |
|
} |
267 |
|
else if (retcode != -RIG_ENAVAIL) |
268 |
|
hamlib_error(retcode); |
269 |
|
} |
270 |
|
|
271 |
|
/* get s-meter value */ |
272 |
|
void get_smeter(void) |
273 |
|
{ |
274 |
|
gint retcode, strength, spoint, i, smax = 1; |
275 |
|
|
276 |
|
retcode = rig_get_strength (myrig, RIG_VFO_CURR, &strength); |
277 |
|
if (retcode == RIG_OK) |
278 |
|
{ |
279 |
|
if (strength >= 0) |
280 |
|
spoint = 9; |
281 |
|
else if (strength < -60) |
282 |
|
spoint = 0; |
283 |
|
else |
284 |
|
spoint = (gint) ceil ((strength + 60) / 6); |
285 |
|
svalue[state.scounter] = spoint; |
286 |
|
state.scounter++; |
287 |
|
if (state.scounter == 10) |
288 |
|
state.scounter = 0; |
289 |
|
|
290 |
|
/* find maximum of s-meter during last 3 seconds */ |
291 |
|
for (i = 0; i < 10; i++) |
292 |
|
if (svalue[i] > smax) smax = svalue[i]; |
293 |
|
|
294 |
|
if ((preferences.hamlib == 3) || (preferences.hamlib == 4)) |
295 |
|
draw_smeter (smax); |
296 |
|
|
297 |
|
if (smax == 0) smax = 1; |
298 |
|
if ((state.rigmode == RIG_MODE_CW) || (state.rigmode == RIG_MODE_RTTY)) |
299 |
|
state.rigrst = g_strdup_printf ("5%d9", smax); |
300 |
|
else |
301 |
|
state.rigrst = g_strdup_printf ("5%d", smax); |
302 |
|
} |
303 |
|
else if (retcode != -RIG_ENAVAIL) |
304 |
|
hamlib_error(retcode); |
305 |
|
} |
306 |
|
|
307 |
|
/* poll the rig */ |
308 |
|
gint |
309 |
|
poll_riginfo (void) |
310 |
|
{ |
311 |
if (state.hlcounter == 0) |
if (state.hlcounter == 0) |
312 |
{ |
{ |
|
retcode = rig_get_freq (myrig, RIG_VFO_CURR, &freq); |
|
313 |
state.hlcounter++; |
state.hlcounter++; |
314 |
if (retcode == RIG_OK) |
get_frequency(); |
315 |
{ |
return 1; |
|
state.rigfrequency = freq; |
|
|
if ((preferences.hamlib == 2) || (preferences.hamlib == 4)) |
|
|
{ |
|
|
if (preferences.round == 0) |
|
|
g_string_printf (digits, "%Ld", freq); |
|
|
else |
|
|
g_string_printf (digits, "%Ld", (long long) rintl (freq / |
|
|
pow (10, preferences. round))); |
|
|
g_string_insert_c (digits, (digits->len) - 6 + preferences.round, |
|
|
'.'); |
|
|
g_strstrip (digits->str); |
|
|
g_strdelimit (digits->str, " ", '0'); |
|
|
digits = g_string_append (digits, " MHz"); |
|
|
frequencylabel = lookup_widget (mainwindow, "frequencylabel"); |
|
|
gtk_label_set_text (GTK_LABEL (frequencylabel), digits->str); |
|
|
g_string_free (digits, TRUE); |
|
|
} |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = g_strdup_printf (_("Hamlib error %d: %s"), retcode, |
|
|
rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
316 |
} |
} |
|
|
|
|
/* get mode */ |
|
317 |
if (state.hlcounter == 1) |
if (state.hlcounter == 1) |
318 |
{ |
{ |
|
retcode = rig_get_mode (myrig, RIG_VFO_CURR, &rmode, &width); |
|
319 |
state.hlcounter++; |
state.hlcounter++; |
320 |
if (retcode == RIG_OK) |
get_mode(); |
321 |
{ |
return 1; |
|
state.rigmode = rmode; |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = g_strdup_printf (_("Hamlib error %d: %s"), retcode, |
|
|
rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
322 |
} |
} |
|
|
|
|
/* are we transmitting or receiving ? */ |
|
323 |
if (state.hlcounter == 2) |
if (state.hlcounter == 2) |
324 |
{ |
{ |
|
retcode = rig_get_ptt (myrig, RIG_VFO_CURR, &ptt); |
|
325 |
state.hlcounter++; |
state.hlcounter++; |
326 |
if (retcode == RIG_OK) |
get_ptt(); |
327 |
{ |
return 1; |
|
if (ptt == RIG_PTT_OFF) |
|
|
state.tx = FALSE; |
|
|
else |
|
|
state.tx = TRUE; |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = g_strdup_printf (_("Hamlib error %d: %s"), retcode, |
|
|
rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
328 |
} |
} |
|
|
|
|
/* get s-meter value */ |
|
329 |
if (state.hlcounter == 3) |
if (state.hlcounter == 3) |
330 |
{ |
{ |
331 |
|
state.hlcounter++; |
332 |
if (!state.tx) |
if (!state.tx) |
333 |
{ |
get_smeter(); |
334 |
retcode = rig_get_strength (myrig, RIG_VFO_CURR, &strength); |
else if ((preferences.hamlib == 3) || (preferences.hamlib == 4)) |
335 |
state.hlcounter++; |
draw_smeter (0); |
336 |
if (retcode == RIG_OK) |
return 1; |
|
{ |
|
|
if (strength >= 0) |
|
|
spoint = 9; |
|
|
else if (strength < -60) |
|
|
spoint = 0; |
|
|
else |
|
|
spoint = (gint) ceil ((strength + 60) / 6); |
|
|
svalue[state.scounter] = spoint; |
|
|
state.scounter++; |
|
|
if (state.scounter == 10) |
|
|
state.scounter = 0; |
|
|
|
|
|
/* find maximum of s-meter during last 3 seconds */ |
|
|
for (i = 0; i < 10; i++) |
|
|
if (svalue[i] > smax) smax = svalue[i]; |
|
|
|
|
|
if ((preferences.hamlib == 3) || (preferences.hamlib == 4)) |
|
|
draw_smeter (smax); |
|
|
|
|
|
if (smax == 0) smax = 1; |
|
|
if ((state.rigmode == RIG_MODE_CW) |
|
|
|| (state.rigmode == RIG_MODE_RTTY)) |
|
|
state.rigrst = g_strdup_printf ("5%d9", smax); |
|
|
else |
|
|
state.rigrst = g_strdup_printf ("5%d", smax); |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = g_strdup_printf (_("Hamlib error %d: %s"), retcode, |
|
|
rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
state.hlcounter++; |
|
|
if ((preferences.hamlib == 3) || (preferences.hamlib == 4)) |
|
|
draw_smeter (0); |
|
|
} |
|
337 |
} |
} |
|
|
|
|
/* get power level */ |
|
338 |
if (state.hlcounter == 4) |
if (state.hlcounter == 4) |
339 |
{ |
{ |
340 |
state.hlcounter = 0; |
state.hlcounter = 0; |
341 |
retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &val); |
get_powerlevel(); |
342 |
if (retcode == RIG_OK) |
return 1; |
|
{ |
|
|
status = rig_power2mW (myrig, &state.rigpower, val.f, |
|
|
state.rigfrequency, state.rigmode); |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = g_strdup_printf (_("Hamlib error %d: %s"), retcode, |
|
|
rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
343 |
} |
} |
344 |
return 1; |
return 1; |
345 |
} |
} |
346 |
|
|
|
gint |
|
|
get_riginfo (void) |
|
|
{ |
|
|
gint retcode, strength, spoint, status; |
|
|
freq_t freq; |
|
|
rmode_t rmode; |
|
|
pbwidth_t width; |
|
|
ptt_t ptt; |
|
|
value_t val; |
|
|
GString *digits = g_string_new (""); |
|
|
GtkWidget *frequencylabel; |
|
|
gchar *message; |
|
|
|
|
|
/* get frequency */ |
|
|
retcode = rig_get_freq (myrig, RIG_VFO_CURR, &freq); |
|
|
if (retcode == RIG_OK) |
|
|
{ |
|
|
state.rigfrequency = freq; |
|
|
if ((preferences.hamlib == 2) || (preferences.hamlib == 4)) |
|
|
{ |
|
|
if (preferences.round == 0) |
|
|
g_string_printf (digits, "%Ld", freq); |
|
|
else |
|
|
g_string_printf (digits, "%Ld", (long long) rintl (freq / |
|
|
pow (10, preferences. round))); |
|
|
g_string_insert_c (digits, (digits->len) - 6 + preferences.round, '.'); |
|
|
g_strstrip (digits->str); |
|
|
g_strdelimit (digits->str, " ", '0'); |
|
|
digits = g_string_append (digits, " MHz"); |
|
|
frequencylabel = lookup_widget (mainwindow, "frequencylabel"); |
|
|
gtk_label_set_text (GTK_LABEL (frequencylabel), digits->str); |
|
|
g_string_free (digits, TRUE); |
|
|
} |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = g_strdup_printf (_("Hamlib error %d: %s"), retcode, |
|
|
rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
/* get mode */ |
|
|
retcode = rig_get_mode (myrig, RIG_VFO_CURR, &rmode, &width); |
|
|
if (retcode == RIG_OK) |
|
|
{ |
|
|
state.rigmode = rmode; |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = g_strdup_printf (_("Hamlib error %d: %s"), retcode, |
|
|
rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
/* are we transmitting or receiving ? */ |
|
|
retcode = rig_get_ptt (myrig, RIG_VFO_CURR, &ptt); |
|
|
if (retcode == RIG_OK) |
|
|
{ |
|
|
if (ptt == RIG_PTT_OFF) |
|
|
state.tx = FALSE; |
|
|
else |
|
|
state.tx = TRUE; |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = |
|
|
g_strdup_printf (_("Hamlib error %d: %s"), retcode, rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
/* get s-meter value if receiving */ |
|
|
if (!state.tx) |
|
|
{ |
|
|
retcode = rig_get_strength (myrig, RIG_VFO_CURR, &strength); |
|
|
if (retcode == RIG_OK) |
|
|
{ |
|
|
if (strength >= 0) |
|
|
spoint = 9; |
|
|
else if (strength < -60) |
|
|
spoint = 0; |
|
|
else |
|
|
spoint = (gint) ceil ((strength + 60) / 6); |
|
|
|
|
|
if ((preferences.hamlib == 3) || (preferences.hamlib == 4)) |
|
|
draw_smeter (spoint); |
|
|
|
|
|
if ((state.rigmode == RIG_MODE_CW) || (state.rigmode == RIG_MODE_RTTY)) |
|
|
state.rigrst = g_strdup_printf ("5%d9", spoint); |
|
|
else |
|
|
state.rigrst = g_strdup_printf ("5%d", spoint); |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = g_strdup_printf (_("Hamlib error %d: %s"), retcode, |
|
|
rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
else if ((preferences.hamlib == 3) || (preferences.hamlib == 4)) |
|
|
draw_smeter (0); |
|
|
|
|
|
/* get power level */ |
|
|
retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &val); |
|
|
if (retcode == RIG_OK) |
|
|
{ |
|
|
status = rig_power2mW (myrig, &state.rigpower, val.f, state.rigfrequency, |
|
|
state.rigmode); |
|
|
} |
|
|
else if (retcode != -RIG_ENAVAIL) |
|
|
{ |
|
|
message = g_strdup_printf (_("Hamlib error %d: %s"), retcode, |
|
|
rigerror (retcode)); |
|
|
update_statusbar (message); |
|
|
g_free (message); |
|
|
return 1; |
|
|
} |
|
|
|
|
|
return 0; |
|
|
} |
|
347 |
|
|
348 |
/* set appearance of some widgets dependent on preferences.hamlib */ |
/* set appearance of some widgets dependent on preferences.hamlib */ |
349 |
void |
void |