astyle gs232a and minor debug format change

pull/142/head
Michael Black 2019-11-18 23:07:34 -06:00
rodzic a79e1c9d7d
commit ac2f19a0dd
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6599353EC683404D
2 zmienionych plików z 353 dodań i 298 usunięć

Wyświetl plik

@ -58,7 +58,7 @@
* recognized by rig. * recognized by rig.
*/ */
static int static int
gs232a_transaction (ROT *rot, const char *cmdstr, gs232a_transaction(ROT *rot, const char *cmdstr,
char *data, size_t data_len, int no_reply) char *data, size_t data_len, int no_reply)
{ {
struct rot_state *rs; struct rot_state *rs;
@ -72,40 +72,65 @@ 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) }
data_len = BUFSZ;
if (!no_reply) { if (!data_len)
memset(data,0,data_len); {
retval = read_string(&rs->rotport, data, data_len, REPLY_EOM, strlen(REPLY_EOM)); data_len = BUFSZ;
if (retval < 0) { }
if (!no_reply)
{
memset(data, 0, data_len);
retval = read_string(&rs->rotport, data, data_len, REPLY_EOM,
strlen(REPLY_EOM));
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;
} }
} }
#if 0 #if 0
/* Check that command termination is correct */ /* Check that command termination is correct */
if (strchr(REPLY_EOM, data[strlen(data)-1])==NULL) { if (strchr(REPLY_EOM, data[strlen(data) - 1]) == NULL)
rig_debug(RIG_DEBUG_ERR, "%s: Command is not correctly terminated '%s'\n", __FUNCTION__, data); {
rig_debug(RIG_DEBUG_ERR, "%s: Command is not correctly terminated '%s'\n",
__FUNCTION__, data);
if (retry_read++ < rig->state.rotport.retry) if (retry_read++ < rig->state.rotport.retry)
{
goto transaction_write; goto transaction_write;
}
retval = -RIG_EPROTO; retval = -RIG_EPROTO;
goto transaction_quit; goto transaction_quit;
} }
#endif #endif
if (data[0] == '?') { if (data[0] == '?')
{
/* Invalid command */ /* Invalid command */
rig_debug(RIG_DEBUG_VERBOSE, "%s: Error for '%s': '%s'\n", rig_debug(RIG_DEBUG_VERBOSE, "%s: Error for '%s': '%s'\n",
__FUNCTION__, cmdstr, data); __FUNCTION__, cmdstr, data);
@ -126,17 +151,22 @@ gs232a_rot_set_position(ROT *rot, azimuth_t az, elevation_t el)
int retval; int retval;
unsigned u_az, u_el; unsigned u_az, u_el;
rig_debug(RIG_DEBUG_TRACE, "%s called: %f %f\n", __FUNCTION__, az, el); rig_debug(RIG_DEBUG_TRACE, "%s called: az=%.02f el=%.02f\n", __FUNCTION__, az,
if (az < 0.0) { el);
if (az < 0.0)
{
az = az + 360.0; az = az + 360.0;
} }
u_az = (unsigned)rint(az); u_az = (unsigned)rint(az);
u_el = (unsigned)rint(el); u_el = (unsigned)rint(el);
sprintf(cmdstr, "W%03u %03u" EOM, u_az, u_el); sprintf(cmdstr, "W%03u %03u" EOM, u_az, u_el);
retval = gs232a_transaction(rot, cmdstr, NULL, 0, 0); retval = gs232a_transaction(rot, cmdstr, NULL, 0, 0);
if (retval != RIG_OK) { if (retval != RIG_OK)
{
return retval; return retval;
} }
@ -152,21 +182,27 @@ gs232a_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
rig_debug(RIG_DEBUG_TRACE, "%s called\n", __FUNCTION__); rig_debug(RIG_DEBUG_TRACE, "%s called\n", __FUNCTION__);
retval = gs232a_transaction(rot, "C2" EOM, posbuf, sizeof(posbuf), 0); retval = gs232a_transaction(rot, "C2" EOM, posbuf, sizeof(posbuf), 0);
if (retval != RIG_OK || strlen(posbuf) < 10) {
if (retval != RIG_OK || strlen(posbuf) < 10)
{
return retval < 0 ? retval : -RIG_EPROTO; return retval < 0 ? retval : -RIG_EPROTO;
} }
/* parse "+0aaa+0eee" */ /* parse "+0aaa+0eee" */
if (sscanf(posbuf+2, "%d", &angle) != 1) { if (sscanf(posbuf + 2, "%d", &angle) != 1)
{
rig_debug(RIG_DEBUG_ERR, "%s: wrong reply '%s'\n", __FUNCTION__, posbuf); rig_debug(RIG_DEBUG_ERR, "%s: wrong reply '%s'\n", __FUNCTION__, posbuf);
return -RIG_EPROTO; return -RIG_EPROTO;
} }
*az = (azimuth_t)angle; *az = (azimuth_t)angle;
if (sscanf(posbuf+7, "%d", &angle) != 1) { if (sscanf(posbuf + 7, "%d", &angle) != 1)
{
rig_debug(RIG_DEBUG_ERR, "%s: wrong reply '%s'\n", __FUNCTION__, posbuf); rig_debug(RIG_DEBUG_ERR, "%s: wrong reply '%s'\n", __FUNCTION__, posbuf);
return -RIG_EPROTO; return -RIG_EPROTO;
} }
*el = (elevation_t)angle; *el = (elevation_t)angle;
rig_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.1f, %.1f)\n", rig_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.1f, %.1f)\n",
@ -184,8 +220,11 @@ gs232a_rot_stop(ROT *rot)
/* All Stop */ /* All Stop */
retval = gs232a_transaction(rot, "S" EOM, NULL, 0, 0); retval = gs232a_transaction(rot, "S" EOM, NULL, 0, 0);
if (retval != RIG_OK) if (retval != RIG_OK)
{
return retval; return retval;
}
return RIG_OK; return RIG_OK;
} }
@ -201,36 +240,47 @@ gs232a_rot_move(ROT *rot, int direction, int speed)
rig_debug(RIG_DEBUG_TRACE, "%s called %d %d\n", __FUNCTION__, rig_debug(RIG_DEBUG_TRACE, "%s called %d %d\n", __FUNCTION__,
direction, speed); direction, speed);
x_speed = (3*speed)/100 + 1; x_speed = (3 * speed) / 100 + 1;
/* between 1 (slowest) and 4 (fastest) */ /* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, x_speed); sprintf(cmdstr, "X%u" EOM, x_speed);
retval = gs232a_transaction(rot, cmdstr, NULL, 0, 1); retval = gs232a_transaction(rot, cmdstr, NULL, 0, 1);
if (retval != RIG_OK)
return retval;
switch (direction) { if (retval != RIG_OK)
{
return retval;
}
switch (direction)
{
case ROT_MOVE_UP: /* Elevation increase */ case ROT_MOVE_UP: /* Elevation increase */
sprintf(cmdstr, "U" EOM); sprintf(cmdstr, "U" EOM);
break; break;
case ROT_MOVE_DOWN: /* Elevation decrease */ case ROT_MOVE_DOWN: /* Elevation decrease */
sprintf(cmdstr, "D" EOM); sprintf(cmdstr, "D" EOM);
break; break;
case ROT_MOVE_LEFT: /* Azimuth decrease */ case ROT_MOVE_LEFT: /* Azimuth decrease */
sprintf(cmdstr, "L" EOM); sprintf(cmdstr, "L" EOM);
break; break;
case ROT_MOVE_RIGHT: /* Azimuth increase */ case ROT_MOVE_RIGHT: /* Azimuth increase */
sprintf(cmdstr, "R" EOM); sprintf(cmdstr, "R" EOM);
break; break;
default: default:
rig_debug(RIG_DEBUG_ERR,"%s: Invalid direction value! (%d)\n", rig_debug(RIG_DEBUG_ERR, "%s: Invalid direction value! (%d)\n",
__FUNCTION__, direction); __FUNCTION__, direction);
return -RIG_EINVAL; return -RIG_EINVAL;
} }
retval = gs232a_transaction(rot, cmdstr, NULL, 0, 1); retval = gs232a_transaction(rot, cmdstr, NULL, 0, 1);
if (retval != RIG_OK) if (retval != RIG_OK)
{
return retval; return retval;
}
return RIG_OK; return RIG_OK;
} }
@ -240,7 +290,8 @@ gs232a_rot_move(ROT *rot, int direction, int speed)
* Generic GS23 rotator capabilities. * Generic GS23 rotator capabilities.
*/ */
const struct rot_caps gs23_rot_caps = { const struct rot_caps gs23_rot_caps =
{
.rot_model = ROT_MODEL_GS23, .rot_model = ROT_MODEL_GS23,
.model_name = "GS-23", .model_name = "GS-23",
.mfg_name = "Yaesu/Kenpro", .mfg_name = "Yaesu/Kenpro",
@ -275,7 +326,8 @@ const struct rot_caps gs23_rot_caps = {
* Generic GS232 rotator capabilities. * Generic GS232 rotator capabilities.
*/ */
const struct rot_caps gs232_rot_caps = { const struct rot_caps gs232_rot_caps =
{
.rot_model = ROT_MODEL_GS232, .rot_model = ROT_MODEL_GS232,
.model_name = "GS-232", .model_name = "GS-232",
.mfg_name = "Yaesu/Kenpro", .mfg_name = "Yaesu/Kenpro",
@ -310,7 +362,8 @@ const struct rot_caps gs232_rot_caps = {
* Generic GS232A rotator capabilities. * Generic GS232A rotator capabilities.
*/ */
const struct rot_caps gs232a_rot_caps = { const struct rot_caps gs232a_rot_caps =
{
.rot_model = ROT_MODEL_GS232A, .rot_model = ROT_MODEL_GS232A,
.model_name = "GS-232A", .model_name = "GS-232A",
.mfg_name = "Yaesu", .mfg_name = "Yaesu",

Wyświetl plik

@ -88,7 +88,7 @@ transaction_write:
} }
} }
if (no_reply) return RIG_OK; // nothing expected so return if (no_reply) { return RIG_OK; } // nothing expected so return
/* 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)
@ -103,7 +103,8 @@ transaction_write:
memset(data, 0, data_len); memset(data, 0, data_len);
retval = read_string(&rs->rotport, data, data_len, REPLY_EOM, strlen(REPLY_EOM)); retval = read_string(&rs->rotport, data, data_len, REPLY_EOM,
strlen(REPLY_EOM));
if (retval < 0) if (retval < 0)
{ {
@ -169,7 +170,8 @@ gs232b_rot_set_position(ROT *rot, azimuth_t az, elevation_t el)
int retval; int retval;
unsigned u_az, u_el; unsigned u_az, u_el;
rig_debug(RIG_DEBUG_TRACE, "%s called: az=.0f el=%.0f\n", __FUNCTION__, az, el); rig_debug(RIG_DEBUG_TRACE, "%s called: az=%.02f el=%.02f\n", __FUNCTION__, az,
el);
if (az < 0.0) if (az < 0.0)
{ {