2009-01-20 19:44:04 +00:00
|
|
|
/*
|
|
|
|
* Hamlib backend library for the HD 1780 Intellirotor command set.
|
|
|
|
*
|
|
|
|
* hd1780.c - (C) Nate Bargmann 2003 (n0nb at arrl.net)
|
|
|
|
* (C) Rob Frohne 2008 (kl7na at arrl.net)
|
|
|
|
*
|
|
|
|
* This shared library provides an API for communicating
|
|
|
|
* via serial interface to a Heathkit HD 1780 Intellirotor.
|
|
|
|
*
|
|
|
|
* Heathkit is a trademark of Heath Company
|
|
|
|
*
|
|
|
|
*
|
2011-08-21 00:34:57 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2009-01-20 19:44:04 +00:00
|
|
|
*
|
2011-08-21 00:34:57 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2009-01-20 19:44:04 +00:00
|
|
|
*
|
2011-08-21 00:34:57 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2009-01-20 19:44:04 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h> /* Standard library definitions */
|
|
|
|
#include <string.h> /* String function definitions */
|
|
|
|
#include <unistd.h> /* UNIX standard function definitions */
|
|
|
|
|
|
|
|
#include "hamlib/rotator.h"
|
|
|
|
#include "serial.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "register.h"
|
|
|
|
|
|
|
|
#include "hd1780.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private data structure
|
|
|
|
*/
|
2019-11-30 16:19:08 +00:00
|
|
|
struct hd1780_rot_priv_data
|
|
|
|
{
|
|
|
|
azimuth_t az;
|
2009-01-20 19:44:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private helper function prototypes
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int hd1780_send_priv_cmd(ROT *rot, const char *cmd);
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HD 1780 Intellirotor rotor capabilities
|
|
|
|
*/
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
const struct rot_caps hd1780_rot_caps =
|
|
|
|
{
|
2020-03-06 05:48:14 +00:00
|
|
|
ROT_MODEL(ROT_MODEL_HD1780),
|
2019-11-30 16:19:08 +00:00
|
|
|
.model_name = "HD 1780 Intellirotor",
|
|
|
|
.mfg_name = "Heathkit",
|
2020-06-08 21:13:08 +00:00
|
|
|
.version = "20200112.0",
|
2019-11-30 16:19:08 +00:00
|
|
|
.copyright = "LGPL",
|
|
|
|
.status = RIG_STATUS_BETA,
|
|
|
|
.rot_type = ROT_TYPE_OTHER,
|
|
|
|
.port_type = RIG_PORT_SERIAL,
|
|
|
|
.serial_rate_min = 300,
|
|
|
|
.serial_rate_max = 9600,
|
|
|
|
.serial_data_bits = 8,
|
|
|
|
.serial_stop_bits = 1,
|
|
|
|
.serial_parity = RIG_PARITY_NONE,
|
|
|
|
.serial_handshake = RIG_HANDSHAKE_NONE,
|
|
|
|
.write_delay = 10,
|
|
|
|
.post_write_delay = 500,
|
|
|
|
.timeout = 60000,
|
|
|
|
.retry = 0,
|
|
|
|
|
|
|
|
.min_az = -180,
|
|
|
|
.max_az = 180,
|
|
|
|
.min_el = 0,
|
|
|
|
.max_el = 0,
|
|
|
|
|
|
|
|
.priv = NULL, /* priv */
|
|
|
|
|
|
|
|
.rot_init = hd1780_rot_init,
|
|
|
|
.rot_cleanup = hd1780_rot_cleanup,
|
|
|
|
.set_position = hd1780_rot_set_position,
|
|
|
|
.get_position = hd1780_rot_get_position,
|
2009-01-20 19:44:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* ************************************
|
|
|
|
*
|
|
|
|
* API functions
|
|
|
|
*
|
|
|
|
* ************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize data structures
|
|
|
|
*/
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static int hd1780_rot_init(ROT *rot)
|
|
|
|
{
|
|
|
|
struct hd1780_rot_priv_data *priv;
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!rot)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2020-01-13 04:59:59 +00:00
|
|
|
rot->state.priv = (struct hd1780_rot_priv_data *)
|
2020-02-23 17:26:09 +00:00
|
|
|
malloc(sizeof(struct hd1780_rot_priv_data));
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2020-01-13 04:59:59 +00:00
|
|
|
if (!rot->state.priv)
|
2019-11-30 16:19:08 +00:00
|
|
|
{
|
|
|
|
return -RIG_ENOMEM;
|
|
|
|
}
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2020-01-13 04:59:59 +00:00
|
|
|
priv = rot->state.priv;
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rot->state.rotport.type.rig = RIG_PORT_SERIAL;
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
priv->az = 0;
|
|
|
|
|
|
|
|
return RIG_OK;
|
2009-01-20 19:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clean up allocated memory structures
|
|
|
|
*/
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static int hd1780_rot_cleanup(ROT *rot)
|
|
|
|
{
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!rot)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (rot->state.priv)
|
|
|
|
{
|
|
|
|
free(rot->state.priv);
|
|
|
|
}
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rot->state.priv = NULL;
|
|
|
|
|
|
|
|
return RIG_OK;
|
2009-01-20 19:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set position
|
|
|
|
* HD 1780 protocol supports azimuth only--elevation is ignored
|
|
|
|
* Range is converted to an integer string, 0 to 360 degrees
|
|
|
|
*/
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static int hd1780_rot_set_position(ROT *rot, azimuth_t azimuth,
|
|
|
|
elevation_t elevation)
|
|
|
|
{
|
|
|
|
struct rot_state *rs;
|
|
|
|
char cmdstr[8];
|
|
|
|
char execstr[5] = "\r", ok[3];
|
|
|
|
int err;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!rot)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (azimuth < hd1780_rot_caps.min_az || azimuth > hd1780_rot_caps.max_az)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (azimuth < 0) { azimuth = azimuth + 360; }
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
sprintf(cmdstr, "%03.0f", azimuth); /* Target bearing */
|
|
|
|
err = hd1780_send_priv_cmd(rot, cmdstr);
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (err != RIG_OK)
|
|
|
|
{
|
|
|
|
return err;
|
|
|
|
}
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
err = hd1780_send_priv_cmd(rot, execstr); /* Execute command */
|
2011-08-21 00:34:57 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (err != RIG_OK)
|
|
|
|
{
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We need to look for the <CR> +<LF> to signify that everything finished. The HD 1780
|
|
|
|
* sends a <CR> when it is finished rotating.
|
|
|
|
*/
|
|
|
|
rs = &rot->state;
|
|
|
|
err = read_block(&rs->rotport, ok, 2);
|
|
|
|
|
|
|
|
if (err != 2)
|
|
|
|
{
|
|
|
|
return -RIG_ETRUNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ok[0] != '\r') || (ok[1] != '\n'))
|
|
|
|
{
|
|
|
|
return -RIG_ETRUNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return RIG_OK;
|
2009-01-20 19:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get position
|
|
|
|
* Returns current azimuth position in whole degrees.
|
|
|
|
* Range returned from Rotor-EZ is an integer, 0 to 359 degrees
|
|
|
|
* Elevation is set to 0
|
|
|
|
*/
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static int hd1780_rot_get_position(ROT *rot, azimuth_t *azimuth,
|
|
|
|
elevation_t *elevation)
|
|
|
|
{
|
|
|
|
struct rot_state *rs;
|
|
|
|
char cmdstr[3] = "b\r";
|
|
|
|
char az[7]; /* read azimuth string */
|
|
|
|
char *p;
|
|
|
|
azimuth_t tmp = 0;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
|
|
|
|
|
|
|
if (!rot)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = hd1780_send_priv_cmd(rot, cmdstr);
|
|
|
|
|
|
|
|
if (err != RIG_OK)
|
|
|
|
{
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
rs = &rot->state;
|
|
|
|
err = read_block(&rs->rotport, az, AZ_READ_LEN);
|
|
|
|
|
|
|
|
if (err != AZ_READ_LEN)
|
|
|
|
{
|
|
|
|
return -RIG_ETRUNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HD 1780 returns a four octet string consisting of
|
|
|
|
* three octets containing the rotor's position in degrees followed by a
|
|
|
|
* space and a <CR> and a <LF>. The
|
|
|
|
* space is ignored when passing the string to atof().
|
|
|
|
*/
|
|
|
|
az[4] = 0x00; /* NULL terminated string */
|
|
|
|
p = az; /* for hd1780 */
|
|
|
|
tmp = (azimuth_t)atof(p);
|
|
|
|
rig_debug(RIG_DEBUG_TRACE, "%s: \"%s\" after conversion = %.1f\n",
|
|
|
|
__func__, p, tmp);
|
|
|
|
|
|
|
|
if (tmp < 0 || tmp > 359)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*azimuth = tmp;
|
|
|
|
*elevation = 0; /* assume aiming at the horizon */
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_TRACE,
|
|
|
|
"%s: azimuth = %.1f deg; elevation = %.1f deg\n",
|
|
|
|
__func__, *azimuth, *elevation);
|
|
|
|
|
|
|
|
return RIG_OK;
|
2009-01-20 19:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send command string to rotor.
|
|
|
|
*
|
|
|
|
* To make sure that the rotor is ready to take a command, we send it a <CR> and
|
|
|
|
* it will normally reply with a ? <CR> <LF>. If you don't do this, using the
|
|
|
|
* w: command of rotctl it is possible to get it out of sequence. This kind of
|
|
|
|
* resets its command buffer before sending the command.
|
|
|
|
*/
|
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
static int hd1780_send_priv_cmd(ROT *rot, const char *cmdstr)
|
|
|
|
{
|
|
|
|
struct rot_state *rs;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (!rot)
|
|
|
|
{
|
|
|
|
return -RIG_EINVAL;
|
|
|
|
}
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rs = &rot->state;
|
2011-08-21 00:34:57 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
err = write_block(&rs->rotport, cmdstr, strlen(cmdstr));
|
2011-08-21 00:34:57 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
if (err != RIG_OK)
|
|
|
|
{
|
|
|
|
return err;
|
|
|
|
}
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2009-01-20 19:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize backend
|
|
|
|
*/
|
|
|
|
|
|
|
|
DECLARE_INITROT_BACKEND(heathkit)
|
|
|
|
{
|
2019-11-30 16:19:08 +00:00
|
|
|
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
|
2009-01-20 19:44:04 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
rot_register(&hd1780_rot_caps);
|
2011-08-21 00:34:57 +00:00
|
|
|
|
2019-11-30 16:19:08 +00:00
|
|
|
return RIG_OK;
|
2009-01-20 19:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|