astyle for gs232b.c and minor changes to debug msgs

pull/133/head
Michael Black 2019-10-07 08:15:26 -05:00
rodzic ed2e552852
commit aa3a701248
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6599353EC683404D
1 zmienionych plików z 210 dodań i 155 usunięć

Wyświetl plik

@ -59,7 +59,7 @@
* recognized by rig.
*/
static int
gs232b_transaction (ROT *rot, const char *cmdstr,
gs232b_transaction(ROT *rot, const char *cmdstr,
char *data, size_t data_len)
{
struct rot_state *rs;
@ -74,52 +74,84 @@ transaction_write:
serial_flush(&rs->rotport);
if (cmdstr) {
if (cmdstr)
{
retval = write_block(&rs->rotport, cmdstr, strlen(cmdstr));
if (retval != RIG_OK)
{
goto transaction_quit;
if (!data) {
write_block(&rs->rotport,EOM,strlen(EOM));
}
if (!data)
{
write_block(&rs->rotport, EOM, strlen(EOM));
noreply = 1; // we will check for connectivity though
}
}
/* Always read the reply to know whether the cmd went OK */
if (!data)
{
data = replybuf;
if (!data_len)
data_len = BUFSZ;
}
memset(data,0,data_len);
retval = read_string(&rs->rotport, data, data_len, REPLY_EOM, strlen(REPLY_EOM));
if (retval < 0) {
if (!data_len)
{
data_len = BUFSZ;
}
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)
{
goto transaction_write;
}
goto transaction_quit;
}
#if 0
/* Check that command termination is correct */
if (strchr(REPLY_EOM, data[strlen(data)-1])==NULL) {
rig_debug(RIG_DEBUG_ERR, "%s: Command is not correctly terminated '%s'\n", __FUNCTION__, data);
if (strchr(REPLY_EOM, data[strlen(data) - 1]) == NULL)
{
rig_debug(RIG_DEBUG_ERR,
"%s: Command is not correctly terminated '%s'\n",
__FUNCTION__, data);
if (retry_read++ < rig->state.rotport.retry)
{
goto transaction_write;
}
retval = -RIG_EPROTO;
goto transaction_quit;
}
#endif
if (noreply) { // we don't expect a reply...just a prompt return
if (strncmp(data,"?>",2) != 0) {
rig_debug(RIG_DEBUG_VERBOSE, "%s: Expected '?>' but got '%s' from cmd '%s'\n",
if (noreply)
{
// we don't expect a reply...just a prompt return
if (strncmp(data, "?>", 2) != 0)
{
rig_debug(RIG_DEBUG_VERBOSE,
"%s: Expected '?>' but got '%s' from cmd '%s'\n",
__FUNCTION__, data, cmdstr);
return -RIG_EPROTO;
}
return RIG_OK;
}
if (data[0] == '?') {
if (data[0] == '?')
{
/* Invalid command */
rig_debug(RIG_DEBUG_VERBOSE, "%s: Error for '%s': '%s'\n",
__FUNCTION__, cmdstr, data);
@ -140,17 +172,21 @@ gs232b_rot_set_position(ROT *rot, azimuth_t az, elevation_t el)
int retval;
unsigned u_az, u_el;
rig_debug(RIG_DEBUG_TRACE, "%s called: %f %f\n", __FUNCTION__, az, el);
if (az < 0.0){
rig_debug(RIG_DEBUG_TRACE, "%s called: az=.0f el=%.0f\n", __FUNCTION__, az, el);
if (az < 0.0)
{
az = az + 360.0;
}
u_az = (unsigned)rint(az);
u_el = (unsigned)rint(el);
u_az = (unsigned) rint(az);
u_el = (unsigned) rint(el);
sprintf(cmdstr, "W%03u %03u" EOM, u_az, u_el);
retval = gs232b_transaction(rot, cmdstr, NULL, 0);
if (retval != RIG_OK) {
if (retval != RIG_OK)
{
return retval;
}
@ -166,7 +202,9 @@ gs232b_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
rig_debug(RIG_DEBUG_TRACE, "%s called\n", __FUNCTION__);
retval = gs232b_transaction(rot, "C2" EOM, posbuf, sizeof(posbuf));
if (retval != RIG_OK || strlen(posbuf) < 10) {
if (retval != RIG_OK || strlen(posbuf) < 10)
{
return retval < 0 ? retval : -RIG_EPROTO;
}
@ -175,14 +213,17 @@ gs232b_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
/* With the format string containing a space character as one of the
* directives, any amount of space is matched, including none in the input.
*/
if (sscanf(posbuf, "AZ=%d EL=%d", &int_az, &int_el) != 2) {
rig_debug(RIG_DEBUG_ERR, "%s: wrong reply '%s'\n", __FUNCTION__, posbuf);
if (sscanf(posbuf, "AZ=%d EL=%d", &int_az, &int_el) != 2)
{
rig_debug(RIG_DEBUG_ERR, "%s: wrong reply '%s'\n", __FUNCTION__,
posbuf);
return -RIG_EPROTO;
}
*az = (azimuth_t)int_az;
*el = (elevation_t)int_el;
rig_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.1f, %.1f)\n",
*az = (azimuth_t) int_az;
*el = (elevation_t) int_el;
rig_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.0f, %.0f)\n",
__FUNCTION__, *az, *el);
return RIG_OK;
@ -197,8 +238,11 @@ gs232b_rot_stop(ROT *rot)
/* All Stop */
retval = gs232b_transaction(rot, "S" EOM, NULL, 0);
if (retval != RIG_OK)
{
return retval;
}
return RIG_OK;
}
@ -214,36 +258,47 @@ gs232b_rot_move(ROT *rot, int direction, int speed)
rig_debug(RIG_DEBUG_TRACE, "%s called %d %d\n", __FUNCTION__,
direction, speed);
x_speed = (3*speed)/100 + 1;
x_speed = (3 * speed) / 100 + 1;
/* between 1 (slowest) and 4 (fastest) */
sprintf(cmdstr, "X%u" EOM, x_speed);
retval = gs232b_transaction(rot, cmdstr, NULL, 0);
if (retval != RIG_OK)
return retval;
switch (direction) {
if (retval != RIG_OK)
{
return retval;
}
switch (direction)
{
case ROT_MOVE_UP: /* Elevation increase */
sprintf(cmdstr, "U" EOM);
break;
case ROT_MOVE_DOWN: /* Elevation decrease */
sprintf(cmdstr, "D" EOM);
break;
case ROT_MOVE_LEFT: /* Azimuth decrease */
sprintf(cmdstr, "L" EOM);
break;
case ROT_MOVE_RIGHT: /* Azimuth increase */
sprintf(cmdstr, "R" EOM);
break;
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);
return -RIG_EINVAL;
}
retval = gs232b_transaction(rot, cmdstr, NULL, 0);
if (retval != RIG_OK)
{
return retval;
}
return RIG_OK;
}
@ -253,7 +308,8 @@ gs232b_rot_move(ROT *rot, int direction, int speed)
* Generic GS232B rotator capabilities.
*/
const struct rot_caps gs232b_rot_caps = {
const struct rot_caps gs232b_rot_caps =
{
.rot_model = ROT_MODEL_GS232B,
.model_name = "GS-232B",
.mfg_name = "Yaesu",
@ -285,4 +341,3 @@ const struct rot_caps gs232b_rot_caps = {
};
/* end of file */