diff --git a/rigs/dummy/netrigctl.c b/rigs/dummy/netrigctl.c index fa06c42d0..fb19f8eee 100644 --- a/rigs/dummy/netrigctl.c +++ b/rigs/dummy/netrigctl.c @@ -683,7 +683,8 @@ static int netrigctl_open(RIG *rig) ptt_type_t temp = (ptt_type_t)strtol(value, NULL, 0); rig_debug(RIG_DEBUG_ERR, "%s: ptt_type='%s'(%d)\n", __func__, value, temp); - if (RIG_PTT_RIG_MICDATA == rig->state.pttport.type.ptt || temp == RIG_PTT_RIG_MICDATA) + if (RIG_PTT_RIG_MICDATA == rig->state.pttport.type.ptt + || temp == RIG_PTT_RIG_MICDATA) { /* * remote PTT must always be RIG_PTT_RIG_MICDATA diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index 3d975a8dc..532954cb4 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -9157,10 +9157,12 @@ int newcat_get_rx_bandwidth(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t *width) else if (is_ft991) { // some modes are fixed and can't be queried with "NA0" - if (mode != RIG_MODE_C4FM && mode != RIG_MODE_PKTFM && mode != RIG_MODE_PKTFMN && (narrow = get_narrow(rig, vfo)) < 0) + if (mode != RIG_MODE_C4FM && mode != RIG_MODE_PKTFM && mode != RIG_MODE_PKTFMN + && (narrow = get_narrow(rig, vfo)) < 0) { RETURNFUNC(-RIG_EPROTO); } + narrow = 0; switch (mode) diff --git a/rotators/grbltrk/grbltrk.c b/rotators/grbltrk/grbltrk.c old mode 100755 new mode 100644 index 00142361d..8a174a3f5 --- a/rotators/grbltrk/grbltrk.c +++ b/rotators/grbltrk/grbltrk.c @@ -112,40 +112,52 @@ char *grbl_init_list[] = "G0 X0 Y0\r\n", }; -static int -grbl_request(ROT *rot, char *request, uint32_t req_size, char *response, uint32_t *resp_size) +static int +grbl_request(ROT *rot, char *request, uint32_t req_size, char *response, + uint32_t *resp_size) { int retval; static int fail_count = 0; 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) { + if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_SER + || rot->caps->rot_model == ROT_MODEL_GRBLTRK_NET) + { //fprintf(stderr, "ctrl by serial/network\n"); - if ((retval = write_block(&rot->state.rotport, (unsigned char *)request, req_size)) != RIG_OK) { + if ((retval = write_block(&rot->state.rotport, (unsigned char *)request, + req_size)) != RIG_OK) + { rot_debug(RIG_DEBUG_ERR, "%s write_block fail!\n", __func__); //exit(-1); fail_count++; //return RIG_EIO; - } else { + } + else + { fail_count = 0; } rig_flush(&rot->state.rotport); usleep(300000); - if ((retval = read_string(&rot->state.rotport, (unsigned char *)response, 1024, "\n", 1, 0, 1)) < 0) { + + if ((retval = read_string(&rot->state.rotport, (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++; //return RIG_EIO; - } else { + } + else + { fail_count = 0; } - if (fail_count >= 10) { + if (fail_count >= 10) + { rot_debug(RIG_DEBUG_ERR, "%s too much xfer fail! exit\n", __func__); exit(-1); } @@ -157,7 +169,7 @@ grbl_request(ROT *rot, char *request, uint32_t req_size, char *response, uint32_ *resp_size = retval; - } + } return RIG_OK; } @@ -172,18 +184,24 @@ grbl_init(ROT *rot) /* get total config */ grbl_request(rot, grbl_get_config, strlen(grbl_get_config), rsp, &resp_size); - if (strstr(rsp, grbl_init_list[0]) != NULL) { + + if (strstr(rsp, grbl_init_list[0]) != NULL) + { rot_debug(RIG_DEBUG_ERR, "%s: grbl already configured\n", __func__); return RIG_OK; } init_count = sizeof(grbl_init_list) / sizeof(grbl_init_list[0]); - for(i = 0; i < init_count; i++) { + for (i = 0; i < init_count; i++) + { 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); + retval = grbl_request(rot, grbl_init_list[i], strlen(grbl_init_list[i]), rsp, + &resp_size); + //fprintf(stderr, "done\n"); - if (retval != RIG_OK) { + if (retval != RIG_OK) + { rot_debug(RIG_DEBUG_ERR, "grbl_request [%s] fail\n", grbl_init_list[i]); return RIG_EIO; } @@ -203,7 +221,7 @@ grbltrk_rot_set_position(ROT *rot, azimuth_t curr_az, elevation_t curr_el) float x[3], delta[3]; float y; - + char req[RSIZE] = {0}; char rsp[RSIZE] = {0}; uint32_t rsp_size; @@ -213,40 +231,56 @@ 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, - "%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); + rot_debug(RIG_DEBUG_ERR, + "%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); /* convert degree to mm, 360 degree = 40mm, 1 degree = 0.111mm */ //x = az * 0.111; //y = el * 0.111; - /* 360 -> 0 */ + /* 360 -> 0 */ if ((prev_az > 270 && prev_az < 360) && - (curr_az > 0 && curr_az < 90 )) { + (curr_az > 0 && curr_az < 90)) + { rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__); - if (prev_x >= XDEGREE2MM(270)) { + + if (prev_x >= XDEGREE2MM(270)) + { curr_x = XDEGREE2MM(curr_az) + XDEGREE2MM(360); - } else { + } + else + { curr_x = XDEGREE2MM(curr_az); } + /* 0 -> 360 */ - } else if ((prev_az > 0 && prev_az < 90 ) && - (curr_az > 270 && curr_az < 360)) { + } + else if ((prev_az > 0 && prev_az < 90) && + (curr_az > 270 && curr_az < 360)) + { rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__); - if (prev_x >= XDEGREE2MM(360)) { + if (prev_x >= XDEGREE2MM(360)) + { curr_x = XDEGREE2MM(curr_az); - } else { + } + else + { curr_x = XDEGREE2MM(curr_az) - XDEGREE2MM(360); } /* reset */ - } else if (curr_az == 0 && curr_el == 0) { + } + else if (curr_az == 0 && curr_el == 0) + { rot_debug(RIG_DEBUG_ERR, "%s: reset\n", __func__); curr_x = 0; - } else { + } + else + { rot_debug(RIG_DEBUG_ERR, "%s:%d prev_x: %.3f\n", __func__, __LINE__, prev_x); x[0] = XDEGREE2MM(curr_az) - XDEGREE2MM(360); @@ -258,14 +292,18 @@ grbltrk_rot_set_position(ROT *rot, azimuth_t curr_az, elevation_t curr_el) delta[2] = prev_x - x[2]; if (delta[0] < 0) { delta[0] = -1 * delta[0]; } + if (delta[1] < 0) { delta[1] = -1 * delta[1]; } + if (delta[2] < 0) { delta[2] = -1 * delta[2]; } min_value = delta[0]; min_index = 0; - for(i = 0; i < 3; i++) { - if (delta[i] <= min_value) { + for (i = 0; i < 3; i++) + { + if (delta[i] <= min_value) + { min_value = delta[i]; min_index = i; } @@ -280,9 +318,9 @@ grbltrk_rot_set_position(ROT *rot, azimuth_t curr_az, elevation_t curr_el) /**/ snprintf(req, sizeof(req), "G0 X%.3f Y%.3f\n", curr_x, y); - + retval = grbl_request(rot, req, strlen(req), rsp, &rsp_size); - + if (retval != RIG_OK) { return retval; @@ -314,8 +352,9 @@ grbltrk_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) rot_debug(RIG_DEBUG_ERR, "%s called\n", __func__); //snprintf(req, sizeof(req), "?\r\n"); - - for(i = 0; i < 5; i++) { + + for (i = 0; i < 5; i++) + { retval = grbl_request(rot, grbl_get_pos, strlen(grbl_get_pos), rsp, &rsp_size); /*FIXME: X Y safe check */ @@ -325,7 +364,8 @@ grbltrk_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) return retval; } - if (strstr(rsp, "MPos") == NULL) { + if (strstr(rsp, "MPos") == NULL) + { rot_debug(RIG_DEBUG_ERR, "%s no MPos found, continue\n", __func__); continue; } @@ -345,7 +385,8 @@ grbltrk_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) *az = (azimuth_t) mpos[0] * 9; *el = (elevation_t) mpos[1] * 9; - if ((*az) < 0) { + if ((*az) < 0) + { (*az) = (*az) + 360; } @@ -362,7 +403,7 @@ grbltrk_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) return RIG_OK; } -static int +static int grbltrk_rot_set_conf(ROT *rot, token_t token, const char *val) { int i, retval; @@ -374,13 +415,18 @@ grbltrk_rot_set_conf(ROT *rot, token_t token, const char *val) len = strlen(val); - if ((len != 0) && (val[0] == 'G')) { + if ((len != 0) && (val[0] == 'G')) + { - for(i = 0; i < len; i++) { + for (i = 0; i < len; i++) + { - if (val[i] == '@') { + if (val[i] == '@') + { req[i] = ' '; - } else { + } + else + { req[i] = val[i]; } } @@ -390,7 +436,9 @@ grbltrk_rot_set_conf(ROT *rot, token_t token, const char *val) rot_debug(RIG_DEBUG_ERR, "send gcode [%s]\n", req); retval = grbl_request(rot, req, len, rsp, &resp_size); - if (retval < 0) { + + if (retval < 0) + { rot_debug(RIG_DEBUG_ERR, "grbl_request [%s] fail\n", val); return RIG_EIO; } @@ -399,28 +447,29 @@ grbltrk_rot_set_conf(ROT *rot, token_t token, const char *val) return RIG_OK; } -static int +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); + rot_debug(RIG_DEBUG_ERR, "%s:%d rot->caps->rot_model: %d\n", __func__, __LINE__, + rot->caps->rot_model); return r; } -static int +static int grbl_net_open(ROT *rot, int port) { //network_open(&rot->state.rotport, port); //rot_debug(RIG_DEBUG_ERR, "%s:%d network_fd: %d\n", __func__, __LINE__, (&rot->state.rotport)->fd); rot_debug(RIG_DEBUG_ERR, "%s:%d \n", __func__, __LINE__); - + return 0; } -static int +static int grbltrk_rot_open(ROT *rot) { int r = RIG_OK; @@ -429,19 +478,28 @@ grbltrk_rot_open(ROT *rot) //int port; //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) { + 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) { + } + else if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_NET) + { rot_get_conf(rot, TOK_PATHNAME, host); - rot_debug(RIG_DEBUG_ERR, "%s:%d ctrl via net, host [%s]\n", __func__, __LINE__, host); + rot_debug(RIG_DEBUG_ERR, "%s:%d ctrl via net, host [%s]\n", __func__, __LINE__, + host); grbl_net_open(rot, 23); #if 0 - if (sscanf(host, "%[^:]:%d", ip, &port) == 2) { + + if (sscanf(host, "%[^:]:%d", ip, &port) == 2) + { grbl_net_open(rot, ip, port); - } else { + } + else + { grbl_net_open(rot, NULL, 0); /* use default ip & port */ } + #endif } @@ -453,20 +511,23 @@ grbltrk_rot_open(ROT *rot) return r; } -static void +static void grbl_net_close(ROT *rot) { port_close(&rot->state.rotport, RIG_PORT_NETWORK); } -static int +static int 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_SER) + { rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__); - } else if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_NET) { + } + else if (rot->caps->rot_model == ROT_MODEL_GRBLTRK_NET) + { rot_debug(RIG_DEBUG_ERR, "%s:%d\n", __func__, __LINE__); grbl_net_close(rot); } @@ -511,7 +572,7 @@ const struct rot_caps grbltrk_serial_rot_caps = .set_position = grbltrk_rot_set_position, .get_position = grbltrk_rot_get_position, - .set_conf = grbltrk_rot_set_conf, + .set_conf = grbltrk_rot_set_conf, }; const struct rot_caps grbltrk_net_rot_caps = @@ -544,7 +605,7 @@ const struct rot_caps grbltrk_net_rot_caps = .set_position = grbltrk_rot_set_position, .get_position = grbltrk_rot_get_position, - .set_conf = grbltrk_rot_set_conf, + .set_conf = grbltrk_rot_set_conf, }; diff --git a/simulators/simicom.c b/simulators/simicom.c index 93e963461..54f010334 100644 --- a/simulators/simicom.c +++ b/simulators/simicom.c @@ -284,16 +284,19 @@ void frameParse(int fd, unsigned char *frame, int len) } break; + case 0x26: - for(int i=0;i<6;++i) printf("%02x:",frame[i]); + for (int i = 0; i < 6; ++i) { printf("%02x:", frame[i]); } + if (frame[6] == 0xfd) // then a query { - frame[6] = frame[5] == 0? modeA : modeB; + frame[6] = frame[5] == 0 ? modeA : modeB; frame[7] = datamode; frame[8] = 0xfb; frame[9] = 0xfd; write(fd, frame, 10); } + printf("\n"); break; #else @@ -302,6 +305,7 @@ void frameParse(int fd, unsigned char *frame, int len) frame[4] = 0xfa; frame[5] = 0xfd; break; + case 0x26: frame[4] = 0xfa; frame[5] = 0xfd; diff --git a/simulators/simkenwood.c b/simulators/simkenwood.c index 89c9e1079..1f8d9077f 100644 --- a/simulators/simkenwood.c +++ b/simulators/simkenwood.c @@ -264,13 +264,18 @@ int main(int argc, char *argv[]) else if (strncmp(buf, "TX", 2) == 0) { ptt = ptt_mic = ptt_data = ptt_tune = 0; - switch(buf[2]) + + switch (buf[2]) { - case ';': ptt = 1; - case '0': ptt_mic = 1; - case '1': ptt_data = 1; - case '2': ptt_tune = 1; + case ';': ptt = 1; + + case '0': ptt_mic = 1; + + case '1': ptt_data = 1; + + case '2': ptt_tune = 1; } + continue; } else if (strlen(buf) > 0) diff --git a/simulators/simyaesu.c b/simulators/simyaesu.c index 8e5c2e731..f32c52c27 100644 --- a/simulators/simyaesu.c +++ b/simulators/simyaesu.c @@ -378,7 +378,8 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "RF", 2) == 0) { - SNPRINTF(buf, sizeof(buf), "RF%c%d;", buf[2], buf[2]==0?roofing_filter_main:roofing_filter_sub); + SNPRINTF(buf, sizeof(buf), "RF%c%d;", buf[2], + buf[2] == 0 ? roofing_filter_main : roofing_filter_sub); usleep(50 * 1000); n = write(fd, buf, strlen(buf)); } @@ -394,17 +395,20 @@ int main(int argc, char *argv[]) usleep(50 * 1000); n = write(fd, buf, strlen(buf)); } - else if (strncmp(buf, "SH",2) == 0 && strlen(buf) > 4) + else if (strncmp(buf, "SH", 2) == 0 && strlen(buf) > 4) { int vfo, twidth; - sscanf(buf,"SH%1d%d", &vfo, &twidth); - if (vfo == 0) width_main = twidth; - else width_sub = twidth; + sscanf(buf, "SH%1d%d", &vfo, &twidth); + + if (vfo == 0) { width_main = twidth; } + else { width_sub = twidth; } + printf("width_main=%d, width_sub=%d\n", width_main, width_sub); } - else if (strncmp(buf, "SH",2) == 0) + else if (strncmp(buf, "SH", 2) == 0) { - SNPRINTF(buf, sizeof(buf), "SH%c%02d;", buf[2], buf[2]==0?width_main:width_sub); + SNPRINTF(buf, sizeof(buf), "SH%c%02d;", buf[2], + buf[2] == 0 ? width_main : width_sub); } else if (strlen(buf) > 0) diff --git a/src/rig.c b/src/rig.c index c11335ffd..496792e55 100644 --- a/src/rig.c +++ b/src/rig.c @@ -2105,10 +2105,11 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) RETURNFUNC2(-RIG_ENAVAIL); } - if (vfo == RIG_VFO_CURR) - { - vfo = rig->state.current_vfo; + if (vfo == RIG_VFO_CURR) + { + vfo = rig->state.current_vfo; } + if (mode == RIG_MODE_NONE) // the we just use the current mode to set width { pbwidth_t twidth; diff --git a/src/settings.c b/src/settings.c index 40add6a76..a9f3e4e72 100644 --- a/src/settings.c +++ b/src/settings.c @@ -1114,7 +1114,8 @@ HAMLIB_EXPORT(int) rig_settings_load_all(char *settings_file) if (strcmp(s, "sharedkey") == 0) { char *sharedkey = strdup(v); - rig_debug(RIG_DEBUG_TRACE, "%s: settings_file=%s, shared_key=%s\n", __func__, settings_file, sharedkey); + rig_debug(RIG_DEBUG_TRACE, "%s: settings_file=%s, shared_key=%s\n", __func__, + settings_file, sharedkey); free(sharedkey); } } diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 30dd52de1..811ab64bf 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -1786,7 +1786,8 @@ readline_repeat: } } } - if (*resp_sep_ptr != '\n') fprintf(fout, "\n"); + + if (*resp_sep_ptr != '\n') { fprintf(fout, "\n"); } fflush(fout); @@ -2471,12 +2472,15 @@ declare_proto_rig(set_ptt) // No longer map this -- is confusing rigctld and MICDATA rigs // https://github.com/Hamlib/Hamlib/issues/998 #if 0 + // map to a legal value if (rig->caps->ptt_type != RIG_PTT_RIG_MICDATA) { - rig_debug(RIG_DEBUG_ERR, "%s: pttport.type.ptt=%d\n", __func__, rig->state.pttport.type.ptt); + rig_debug(RIG_DEBUG_ERR, "%s: pttport.type.ptt=%d\n", __func__, + rig->state.pttport.type.ptt); ptt = RIG_PTT_ON; } + #endif break; @@ -5184,7 +5188,8 @@ char rig_resp_sep = '\n'; declare_proto_rig(set_separator) { CHKSCN1ARG(sscanf(arg1, "%c", &rig_resp_sep)); - rig_debug(RIG_DEBUG_ERR, "%s: arg1=%s, resp_sep=0x%x, %p\n", __func__, arg1, (unsigned int)rig_resp_sep, &rig_resp_sep); + rig_debug(RIG_DEBUG_ERR, "%s: arg1=%s, resp_sep=0x%x, %p\n", __func__, arg1, + (unsigned int)rig_resp_sep, &rig_resp_sep); return RIG_OK; } @@ -5192,9 +5197,13 @@ declare_proto_rig(set_separator) declare_proto_rig(get_separator) { char buf[32]; + if (isprint(rig_resp_sep)) - sprintf(buf,"%c",rig_resp_sep); - else sprintf(buf,"0x%x %p",rig_resp_sep, &rig_resp_sep); - fprintf(fout,"%s\n", buf); + { + sprintf(buf, "%c", rig_resp_sep); + } + else { sprintf(buf, "0x%x %p", rig_resp_sep, &rig_resp_sep); } + + fprintf(fout, "%s\n", buf); return RIG_OK; } diff --git a/tests/rigctld.c b/tests/rigctld.c index c561d35cf..1766b806b 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -468,6 +468,7 @@ int main(int argc, char *argv[]) usage(); /* wrong arg count */ exit(1); } + resp_sep = *optarg; rig_debug(RIG_DEBUG_VERBOSE, "%s: resp_sep=%c\n", __func__, resp_sep); break;