kopia lustrzana https://github.com/Hamlib/Hamlib
astyle gs232a and minor debug format change
rodzic
a79e1c9d7d
commit
ac2f19a0dd
103
gs232a/gs232a.c
103
gs232a/gs232a.c
|
@ -58,7 +58,7 @@
|
|||
* recognized by rig.
|
||||
*/
|
||||
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)
|
||||
{
|
||||
struct rot_state *rs;
|
||||
|
@ -72,40 +72,65 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
/* Always read the reply to know whether the cmd went OK */
|
||||
if (!data)
|
||||
{
|
||||
data = replybuf;
|
||||
if (!data_len)
|
||||
data_len = BUFSZ;
|
||||
}
|
||||
|
||||
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 (!data_len)
|
||||
{
|
||||
data_len = BUFSZ;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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 (data[0] == '?') {
|
||||
if (data[0] == '?')
|
||||
{
|
||||
/* Invalid command */
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: Error for '%s': '%s'\n",
|
||||
__FUNCTION__, cmdstr, data);
|
||||
|
@ -126,17 +151,22 @@ gs232a_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=%.02f el=%.02f\n", __FUNCTION__, az,
|
||||
el);
|
||||
|
||||
if (az < 0.0)
|
||||
{
|
||||
az = az + 360.0;
|
||||
}
|
||||
|
||||
u_az = (unsigned)rint(az);
|
||||
u_el = (unsigned)rint(el);
|
||||
|
||||
sprintf(cmdstr, "W%03u %03u" EOM, u_az, u_el);
|
||||
retval = gs232a_transaction(rot, cmdstr, NULL, 0, 0);
|
||||
|
||||
if (retval != RIG_OK) {
|
||||
if (retval != RIG_OK)
|
||||
{
|
||||
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__);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
return -RIG_EPROTO;
|
||||
}
|
||||
|
||||
*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);
|
||||
return -RIG_EPROTO;
|
||||
}
|
||||
|
||||
*el = (elevation_t)angle;
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.1f, %.1f)\n",
|
||||
|
@ -184,8 +220,11 @@ gs232a_rot_stop(ROT *rot)
|
|||
|
||||
/* All Stop */
|
||||
retval = gs232a_transaction(rot, "S" EOM, NULL, 0, 0);
|
||||
|
||||
if (retval != RIG_OK)
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
|
||||
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__,
|
||||
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 = 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 */
|
||||
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 = gs232a_transaction(rot, cmdstr, NULL, 0, 1);
|
||||
|
||||
if (retval != RIG_OK)
|
||||
{
|
||||
return retval;
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
@ -240,7 +290,8 @@ gs232a_rot_move(ROT *rot, int direction, int speed)
|
|||
* Generic GS23 rotator capabilities.
|
||||
*/
|
||||
|
||||
const struct rot_caps gs23_rot_caps = {
|
||||
const struct rot_caps gs23_rot_caps =
|
||||
{
|
||||
.rot_model = ROT_MODEL_GS23,
|
||||
.model_name = "GS-23",
|
||||
.mfg_name = "Yaesu/Kenpro",
|
||||
|
@ -275,7 +326,8 @@ const struct rot_caps gs23_rot_caps = {
|
|||
* Generic GS232 rotator capabilities.
|
||||
*/
|
||||
|
||||
const struct rot_caps gs232_rot_caps = {
|
||||
const struct rot_caps gs232_rot_caps =
|
||||
{
|
||||
.rot_model = ROT_MODEL_GS232,
|
||||
.model_name = "GS-232",
|
||||
.mfg_name = "Yaesu/Kenpro",
|
||||
|
@ -310,7 +362,8 @@ const struct rot_caps gs232_rot_caps = {
|
|||
* Generic GS232A rotator capabilities.
|
||||
*/
|
||||
|
||||
const struct rot_caps gs232a_rot_caps = {
|
||||
const struct rot_caps gs232a_rot_caps =
|
||||
{
|
||||
.rot_model = ROT_MODEL_GS232A,
|
||||
.model_name = "GS-232A",
|
||||
.mfg_name = "Yaesu",
|
||||
|
|
|
@ -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 */
|
||||
if (!data)
|
||||
|
@ -103,7 +103,8 @@ transaction_write:
|
|||
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -169,7 +170,8 @@ 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: 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)
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue