pull/1873/head
Nate Bargmann 2025-08-24 16:26:05 -05:00
commit 2332826713
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: FB2C5130D55A8819
1 zmienionych plików z 27 dodań i 93 usunięć

Wyświetl plik

@ -116,8 +116,6 @@ grbl_request(ROT *rot, char *request, uint32_t req_size, char *response,
static int fail_count = 0;
hamlib_port_t *rotp = ROTPORT(rot);
rot_debug(RIG_DEBUG_ERR, "req: [%s][%d]\n", request, fail_count);
if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_SER
|| rot->caps->rot_model == ROT_MODEL_GRBLTRK_NET)
{
@ -127,9 +125,9 @@ grbl_request(ROT *rot, char *request, uint32_t req_size, char *response,
if ((retval = write_block(rotp, (unsigned char *)request,
req_size)) != RIG_OK)
{
rot_debug(RIG_DEBUG_ERR, "%s write_block fail!\n", __func__);
//exit(-1);
fail_count++;
rot_debug(RIG_DEBUG_ERR, "%s write_block fail! (%d) fail_count %d\n", __func__, retval, fail_count);
//exit(-1);
//return -RIG_EIO;
}
else
@ -144,9 +142,9 @@ grbl_request(ROT *rot, char *request, uint32_t req_size, char *response,
if ((retval = read_string(rotp, (unsigned char *)response, 1024,
"\n", 1, 0, 1)) < 0)
{
rot_debug(RIG_DEBUG_ERR, "%s read_string fail! (%d) \n", __func__, retval);
//exit(-1);
fail_count++;
rot_debug(RIG_DEBUG_ERR, "%s read_string fail! (%d) fail_count %d\n", __func__, retval, fail_count);
//exit(-1);
//return -RIG_EIO;
}
else
@ -157,16 +155,12 @@ grbl_request(ROT *rot, char *request, uint32_t req_size, char *response,
if (fail_count >= 10)
{
rot_debug(RIG_DEBUG_ERR, "%s too much xfer fail! exit\n", __func__);
return -RIG_EPROTO;
return retval;
}
rig_flush(rotp);
rot_debug(RIG_DEBUG_ERR, "rsp: [%s]\n", response);
//fprintf(stderr, "rsp: [%s]\n", response);
*resp_size = retval;
}
return RIG_OK;
@ -180,6 +174,8 @@ grbl_init(ROT *rot)
char rsp[RSIZE];
uint32_t resp_size;
rot_debug(RIG_DEBUG_TRACE, "%s:%d\n", __func__, __LINE__);
/* get total config */
grbl_request(rot, grbl_get_config, strlen(grbl_get_config), rsp, &resp_size);
@ -194,7 +190,7 @@ grbl_init(ROT *rot)
for (i = 0; i < init_count; i++)
{
int retval;
rot_debug(RIG_DEBUG_ERR, "grbl_request [%s] ", grbl_init_list[i]);
retval = grbl_request(rot, grbl_init_list[i], strlen(grbl_init_list[i]), rsp,
&resp_size);
@ -202,7 +198,7 @@ grbl_init(ROT *rot)
if (retval != RIG_OK)
{
rot_debug(RIG_DEBUG_ERR, "grbl_request [%s] fail\n", grbl_init_list[i]);
return -RIG_EIO;
return retval;
}
}
@ -230,7 +226,7 @@ grbltrk_rot_set_position(ROT *rot, azimuth_t curr_az, elevation_t curr_el)
/* az:x: 0 - 360 */
/* el:y: 0 - 90 */
rot_debug(RIG_DEBUG_ERR,
rot_debug(RIG_DEBUG_TRACE,
"%s: (prev_x) = (%.3f); (prev_az) = (%.3f); (prev_el) = (%.3f); (curr_az, curr_el) = (%.3f, %.3f)\n",
__func__,
prev_x, prev_az, prev_el, curr_az, curr_el);
@ -244,7 +240,7 @@ grbltrk_rot_set_position(ROT *rot, azimuth_t curr_az, elevation_t curr_el)
(curr_az > 0 && curr_az < 90))
{
rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__);
rot_debug(RIG_DEBUG_TRACE, "%s:%d\n", __func__, __LINE__);
if (prev_x >= XDEGREE2MM(270))
{
@ -260,7 +256,7 @@ grbltrk_rot_set_position(ROT *rot, azimuth_t curr_az, elevation_t curr_el)
else if ((prev_az > 0 && prev_az < 90) &&
(curr_az > 270 && curr_az < 360))
{
rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__);
rot_debug(RIG_DEBUG_TRACE, "%s:%d\n", __func__, __LINE__);
if (prev_x >= XDEGREE2MM(360))
{
@ -275,12 +271,12 @@ grbltrk_rot_set_position(ROT *rot, azimuth_t curr_az, elevation_t curr_el)
}
else if (curr_az == 0 && curr_el == 0)
{
rot_debug(RIG_DEBUG_ERR, "%s: reset\n", __func__);
rot_debug(RIG_DEBUG_TRACE, "%s: reset\n", __func__);
curr_x = 0;
}
else
{
rot_debug(RIG_DEBUG_ERR, "%s:%d prev_x: %.3f\n", __func__, __LINE__, prev_x);
rot_debug(RIG_DEBUG_TRACE, "%s:%d prev_x: %.3f\n", __func__, __LINE__, prev_x);
x[0] = XDEGREE2MM(curr_az) - XDEGREE2MM(360);
x[1] = XDEGREE2MM(curr_az);
@ -309,7 +305,7 @@ grbltrk_rot_set_position(ROT *rot, azimuth_t curr_az, elevation_t curr_el)
}
curr_x = x[min_index];
rot_debug(RIG_DEBUG_ERR, "min_index: %d; curr_x: %.3f\n", min_index, curr_x);
rot_debug(RIG_DEBUG_TRACE, "min_index: %d; curr_x: %.3f\n", min_index, curr_x);
}
y = YDEGREE2MM(curr_el);
@ -347,7 +343,7 @@ grbltrk_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
int i;
rot_debug(RIG_DEBUG_ERR, "%s called\n", __func__);
rot_debug(RIG_DEBUG_TRACE, "%s called\n", __func__);
//snprintf(req, sizeof(req), "?\r\n");
@ -377,7 +373,7 @@ grbltrk_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
//<Idle|MPos:0.000,0.000,0.000|FS:0,0|Pn:P|WCO:5.000,0.000,0.000>
sscanf(rsp, "%[^'|']|MPos:%f,%f,%255s", dummy0, &mpos[0], &mpos[1], dummy1);
//rot_debug(RIG_DEBUG_ERR, "%s: (%.3f, %.3f) (%.3f, %.3f)\n", __func__, mpos[0], mpos[1], wpos[0], wpos[1]);
//rot_debug(RIG_DEBUG_TRACE, "%s: (%.3f, %.3f) (%.3f, %.3f)\n", __func__, mpos[0], mpos[1], wpos[0], wpos[1]);
//*az = (azimuth_t) mpos[0] / 0.111;
//*el = (elevation_t) mpos[1] / 0.111;
@ -389,9 +385,7 @@ grbltrk_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el)
(*az) = (*az) + 360;
}
//rot_debug(RIG_DEBUG_ERR, "%s: (az, el) = (%.3f, %.3f)\n", __func__, *az, *el);
rot_debug(RIG_DEBUG_ERR, "%s: (az, el) = (%.3f, %.3f)\n", __func__, *az, *el);
rot_debug(RIG_DEBUG_TRACE, "%s: (az, el) = (%.3f, %.3f)\n", __func__, *az, *el);
return RIG_OK;
@ -407,7 +401,7 @@ grbltrk_rot_set_conf(ROT *rot, hamlib_token_t token, const char *val)
{
uint32_t resp_size, len;
rot_debug(RIG_DEBUG_ERR, "token: %ld; value: [%s]\n", token, val);
rot_debug(RIG_DEBUG_TRACE, "token: %ld; value: [%s]\n", token, val);
len = strlen(val);
@ -438,7 +432,7 @@ grbltrk_rot_set_conf(ROT *rot, hamlib_token_t token, const char *val)
req[i] = '\n';
len = strlen(req);
rot_debug(RIG_DEBUG_ERR, "send gcode [%s]\n", req);
rot_debug(RIG_DEBUG_TRACE, "send gcode [%s]\n", req);
retval = grbl_request(rot, req, len, rsp, &resp_size);
if (retval < 0)
@ -451,66 +445,14 @@ grbltrk_rot_set_conf(ROT *rot, hamlib_token_t token, const char *val)
return RIG_OK;
}
static int
grbltrk_rot_init(ROT *rot)
{
int r = RIG_OK;
rot_debug(RIG_DEBUG_ERR, "%s:%d rot->caps->rot_model: %d\n", __func__, __LINE__,
rot->caps->rot_model);
return r;
}
static int
grbl_net_open(ROT *rot, int port)
{
//network_open(ROTPORT(rot), port);
//rot_debug(RIG_DEBUG_ERR, "%s:%d network_fd: %d\n", __func__, __LINE__, ROTPORT(rot)->fd);
rot_debug(RIG_DEBUG_ERR, "%s:%d \n", __func__, __LINE__);
return 0;
}
static int
grbltrk_rot_open(ROT *rot)
{
int r = RIG_OK;
char host[128] = {0};
//char ip[32];
//int port;
int r;
//rot_debug(RIG_DEBUG_ERR, "%s:%d rot->caps->rot_model: %d\n", __func__, __LINE__, rot->caps->rot_model);
if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_SER)
{
rot_debug(RIG_DEBUG_ERR, "%s:%d ctrl via serial\n", __func__, __LINE__);
}
else if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_NET)
{
rot_get_conf2(rot, TOK_PATHNAME, host, sizeof(host));
rot_debug(RIG_DEBUG_ERR, "%s:%d ctrl via net, host [%s]\n", __func__, __LINE__,
host);
grbl_net_open(rot, 23);
rot_debug(RIG_DEBUG_TRACE, "%s:%d\n", __func__, __LINE__);
#if 0
if (sscanf(host, "%[^:]:%d", ip, &port) == 2)
{
grbl_net_open(rot, ip, port);
}
else
{
grbl_net_open(rot, NULL, 0); /* use default ip & port */
}
#endif
}
grbl_init(rot);
//rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__);
r = grbl_init(rot);
return r;
}
@ -526,17 +468,13 @@ grbltrk_rot_close(ROT *rot)
{
int r = RIG_OK;
if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_SER)
if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_NET)
{
rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__);
}
else if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_NET)
{
rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__);
rot_debug(RIG_DEBUG_TRACE, "%s:%d\n", __func__, __LINE__);
grbl_net_close(rot);
}
rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__);
rot_debug(RIG_DEBUG_TRACE, "%s:%d\n", __func__, __LINE__);
return r;
}
@ -571,7 +509,6 @@ const struct rot_caps grbltrk_serial_rot_caps =
.min_el = 0,
.max_el = 90,
.rot_init = grbltrk_rot_init,
.rot_open = grbltrk_rot_open,
.set_position = grbltrk_rot_set_position,
@ -603,7 +540,6 @@ const struct rot_caps grbltrk_net_rot_caps =
.min_el = 0,
.max_el = 90,
.rot_init = grbltrk_rot_init,
.rot_open = grbltrk_rot_open,
.rot_close = grbltrk_rot_close,
@ -617,9 +553,7 @@ const struct rot_caps grbltrk_net_rot_caps =
DECLARE_INITROT_BACKEND(grbltrk)
{
rig_debug(RIG_DEBUG_VERBOSE, "%s: _init called\n", __func__);
//rot_debug(RIG_DEBUG_ERR, "%s: _init called\n", __func__);
rot_debug(RIG_DEBUG_TRACE, "%s: _init called\n", __func__);
rot_register(&grbltrk_serial_rot_caps);