astyle meade and prosistel

pull/139/head
Michael Black 2019-11-07 07:52:56 -06:00
rodzic 3bccc571e7
commit b8da8cd4a8
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6599353EC683404D
2 zmienionych plików z 374 dodań i 298 usunięć

Wyświetl plik

@ -39,13 +39,14 @@
#include "meade.h" #include "meade.h"
struct meade_priv_data { struct meade_priv_data
azimuth_t az; {
elevation_t el; azimuth_t az;
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;
}; };
/** /**
@ -96,43 +97,54 @@ 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;
int return_value; int return_value;
int retry_read = 0; int retry_read = 0;
rs = &rot->state; rs = &rot->state;
while(1) { while (1)
serial_flush(&rs->rotport); {
serial_flush(&rs->rotport);
if (cmdstr) { if (cmdstr)
return_value = write_block(&rs->rotport, cmdstr, strlen(cmdstr)); {
if (return_value != RIG_OK) { return_value = write_block(&rs->rotport, cmdstr, strlen(cmdstr));
return return_value;
}
}
/* Not all commands will send a return value, so use data = NULL if no if (return_value != RIG_OK)
return value is expected, Strings end with '#' */ {
if (data != NULL) { return return_value;
memset(data,0,BUFSIZE); }
*data_len = read_string(&rs->rotport, data, expected_return_length + 1, "\n", strlen("\n")); }
if (*data_len < 0) {
if (retry_read++ >= rot->state.rotport.retry) { /* Not all commands will send a return value, so use data = NULL if no
return RIG_ETIMEOUT; return value is expected, Strings end with '#' */
if (data != NULL)
{
memset(data, 0, BUFSIZE);
*data_len = read_string(&rs->rotport, data, expected_return_length + 1, "\n",
strlen("\n"));
if (*data_len < 0)
{
if (retry_read++ >= rot->state.rotport.retry)
{
return RIG_ETIMEOUT;
}
}
else
{
return RIG_OK;
}
}
else
{
return RIG_OK;
} }
}
else {
return RIG_OK;
}
} }
else {
return RIG_OK;
}
}
} }
/* /*
@ -140,23 +152,26 @@ static int meade_transaction (ROT *rot, const char *cmdstr,
*/ */
static int meade_init(ROT *rot) 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)); malloc(sizeof(struct meade_priv_data));
if (!priv) if (!priv)
return -RIG_ENOMEM; {
rot->state.priv = (void*)priv; return -RIG_ENOMEM;
}
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rot->state.priv = (void *)priv;
rot->state.rotport.type.rig = RIG_PORT_SERIAL;
priv->az = priv->el = 0; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
rot->state.rotport.type.rig = RIG_PORT_SERIAL;
priv->target_az = priv->target_el = 0; priv->az = priv->el = 0;
return RIG_OK; priv->target_az = priv->target_el = 0;
return RIG_OK;
} }
/* /*
@ -164,14 +179,16 @@ static int meade_init(ROT *rot)
*/ */
static int meade_cleanup(ROT *rot) 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;
return RIG_OK; return RIG_OK;
} }
/* /*
@ -179,11 +196,11 @@ static int meade_cleanup(ROT *rot)
*/ */
static int meade_open(ROT *rot) static int meade_open(ROT *rot)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* 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); return meade_transaction(rot, ":AL#:So00#:Sh90#", NULL, 0, 0);
} }
/* /*
@ -191,9 +208,9 @@ static int meade_open(ROT *rot)
*/ */
static int meade_close(ROT *rot) 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);
} }
/* /*
@ -204,43 +221,54 @@ static int meade_close(ROT *rot)
*/ */
static int meade_set_position(ROT *rot, azimuth_t az, elevation_t el) static int meade_set_position(ROT *rot, azimuth_t az, elevation_t el)
{ {
struct meade_priv_data *priv = (struct meade_priv_data *)rot->state.priv; struct meade_priv_data *priv = (struct meade_priv_data *)rot->state.priv;
char cmd_str[BUFSIZE]; char cmd_str[BUFSIZE];
char return_str[BUFSIZE]; char return_str[BUFSIZE];
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;
/* Check if there is an active movement, if yes, stop it if /* Check if there is an active movement, if yes, stop it if
new target is more than 5 Degrees away from old target new target is more than 5 Degrees away from old target
if not, don't accept new target*/ if not, don't accept new target*/
meade_transaction(rot, ":D#", return_str, &return_str_size, 1); 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) if (return_str_size > 0 && return_str[0] == 0x7F)
meade_transaction(rot, ":Q#", NULL, 0, 0); {
if (fabsf(az - priv->target_az) > 5 || fabsf(el - priv->target_el) > 5)
{
meade_transaction(rot, ":Q#", NULL, 0, 0);
}
else
{
return RIG_OK;
}
}
priv->target_az = az;
priv->target_el = el;
num_sprintf(cmd_str, ":Sz %03.0f*%02.0f#:Sa+%02.0f*%02.0f#:MA#",
az_degrees, az_minutes, el_degrees, el_minutes);
meade_transaction(rot, cmd_str, return_str, &return_str_size, 3);
/* '1' == Azimuth accepted '1' == Elevation accepted '0' == No error */
if (return_str_size > 0 && strstr(return_str, "110") != NULL)
{
return RIG_OK;
}
else else
return RIG_OK; {
} return RIG_EINVAL;
}
priv->target_az = az;
priv->target_el = el;
num_sprintf(cmd_str, ":Sz %03.0f*%02.0f#:Sa+%02.0f*%02.0f#:MA#",
az_degrees, az_minutes, el_degrees, el_minutes);
meade_transaction(rot, cmd_str, return_str, &return_str_size, 3);
/* '1' == Azimuth accepted '1' == Elevation accepted '0' == No error */
if(return_str_size > 0 && strstr(return_str , "110") != NULL)
return RIG_OK;
else
return RIG_EINVAL;
} }
/* /*
@ -248,31 +276,39 @@ 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];
size_t return_str_size; size_t return_str_size;
int az_degree, az_minutes, el_degree, el_minutes; int az_degree, az_minutes, el_degree, el_minutes;
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 // answer expecting one of two formats depending on precision setting
// The Meade manual is not clear on this format // The Meade manual is not clear on this format
// The period separator is coming back as 0xdf so we won't assume which char it is // The period separator is coming back as 0xdf so we won't assume which char it is
// DDD.MM:SS#sDD.MM:SS# // DDD.MM:SS#sDD.MM:SS#
// DDD.MM#sDD.MM# // DDD.MM#sDD.MM#
// Tested and working with the Meade LX200 and Autostar 497 // Tested and working with the Meade LX200 and Autostar 497
rig_debug(RIG_DEBUG_VERBOSE, "%s: parsing \"%s\" as high precision\n", __func__, return_str); rig_debug(RIG_DEBUG_VERBOSE, "%s: parsing \"%s\" as high precision\n", __func__,
int n = sscanf(return_str,"%d%*c%d:%*d#%d%*c%d:%*d#",&az_degree,&az_minutes,&el_degree,&el_minutes); return_str);
if (n != 4) { int n = sscanf(return_str, "%d%*c%d:%*d#%d%*c%d:%*d#", &az_degree, &az_minutes,
rig_debug(RIG_DEBUG_VERBOSE, "%s: parsing as low precision\n", __func__); &el_degree, &el_minutes);
n = sscanf(return_str,"%d%*c%d#%d%*c%d",&az_degree,&az_minutes,&el_degree,&el_minutes);
if (n != 4) { if (n != 4)
return RIG_EPROTO; {
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;
}
} }
}
*az = dmmm2dec(az_degree, az_minutes, 0); *az = dmmm2dec(az_degree, az_minutes, 0);
*el = dmmm2dec(el_degree, el_minutes, 0); *el = dmmm2dec(el_degree, el_minutes, 0);
return RIG_OK; return RIG_OK;
} }
/* /*
@ -280,19 +316,19 @@ static int meade_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
*/ */
static int meade_stop(ROT *rot) static int meade_stop(ROT *rot)
{ {
struct meade_priv_data *priv = (struct meade_priv_data *)rot->state.priv; struct meade_priv_data *priv = (struct meade_priv_data *)rot->state.priv;
azimuth_t az; azimuth_t az;
elevation_t el; elevation_t el;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
meade_transaction(rot, ":Q#", NULL, 0, 0); meade_transaction(rot, ":Q#", NULL, 0, 0);
meade_get_position(rot, &az, &el); meade_get_position(rot, &az, &el);
priv->target_az = priv->az = az; priv->target_az = priv->az = az;
priv->target_el = priv->el = el; priv->target_el = priv->el = el;
return RIG_OK; return RIG_OK;
} }
/* /*
@ -300,12 +336,12 @@ static int meade_stop(ROT *rot)
*/ */
static int meade_park(ROT *rot) static int meade_park(ROT *rot)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
/* Assume home is 0,0 */ /* Assume home is 0,0 */
meade_set_position(rot, 0, 0); meade_set_position(rot, 0, 0);
return RIG_OK; return RIG_OK;
} }
/* /*
@ -313,10 +349,10 @@ static int meade_park(ROT *rot)
*/ */
static int meade_reset(ROT *rot, rot_reset_t reset) static int meade_reset(ROT *rot, rot_reset_t reset)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
meade_park(rot); meade_park(rot);
return RIG_OK; return RIG_OK;
} }
/* /*
@ -324,90 +360,93 @@ static int meade_reset(ROT *rot, rot_reset_t reset)
*/ */
static int meade_move(ROT *rot, int direction, int speed) 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__, direction, speed); rig_debug(RIG_DEBUG_TRACE, "%s: Direction = %d, Speed = %d\n", __func__,
direction, speed);
switch(direction) { switch (direction)
case ROT_MOVE_UP: {
return meade_set_position(rot, priv->target_az, 90); case ROT_MOVE_UP:
return meade_set_position(rot, priv->target_az, 90);
case ROT_MOVE_DOWN: case ROT_MOVE_DOWN:
return meade_set_position(rot, priv->target_az, 0); return meade_set_position(rot, priv->target_az, 0);
case ROT_MOVE_CCW: case ROT_MOVE_CCW:
return meade_set_position(rot, -180, priv->target_el); return meade_set_position(rot, -180, priv->target_el);
case ROT_MOVE_CW: case ROT_MOVE_CW:
return meade_set_position(rot, 180, priv->target_el); return meade_set_position(rot, 180, priv->target_el);
default: default:
return -RIG_EINVAL; return -RIG_EINVAL;
} }
return RIG_OK; return RIG_OK;
} }
static const char *meade_get_info(ROT *rot) static const char *meade_get_info(ROT *rot)
{ {
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."; return "Meade telescope rotator with LX200 protocol.";
} }
/* /*
* 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, {
.model_name = "LX200", .rot_model = ROT_MODEL_MEADE,
.mfg_name = "Meade", .model_name = "LX200",
.version = "0.2", .mfg_name = "Meade",
.copyright = "LGPL", .version = "0.2",
.status = RIG_STATUS_ALPHA, .copyright = "LGPL",
.rot_type = ROT_TYPE_AZEL, .status = RIG_STATUS_ALPHA,
.rot_type = ROT_TYPE_AZEL,
.port_type = RIG_PORT_SERIAL, .port_type = RIG_PORT_SERIAL,
.serial_rate_min = 9600, .serial_rate_min = 9600,
.serial_rate_max = 9600, .serial_rate_max = 9600,
.serial_data_bits = 8, .serial_data_bits = 8,
.serial_stop_bits = 1, .serial_stop_bits = 1,
.serial_parity = RIG_PARITY_NONE, .serial_parity = RIG_PARITY_NONE,
.serial_handshake = RIG_HANDSHAKE_NONE, .serial_handshake = RIG_HANDSHAKE_NONE,
.write_delay = 0, .write_delay = 0,
.post_write_delay = 200, .post_write_delay = 200,
.timeout = 400, .timeout = 400,
.retry = 5, .retry = 5,
.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,
.rot_cleanup = meade_cleanup, .rot_cleanup = meade_cleanup,
.rot_open = meade_open, .rot_open = meade_open,
.rot_close = meade_close, .rot_close = meade_close,
.set_position = meade_set_position, .set_position = meade_set_position,
.get_position = meade_get_position, .get_position = meade_get_position,
.park = meade_park, .park = meade_park,
.stop = meade_stop, .stop = meade_stop,
.reset = meade_reset, .reset = meade_reset,
.move = meade_move, .move = meade_move,
.get_info = meade_get_info, .get_info = meade_get_info,
}; };
DECLARE_INITROT_BACKEND(meade) DECLARE_INITROT_BACKEND(meade)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "meade: _init called\n"); rig_debug(RIG_DEBUG_VERBOSE, "meade: _init called\n");
rot_register(&meade_caps); rot_register(&meade_caps);
return RIG_OK; return RIG_OK;
} }

Wyświetl plik

@ -44,13 +44,14 @@
#define STX "\x02" #define STX "\x02"
struct prosistel_rot_priv_data { struct prosistel_rot_priv_data
azimuth_t az; {
elevation_t el; azimuth_t az;
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;
}; };
@ -69,8 +70,8 @@ struct prosistel_rot_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 prosistel_transaction (ROT *rot, const char *cmdstr, static int prosistel_transaction(ROT *rot, const char *cmdstr,
char *data, size_t data_len) char *data, size_t data_len)
{ {
struct rot_state *rs; struct rot_state *rs;
int retval; int retval;
@ -83,37 +84,58 @@ transaction_write:
serial_flush(&rs->rotport); serial_flush(&rs->rotport);
if (cmdstr) { if (cmdstr)
retval = write_block(&rs->rotport, cmdstr, strlen(cmdstr)); {
retval = write_block(&rs->rotport, cmdstr, strlen(cmdstr));
if (retval != RIG_OK) if (retval != RIG_OK)
{
goto transaction_quit; goto transaction_quit;
}
} }
/* Always read the reply to know whether the cmd went OK */ /* Always read the reply to know whether the cmd went OK */
if (!data) if (!data)
{
data = replybuf; data = replybuf;
}
if (!data_len) if (!data_len)
{
data_len = BUFSZ; data_len = BUFSZ;
}
memset(data,0,data_len); memset(data, 0, data_len);
//remember check for STXA,G,R or STXA,?,XXX,R 10 bytes //remember check for STXA,G,R or STXA,?,XXX,R 10 bytes
retval = read_string(&rs->rotport, data, 20, CR, strlen(CR)); retval = read_string(&rs->rotport, data, 20, CR, strlen(CR));
if (retval < 0) {
if (retval < 0)
{
if (retry_read++ < rot->state.rotport.retry) if (retry_read++ < rot->state.rotport.retry)
{
goto transaction_write; goto transaction_write;
}
goto transaction_quit; goto transaction_quit;
} }
//check if reply match issued command //check if reply match issued command
if(data[0]==0x02 && data[3]==cmdstr[2]) { if (data[0] == 0x02 && data[3] == cmdstr[2])
rig_debug(RIG_DEBUG_VERBOSE, "%s Command %c reply received\n", __func__, data[3]); {
retval = RIG_OK; rig_debug(RIG_DEBUG_VERBOSE, "%s Command %c reply received\n", __func__,
} else { data[3]);
rig_debug(RIG_DEBUG_VERBOSE, "%s Error Command issued: %c doesn't match reply %c\n", __func__, cmdstr[2], data[3]); retval = RIG_OK;
retval = RIG_EIO; }
} else
{
rig_debug(RIG_DEBUG_VERBOSE,
"%s Error Command issued: %c doesn't match reply %c\n", __func__, cmdstr[2],
data[3]);
retval = RIG_EIO;
}
transaction_quit: transaction_quit:
return retval; return retval;
} }
@ -125,44 +147,47 @@ transaction_quit:
static int prosistel_rot_open(ROT *rot) static int prosistel_rot_open(ROT *rot)
{ {
char cmdstr[64]; char cmdstr[64];
int retval; int retval;
rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__);
rot_open(rot); rot_open(rot);
//disable CPM mode - CPM stands for Continuous Position Monitor operating mode //disable CPM mode - CPM stands for Continuous Position Monitor operating mode
//MCU continuously sends position data when CPM enabled //MCU continuously sends position data when CPM enabled
num_sprintf(cmdstr, STX"AS"CR); num_sprintf(cmdstr, STX"AS"CR);
retval = prosistel_transaction(rot, cmdstr, NULL, 0); retval = prosistel_transaction(rot, cmdstr, NULL, 0);
return retval; return retval;
} }
static int prosistel_rot_set_position(ROT *rot, azimuth_t az, elevation_t el) { static int prosistel_rot_set_position(ROT *rot, azimuth_t az, elevation_t el)
{
char cmdstr[64]; char cmdstr[64];
int retval; int retval;
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);
num_sprintf(cmdstr, STX"AG%03.0f"CR, az); num_sprintf(cmdstr, STX"AG%03.0f"CR, az);
retval = prosistel_transaction(rot, cmdstr, NULL, 0); retval = prosistel_transaction(rot, cmdstr, NULL, 0);
if(retval!=RIG_OK) {
return retval;
}
/* if (retval != RIG_OK)
* Elevation section: have no hardware to test {
memset(cmdstr,0,64); return retval;
num_sprintf(cmdstr, STX"EG%03.0f"CR, el); }
retval = prosistel_transaction(rot, cmdstr, NULL, 0);
if(retval!=RIG_OK) {
return retval;
}
*/ /*
return retval; * Elevation section: have no hardware to test
memset(cmdstr,0,64);
num_sprintf(cmdstr, STX"EG%03.0f"CR, el);
retval = prosistel_transaction(rot, cmdstr, NULL, 0);
if(retval!=RIG_OK) {
return retval;
}
*/
return retval;
} }
@ -171,45 +196,56 @@ static int prosistel_rot_set_position(ROT *rot, azimuth_t az, elevation_t el) {
*/ */
static int prosistel_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) static int prosistel_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
{ {
char cmdstr[64]; char cmdstr[64];
char data[20]; char data[20];
float posval; float posval;
int retval; int retval;
num_sprintf(cmdstr, STX"A?"CR); num_sprintf(cmdstr, STX"A?"CR);
retval = prosistel_transaction(rot, cmdstr, data, sizeof(data)); retval = prosistel_transaction(rot, cmdstr, data, sizeof(data));
if(retval!=RIG_OK) {
return retval; if (retval != RIG_OK)
} {
// Example response of 100 azimuth return retval;
// 02 41 2c 3f 2c 31 30 30 30 2c 52 0d .A,?,1000,R. }
int n = sscanf(data,"%*cA,?,%f,%*c.",&posval);
if (n != 1) { // Example response of 100 azimuth
rig_debug(RIG_DEBUG_ERR, "%s failed to parse azimuth '%s'\n", __func__,data); // 02 41 2c 3f 2c 31 30 30 30 2c 52 0d .A,?,1000,R.
return RIG_EPROTO; int n = sscanf(data, "%*cA,?,%f,%*c.", &posval);
}
posval /= 10.0; if (n != 1)
rig_debug(RIG_DEBUG_VERBOSE, "%s got position from '%s' converted to %d\n", __func__,data,posval); {
*az = (azimuth_t) posval; rig_debug(RIG_DEBUG_ERR, "%s failed to parse azimuth '%s'\n", __func__, data);
return RIG_EPROTO;
}
posval /= 10.0;
rig_debug(RIG_DEBUG_VERBOSE, "%s got position from '%s' converted to %d\n",
__func__, data, posval);
*az = (azimuth_t) posval;
/* /*
* Elevation section * Elevation section
*/ */
num_sprintf(cmdstr, STX"B?"CR); num_sprintf(cmdstr, STX"B?"CR);
retval = prosistel_transaction(rot, cmdstr, data, sizeof(data)); retval = prosistel_transaction(rot, cmdstr, data, sizeof(data));
// Example response of 90 elevation // Example response of 90 elevation
// 02 42 2c 3f 2c 30 39 30 30 2c 52 0d .B,?,0900,R. // 02 42 2c 3f 2c 30 39 30 30 2c 52 0d .B,?,0900,R.
n = sscanf(data,"%*cB,?,%f,%*c.",&posval); n = sscanf(data, "%*cB,?,%f,%*c.", &posval);
if (n != 1) {
rig_debug(RIG_DEBUG_ERR, "%s failed to parse elevation '%s'\n", __func__,data);
return RIG_EPROTO;
}
posval /= 10.0;
rig_debug(RIG_DEBUG_VERBOSE, "%s got position from '%s' converted to %d\n", __func__,data,posval);
*el = (elevation_t) posval/10.0;
return retval; if (n != 1)
{
rig_debug(RIG_DEBUG_ERR, "%s failed to parse elevation '%s'\n", __func__, data);
return RIG_EPROTO;
}
posval /= 10.0;
rig_debug(RIG_DEBUG_VERBOSE, "%s got position from '%s' converted to %d\n",
__func__, data, posval);
*el = (elevation_t) posval / 10.0;
return retval;
} }
@ -220,44 +256,45 @@ static int prosistel_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
* Prosistel rotator capabilities. * Prosistel rotator capabilities.
*/ */
const struct rot_caps prosistel_rot_caps = { const struct rot_caps prosistel_rot_caps =
.rot_model = ROT_MODEL_PROSISTEL, {
.model_name = "Prosistel D", .rot_model = ROT_MODEL_PROSISTEL,
.mfg_name = "Prosistel", .model_name = "Prosistel D",
.version = "0.4", .mfg_name = "Prosistel",
.copyright = "LGPL", .version = "0.4",
.status = RIG_STATUS_STABLE, .copyright = "LGPL",
.rot_type = ROT_TYPE_AZIMUTH, .status = RIG_STATUS_STABLE,
.port_type = RIG_PORT_SERIAL, .rot_type = ROT_TYPE_AZIMUTH,
.serial_rate_min = 9600, .port_type = RIG_PORT_SERIAL,
.serial_rate_max = 9600, .serial_rate_min = 9600,
.serial_data_bits = 8, .serial_rate_max = 9600,
.serial_stop_bits = 1, .serial_data_bits = 8,
.serial_parity = RIG_PARITY_NONE, .serial_stop_bits = 1,
.serial_handshake = RIG_HANDSHAKE_NONE, .serial_parity = RIG_PARITY_NONE,
.write_delay = 0, .serial_handshake = RIG_HANDSHAKE_NONE,
.post_write_delay = 0, .write_delay = 0,
.timeout = 3000, .post_write_delay = 0,
.retry = 3, .timeout = 3000,
.retry = 3,
.min_az = 0.0, .min_az = 0.0,
.max_az = 360.0, .max_az = 360.0,
.min_el = 0.0, .min_el = 0.0,
.max_el = 90.0, .max_el = 90.0,
.rot_open = prosistel_rot_open, .rot_open = prosistel_rot_open,
.set_position = prosistel_rot_set_position, .set_position = prosistel_rot_set_position,
.get_position = prosistel_rot_get_position, .get_position = prosistel_rot_get_position,
}; };
DECLARE_INITROT_BACKEND(prosistel) DECLARE_INITROT_BACKEND(prosistel)
{ {
rig_debug(RIG_DEBUG_VERBOSE, "prosistel: _init called\n"); rig_debug(RIG_DEBUG_VERBOSE, "prosistel: _init called\n");
rot_register(&prosistel_rot_caps); rot_register(&prosistel_rot_caps);
return RIG_OK; return RIG_OK;
} }