Tested with LX200 & Autostar

Move command during active rotation ignored
Added --conf=south_zero=1 option for LX200 south orientation
LX200 now moves smoothly through 180 degrees
Parses both low and high precision answers
pull/145/head
Michael Black 2019-11-23 23:04:54 -06:00
rodzic 243fe294f4
commit 49fde34f2f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6599353EC683404D
1 zmienionych plików z 226 dodań i 225 usunięć

Wyświetl plik

@ -39,14 +39,15 @@
#include "meade.h" #include "meade.h"
struct meade_priv_data
{ struct meade_priv_data {
azimuth_t az; azimuth_t az;
elevation_t el; elevation_t el;
struct timeval tv; /* time last az/el update */ struct timeval tv; /* time last az/el update */
azimuth_t target_az; azimuth_t target_az;
elevation_t target_el; elevation_t target_el;
char product_name[32];
}; };
/** /**
@ -97,7 +98,7 @@ struct meade_priv_data
* RIG_EIO - if an I/O error occurred while sending/receiving data. * RIG_EIO - if an I/O error occurred while sending/receiving data.
* RIG_ETIMEOUT - if timeout expires without any characters received. * RIG_ETIMEOUT - if timeout expires without any characters received.
*/ */
static int meade_transaction(ROT *rot, const char *cmdstr, static int meade_transaction (ROT *rot, const char *cmdstr,
char *data, size_t *data_len, size_t expected_return_length) char *data, size_t *data_len, size_t expected_return_length)
{ {
struct rot_state *rs; struct rot_state *rs;
@ -106,42 +107,38 @@ static int meade_transaction(ROT *rot, const char *cmdstr,
rs = &rot->state; rs = &rot->state;
while (1) while(1) {
{ transaction:
serial_flush(&rs->rotport); serial_flush(&rs->rotport);
if (cmdstr) if (cmdstr) {
{
return_value = write_block(&rs->rotport, cmdstr, strlen(cmdstr)); return_value = write_block(&rs->rotport, cmdstr, strlen(cmdstr));
if (return_value != RIG_OK) {
if (return_value != RIG_OK) *data_len = 0;
{
return return_value; return return_value;
} }
} }
/* Not all commands will send a return value, so use data = NULL if no /* Not all commands will send a return value, so use data = NULL if no
return value is expected, Strings end with '#' */ return value is expected, Strings end with '#' */
if (data != NULL) if (data != NULL) {
{ return_value = read_string(&rs->rotport, data, expected_return_length + 1, "\r\n", strlen("\r\n"));
memset(data, 0, BUFSIZE); if (return_value > 0) {
*data_len = read_string(&rs->rotport, data, expected_return_length + 1, "\n", *data_len = return_value;
strlen("\n"));
if (*data_len < 0)
{
if (retry_read++ >= rot->state.rotport.retry)
{
return RIG_ETIMEOUT;
}
}
else
{
return RIG_OK; return RIG_OK;
} }
else {
if (retry_read++ >= rot->state.rotport.retry) {
rig_debug(RIG_DEBUG_ERR,"%s: read_string error %s\n",__func__, rigerror(return_value));
*data_len = 0;
return -RIG_ETIMEOUT;
} }
else else {
{ goto transaction;
}
}
}
else {
return RIG_OK; return RIG_OK;
} }
} }
@ -154,17 +151,14 @@ static int meade_init(ROT *rot)
{ {
struct meade_priv_data *priv; struct meade_priv_data *priv;
priv = (struct meade_priv_data *) priv = (struct meade_priv_data*)
malloc(sizeof(struct meade_priv_data)); calloc(1,sizeof(struct meade_priv_data));
if (!priv) if (!priv)
{
return -RIG_ENOMEM; return -RIG_ENOMEM;
} rot->state.priv = (void*)priv;
rot->state.priv = (void *)priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called version %s\n", __func__, rot->caps->version);
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
rot->state.rotport.type.rig = RIG_PORT_SERIAL; rot->state.rotport.type.rig = RIG_PORT_SERIAL;
priv->az = priv->el = 0; priv->az = priv->el = 0;
@ -182,9 +176,7 @@ static int meade_cleanup(ROT *rot)
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
if (rot->state.priv) if (rot->state.priv)
{
free(rot->state.priv); free(rot->state.priv);
}
rot->state.priv = NULL; rot->state.priv = NULL;
@ -196,11 +188,26 @@ static int meade_cleanup(ROT *rot)
*/ */
static int meade_open(ROT *rot) static int meade_open(ROT *rot)
{ {
char return_str[BUFSIZE];
size_t return_str_size = 0;
struct meade_priv_data *priv = (struct meade_priv_data *)rot->state.priv;
int retval;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
// Get our product name for any custom things we need to do
// The LX200 does not have :GVP# so no response will default to LX200
retval = meade_transaction(rot, ":GVP#", return_str, &return_str_size, sizeof(return_str));
if (retval != RIG_OK) rig_debug(RIG_DEBUG_ERR,"%s: meade_transaction %s\n",__func__,rigerror(retval));
if (return_str_size > 0) strtok(return_str,"#");
strcpy(priv->product_name, return_str_size > 0? return_str : "LX200 Assumed");
rig_debug(RIG_DEBUG_VERBOSE, "%s product_name=%s\n", __func__, priv->product_name);
/* Set Telescope to Land alignment mode to deactivate sloping */ /* Set Telescope to Land alignment mode to deactivate sloping */
/* Allow 0-90 Degree Elevation */ /* Allow 0-90 Degree Elevation */
return meade_transaction(rot, ":AL#:So00#:Sh90#", NULL, 0, 0); retval = meade_transaction(rot, ":AL#:So00#:Sh90#" , NULL, 0, 0);
if (retval != RIG_OK) rig_debug(RIG_DEBUG_ERR,"%s: meade_transaction %s\n",__func__,rigerror(retval));
return RIG_OK;
} }
/* /*
@ -210,7 +217,7 @@ static int meade_close(ROT *rot)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* Stop all Movement */ /* Stop all Movement */
return meade_transaction(rot, ":Q#", NULL, 0, 0); return meade_transaction(rot, ":Q#" , NULL, 0, 0);
} }
/* /*
@ -227,29 +234,29 @@ static int meade_set_position(ROT *rot, azimuth_t az, elevation_t el)
size_t return_str_size; size_t return_str_size;
float az_degrees, az_minutes, el_degrees, el_minutes; float az_degrees, az_minutes, el_degrees, el_minutes;
rig_debug(RIG_DEBUG_VERBOSE, "%s called: %.2f %.2f\n", __func__, rig_debug(RIG_DEBUG_VERBOSE,"%s called: %.2f %.2f\n", __func__,
az, el); az, el);
az_degrees = floor(az); az_degrees = floor(az);
az_minutes = (az - az_degrees) * 60; az_minutes = (az - az_degrees) * 60;
el_degrees = floor(el); el_degrees = floor(el);
el_minutes = (el - el_degrees) * 60; el_minutes = (el - el_degrees) * 60;
// LX200 won't do 180 degrees exactly...so we fudge everybody
/* Check if there is an active movement, if yes, stop it if if (strstr(priv->product_name,"LX200") && az_degrees == 180 && az_minutes == 0) {
new target is more than 5 Degrees away from old target az_degrees = 179;
if not, don't accept new target*/ az_minutes = 59;
meade_transaction(rot, ":D#", return_str, &return_str_size, 1);
if (return_str_size > 0 && return_str[0] == 0x7F)
{
if (fabsf(az - priv->target_az) > 5 || fabsf(el - priv->target_el) > 5)
{
meade_transaction(rot, ":Q#", NULL, 0, 0);
}
else
{
return RIG_OK;
} }
/* Check if there is an active movement and stop it */
/* Undesirable behavior if stopped can happen */
/* So we just ignore commands while moving */
/* Should we return RIG_OK or an error though? */
meade_transaction(rot, ":D#", return_str, &return_str_size, sizeof(return_str));
rig_debug(RIG_DEBUG_VERBOSE,"%s: size=%d, str[0]=0x%02x\n",__func__, return_str_size, return_str[0]);
// LX200 return 0xff bytes and Autostart returns 0x7f
if(return_str_size > 0 && ((return_str[0] & 0x7f) == 0x7f)) {
rig_debug(RIG_DEBUG_WARN,"%s: rotor is moving...ignoring move\n",__func__);
return RIG_OK; // we don't give an error -- just ignore it
} }
priv->target_az = az; priv->target_az = az;
@ -259,14 +266,12 @@ static int meade_set_position(ROT *rot, azimuth_t az, elevation_t el)
az_degrees, az_minutes, el_degrees, el_minutes); az_degrees, az_minutes, el_degrees, el_minutes);
meade_transaction(rot, cmd_str, return_str, &return_str_size, 3); meade_transaction(rot, cmd_str, return_str, &return_str_size, 3);
/* '1' == Azimuth accepted '1' == Elevation accepted '0' == No error */ /* '1' == Azimuth accepted '1' == Elevation accepted '0' == No error */
if (return_str_size > 0 && strstr(return_str, "110") != NULL) if(return_str_size > 0 && strstr(return_str , "110") != NULL) {
{
return RIG_OK; return RIG_OK;
} }
else else {
{ rig_debug(RIG_DEBUG_VERBOSE,"%s: expected 110, got %s\n", __func__,return_str);
return RIG_EINVAL; return RIG_EINVAL;
} }
} }
@ -277,37 +282,29 @@ static int meade_set_position(ROT *rot, azimuth_t az, elevation_t el)
static int meade_get_position(ROT *rot, azimuth_t *az, elevation_t *el) static int meade_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
{ {
char return_str[BUFSIZE]; char return_str[BUFSIZE];
char eom;
size_t return_str_size; size_t return_str_size;
int az_degree, az_minutes, el_degree, el_minutes; int az_degrees, az_minutes, az_seconds, el_degrees, el_minutes, el_seconds;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
meade_transaction(rot, ":GZ#:GA#", return_str, &return_str_size, BUFSIZE); meade_transaction(rot, ":GZ#:GA#", return_str, &return_str_size, BUFSIZE);
// answer expecting one of two formats depending on precision setting rig_debug(RIG_DEBUG_VERBOSE, "%s: returned '%s'\n", __func__, return_str);
// The Meade manual is not clear on this format // GZ returns DDD*MM# or DDD*MM'SS#
// The period separator is coming back as 0xdf so we won't assume which char it is // GA returns sDD*MM# or sDD*MM'SS#
// DDD.MM:SS#sDD.MM:SS# int n = sscanf(return_str,"%d%*c%d:%d#%d%*c%d:%d%c",&az_degrees,&az_minutes,&az_seconds,&el_degrees,&el_minutes,&el_seconds,&eom);
// DDD.MM#sDD.MM# if (n != 7 || eom!='#') {
// Tested and working with the Meade LX200 and Autostar 497 rig_debug(RIG_DEBUG_VERBOSE, "%s: not 6 args in '%s'\nTrying low precision\n", __func__, return_str);
rig_debug(RIG_DEBUG_VERBOSE, "%s: parsing \"%s\" as high precision\n", __func__, az_seconds = el_seconds = 0;
return_str); n = sscanf(return_str,"%d%*c%d#%d%*c%d%c",&az_degrees,&az_minutes,&el_degrees,&el_minutes,&eom);
int n = sscanf(return_str, "%d%*c%d:%*d#%d%*c%d:%*d#", &az_degree, &az_minutes, if (n != 5 || eom!='#') {
&el_degree, &el_minutes); rig_debug(RIG_DEBUG_ERR, "%s: not 4 args in '%s', parsing failed\n", __func__, return_str);
return -RIG_EPROTO;
if (n != 4)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: parsing as low precision\n", __func__);
n = sscanf(return_str, "%d%*c%d#%d%*c%d", &az_degree, &az_minutes, &el_degree,
&el_minutes);
if (n != 4)
{
return RIG_EPROTO;
} }
} }
rig_debug(RIG_DEBUG_VERBOSE,"%s: az=%03d:%02d:%02d, el=%03d:%02d:%02d\n",__func__,az_degrees, az_minutes, az_seconds, el_degrees, el_minutes, el_seconds);
*az = dmmm2dec(az_degree, az_minutes, 0); *az = dmmm2dec(az_degrees, az_minutes, az_seconds);
*el = dmmm2dec(el_degree, el_minutes, 0); *el = dmmm2dec(el_degrees, el_minutes, el_seconds);
return RIG_OK; return RIG_OK;
} }
@ -363,11 +360,9 @@ static int meade_move(ROT *rot, int direction, int speed)
struct meade_priv_data *priv = (struct meade_priv_data *)rot->state.priv; struct meade_priv_data *priv = (struct meade_priv_data *)rot->state.priv;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
rig_debug(RIG_DEBUG_TRACE, "%s: Direction = %d, Speed = %d\n", __func__, rig_debug(RIG_DEBUG_TRACE, "%s: Direction = %d, Speed = %d\n", __func__, direction, speed);
direction, speed);
switch (direction) switch(direction) {
{
case ROT_MOVE_UP: case ROT_MOVE_UP:
return meade_set_position(rot, priv->target_az, 90); return meade_set_position(rot, priv->target_az, 90);
@ -389,23 +384,25 @@ static int meade_move(ROT *rot, int direction, int speed)
static const char *meade_get_info(ROT *rot) static const char *meade_get_info(ROT *rot)
{ {
struct meade_priv_data *priv = (struct meade_priv_data *)rot->state.priv;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
return "Meade telescope rotator with LX200 protocol."; static char buf[256]; // this is not thread-safe but not important either
sprintf(buf,"Meade telescope rotator with LX200 protocol.\nModel: %s", priv->product_name);
return buf;
} }
/* /*
* Meade telescope rotator capabilities. * Meade telescope rotator capabilities.
*/ */
const struct rot_caps meade_caps = const struct rot_caps meade_caps = {
{
.rot_model = ROT_MODEL_MEADE, .rot_model = ROT_MODEL_MEADE,
.model_name = "LX200", .model_name = "LX200/Autostar",
.mfg_name = "Meade", .mfg_name = "Meade",
.version = "0.2", .version = "0.2",
.copyright = "LGPL", .copyright = "LGPL",
.status = RIG_STATUS_ALPHA, .status = RIG_STATUS_STABLE,
.rot_type = ROT_TYPE_AZEL, .rot_type = ROT_TYPE_AZEL,
.port_type = RIG_PORT_SERIAL, .port_type = RIG_PORT_SERIAL,
@ -418,13 +415,14 @@ const struct rot_caps meade_caps =
.write_delay = 0, .write_delay = 0,
.post_write_delay = 200, .post_write_delay = 200,
.timeout = 400, .timeout = 400,
.retry = 5, .retry = 2,
.min_az = 0., .min_az = 0.,
.max_az = 360., .max_az = 360.,
.min_el = 0., .min_el = 0.,
.max_el = 90., .max_el = 90.,
.priv = NULL, /* priv */ .priv = NULL, /* priv */
.rot_init = meade_init, .rot_init = meade_init,
@ -440,6 +438,9 @@ const struct rot_caps meade_caps =
.move = meade_move, .move = meade_move,
.get_info = meade_get_info, .get_info = meade_get_info,
.get_conf = rot_get_conf,
.set_conf = rot_set_conf,
}; };
DECLARE_INITROT_BACKEND(meade) DECLARE_INITROT_BACKEND(meade)