Skip to content

Commit

Permalink
Fix RT21 2nd device for elevation
Browse files Browse the repository at this point in the history
  • Loading branch information
mdblack98 committed Apr 30, 2023
1 parent 4ada211 commit 1e9ecb0
Show file tree
Hide file tree
Showing 4 changed files with 216 additions and 21 deletions.
94 changes: 91 additions & 3 deletions rotators/rotorez/rotorez.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ const struct rot_caps rt21_rot_caps =
ROT_MODEL(ROT_MODEL_RT21),
.model_name = "RT-21",
.mfg_name = "Green Heron",
.version = "20230328.0",
.version = "20230430.0",
.copyright = "LGPL",
.status = RIG_STATUS_STABLE,
.rot_type = ROT_TYPE_OTHER,
Expand Down Expand Up @@ -652,7 +652,68 @@ static int rotorez_rot_get_position(ROT *rot, azimuth_t *azimuth,
}

*azimuth = tmp;
*elevation = 0; /* RotorEZ does not support elevation */

if (rot->state.rotport2.pathname != NULL)
{
do
{
err = rotorez_send_priv_cmd2(rot, cmdstr);

if (err != RIG_OK)
{
return err;
}

rs = &rot->state;

err = read_block(&rs->rotport, (unsigned char *) az, AZ_READ_LEN);

if (err != AZ_READ_LEN)
{
return -RIG_ETRUNC;
}

/* The elevation string should be ';xxx' beginning at offset 0. If the
* ';' is not there, it's likely the RotorEZ has received an invalid
* command and the buffer needs to be flushed. See
* rotorez_flush_buffer() definition below for a complete description.
*/
if (az[0] != ';')
{
err = rotorez_flush_buffer(rot);

if (err == -RIG_EIO)
{
return err;
}
else
{
err = -RIG_EINVAL;
}
}
else if (err == AZ_READ_LEN)
{
/* Check if remaining chars are digits if az[0] == ';' */
for (p = az + 1; p < az + 4; p++)
if (isdigit((int)*p))
{
continue;
}
else
{
err = -RIG_EINVAL;
}
}
}
while (err == -RIG_EINVAL);

sscanf(az, ";%f", elevation);
}
else
{
*elevation = 0; /* RotorEZ does not support elevation */
}

rig_debug(RIG_DEBUG_TRACE,
"%s: azimuth = %.1f deg; elevation = %.1f deg\n",
__func__, *azimuth, *elevation);
Expand Down Expand Up @@ -844,7 +905,34 @@ static int rt21_rot_get_position(ROT *rot, azimuth_t *azimuth,
}

*azimuth = tmp;
*elevation = 0.0; /* RT-21 backend does not support el at this time. */

if (rot->state.rotport2.pathname != NULL)
{
err = rotorez_send_priv_cmd2(rot, "BI1;");

if (err != RIG_OK)
{
return err;
}

rs = &rot->state;

err = read_string(&rs->rotport2, (unsigned char *) az, RT21_AZ_LEN + 1, ";",
strlen(";"), 0, 1);

if (err < 0) /* read_string returns negative on error. */
{
return err;
}

sscanf(az, "%f", elevation);

}
else
{
*elevation = 0.0; /* RT-21 backend does not support el at this time. */
}

rig_debug(RIG_DEBUG_TRACE,
"%s: azimuth = %.1f deg; elevation = %.1f deg\n",
__func__, *azimuth, *elevation);
Expand Down
110 changes: 97 additions & 13 deletions simulators/simrotorez.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@

#define BUFSIZE 256

float az = 0;
float el = 0;
static void *rotorez_thread(void *arg);

int
getmyline(int fd, char *buf)
{
unsigned char c;
unsigned char c = 0;
int i = 0;
int n = 0;
memset(buf, 0, BUFSIZE);

while (read(fd, &c, 1) > 0 && c!=';')
//printf("fd=%d\n", fd);

while (read(fd, &c, 1) > 0 && c != ';')
{
buf[i++] = c;
n++;
for(int i=0;i<strlen(buf);++i) printf("%02x ", buf[i]);

for (int i = 0; i < strlen(buf); ++i) { printf("%02x ", buf[i]); }

printf("\n");
}

Expand Down Expand Up @@ -70,20 +73,26 @@ int openPort(char *comport) // doesn't matter for using pts devices
}
#endif

int thread_args[2];


int main(int argc, char *argv[])
{
char buf[256];
int n;

again:
int fd = openPort(argv[1]);
int fd2 = openPort(argv[2]);
pthread_t threads[2];
thread_args[0] = fd;
thread_args[1] = fd2;
pthread_create(&threads[0], NULL, rotorez_thread, (void *)&thread_args[0]);
pthread_create(&threads[1], NULL, rotorez_thread, (void *)&thread_args[1]);
pthread_exit(NULL);
return 0;
/*
again:
int flag = 0;
while (1)
{
{
int bytes;
if (!flag) bytes = getmyline(fd, buf);
else bytes = getmyline(fd2, buf);
Expand All @@ -92,14 +101,15 @@ int main(int argc, char *argv[])
if (bytes == 0)
{
//close(fd);
printf("again\n");
goto again;
}
printf("line=%s\n", buf);
if (strncmp(buf,"BI1",3) == 0)
{
sprintf(buf,"%3.1f;", az);
n = write(fd, buf, strlen(buf));
n = write(flag?fd:fd2, buf, strlen(buf));
printf("n=%d\n", n);
}
else if (strncmp(buf,"AP1",3) == 0)
Expand All @@ -110,8 +120,81 @@ int main(int argc, char *argv[])
{
printf("Unknown cmd=%s\n", buf);
}

#if 0
switch (buf[0])
{
case '?': printf("Query %c\n", buf[1]); break;
case '*': printf("Set %c\n", buf[1]); break;
default: printf("Unknown cmd=%02x\n", buf[4]);
}
#endif
}
return 0;
*/
}

static void *rotorez_thread(void *arg)
{
int n = 0;
char buf[256];
int fd = *(int *)arg;
float az = 123;
float el = 45;
again:

while (1)
{
int bytes;
bytes = getmyline(fd, buf);

if (bytes == 0)
{
//close(fd);
hl_usleep(100 * 1000);
//printf("again\n");
goto again;
}

printf("line[%d]=%s\n", fd, buf);

if (strncmp(buf, "BI1", 3) == 0)
{
if (fd == thread_args[0])
{
sprintf(buf, "%3.1f;", az);
printf("az=%f\n", az);
}
else
{
sprintf(buf, "%3.1f;", el);
printf("el=%f\n", el);
}

n = write(fd, buf, strlen(buf));
printf("n=%d fd=%d\n", n, fd);
}
else if (strncmp(buf, "AP1", 3) == 0)
{
if (fd == thread_args[0])
{
sscanf(buf, "AP1%f", &az);
}
else
{
sscanf(buf, "AP1%f", &el);
}
}
else
{
printf("Unknown cmd=%s\n", buf);
}

#if 0

switch (buf[0])
{
case '?': printf("Query %c\n", buf[1]); break;
Expand All @@ -120,8 +203,9 @@ int main(int argc, char *argv[])

default: printf("Unknown cmd=%02x\n", buf[4]);
}

#endif
}

return 0;
pthread_exit(NULL);
}
30 changes: 25 additions & 5 deletions src/rotator.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,11 @@ ROT *HAMLIB_API rot_init(rot_model_t rot_model)
{
case RIG_PORT_SERIAL:
strncpy(rs->rotport.pathname, DEFAULT_SERIAL_PORT, HAMLIB_FILPATHLEN - 1);
rs->rotport.parm.serial.rate = caps->serial_rate_max; /* fastest ! */
rs->rotport.parm.serial.data_bits = caps->serial_data_bits;
rs->rotport.parm.serial.stop_bits = caps->serial_stop_bits;
rs->rotport.parm.serial.parity = caps->serial_parity;
rs->rotport.parm.serial.handshake = caps->serial_handshake;
rs->rotport.parm.serial.rate = rs->rotport2.parm.serial.rate = caps->serial_rate_max; /* fastest ! */
rs->rotport.parm.serial.data_bits = rs->rotport2.parm.serial.data_bits = caps->serial_data_bits;
rs->rotport.parm.serial.stop_bits = rs->rotport2.parm.serial.stop_bits = caps->serial_stop_bits;
rs->rotport.parm.serial.parity = rs->rotport2.parm.serial.parity = caps->serial_parity;
rs->rotport.parm.serial.handshake = rs->rotport2.parm.serial.handshake = caps->serial_handshake;
break;

case RIG_PORT_PARALLEL:
Expand Down Expand Up @@ -379,6 +379,7 @@ int HAMLIB_API rot_open(ROT *rot)
}

rs->rotport.fd = -1;
rs->rotport2.fd = -1;

// determine if we have a network address
if (sscanf(rs->rotport.pathname, "%d.%d.%d.%d:%d", &net1, &net2, &net3, &net4,
Expand All @@ -388,6 +389,13 @@ int HAMLIB_API rot_open(ROT *rot)
rs->rotport.pathname);
rs->rotport.type.rig = RIG_PORT_NETWORK;
}
if (sscanf(rs->rotport2.pathname, "%d.%d.%d.%d:%d", &net1, &net2, &net3, &net4,
&port) == 5)
{
rig_debug(RIG_DEBUG_TRACE, "%s: using network address %s\n", __func__,
rs->rotport2.pathname);
rs->rotport2.type.rig = RIG_PORT_NETWORK;
}

switch (rs->rotport.type.rig)
{
Expand All @@ -399,6 +407,18 @@ int HAMLIB_API rot_open(ROT *rot)
return status;
}

// RT21 has 2nd serial port elevation
// so if a 2nd pathname is provided we'll open it
if (rot->caps->rot_model == ROT_MODEL_RT21 && rs->rotport2.pathname[0] != 0)
{
status = serial_open(&rs->rotport2);

if (status != 0)
{
return status;
}
}

break;

case RIG_PORT_PARALLEL:
Expand Down
3 changes: 3 additions & 0 deletions tests/rotctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,12 @@ int main(int argc, char *argv[])
}

/* FIXME: bound checking and port type == serial */
my_rot->state.rotport2.parm.serial.rate = my_rot->state.rotport2.parm.serial.rate;
my_rot->state.rotport2.parm.serial.data_bits = my_rot->state.rotport2.parm.serial.data_bits;
if (serial_rate != 0)
{
my_rot->state.rotport.parm.serial.rate = serial_rate;
my_rot->state.rotport2.parm.serial.rate = serial_rate;
}

/*
Expand Down

0 comments on commit 1e9ecb0

Please sign in to comment.