2000-10-01 12:53:01 +00:00
|
|
|
/*
|
|
|
|
* Hamlib sample program
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2000-12-05 22:04:44 +00:00
|
|
|
#include <unistd.h>
|
2001-05-04 22:46:47 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <hamlib/rig.h>
|
2000-10-01 12:53:01 +00:00
|
|
|
|
|
|
|
#define SERIAL_PORT "/dev/ttyS0"
|
|
|
|
|
2001-05-04 22:46:47 +00:00
|
|
|
int main (int argc, char *argv[])
|
2000-10-01 12:53:01 +00:00
|
|
|
{
|
|
|
|
RIG *my_rig; /* handle to rig (nstance) */
|
|
|
|
freq_t freq; /* frequency */
|
|
|
|
rmode_t rmode; /* radio mode of operation */
|
2000-12-05 19:32:48 +00:00
|
|
|
pbwidth_t width;
|
2000-10-01 12:53:01 +00:00
|
|
|
vfo_t vfo; /* vfo selection */
|
2000-10-08 21:48:52 +00:00
|
|
|
int strength; /* S-Meter level */
|
2000-10-01 12:53:01 +00:00
|
|
|
int retcode; /* generic return code from functions */
|
2001-06-10 22:31:44 +00:00
|
|
|
rig_model_t myrig_model;
|
2000-10-01 12:53:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
printf("testrig:hello, I am your main() !\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* allocate memory, setup & open port
|
|
|
|
*/
|
|
|
|
|
2001-06-10 22:31:44 +00:00
|
|
|
if (argc < 2) {
|
2005-04-03 12:27:17 +00:00
|
|
|
hamlib_port_t myport;
|
2001-06-10 22:31:44 +00:00
|
|
|
/* may be overriden by backend probe */
|
|
|
|
myport.type.rig = RIG_PORT_SERIAL;
|
|
|
|
myport.parm.serial.rate = 9600;
|
|
|
|
myport.parm.serial.data_bits = 8;
|
|
|
|
myport.parm.serial.stop_bits = 1;
|
|
|
|
myport.parm.serial.parity = RIG_PARITY_NONE;
|
|
|
|
myport.parm.serial.handshake = RIG_HANDSHAKE_NONE;
|
2001-07-25 21:59:55 +00:00
|
|
|
strncpy(myport.pathname, SERIAL_PORT, FILPATHLEN);
|
2001-06-10 22:31:44 +00:00
|
|
|
|
|
|
|
rig_load_all_backends();
|
|
|
|
myrig_model = rig_probe(&myport);
|
|
|
|
} else {
|
|
|
|
myrig_model = atoi(argv[1]);
|
2000-10-08 21:48:52 +00:00
|
|
|
}
|
|
|
|
|
2001-06-10 22:31:44 +00:00
|
|
|
my_rig = rig_init(myrig_model);
|
2001-05-04 22:46:47 +00:00
|
|
|
|
|
|
|
if (!my_rig) {
|
2001-06-10 22:31:44 +00:00
|
|
|
fprintf(stderr,"Unknown rig num: %d\n", myrig_model);
|
2001-05-04 22:46:47 +00:00
|
|
|
fprintf(stderr,"Please check riglist.h\n");
|
|
|
|
exit(1); /* whoops! something went wrong (mem alloc?) */
|
|
|
|
}
|
2000-10-01 12:53:01 +00:00
|
|
|
|
2001-07-25 21:59:55 +00:00
|
|
|
strncpy(my_rig->state.rigport.pathname,SERIAL_PORT,FILPATHLEN);
|
2000-10-01 12:53:01 +00:00
|
|
|
|
2001-06-10 22:31:44 +00:00
|
|
|
retcode = rig_open(my_rig);
|
|
|
|
if (retcode != RIG_OK) {
|
|
|
|
printf("rig_open: error = %s\n", rigerror(retcode));
|
|
|
|
exit(2);
|
|
|
|
}
|
2000-10-01 12:53:01 +00:00
|
|
|
|
|
|
|
printf("Port %s opened ok\n", SERIAL_PORT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Below are examples of set/get routines.
|
|
|
|
* Must add checking of functionality map prior to command execution -- FS
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2000-12-09 21:50:09 +00:00
|
|
|
* Example of setting rig paameters
|
2000-10-01 12:53:01 +00:00
|
|
|
* and some error checking on the return code.
|
|
|
|
*/
|
|
|
|
|
2000-10-09 01:17:20 +00:00
|
|
|
retcode = rig_set_vfo(my_rig, RIG_VFO_B);
|
|
|
|
|
2000-10-01 12:53:01 +00:00
|
|
|
|
|
|
|
if (retcode != RIG_OK ) {
|
|
|
|
printf("rig_set_vfo: error = %s \n", rigerror(retcode));
|
|
|
|
}
|
|
|
|
|
2000-11-25 21:52:41 +00:00
|
|
|
|
|
|
|
/*
|
2000-12-13 01:27:43 +00:00
|
|
|
* Lets try some frequencies and modes. Return code is not checked.
|
|
|
|
* Examples of checking return code are further down.
|
|
|
|
*
|
2000-11-25 21:52:41 +00:00
|
|
|
*/
|
|
|
|
|
2000-12-13 01:27:43 +00:00
|
|
|
/* 10m FM Narrow */
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 28350125); /* 10m */
|
2001-05-04 22:46:47 +00:00
|
|
|
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_FM,
|
|
|
|
rig_passband_narrow(my_rig, RIG_MODE_FM));
|
2000-12-13 01:27:43 +00:00
|
|
|
sleep(3); /* so you can see it -- FS */
|
|
|
|
|
|
|
|
/* 15m USB */
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 21235175); /* 15m */
|
2000-12-13 01:27:43 +00:00
|
|
|
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_USB, RIG_PASSBAND_NORMAL);
|
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
/* AM Broadcast band */
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 770000); /* KAAM */
|
2000-12-13 01:27:43 +00:00
|
|
|
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM, RIG_PASSBAND_NORMAL);
|
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
/* 40m LSB */
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 7250100); /* 40m */
|
2000-12-13 01:27:43 +00:00
|
|
|
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, RIG_PASSBAND_NORMAL);
|
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
/* 80m AM NArrow */
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 3980000); /* 80m */
|
2001-05-04 22:46:47 +00:00
|
|
|
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_AM,
|
|
|
|
rig_passband_narrow(my_rig, RIG_MODE_FM));
|
2000-12-13 01:27:43 +00:00
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
/* 160m CW Normal */
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 1875000); /* 160m */
|
2000-12-13 01:27:43 +00:00
|
|
|
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_CW, RIG_PASSBAND_NORMAL);
|
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
/* 160m CW Narrow -- The band is noisy tonight -- FS*/
|
|
|
|
|
2001-05-04 22:46:47 +00:00
|
|
|
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_CW,
|
|
|
|
rig_passband_narrow(my_rig, RIG_MODE_FM));
|
2000-12-13 01:27:43 +00:00
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
/* 20m USB on VFO_A */
|
|
|
|
|
|
|
|
retcode = rig_set_vfo(my_rig, RIG_VFO_A);
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 14250375); /* cq de vk3fcs */
|
2000-12-13 01:27:43 +00:00
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
/* 20m USB on VFO_A , with only 1 call */
|
|
|
|
|
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_A, 14295125); /* cq de vk3fcs */
|
|
|
|
sleep(3);
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-11-25 21:52:41 +00:00
|
|
|
#if 0
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 145100000); /* 2m */
|
2000-11-25 21:52:41 +00:00
|
|
|
sleep(2);
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_freq(my_rig, RIG_VFO_CURR, 435125000); /* 70cm */
|
2000-11-25 21:52:41 +00:00
|
|
|
sleep(2);
|
|
|
|
#endif
|
2000-10-01 12:53:01 +00:00
|
|
|
|
|
|
|
if (retcode != RIG_OK ) {
|
|
|
|
printf("rig_set_freq: error = %s \n", rigerror(retcode));
|
|
|
|
}
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_set_mode(my_rig, RIG_VFO_CURR, RIG_MODE_LSB, RIG_PASSBAND_NORMAL);
|
2000-10-01 12:53:01 +00:00
|
|
|
|
|
|
|
if (retcode != RIG_OK ) {
|
|
|
|
printf("rig_set_mode: error = %s \n", rigerror(retcode));
|
|
|
|
}
|
|
|
|
|
2000-12-09 21:50:09 +00:00
|
|
|
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_ON ); /* stand back ! */
|
|
|
|
|
|
|
|
if (retcode != RIG_OK ) {
|
|
|
|
printf("rig_set_ptt: error = %s \n", rigerror(retcode));
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
retcode = rig_set_ptt(my_rig, RIG_VFO_A, RIG_PTT_OFF ); /* phew ! */
|
|
|
|
|
|
|
|
if (retcode != RIG_OK ) {
|
|
|
|
printf("rig_set_ptt: error = %s \n", rigerror(retcode));
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
2000-10-01 12:53:01 +00:00
|
|
|
/*
|
|
|
|
* Simple examples of getting rig information -- FS
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
retcode = rig_get_vfo(my_rig, &vfo); /* try to get vfo info */
|
|
|
|
|
|
|
|
if (retcode == RIG_OK ) {
|
|
|
|
printf("rig_get_vfo: vfo = %i \n", vfo);
|
|
|
|
} else {
|
|
|
|
printf("rig_get_vfo: error = %s \n", rigerror(retcode));
|
|
|
|
}
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq);
|
2000-10-01 12:53:01 +00:00
|
|
|
|
|
|
|
if (retcode == RIG_OK ) {
|
2005-01-24 23:04:35 +00:00
|
|
|
printf("rig_get_freq: freq = %"PRIfreq"\n", freq);
|
2000-10-01 12:53:01 +00:00
|
|
|
} else {
|
|
|
|
printf("rig_get_freq: error = %s \n", rigerror(retcode));
|
|
|
|
}
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_get_mode(my_rig, RIG_VFO_CURR, &rmode, &width);
|
2000-10-01 12:53:01 +00:00
|
|
|
|
|
|
|
if (retcode == RIG_OK ) {
|
|
|
|
printf("rig_get_mode: mode = %i \n", rmode);
|
|
|
|
} else {
|
|
|
|
printf("rig_get_mode: error = %s \n", rigerror(retcode));
|
|
|
|
}
|
|
|
|
|
2000-12-05 22:04:44 +00:00
|
|
|
retcode = rig_get_strength(my_rig, RIG_VFO_CURR, &strength);
|
2000-10-08 21:48:52 +00:00
|
|
|
|
|
|
|
if (retcode == RIG_OK ) {
|
|
|
|
printf("rig_get_strength: strength = %i \n", strength);
|
|
|
|
} else {
|
|
|
|
printf("rig_get_strength: error = %s \n", rigerror(retcode));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-01 12:53:01 +00:00
|
|
|
rig_close(my_rig); /* close port */
|
|
|
|
rig_cleanup(my_rig); /* if you care about memory */
|
|
|
|
|
|
|
|
printf("port %s closed ok \n",SERIAL_PORT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|