From e267c6276495bee71eaf217715874cb56bcb4d6b Mon Sep 17 00:00:00 2001 From: Mike Black W9MDB Date: Sat, 16 Dec 2023 11:37:58 -0600 Subject: [PATCH] astyle files --- amplifiers/gemini/gemini.c | 5 +- lib/cJSON.c | 1287 ++++++++++++++++++++------------ lib/precise_time.c | 200 ++--- rigs/adat/adat.c | 83 +- rigs/anytone/anytone.c | 46 +- rigs/aor/ar3030.c | 3 +- rigs/aor/ar7030.c | 3 +- rigs/aor/ar7030p.c | 11 +- rigs/barrett/950.c | 4 +- rigs/barrett/barrett.c | 11 +- rigs/dummy/aclog.c | 4 +- rigs/dummy/amp_dummy.c | 4 +- rigs/dummy/dummy.c | 13 +- rigs/dummy/flrig.c | 13 +- rigs/dummy/netrigctl.c | 4 +- rigs/dummy/quisk.c | 39 +- rigs/dummy/rot_dummy.c | 8 +- rigs/dummy/sdrsharp.c | 4 +- rigs/dummy/trxmanager.c | 4 +- rigs/elad/elad.c | 3 + rigs/gomspace/gs100.c | 27 +- rigs/icom/frame.c | 8 +- rigs/icom/ic7100.c | 4 + rigs/icom/ic7300.c | 50 +- rigs/icom/ic7600.c | 4 + rigs/icom/ic7610.c | 6 +- rigs/icom/ic7700.c | 4 + rigs/icom/ic7800.c | 10 +- rigs/icom/icf8101.c | 4 + rigs/icom/icom.c | 182 +++-- rigs/icom/id5100.c | 3 +- rigs/kenwood/elecraft.c | 62 +- rigs/kenwood/flex6xxx.c | 171 +++-- rigs/kenwood/ic10.c | 24 +- rigs/kenwood/k3.c | 22 +- rigs/kenwood/kenwood.c | 78 +- rigs/kenwood/pihpsdr.c | 4 +- rigs/kenwood/th.c | 4 +- rigs/kenwood/thd72.c | 8 + rigs/kenwood/tmd710.c | 38 +- rigs/kenwood/ts590.c | 30 +- rigs/kenwood/ts870s.c | 2 +- rigs/kenwood/ts890s.c | 68 +- rigs/kenwood/ts930.c | 2 +- rigs/kenwood/ts990s.c | 7 +- rigs/kit/elektor507.c | 6 +- rigs/kit/fifisdr.c | 6 +- rigs/kit/funcube.c | 3 +- rigs/kit/hiqsdr.c | 3 +- rigs/kit/rs_hfiq.c | 3 +- rigs/kit/si570avrusb.c | 10 +- rigs/mds/mds.c | 7 +- rigs/pcr/pcr.c | 12 +- rigs/racal/ra37xx.c | 6 +- rigs/tentec/tentec.c | 9 +- rigs/uniden/uniden.c | 6 +- rigs/yaesu/ft1200.c | 8 +- rigs/yaesu/ft2000.c | 6 +- rigs/yaesu/ft3000.c | 8 +- rigs/yaesu/ft450.c | 6 +- rigs/yaesu/ft5000.c | 6 +- rigs/yaesu/ft710.c | 10 +- rigs/yaesu/ft767gx.c | 1 + rigs/yaesu/ft817.c | 3 +- rigs/yaesu/ft857.c | 6 +- rigs/yaesu/ft891.c | 12 +- rigs/yaesu/ft897.c | 3 +- rigs/yaesu/ft9000.c | 8 +- rigs/yaesu/ft920.c | 3 +- rigs/yaesu/ft950.c | 4 +- rigs/yaesu/ft980.c | 4 +- rigs/yaesu/ft991.c | 10 +- rigs/yaesu/ftdx10.c | 10 +- rigs/yaesu/ftdx101.c | 16 +- rigs/yaesu/ftdx101mp.c | 14 +- rigs/yaesu/newcat.c | 588 +++++++++------ rigs/yaesu/vx1700.c | 6 +- rigs/yaesu/yaesu.c | 2 +- rotators/flir/flir.c | 11 +- rotators/fodtrack/fodtrack.c | 20 +- rotators/gs232a/gs232b.c | 3 +- rotators/ioptron/rot_ioptron.c | 21 +- rotators/spid/spid.c | 53 +- rotators/ts7400/ts7400.c | 2 +- security/md5.c | 2 +- security/password.c | 1 + security/sha256.c | 1 + simulators/simelecraft.c | 3 +- simulators/simft817.c | 18 +- simulators/simft818.c | 3 +- simulators/simft991.c | 6 +- simulators/simftdx101.c | 17 +- simulators/simftdx1200.c | 3 +- simulators/simftdx3000.c | 3 +- simulators/simftdx5000.c | 3 +- simulators/simic7300.c | 4 +- simulators/simic7610.c | 31 +- simulators/simic9100.c | 1 + simulators/simic9700.c | 1 + simulators/simkenwood.c | 3 +- simulators/simpowersdr.c | 3 +- simulators/simqrplabs.c | 3 +- simulators/simrotorez.c | 3 +- simulators/simtmd700.c | 3 +- simulators/simtrusdx.c | 3 +- simulators/simts450.c | 3 +- simulators/simts590.c | 20 +- simulators/simts950.c | 3 +- simulators/simts990.c | 8 +- simulators/simyaesu.c | 3 +- src/amp_conf.c | 1 + src/amplifier.c | 6 +- src/cache.c | 11 +- src/conf.c | 4 +- src/event.c | 35 +- src/fifo.c | 51 +- src/iofunc.c | 61 +- src/misc.c | 146 ++-- src/multicast.c | 11 +- src/network.c | 117 ++- src/rig.c | 350 +++++---- src/rotator.c | 6 +- src/serial.c | 10 +- src/settings.c | 12 +- src/sleep.c | 3 +- src/snapshot_data.c | 14 +- src/sprintflst.c | 15 +- tests/ampctl.c | 14 +- tests/ampctl_parse.c | 1 + tests/ampctld.c | 14 +- tests/dumpcaps.c | 3 +- tests/dumpstate.c | 51 +- tests/memcsv.c | 5 + tests/rig_tests.c | 2 +- tests/rigctl.c | 36 +- tests/rigctl_parse.c | 241 ++++-- tests/rigctld.c | 70 +- tests/rigfreqwalk.c | 38 +- tests/rigmem.c | 2 +- tests/rigtestlibusb.c | 3 +- tests/rotctl.c | 20 +- tests/rotctl_parse.c | 59 +- tests/rotctld.c | 17 +- tests/testcache.c | 1 + tests/testrig.c | 14 +- 145 files changed, 3177 insertions(+), 1905 deletions(-) diff --git a/amplifiers/gemini/gemini.c b/amplifiers/gemini/gemini.c index 6f69b0678..df7ad27f7 100644 --- a/amplifiers/gemini/gemini.c +++ b/amplifiers/gemini/gemini.c @@ -103,8 +103,9 @@ int gemini_transaction(AMP *amp, const char *cmd, char *response, if (response) // if response expected get it { response[0] = 0; - int len = read_string(&rs->ampport, (unsigned char *) response, response_len, "\n", - 1, 0, 1); + int len = read_string(&rs->ampport, (unsigned char *) response, response_len, + "\n", + 1, 0, 1); if (len < 0) { diff --git a/lib/cJSON.c b/lib/cJSON.c index 524ba4641..d9b70dcd0 100644 --- a/lib/cJSON.c +++ b/lib/cJSON.c @@ -85,7 +85,8 @@ #endif #endif -typedef struct { +typedef struct +{ const unsigned char *json; size_t position; } error; @@ -93,10 +94,10 @@ static error global_error = { NULL, 0 }; CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void) { - return (const char*) (global_error.json + global_error.position); + return (const char *)(global_error.json + global_error.position); } -CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) +CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON *const item) { if (!cJSON_IsString(item)) { @@ -106,7 +107,7 @@ CJSON_PUBLIC(char *) cJSON_GetStringValue(const cJSON * const item) return item->valuestring; } -CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) +CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON *const item) { if (!cJSON_IsNumber(item)) { @@ -118,19 +119,21 @@ CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON * const item) /* This is a safeguard to prevent copy-pasters from using incompatible C and header files */ #if (CJSON_VERSION_MAJOR != 1) || (CJSON_VERSION_MINOR != 7) || (CJSON_VERSION_PATCH != 15) - #error cJSON.h and cJSON.c have different versions. Make sure that both have the same. +#error cJSON.h and cJSON.c have different versions. Make sure that both have the same. #endif -CJSON_PUBLIC(const char*) cJSON_Version(void) +CJSON_PUBLIC(const char *) cJSON_Version(void) { static char version[15]; - sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH); + sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, + CJSON_VERSION_PATCH); return version; } /* Case insensitive string comparison, doesn't consider two NULL pointers equal though */ -static int case_insensitive_strcmp(const unsigned char *string1, const unsigned char *string2) +static int case_insensitive_strcmp(const unsigned char *string1, + const unsigned char *string2) { if ((string1 == NULL) || (string2 == NULL)) { @@ -142,7 +145,7 @@ static int case_insensitive_strcmp(const unsigned char *string1, const unsigned return 0; } - for(; tolower(*string1) == tolower(*string2); (void)string1++, string2++) + for (; tolower(*string1) == tolower(*string2); (void)string1++, string2++) { if (*string1 == '\0') { @@ -162,7 +165,7 @@ typedef struct internal_hooks #if defined(_MSC_VER) /* work around MSVC error C2322: '...' address of dllimport '...' is not static */ -static void * CJSON_CDECL internal_malloc(size_t size) +static void *CJSON_CDECL internal_malloc(size_t size) { return malloc(size); } @@ -170,7 +173,7 @@ static void CJSON_CDECL internal_free(void *pointer) { free(pointer); } -static void * CJSON_CDECL internal_realloc(void *pointer, size_t size) +static void *CJSON_CDECL internal_realloc(void *pointer, size_t size) { return realloc(pointer, size); } @@ -185,7 +188,8 @@ static void * CJSON_CDECL internal_realloc(void *pointer, size_t size) static internal_hooks global_hooks = { internal_malloc, internal_free, internal_realloc }; -static unsigned char* cJSON_strdup(const unsigned char* string, const internal_hooks * const hooks) +static unsigned char *cJSON_strdup(const unsigned char *string, + const internal_hooks *const hooks) { size_t length = 0; unsigned char *copy = NULL; @@ -195,18 +199,20 @@ static unsigned char* cJSON_strdup(const unsigned char* string, const internal_h return NULL; } - length = strlen((const char*)string) + sizeof(""); - copy = (unsigned char*)hooks->allocate(length); + length = strlen((const char *)string) + sizeof(""); + copy = (unsigned char *)hooks->allocate(length); + if (copy == NULL) { return NULL; } + memcpy(copy, string, length); return copy; } -CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) +CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks *hooks) { if (hooks == NULL) { @@ -218,12 +224,14 @@ CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) } global_hooks.allocate = malloc; + if (hooks->malloc_fn != NULL) { global_hooks.allocate = hooks->malloc_fn; } global_hooks.deallocate = free; + if (hooks->free_fn != NULL) { global_hooks.deallocate = hooks->free_fn; @@ -231,6 +239,7 @@ CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) /* use realloc only if both free and malloc are used */ global_hooks.reallocate = NULL; + if ((global_hooks.allocate == malloc) && (global_hooks.deallocate == free)) { global_hooks.reallocate = realloc; @@ -238,9 +247,10 @@ CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks) } /* Internal constructor. */ -static cJSON *cJSON_New_Item(const internal_hooks * const hooks) +static cJSON *cJSON_New_Item(const internal_hooks *const hooks) { - cJSON* node = (cJSON*)hooks->allocate(sizeof(cJSON)); + cJSON *node = (cJSON *)hooks->allocate(sizeof(cJSON)); + if (node) { memset(node, '\0', sizeof(cJSON)); @@ -253,21 +263,26 @@ static cJSON *cJSON_New_Item(const internal_hooks * const hooks) CJSON_PUBLIC(void) cJSON_Delete(cJSON *item) { cJSON *next = NULL; + while (item != NULL) { next = item->next; + if (!(item->type & cJSON_IsReference) && (item->child != NULL)) { cJSON_Delete(item->child); } + if (!(item->type & cJSON_IsReference) && (item->valuestring != NULL)) { global_hooks.deallocate(item->valuestring); } + if (!(item->type & cJSON_StringIsConst) && (item->string != NULL)) { global_hooks.deallocate(item->string); } + global_hooks.deallocate(item); item = next; } @@ -302,7 +317,8 @@ typedef struct #define buffer_at_offset(buffer) ((buffer)->content + (buffer)->offset) /* Parse the input text to generate a number, and populate the result into item. */ -static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_buffer) +static cJSON_bool parse_number(cJSON *const item, + parse_buffer *const input_buffer) { double number = 0; unsigned char *after_end = NULL; @@ -318,39 +334,42 @@ static cJSON_bool parse_number(cJSON * const item, parse_buffer * const input_bu /* copy the number into a temporary buffer and replace '.' with the decimal point * of the current locale (for strtod) * This also takes care of '\0' not necessarily being available for marking the end of the input */ - for (i = 0; (i < (sizeof(number_c_string) - 1)) && can_access_at_index(input_buffer, i); i++) + for (i = 0; (i < (sizeof(number_c_string) - 1)) + && can_access_at_index(input_buffer, i); i++) { switch (buffer_at_offset(input_buffer)[i]) { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case '+': - case '-': - case 'e': - case 'E': - number_c_string[i] = buffer_at_offset(input_buffer)[i]; - break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case '+': + case '-': + case 'e': + case 'E': + number_c_string[i] = buffer_at_offset(input_buffer)[i]; + break; - case '.': - number_c_string[i] = decimal_point; - break; + case '.': + number_c_string[i] = decimal_point; + break; - default: - goto loop_end; + default: + goto loop_end; } } + loop_end: number_c_string[i] = '\0'; - number = strtod((const char*)number_c_string, (char**)&after_end); + number = strtod((const char *)number_c_string, (char **)&after_end); + if (number_c_string == after_end) { return false; /* parse_error */ @@ -397,28 +416,35 @@ CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number) return object->valuedouble = number; } -CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring) +CJSON_PUBLIC(char *) cJSON_SetValuestring(cJSON *object, + const char *valuestring) { char *copy = NULL; + /* if object's type is not cJSON_String or is cJSON_IsReference, it should not set valuestring */ if (!(object->type & cJSON_String) || (object->type & cJSON_IsReference)) { return NULL; } + if (strlen(valuestring) <= strlen(object->valuestring)) { strcpy(object->valuestring, valuestring); return object->valuestring; } - copy = (char*) cJSON_strdup((const unsigned char*)valuestring, &global_hooks); + + copy = (char *) cJSON_strdup((const unsigned char *)valuestring, &global_hooks); + if (copy == NULL) { return NULL; } + if (object->valuestring != NULL) { cJSON_free(object->valuestring); } + object->valuestring = copy; return copy; @@ -436,7 +462,7 @@ typedef struct } printbuffer; /* realloc printbuffer if necessary to have at least "needed" bytes more */ -static unsigned char* ensure(printbuffer * const p, size_t needed) +static unsigned char *ensure(printbuffer *const p, size_t needed) { unsigned char *newbuffer = NULL; size_t newsize = 0; @@ -459,12 +485,14 @@ static unsigned char* ensure(printbuffer * const p, size_t needed) } needed += p->offset + 1; + if (needed <= p->length) { return p->buffer + p->offset; } - if (p->noalloc) { + if (p->noalloc) + { return NULL; } @@ -489,7 +517,8 @@ static unsigned char* ensure(printbuffer * const p, size_t needed) if (p->hooks.reallocate != NULL) { /* reallocate with realloc if available */ - newbuffer = (unsigned char*)p->hooks.reallocate(p->buffer, newsize); + newbuffer = (unsigned char *)p->hooks.reallocate(p->buffer, newsize); + if (newbuffer == NULL) { p->hooks.deallocate(p->buffer); @@ -502,7 +531,8 @@ static unsigned char* ensure(printbuffer * const p, size_t needed) else { /* otherwise reallocate manually */ - newbuffer = (unsigned char*)p->hooks.allocate(newsize); + newbuffer = (unsigned char *)p->hooks.allocate(newsize); + if (!newbuffer) { p->hooks.deallocate(p->buffer); @@ -515,6 +545,7 @@ static unsigned char* ensure(printbuffer * const p, size_t needed) memcpy(newbuffer, p->buffer, p->offset + 1); p->hooks.deallocate(p->buffer); } + p->length = newsize; p->buffer = newbuffer; @@ -522,16 +553,18 @@ static unsigned char* ensure(printbuffer * const p, size_t needed) } /* calculate the new length of the string in a printbuffer and update the offset */ -static void update_offset(printbuffer * const buffer) +static void update_offset(printbuffer *const buffer) { const unsigned char *buffer_pointer = NULL; + if ((buffer == NULL) || (buffer->buffer == NULL)) { return; } + buffer_pointer = buffer->buffer + buffer->offset; - buffer->offset += strlen((const char*)buffer_pointer); + buffer->offset += strlen((const char *)buffer_pointer); } /* securely comparison of floating-point variables */ @@ -542,7 +575,8 @@ static cJSON_bool compare_double(double a, double b) } /* Render the number nicely from the given item into a string. */ -static cJSON_bool print_number(const cJSON * const item, printbuffer * const output_buffer) +static cJSON_bool print_number(const cJSON *const item, + printbuffer *const output_buffer) { unsigned char *output_pointer = NULL; double d = item->valuedouble; @@ -560,22 +594,23 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out /* This checks for NaN and Infinity */ if (isnan(d) || isinf(d)) { - length = sprintf((char*)number_buffer, "null"); + length = sprintf((char *)number_buffer, "null"); + } + else if (d == (double)item->valueint) + { + length = sprintf((char *)number_buffer, "%d", item->valueint); } - else if(d == (double)item->valueint) - { - length = sprintf((char*)number_buffer, "%d", item->valueint); - } else { /* Try 15 decimal places of precision to avoid nonsignificant nonzero digits */ - length = sprintf((char*)number_buffer, "%1.15g", d); + length = sprintf((char *)number_buffer, "%1.15g", d); /* Check whether the original double can be recovered */ - if ((sscanf((char*)number_buffer, "%lg", &test) != 1) || !compare_double((double)test, d)) + if ((sscanf((char *)number_buffer, "%lg", &test) != 1) + || !compare_double((double)test, d)) { /* If not, print with 17 decimal places of precision */ - length = sprintf((char*)number_buffer, "%1.17g", d); + length = sprintf((char *)number_buffer, "%1.17g", d); } } @@ -587,6 +622,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out /* reserve appropriate space in the output */ output_pointer = ensure(output_buffer, (size_t)length + sizeof("")); + if (output_pointer == NULL) { return false; @@ -604,6 +640,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out output_pointer[i] = number_buffer[i]; } + output_pointer[i] = '\0'; output_buffer->offset += (size_t)length; @@ -612,7 +649,7 @@ static cJSON_bool print_number(const cJSON * const item, printbuffer * const out } /* parse 4 digit hexadecimal number */ -static unsigned parse_hex4(const unsigned char * const input) +static unsigned parse_hex4(const unsigned char *const input) { unsigned int h = 0; size_t i = 0; @@ -649,7 +686,9 @@ static unsigned parse_hex4(const unsigned char * const input) /* converts a UTF-16 literal to UTF-8 * A literal can be one or two sequences of the form \uXXXX */ -static unsigned char utf16_literal_to_utf8(const unsigned char * const input_pointer, const unsigned char * const input_end, unsigned char **output_pointer) +static unsigned char utf16_literal_to_utf8(const unsigned char *const + input_pointer, const unsigned char *const input_end, + unsigned char **output_pointer) { long unsigned int codepoint = 0; unsigned int first_code = 0; @@ -695,6 +734,7 @@ static unsigned char utf16_literal_to_utf8(const unsigned char * const input_poi /* get the second utf16 sequence */ second_code = parse_hex4(second_sequence + 2); + /* check that the code is valid */ if ((second_code < 0xDC00) || (second_code > 0xDFFF)) { @@ -745,12 +785,14 @@ static unsigned char utf16_literal_to_utf8(const unsigned char * const input_poi } /* encode as utf8 */ - for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; utf8_position--) + for (utf8_position = (unsigned char)(utf8_length - 1); utf8_position > 0; + utf8_position--) { /* 10xxxxxx */ (*output_pointer)[utf8_position] = (unsigned char)((codepoint | 0x80) & 0xBF); codepoint >>= 6; } + /* encode first byte */ if (utf8_length > 1) { @@ -770,7 +812,8 @@ fail: } /* Parse the input text into an unescaped cinput, and populate item. */ -static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_buffer) +static cJSON_bool parse_string(cJSON *const item, + parse_buffer *const input_buffer) { const unsigned char *input_pointer = buffer_at_offset(input_buffer) + 1; const unsigned char *input_end = buffer_at_offset(input_buffer) + 1; @@ -787,7 +830,9 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu /* calculate approximate size of the output (overestimate) */ size_t allocation_length = 0; size_t skipped_bytes = 0; - while (((size_t)(input_end - input_buffer->content) < input_buffer->length) && (*input_end != '\"')) + + while (((size_t)(input_end - input_buffer->content) < input_buffer->length) + && (*input_end != '\"')) { /* is escape sequence */ if (input_end[0] == '\\') @@ -797,19 +842,26 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu /* prevent buffer overflow when last input character is a backslash */ goto fail; } + skipped_bytes++; input_end++; } + input_end++; } - if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) || (*input_end != '\"')) + + if (((size_t)(input_end - input_buffer->content) >= input_buffer->length) + || (*input_end != '\"')) { goto fail; /* string ended unexpectedly */ } /* This is at most how much we need for the output */ - allocation_length = (size_t) (input_end - buffer_at_offset(input_buffer)) - skipped_bytes; - output = (unsigned char*)input_buffer->hooks.allocate(allocation_length + sizeof("")); + allocation_length = (size_t)(input_end - buffer_at_offset( + input_buffer)) - skipped_bytes; + output = (unsigned char *)input_buffer->hooks.allocate(allocation_length + + sizeof("")); + if (output == NULL) { goto fail; /* allocation failure */ @@ -817,6 +869,7 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu } output_pointer = output; + /* loop through the string literal */ while (input_pointer < input_end) { @@ -828,6 +881,7 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu else { unsigned char sequence_length = 2; + if ((input_end - input_pointer) < 1) { goto fail; @@ -835,40 +889,49 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu switch (input_pointer[1]) { - case 'b': - *output_pointer++ = '\b'; - break; - case 'f': - *output_pointer++ = '\f'; - break; - case 'n': - *output_pointer++ = '\n'; - break; - case 'r': - *output_pointer++ = '\r'; - break; - case 't': - *output_pointer++ = '\t'; - break; - case '\"': - case '\\': - case '/': - *output_pointer++ = input_pointer[1]; - break; + case 'b': + *output_pointer++ = '\b'; + break; - /* UTF-16 literal */ - case 'u': - sequence_length = utf16_literal_to_utf8(input_pointer, input_end, &output_pointer); - if (sequence_length == 0) - { - /* failed to convert UTF16-literal to UTF-8 */ - goto fail; - } - break; + case 'f': + *output_pointer++ = '\f'; + break; - default: + case 'n': + *output_pointer++ = '\n'; + break; + + case 'r': + *output_pointer++ = '\r'; + break; + + case 't': + *output_pointer++ = '\t'; + break; + + case '\"': + case '\\': + case '/': + *output_pointer++ = input_pointer[1]; + break; + + /* UTF-16 literal */ + case 'u': + sequence_length = utf16_literal_to_utf8(input_pointer, input_end, + &output_pointer); + + if (sequence_length == 0) + { + /* failed to convert UTF16-literal to UTF-8 */ goto fail; + } + + break; + + default: + goto fail; } + input_pointer += sequence_length; } } @@ -877,14 +940,15 @@ static cJSON_bool parse_string(cJSON * const item, parse_buffer * const input_bu *output_pointer = '\0'; item->type = cJSON_String; - item->valuestring = (char*)output; + item->valuestring = (char *)output; - input_buffer->offset = (size_t) (input_end - input_buffer->content); + input_buffer->offset = (size_t)(input_end - input_buffer->content); input_buffer->offset++; return true; fail: + if (output != NULL) { input_buffer->hooks.deallocate(output); @@ -899,7 +963,8 @@ fail: } /* Render the cstring provided to an escaped version that can be printed. */ -static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffer * const output_buffer) +static cJSON_bool print_string_ptr(const unsigned char *const input, + printbuffer *const output_buffer) { const unsigned char *input_pointer = NULL; unsigned char *output = NULL; @@ -917,11 +982,13 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe if (input == NULL) { output = ensure(output_buffer, sizeof("\"\"")); + if (output == NULL) { return false; } - strcpy((char*)output, "\"\""); + + strcpy((char *)output, "\"\""); return true; } @@ -931,28 +998,32 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe { switch (*input_pointer) { - case '\"': - case '\\': - case '\b': - case '\f': - case '\n': - case '\r': - case '\t': - /* one character escape sequence */ - escape_characters++; - break; - default: - if (*input_pointer < 32) - { - /* UTF-16 escape sequence uXXXX */ - escape_characters += 5; - } - break; + case '\"': + case '\\': + case '\b': + case '\f': + case '\n': + case '\r': + case '\t': + /* one character escape sequence */ + escape_characters++; + break; + + default: + if (*input_pointer < 32) + { + /* UTF-16 escape sequence uXXXX */ + escape_characters += 5; + } + + break; } } + output_length = (size_t)(input_pointer - input) + escape_characters; output = ensure(output_buffer, output_length + sizeof("\"\"")); + if (output == NULL) { return false; @@ -971,10 +1042,13 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe output[0] = '\"'; output_pointer = output + 1; + /* copy the string */ - for (input_pointer = input; *input_pointer != '\0'; (void)input_pointer++, output_pointer++) + for (input_pointer = input; *input_pointer != '\0'; + (void)input_pointer++, output_pointer++) { - if ((*input_pointer > 31) && (*input_pointer != '\"') && (*input_pointer != '\\')) + if ((*input_pointer > 31) && (*input_pointer != '\"') + && (*input_pointer != '\\')) { /* normal character, copy */ *output_pointer = *input_pointer; @@ -983,37 +1057,46 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe { /* character needs to be escaped */ *output_pointer++ = '\\'; + switch (*input_pointer) { - case '\\': - *output_pointer = '\\'; - break; - case '\"': - *output_pointer = '\"'; - break; - case '\b': - *output_pointer = 'b'; - break; - case '\f': - *output_pointer = 'f'; - break; - case '\n': - *output_pointer = 'n'; - break; - case '\r': - *output_pointer = 'r'; - break; - case '\t': - *output_pointer = 't'; - break; - default: - /* escape and print as unicode codepoint */ - sprintf((char*)output_pointer, "u%04x", *input_pointer); - output_pointer += 4; - break; + case '\\': + *output_pointer = '\\'; + break; + + case '\"': + *output_pointer = '\"'; + break; + + case '\b': + *output_pointer = 'b'; + break; + + case '\f': + *output_pointer = 'f'; + break; + + case '\n': + *output_pointer = 'n'; + break; + + case '\r': + *output_pointer = 'r'; + break; + + case '\t': + *output_pointer = 't'; + break; + + default: + /* escape and print as unicode codepoint */ + sprintf((char *)output_pointer, "u%04x", *input_pointer); + output_pointer += 4; + break; } } } + output[output_length + 1] = '\"'; output[output_length + 2] = '\0'; @@ -1021,21 +1104,27 @@ static cJSON_bool print_string_ptr(const unsigned char * const input, printbuffe } /* Invoke print_string_ptr (which is useful) on an item. */ -static cJSON_bool print_string(const cJSON * const item, printbuffer * const p) +static cJSON_bool print_string(const cJSON *const item, printbuffer *const p) { - return print_string_ptr((unsigned char*)item->valuestring, p); + return print_string_ptr((unsigned char *)item->valuestring, p); } /* Predeclare these prototypes. */ -static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer); -static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer); -static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer); -static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer); -static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer); -static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer); +static cJSON_bool parse_value(cJSON *const item, + parse_buffer *const input_buffer); +static cJSON_bool print_value(const cJSON *const item, + printbuffer *const output_buffer); +static cJSON_bool parse_array(cJSON *const item, + parse_buffer *const input_buffer); +static cJSON_bool print_array(const cJSON *const item, + printbuffer *const output_buffer); +static cJSON_bool parse_object(cJSON *const item, + parse_buffer *const input_buffer); +static cJSON_bool print_object(const cJSON *const item, + printbuffer *const output_buffer); /* Utility to jump whitespace and cr/lf */ -static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) +static parse_buffer *buffer_skip_whitespace(parse_buffer *const buffer) { if ((buffer == NULL) || (buffer->content == NULL)) { @@ -1049,7 +1138,7 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) while (can_access_at_index(buffer, 0) && (buffer_at_offset(buffer)[0] <= 32)) { - buffer->offset++; + buffer->offset++; } if (buffer->offset == buffer->length) @@ -1061,14 +1150,15 @@ static parse_buffer *buffer_skip_whitespace(parse_buffer * const buffer) } /* skip the UTF-8 BOM (byte order mark) if it is at the beginning of a buffer */ -static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) +static parse_buffer *skip_utf8_bom(parse_buffer *const buffer) { if ((buffer == NULL) || (buffer->content == NULL) || (buffer->offset != 0)) { return NULL; } - if (can_access_at_index(buffer, 4) && (strncmp((const char*)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) + if (can_access_at_index(buffer, 4) + && (strncmp((const char *)buffer_at_offset(buffer), "\xEF\xBB\xBF", 3) == 0)) { buffer->offset += 3; } @@ -1076,7 +1166,8 @@ static parse_buffer *skip_utf8_bom(parse_buffer * const buffer) return buffer; } -CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) +CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, + const char **return_parse_end, cJSON_bool require_null_terminated) { size_t buffer_length; @@ -1088,11 +1179,14 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return /* Adding null character size due to require_null_terminated. */ buffer_length = strlen(value) + sizeof(""); - return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, require_null_terminated); + return cJSON_ParseWithLengthOpts(value, buffer_length, return_parse_end, + require_null_terminated); } /* Parse an object - create a new root, and populate. */ -CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated) +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, + size_t buffer_length, const char **return_parse_end, + cJSON_bool require_null_terminated) { parse_buffer buffer = { 0, 0, 0, 0, { 0, 0, 0 } }; cJSON *item = NULL; @@ -1106,12 +1200,13 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer goto fail; } - buffer.content = (const unsigned char*)value; + buffer.content = (const unsigned char *)value; buffer.length = buffer_length; buffer.offset = 0; buffer.hooks = global_hooks; item = cJSON_New_Item(&global_hooks); + if (item == NULL) /* memory fail */ { goto fail; @@ -1127,19 +1222,22 @@ CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer if (require_null_terminated) { buffer_skip_whitespace(&buffer); + if ((buffer.offset >= buffer.length) || buffer_at_offset(&buffer)[0] != '\0') { goto fail; } } + if (return_parse_end) { - *return_parse_end = (const char*)buffer_at_offset(&buffer); + *return_parse_end = (const char *)buffer_at_offset(&buffer); } return item; fail: + if (item != NULL) { cJSON_Delete(item); @@ -1148,7 +1246,7 @@ fail: if (value != NULL) { error local_error; - local_error.json = (const unsigned char*)value; + local_error.json = (const unsigned char *)value; local_error.position = 0; if (buffer.offset < buffer.length) @@ -1162,7 +1260,7 @@ fail: if (return_parse_end != NULL) { - *return_parse_end = (const char*)local_error.json + local_error.position; + *return_parse_end = (const char *)local_error.json + local_error.position; } global_error = local_error; @@ -1177,14 +1275,16 @@ CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value) return cJSON_ParseWithOpts(value, 0, 0); } -CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length) +CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, + size_t buffer_length) { return cJSON_ParseWithLengthOpts(value, buffer_length, 0, 0); } #define cjson_min(a, b) (((a) < (b)) ? (a) : (b)) -static unsigned char *print(const cJSON * const item, cJSON_bool format, const internal_hooks * const hooks) +static unsigned char *print(const cJSON *const item, cJSON_bool format, + const internal_hooks *const hooks) { static const size_t default_buffer_size = 256; printbuffer buffer[1]; @@ -1193,10 +1293,11 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i memset(buffer, 0, sizeof(buffer)); /* create buffer */ - buffer->buffer = (unsigned char*) hooks->allocate(default_buffer_size); + buffer->buffer = (unsigned char *) hooks->allocate(default_buffer_size); buffer->length = default_buffer_size; buffer->format = format; buffer->hooks = *hooks; + if (buffer->buffer == NULL) { goto fail; @@ -1207,24 +1308,31 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i { goto fail; } + update_offset(buffer); /* check if reallocate is available */ if (hooks->reallocate != NULL) { - printed = (unsigned char*) hooks->reallocate(buffer->buffer, buffer->offset + 1); - if (printed == NULL) { - goto fail; - } - buffer->buffer = NULL; - } - else /* otherwise copy the JSON over to a new buffer */ - { - printed = (unsigned char*) hooks->allocate(buffer->offset + 1); + printed = (unsigned char *) hooks->reallocate(buffer->buffer, + buffer->offset + 1); + if (printed == NULL) { goto fail; } + + buffer->buffer = NULL; + } + else /* otherwise copy the JSON over to a new buffer */ + { + printed = (unsigned char *) hooks->allocate(buffer->offset + 1); + + if (printed == NULL) + { + goto fail; + } + memcpy(printed, buffer->buffer, cjson_min(buffer->length, buffer->offset + 1)); printed[buffer->offset] = '\0'; /* just to be sure */ @@ -1235,6 +1343,7 @@ static unsigned char *print(const cJSON * const item, cJSON_bool format, const i return printed; fail: + if (buffer->buffer != NULL) { hooks->deallocate(buffer->buffer); @@ -1251,15 +1360,16 @@ fail: /* Render a cJSON item/entity/structure to text. */ CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item) { - return (char*)print(item, true, &global_hooks); + return (char *)print(item, true, &global_hooks); } CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) { - return (char*)print(item, false, &global_hooks); + return (char *)print(item, false, &global_hooks); } -CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) +CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, + cJSON_bool fmt) { printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; @@ -1268,7 +1378,8 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON return NULL; } - p.buffer = (unsigned char*)global_hooks.allocate((size_t)prebuffer); + p.buffer = (unsigned char *)global_hooks.allocate((size_t)prebuffer); + if (!p.buffer) { return NULL; @@ -1286,10 +1397,11 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON return NULL; } - return (char*)p.buffer; + return (char *)p.buffer; } -CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) +CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, + const int length, const cJSON_bool format) { printbuffer p = { 0, 0, 0, 0, 0, 0, { 0, 0, 0 } }; @@ -1298,7 +1410,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, cons return false; } - p.buffer = (unsigned char*)buffer; + p.buffer = (unsigned char *)buffer; p.length = (size_t)length; p.offset = 0; p.noalloc = true; @@ -1309,7 +1421,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, cons } /* Parser core - when encountering text, process appropriately. */ -static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buffer) +static cJSON_bool parse_value(cJSON *const item, + parse_buffer *const input_buffer) { if ((input_buffer == NULL) || (input_buffer->content == NULL)) { @@ -1318,44 +1431,59 @@ static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buf /* parse the different types of values */ /* null */ - if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "null", 4) == 0)) + if (can_read(input_buffer, 4) + && (strncmp((const char *)buffer_at_offset(input_buffer), "null", 4) == 0)) { item->type = cJSON_NULL; input_buffer->offset += 4; return true; } + /* false */ - if (can_read(input_buffer, 5) && (strncmp((const char*)buffer_at_offset(input_buffer), "false", 5) == 0)) + if (can_read(input_buffer, 5) + && (strncmp((const char *)buffer_at_offset(input_buffer), "false", 5) == 0)) { item->type = cJSON_False; input_buffer->offset += 5; return true; } + /* true */ - if (can_read(input_buffer, 4) && (strncmp((const char*)buffer_at_offset(input_buffer), "true", 4) == 0)) + if (can_read(input_buffer, 4) + && (strncmp((const char *)buffer_at_offset(input_buffer), "true", 4) == 0)) { item->type = cJSON_True; item->valueint = 1; input_buffer->offset += 4; return true; } + /* string */ - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '\"')) + if (can_access_at_index(input_buffer, 0) + && (buffer_at_offset(input_buffer)[0] == '\"')) { return parse_string(item, input_buffer); } + /* number */ - if (can_access_at_index(input_buffer, 0) && ((buffer_at_offset(input_buffer)[0] == '-') || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) + if (can_access_at_index(input_buffer, 0) + && ((buffer_at_offset(input_buffer)[0] == '-') + || ((buffer_at_offset(input_buffer)[0] >= '0') + && (buffer_at_offset(input_buffer)[0] <= '9')))) { return parse_number(item, input_buffer); } + /* array */ - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '[')) + if (can_access_at_index(input_buffer, 0) + && (buffer_at_offset(input_buffer)[0] == '[')) { return parse_array(item, input_buffer); } + /* object */ - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '{')) + if (can_access_at_index(input_buffer, 0) + && (buffer_at_offset(input_buffer)[0] == '{')) { return parse_object(item, input_buffer); } @@ -1364,7 +1492,8 @@ static cJSON_bool parse_value(cJSON * const item, parse_buffer * const input_buf } /* Render a value to text. */ -static cJSON_bool print_value(const cJSON * const item, printbuffer * const output_buffer) +static cJSON_bool print_value(const cJSON *const item, + printbuffer *const output_buffer) { unsigned char *output = NULL; @@ -1375,70 +1504,80 @@ static cJSON_bool print_value(const cJSON * const item, printbuffer * const outp switch ((item->type) & 0xFF) { - case cJSON_NULL: - output = ensure(output_buffer, 5); - if (output == NULL) - { - return false; - } - strcpy((char*)output, "null"); - return true; + case cJSON_NULL: + output = ensure(output_buffer, 5); - case cJSON_False: - output = ensure(output_buffer, 6); - if (output == NULL) - { - return false; - } - strcpy((char*)output, "false"); - return true; - - case cJSON_True: - output = ensure(output_buffer, 5); - if (output == NULL) - { - return false; - } - strcpy((char*)output, "true"); - return true; - - case cJSON_Number: - return print_number(item, output_buffer); - - case cJSON_Raw: + if (output == NULL) { - size_t raw_length = 0; - if (item->valuestring == NULL) - { - return false; - } - - raw_length = strlen(item->valuestring) + sizeof(""); - output = ensure(output_buffer, raw_length); - if (output == NULL) - { - return false; - } - memcpy(output, item->valuestring, raw_length); - return true; + return false; } - case cJSON_String: - return print_string(item, output_buffer); + strcpy((char *)output, "null"); + return true; - case cJSON_Array: - return print_array(item, output_buffer); + case cJSON_False: + output = ensure(output_buffer, 6); - case cJSON_Object: - return print_object(item, output_buffer); - - default: + if (output == NULL) + { return false; + } + + strcpy((char *)output, "false"); + return true; + + case cJSON_True: + output = ensure(output_buffer, 5); + + if (output == NULL) + { + return false; + } + + strcpy((char *)output, "true"); + return true; + + case cJSON_Number: + return print_number(item, output_buffer); + + case cJSON_Raw: + { + size_t raw_length = 0; + + if (item->valuestring == NULL) + { + return false; + } + + raw_length = strlen(item->valuestring) + sizeof(""); + output = ensure(output_buffer, raw_length); + + if (output == NULL) + { + return false; + } + + memcpy(output, item->valuestring, raw_length); + return true; + } + + case cJSON_String: + return print_string(item, output_buffer); + + case cJSON_Array: + return print_array(item, output_buffer); + + case cJSON_Object: + return print_object(item, output_buffer); + + default: + return false; } } /* Build an array from input text. */ -static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buffer) +static cJSON_bool parse_array(cJSON *const item, + parse_buffer *const input_buffer) { cJSON *head = NULL; /* head of the linked list */ cJSON *current_item = NULL; @@ -1447,6 +1586,7 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf { return false; /* to deeply nested */ } + input_buffer->depth++; if (buffer_at_offset(input_buffer)[0] != '[') @@ -1457,7 +1597,9 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf input_buffer->offset++; buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ']')) + + if (can_access_at_index(input_buffer, 0) + && (buffer_at_offset(input_buffer)[0] == ']')) { /* empty array */ goto success; @@ -1472,11 +1614,13 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf /* step back to character in front of the first element */ input_buffer->offset--; + /* loop through the comma separated array elements */ do { /* allocate next item */ cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) { goto fail; /* allocation failure */ @@ -1499,15 +1643,19 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf /* parse next value */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) { goto fail; /* failed to parse value */ } + buffer_skip_whitespace(input_buffer); } - while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + while (can_access_at_index(input_buffer, 0) + && (buffer_at_offset(input_buffer)[0] == ',')); - if (cannot_access_at_index(input_buffer, 0) || buffer_at_offset(input_buffer)[0] != ']') + if (cannot_access_at_index(input_buffer, 0) + || buffer_at_offset(input_buffer)[0] != ']') { goto fail; /* expected end of array */ } @@ -1515,7 +1663,8 @@ static cJSON_bool parse_array(cJSON * const item, parse_buffer * const input_buf success: input_buffer->depth--; - if (head != NULL) { + if (head != NULL) + { head->prev = current_item; } @@ -1527,6 +1676,7 @@ success: return true; fail: + if (head != NULL) { cJSON_Delete(head); @@ -1536,7 +1686,8 @@ fail: } /* Render an array to text */ -static cJSON_bool print_array(const cJSON * const item, printbuffer * const output_buffer) +static cJSON_bool print_array(const cJSON *const item, + printbuffer *const output_buffer) { unsigned char *output_pointer = NULL; size_t length = 0; @@ -1550,6 +1701,7 @@ static cJSON_bool print_array(const cJSON * const item, printbuffer * const outp /* Compose the output array. */ /* opening square bracket */ output_pointer = ensure(output_buffer, 1); + if (output_pointer == NULL) { return false; @@ -1565,31 +1717,40 @@ static cJSON_bool print_array(const cJSON * const item, printbuffer * const outp { return false; } + update_offset(output_buffer); + if (current_element->next) { - length = (size_t) (output_buffer->format ? 2 : 1); + length = (size_t)(output_buffer->format ? 2 : 1); output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) { return false; } + *output_pointer++ = ','; - if(output_buffer->format) + + if (output_buffer->format) { *output_pointer++ = ' '; } + *output_pointer = '\0'; output_buffer->offset += length; } + current_element = current_element->next; } output_pointer = ensure(output_buffer, 2); + if (output_pointer == NULL) { return false; } + *output_pointer++ = ']'; *output_pointer = '\0'; output_buffer->depth--; @@ -1598,7 +1759,8 @@ static cJSON_bool print_array(const cJSON * const item, printbuffer * const outp } /* Build an object from the text. */ -static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_buffer) +static cJSON_bool parse_object(cJSON *const item, + parse_buffer *const input_buffer) { cJSON *head = NULL; /* linked list head */ cJSON *current_item = NULL; @@ -1607,16 +1769,20 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu { return false; /* to deeply nested */ } + input_buffer->depth++; - if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '{')) + if (cannot_access_at_index(input_buffer, 0) + || (buffer_at_offset(input_buffer)[0] != '{')) { goto fail; /* not an object */ } input_buffer->offset++; buffer_skip_whitespace(input_buffer); - if (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == '}')) + + if (can_access_at_index(input_buffer, 0) + && (buffer_at_offset(input_buffer)[0] == '}')) { goto success; /* empty object */ } @@ -1630,11 +1796,13 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu /* step back to character in front of the first element */ input_buffer->offset--; + /* loop through the comma separated array elements */ do { /* allocate next item */ cJSON *new_item = cJSON_New_Item(&(input_buffer->hooks)); + if (new_item == NULL) { goto fail; /* allocation failure */ @@ -1657,17 +1825,20 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu /* parse the name of the child */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); + if (!parse_string(current_item, input_buffer)) { goto fail; /* failed to parse name */ } + buffer_skip_whitespace(input_buffer); /* swap valuestring and string, because we parsed the name */ current_item->string = current_item->valuestring; current_item->valuestring = NULL; - if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != ':')) + if (cannot_access_at_index(input_buffer, 0) + || (buffer_at_offset(input_buffer)[0] != ':')) { goto fail; /* invalid object */ } @@ -1675,15 +1846,19 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu /* parse the value */ input_buffer->offset++; buffer_skip_whitespace(input_buffer); + if (!parse_value(current_item, input_buffer)) { goto fail; /* failed to parse value */ } + buffer_skip_whitespace(input_buffer); } - while (can_access_at_index(input_buffer, 0) && (buffer_at_offset(input_buffer)[0] == ',')); + while (can_access_at_index(input_buffer, 0) + && (buffer_at_offset(input_buffer)[0] == ',')); - if (cannot_access_at_index(input_buffer, 0) || (buffer_at_offset(input_buffer)[0] != '}')) + if (cannot_access_at_index(input_buffer, 0) + || (buffer_at_offset(input_buffer)[0] != '}')) { goto fail; /* expected end of object */ } @@ -1691,7 +1866,8 @@ static cJSON_bool parse_object(cJSON * const item, parse_buffer * const input_bu success: input_buffer->depth--; - if (head != NULL) { + if (head != NULL) + { head->prev = current_item; } @@ -1702,6 +1878,7 @@ success: return true; fail: + if (head != NULL) { cJSON_Delete(head); @@ -1711,7 +1888,8 @@ fail: } /* Render an object to text. */ -static cJSON_bool print_object(const cJSON * const item, printbuffer * const output_buffer) +static cJSON_bool print_object(const cJSON *const item, + printbuffer *const output_buffer) { unsigned char *output_pointer = NULL; size_t length = 0; @@ -1723,8 +1901,9 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out } /* Compose the output: */ - length = (size_t) (output_buffer->format ? 2 : 1); /* fmt: {\n */ + length = (size_t)(output_buffer->format ? 2 : 1); /* fmt: {\n */ output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) { return false; @@ -1732,10 +1911,12 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out *output_pointer++ = '{'; output_buffer->depth++; + if (output_buffer->format) { *output_pointer++ = '\n'; } + output_buffer->offset += length; while (current_item) @@ -1744,35 +1925,43 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out { size_t i; output_pointer = ensure(output_buffer, output_buffer->depth); + if (output_pointer == NULL) { return false; } + for (i = 0; i < output_buffer->depth; i++) { *output_pointer++ = '\t'; } + output_buffer->offset += output_buffer->depth; } /* print key */ - if (!print_string_ptr((unsigned char*)current_item->string, output_buffer)) + if (!print_string_ptr((unsigned char *)current_item->string, output_buffer)) { return false; } + update_offset(output_buffer); - length = (size_t) (output_buffer->format ? 2 : 1); + length = (size_t)(output_buffer->format ? 2 : 1); output_pointer = ensure(output_buffer, length); + if (output_pointer == NULL) { return false; } + *output_pointer++ = ':'; + if (output_buffer->format) { *output_pointer++ = '\t'; } + output_buffer->offset += length; /* print value */ @@ -1780,15 +1969,19 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out { return false; } + update_offset(output_buffer); /* print comma if not last */ - length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)(current_item->next ? 1 : 0)); + length = ((size_t)(output_buffer->format ? 1 : 0) + (size_t)( + current_item->next ? 1 : 0)); output_pointer = ensure(output_buffer, length + 1); + if (output_pointer == NULL) { return false; } + if (current_item->next) { *output_pointer++ = ','; @@ -1798,25 +1991,31 @@ static cJSON_bool print_object(const cJSON * const item, printbuffer * const out { *output_pointer++ = '\n'; } + *output_pointer = '\0'; output_buffer->offset += length; current_item = current_item->next; } - output_pointer = ensure(output_buffer, output_buffer->format ? (output_buffer->depth + 1) : 2); + output_pointer = ensure(output_buffer, + output_buffer->format ? (output_buffer->depth + 1) : 2); + if (output_pointer == NULL) { return false; } + if (output_buffer->format) { size_t i; + for (i = 0; i < (output_buffer->depth - 1); i++) { *output_pointer++ = '\t'; } } + *output_pointer++ = '}'; *output_pointer = '\0'; output_buffer->depth--; @@ -1837,7 +2036,7 @@ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) child = array->child; - while(child != NULL) + while (child != NULL) { size++; child = child->next; @@ -1848,7 +2047,7 @@ CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array) return (int)size; } -static cJSON* get_array_item(const cJSON *array, size_t index) +static cJSON *get_array_item(const cJSON *array, size_t index) { cJSON *current_child = NULL; @@ -1858,6 +2057,7 @@ static cJSON* get_array_item(const cJSON *array, size_t index) } current_child = array->child; + while ((current_child != NULL) && (index > 0)) { index--; @@ -1877,7 +2077,8 @@ CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index) return get_array_item(array, (size_t)index); } -static cJSON *get_object_item(const cJSON * const object, const char * const name, const cJSON_bool case_sensitive) +static cJSON *get_object_item(const cJSON *const object, const char *const name, + const cJSON_bool case_sensitive) { cJSON *current_element = NULL; @@ -1887,39 +2088,47 @@ static cJSON *get_object_item(const cJSON * const object, const char * const nam } current_element = object->child; + if (case_sensitive) { - while ((current_element != NULL) && (current_element->string != NULL) && (strcmp(name, current_element->string) != 0)) + while ((current_element != NULL) && (current_element->string != NULL) + && (strcmp(name, current_element->string) != 0)) { current_element = current_element->next; } } else { - while ((current_element != NULL) && (case_insensitive_strcmp((const unsigned char*)name, (const unsigned char*)(current_element->string)) != 0)) + while ((current_element != NULL) + && (case_insensitive_strcmp((const unsigned char *)name, + (const unsigned char *)(current_element->string)) != 0)) { current_element = current_element->next; } } - if ((current_element == NULL) || (current_element->string == NULL)) { + if ((current_element == NULL) || (current_element->string == NULL)) + { return NULL; } return current_element; } -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string) +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON *const object, + const char *const string) { return get_object_item(object, string, false); } -CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string) +CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON *const + object, const char *const string) { return get_object_item(object, string, true); } -CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string) +CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, + const char *string) { return cJSON_GetObjectItem(object, string) ? 1 : 0; } @@ -1932,15 +2141,18 @@ static void suffix_object(cJSON *prev, cJSON *item) } /* Utility for handling references. */ -static cJSON *create_reference(const cJSON *item, const internal_hooks * const hooks) +static cJSON *create_reference(const cJSON *item, + const internal_hooks *const hooks) { cJSON *reference = NULL; + if (item == NULL) { return NULL; } reference = cJSON_New_Item(hooks); + if (reference == NULL) { return NULL; @@ -1963,6 +2175,7 @@ static cJSON_bool add_item_to_array(cJSON *array, cJSON *item) } child = array->child; + /* * To find the last item in array quickly, we use prev in array */ @@ -1993,22 +2206,24 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item) } #if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) - #pragma GCC diagnostic push +#pragma GCC diagnostic push #endif #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wcast-qual" #endif /* helper function to cast away const */ -static void* cast_away_const(const void* string) +static void *cast_away_const(const void *string) { - return (void*)string; + return (void *)string; } #if defined(__clang__) || (defined(__GNUC__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 5)))) - #pragma GCC diagnostic pop +#pragma GCC diagnostic pop #endif -static cJSON_bool add_item_to_object(cJSON * const object, const char * const string, cJSON * const item, const internal_hooks * const hooks, const cJSON_bool constant_key) +static cJSON_bool add_item_to_object(cJSON *const object, + const char *const string, cJSON *const item, const internal_hooks *const hooks, + const cJSON_bool constant_key) { char *new_key = NULL; int new_type = cJSON_Invalid; @@ -2020,12 +2235,13 @@ static cJSON_bool add_item_to_object(cJSON * const object, const char * const st if (constant_key) { - new_key = (char*)cast_away_const(string); + new_key = (char *)cast_away_const(string); new_type = item->type | cJSON_StringIsConst; } else { - new_key = (char*)cJSON_strdup((const unsigned char*)string, hooks); + new_key = (char *)cJSON_strdup((const unsigned char *)string, hooks); + if (new_key == NULL) { return false; @@ -2045,18 +2261,21 @@ static cJSON_bool add_item_to_object(cJSON * const object, const char * const st return add_item_to_array(object, item); } -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item) +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, + const char *string, cJSON *item) { return add_item_to_object(object, string, item, &global_hooks, false); } /* Add an item to an object with constant string as key */ -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item) +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, + const char *string, cJSON *item) { return add_item_to_object(object, string, item, &global_hooks, true); } -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, + cJSON *item) { if (array == NULL) { @@ -2066,19 +2285,23 @@ CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item return add_item_to_array(array, create_reference(item, &global_hooks)); } -CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item) +CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, + const char *string, cJSON *item) { if ((object == NULL) || (string == NULL)) { return false; } - return add_item_to_object(object, string, create_reference(item, &global_hooks), &global_hooks, false); + return add_item_to_object(object, string, create_reference(item, &global_hooks), + &global_hooks, false); } -CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name) +CJSON_PUBLIC(cJSON *) cJSON_AddNullToObject(cJSON *const object, + const char *const name) { cJSON *null = cJSON_CreateNull(); + if (add_item_to_object(object, name, null, &global_hooks, false)) { return null; @@ -2088,9 +2311,11 @@ CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * co return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name) +CJSON_PUBLIC(cJSON *) cJSON_AddTrueToObject(cJSON *const object, + const char *const name) { cJSON *true_item = cJSON_CreateTrue(); + if (add_item_to_object(object, name, true_item, &global_hooks, false)) { return true_item; @@ -2100,9 +2325,11 @@ CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * co return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name) +CJSON_PUBLIC(cJSON *) cJSON_AddFalseToObject(cJSON *const object, + const char *const name) { cJSON *false_item = cJSON_CreateFalse(); + if (add_item_to_object(object, name, false_item, &global_hooks, false)) { return false_item; @@ -2112,9 +2339,11 @@ CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * c return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean) +CJSON_PUBLIC(cJSON *) cJSON_AddBoolToObject(cJSON *const object, + const char *const name, const cJSON_bool boolean) { cJSON *bool_item = cJSON_CreateBool(boolean); + if (add_item_to_object(object, name, bool_item, &global_hooks, false)) { return bool_item; @@ -2124,9 +2353,11 @@ CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * co return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number) +CJSON_PUBLIC(cJSON *) cJSON_AddNumberToObject(cJSON *const object, + const char *const name, const double number) { cJSON *number_item = cJSON_CreateNumber(number); + if (add_item_to_object(object, name, number_item, &global_hooks, false)) { return number_item; @@ -2136,9 +2367,11 @@ CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string) +CJSON_PUBLIC(cJSON *) cJSON_AddStringToObject(cJSON *const object, + const char *const name, const char *const string) { cJSON *string_item = cJSON_CreateString(string); + if (add_item_to_object(object, name, string_item, &global_hooks, false)) { return string_item; @@ -2148,9 +2381,11 @@ CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw) +CJSON_PUBLIC(cJSON *) cJSON_AddRawToObject(cJSON *const object, + const char *const name, const char *const raw) { cJSON *raw_item = cJSON_CreateRaw(raw); + if (add_item_to_object(object, name, raw_item, &global_hooks, false)) { return raw_item; @@ -2160,9 +2395,11 @@ CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * con return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name) +CJSON_PUBLIC(cJSON *) cJSON_AddObjectToObject(cJSON *const object, + const char *const name) { cJSON *object_item = cJSON_CreateObject(); + if (add_item_to_object(object, name, object_item, &global_hooks, false)) { return object_item; @@ -2172,9 +2409,11 @@ CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * return NULL; } -CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name) +CJSON_PUBLIC(cJSON *) cJSON_AddArrayToObject(cJSON *const object, + const char *const name) { cJSON *array = cJSON_CreateArray(); + if (add_item_to_object(object, name, array, &global_hooks, false)) { return array; @@ -2184,7 +2423,8 @@ CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * c return NULL; } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item) +CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, + cJSON *const item) { if ((parent == NULL) || (item == NULL)) { @@ -2196,6 +2436,7 @@ CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const it /* not the first element */ item->prev->next = item->next; } + if (item->next != NULL) { /* not the last element */ @@ -2235,14 +2476,16 @@ CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which) cJSON_Delete(cJSON_DetachItemFromArray(array, which)); } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string) +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, + const char *string) { cJSON *to_detach = cJSON_GetObjectItem(object, string); return cJSON_DetachItemViaPointer(object, to_detach); } -CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string) +CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, + const char *string) { cJSON *to_detach = cJSON_GetObjectItemCaseSensitive(object, string); @@ -2254,13 +2497,15 @@ CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string) cJSON_Delete(cJSON_DetachItemFromObject(object, string)); } -CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string) +CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, + const char *string) { cJSON_Delete(cJSON_DetachItemFromObjectCaseSensitive(object, string)); } /* Replace array/object items with new ones. */ -CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem) +CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, + cJSON *newitem) { cJSON *after_inserted = NULL; @@ -2270,6 +2515,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON } after_inserted = get_array_item(array, (size_t)which); + if (after_inserted == NULL) { return add_item_to_array(array, newitem); @@ -2278,6 +2524,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON newitem->next = after_inserted; newitem->prev = after_inserted->prev; after_inserted->prev = newitem; + if (after_inserted == array->child) { array->child = newitem; @@ -2286,10 +2533,12 @@ CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON { newitem->prev->next = newitem; } + return true; } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON *const parent, + cJSON *const item, cJSON *replacement) { if ((parent == NULL) || (replacement == NULL) || (item == NULL)) { @@ -2308,16 +2557,19 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON { replacement->next->prev = replacement; } + if (parent->child == item) { if (parent->child->prev == parent->child) { replacement->prev = replacement; } + parent->child = replacement; } else - { /* + { + /* * To find the last item in array quickly, we use prev in array. * We can't modify the last item's next pointer where this item was the parent's child */ @@ -2325,6 +2577,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON { replacement->prev->next = replacement; } + if (replacement->next == NULL) { parent->child->prev = replacement; @@ -2338,17 +2591,20 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON return true; } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, + cJSON *newitem) { if (which < 0) { return false; } - return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), newitem); + return cJSON_ReplaceItemViaPointer(array, get_array_item(array, (size_t)which), + newitem); } -static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSON *replacement, cJSON_bool case_sensitive) +static cJSON_bool replace_item_in_object(cJSON *object, const char *string, + cJSON *replacement, cJSON_bool case_sensitive) { if ((replacement == NULL) || (string == NULL)) { @@ -2360,7 +2616,10 @@ static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSO { cJSON_free(replacement->string); } - replacement->string = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); + + replacement->string = (char *)cJSON_strdup((const unsigned char *)string, + &global_hooks); + if (replacement->string == NULL) { return false; @@ -2368,15 +2627,18 @@ static cJSON_bool replace_item_in_object(cJSON *object, const char *string, cJSO replacement->type &= ~cJSON_StringIsConst; - return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, case_sensitive), replacement); + return cJSON_ReplaceItemViaPointer(object, get_object_item(object, string, + case_sensitive), replacement); } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, const char *string, cJSON *newitem) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object, + const char *string, cJSON *newitem) { return replace_item_in_object(object, string, newitem, false); } -CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, const char *string, cJSON *newitem) +CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, + const char *string, cJSON *newitem) { return replace_item_in_object(object, string, newitem, true); } @@ -2385,7 +2647,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object, c CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + + if (item) { item->type = cJSON_NULL; } @@ -2396,7 +2659,8 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void) CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + + if (item) { item->type = cJSON_True; } @@ -2407,7 +2671,8 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void) CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + + if (item) { item->type = cJSON_False; } @@ -2418,7 +2683,8 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void) CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + + if (item) { item->type = boolean ? cJSON_True : cJSON_False; } @@ -2429,7 +2695,8 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean) CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + + if (item) { item->type = cJSON_Number; item->valuedouble = num; @@ -2455,11 +2722,14 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num) CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + + if (item) { item->type = cJSON_String; - item->valuestring = (char*)cJSON_strdup((const unsigned char*)string, &global_hooks); - if(!item->valuestring) + item->valuestring = (char *)cJSON_strdup((const unsigned char *)string, + &global_hooks); + + if (!item->valuestring) { cJSON_Delete(item); return NULL; @@ -2472,10 +2742,11 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string) CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) { cJSON *item = cJSON_New_Item(&global_hooks); + if (item != NULL) { item->type = cJSON_String | cJSON_IsReference; - item->valuestring = (char*)cast_away_const(string); + item->valuestring = (char *)cast_away_const(string); } return item; @@ -2484,19 +2755,24 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string) CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child) { cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { + + if (item != NULL) + { item->type = cJSON_Object | cJSON_IsReference; - item->child = (cJSON*)cast_away_const(child); + item->child = (cJSON *)cast_away_const(child); } return item; } -CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { +CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) +{ cJSON *item = cJSON_New_Item(&global_hooks); - if (item != NULL) { + + if (item != NULL) + { item->type = cJSON_Array | cJSON_IsReference; - item->child = (cJSON*)cast_away_const(child); + item->child = (cJSON *)cast_away_const(child); } return item; @@ -2505,11 +2781,14 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child) { CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + + if (item) { item->type = cJSON_Raw; - item->valuestring = (char*)cJSON_strdup((const unsigned char*)raw, &global_hooks); - if(!item->valuestring) + item->valuestring = (char *)cJSON_strdup((const unsigned char *)raw, + &global_hooks); + + if (!item->valuestring) { cJSON_Delete(item); return NULL; @@ -2522,9 +2801,10 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw) CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) { cJSON *item = cJSON_New_Item(&global_hooks); - if(item) + + if (item) { - item->type=cJSON_Array; + item->type = cJSON_Array; } return item; @@ -2533,6 +2813,7 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void) CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void) { cJSON *item = cJSON_New_Item(&global_hooks); + if (item) { item->type = cJSON_Object; @@ -2556,15 +2837,17 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) a = cJSON_CreateArray(); - for(i = 0; a && (i < (size_t)count); i++) + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) + + if (!i) { a->child = n; } @@ -2572,10 +2855,12 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count) { suffix_object(p, n); } + p = n; } - if (a && a->child) { + if (a && a->child) + { a->child->prev = n; } @@ -2596,15 +2881,17 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) a = cJSON_CreateArray(); - for(i = 0; a && (i < (size_t)count); i++) + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber((double)numbers[i]); - if(!n) + + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) + + if (!i) { a->child = n; } @@ -2612,10 +2899,12 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count) { suffix_object(p, n); } + p = n; } - if (a && a->child) { + if (a && a->child) + { a->child->prev = n; } @@ -2636,15 +2925,17 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) a = cJSON_CreateArray(); - for(i = 0; a && (i < (size_t)count); i++) + for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateNumber(numbers[i]); - if(!n) + + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) + + if (!i) { a->child = n; } @@ -2652,17 +2943,20 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count) { suffix_object(p, n); } + p = n; } - if (a && a->child) { + if (a && a->child) + { a->child->prev = n; } return a; } -CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count) +CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, + int count) { size_t i = 0; cJSON *n = NULL; @@ -2679,23 +2973,27 @@ CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int co for (i = 0; a && (i < (size_t)count); i++) { n = cJSON_CreateString(strings[i]); - if(!n) + + if (!n) { cJSON_Delete(a); return NULL; } - if(!i) + + if (!i) { a->child = n; } else { - suffix_object(p,n); + suffix_object(p, n); } + p = n; } - if (a && a->child) { + if (a && a->child) + { a->child->prev = n; } @@ -2715,46 +3013,61 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) { goto fail; } + /* Create new item */ newitem = cJSON_New_Item(&global_hooks); + if (!newitem) { goto fail; } + /* Copy over all vars */ newitem->type = item->type & (~cJSON_IsReference); newitem->valueint = item->valueint; newitem->valuedouble = item->valuedouble; + if (item->valuestring) { - newitem->valuestring = (char*)cJSON_strdup((unsigned char*)item->valuestring, &global_hooks); + newitem->valuestring = (char *)cJSON_strdup((unsigned char *)item->valuestring, + &global_hooks); + if (!newitem->valuestring) { goto fail; } } + if (item->string) { - newitem->string = (item->type&cJSON_StringIsConst) ? item->string : (char*)cJSON_strdup((unsigned char*)item->string, &global_hooks); + newitem->string = (item->type & cJSON_StringIsConst) ? item->string : + (char *)cJSON_strdup((unsigned char *)item->string, &global_hooks); + if (!newitem->string) { goto fail; } } + /* If non-recursive, then we're done! */ if (!recurse) { return newitem; } + /* Walk the ->next chain for the child. */ child = item->child; + while (child != NULL) { - newchild = cJSON_Duplicate(child, true); /* Duplicate (with recurse) each item in the ->next chain */ + newchild = cJSON_Duplicate(child, + true); /* Duplicate (with recurse) each item in the ->next chain */ + if (!newchild) { goto fail; } + if (next != NULL) { /* If newitem->child already set, then crosswire ->prev and ->next and move on */ @@ -2768,8 +3081,10 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) newitem->child = newchild; next = newchild; } + child = child->next; } + if (newitem && newitem->child) { newitem->child->prev = newchild; @@ -2778,6 +3093,7 @@ CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse) return newitem; fail: + if (newitem != NULL) { cJSON_Delete(newitem); @@ -2792,7 +3108,8 @@ static void skip_oneline_comment(char **input) for (; (*input)[0] != '\0'; ++(*input)) { - if ((*input)[0] == '\n') { + if ((*input)[0] == '\n') + { *input += static_strlen("\n"); return; } @@ -2813,21 +3130,26 @@ static void skip_multiline_comment(char **input) } } -static void minify_string(char **input, char **output) { +static void minify_string(char **input, char **output) +{ (*output)[0] = (*input)[0]; *input += static_strlen("\""); *output += static_strlen("\""); - for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) { + for (; (*input)[0] != '\0'; (void)++(*input), ++(*output)) + { (*output)[0] = (*input)[0]; - if ((*input)[0] == '\"') { + if ((*input)[0] == '\"') + { (*output)[0] = '\"'; *input += static_strlen("\""); *output += static_strlen("\""); return; - } else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) { + } + else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) + { (*output)[1] = (*input)[1]; *input += static_strlen("\""); *output += static_strlen("\""); @@ -2848,34 +3170,37 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json) { switch (json[0]) { - case ' ': - case '\t': - case '\r': - case '\n': + case ' ': + case '\t': + case '\r': + case '\n': + json++; + break; + + case '/': + if (json[1] == '/') + { + skip_oneline_comment(&json); + } + else if (json[1] == '*') + { + skip_multiline_comment(&json); + } + else + { json++; - break; + } - case '/': - if (json[1] == '/') - { - skip_oneline_comment(&json); - } - else if (json[1] == '*') - { - skip_multiline_comment(&json); - } else { - json++; - } - break; + break; - case '\"': - minify_string(&json, (char**)&into); - break; + case '\"': + minify_string(&json, (char **)&into); + break; - default: - into[0] = json[0]; - json++; - into++; + default: + into[0] = json[0]; + json++; + into++; } } @@ -2883,7 +3208,7 @@ CJSON_PUBLIC(void) cJSON_Minify(char *json) *into = '\0'; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON *const item) { if (item == NULL) { @@ -2893,7 +3218,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item) return (item->type & 0xFF) == cJSON_Invalid; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON *const item) { if (item == NULL) { @@ -2903,7 +3228,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item) return (item->type & 0xFF) == cJSON_False; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON *const item) { if (item == NULL) { @@ -2914,7 +3239,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item) } -CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON *const item) { if (item == NULL) { @@ -2923,7 +3248,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item) return (item->type & (cJSON_True | cJSON_False)) != 0; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON *const item) { if (item == NULL) { @@ -2933,7 +3258,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item) return (item->type & 0xFF) == cJSON_NULL; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON *const item) { if (item == NULL) { @@ -2943,7 +3268,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item) return (item->type & 0xFF) == cJSON_Number; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON *const item) { if (item == NULL) { @@ -2953,7 +3278,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item) return (item->type & 0xFF) == cJSON_String; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON *const item) { if (item == NULL) { @@ -2963,7 +3288,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item) return (item->type & 0xFF) == cJSON_Array; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON *const item) { if (item == NULL) { @@ -2973,7 +3298,7 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item) return (item->type & 0xFF) == cJSON_Object; } -CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) +CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON *const item) { if (item == NULL) { @@ -2983,7 +3308,8 @@ CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item) return (item->type & 0xFF) == cJSON_Raw; } -CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive) +CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON *const a, + const cJSON *const b, const cJSON_bool case_sensitive) { if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) { @@ -2993,18 +3319,18 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons /* check if type is valid */ switch (a->type & 0xFF) { - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - case cJSON_Number: - case cJSON_String: - case cJSON_Raw: - case cJSON_Array: - case cJSON_Object: - break; + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + case cJSON_Number: + case cJSON_String: + case cJSON_Raw: + case cJSON_Array: + case cJSON_Object: + break; - default: - return false; + default: + return false; } /* identical objects are equal */ @@ -3015,96 +3341,101 @@ CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * cons switch (a->type & 0xFF) { - /* in these cases and equal type is enough */ - case cJSON_False: - case cJSON_True: - case cJSON_NULL: - return true; + /* in these cases and equal type is enough */ + case cJSON_False: + case cJSON_True: + case cJSON_NULL: + return true; - case cJSON_Number: - if (compare_double(a->valuedouble, b->valuedouble)) - { - return true; - } - return false; - - case cJSON_String: - case cJSON_Raw: - if ((a->valuestring == NULL) || (b->valuestring == NULL)) - { - return false; - } - if (strcmp(a->valuestring, b->valuestring) == 0) - { - return true; - } - - return false; - - case cJSON_Array: + case cJSON_Number: + if (compare_double(a->valuedouble, b->valuedouble)) { - cJSON *a_element = a->child; - cJSON *b_element = b->child; - - for (; (a_element != NULL) && (b_element != NULL);) - { - if (!cJSON_Compare(a_element, b_element, case_sensitive)) - { - return false; - } - - a_element = a_element->next; - b_element = b_element->next; - } - - /* one of the arrays is longer than the other */ - if (a_element != b_element) { - return false; - } - return true; } - case cJSON_Object: + return false; + + case cJSON_String: + case cJSON_Raw: + if ((a->valuestring == NULL) || (b->valuestring == NULL)) { - cJSON *a_element = NULL; - cJSON *b_element = NULL; - cJSON_ArrayForEach(a_element, a) - { - /* TODO This has O(n^2) runtime, which is horrible! */ - b_element = get_object_item(b, a_element->string, case_sensitive); - if (b_element == NULL) - { - return false; - } - - if (!cJSON_Compare(a_element, b_element, case_sensitive)) - { - return false; - } - } - - /* doing this twice, once on a and b to prevent true comparison if a subset of b - * TODO: Do this the proper way, this is just a fix for now */ - cJSON_ArrayForEach(b_element, b) - { - a_element = get_object_item(a, b_element->string, case_sensitive); - if (a_element == NULL) - { - return false; - } - - if (!cJSON_Compare(b_element, a_element, case_sensitive)) - { - return false; - } - } + return false; + } + if (strcmp(a->valuestring, b->valuestring) == 0) + { return true; } - default: + return false; + + case cJSON_Array: + { + cJSON *a_element = a->child; + cJSON *b_element = b->child; + + for (; (a_element != NULL) && (b_element != NULL);) + { + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + + a_element = a_element->next; + b_element = b_element->next; + } + + /* one of the arrays is longer than the other */ + if (a_element != b_element) + { return false; + } + + return true; + } + + case cJSON_Object: + { + cJSON *a_element = NULL; + cJSON *b_element = NULL; + cJSON_ArrayForEach(a_element, a) + { + /* TODO This has O(n^2) runtime, which is horrible! */ + b_element = get_object_item(b, a_element->string, case_sensitive); + + if (b_element == NULL) + { + return false; + } + + if (!cJSON_Compare(a_element, b_element, case_sensitive)) + { + return false; + } + } + + /* doing this twice, once on a and b to prevent true comparison if a subset of b + * TODO: Do this the proper way, this is just a fix for now */ + cJSON_ArrayForEach(b_element, b) + { + a_element = get_object_item(a, b_element->string, case_sensitive); + + if (a_element == NULL) + { + return false; + } + + if (!cJSON_Compare(b_element, a_element, case_sensitive)) + { + return false; + } + } + + return true; + } + + default: + return false; } } diff --git a/lib/precise_time.c b/lib/precise_time.c index b8c66f07a..bcd882233 100644 --- a/lib/precise_time.c +++ b/lib/precise_time.c @@ -2,7 +2,7 @@ // precise_time.cxx // // Copyright (C) 2023 -// Dave Freese, W1HKJ +// Dave Freese, W1HKJ // // This file is part of flrig // @@ -28,9 +28,9 @@ // return current tick time in seconds double monotonic_seconds() { - static struct timeval t1; - gettimeofday(&t1, NULL); - return t1.tv_sec + t1.tv_usec / 1e6; + static struct timeval t1; + gettimeofday(&t1, NULL); + return t1.tv_sec + t1.tv_usec / 1e6; } #else @@ -49,118 +49,132 @@ double monotonic_seconds() static int showme = 0; #if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK) - // If we have it, use clock_gettime and CLOCK_MONOTONIC. +// If we have it, use clock_gettime and CLOCK_MONOTONIC. - #include +#include - double monotonic_seconds() { - if (showme) { - showme = 0; - } - struct timespec time; - // Note: Make sure to link with -lrt to define clock_gettime. - clock_gettime(CLOCK_MONOTONIC, &time); - return ((double) time.tv_sec) + ((double) time.tv_nsec / (NANOS_PER_SECF)); - } +double monotonic_seconds() +{ + if (showme) + { + showme = 0; + } + + struct timespec time; + + // Note: Make sure to link with -lrt to define clock_gettime. + clock_gettime(CLOCK_MONOTONIC, &time); + + return ((double) time.tv_sec) + ((double) time.tv_nsec / (NANOS_PER_SECF)); +} #elif defined(__APPLE__) - // If we don't have CLOCK_MONOTONIC, we might be on a Mac. There we instead - // use mach_absolute_time(). +// If we don't have CLOCK_MONOTONIC, we might be on a Mac. There we instead +// use mach_absolute_time(). - #include +#include - static mach_timebase_info_data_t info; - static void __attribute__((constructor)) init_info() { - mach_timebase_info(&info); - } +static mach_timebase_info_data_t info; +static void __attribute__((constructor)) init_info() +{ + mach_timebase_info(&info); +} - double monotonic_seconds() { - uint64_t time = mach_absolute_time(); - double dtime = (double) time; - dtime *= (double) info.numer; - dtime /= (double) info.denom; - return dtime / NANOS_PER_SECF; - } +double monotonic_seconds() +{ + uint64_t time = mach_absolute_time(); + double dtime = (double) time; + dtime *= (double) info.numer; + dtime /= (double) info.denom; + return dtime / NANOS_PER_SECF; +} #elif defined(__WIN32__) - // On Windows, use QueryPerformanceCounter and QueryPerformanceFrequency. +// On Windows, use QueryPerformanceCounter and QueryPerformanceFrequency. - #include +#include - static double PCFreq = 0.0; +static double PCFreq = 0.0; - // According to http://stackoverflow.com/q/1113409/447288, this will - // make this function a constructor. - // TODO(awreece) Actually attempt to compile on windows. - // w1hkj - builds OK on mingw32 +// According to http://stackoverflow.com/q/1113409/447288, this will +// make this function a constructor. +// TODO(awreece) Actually attempt to compile on windows. +// w1hkj - builds OK on mingw32 - static void __cdecl init_pcfreq(); - __declspec(allocate(".CRT$XCU")) void (__cdecl*init_pcfreq_)() = init_pcfreq; - static void __cdecl init_pcfreq() { - // Accoring to http://stackoverflow.com/a/1739265/447288, this will - // properly initialize the QueryPerformanceCounter. - LARGE_INTEGER li; - int has_qpc = QueryPerformanceFrequency(&li); - assert(has_qpc); +static void __cdecl init_pcfreq(); +__declspec(allocate(".CRT$XCU")) void (__cdecl *init_pcfreq_)() = init_pcfreq; +static void __cdecl init_pcfreq() +{ + // Accoring to http://stackoverflow.com/a/1739265/447288, this will + // properly initialize the QueryPerformanceCounter. + LARGE_INTEGER li; + int has_qpc = QueryPerformanceFrequency(&li); + assert(has_qpc); - PCFreq = ((double) li.QuadPart) / 1000.0; - } + PCFreq = ((double) li.QuadPart) / 1000.0; +} - double monotonic_seconds() { - LARGE_INTEGER li; - QueryPerformanceCounter(&li); - return ((double) li.QuadPart) / PCFreq; - } +double monotonic_seconds() +{ + LARGE_INTEGER li; + QueryPerformanceCounter(&li); + return ((double) li.QuadPart) / PCFreq; +} #else - // Fall back to rdtsc. The reason we don't use clock() is this scary message - // from the man page: - // "On several other implementations, the value returned by clock() also - // includes the times of any children whose status has been collected via - // wait(2) (or another wait-type call)." - // - // Also, clock() only has microsecond accuracy. - // - // This whitepaper offered excellent advice on how to use rdtscp for - // profiling: http://download.intel.com/embedded/software/IA/324264.pdf - // - // Unfortunately, we can't follow its advice exactly with our semantics, - // so we're just going to use rdtscp with cpuid. - // - // Note that rdtscp will only be available on new processors. +// Fall back to rdtsc. The reason we don't use clock() is this scary message +// from the man page: +// "On several other implementations, the value returned by clock() also +// includes the times of any children whose status has been collected via +// wait(2) (or another wait-type call)." +// +// Also, clock() only has microsecond accuracy. +// +// This whitepaper offered excellent advice on how to use rdtscp for +// profiling: http://download.intel.com/embedded/software/IA/324264.pdf +// +// Unfortunately, we can't follow its advice exactly with our semantics, +// so we're just going to use rdtscp with cpuid. +// +// Note that rdtscp will only be available on new processors. - #include +#include - static inline uint64_t rdtsc() { - uint32_t hi, lo; - uint64_t hi64, lo64; - asm volatile("rdtscp\n" - "movl %%edx, %0\n" - "movl %%eax, %1\n" - "cpuid" - : "=r" (hi), "=r" (lo) : : "%rax", "%rbx", "%rcx", "%rdx"); - hi64 = hi; - lo64 = lo; - return (hi64 << 32) | lo64; - } +static inline uint64_t rdtsc() +{ + uint32_t hi, lo; + uint64_t hi64, lo64; + asm volatile("rdtscp\n" + "movl %%edx, %0\n" + "movl %%eax, %1\n" + "cpuid" + : "=r"(hi), "=r"(lo) : : "%rax", "%rbx", "%rcx", "%rdx"); + hi64 = hi; + lo64 = lo; + return (hi64 << 32) | lo64; +} - static uint64_t rdtsc_per_sec = 0; - static void __attribute__((constructor)) init_rdtsc_per_sec() { - uint64_t before, after; +static uint64_t rdtsc_per_sec = 0; +static void __attribute__((constructor)) init_rdtsc_per_sec() +{ + uint64_t before, after; - before = rdtsc(); - usleep(USECS_PER_SEC); - after = rdtsc(); + before = rdtsc(); + usleep(USECS_PER_SEC); + after = rdtsc(); - rdtsc_per_sec = after - before; - } + rdtsc_per_sec = after - before; +} - double monotonic_seconds() { - if (showme) { - showme = false; - } - return (double) rdtsc() / (double) rdtsc_per_sec; - } +double monotonic_seconds() +{ + if (showme) + { + showme = false; + } + + return (double) rdtsc() / (double) rdtsc_per_sec; +} #endif diff --git a/rigs/adat/adat.c b/rigs/adat/adat.c index a7aa8c00a..8a5cfd583 100644 --- a/rigs/adat/adat.c +++ b/rigs/adat/adat.c @@ -1312,8 +1312,8 @@ int adat_priv_set_cmd(RIG *pRig, char *pcCmd, int nCmdKind) { adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - memset( pPriv->acCmd, 0, ADAT_PRIV_DATA_CMD_LENGTH + 1 ); - snprintf(pPriv->acCmd,ADAT_PRIV_DATA_CMD_LENGTH+1,"%s",pcCmd ); + memset(pPriv->acCmd, 0, ADAT_PRIV_DATA_CMD_LENGTH + 1); + snprintf(pPriv->acCmd, ADAT_PRIV_DATA_CMD_LENGTH + 1, "%s", pcCmd); pPriv->nCmdKind = nCmdKind; } @@ -1351,8 +1351,8 @@ int adat_priv_set_result(RIG *pRig, char *pcResult) { adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - memset( pPriv->acResult, 0, ADAT_PRIV_DATA_RESULT_LENGTH + 1 ); - snprintf(pPriv->acResult,ADAT_PRIV_DATA_RESULT_LENGTH+1,"%s",pcResult ); + memset(pPriv->acResult, 0, ADAT_PRIV_DATA_RESULT_LENGTH + 1); + snprintf(pPriv->acResult, ADAT_PRIV_DATA_RESULT_LENGTH + 1, "%s", pcResult); rig_debug(RIG_DEBUG_TRACE, "*** ADAT: %d pPriv->acResult = \"%s\"\n", @@ -1392,7 +1392,7 @@ int adat_priv_clear_result(RIG *pRig) else { adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - memset( pPriv->acResult, 0, ADAT_PRIV_DATA_RESULT_LENGTH + 1 ); + memset(pPriv->acResult, 0, ADAT_PRIV_DATA_RESULT_LENGTH + 1); } // Done ! @@ -1631,8 +1631,9 @@ int adat_cmd_fn_get_callsign(RIG *pRig) if (nRC == RIG_OK) { - memset( pPriv->acCallsign, 0, ADAT_PRIV_DATA_CALLSIGN_LENGTH + 1 ); - snprintf(pPriv->acCallsign,ADAT_PRIV_DATA_CALLSIGN_LENGTH+1,"%s",pPriv->acResult ); + memset(pPriv->acCallsign, 0, ADAT_PRIV_DATA_CALLSIGN_LENGTH + 1); + snprintf(pPriv->acCallsign, ADAT_PRIV_DATA_CALLSIGN_LENGTH + 1, "%s", + pPriv->acResult); rig_debug(RIG_DEBUG_TRACE, "*** ADAT: %d pPriv->acCallsign = \"%s\"\n", @@ -1684,8 +1685,9 @@ int adat_cmd_fn_get_serial_nr(RIG *pRig) if (nRC == RIG_OK) { - memset( pPriv->acSerialNr, 0, ADAT_PRIV_DATA_SERIALNR_LENGTH + 1 ); - snprintf(pPriv->acSerialNr,ADAT_PRIV_DATA_SERIALNR_LENGTH+1,"%s",pPriv->acResult ); + memset(pPriv->acSerialNr, 0, ADAT_PRIV_DATA_SERIALNR_LENGTH + 1); + snprintf(pPriv->acSerialNr, ADAT_PRIV_DATA_SERIALNR_LENGTH + 1, "%s", + pPriv->acResult); rig_debug(RIG_DEBUG_TRACE, "*** ADAT: %d pPriv->acSerialNr = \"%s\"\n", @@ -1737,8 +1739,9 @@ int adat_cmd_fn_get_fw_version(RIG *pRig) if (nRC == RIG_OK) { - memset( pPriv->acFWVersion, 0, ADAT_PRIV_DATA_FWVERSION_LENGTH + 1 ); - snprintf(pPriv->acFWVersion,ADAT_PRIV_DATA_FWVERSION_LENGTH+1,"%s",pPriv->acResult ); + memset(pPriv->acFWVersion, 0, ADAT_PRIV_DATA_FWVERSION_LENGTH + 1); + snprintf(pPriv->acFWVersion, ADAT_PRIV_DATA_FWVERSION_LENGTH + 1, "%s", + pPriv->acResult); rig_debug(RIG_DEBUG_TRACE, "*** ADAT: %d pPriv->acFWVersion = \"%s\"\n", @@ -1791,8 +1794,9 @@ int adat_cmd_fn_get_hw_version(RIG *pRig) if (nRC == RIG_OK) { - memset( pPriv->acHWVersion, 0, ADAT_PRIV_DATA_HWVERSION_LENGTH + 1 ); - snprintf(pPriv->acHWVersion,ADAT_PRIV_DATA_HWVERSION_LENGTH+1,"%s",pPriv->acResult ); + memset(pPriv->acHWVersion, 0, ADAT_PRIV_DATA_HWVERSION_LENGTH + 1); + snprintf(pPriv->acHWVersion, ADAT_PRIV_DATA_HWVERSION_LENGTH + 1, "%s", + pPriv->acResult); rig_debug(RIG_DEBUG_TRACE, "*** ADAT: %d pPriv->acHWVersion = \"%s\"\n", @@ -1844,8 +1848,9 @@ int adat_cmd_fn_get_gui_fw_version(RIG *pRig) if (nRC == RIG_OK) { - memset( pPriv->acGUIFWVersion, 0, ADAT_PRIV_DATA_GUIFWVERSION_LENGTH + 1 ); - snprintf(pPriv->acGUIFWVersion,ADAT_PRIV_DATA_GUIFWVERSION_LENGTH+1,"%s",pPriv->acResult ); + memset(pPriv->acGUIFWVersion, 0, ADAT_PRIV_DATA_GUIFWVERSION_LENGTH + 1); + snprintf(pPriv->acGUIFWVersion, ADAT_PRIV_DATA_GUIFWVERSION_LENGTH + 1, "%s", + pPriv->acResult); rig_debug(RIG_DEBUG_TRACE, "*** ADAT: %d pPriv->acGUIFWVersion = \"%s\"\n", @@ -1898,8 +1903,9 @@ int adat_cmd_fn_get_id_code(RIG *pRig) if (nRC == RIG_OK) { - memset( pPriv->acIDCode, 0, ADAT_PRIV_DATA_IDCODE_LENGTH + 1 ); - snprintf(pPriv->acIDCode,ADAT_PRIV_DATA_IDCODE_LENGTH+1,"%s",pPriv->acResult ); + memset(pPriv->acIDCode, 0, ADAT_PRIV_DATA_IDCODE_LENGTH + 1); + snprintf(pPriv->acIDCode, ADAT_PRIV_DATA_IDCODE_LENGTH + 1, "%s", + pPriv->acResult); rig_debug(RIG_DEBUG_TRACE, "*** ADAT: %d pPriv->acIDCode = \"%s\"\n", @@ -1951,8 +1957,9 @@ int adat_cmd_fn_get_options(RIG *pRig) if (nRC == RIG_OK) { - memset( pPriv->acOptions, 0, ADAT_PRIV_DATA_OPTIONS_LENGTH + 1 ); - snprintf(pPriv->acOptions,ADAT_PRIV_DATA_OPTIONS_LENGTH+1,"%s",pPriv->acResult ); + memset(pPriv->acOptions, 0, ADAT_PRIV_DATA_OPTIONS_LENGTH + 1); + snprintf(pPriv->acOptions, ADAT_PRIV_DATA_OPTIONS_LENGTH + 1, "%s", + pPriv->acResult); rig_debug(RIG_DEBUG_TRACE, "*** ADAT: %d pPriv->acOptions = \"%s\"\n", @@ -2056,7 +2063,7 @@ int adat_cmd_fn_set_mode(RIG *pRig) memset(acBuf, 0, ADAT_BUFSZ + 1); - snprintf(acBuf,sizeof(acBuf),"%s%02d%s", + snprintf(acBuf, sizeof(acBuf), "%s%02d%s", ADAT_CMD_DEF_STRING_SET_MODE, (int) pPriv->nADATMode, ADAT_EOM); @@ -2173,7 +2180,7 @@ int adat_cmd_fn_set_freq(RIG *pRig) memset(acBuf, 0, ADAT_BUFSZ + 1); - snprintf(acBuf,sizeof(acBuf),"%s%d%s", + snprintf(acBuf, sizeof(acBuf), "%s%d%s", ADAT_CMD_DEF_STRING_SET_FREQ, (int) pPriv->nFreq, ADAT_EOM); @@ -2229,7 +2236,7 @@ int adat_cmd_fn_set_vfo(RIG *pRig) memset(acBuf, 0, ADAT_BUFSZ + 1); - snprintf(acBuf,sizeof(acBuf), ADAT_CMD_DEF_STRING_SWITCH_ON_VFO, + snprintf(acBuf, sizeof(acBuf), ADAT_CMD_DEF_STRING_SWITCH_ON_VFO, (int) pPriv->nCurrentVFO, ADAT_EOM); @@ -2242,7 +2249,7 @@ int adat_cmd_fn_set_vfo(RIG *pRig) if (nRC == RIG_OK) { memset(acBuf, 0, ADAT_BUFSZ + 1); - snprintf(acBuf,sizeof(acBuf), + snprintf(acBuf, sizeof(acBuf), ADAT_CMD_DEF_STRING_SET_VFO_AS_MAIN_VFO, (int) pPriv->nCurrentVFO, ADAT_EOM); @@ -2375,7 +2382,7 @@ int adat_cmd_fn_set_ptt(RIG *pRig) { char acBuf[ ADAT_BUFSZ + 1 ]; memset(acBuf, 0, ADAT_BUFSZ + 1); - snprintf(acBuf,sizeof(acBuf),ADAT_CMD_DEF_STRING_SET_PTT, + snprintf(acBuf, sizeof(acBuf), ADAT_CMD_DEF_STRING_SET_PTT, pcPTTStr, ADAT_EOM); @@ -2490,8 +2497,8 @@ int adat_transaction(RIG *pRig, nRC = adat_receive(pRig, acBuf); } - memset( pPriv->acResult, 0, ADAT_PRIV_DATA_RESULT_LENGTH + 1 ); - snprintf(pPriv->acResult,ADAT_PRIV_DATA_RESULT_LENGTH+1,"%s",acBuf); + memset(pPriv->acResult, 0, ADAT_PRIV_DATA_RESULT_LENGTH + 1); + snprintf(pPriv->acResult, ADAT_PRIV_DATA_RESULT_LENGTH + 1, "%s", acBuf); } } @@ -2546,8 +2553,8 @@ int adat_init(RIG *pRig) { // Set Rig Priv data - memset( &gsADATPrivData, 0, sizeof( adat_priv_data_t )); - pRig->state.priv = &gsADATPrivData; + memset(&gsADATPrivData, 0, sizeof(adat_priv_data_t)); + pRig->state.priv = &gsADATPrivData; } // Done ! @@ -2685,10 +2692,10 @@ const char *adat_get_info(RIG *pRig) if (nRC == RIG_OK) { - // cppcheck-suppress constVariablePointer + // cppcheck-suppress constVariablePointer const adat_priv_data_ptr pPriv = (adat_priv_data_ptr) pRig->state.priv; - snprintf(acBuf,2048, + snprintf(acBuf, 2048, "ADAT ADT-200A, Callsign: %s, S/N: %s, ID Code: %s, Options: %s, FW: %s, GUI FW: %s, HW: %s", pPriv->acCallsign, pPriv->acSerialNr, @@ -3271,7 +3278,8 @@ int adat_set_conf(RIG *pRig, token_t token, const char *val) { case TOKEN_ADAT_PRODUCT_NAME: - snprintf(pPriv->acProductName,ADAT_PRIV_DATA_PRODUCTNAME_LENGTH+1,"%s",val ); + snprintf(pPriv->acProductName, ADAT_PRIV_DATA_PRODUCTNAME_LENGTH + 1, "%s", + val); break; default: @@ -3316,10 +3324,15 @@ int adat_get_conf(RIG *pRig, token_t token, char *val) switch (token) { case TOKEN_ADAT_PRODUCT_NAME: - if (strlen(pPriv->acProductName) > 0) - strcpy(val, pPriv->acProductName); - else - strcpy(val,"Unknown product"); + if (strlen(pPriv->acProductName) > 0) + { + strcpy(val, pPriv->acProductName); + } + else + { + strcpy(val, "Unknown product"); + } + break; default: diff --git a/rigs/anytone/anytone.c b/rigs/anytone/anytone.c index 8d0ca06fd..675eb4229 100644 --- a/rigs/anytone/anytone.c +++ b/rigs/anytone/anytone.c @@ -46,7 +46,8 @@ // --------------------------------------------------------------------------- #include "anytone.h" -int anytone_transaction(RIG *rig, unsigned char *cmd, int cmd_len, unsigned char *reply, int reply_len, int expected_len); +int anytone_transaction(RIG *rig, unsigned char *cmd, int cmd_len, + unsigned char *reply, int reply_len, int expected_len); DECLARE_INITRIG_BACKEND(anytone) { @@ -116,7 +117,7 @@ void *anytone_thread(void *vrig) write_block(&rig->state.rigport, (unsigned char *)c, strlen(c)); char buf[32]; - read_block(&rig->state.rigport, (unsigned char*)buf, 22); + read_block(&rig->state.rigport, (unsigned char *)buf, 22); if (rig_need_debug(RIG_DEBUG_CACHE) == 0) { @@ -176,7 +177,8 @@ int anytone_receive(RIG *rig, unsigned char *buf, int buf_len, int expected) // --------------------------------------------------------------------------- // anytone_transaction // --------------------------------------------------------------------------- -int anytone_transaction(RIG *rig, unsigned char *cmd, int cmd_len, unsigned char *reply, int reply_len, int expected_len) +int anytone_transaction(RIG *rig, unsigned char *cmd, int cmd_len, + unsigned char *reply, int reply_len, int expected_len) { int retval = RIG_OK; //anytone_priv_data_t *p = rig->state.priv; @@ -258,7 +260,7 @@ int anytone_open(RIG *rig) ENTERFUNC; - unsigned char cmd[] = { 0x2B,0x41,0x44,0x41,0x54,0x41,0x3A,0x30,0x30,0x2C,0x30,0x30,0x31,0x0d,0x0a,'a',0x0d,0x0a }; + unsigned char cmd[] = { 0x2B, 0x41, 0x44, 0x41, 0x54, 0x41, 0x3A, 0x30, 0x30, 0x2C, 0x30, 0x30, 0x31, 0x0d, 0x0a, 'a', 0x0d, 0x0a }; write_block(&rig->state.rigport, cmd, sizeof(cmd)); hl_usleep(500 * 1000); char cmd2[64]; @@ -266,7 +268,8 @@ int anytone_open(RIG *rig) write_block(&rig->state.rigport, (unsigned char *)cmd2, strlen(cmd2)); SNPRINTF(cmd2, sizeof(cmd2), "+ADATA:00,000\r\n"); unsigned char reply[512]; - anytone_transaction(rig, (unsigned char*)cmd2, strlen(cmd2), reply, sizeof(reply), strlen(cmd2)); + anytone_transaction(rig, (unsigned char *)cmd2, strlen(cmd2), reply, + sizeof(reply), strlen(cmd2)); pthread_t id; // will start the keep alive @@ -291,7 +294,7 @@ int anytone_close(RIG *rig) ENTERFUNC; char *cmd = "+ADATA:00,000\r\n"; - anytone_transaction(rig, (unsigned char*)cmd, strlen(cmd), NULL, 0, 0); + anytone_transaction(rig, (unsigned char *)cmd, strlen(cmd), NULL, 0, 0); RETURNFUNC(retval); } @@ -309,10 +312,11 @@ int anytone_get_vfo(RIG *rig, vfo_t *vfo) const anytone_priv_data_ptr p = (anytone_priv_data_ptr) rig->state.priv; unsigned char reply[512]; - unsigned char cmd[] = { 0x2b,0x41,0x44,0x41,0x54,0x41,0x3a,0x30,0x30,0x2c,0x30,0x30,0x36,0x0d,0x0a,0x04,0x05,0x00,0x00,0x00,0x00,0x0d,0x0a }; + unsigned char cmd[] = { 0x2b, 0x41, 0x44, 0x41, 0x54, 0x41, 0x3a, 0x30, 0x30, 0x2c, 0x30, 0x30, 0x36, 0x0d, 0x0a, 0x04, 0x05, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x0a }; anytone_transaction(rig, cmd, sizeof(cmd), reply, sizeof(reply), 114); - if (reply[113] == 0x9b) *vfo = RIG_VFO_A; - else if (reply[113] == 0x9c) *vfo = RIG_VFO_B; + + if (reply[113] == 0x9b) { *vfo = RIG_VFO_A; } + else if (reply[113] == 0x9c) { *vfo = RIG_VFO_B; } else { *vfo = RIG_VFO_A; // default to VFOA @@ -357,10 +361,11 @@ int anytone_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) ENTERFUNC; //char buf[8] = { 0x41, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x06 }; - unsigned char ptton[] = { 0x2B,0x41,0x44,0x41,0x54,0x41,0x3A,0x30,0x30,0x2C,0x30,0x30,0x31,0x0d,0x0a,0x61,0x0d,0x0a }; - unsigned char pttoff[] = { 0x2B,0x41,0x44,0x41,0x54,0x41,0x3A,0x30,0x30,0x2C,0x30,0x32,0x33,0x0d,0x0a,0x56,0x0d,0x0a }; + unsigned char ptton[] = { 0x2B, 0x41, 0x44, 0x41, 0x54, 0x41, 0x3A, 0x30, 0x30, 0x2C, 0x30, 0x30, 0x31, 0x0d, 0x0a, 0x61, 0x0d, 0x0a }; + unsigned char pttoff[] = { 0x2B, 0x41, 0x44, 0x41, 0x54, 0x41, 0x3A, 0x30, 0x30, 0x2C, 0x30, 0x32, 0x33, 0x0d, 0x0a, 0x56, 0x0d, 0x0a }; void *pttcmd = ptton; - if (!ptt) pttcmd = pttoff; + + if (!ptt) { pttcmd = pttoff; } //if (!ptt) { cmd = " (unsigned char*)+ADATA:00,023\r\nV\r\n"; } @@ -409,6 +414,7 @@ int anytone_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) } } while (retval != 138 && --retry > 0); + MUTEX_UNLOCK(p->priv.mutex); return RIG_OK; @@ -417,19 +423,25 @@ int anytone_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int anytone_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { char cmd[64]; + if (vfo == RIG_VFO_A) - snprintf(cmd, sizeof(cmd), "ADATA:00,005\r\n%c%c%c%c\r\n", 2, 0, 0, 0); + { + snprintf(cmd, sizeof(cmd), "ADATA:00,005\r\n%c%c%c%c\r\n", 2, 0, 0, 0); + } else - snprintf(cmd, sizeof(cmd), "ADATA:00,005\r\n%c%c%c%c\r\n", 1, 0, 0, 0); + { + snprintf(cmd, sizeof(cmd), "ADATA:00,005\r\n%c%c%c%c\r\n", 1, 0, 0, 0); + } + MUTEX_LOCK(p->priv.mutex); rig_flush(&rig->state.rigport); - write_block(&rig->state.rigport, (unsigned char*) cmd, 20); + write_block(&rig->state.rigport, (unsigned char *) cmd, 20); unsigned char backend[] = { 0x2f, 0x03, 0x00, 0xff, 0xff, 0xff, 0xff, 0x15, 0x50, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcf, 0x09, 0x00, 0x00, 0x0d, 0x0a}; snprintf(cmd, sizeof(cmd), "ADATA:00,023\r\n"); int bytes = strlen(cmd) + sizeof(backend); memcpy(&cmd[15], backend, sizeof(backend)); - hl_usleep(10*1000); - write_block(&rig->state.rigport, (unsigned char*)cmd, bytes); + hl_usleep(10 * 1000); + write_block(&rig->state.rigport, (unsigned char *)cmd, bytes); MUTEX_UNLOCK(p->priv.mutex); return -RIG_ENIMPL; diff --git a/rigs/aor/ar3030.c b/rigs/aor/ar3030.c index 572c619d9..ded41f433 100644 --- a/rigs/aor/ar3030.c +++ b/rigs/aor/ar3030.c @@ -356,7 +356,8 @@ int ar3030_set_vfo(RIG *rig, vfo_t vfo) int ar3030_get_vfo(RIG *rig, vfo_t *vfo) { - const struct ar3030_priv_data *priv = (struct ar3030_priv_data *)rig->state.priv; + const struct ar3030_priv_data *priv = (struct ar3030_priv_data *) + rig->state.priv; *vfo = priv->curr_vfo; diff --git a/rigs/aor/ar7030.c b/rigs/aor/ar7030.c index 430e859b4..8ba26838b 100644 --- a/rigs/aor/ar7030.c +++ b/rigs/aor/ar7030.c @@ -190,7 +190,8 @@ static void Execute_Routine_2_1(RIG *rig, char mp, char ad, int numSteps) } #endif // Routine 3 Set passband Setup all IF parameters from filter, pbsval and bfoval bytes. -static void Execute_Routine_3_1(RIG *rig, char mp, char ad, unsigned int numSteps) +static void Execute_Routine_3_1(RIG *rig, char mp, char ad, + unsigned int numSteps) { setLock(rig, 1); //Set Lock Level setMemPtr(rig, mp, ad); //page, address diff --git a/rigs/aor/ar7030p.c b/rigs/aor/ar7030p.c index a6d33cbf3..6d4757998 100644 --- a/rigs/aor/ar7030p.c +++ b/rigs/aor/ar7030p.c @@ -333,7 +333,7 @@ static int ar7030p_cleanup(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (priv == NULL) return RIG_OK; + if (priv == NULL) { return RIG_OK; } for (i = 0; i < NB_CHAN; i++) { @@ -1264,7 +1264,8 @@ static int ar7030p_set_vfo(RIG *rig, vfo_t vfo) static int ar7030p_get_vfo(RIG *rig, vfo_t *vfo) { int rc = RIG_OK; - struct ar7030p_priv_data const *priv = (struct ar7030p_priv_data *) rig->state.priv; + struct ar7030p_priv_data const *priv = (struct ar7030p_priv_data *) + rig->state.priv; assert(NULL != vfo); @@ -1348,7 +1349,8 @@ static int ar7030p_get_mem(RIG *rig, vfo_t vfo, int *ch) { int rc = RIG_OK; - struct ar7030p_priv_data const *priv = (struct ar7030p_priv_data *) rig->state.priv; + struct ar7030p_priv_data const *priv = (struct ar7030p_priv_data *) + rig->state.priv; const channel_t *curr = priv->curr; assert(NULL != ch); @@ -1648,7 +1650,8 @@ static int ar7030p_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, unsigned int f; unsigned char *p = NULL; int ch; - const struct ar7030p_priv_data *priv = (struct ar7030p_priv_data *)rig->state.priv; + const struct ar7030p_priv_data *priv = (struct ar7030p_priv_data *) + rig->state.priv; const channel_t *curr = priv->curr; assert(NULL != chan); diff --git a/rigs/barrett/950.c b/rigs/barrett/950.c index ac35231ca..1c6e40045 100644 --- a/rigs/barrett/950.c +++ b/rigs/barrett/950.c @@ -164,7 +164,9 @@ int barrett950_set_freq(RIG *rig, vfo_t vfo, freq_t freq) for (i = 0; i < 10; ++i) { - rig_debug(RIG_DEBUG_VERBOSE, "%s: Mhz=%lg, lo=%lg, hi=%lg\n", __func__, freq_MHz, chan_map[i].lo, chan_map[i].hi); + rig_debug(RIG_DEBUG_VERBOSE, "%s: Mhz=%lg, lo=%lg, hi=%lg\n", __func__, + freq_MHz, chan_map[i].lo, chan_map[i].hi); + if (freq_MHz >= chan_map[i].lo && freq_MHz <= chan_map[i].hi) { int channel_base = priv->channel_base; diff --git a/rigs/barrett/barrett.c b/rigs/barrett/barrett.c index 37477a31a..d994e8d91 100644 --- a/rigs/barrett/barrett.c +++ b/rigs/barrett/barrett.c @@ -683,11 +683,13 @@ int barrett_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) switch (level) { - case RIG_LEVEL_AGC: - sprintf(cmd_buf,"EG%c%s", val.i==0?'N':'H' , EOM); - break; - default: return -RIG_ENIMPL; + case RIG_LEVEL_AGC: + sprintf(cmd_buf, "EG%c%s", val.i == 0 ? 'N' : 'H', EOM); + break; + + default: return -RIG_ENIMPL; } + rig_flush(&rs->rigport); retval = write_block(&rs->rigport, (unsigned char *) cmd_buf, strlen(cmd_buf)); @@ -695,6 +697,7 @@ int barrett_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { return retval; } + return RIG_OK; } diff --git a/rigs/dummy/aclog.c b/rigs/dummy/aclog.c index 4427506ad..d29aceef6 100644 --- a/rigs/dummy/aclog.c +++ b/rigs/dummy/aclog.c @@ -257,7 +257,7 @@ static int aclog_transaction(RIG *rig, char *cmd, char *value, ENTERFUNC; ELAPSED1; - strcpy(xml,"UNKNOWN"); + strcpy(xml, "UNKNOWN"); set_transaction_active(rig); @@ -710,10 +710,12 @@ static int aclog_set_freq(RIG *rig, vfo_t vfo, freq_t freq) } #if 0 + if (vfo == RIG_VFO_CURR) { vfo = rig->state.current_vfo; } + #endif SNPRINTF(cmd, sizeof(cmd), diff --git a/rigs/dummy/amp_dummy.c b/rigs/dummy/amp_dummy.c index 20196c71e..d72135942 100644 --- a/rigs/dummy/amp_dummy.c +++ b/rigs/dummy/amp_dummy.c @@ -143,7 +143,7 @@ Also a way to display faults (there are commands) static int dummy_amp_get_freq(AMP *amp, freq_t *freq) { const struct dummy_amp_priv_data *priv = (struct dummy_amp_priv_data *) - amp->state.priv; + amp->state.priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); *freq = priv->freq; return RIG_OK; @@ -267,7 +267,7 @@ static int dummy_amp_set_powerstat(AMP *amp, powerstat_t status) static int dummy_amp_get_powerstat(AMP *amp, powerstat_t *status) { const struct dummy_amp_priv_data *priv = (struct dummy_amp_priv_data *) - amp->state.priv; + amp->state.priv; *status = priv->powerstat; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); diff --git a/rigs/dummy/dummy.c b/rigs/dummy/dummy.c index 765231670..a8e2fdcb4 100644 --- a/rigs/dummy/dummy.c +++ b/rigs/dummy/dummy.c @@ -423,7 +423,9 @@ static int dummy_set_freq(RIG *rig, vfo_t vfo, freq_t freq) rig_debug(RIG_DEBUG_ERR, "%s: rig is NULL!!!\n", __func__); return -RIG_EINVAL; } + priv = (struct dummy_priv_data *)rig->state.priv; + if (priv == NULL) { RETURNFUNC(-RIG_EINTERNAL); @@ -1533,9 +1535,10 @@ static int dummy_set_parm(RIG *rig, setting_t parm, value_t val) { SNPRINTF(pstr, sizeof(pstr), "%f", val.f); } + if (RIG_PARM_IS_STRING(parm)) { - strcpy(pstr,val.cs); + strcpy(pstr, val.cs); } else { @@ -2302,10 +2305,10 @@ struct rig_caps dummy_caps = .has_get_parm = DUMMY_PARM, .has_set_parm = RIG_PARM_SET(DUMMY_PARM), .level_gran = { - [LVL_RF] = { .min = { .f = 0 }, .max = { .f = 1.0f }, .step = { .f = 1.0f/255.0f } }, - [LVL_RFPOWER] = { .min = { .f = .05f }, .max = { .f = 1 }, .step = { .f = 1.0f/511.0f } }, - [LVL_RFPOWER_METER] = { .min = { .f = .0f }, .max = { .f = 1 }, .step = { .f = 1.0f/255.0f } }, - [LVL_RFPOWER_METER_WATTS] = { .min = { .f = .0f }, .max = { .f = 100 }, .step = { .f = 1.0f/255.0f } }, + [LVL_RF] = { .min = { .f = 0 }, .max = { .f = 1.0f }, .step = { .f = 1.0f / 255.0f } }, + [LVL_RFPOWER] = { .min = { .f = .05f }, .max = { .f = 1 }, .step = { .f = 1.0f / 511.0f } }, + [LVL_RFPOWER_METER] = { .min = { .f = .0f }, .max = { .f = 1 }, .step = { .f = 1.0f / 255.0f } }, + [LVL_RFPOWER_METER_WATTS] = { .min = { .f = .0f }, .max = { .f = 100 }, .step = { .f = 1.0f / 255.0f } }, [LVL_CWPITCH] = { .step = { .i = 10 } }, [LVL_SPECTRUM_SPEED] = {.min = {.i = 0}, .max = {.i = 2}, .step = {.i = 1}}, [LVL_SPECTRUM_REF] = {.min = {.f = -30.0f}, .max = {.f = 10.0f}, .step = {.f = 0.5f}}, diff --git a/rigs/dummy/flrig.c b/rigs/dummy/flrig.c index a6f262c4d..c1b467797 100644 --- a/rigs/dummy/flrig.c +++ b/rigs/dummy/flrig.c @@ -896,7 +896,8 @@ static int flrig_open(RIG *rig) retval = flrig_transaction(rig, "rig.get_bwA", NULL, value, sizeof(value)); int dummy; - if (retval == RIG_ENAVAIL || value[0] == 0 || sscanf(value,"%d",&dummy)==0) // must not have it + if (retval == RIG_ENAVAIL || value[0] == 0 + || sscanf(value, "%d", &dummy) == 0) // must not have it { priv->has_get_bwA = 0; priv->has_get_bwB = 0; // if we don't have A then surely we don't have B either @@ -1757,14 +1758,15 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) /* so we may not be 100% accurate if op is twiddling knobs */ cmdp = "rig.get_bwA"; retval = flrig_transaction(rig, cmdp, NULL, value, sizeof(value)); - if (retval == RIG_OK && strstr(value,"NONE")) + + if (retval == RIG_OK && strstr(value, "NONE")) { priv->has_get_bwA = priv->has_get_bwB = 0; *width = 0; rig_debug(RIG_DEBUG_VERBOSE, "%s: does not have rig.get_bwA/B\n", __func__); } - if (retval != RIG_OK || strstr(value,"NONE")) + if (retval != RIG_OK || strstr(value, "NONE")) { RETURNFUNC(retval); } @@ -1774,7 +1776,8 @@ static int flrig_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { cmdp = "rig.get_bwB"; retval = flrig_transaction(rig, cmdp, NULL, value, sizeof(value)); - if (retval == RIG_OK && strlen(value)==0) + + if (retval == RIG_OK && strlen(value) == 0) { rig_debug(RIG_DEBUG_VERBOSE, "%s: does not have rig.get_bwB\n", __func__); priv->has_get_bwB = 0; @@ -2523,7 +2526,7 @@ HAMLIB_EXPORT(int) flrig_cat_string(RIG *rig, const char *arg) } int flrig_set_func(RIG *rig, vfo_t vfo, setting_t func, - int status) + int status) { int retval; char cmd_arg[MAXARGLEN]; diff --git a/rigs/dummy/netrigctl.c b/rigs/dummy/netrigctl.c index 1ad73fd60..8002348e4 100644 --- a/rigs/dummy/netrigctl.c +++ b/rigs/dummy/netrigctl.c @@ -861,6 +861,7 @@ static int netrigctl_open(RIG *rig) else if (strcmp(setting, "parm_gran") == 0) { char *p = strtok(value, ";"); + for (i = 0; p != NULL && i < RIG_SETTING_MAX; ++i) { int level; @@ -882,6 +883,7 @@ static int netrigctl_open(RIG *rig) rig->caps->parm_gran[i].max.i = rs->parm_gran[i].max.i = max; rig->caps->parm_gran[i].step.i = rs->parm_gran[i].step.i = step; } + p = strtok(NULL, ";"); } } @@ -2577,7 +2579,7 @@ static int netrigctl_send_voice_mem(RIG *rig, vfo_t vfo, int ch) static int netrigctl_send_morse(RIG *rig, vfo_t vfo, const char *msg) { int ret, len; - char *cmdp; + char *cmdp; const char cmd[] = "\\send_morse "; char buf[BUF_MAX]; diff --git a/rigs/dummy/quisk.c b/rigs/dummy/quisk.c index a0d22f411..01d207565 100644 --- a/rigs/dummy/quisk.c +++ b/rigs/dummy/quisk.c @@ -199,8 +199,10 @@ static int quisk_cleanup(RIG *rig) } // these are in netrigctl.c -extern int parse_array_int(const char *s, const char *delim, int *array, int array_len); -extern int parse_array_double(const char *s, const char *delim, double *array, int array_len); +extern int parse_array_int(const char *s, const char *delim, int *array, + int array_len); +extern int parse_array_double(const char *s, const char *delim, double *array, + int array_len); static int quisk_open(RIG *rig) { @@ -554,6 +556,7 @@ static int quisk_open(RIG *rig) { RETURNFUNC((ret < 0) ? ret : -RIG_EPROTO); } + HAMLIB_TRACE; rig->caps->has_set_parm = rs->has_set_parm = strtoll(buf, NULL, 0); @@ -564,6 +567,7 @@ static int quisk_open(RIG *rig) rs->mode_list |= rs->rx_range_list[i].modes; rs->vfo_list |= rs->rx_range_list[i].vfo; } + HAMLIB_TRACE; for (i = 0; i < HAMLIB_FRQRANGESIZ @@ -572,6 +576,7 @@ static int quisk_open(RIG *rig) rs->mode_list |= rs->tx_range_list[i].modes; rs->vfo_list |= rs->tx_range_list[i].vfo; } + HAMLIB_TRACE; if (rs->vfo_list == 0) @@ -580,10 +585,12 @@ static int quisk_open(RIG *rig) __func__); rs->vfo_list = RIG_VFO_A | RIG_VFO_B; } + HAMLIB_TRACE; #endif if (prot_ver == 0) { RETURNFUNC(RIG_OK); } + HAMLIB_TRACE; // otherwise we continue reading protocol 1 fields @@ -805,6 +812,7 @@ static int quisk_open(RIG *rig) else if (strcmp(setting, "parm_gran") == 0) { char *p = strtok(value, ";"); + for (i = 0; p != NULL && i < RIG_SETTING_MAX; ++i) { int level; @@ -826,6 +834,7 @@ static int quisk_open(RIG *rig) rig->caps->parm_gran[i].max.i = rs->parm_gran[i].max.i = max; rig->caps->parm_gran[i].step.i = rs->parm_gran[i].step.i = step; } + p = strtok(NULL, ";"); } } @@ -961,7 +970,7 @@ static int quisk_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) static int quisk_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, - pbwidth_t width) + pbwidth_t width) { int ret; char cmd[CMD_MAX]; @@ -991,7 +1000,7 @@ static int quisk_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, static int quisk_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, - pbwidth_t *width) + pbwidth_t *width) { int ret; char cmd[CMD_MAX]; @@ -1186,7 +1195,7 @@ static int quisk_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) static int quisk_set_rptr_shift(RIG *rig, vfo_t vfo, - rptr_shift_t rptr_shift) + rptr_shift_t rptr_shift) { int ret; char cmd[CMD_MAX]; @@ -1215,7 +1224,7 @@ static int quisk_set_rptr_shift(RIG *rig, vfo_t vfo, static int quisk_get_rptr_shift(RIG *rig, vfo_t vfo, - rptr_shift_t *rptr_shift) + rptr_shift_t *rptr_shift) { int ret; char cmd[CMD_MAX]; @@ -1581,7 +1590,7 @@ static int quisk_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) } static int quisk_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, - pbwidth_t tx_width) + pbwidth_t tx_width) { int ret; char cmd[CMD_MAX]; @@ -1610,7 +1619,7 @@ static int quisk_set_split_mode(RIG *rig, vfo_t vfo, rmode_t tx_mode, } static int quisk_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, - pbwidth_t *tx_width) + pbwidth_t *tx_width) { int ret; char cmd[CMD_MAX]; @@ -1650,7 +1659,7 @@ static int quisk_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, } static int quisk_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, - vfo_t tx_vfo) + vfo_t tx_vfo) { int ret; char cmd[CMD_MAX]; @@ -1680,7 +1689,7 @@ static int quisk_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, static int quisk_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, - vfo_t *tx_vfo) + vfo_t *tx_vfo) { int ret; char cmd[CMD_MAX]; @@ -1952,7 +1961,7 @@ static int quisk_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) static int quisk_set_level(RIG *rig, vfo_t vfo, setting_t level, - value_t val) + value_t val) { int ret; char cmd[CMD_MAX]; @@ -1993,7 +2002,7 @@ static int quisk_set_level(RIG *rig, vfo_t vfo, setting_t level, static int quisk_get_level(RIG *rig, vfo_t vfo, setting_t level, - value_t *val) + value_t *val) { int ret; char cmd[CMD_MAX]; @@ -2208,7 +2217,7 @@ static int quisk_set_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t option) static int quisk_get_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t *option, - ant_t *ant_curr, ant_t *ant_tx, ant_t *ant_rx) + ant_t *ant_curr, ant_t *ant_tx, ant_t *ant_rx) { int ret; char cmd[CMD_MAX]; @@ -2645,7 +2654,7 @@ static int quisk_get_trn(RIG *rig, int *trn) #endif static int quisk_mW2power(RIG *rig, float *power, unsigned int mwpower, - freq_t freq, rmode_t mode) + freq_t freq, rmode_t mode) { char cmdbuf[32]; char buf[BUF_MAX]; @@ -2669,7 +2678,7 @@ static int quisk_mW2power(RIG *rig, float *power, unsigned int mwpower, static int quisk_power2mW(RIG *rig, unsigned int *mwpower, float power, - freq_t freq, rmode_t mode) + freq_t freq, rmode_t mode) { char cmdbuf[64]; char buf[BUF_MAX]; diff --git a/rigs/dummy/rot_dummy.c b/rigs/dummy/rot_dummy.c index a538a5794..11fc36b52 100644 --- a/rigs/dummy/rot_dummy.c +++ b/rigs/dummy/rot_dummy.c @@ -354,7 +354,7 @@ static void dummy_rot_simulate_rotation(ROT *rot) static int dummy_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) { const struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *) - rot->state.priv; + rot->state.priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -416,7 +416,7 @@ static int dummy_rot_reset(ROT *rot, rot_reset_t reset) static int dummy_rot_move(ROT *rot, int direction, int speed) { const struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *) - rot->state.priv; + rot->state.priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_TRACE, "%s: Direction = %d, Speed = %d\n", __func__, @@ -474,7 +474,7 @@ static int dummy_set_func(ROT *rot, setting_t func, int status) static int dummy_get_func(ROT *rot, setting_t func, int *status) { const struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *) - rot->state.priv; + rot->state.priv; *status = (priv->funcs & func) ? 1 : 0; @@ -904,7 +904,7 @@ static int dummy_get_ext_parm(ROT *rot, token_t token, value_t *val) static int dummy_rot_get_status(ROT *rot, rot_status_t *status) { const struct dummy_rot_priv_data *priv = (struct dummy_rot_priv_data *) - rot->state.priv; + rot->state.priv; if (simulating) { diff --git a/rigs/dummy/sdrsharp.c b/rigs/dummy/sdrsharp.c index c649c5452..97bd8aceb 100644 --- a/rigs/dummy/sdrsharp.c +++ b/rigs/dummy/sdrsharp.c @@ -245,7 +245,7 @@ static int sdrsharp_transaction(RIG *rig, char *cmd, char *value, if (value) { read_transaction(rig, xml, sizeof(xml)); // this might time out -- that's OK - strncpy(value, xml, value_len); + strncpy(value, xml, value_len); } } @@ -486,10 +486,12 @@ static int sdrsharp_set_freq(RIG *rig, vfo_t vfo, freq_t freq) } #if 0 + if (vfo == RIG_VFO_CURR) { vfo = rig->state.current_vfo; } + #endif SNPRINTF(cmd, sizeof(cmd), "F %.0lf\n", freq); diff --git a/rigs/dummy/trxmanager.c b/rigs/dummy/trxmanager.c index 2bf4f5f19..e7ffee2ac 100644 --- a/rigs/dummy/trxmanager.c +++ b/rigs/dummy/trxmanager.c @@ -477,7 +477,7 @@ static int trxmanager_set_freq(RIG *rig, vfo_t vfo, freq_t freq) char response[MAXCMDLEN] = ""; struct rig_state *rs = &rig->state; const struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) - rig->state.priv; + rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s freq=%.1f\n", __func__, @@ -1215,7 +1215,7 @@ static int trxmanager_get_split_freq_mode(RIG *rig, vfo_t vfo, freq_t *freq, static const char *trxmanager_get_info(RIG *rig) { const struct trxmanager_priv_data *priv = (struct trxmanager_priv_data *) - rig->state.priv; + rig->state.priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); return priv->info; diff --git a/rigs/elad/elad.c b/rigs/elad/elad.c index b798b40ff..3c63c3cb7 100644 --- a/rigs/elad/elad.c +++ b/rigs/elad/elad.c @@ -915,6 +915,7 @@ int elad_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); retval = elad_get_split_vfo_if(rig, vfo, &tsplit, &tvfo); + if (retval != RIG_OK) { return retval; @@ -983,10 +984,12 @@ int elad_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) } retval = elad_set_split(rig, vfo, split, txvfo); + if (retval != RIG_OK) { return retval; } + /* Remember whether split is on, for elad_set_vfo */ priv->split = split; diff --git a/rigs/gomspace/gs100.c b/rigs/gomspace/gs100.c index 78f981278..61ca63893 100644 --- a/rigs/gomspace/gs100.c +++ b/rigs/gomspace/gs100.c @@ -83,7 +83,8 @@ static int gomx_set(RIG *rig, int table, char *varname, char *varvalue); /** * Get variable from the GS100 configuration table */ -static int gomx_get(RIG *rig, int table, char *varname, const char *varvalue, int varvalue_len); +static int gomx_get(RIG *rig, int table, char *varname, const char *varvalue, + int varvalue_len); /** * Sends a message to the GS100 and parses response lines @@ -217,8 +218,9 @@ static int gs100_get_conf(RIG *rig, token_t token, char *val) static int gs100_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { #ifdef _LOCAL_SIMULATION_ - __attribute__((unused)) const struct gs100_priv_data *priv = (struct gs100_priv_data - *)rig->state.priv; + __attribute__((unused)) const struct gs100_priv_data *priv = + (struct gs100_priv_data + *)rig->state.priv; #endif char fstr[20], value[20]; int retval; @@ -251,8 +253,9 @@ static int gs100_set_freq(RIG *rig, vfo_t vfo, freq_t freq) static int gs100_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { #ifdef _LOCAL_SIMULATION_ - __attribute__((unused)) const struct gs100_priv_data *priv = (struct gs100_priv_data - *)rig->state.priv; + __attribute__((unused)) const struct gs100_priv_data *priv = + (struct gs100_priv_data + *)rig->state.priv; #endif char resp[20]; int retval; @@ -287,8 +290,9 @@ static int gs100_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) static int gs100_set_tx_freq(RIG *rig, vfo_t vfo, freq_t freq) { #ifdef _LOCAL_SIMULATION_ - __attribute__((unused)) const struct gs100_priv_data *priv = (struct gs100_priv_data - *)rig->state.priv; + __attribute__((unused)) const struct gs100_priv_data *priv = + (struct gs100_priv_data + *)rig->state.priv; #endif char fstr[20], value[20]; int retval; @@ -321,8 +325,9 @@ static int gs100_set_tx_freq(RIG *rig, vfo_t vfo, freq_t freq) static int gs100_get_tx_freq(RIG *rig, vfo_t vfo, freq_t *freq) { #ifdef _LOCAL_SIMULATION_ - __attribute__((unused)) const struct gs100_priv_data *priv = (struct gs100_priv_data - *)rig->state.priv; + __attribute__((unused)) const struct gs100_priv_data *priv = + (struct gs100_priv_data + *)rig->state.priv; #endif char resp[20]; int retval; @@ -470,7 +475,8 @@ static int gomx_set(RIG *rig, int table, char *varname, char *varvalue) /* Get variable from the GS100 configuration table */ -static int gomx_get(RIG *rig, int table, char *varname, const char *varvalue, int varvalue_len) +static int gomx_get(RIG *rig, int table, char *varname, const char *varvalue, + int varvalue_len) { __attribute__((unused)) struct gs100_priv_data *priv = (struct gs100_priv_data *)rig->state.priv; @@ -504,6 +510,7 @@ static int gomx_get(RIG *rig, int table, char *varname, const char *varvalue, in if ((c = strchr(resp, '=')) == NULL) { return (-RIG_EPROTO); } snprintf(fmt, sizeof(fmt), "%%%ds", varvalue_len); + if (sscanf(c + 1, fmt, varvalue_len) != 1) { return (-RIG_EPROTO); } return (RIG_OK); diff --git a/rigs/icom/frame.c b/rigs/icom/frame.c index b61d29f4c..2892482dc 100644 --- a/rigs/icom/frame.c +++ b/rigs/icom/frame.c @@ -261,7 +261,7 @@ collision_retry: // first 2 bytes of everyting are 0xfe so we won't test those // this allows some corruptin of the 0xfe bytes which has been seen in the wild - if (memcmp(&buf[2], &sendbuf[2], frm_len-2) != 0) + if (memcmp(&buf[2], &sendbuf[2], frm_len - 2) != 0) { /* Frames are different? */ /* Problem on ci-v bus? */ @@ -290,8 +290,11 @@ read_another_frame: */ buf[0] = 0; frm_len = read_icom_frame(&rs->rigport, buf, sizeof(buf)); + if (frm_len > 4 && memcmp(buf, sendbuf, frm_len) == 0) + { priv->serial_USB_echo_off = 0; + } #if 0 @@ -587,7 +590,8 @@ int rig2icom_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width, unsigned char icmode; signed char icmode_ext; pbwidth_t width_tmp = width; - const struct icom_priv_data *priv_data = (struct icom_priv_data *) rig->state.priv; + const struct icom_priv_data *priv_data = (struct icom_priv_data *) + rig->state.priv; ENTERFUNC; rig_debug(RIG_DEBUG_TRACE, "%s: mode=%d, width=%d\n", __func__, (int)mode, diff --git a/rigs/icom/ic7100.c b/rigs/icom/ic7100.c index 7dd017e93..cb29897ea 100644 --- a/rigs/icom/ic7100.c +++ b/rigs/icom/ic7100.c @@ -281,10 +281,12 @@ int ic7100_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x01; prmbuf[1] = 0x21; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *hour = from_bcd(&respbuf[4], 2); *min = from_bcd(&respbuf[5], 2); *sec = 0; @@ -293,10 +295,12 @@ int ic7100_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x01; prmbuf[1] = 0x23; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *utc_offset = from_bcd(&respbuf[4], 2) * 100; *utc_offset += from_bcd(&respbuf[5], 2); diff --git a/rigs/icom/ic7300.c b/rigs/icom/ic7300.c index 960a9d1d3..653c15bc5 100644 --- a/rigs/icom/ic7300.c +++ b/rigs/icom/ic7300.c @@ -756,8 +756,8 @@ struct rig_caps ic7300_caps = .chan_list = { { 1, 99, RIG_MTYPE_MEM }, - { 1, 8, RIG_MTYPE_VOICE }, - { 1, 8, RIG_MTYPE_MORSE }, + { 1, 8, RIG_MTYPE_VOICE }, + { 1, 8, RIG_MTYPE_MORSE }, RIG_CHAN_END, }, @@ -978,7 +978,7 @@ struct rig_caps ic9700_caps = [PARM_BEEP] = {.min = {.i = 0}, .max = {.i = 1}}, [PARM_SCREENSAVER] = {.min = {.i = 0}, .max = {.i = 3}, .step = {.i = 1}}, [PARM_KEYERTYPE] = {.step = {.s = "STRAIGHT, BUG, PADDLE"}}, - }, + }, .ext_tokens = ic9700_ext_tokens, .extlevels = icom_ext_levels, .ctcss_list = full_ctcss_list, @@ -999,8 +999,8 @@ struct rig_caps ic9700_caps = .chan_list = { { 1, 99, RIG_MTYPE_MEM }, - { 1, 8, RIG_MTYPE_VOICE }, - { 1, 8, RIG_MTYPE_MORSE }, + { 1, 8, RIG_MTYPE_VOICE }, + { 1, 8, RIG_MTYPE_MORSE }, RIG_CHAN_END, }, @@ -1300,7 +1300,7 @@ struct rig_caps ic705_caps = [PARM_BANDSELECT] = {.step = {.s = "BANDUNUSED,BAND160M,BAND80M,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDWFM,BANDAIR,BAND70CM,BAND33CM,BANDGEN"}}, [PARM_BEEP] = {.min = {.i = 0}, .max = {.i = 1}}, [PARM_SCREENSAVER] = {.min = {.i = 0}, .max = {.i = 3}, .step = {.i = 1}}, - }, + }, .ext_tokens = ic705_ext_tokens, .extlevels = icom_ext_levels, .ctcss_list = full_ctcss_list, @@ -1321,8 +1321,8 @@ struct rig_caps ic705_caps = .chan_list = { { 1, 99, RIG_MTYPE_MEM }, - { 1, 8, RIG_MTYPE_VOICE }, - { 1, 8, RIG_MTYPE_MORSE }, + { 1, 8, RIG_MTYPE_VOICE }, + { 1, 8, RIG_MTYPE_MORSE }, RIG_CHAN_END, }, @@ -1574,7 +1574,7 @@ struct rig_caps ic905_caps = [PARM_BEEP] = {.min = {.i = 0}, .max = {.i = 1}}, [PARM_SCREENSAVER] = {.min = {.i = 0}, .max = {.i = 3}, .step = {.i = 1}}, [PARM_KEYERTYPE] = {.step = {.s = "STRAIGHT, BUG, PADDLE"}}, - }, + }, .ext_tokens = ic705_ext_tokens, .extlevels = icom_ext_levels, .ctcss_list = full_ctcss_list, @@ -1595,8 +1595,8 @@ struct rig_caps ic905_caps = .chan_list = { { 1, 99, RIG_MTYPE_MEM }, - { 1, 8, RIG_MTYPE_VOICE }, - { 1, 8, RIG_MTYPE_MORSE }, + { 1, 8, RIG_MTYPE_VOICE }, + { 1, 8, RIG_MTYPE_MORSE }, RIG_CHAN_END, }, @@ -1897,6 +1897,7 @@ int ic7300_get_parm(RIG *rig, setting_t parm, value_t *val) switch (parm) { #if 0 + case RIG_PARM_ANN: return -RIG_ENIMPL; // How can we implement this? #endif @@ -1929,6 +1930,7 @@ int ic7300_get_parm(RIG *rig, setting_t parm, value_t *val) { #if 0 + case RIG_PARM_ANN: rig_debug(RIG_DEBUG_WARN, "%s: not implemented\n", __func__); return -RIG_ENIMPL; @@ -2023,10 +2025,12 @@ int ic7300_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x95; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *hour = from_bcd(&respbuf[4], 2); *min = from_bcd(&respbuf[5], 2); *sec = 0; @@ -2035,10 +2039,12 @@ int ic7300_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x96; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *utc_offset = from_bcd(&respbuf[4], 2) * 100; *utc_offset += from_bcd(&respbuf[5], 2); @@ -2131,10 +2137,12 @@ int ic9700_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x01; prmbuf[1] = 0x80; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *hour = from_bcd(&respbuf[4], 2); *min = from_bcd(&respbuf[5], 2); *sec = 0; @@ -2143,10 +2151,12 @@ int ic9700_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x01; prmbuf[1] = 0x84; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *utc_offset = from_bcd(&respbuf[4], 2) * 100; *utc_offset += from_bcd(&respbuf[5], 2); @@ -2168,16 +2178,18 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) int ack_len = sizeof(ackbuf), retval = -RIG_EINTERNAL; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); + if (rig->state.cache.satmode) { - if (vfo == RIG_VFO_A) vfo = RIG_VFO_MAIN; - else if (vfo == RIG_VFO_B) vfo = RIG_VFO_SUB; + if (vfo == RIG_VFO_A) { vfo = RIG_VFO_MAIN; } + else if (vfo == RIG_VFO_B) { vfo = RIG_VFO_SUB; } else { rig_debug(RIG_DEBUG_ERR, "%s: unknown vfo %s\n", __func__, rig_strvfo(vfo)); return -RIG_EINVAL; } } + if (vfo == RIG_VFO_A) { retval = icom_transaction(rig, 0x07, 0x00, NULL, 0, ackbuf, &ack_len); @@ -2189,14 +2201,16 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) else if (vfo == RIG_VFO_MAIN || vfo == RIG_VFO_MAIN_A || vfo == RIG_VFO_MAIN_B) { retval = icom_transaction(rig, 0x07, 0xd0, NULL, 0, ackbuf, &ack_len); + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: %s\n", __func__, rigerror(retval)); return -retval; } + if (vfo == RIG_VFO_MAIN_A || vfo == RIG_VFO_MAIN_B) { - int subcmd = vfo == RIG_VFO_MAIN_A ? 0x00: 0x01; + int subcmd = vfo == RIG_VFO_MAIN_A ? 0x00 : 0x01; retval = icom_transaction(rig, 0x07, subcmd, NULL, 0, ackbuf, &ack_len); } } @@ -2204,21 +2218,25 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) { if (rig->state.cache.satmode) { - rig_debug(RIG_DEBUG_WARN, "%s: cannot switch to VFOB when in satmode\n", __func__); + rig_debug(RIG_DEBUG_WARN, "%s: cannot switch to VFOB when in satmode\n", + __func__); // we return RIG_OK anyways as this should just be a bad request return RIG_OK; } + // first switch to sub retval = icom_transaction(rig, 0x07, 0xd1, NULL, 0, ackbuf, &ack_len); + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: %s\n", __func__, rigerror(retval)); return -retval; } + if (vfo == RIG_VFO_SUB_A || vfo == RIG_VFO_SUB_B) { HAMLIB_TRACE; - int subcmd = vfo == RIG_VFO_SUB_A ? 0x00: 0x01; + int subcmd = vfo == RIG_VFO_SUB_A ? 0x00 : 0x01; retval = icom_transaction(rig, 0x07, subcmd, NULL, 0, ackbuf, &ack_len); } } diff --git a/rigs/icom/ic7600.c b/rigs/icom/ic7600.c index faf535a7c..297e5b20a 100644 --- a/rigs/icom/ic7600.c +++ b/rigs/icom/ic7600.c @@ -242,10 +242,12 @@ int ic7600_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x54; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *hour = from_bcd(&respbuf[4], 2); *min = from_bcd(&respbuf[5], 2); *sec = 0; @@ -254,10 +256,12 @@ int ic7600_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x56; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *utc_offset = from_bcd(&respbuf[4], 2) * 100; *utc_offset += from_bcd(&respbuf[5], 2); diff --git a/rigs/icom/ic7610.c b/rigs/icom/ic7610.c index 4a7bc799f..d489ec648 100644 --- a/rigs/icom/ic7610.c +++ b/rigs/icom/ic7610.c @@ -144,7 +144,7 @@ struct cmdparams ic7610_extcmds[] = int ic7610_ext_tokens[] = { TOK_DRIVE_GAIN, TOK_DIGI_SEL_FUNC, TOK_DIGI_SEL_LEVEL, - TOK_SCOPE_MSS, TOK_SCOPE_SDS, TOK_SCOPE_STX, TOK_SCOPE_CFQ, TOK_SCOPE_EDG, TOK_SCOPE_VBW, TOK_SCOPE_RBW, TOK_SCOPE_MKP,TOK_IPP_FUNC,TOK_TX_INHIBIT_FUNC,TOK_DPP_FUNC,TOK_ICPW2_FUNC, + TOK_SCOPE_MSS, TOK_SCOPE_SDS, TOK_SCOPE_STX, TOK_SCOPE_CFQ, TOK_SCOPE_EDG, TOK_SCOPE_VBW, TOK_SCOPE_RBW, TOK_SCOPE_MKP, TOK_IPP_FUNC, TOK_TX_INHIBIT_FUNC, TOK_DPP_FUNC, TOK_ICPW2_FUNC, TOK_BACKEND_NONE }; @@ -324,10 +324,12 @@ int ic7610_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x59; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *hour = from_bcd(&respbuf[4], 2); *min = from_bcd(&respbuf[5], 2); *sec = 0; @@ -336,10 +338,12 @@ int ic7610_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x62; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *utc_offset = from_bcd(&respbuf[4], 2) * 100; *utc_offset += from_bcd(&respbuf[5], 2); diff --git a/rigs/icom/ic7700.c b/rigs/icom/ic7700.c index 103fb9193..3df209aa4 100644 --- a/rigs/icom/ic7700.c +++ b/rigs/icom/ic7700.c @@ -223,10 +223,12 @@ int ic7700_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x59; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *hour = from_bcd(&respbuf[4], 2); *min = from_bcd(&respbuf[5], 2); *sec = 0; @@ -235,10 +237,12 @@ int ic7700_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x61; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *utc_offset = from_bcd(&respbuf[4], 2) * 100; *utc_offset += from_bcd(&respbuf[5], 2); diff --git a/rigs/icom/ic7800.c b/rigs/icom/ic7800.c index 303016606..3a5d85c2d 100644 --- a/rigs/icom/ic7800.c +++ b/rigs/icom/ic7800.c @@ -34,8 +34,10 @@ #include "bandplan.h" #include "ic7300.h" -int ic7800_set_clock(RIG *rig, int year, int month, int day, int hour, int min, int sec, double msec, int utc_offset); -int ic7800_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, int *min, int *sec, double *msec, int *utc_offset); +int ic7800_set_clock(RIG *rig, int year, int month, int day, int hour, int min, + int sec, double msec, int utc_offset); +int ic7800_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, + int *min, int *sec, double *msec, int *utc_offset); #define IC7800_ALL_RX_MODES (RIG_MODE_AM|RIG_MODE_CW|RIG_MODE_CWR|RIG_MODE_SSB|RIG_MODE_RTTY|RIG_MODE_RTTYR|RIG_MODE_FM|RIG_MODE_PSK|RIG_MODE_PSKR|RIG_MODE_PKTLSB|RIG_MODE_PKTUSB|RIG_MODE_PKTAM|RIG_MODE_PKTFM) #define IC7800_1HZ_TS_MODES IC7800_ALL_RX_MODES @@ -492,10 +494,12 @@ int ic7800_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x60; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *hour = from_bcd(&respbuf[4], 2); *min = from_bcd(&respbuf[5], 2); *sec = 0; @@ -504,10 +508,12 @@ int ic7800_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, prmbuf[0] = 0x00; prmbuf[1] = 0x62; retval = icom_transaction(rig, cmd, subcmd, prmbuf, 2, respbuf, &resplen); + if (retval != RIG_OK) { return retval; } + *utc_offset = from_bcd(&respbuf[4], 2) * 100; *utc_offset += from_bcd(&respbuf[5], 2); diff --git a/rigs/icom/icf8101.c b/rigs/icom/icf8101.c index 3fe58b502..2c6e448d0 100644 --- a/rigs/icom/icf8101.c +++ b/rigs/icom/icf8101.c @@ -99,15 +99,19 @@ static int icf8101_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, int modebuf_len; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); + if (retval != RIG_OK) { return retval; } + retval = icom_transaction(rig, 0x1A, 0x34, NULL, 0, modebuf, &modebuf_len); + if (retval != RIG_OK) { return retval; } + dump_hex(modebuf, modebuf_len); switch (modebuf[1]) diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 833f13f57..8dc4a3dff 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -958,7 +958,9 @@ static vfo_t icom_current_vfo(RIG *rig) } rig_debug(RIG_DEBUG_TRACE, "%s: currVFO=%s\n", __func__, rig_strvfo(currVFO)); - if (rig->state.current_vfo != RIG_VFO_NONE) currVFO = rig->state.current_vfo; + + if (rig->state.current_vfo != RIG_VFO_NONE) { currVFO = rig->state.current_vfo; } + return currVFO; } @@ -1030,10 +1032,12 @@ retry_open: rs->dual_watch = 0; retval = rig_get_func(rig, RIG_VFO_CURR, RIG_FUNC_DUAL_WATCH, &value); - if (retval == RIG_OK) { + if (retval == RIG_OK) + { rs->dual_watch = value; } - rig_debug(RIG_DEBUG_VERBOSE, "%s: dual_watch=%d\n", __func__, rs->dual_watch); + + rig_debug(RIG_DEBUG_VERBOSE, "%s: dual_watch=%d\n", __func__, rs->dual_watch); rig_debug(RIG_DEBUG_TRACE, "%s: echo status known, getting frequency\n", __func__); rs->rigport.retry = 0; @@ -1389,18 +1393,23 @@ int icom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) HAMLIB_TRACE; subcmd = 0x01; // get unselected VFO } + if (RIG_IS_IC7600 || RIG_IS_IC9700) - { // the 7600/7610 do it different 0=Main, 1=Sub -- maybe other Icoms will start doing this too + { + // the 7600/7610 do it different 0=Main, 1=Sub -- maybe other Icoms will start doing this too subcmd = 0; - if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) subcmd = 1; + + if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) { subcmd = 1; } } cmd = 0x25; retval = icom_transaction(rig, cmd, subcmd, freqbuf, freq_len, ackbuf, &ack_len); + if (retval == -RIG_ERJCTED && vfo == RIG_VFO_MEM) { - rig_debug(RIG_DEBUG_ERR, "%s: Rig is in MEM mode and MEM channel is empty\n", __func__); + rig_debug(RIG_DEBUG_ERR, "%s: Rig is in MEM mode and MEM channel is empty\n", + __func__); return -RIG_ECONF; } } @@ -1410,7 +1419,9 @@ int icom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) subcmd = -1; #if 0 - if (rig->state.cache.ptt && (ICOM_IS_ID5100 || ICOM_IS_ID4100 || ICOM_IS_ID31 || ICOM_IS_ID51)) + + if (rig->state.cache.ptt && (ICOM_IS_ID5100 || ICOM_IS_ID4100 || ICOM_IS_ID31 + || ICOM_IS_ID51)) { rig_debug(RIG_DEBUG_TRACE, "%s(%d): ID55100 0x00\n", __func__, __LINE__); // for these rigs 0x00 is setting the freq and 0x03 is just for reading @@ -1418,11 +1429,14 @@ int icom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) // temporary fix for ID5100 not giving ACK/NAK on 0x00 freq on E8 firmware retval = icom_transaction(rig, cmd, subcmd, freqbuf, freq_len, NULL, NULL); + if (retval != RIG_OK) { - rig_debug(RIG_DEBUG_ERR, "%s: set_freq failed: %s\n", __func__, rigerror(retval)); + rig_debug(RIG_DEBUG_ERR, "%s: set_freq failed: %s\n", __func__, + rigerror(retval)); return retval; } + return RIG_OK; } else @@ -1558,7 +1572,8 @@ int icom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) rs = &rig->state; priv = (struct icom_priv_data *) rs->priv; - if (priv->serial_USB_echo_off == -1) icom_get_usb_echo_off(rig); + + if (priv->serial_USB_echo_off == -1) { icom_get_usb_echo_off(rig); } cmd = C_RD_FREQ; subcmd = -1; @@ -1696,20 +1711,29 @@ int icom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) // Rigs like IC-7600 new firmware has 0x25 and 0x26 // So if this succeeds we'll assume all such rigs are targetable freq & mode int targetable_vfo_save = rig->caps->targetable_vfo; + if ((RIG_IS_IC7600 || RIG_IS_IC7610) && priv->x25cmdfails <= 0) - { // the 7600/7610 do it different 0=Main, 1=Sub -- maybe other Icoms will start doing this too + { + // the 7600/7610 do it different 0=Main, 1=Sub -- maybe other Icoms will start doing this too subcmd2 = 0; - if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) subcmd2 = 1; + + if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) { subcmd2 = 1; } + if (priv->x25cmdfails < 0) - { // we'll test this once to support the newer firmware - rig_debug(RIG_DEBUG_VERBOSE, "%s: TARGETABLE_FREQ and TARGETABLE_MODE enabled for testing\n", __func__); - rig->caps->targetable_vfo = rig->state.targetable_vfo |= RIG_TARGETABLE_FREQ | RIG_TARGETABLE_MODE; + { + // we'll test this once to support the newer firmware + rig_debug(RIG_DEBUG_VERBOSE, + "%s: TARGETABLE_FREQ and TARGETABLE_MODE enabled for testing\n", __func__); + rig->caps->targetable_vfo = rig->state.targetable_vfo |= RIG_TARGETABLE_FREQ | + RIG_TARGETABLE_MODE; } } + if (RIG_IS_IC9700) { subcmd2 = 0; - if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) subcmd2 = 1; + + if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) { subcmd2 = 1; } } retval = icom_transaction(rig, cmd2, subcmd2, NULL, 0, freqbuf, &freq_len); @@ -1723,10 +1747,13 @@ int icom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) if (priv->x25cmdfails < 0) { priv->x25cmdfails = 1; + if (RIG_IS_IC7600 || RIG_IS_IC7610) { rig->caps->targetable_vfo = targetable_vfo_save; - rig_debug(RIG_DEBUG_VERBOSE, "%s: TARGETABLE_FREQ and TARGETABLE_MODE disabled -- older firmare likely\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, + "%s: TARGETABLE_FREQ and TARGETABLE_MODE disabled -- older firmare likely\n", + __func__); } } @@ -1806,10 +1833,12 @@ int icom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) __func__, freq_len); if (vfo == RIG_VFO_MEM && civ_731_mode) { priv->civ_731_mode = 1; } + if (freq_len == 1 && vfo == RIG_VFO_MEM) { *freq = 0; - rig_debug(RIG_DEBUG_ERR, "%s: Rig is in MEM mode and MEM channel is empty\n", __func__); + rig_debug(RIG_DEBUG_ERR, "%s: Rig is in MEM mode and MEM channel is empty\n", + __func__); return -RIG_ETRUNC; } @@ -2221,10 +2250,13 @@ static int icom_set_mode_x26(RIG *rig, vfo_t vfo, rmode_t mode, int datamode, { subcmd2 = 0x01; // get unselected VFO } + if (RIG_IS_IC7600 || RIG_IS_IC7610) - { // the 7600/7610 do it different 0=Main, 1=Sub -- maybe other Icoms will start doing this too + { + // the 7600/7610 do it different 0=Main, 1=Sub -- maybe other Icoms will start doing this too subcmd2 = 0; - if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) subcmd2 = 1; + + if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) { subcmd2 = 1; } } buf[0] = mode; @@ -2727,7 +2759,8 @@ int icom_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) if (mode_len == 2) { priv_data->filter = modebuf[2]; } rig_debug(RIG_DEBUG_TRACE, - "%s(%d): modebuf[0]=0x%02x, modebuf[1]=0x%02x, mode_len=%d\n", __func__, __LINE__, modebuf[0], + "%s(%d): modebuf[0]=0x%02x, modebuf[1]=0x%02x, mode_len=%d\n", __func__, + __LINE__, modebuf[0], modebuf[1], mode_len); } @@ -2796,11 +2829,13 @@ int icom_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) } retval = 0; - // G90 does have dsp_flt command + + // G90 does have dsp_flt command if (rig->caps->rig_model != RIG_MODEL_G90) { retval = icom_get_dsp_flt(rig, *mode); } + *width = retval; if (retval == 0) @@ -2829,6 +2864,7 @@ int icom_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { retval = icom_get_dsp_flt(rig, *mode); } + *width = retval; if (*width == 0) { *width = rig->state.cache.widthMainA; } // we'll use VFOA's width @@ -3650,7 +3686,8 @@ int icom_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int found = 0; for (i = 0; - i <= HAMLIB_MAX_AGC_LEVELS && priv_caps->agc_levels[i].level != RIG_AGC_LAST; i++) + i <= HAMLIB_MAX_AGC_LEVELS + && priv_caps->agc_levels[i].level != RIG_AGC_LAST; i++) { if (priv_caps->agc_levels[i].level == val.i) { @@ -5871,11 +5908,15 @@ int icom_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) // when transmitting in split mode the split VFO is active subcmd = (rig->state.cache.split && rig->state.cache.ptt) ? 0x00 : 0x01; // get the unselected vfo + if (RIG_IS_IC7600 || RIG_IS_IC7610) - { // the 7600/7610 do it different 0=Main, 1=Sub -- maybe other Icoms will start doing this too + { + // the 7600/7610 do it different 0=Main, 1=Sub -- maybe other Icoms will start doing this too subcmd = 0; - if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) subcmd = 1; + + if (vfo & RIG_VFO_B || vfo & RIG_VFO_SUB) { subcmd = 1; } } + retval = icom_transaction(rig, cmd, subcmd, NULL, 0, ackbuf, &ack_len); @@ -7495,8 +7536,8 @@ int icom_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) case RIG_FUNC_DUAL_WATCH: if ((RIG_IS_IC9100) || - (RIG_IS_IC9700) || - (RIG_IS_ID5100)) + (RIG_IS_IC9700) || + (RIG_IS_ID5100)) { fct_cn = C_CTL_FUNC; fct_sc = S_MEM_DUALMODE; @@ -7640,10 +7681,10 @@ int icom_set_parm(RIG *rig, setting_t parm, value_t val) RETURNFUNC(-RIG_EINVAL); } -const char * icom_get_band(RIG *rig, int band) +const char *icom_get_band(RIG *rig, int band) { rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - + const char *s = rig_get_band_str(rig, band, 1); rig_debug(RIG_DEBUG_VERBOSE, "%s: %d=%s\n", __func__, band, s); @@ -7674,11 +7715,13 @@ int icom_get_parm(RIG *rig, setting_t parm, value_t *val) if (cmd[i].cmdparamtype == CMD_PARAM_TYPE_PARM && cmd[i].id.s == parm) { int retval = icom_get_cmd(rig, RIG_VFO_NONE, (struct cmdparams *)&cmd[i], val); + if (parm == RIG_PARM_BANDSELECT) { - char *s = (char*)icom_get_band(rig, val->i); + char *s = (char *)icom_get_band(rig, val->i); val->s = s; } + RETURNFUNC(retval); } } @@ -8153,29 +8196,36 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) switch (status) { case RIG_POWER_ON: + // ic7300 manual says ~150 for 115,200 // we'll just send a few more to be sure for all speeds - switch(rs->rigport.parm.serial.rate) + switch (rs->rigport.parm.serial.rate) { - case 4800: - fe_max = 7; - break; - case 9600: - fe_max = 13; - break; - case 19200: - fe_max = 25; - break; - case 38400: - fe_max = 50; - break; - case 57600: - fe_max = 75; - break; - case 115200: - default: - fe_max = 150; + case 4800: + fe_max = 7; + break; + + case 9600: + fe_max = 13; + break; + + case 19200: + fe_max = 25; + break; + + case 38400: + fe_max = 50; + break; + + case 57600: + fe_max = 75; + break; + + case 115200: + default: + fe_max = 150; } + memset(fe_buf, 0xfe, fe_max); // sending more than enough 0xfe's to wake up the rs232 write_block(&rs->rigport, fe_buf, fe_max); @@ -8189,11 +8239,15 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) retval = icom_transaction(rig, C_SET_PWR, pwr_sc, NULL, 0, ackbuf, &ack_len); - float sec_wait = 5.5; // 5.5 worked for IC-9700 -- we default to worst-case-found - if (RIG_IS_IC7300) sec_wait = 3.8; + float sec_wait = + 5.5; // 5.5 worked for IC-9700 -- we default to worst-case-found + + if (RIG_IS_IC7300) { sec_wait = 3.8; } + rig_debug(RIG_DEBUG_VERBOSE, "%s: waiting %g seconds for rig to wake up\n", __func__, sec_wait); - hl_usleep(sec_wait * 1000 * 1000); // some are slow to start up -- may need to add more rigs + hl_usleep(sec_wait * 1000 * + 1000); // some are slow to start up -- may need to add more rigs // poweron == 0 means never powered -- == 2 means CAT turned off if (priv->poweron == 0 || priv->poweron == 2) @@ -8202,13 +8256,14 @@ int icom_set_powerstat(RIG *rig, powerstat_t status) for (i = 0; i < 10 && echo_status < 0; ++i) { - echo_status = icom_get_usb_echo_off(rig); + echo_status = icom_get_usb_echo_off(rig); if (echo_status < 0) { - hl_usleep(500*1000); + hl_usleep(500 * 1000); } } + if (echo_status >= 0) { priv->poweron = 1; @@ -8333,6 +8388,7 @@ int icom_get_powerstat(RIG *rig, powerstat_t *status) } HAMLIB_TRACE; + if (RIG_IS_IC2730 || RIG_IS_IC705 || RIG_IS_IC7100 @@ -8348,7 +8404,7 @@ int icom_get_powerstat(RIG *rig, powerstat_t *status) freq_t freq; short retry_save = rig->state.rigport.retry; short timeout_retry_save = rig->state.rigport.timeout_retry; - HAMLIB_TRACE; + HAMLIB_TRACE; rig->state.rigport.retry = 0; rig->state.rigport.timeout_retry = 0; @@ -8356,13 +8412,16 @@ int icom_get_powerstat(RIG *rig, powerstat_t *status) retval = rig_get_freq(rig, RIG_VFO_A, &freq); if (retval == -RIG_ETIMEOUT) - { // then rig must be turned off - HAMLIB_TRACE; - rig_debug(RIG_DEBUG_WARN, "%s: get freq failed...assuming power is off\n", __func__); + { + // then rig must be turned off + HAMLIB_TRACE; + rig_debug(RIG_DEBUG_WARN, "%s: get freq failed...assuming power is off\n", + __func__); rig->state.powerstat = RIG_POWER_OFF; return RIG_OK; // returning RIG_OK here makes the rig->state reflect POWER_OFF } - HAMLIB_TRACE; + + HAMLIB_TRACE; rig->state.rigport.retry = retry_save; rig->state.rigport.timeout_retry = timeout_retry_save; @@ -8377,11 +8436,14 @@ int icom_get_powerstat(RIG *rig, powerstat_t *status) ackbuf, &ack_len); if (retval == -RIG_ETIMEOUT) - { // then rig must be turned off - rig_debug(RIG_DEBUG_WARN, "%s: get powerstat failed...assuming power is off\n", __func__); + { + // then rig must be turned off + rig_debug(RIG_DEBUG_WARN, "%s: get powerstat failed...assuming power is off\n", + __func__); rig->state.powerstat = RIG_POWER_OFF; return RIG_OK; // returning RIG_OK here makes the rig->state reflect POWER_OFF } + if (retval != RIG_OK) { RETURNFUNC(retval); diff --git a/rigs/icom/id5100.c b/rigs/icom/id5100.c index 281e85725..b1e114843 100644 --- a/rigs/icom/id5100.c +++ b/rigs/icom/id5100.c @@ -246,7 +246,8 @@ int id5100_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Sub on left\n", __func__, __LINE__); - if ((currvfo == RIG_VFO_B || currvfo == RIG_VFO_SUB) && (vfo == RIG_VFO_B || vfo == RIG_VFO_SUB)) + if ((currvfo == RIG_VFO_B || currvfo == RIG_VFO_SUB) && (vfo == RIG_VFO_B + || vfo == RIG_VFO_SUB)) { rig_debug(RIG_DEBUG_ERR, "%s: Method#3\n", __func__); id5100_set_vfo(rig, RIG_VFO_MAIN); diff --git a/rigs/kenwood/elecraft.c b/rigs/kenwood/elecraft.c index bcf35232a..b0d88af6c 100644 --- a/rigs/kenwood/elecraft.c +++ b/rigs/kenwood/elecraft.c @@ -321,6 +321,7 @@ int elecraft_open(RIG *rig) rig_debug(RIG_DEBUG_ERR, "%s: Firmware RVM failed\n", __func__); return err; } + err = elecraft_get_firmware_revision_level(rig, "RVD", priv->fw_rev, (sizeof(k3_fw_rev) / sizeof(k3_fw_rev[0]))); @@ -331,27 +332,29 @@ int elecraft_open(RIG *rig) if (priv->is_k3) { - err = elecraft_get_firmware_revision_level(rig, "RVA", priv->fw_rev, - (sizeof(k3_fw_rev) / sizeof(k3_fw_rev[0]))); + err = elecraft_get_firmware_revision_level(rig, "RVA", priv->fw_rev, + (sizeof(k3_fw_rev) / sizeof(k3_fw_rev[0]))); - if (err != RIG_OK) - { - rig_debug(RIG_DEBUG_ERR, "%s: Firmware RVA failed\n", __func__); - } - err = elecraft_get_firmware_revision_level(rig, "RVR", priv->fw_rev, - (sizeof(k3_fw_rev) / sizeof(k3_fw_rev[0]))); + if (err != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: Firmware RVA failed\n", __func__); + } - if (err != RIG_OK) - { - rig_debug(RIG_DEBUG_ERR, "%s: Firmware RVR failed\n", __func__); - } - err = elecraft_get_firmware_revision_level(rig, "RVF", priv->fw_rev, - (sizeof(k3_fw_rev) / sizeof(k3_fw_rev[0]))); + err = elecraft_get_firmware_revision_level(rig, "RVR", priv->fw_rev, + (sizeof(k3_fw_rev) / sizeof(k3_fw_rev[0]))); - if (err != RIG_OK) - { - rig_debug(RIG_DEBUG_ERR, "%s: Firmware RVF failed\n", __func__); - } + if (err != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: Firmware RVR failed\n", __func__); + } + + err = elecraft_get_firmware_revision_level(rig, "RVF", priv->fw_rev, + (sizeof(k3_fw_rev) / sizeof(k3_fw_rev[0]))); + + if (err != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: Firmware RVF failed\n", __func__); + } } break; @@ -515,14 +518,20 @@ int elecraft_get_firmware_revision_level(RIG *rig, const char *cmd, char buf[KENWOOD_MAX_BUF_LEN]; char rvp = cmd[3]; char *rv = "UNK"; - switch(rvp) + + switch (rvp) { - case 'M': rv = "MCU";break; - case 'D': rv = "DSP";break; - case 'A': rv = "AUX";break; - case 'R': rv = "DVR";break; - case 'F': rv = "FPF";break; - default: rv = "???";break; + case 'M': rv = "MCU"; break; + + case 'D': rv = "DSP"; break; + + case 'A': rv = "AUX"; break; + + case 'R': rv = "DVR"; break; + + case 'F': rv = "FPF"; break; + + default: rv = "???"; break; } rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); @@ -557,7 +566,8 @@ int elecraft_get_firmware_revision_level(RIG *rig, const char *cmd, /* Copy out */ strncpy(fw_rev, bufptr, fw_rev_sz - 1); - rig_debug(RIG_DEBUG_VERBOSE, "%s: Elecraft %s firmware revision is %s\n", __func__, + rig_debug(RIG_DEBUG_VERBOSE, "%s: Elecraft %s firmware revision is %s\n", + __func__, rv, fw_rev); return RIG_OK; diff --git a/rigs/kenwood/flex6xxx.c b/rigs/kenwood/flex6xxx.c index 57c42af89..a386b6366 100644 --- a/rigs/kenwood/flex6xxx.c +++ b/rigs/kenwood/flex6xxx.c @@ -839,21 +839,28 @@ int powersdr_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) break; case RIG_LEVEL_SWR: - { - struct kenwood_priv_caps *priv = kenwood_caps(rig); - ptt_t ptt = 0; - rig_get_ptt(rig, RIG_VFO_CURR, &ptt); - if (ptt == RIG_PTT_OFF) { val->f = priv->swr; return RIG_OK;} - cmd = "ZZRM8"; // get SWR - len = 5; - ans = 8; - retval = kenwood_transaction(rig, cmd, lvlbuf, sizeof(lvlbuf)); - if (retval != RIG_OK) { val->f = priv->swr; return RIG_OK;}; - sscanf(lvlbuf,"ZZRM8%lg", &priv->swr); - val->f = priv->swr; - rig_debug(RIG_DEBUG_ERR, "%s(%d) swr=%.1f\n", __func__, __LINE__, val->f); - return RIG_OK; - } + { + struct kenwood_priv_caps *priv = kenwood_caps(rig); + ptt_t ptt = 0; + rig_get_ptt(rig, RIG_VFO_CURR, &ptt); + + if (ptt == RIG_PTT_OFF) { val->f = priv->swr; return RIG_OK;} + + cmd = "ZZRM8"; // get SWR + len = 5; + ans = 8; + retval = kenwood_transaction(rig, cmd, lvlbuf, sizeof(lvlbuf)); + + if (retval != RIG_OK) { val->f = priv->swr; return RIG_OK;}; + + sscanf(lvlbuf, "ZZRM8%lg", &priv->swr); + + val->f = priv->swr; + + rig_debug(RIG_DEBUG_ERR, "%s(%d) swr=%.1f\n", __func__, __LINE__, val->f); + + return RIG_OK; + } default: return kenwood_get_level(rig, vfo, level, val); @@ -939,28 +946,30 @@ int powersdr_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) case RIG_LEVEL_RFPOWER_METER: case RIG_LEVEL_RFPOWER_METER_WATTS: - { - // if not ptt then no power is going out so return 0W - ptt_t ptt; - rig_get_ptt(rig, RIG_VFO_TX, &ptt); - if (!ptt) { val->f = 0; return RIG_OK; } - n = sscanf(lvlbuf, "ZZRM5%f", &val->f); + { + // if not ptt then no power is going out so return 0W + ptt_t ptt; + rig_get_ptt(rig, RIG_VFO_TX, &ptt); - if (n != 1) - { - rig_debug(RIG_DEBUG_ERR, "%s: Error parsing value from lvlbuf='%s'\n", + if (!ptt) { val->f = 0; return RIG_OK; } + + n = sscanf(lvlbuf, "ZZRM5%f", &val->f); + + if (n != 1) + { + rig_debug(RIG_DEBUG_ERR, "%s: Error parsing value from lvlbuf='%s'\n", __func__, lvlbuf); - val->f = 0; - return -RIG_EPROTO; - } + val->f = 0; + return -RIG_EPROTO; } + } - if (level != RIG_LEVEL_RFPOWER_METER_WATTS) - { - val->f /= 100; - } + if (level != RIG_LEVEL_RFPOWER_METER_WATTS) + { + val->f /= 100; + } - break; + break; case RIG_LEVEL_RF: n = sscanf(lvlbuf + len, "%d", &val->i); @@ -1137,20 +1146,23 @@ int powersdr_set_parm(RIG *rig, setting_t parm, value_t val) rig_debug(RIG_DEBUG_VERBOSE, "%s: val=%s\n", __func__, val.s); - switch(parm) + switch (parm) { - case RIG_PARM_BANDSELECT: - if (strcmp(val.s,"BANDWWV")!=0) + case RIG_PARM_BANDSELECT: + if (strcmp(val.s, "BANDWWV") != 0) + { + int n = sscanf(val.s, "BAND%d", &band); + + if (n != 1) { - int n = sscanf(val.s, "BAND%d", &band); - if (n != 1) - { - rig_debug(RIG_DEBUG_ERR, "%s: unknown band=%s\n", __func__, val.s); - } + rig_debug(RIG_DEBUG_ERR, "%s: unknown band=%s\n", __func__, val.s); } - SNPRINTF(cmd,sizeof(cmd),"ZZBS%03d;", band); - retval = kenwood_transaction(rig, cmd, NULL, 0); + } + + SNPRINTF(cmd, sizeof(cmd), "ZZBS%03d;", band); + retval = kenwood_transaction(rig, cmd, NULL, 0); } + RETURNFUNC(retval); } @@ -1159,47 +1171,66 @@ int powersdr_get_parm(RIG *rig, setting_t parm, value_t *val) char cmd[KENWOOD_MAX_BUF_LEN]; char buf[KENWOOD_MAX_BUF_LEN]; int retval; - int len,ans; + int len, ans; ENTERFUNC; - switch(parm) + switch (parm) { - case RIG_PARM_BANDSELECT: + case RIG_PARM_BANDSELECT: len = 4; ans = 3; - SNPRINTF(cmd,sizeof(cmd),"%s","ZZBS;"); + SNPRINTF(cmd, sizeof(cmd), "%s", "ZZBS;"); break; - default: + + default: RETURNFUNC(-RIG_EINVAL); } + retval = kenwood_safe_transaction(rig, cmd, buf, 10, len + ans); - if (retval != RIG_OK) RETURNFUNC(retval); + + if (retval != RIG_OK) { RETURNFUNC(retval); } + int band; - int n = sscanf(buf,"ZZBS%3d", &band); - if (n != 1) + int n = sscanf(buf, "ZZBS%3d", &band); + + if (n != 1) { rig_debug(RIG_DEBUG_ERR, "%s: unknown band=%s\n", __func__, buf); return (-RIG_EPROTO); } - switch(band) + + switch (band) { - case 160: val->cs = "BAND160M";break; - case 80: val->cs = "BAND80M";break; - case 60: val->cs = "BAND60M";break; - case 40: val->cs = "BAND40M";break; - case 30: val->cs = "BAND30M";break; - case 20: val->cs = "BAND20M";break; - case 17: val->cs = "BAND17M";break; - case 15: val->cs = "BAND15M";break; - case 12: val->cs = "BAND12M";break; - case 10: val->cs = "BAND10M";break; - case 6: val->cs = "BAND6M";break; - case 999: val->cs = "BANDWWV";break; - default: + case 160: val->cs = "BAND160M"; break; + + case 80: val->cs = "BAND80M"; break; + + case 60: val->cs = "BAND60M"; break; + + case 40: val->cs = "BAND40M"; break; + + case 30: val->cs = "BAND30M"; break; + + case 20: val->cs = "BAND20M"; break; + + case 17: val->cs = "BAND17M"; break; + + case 15: val->cs = "BAND15M"; break; + + case 12: val->cs = "BAND12M"; break; + + case 10: val->cs = "BAND10M"; break; + + case 6: val->cs = "BAND6M"; break; + + case 999: val->cs = "BANDWWV"; break; + + default: rig_debug(RIG_DEBUG_ERR, "%s: unknown band=%d\n", __func__, band); - val->cs = "BAND???"; + val->cs = "BAND???"; } + RETURNFUNC(RIG_OK); } @@ -1233,9 +1264,9 @@ struct rig_caps f6k_caps = .has_get_parm = RIG_PARM_NONE, .has_set_parm = RIG_PARM_NONE, /* FIXME: parms */ .level_gran = { - [LVL_KEYSPD] = { .min = { .i = 5 }, .max = { .i = 60 }, .step = { .i = 1 } }, - [LVL_SLOPE_LOW] = { .min = { .i = 10}, .max = { .i = 1000}, .step = { .i = 50} }, - [LVL_SLOPE_HIGH] = { .min = { .i = 1000}, .max = { .i = 5000}, .step = { .i = 10} }, + [LVL_KEYSPD] = { .min = { .i = 5 }, .max = { .i = 60 }, .step = { .i = 1 } }, + [LVL_SLOPE_LOW] = { .min = { .i = 10}, .max = { .i = 1000}, .step = { .i = 50} }, + [LVL_SLOPE_HIGH] = { .min = { .i = 1000}, .max = { .i = 5000}, .step = { .i = 10} }, }, /* FIXME: granularity */ .parm_gran = {}, //.extlevels = elecraft_ext_levels, @@ -1373,7 +1404,7 @@ struct rig_caps powersdr_caps = .has_get_level = POWERSDR_LEVEL_ALL, .has_set_level = POWERSDR_LEVEL_SET, .has_get_parm = RIG_PARM_BANDSELECT, - .has_set_parm = RIG_PARM_BANDSELECT, + .has_set_parm = RIG_PARM_BANDSELECT, .level_gran = { #include "level_gran_kenwood.h" [LVL_KEYSPD] = { .min = { .i = 5 }, .max = { .i = 60 }, .step = { .i = 1 } }, @@ -1381,7 +1412,7 @@ struct rig_caps powersdr_caps = .parm_gran = { // there are V00 thru V13 but we don't cover them as of yet -- what rig? [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BAND60M,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BAND2M,BANDWWV,BANDGEN"}} - }, + }, //.extlevels = elecraft_ext_levels, //.extparms = kenwood_cfg_params, diff --git a/rigs/kenwood/ic10.c b/rigs/kenwood/ic10.c index 28bb8e90a..ed6dfcddc 100644 --- a/rigs/kenwood/ic10.c +++ b/rigs/kenwood/ic10.c @@ -81,6 +81,7 @@ int ic10_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, rig_debug(RIG_DEBUG_ERR, "%s: cmd==NULL?\n", __func__); return -RIG_EARG; } + rig_debug(RIG_DEBUG_TRACE, "%s: called cmd='%s', len=%d, data=%p, data_len=%p\n", __func__, cmd, cmd_len, data, data_len); @@ -151,7 +152,8 @@ transaction: */ static int get_ic10_if(RIG *rig, char *data) { - const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *)rig->caps->priv; + const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *) + rig->caps->priv; int i, data_len, retval = RIG_EINVAL; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -167,7 +169,7 @@ static int get_ic10_if(RIG *rig, char *data) } if (data_len < priv->if_len || - data[0] != 'I' || data[1] != 'F') + data[0] != 'I' || data[1] != 'F') { rig_debug(RIG_DEBUG_WARN, "%s: unexpected answer %s, len=%d\n", __func__, data, data_len); @@ -221,7 +223,8 @@ int ic10_set_vfo(RIG *rig, vfo_t vfo) */ int ic10_get_vfo(RIG *rig, vfo_t *vfo) { - const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *)rig->caps->priv; + const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *) + rig->caps->priv; char vfobuf[50]; unsigned char c; int retval, iflen; @@ -288,7 +291,8 @@ int ic10_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t txvfo) int ic10_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *txvfo) { - const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *)rig->caps->priv; + const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *) + rig->caps->priv; char infobuf[50]; int retval, iflen; @@ -317,7 +321,8 @@ int ic10_get_split_vfo(RIG *rig, vfo_t vfo, split_t *split, vfo_t *txvfo) */ int ic10_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *)rig->caps->priv; + const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *) + rig->caps->priv; char modebuf[50]; unsigned char c; int retval, iflen; @@ -531,7 +536,8 @@ int ic10_get_ant(RIG *rig, vfo_t vfo, ant_t dummy, value_t *option, */ int ic10_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) { - const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *)rig->caps->priv; + const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *) + rig->caps->priv; char infobuf[50]; int retval, iflen, offset; @@ -600,7 +606,8 @@ int ic10_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) */ int ic10_get_mem(RIG *rig, vfo_t vfo, int *ch) { - const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *)rig->caps->priv; + const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *) + rig->caps->priv; char membuf[50]; int retval, iflen; @@ -1155,7 +1162,8 @@ const char *ic10_get_info(RIG *rig) */ int ic10_decode_event(RIG *rig) { - const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *)rig->caps->priv; + const struct kenwood_priv_caps *priv = (struct kenwood_priv_caps *) + rig->caps->priv; char asyncbuf[128], c; int retval, async_len = 128, iflen; vfo_t vfo; diff --git a/rigs/kenwood/k3.c b/rigs/kenwood/k3.c index c6f9a88fc..586272b19 100644 --- a/rigs/kenwood/k3.c +++ b/rigs/kenwood/k3.c @@ -2867,15 +2867,20 @@ int k3_send_voice_mem(RIG *rig, vfo_t vfo, int ch) if (ch < 1 || ch > 4) { rig_debug(RIG_DEBUG_ERR, "%s: expected 1<=ch<=4, got %d\n", __func__, ch); - return(-RIG_EINVAL); + return (-RIG_EINVAL); } - switch(ch) + + switch (ch) { - case 1: cmd = "SWT21;";break; - case 2: cmd = "SWT31;";break; - case 3: cmd = "SWT35;";break; - case 4: cmd = "SWT39;";break; + case 1: cmd = "SWT21;"; break; + + case 2: cmd = "SWT31;"; break; + + case 3: cmd = "SWT35;"; break; + + case 4: cmd = "SWT39;"; break; } + retval = kenwood_transaction(rig, cmd, NULL, 0); return retval; } @@ -2895,8 +2900,9 @@ int k4_send_voice_mem(RIG *rig, vfo_t vfo, int ch) if (ch < 1 || ch > 8) { rig_debug(RIG_DEBUG_ERR, "%s: expected 1<=ch<=8, got %d\n", __func__, ch); - return(-RIG_EINVAL); + return (-RIG_EINVAL); } + sprintf(cmd, "DAMP%d00000;", ch); retval = kenwood_transaction(rig, cmd, NULL, 0); return retval; @@ -2920,7 +2926,7 @@ int k3_stop_morse(RIG *rig, vfo_t vfo) { int retval; char cmd[32]; - SNPRINTF(cmd,sizeof(cmd),"KY %c;", 0x04); + SNPRINTF(cmd, sizeof(cmd), "KY %c;", 0x04); retval = kenwood_transaction(rig, cmd, NULL, 0); return retval; } diff --git a/rigs/kenwood/kenwood.c b/rigs/kenwood/kenwood.c index 605bdcb51..c234a1646 100644 --- a/rigs/kenwood/kenwood.c +++ b/rigs/kenwood/kenwood.c @@ -246,15 +246,17 @@ int kenwood_transaction(RIG *rig, const char *cmdstr, char *data, struct kenwood_priv_caps *caps = kenwood_caps(rig); struct rig_state *rs; - if (datasize > 0 && datasize < (cmdstr ? strlen(cmdstr) : 0)) { - rig_debug(RIG_DEBUG_WARN, "%s called cmd=%s datasize=%d, datasize < cmd length?\n", __func__, - cmdstr ? cmdstr : "(NULL)", - (int)datasize); - } + if (datasize > 0 && datasize < (cmdstr ? strlen(cmdstr) : 0)) + { + rig_debug(RIG_DEBUG_WARN, + "%s called cmd=%s datasize=%d, datasize < cmd length?\n", __func__, + cmdstr ? cmdstr : "(NULL)", + (int)datasize); + } else { - rig_debug(RIG_DEBUG_VERBOSE, "%s called cmd=%s\n", __func__, - cmdstr ? cmdstr : "(NULL)"); + rig_debug(RIG_DEBUG_VERBOSE, "%s called cmd=%s\n", __func__, + cmdstr ? cmdstr : "(NULL)"); } if ((!cmdstr && !datasize) || (datasize && !data)) @@ -358,8 +360,11 @@ transaction_write: if (skip) { // most command we give them a little time -- but not KY - if (strncmp(cmdstr, "KY ", 3)!= 0) - hl_usleep(200 * 1000); // give little settle time for these commands + if (strncmp(cmdstr, "KY ", 3) != 0) + { + hl_usleep(200 * 1000); // give little settle time for these commands + } + goto transaction_quit; } } @@ -367,7 +372,7 @@ transaction_write: // Malachite SDR cannot send ID after FA if (!datasize && priv->no_id) { RETURNFUNC2(RIG_OK); } - if (!datasize && strncmp(cmdstr, "KY",2)!=0) + if (!datasize && strncmp(cmdstr, "KY", 2) != 0) { rig->state.transaction_active = 0; @@ -720,13 +725,18 @@ int kenwood_safe_transaction(RIG *rig, const char *cmd, char *buf, occasionally send short results */ { // QRPLABS can't seem top decide if they give 37 or 38 bytes for IF command - if (strncmp(cmd,"IF",2)==0 && rig->caps->rig_model == RIG_MODEL_QRPLABS) break; + if (strncmp(cmd, "IF", 2) == 0 && rig->caps->rig_model == RIG_MODEL_QRPLABS) { break; } + struct kenwood_priv_data *priv = rig->state.priv; + rig_debug(RIG_DEBUG_ERR, "%s: wrong answer; len for cmd %s: expected = %d, got %d\n", __func__, cmd, (int)expected, (int)length); + err = -RIG_EPROTO; + elapsed_ms(&priv->cache_start, HAMLIB_ELAPSED_INVALIDATE); + hl_usleep(50 * 1000); // let's do a short wait } } @@ -1160,7 +1170,7 @@ int kenwood_get_if(RIG *rig) int post_write_delay_save = 0; ENTERFUNC; - + // Malachite has a 400ms delay but some get commands can work with no delay if (RIG_IS_MALACHITE) { @@ -1169,12 +1179,13 @@ int kenwood_get_if(RIG *rig) } retval = kenwood_safe_transaction(rig, "IF", priv->info, - KENWOOD_MAX_BUF_LEN, caps->if_len); + KENWOOD_MAX_BUF_LEN, caps->if_len); if (RIG_IS_MALACHITE) { rig->state.post_write_delay = post_write_delay_save; } + RETURNFUNC(retval); } @@ -1862,9 +1873,9 @@ int kenwood_set_freq(RIG *rig, vfo_t vfo, freq_t freq) } // Malchite is so slow we don't do the get_freq - // And when we have detected Doppler operations we just set the freq all the time + // And when we have detected Doppler operations we just set the freq all the time // This should provide stable timing for set_ptt operation so relay delays are consistent - if (!RIG_IS_MALACHITE && rig->state.doppler == 0) + if (!RIG_IS_MALACHITE && rig->state.doppler == 0) { rig_get_freq(rig, tvfo, &tfreq); @@ -2461,6 +2472,7 @@ int kenwood_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { SNPRINTF(buf, sizeof(buf), "MD%c", c); err = kenwood_transaction(rig, buf, NULL, 0); + if (err != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: MD cmd failed: %s\n", __func__, rigerror(err)); @@ -3150,6 +3162,7 @@ int kenwood_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) /* Check input parameter against level_gran limits */ result = check_level_param(rig, level, val, &level_info); + if (result != RIG_OK) { RETURNFUNC(result); } if (RIG_LEVEL_IS_FLOAT(level)) @@ -3534,7 +3547,7 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } level_info = &rig->caps->level_gran[rig_setting2idx(level)]; - + switch (level) { int power_now, power_min, power_max; @@ -3882,6 +3895,7 @@ int kenwood_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) rig_debug(RIG_DEBUG_ERR, "%s: Error getting MICGAIN\n", __func__); RETURNFUNC(ret); } + vali = val->i; val->f = (vali - priv->micgain_min) / (float)(priv->micgain_max - priv->micgain_min); @@ -5001,7 +5015,8 @@ int kenwood_set_trn(RIG *rig, int trn) switch (rig->caps->rig_model) { - char buf[5]; + char buf[5]; + case RIG_MODEL_POWERSDR: // powersdr doesn't have AI command RETURNFUNC(-RIG_ENAVAIL); @@ -5209,6 +5224,7 @@ int kenwood_get_powerstat(RIG *rig, powerstat_t *status) rig_flush(&rig->state.rigport); result = kenwood_safe_transaction(rig, "PS", pwrbuf, 6, 3); + if (result != RIG_OK) { RETURNFUNC(result); @@ -5314,7 +5330,7 @@ int kenwood_send_morse(RIG *rig, vfo_t vfo, const char *msg) if (!strncmp(m2, "KY2", 3)) { break; } - if (!strncmp(m2, "KY1", 3)) { hl_usleep(50*1000); } + if (!strncmp(m2, "KY1", 3)) { hl_usleep(50 * 1000); } else { RETURNFUNC(-RIG_EINVAL); } } @@ -5386,25 +5402,28 @@ int kenwood_send_voice_mem(RIG *rig, vfo_t vfo, int bank) SNPRINTF(cmd, sizeof(cmd), "PB01"); kenwood_transaction(rig, cmd, NULL, 0); #endif + if ((bank < 1 || bank > 3) && - (rig->caps->rig_model == RIG_MODEL_TS2000 - || rig->caps->rig_model == RIG_MODEL_TS480)) + (rig->caps->rig_model == RIG_MODEL_TS2000 + || rig->caps->rig_model == RIG_MODEL_TS480)) { rig_debug(RIG_DEBUG_ERR, "%s: TS2000/TS480 channel is from 1 to 3\n", __func__); return -RIG_EINVAL; } + // some rigs have 5 channels -- newew ones have 10 channels if ((bank < 1 || bank > 5) - && (rig->caps->rig_model == RIG_MODEL_TS590SG - || rig->caps->rig_model == RIG_MODEL_TS590S)) + && (rig->caps->rig_model == RIG_MODEL_TS590SG + || rig->caps->rig_model == RIG_MODEL_TS590S)) { rig_debug(RIG_DEBUG_ERR, "%s: TS590S/SG channel is from 1 to 5\n", __func__); return -RIG_EINVAL; } + if (rig->caps->rig_model == RIG_MODEL_TS2000 - || (rig->caps->rig_model == RIG_MODEL_TS480 - || (rig->caps->rig_model == RIG_MODEL_TS590SG - || rig->caps->rig_model == RIG_MODEL_TS590S))) + || (rig->caps->rig_model == RIG_MODEL_TS480 + || (rig->caps->rig_model == RIG_MODEL_TS590SG + || rig->caps->rig_model == RIG_MODEL_TS590S))) { SNPRINTF(cmd, sizeof(cmd), "PB%d", bank); } @@ -5412,6 +5431,7 @@ int kenwood_send_voice_mem(RIG *rig, vfo_t vfo, int bank) { SNPRINTF(cmd, sizeof(cmd), "PB1%d1", bank); } + priv->voice_bank = bank; RETURNFUNC(kenwood_transaction(rig, cmd, NULL, 0)); } @@ -5421,10 +5441,11 @@ int kenwood_stop_voice_mem(RIG *rig, vfo_t vfo) char cmd[16]; struct kenwood_priv_data *priv = rig->state.priv; ENTERFUNC; + if (rig->caps->rig_model == RIG_MODEL_TS2000 - || (rig->caps->rig_model == RIG_MODEL_TS480 - || (rig->caps->rig_model == RIG_MODEL_TS590SG - || rig->caps->rig_model == RIG_MODEL_TS590S))) + || (rig->caps->rig_model == RIG_MODEL_TS480 + || (rig->caps->rig_model == RIG_MODEL_TS590SG + || rig->caps->rig_model == RIG_MODEL_TS590S))) { SNPRINTF(cmd, sizeof(cmd), "PB0"); } @@ -5432,6 +5453,7 @@ int kenwood_stop_voice_mem(RIG *rig, vfo_t vfo) { SNPRINTF(cmd, sizeof(cmd), "PB1%d0", priv->voice_bank); } + RETURNFUNC(kenwood_transaction(rig, cmd, NULL, 0)); } diff --git a/rigs/kenwood/pihpsdr.c b/rigs/kenwood/pihpsdr.c index d368a2b95..b802f3d5a 100644 --- a/rigs/kenwood/pihpsdr.c +++ b/rigs/kenwood/pihpsdr.c @@ -832,7 +832,9 @@ int pihpsdr_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) else if (kenwood_val == RIG_AGC_SLOW) { kenwood_val = 20; } else if (kenwood_val != RIG_AGC_OFF) { - rig_debug(RIG_DEBUG_ERR, "%s: unknown AGC level, expect OFF,SLOW,MEDIUM,FAST,SUPERFAST, got %d\n", __func__, kenwood_val); + rig_debug(RIG_DEBUG_ERR, + "%s: unknown AGC level, expect OFF,SLOW,MEDIUM,FAST,SUPERFAST, got %d\n", + __func__, kenwood_val); return -RIG_EINVAL; } diff --git a/rigs/kenwood/th.c b/rigs/kenwood/th.c index 3a2991c45..5e3e6b7ae 100644 --- a/rigs/kenwood/th.c +++ b/rigs/kenwood/th.c @@ -73,7 +73,7 @@ th_decode_event(RIG *rig) retval = num_sscanf(asyncbuf, "BUF %u,%"SCNfreq",%X,%d,%d,%d,%d,,%d,,%d,%"SCNfreq",%d", - &vfo, &freq, (unsigned int*)&step, &shift, &rev, &tone, + &vfo, &freq, (unsigned int *)&step, &shift, &rev, &tone, &ctcss, &tonefq, &ctcssfq, &offset, &mode); if (retval != 11) @@ -268,7 +268,7 @@ th_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) return retval; } - retval = num_sscanf(buf, "FQ %"SCNfreq",%x", freq, (unsigned*)&step); + retval = num_sscanf(buf, "FQ %"SCNfreq",%x", freq, (unsigned *)&step); if (retval != 2) { diff --git a/rigs/kenwood/thd72.c b/rigs/kenwood/thd72.c index 0c138550b..34fe6a71e 100644 --- a/rigs/kenwood/thd72.c +++ b/rigs/kenwood/thd72.c @@ -1282,11 +1282,13 @@ static int thd72_parse_channel(int kind, const char *buf, channel_t *chan) else { data = buf + 7; } n = sscanf(data, "%"SCNfreq, &chan->freq); + if (n != 1) { rig_debug(RIG_DEBUG_ERR, "%s: error scanning %s\n", __func__, data); return -RIG_EPROTO; } + c = data[46]; // mode if (c >= '0' && c <= '2') @@ -1310,16 +1312,19 @@ static int thd72_parse_channel(int kind, const char *buf, channel_t *chan) } n = sscanf(data + 37, "%ld", &chan->rptr_offs); + if (n != 1) { rig_debug(RIG_DEBUG_ERR, "%s: error scanning data[37]%s\n", __func__, data); return -RIG_EPROTO; } + c = data[17]; // Tone status if (c != '0') { n = sscanf(data + 25, "%d", &tmp); + if (n != 1) { rig_debug(RIG_DEBUG_ERR, "%s: error scanning data[25]%s\n", __func__, data); @@ -1341,6 +1346,7 @@ static int thd72_parse_channel(int kind, const char *buf, channel_t *chan) if (c != '0') { n = sscanf(data + 28, "%d", &tmp); + if (n != 1) { rig_debug(RIG_DEBUG_ERR, "%s: error scanning data[28]%s\n", __func__, data); @@ -1362,11 +1368,13 @@ static int thd72_parse_channel(int kind, const char *buf, channel_t *chan) if (c != '0') { n = sscanf(data + 31, "%d", &tmp); + if (n != 1) { rig_debug(RIG_DEBUG_ERR, "%s: error scanning data[31]%s\n", __func__, data); return -RIG_EPROTO; } + chan->dcs_code = tmp; } else diff --git a/rigs/kenwood/tmd710.c b/rigs/kenwood/tmd710.c index 07b092ad4..64d99cbbf 100644 --- a/rigs/kenwood/tmd710.c +++ b/rigs/kenwood/tmd710.c @@ -815,10 +815,10 @@ static int tmd710_scan_me(char *buf, tmd710_me *me_struct) retval = num_sscanf(buf, "ME %x,%"SCNfreq",%x,%x,%x,%x,%x,%x,%d,%d,%d,%d,%d,%"SCNfreq",%d,%d", - (unsigned int*)&me_struct->channel, &me_struct->freq, - (unsigned int*)&me_struct->step, (unsigned int*)&me_struct->shift, - (unsigned int*)&me_struct->reverse, (unsigned int*)&me_struct->tone, - (unsigned int*)&me_struct->ct, (unsigned int*)&me_struct->dcs, + (unsigned int *)&me_struct->channel, &me_struct->freq, + (unsigned int *)&me_struct->step, (unsigned int *)&me_struct->shift, + (unsigned int *)&me_struct->reverse, (unsigned int *)&me_struct->tone, + (unsigned int *)&me_struct->ct, (unsigned int *)&me_struct->dcs, &me_struct->tone_freq, &me_struct->ct_freq, &me_struct->dcs_val, &me_struct->offset, &me_struct->mode, &me_struct->tx_freq, @@ -963,10 +963,10 @@ int tmd710_pull_fo(RIG *rig, vfo_t vfo, tmd710_fo *fo_struct) } retval = num_sscanf(buf, "FO %x,%"SCNfreq",%x,%x,%x,%x,%x,%x,%d,%d,%d,%d,%d", - (unsigned int*)&fo_struct->vfo, &fo_struct->freq, - (unsigned int*)&fo_struct->step, (unsigned int*)&fo_struct->shift, - (unsigned int*)&fo_struct->reverse, (unsigned int*)&fo_struct->tone, - (unsigned int*)&fo_struct->ct, (unsigned int*)&fo_struct->dcs, + (unsigned int *)&fo_struct->vfo, &fo_struct->freq, + (unsigned int *)&fo_struct->step, (unsigned int *)&fo_struct->shift, + (unsigned int *)&fo_struct->reverse, (unsigned int *)&fo_struct->tone, + (unsigned int *)&fo_struct->ct, (unsigned int *)&fo_struct->dcs, &fo_struct->tone_freq, &fo_struct->ct_freq, &fo_struct->dcs_val, &fo_struct->offset, &fo_struct->mode); @@ -1006,10 +1006,10 @@ int tmd710_push_fo(RIG *rig, vfo_t vfo, tmd710_fo *fo_struct) } retval = num_sscanf(buf, "FO %x,%"SCNfreq",%x,%x,%x,%x,%x,%x,%d,%d,%d,%d,%d", - (unsigned int*)&fo_struct->vfo, &fo_struct->freq, - (unsigned int*)&fo_struct->step, (unsigned int*)&fo_struct->shift, - (unsigned int*)&fo_struct->reverse, (unsigned int*)&fo_struct->tone, - (unsigned int*)&fo_struct->ct, (unsigned int*)&fo_struct->dcs, + (unsigned int *)&fo_struct->vfo, &fo_struct->freq, + (unsigned int *)&fo_struct->step, (unsigned int *)&fo_struct->shift, + (unsigned int *)&fo_struct->reverse, (unsigned int *)&fo_struct->tone, + (unsigned int *)&fo_struct->ct, (unsigned int *)&fo_struct->dcs, &fo_struct->tone_freq, &fo_struct->ct_freq, &fo_struct->dcs_val, &fo_struct->offset, &fo_struct->mode); @@ -1061,12 +1061,12 @@ int tmd710_scan_mu(char *buf, tmd710_mu *mu_struct) &mu_struct->brightness_level, &mu_struct->auto_brightness, &mu_struct->backlight_color, - (unsigned int*)&mu_struct->pf1_key, - (unsigned int*)&mu_struct->pf2_key, - (unsigned int*)&mu_struct->mic_pf1_key, - (unsigned int*)&mu_struct->mic_pf2_key, - (unsigned int*)&mu_struct->mic_pf3_key, - (unsigned int*)&mu_struct->mic_pf4_key, + (unsigned int *)&mu_struct->pf1_key, + (unsigned int *)&mu_struct->pf2_key, + (unsigned int *)&mu_struct->mic_pf1_key, + (unsigned int *)&mu_struct->mic_pf2_key, + (unsigned int *)&mu_struct->mic_pf3_key, + (unsigned int *)&mu_struct->mic_pf4_key, &mu_struct->mic_key_lock, &mu_struct->scan_resume, &mu_struct->auto_power_off, @@ -2491,7 +2491,7 @@ int tmd710_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return retval; } - retval = sscanf(ackbuf, "SQ %X", (unsigned int*)&l); + retval = sscanf(ackbuf, "SQ %X", (unsigned int *)&l); if (retval != 1 || l < TMD710_SQL_MIN || l > TMD710_SQL_MAX) { diff --git a/rigs/kenwood/ts590.c b/rigs/kenwood/ts590.c index 5a21fdfad..e2cf81415 100644 --- a/rigs/kenwood/ts590.c +++ b/rigs/kenwood/ts590.c @@ -261,6 +261,7 @@ static int ts590_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) if (vfo == RIG_VFO_TX || vfo == RIG_VFO_RX) { vfo = vfo_fixup(rig, vfo, rig->state.cache.split); } retval = RIG_OK; + if (!sf_fails) { SNPRINTF(cmd, sizeof(cmd), "SF%d", vfo == RIG_VFO_A ? 0 : 1); @@ -284,11 +285,14 @@ static int ts590_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) // now let's get our widths SNPRINTF(cmd, sizeof(cmd), "SH"); retval = kenwood_safe_transaction(rig, cmd, ackbuf, sizeof(ackbuf), 4); + if (retval != RIG_OK) { - rig_debug(RIG_DEBUG_ERR, "%s: SH command failed: %s\n", __func__, rigerror(retval)); + rig_debug(RIG_DEBUG_ERR, "%s: SH command failed: %s\n", __func__, + rigerror(retval)); return retval; } + int hwidth; sscanf(cmd, "SH%d", &hwidth); int lwidth; @@ -296,9 +300,11 @@ static int ts590_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) SNPRINTF(cmd, sizeof(cmd), "SL"); sscanf(cmd, "SH%d", &lwidth); retval = kenwood_safe_transaction(rig, cmd, ackbuf, sizeof(ackbuf), 4); + if (retval != RIG_OK) { - rig_debug(RIG_DEBUG_ERR, "%s: SL command failed: %s\n", __func__, rigerror(retval)); + rig_debug(RIG_DEBUG_ERR, "%s: SL command failed: %s\n", __func__, + rigerror(retval)); return retval; } @@ -463,14 +469,18 @@ static int ts590_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) case RIG_LEVEL_USB_AF: kenwood_val = val.f * 9; cmd = 65; // TS-590S - if (rig->caps->rig_model == RIG_MODEL_TS590SG) cmd=72; + + if (rig->caps->rig_model == RIG_MODEL_TS590SG) { cmd = 72; } + SNPRINTF(levelbuf, sizeof(levelbuf), "EX%03d0000%d", cmd, kenwood_val); break; case RIG_LEVEL_USB_AF_INPUT: kenwood_val = val.f * 9; cmd = 64; // TS-590S - if (rig->caps->rig_model == RIG_MODEL_TS590SG) cmd=71; + + if (rig->caps->rig_model == RIG_MODEL_TS590SG) { cmd = 71; } + SNPRINTF(levelbuf, sizeof(levelbuf), "EX%03d0000%d", cmd, kenwood_val); break; @@ -649,14 +659,18 @@ static int ts590_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { case RIG_LEVEL_USB_AF: cmd = 65; // TS-590S - if (rig->caps->rig_model == RIG_MODEL_TS590SG) cmd=72; + + if (rig->caps->rig_model == RIG_MODEL_TS590SG) { cmd = 72; } + retval = ts590_get_ex_menu(rig, cmd, 1, &levelint); val->f = levelint / 9.0; return retval; case RIG_LEVEL_USB_AF_INPUT: cmd = 65; // TS-590S - if (rig->caps->rig_model == RIG_MODEL_TS590SG) cmd=71; + + if (rig->caps->rig_model == RIG_MODEL_TS590SG) { cmd = 71; } + retval = ts590_get_ex_menu(rig, cmd, 1, &levelint); val->f = levelint / 9.0; return retval; @@ -914,8 +928,12 @@ static int ts590_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) sscanf(ackbuf, "SM0%d", &raw_value); val->f = (float) raw_value / 30.0f; + if (level == RIG_LEVEL_RFPOWER_METER_WATTS) + { val->f *= 100; + } + break; } diff --git a/rigs/kenwood/ts870s.c b/rigs/kenwood/ts870s.c index c6ec8ecf6..55e0550c6 100644 --- a/rigs/kenwood/ts870s.c +++ b/rigs/kenwood/ts870s.c @@ -565,7 +565,7 @@ struct rig_caps ts870s_caps = .level_gran = { #include "level_gran_kenwood.h" - [LVL_ATT] = { .min = { .i = 0 }, .max = { .i = 18 }, .step = { .i = 6 } }, + [LVL_ATT] = { .min = { .i = 0 }, .max = { .i = 18 }, .step = { .i = 6 } }, }, .parm_gran = {}, .ctcss_list = kenwood38_ctcss_list, diff --git a/rigs/kenwood/ts890s.c b/rigs/kenwood/ts890s.c index fdb3695e6..30e0ca09b 100644 --- a/rigs/kenwood/ts890s.c +++ b/rigs/kenwood/ts890s.c @@ -50,11 +50,12 @@ int kenwood_ts890_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); retval = check_level_param(rig, level, val, &level_info); + if (retval != RIG_OK) - { - return retval; - } - + { + return retval; + } + switch (level) { case RIG_LEVEL_AGC: @@ -62,20 +63,22 @@ int kenwood_ts890_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) /* possible values for TS890 0(=off), 1(=slow), 2(=mid), 3(=fast), 4(=off/Last) */ rig_debug(RIG_DEBUG_VERBOSE, "%s TS890S RIG_LEVEL_AGC\n", __func__); - kenwood_val = -1; /* Flag invalid value */ - for (int j = 0; j < rig->caps->agc_level_count; j++) - { - if (val.i == rig->caps->agc_levels[j]) - { - kenwood_val = j; - break; - } - } - if ( kenwood_val < 0) - { + kenwood_val = -1; /* Flag invalid value */ + + for (int j = 0; j < rig->caps->agc_level_count; j++) + { + if (val.i == rig->caps->agc_levels[j]) + { + kenwood_val = j; + break; + } + } + + if (kenwood_val < 0) + { rig_debug(RIG_DEBUG_ERR, "%s: unsupported agc value:%d\n", __func__, val.i); return -RIG_EINVAL; - } + } SNPRINTF(levelbuf, sizeof(levelbuf), "GC%d", kenwood_val); return kenwood_transaction(rig, levelbuf, NULL, 0); /* Odd man out */ @@ -189,16 +192,17 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) return retval; } - levelint = ackbuf[2] - '0'; /* atoi */ - if (levelint >= 0 && levelint < rig->caps->agc_level_count) - { - val->i = rig->caps->agc_levels[levelint]; - } - else - { + levelint = ackbuf[2] - '0'; /* atoi */ + + if (levelint >= 0 && levelint < rig->caps->agc_level_count) + { + val->i = rig->caps->agc_levels[levelint]; + } + else + { rig_debug(RIG_DEBUG_ERR, "%s: unknown agc value: %s\n", __func__, ackbuf); return -RIG_EPROTO; - } + } return RIG_OK; @@ -344,13 +348,17 @@ int kenwood_ts890_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) case RIG_LEVEL_USB_AF: case RIG_LEVEL_USB_AF_INPUT: - if ( level == RIG_LEVEL_USB_AF ) - { command_string = "EX00708"; } + if (level == RIG_LEVEL_USB_AF) + { command_string = "EX00708"; } else - { command_string = "EX00706"; } + { command_string = "EX00706"; } + len = strlen(command_string); - retval = kenwood_safe_transaction(rig, command_string, ackbuf, sizeof(ackbuf), len + 4); + retval = kenwood_safe_transaction(rig, command_string, ackbuf, sizeof(ackbuf), + len + 4); + if (retval != RIG_OK) { return retval; } + sscanf(&ackbuf[len + 1], "%3d", &levelint); /* Skip the extra space */ val->f = levelint * level_info->step.f; return RIG_OK; @@ -542,8 +550,8 @@ struct rig_caps ts890s_caps = [LVL_ATT] = { .min = { .i = 0 }, .max = { .i = 18 }, .step = { .i = 6 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 1100 }, .step = { .i = 5 } }, [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0f }, .step = { .f = 1.0 / 255.0 } }, - [LVL_USB_AF] = { .min = { .f = 0 }, .max = { .f = 1.0f }, .step = { .f = 1.0/100.0 } }, - [LVL_USB_AF_INPUT] = { .min = { .f = 0 }, .max = { .f = 1.0f }, .step = { .f = 1.0/100.0 } }, + [LVL_USB_AF] = { .min = { .f = 0 }, .max = { .f = 1.0f }, .step = { .f = 1.0 / 100.0 } }, + [LVL_USB_AF_INPUT] = { .min = { .f = 0 }, .max = { .f = 1.0f }, .step = { .f = 1.0 / 100.0 } }, }, .has_get_func = TS890_FUNC_ALL, .has_set_func = TS890_FUNC_ALL, diff --git a/rigs/kenwood/ts930.c b/rigs/kenwood/ts930.c index 4bc8859ed..72f3c9088 100644 --- a/rigs/kenwood/ts930.c +++ b/rigs/kenwood/ts930.c @@ -80,7 +80,7 @@ struct rig_caps ts930_caps = .level_gran = { #include "level_gran_kenwood.h" - [LVL_ATT] = { .min = { .i = 0 }, .max = { .i = 18 }, .step = { .i = 6 } }, + [LVL_ATT] = { .min = { .i = 0 }, .max = { .i = 18 }, .step = { .i = 6 } }, }, .parm_gran = {}, .preamp = { RIG_DBLST_END, }, /* FIXME: preamp list */ diff --git a/rigs/kenwood/ts990s.c b/rigs/kenwood/ts990s.c index 7445226e1..c5fc7eb5a 100644 --- a/rigs/kenwood/ts990s.c +++ b/rigs/kenwood/ts990s.c @@ -162,7 +162,7 @@ struct rig_caps ts990s_caps = #include "level_gran_kenwood.h" [LVL_ATT] = { .min = { .i = 0 }, .max = { .i = 18 }, .step = { .i = 6 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 1100 }, .step = { .i = 10 } }, - [LVL_COMP] = { .min = { .f = 0.0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, + [LVL_COMP] = { .min = { .f = 0.0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, }, .parm_gran = {}, .vfo_ops = TS990S_VFO_OP, @@ -648,13 +648,14 @@ int ts990s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) case RIG_LEVEL_SWR: retval = get_kenwood_meter_reading(rig, '2', &lvl); + if (retval != RIG_OK) { return retval; } val->f = rig_raw2val_float(lvl, &rig->caps->swr_cal); - val->f = round(val->f*10)/10.0; // 1 decimal place precision + val->f = round(val->f * 10) / 10.0; // 1 decimal place precision break; case RIG_LEVEL_METER: @@ -739,7 +740,7 @@ int ts990s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } } break; - + default: rig_debug(RIG_DEBUG_ERR, "%s: unsupported get_level %s", __func__, rig_strlevel(level)); diff --git a/rigs/kit/elektor507.c b/rigs/kit/elektor507.c index a7b41aef5..5d095bd4d 100644 --- a/rigs/kit/elektor507.c +++ b/rigs/kit/elektor507.c @@ -1120,7 +1120,7 @@ int elektor507_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int elektor507_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { const struct elektor507_priv_data *priv = (struct elektor507_priv_data *) - rig->state.priv; + rig->state.priv; int ret = 0; switch (level) @@ -1197,7 +1197,7 @@ int elektor507_get_ant(RIG *rig, vfo_t vfo, ant_t dummy, value_t *option, ant_t *ant_curr, ant_t *ant_tx, ant_t *ant_rx) { const struct elektor507_priv_data *priv = (struct elektor507_priv_data *) - rig->state.priv; + rig->state.priv; *ant_curr = priv->ant; @@ -1211,7 +1211,7 @@ int elektor507_get_ant(RIG *rig, vfo_t vfo, ant_t dummy, value_t *option, static int cy_update_pll(RIG *rig, unsigned char IICadr) { const struct elektor507_priv_data *priv = (struct elektor507_priv_data *) - rig->state.priv; + rig->state.priv; int P0, R40, R41, R42; unsigned char Div1N; unsigned char Clk3_src; diff --git a/rigs/kit/fifisdr.c b/rigs/kit/fifisdr.c index 623e492f9..70e7c07bb 100644 --- a/rigs/kit/fifisdr.c +++ b/rigs/kit/fifisdr.c @@ -424,7 +424,8 @@ const char *fifisdr_get_info(RIG *rig) int fifisdr_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { - const struct fifisdr_priv_instance_data *priv = (struct fifisdr_priv_instance_data *) + const struct fifisdr_priv_instance_data *priv = (struct + fifisdr_priv_instance_data *) rig->state.priv; int ret; double mhz; @@ -450,7 +451,8 @@ int fifisdr_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int fifisdr_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - const struct fifisdr_priv_instance_data *priv = (struct fifisdr_priv_instance_data *) + const struct fifisdr_priv_instance_data *priv = (struct + fifisdr_priv_instance_data *) rig->state.priv; int ret; uint32_t freq1121; diff --git a/rigs/kit/funcube.c b/rigs/kit/funcube.c index eeb5790db..0f28484ab 100644 --- a/rigs/kit/funcube.c +++ b/rigs/kit/funcube.c @@ -447,7 +447,8 @@ int funcube_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int get_freq_v0(RIG *rig, vfo_t vfo, freq_t *freq) { - const struct funcube_priv_data *priv = (struct funcube_priv_data *)rig->state.priv; + const struct funcube_priv_data *priv = (struct funcube_priv_data *) + rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s: frequency is not read from the device, the value shown is the last successfully set.\n", diff --git a/rigs/kit/hiqsdr.c b/rigs/kit/hiqsdr.c index 929706380..0215d8f39 100644 --- a/rigs/kit/hiqsdr.c +++ b/rigs/kit/hiqsdr.c @@ -188,7 +188,8 @@ struct rig_caps hiqsdr_caps = static int send_command(RIG *rig) { - const struct hiqsdr_priv_data *priv = (struct hiqsdr_priv_data *)rig->state.priv; + const struct hiqsdr_priv_data *priv = (struct hiqsdr_priv_data *) + rig->state.priv; int ret; ret = write_block(&rig->state.rigport, (unsigned char *) priv->control_frame, diff --git a/rigs/kit/rs_hfiq.c b/rigs/kit/rs_hfiq.c index bd726cd16..af8995fbf 100644 --- a/rigs/kit/rs_hfiq.c +++ b/rigs/kit/rs_hfiq.c @@ -241,7 +241,8 @@ static int rshfiq_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) static int rshfiq_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { // cppcheck-suppress syntaxError - rig_debug(RIG_DEBUG_VERBOSE, "%s called. level type =%"PRIll"\n", __func__, level); + rig_debug(RIG_DEBUG_VERBOSE, "%s called. level type =%"PRIll"\n", __func__, + level); char cmdstr[15]; char stopset[2]; diff --git a/rigs/kit/si570avrusb.c b/rigs/kit/si570avrusb.c index 86b0b0163..50e0ca89e 100644 --- a/rigs/kit/si570avrusb.c +++ b/rigs/kit/si570avrusb.c @@ -1112,7 +1112,7 @@ static const int HS_DIV_MAP[] = {4, 5, 6, 7, -1, 9, -1, 11}; static int calcDividers(RIG *rig, double f, struct solution *solution) { const struct si570xxxusb_priv_data *priv = (struct si570xxxusb_priv_data *) - rig->state.priv; + rig->state.priv; struct solution sols[8]; int i; int imin; @@ -1194,7 +1194,7 @@ static int calcDividers(RIG *rig, double f, struct solution *solution) int si570xxxusb_set_freq(RIG *rig, vfo_t vfo, freq_t freq) { const struct si570xxxusb_priv_data *priv = (struct si570xxxusb_priv_data *) - rig->state.priv; + rig->state.priv; libusb_device_handle *udh = rig->state.rigport.handle; int ret; unsigned char buffer[6]; @@ -1260,7 +1260,7 @@ int si570xxxusb_set_freq(RIG *rig, vfo_t vfo, freq_t freq) int si570xxxusb_set_freq_by_value(RIG *rig, vfo_t vfo, freq_t freq) { const struct si570xxxusb_priv_data *priv = (struct si570xxxusb_priv_data *) - rig->state.priv; + rig->state.priv; libusb_device_handle *udh = rig->state.rigport.handle; int ret; @@ -1299,7 +1299,7 @@ int si570xxxusb_set_freq_by_value(RIG *rig, vfo_t vfo, freq_t freq) static double calculateFrequency(RIG *rig, const unsigned char *buffer) { const struct si570xxxusb_priv_data *priv = (struct si570xxxusb_priv_data *) - rig->state.priv; + rig->state.priv; int RFREQ_int = ((buffer[2] & 0xf0) >> 4) + ((buffer[1] & 0x3f) * 16); int RFREQ_frac = (256 * 256 * 256 * (buffer[2] & 0xf)) + @@ -1362,7 +1362,7 @@ int si570xxxusb_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) int si570xxxusb_get_freq_by_value(RIG *rig, vfo_t vfo, freq_t *freq) { const struct si570xxxusb_priv_data *priv = (struct si570xxxusb_priv_data *) - rig->state.priv; + rig->state.priv; libusb_device_handle *udh = rig->state.rigport.handle; int ret; unsigned char buffer[4]; diff --git a/rigs/mds/mds.c b/rigs/mds/mds.c index 9a2583e39..eda3796d9 100644 --- a/rigs/mds/mds.c +++ b/rigs/mds/mds.c @@ -563,10 +563,13 @@ int mds_open(RIG *rig) ENTERFUNC; mds_get_info(rig); retval = mds_transaction(rig, "MODEM NONE", 0, &response); + if (retval != RIG_OK) { - rig_debug(RIG_DEBUG_ERR, "%s: MODEM cmd failed: %s\n", __func__, rigerror(retval)); + rig_debug(RIG_DEBUG_ERR, "%s: MODEM cmd failed: %s\n", __func__, + rigerror(retval)); } - else retval = mds_transaction(rig, "PTT 0", 0, &response); + else { retval = mds_transaction(rig, "PTT 0", 0, &response); } + RETURNFUNC(retval); } diff --git a/rigs/pcr/pcr.c b/rigs/pcr/pcr.c index a584fa2f8..d33bfa8be 100644 --- a/rigs/pcr/pcr.c +++ b/rigs/pcr/pcr.c @@ -783,7 +783,7 @@ pcr_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { struct pcr_priv_data *priv = (struct pcr_priv_data *) rig->state.priv; const struct pcr_rcvr *rcvr = is_sub_rcvr(rig, - vfo) ? &priv->sub_rcvr : &priv->main_rcvr; + vfo) ? &priv->sub_rcvr : &priv->main_rcvr; *freq = rcvr->last_freq; @@ -1169,7 +1169,7 @@ pcr_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) int err; struct pcr_priv_data *priv = (struct pcr_priv_data *) rig->state.priv; const struct pcr_rcvr *rcvr = is_sub_rcvr(rig, - vfo) ? &priv->sub_rcvr : &priv->main_rcvr; + vfo) ? &priv->sub_rcvr : &priv->main_rcvr; // rig_debug(RIG_DEBUG_TRACE, "%s: level = %d\n", __func__, level); @@ -1243,7 +1243,7 @@ pcr_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) { struct pcr_priv_data *priv = (struct pcr_priv_data *) rig->state.priv; const struct pcr_rcvr *rcvr = is_sub_rcvr(rig, - vfo) ? &priv->sub_rcvr : &priv->main_rcvr; + vfo) ? &priv->sub_rcvr : &priv->main_rcvr; rig_debug(RIG_DEBUG_VERBOSE, "%s: status = %d, func = %s\n", __func__, status, rig_strfunc(func)); @@ -1777,7 +1777,7 @@ int pcr_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) { struct pcr_priv_data *priv = (struct pcr_priv_data *) rig->state.priv; const struct pcr_rcvr *rcvr = is_sub_rcvr(rig, - vfo) ? &priv->sub_rcvr : &priv->main_rcvr; + vfo) ? &priv->sub_rcvr : &priv->main_rcvr; *tone = rcvr->last_ctcss_sql; return RIG_OK; @@ -1827,7 +1827,7 @@ int pcr_get_dcs_sql(RIG *rig, vfo_t vfo, tone_t *tone) { struct pcr_priv_data *priv = (struct pcr_priv_data *) rig->state.priv; const struct pcr_rcvr *rcvr = is_sub_rcvr(rig, - vfo) ? &priv->sub_rcvr : &priv->main_rcvr; + vfo) ? &priv->sub_rcvr : &priv->main_rcvr; *tone = rcvr->last_dcs_sql; return RIG_OK; @@ -1956,7 +1956,7 @@ int pcr_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) { struct pcr_priv_data *priv = (struct pcr_priv_data *) rig->state.priv; const struct pcr_rcvr *rcvr = is_sub_rcvr(rig, - vfo) ? &priv->sub_rcvr : &priv->main_rcvr; + vfo) ? &priv->sub_rcvr : &priv->main_rcvr; if (priv->auto_update == 0) { diff --git a/rigs/racal/ra37xx.c b/rigs/racal/ra37xx.c index 718b4408d..c19b00c94 100644 --- a/rigs/racal/ra37xx.c +++ b/rigs/racal/ra37xx.c @@ -68,7 +68,8 @@ const struct confparams ra37xx_cfg_params[] = static int ra37xx_one_transaction(RIG *rig, const char *cmd, char *data, int *data_len) { - const struct ra37xx_priv_data *priv = (struct ra37xx_priv_data *)rig->state.priv; + const struct ra37xx_priv_data *priv = (struct ra37xx_priv_data *) + rig->state.priv; struct rig_state *rs = &rig->state; char cmdbuf[BUFSZ]; char respbuf[BUFSZ]; @@ -289,7 +290,8 @@ int ra37xx_set_conf(RIG *rig, token_t token, const char *val) */ int ra37xx_get_conf2(RIG *rig, token_t token, char *val, int val_len) { - const struct ra37xx_priv_data *priv = (struct ra37xx_priv_data *)rig->state.priv; + const struct ra37xx_priv_data *priv = (struct ra37xx_priv_data *) + rig->state.priv; switch (token) { diff --git a/rigs/tentec/tentec.c b/rigs/tentec/tentec.c index 0f70fa711..415d31bf8 100644 --- a/rigs/tentec/tentec.c +++ b/rigs/tentec/tentec.c @@ -262,7 +262,8 @@ int tentec_set_freq(RIG *rig, vfo_t vfo, freq_t freq) */ int tentec_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) { - const struct tentec_priv_data *priv = (struct tentec_priv_data *)rig->state.priv; + const struct tentec_priv_data *priv = (struct tentec_priv_data *) + rig->state.priv; *freq = priv->freq; @@ -382,7 +383,8 @@ int tentec_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) */ int tentec_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { - const struct tentec_priv_data *priv = (struct tentec_priv_data *)rig->state.priv; + const struct tentec_priv_data *priv = (struct tentec_priv_data *) + rig->state.priv; *mode = priv->mode; *width = priv->width; @@ -467,7 +469,8 @@ int tentec_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) */ int tentec_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { - const struct tentec_priv_data *priv = (struct tentec_priv_data *)rig->state.priv; + const struct tentec_priv_data *priv = (struct tentec_priv_data *) + rig->state.priv; int retval, lvl_len; unsigned char lvlbuf[32]; diff --git a/rigs/uniden/uniden.c b/rigs/uniden/uniden.c index 6b95f348c..d64ac61fa 100644 --- a/rigs/uniden/uniden.c +++ b/rigs/uniden/uniden.c @@ -692,7 +692,8 @@ int uniden_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan) } /* PM089T08511625 */ - SNPRINTF(cmdbuf, sizeof(cmdbuf), "PM%03d%c%08u" EOM, chan->channel_num, ' ', (unsigned)(chan->freq / 100)); + SNPRINTF(cmdbuf, sizeof(cmdbuf), "PM%03d%c%08u" EOM, chan->channel_num, ' ', + (unsigned)(chan->freq / 100)); ret = uniden_transaction(rig, cmdbuf, strlen(cmdbuf), NULL, membuf, &mem_len); @@ -790,7 +791,8 @@ DECLARE_PROBERIG_BACKEND(uniden) int rates[] = { 9600, 19200, 0 }; /* possible baud rates */ int rates_idx; - memset(idbuf,0,IDBUFSZ); + memset(idbuf, 0, IDBUFSZ); + if (!port) { return RIG_MODEL_NONE; diff --git a/rigs/yaesu/ft1200.c b/rigs/yaesu/ft1200.c index cb6323242..417d1de8e 100644 --- a/rigs/yaesu/ft1200.c +++ b/rigs/yaesu/ft1200.c @@ -174,13 +174,13 @@ struct rig_caps ftdx1200_caps = { #include "level_gran_yaesu.h" [LVL_NOTCHF] = { .min = { .i = 1 }, .max = { .i = 4000 }, .step = { .i = 10 } }, - [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, + [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BANDUNUSED,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ft2000.c b/rigs/yaesu/ft2000.c index 2d0c98b8d..b66c67094 100644 --- a/rigs/yaesu/ft2000.c +++ b/rigs/yaesu/ft2000.c @@ -159,12 +159,12 @@ struct rig_caps ft2000_caps = #include "level_gran_yaesu.h" [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 1050 }, .step = { .i = 50 } }, [LVL_NOTCHF] = { .min = { .i = 1 }, .max = { .i = 4000 }, .step = { .i = 10 } }, - [LVL_COMP] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, - [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, + [LVL_COMP] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, + [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BAND60M,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDRGEN"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ft3000.c b/rigs/yaesu/ft3000.c index e3a2bd3e0..6c041925e 100644 --- a/rigs/yaesu/ft3000.c +++ b/rigs/yaesu/ft3000.c @@ -270,13 +270,13 @@ struct rig_caps ftdx3000_caps = .level_gran = { #include "level_gran_yaesu.h" [LVL_NOTCHF] = { .min = { .i = 1 }, .max = { .i = 4000 }, .step = { .i = 10 } }, - [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, + [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BANDUNUSED,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ft450.c b/rigs/yaesu/ft450.c index ed5bfdd89..e33d9b611 100644 --- a/rigs/yaesu/ft450.c +++ b/rigs/yaesu/ft450.c @@ -67,12 +67,12 @@ struct rig_caps ft450_caps = #include "level_gran_yaesu.h" [LVL_CWPITCH] = { .min = { .i = 400 }, .max = { .i = 800 }, .step = { .i = 100 } }, [LVL_NOTCHF] = { .min = { .i = 1 }, .max = { .i = 4000 }, .step = { .i = 10 } }, - [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, - [LVL_NR] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/11.0f } }, + [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, + [LVL_NR] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 11.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BANDUNUSED,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ft5000.c b/rigs/yaesu/ft5000.c index 8bfbb04f1..759c68f23 100644 --- a/rigs/yaesu/ft5000.c +++ b/rigs/yaesu/ft5000.c @@ -165,12 +165,12 @@ struct rig_caps ftdx5000_caps = { #include "level_gran_yaesu.h" [LVL_NOTCHF] = { .min = { .i = 1 }, .max = { .i = 4000 }, .step = { .i = 10 } }, - [LVL_COMP] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, - [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, + [LVL_COMP] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, + [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BANDUNUSED,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ft710.c b/rigs/yaesu/ft710.c index 188617515..37d07f617 100644 --- a/rigs/yaesu/ft710.c +++ b/rigs/yaesu/ft710.c @@ -145,14 +145,14 @@ struct rig_caps ft710_caps = .level_gran = { #include "level_gran_yaesu.h" - [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, + [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BAND60M,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BAND4M"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ft767gx.c b/rigs/yaesu/ft767gx.c index f5080ea0d..a5df97fa0 100644 --- a/rigs/yaesu/ft767gx.c +++ b/rigs/yaesu/ft767gx.c @@ -495,6 +495,7 @@ int ft767_close(RIG *rig) rig_debug(RIG_DEBUG_ERR, "%s: leave_CAT %d\n", __func__, retval); return retval; } + return RIG_OK; } diff --git a/rigs/yaesu/ft817.c b/rigs/yaesu/ft817.c index 291b0bcf3..95e579fdd 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -640,7 +640,8 @@ static int ft817_close(RIG *rig) /* ---------------------------------------------------------------------- */ -static inline long timediff(const struct timeval *tv1, const struct timeval *tv2) +static inline long timediff(const struct timeval *tv1, + const struct timeval *tv2) { struct timeval tv; diff --git a/rigs/yaesu/ft857.c b/rigs/yaesu/ft857.c index c0e62ff85..7964cdd93 100644 --- a/rigs/yaesu/ft857.c +++ b/rigs/yaesu/ft857.c @@ -431,7 +431,8 @@ int ft857_close(RIG *rig) /* ---------------------------------------------------------------------- */ -static inline long timediff(const struct timeval *tv1, const struct timeval *tv2) +static inline long timediff(const struct timeval *tv1, + const struct timeval *tv2) { struct timeval tv; @@ -673,7 +674,8 @@ int ft857_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) return -RIG_OK; } -static void get_mode(RIG *rig, const struct ft857_priv_data *priv, rmode_t *mode, +static void get_mode(RIG *rig, const struct ft857_priv_data *priv, + rmode_t *mode, pbwidth_t *width) { rig_debug(RIG_DEBUG_VERBOSE, "%s: called \n", __func__); diff --git a/rigs/yaesu/ft891.c b/rigs/yaesu/ft891.c index e53579229..dcd8b9b18 100644 --- a/rigs/yaesu/ft891.c +++ b/rigs/yaesu/ft891.c @@ -156,15 +156,15 @@ struct rig_caps ft891_caps = .level_gran = { #include "level_gran_yaesu.h" - [LVL_RF] = { .min = { .f = 0 }, .max = { .f = 1.0f }, .step = { .f = 1.0f/30.0f } }, - [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, + [LVL_RF] = { .min = { .f = 0 }, .max = { .f = 1.0f }, .step = { .f = 1.0f / 30.0f } }, + [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BANDUNUSED,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDRGEN,BANDMW"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ft897.c b/rigs/yaesu/ft897.c index aa6c35cd5..be2144890 100644 --- a/rigs/yaesu/ft897.c +++ b/rigs/yaesu/ft897.c @@ -583,7 +583,8 @@ int ft897_close(RIG *rig) /* ---------------------------------------------------------------------- */ -static inline long timediff(const struct timeval *tv1, const struct timeval *tv2) +static inline long timediff(const struct timeval *tv1, + const struct timeval *tv2) { struct timeval tv; diff --git a/rigs/yaesu/ft9000.c b/rigs/yaesu/ft9000.c index 831fc294b..3760a772b 100644 --- a/rigs/yaesu/ft9000.c +++ b/rigs/yaesu/ft9000.c @@ -74,8 +74,8 @@ struct rig_caps ft9000_caps = #include "level_gran_yaesu.h" [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 1050 }, .step = { .i = 50 } }, [LVL_NOTCHF] = { .min = { .i = 1 }, .max = { .i = 3000 }, .step = { .i = 10 } }, - [LVL_COMP] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, - [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, + [LVL_COMP] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, + [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, @@ -250,8 +250,8 @@ struct rig_caps ft9000Old_caps = #include "level_gran_yaesu.h" [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 1050 }, .step = { .i = 50 } }, [LVL_NOTCHF] = { .min = { .i = 1 }, .max = { .i = 3000 }, .step = { .i = 10 } }, - [LVL_COMP] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, - [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/255.0f } }, + [LVL_COMP] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, + [LVL_VOXGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 255.0f } }, }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ft920.c b/rigs/yaesu/ft920.c index 097b3fb88..fda80d7f1 100644 --- a/rigs/yaesu/ft920.c +++ b/rigs/yaesu/ft920.c @@ -2296,7 +2296,8 @@ static int ft920_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) { return err; } - hl_usleep(200*1000); // give the rig some time before we try set_freq + + hl_usleep(200 * 1000); // give the rig some time before we try set_freq return RIG_OK; } diff --git a/rigs/yaesu/ft950.c b/rigs/yaesu/ft950.c index c131892d0..5d48226ac 100644 --- a/rigs/yaesu/ft950.c +++ b/rigs/yaesu/ft950.c @@ -111,11 +111,11 @@ struct rig_caps ft950_caps = [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 1050 }, .step = { .i = 50 } }, [LVL_KEYSPD] = { .min = { .i = 4 }, .max = { .i = 60 }, .step = { .i = 1 } }, [LVL_NOTCHF] = { .min = { .i = 1 }, .max = { .i = 3000 }, .step = { .i = 10 } }, - [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, + [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BANDUNUSED,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ft980.c b/rigs/yaesu/ft980.c index 5c3580eb1..d8fea2167 100644 --- a/rigs/yaesu/ft980.c +++ b/rigs/yaesu/ft980.c @@ -755,7 +755,7 @@ int ft980_open(RIG *rig) write_block(&rig->state.rigport, cmd_OK, YAESU_CMD_LENGTH); read_block(&rig->state.rigport, (unsigned char *) &priv->update_data, - FT980_ALL_STATUS_LENGTH); + FT980_ALL_STATUS_LENGTH); } while (!priv->update_data.ext_ctl_flag && retry_count1++ < rig->state.rigport.retry); @@ -801,7 +801,7 @@ int ft980_close(RIG *rig) write_block(&rig->state.rigport, cmd_OK, YAESU_CMD_LENGTH); read_block(&rig->state.rigport, (unsigned char *) &priv->update_data, - FT980_ALL_STATUS_LENGTH); + FT980_ALL_STATUS_LENGTH); } while (priv->update_data.ext_ctl_flag && retry_count1++ < rig->state.rigport.retry); diff --git a/rigs/yaesu/ft991.c b/rigs/yaesu/ft991.c index cc11f96a9..fe1a00076 100644 --- a/rigs/yaesu/ft991.c +++ b/rigs/yaesu/ft991.c @@ -200,14 +200,14 @@ struct rig_caps ft991_caps = .has_set_parm = RIG_PARM_BANDSELECT, .level_gran = { #include "level_gran_yaesu.h" - [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, + [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BANDUNUSED,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN,BANDMW,BANDUNUSED,BANDAIR,BAND70CM,BAND33CM"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = common_dcs_list, diff --git a/rigs/yaesu/ftdx10.c b/rigs/yaesu/ftdx10.c index cd86fbc02..32493b843 100644 --- a/rigs/yaesu/ftdx10.c +++ b/rigs/yaesu/ftdx10.c @@ -161,14 +161,14 @@ struct rig_caps ftdx10_caps = .level_gran = { #include "level_gran_yaesu.h" - [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, + [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BANDUNUSED,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN,BANDMW"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ftdx101.c b/rigs/yaesu/ftdx101.c index 3d08542d5..701f7ce49 100644 --- a/rigs/yaesu/ftdx101.c +++ b/rigs/yaesu/ftdx101.c @@ -120,7 +120,7 @@ const struct confparams ftdx101d_ext_levels[] = RIG_CONF_NUMERIC, { .n = { .min = 1, .max = 11, .step = 1 } }, }, - { + { TOK_MAXPOWER_HF, "MAXPOWER_HF", "Maxpower HF", @@ -199,16 +199,16 @@ struct rig_caps ftdx101d_caps = .level_gran = { #include "level_gran_yaesu.h" - [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_USB_AF] = { .min = { .f = .0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_USB_AF_INPUT] = { .min = { .f = .0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, + [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_RFPOWER] = { .min = { .f = .05 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_USB_AF] = { .min = { .f = .0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_USB_AF_INPUT] = { .min = { .f = .0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BAND60M,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN,BANDMW,BANDUNUSED,BANDUNUSED,BANDUNUSED,BANDUNUSED,BAND4M"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/ftdx101mp.c b/rigs/yaesu/ftdx101mp.c index d459051c0..e7561dbfe 100644 --- a/rigs/yaesu/ftdx101mp.c +++ b/rigs/yaesu/ftdx101mp.c @@ -101,16 +101,16 @@ struct rig_caps ftdx101mp_caps = .has_set_parm = RIG_PARM_BANDSELECT, .level_gran = { #include "level_gran_yaesu.h" - [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_RFPOWER] = { .min = { .f = .025 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/200.0f } }, - [LVL_USB_AF] = { .min = { .f = .0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, - [LVL_USB_AF_INPUT] = { .min = { .f = .0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f/100.0f } }, + [LVL_MICGAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_SQL] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_MONITOR_GAIN] = { .min = { .f = 0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_RFPOWER] = { .min = { .f = .025 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 200.0f } }, + [LVL_USB_AF] = { .min = { .f = .0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, + [LVL_USB_AF_INPUT] = { .min = { .f = .0 }, .max = { .f = 1.0 }, .step = { .f = 1.0f / 100.0f } }, }, .parm_gran = { [PARM_BANDSELECT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.s = "BAND160M,BAND80M,BANDUNUSED,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN,BANDMW,BANDUNUSED,BANDUNUSED,BANDUNUSED,BANDUNUSED,BAND4M"}} - }, + }, .ctcss_list = common_ctcss_list, .dcs_list = NULL, diff --git a/rigs/yaesu/newcat.c b/rigs/yaesu/newcat.c index d4c38f860..4585cc06e 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -703,7 +703,8 @@ int newcat_close(RIG *rig) ENTERFUNC; - if (!no_restore_ai && priv->trn_state >= 0 && rig_s->comm_state && rig_s->powerstat != RIG_POWER_OFF) + if (!no_restore_ai && priv->trn_state >= 0 && rig_s->comm_state + && rig_s->powerstat != RIG_POWER_OFF) { /* restore AI state */ newcat_set_trn(rig, priv->trn_state); /* ignore status in @@ -893,7 +894,8 @@ int newcat_60m_exception(RIG *rig, freq_t freq, mode_t mode) { if ((long)freq == freq_60m[i]) { channel = i; } } - if ((long)freq == 5357000) channel = 3; // 60M channel for FT8 + + if ((long)freq == 5357000) { channel = 3; } // 60M channel for FT8 if (channel < 0) { @@ -1166,7 +1168,7 @@ int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) } // we need to change vfos, BS, and change back - if (is_ft991==FALSE && is_ft891==FALSE && newcat_valid_command(rig, "VS")) + if (is_ft991 == FALSE && is_ft891 == FALSE && newcat_valid_command(rig, "VS")) { SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "VS%d;BS%02d%c", vfo1, newcat_band_index(freq), cat_term); @@ -1590,9 +1592,11 @@ int newcat_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) { RETURNFUNC(-RIG_ENAVAIL); } + if (rig->state.powerstat == 0) { - rig_debug(RIG_DEBUG_WARN, "%s: Cannot get from rig when power is off\n", __func__); + rig_debug(RIG_DEBUG_WARN, "%s: Cannot get from rig when power is off\n", + __func__); return RIG_OK; // to prevent repeats } @@ -1964,7 +1968,7 @@ int newcat_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) } } - break; + break; default: RETURNFUNC(-RIG_EINVAL); @@ -3618,12 +3622,12 @@ int newcat_set_powerstat(RIG *rig, powerstat_t status) case RIG_POWER_ON: // When powering on a Yaesu rig needs dummy bytes to wake it up, // then wait from 1 to 2 seconds and issue the power-on command again - HAMLIB_TRACE; + HAMLIB_TRACE; write_block(&state->rigport, (unsigned char *) "PS1;", 4); hl_usleep(1200000); write_block(&state->rigport, (unsigned char *) "PS1;", 4); // some rigs reset the serial port during power up - // so we reopen the com port again + // so we reopen the com port again HAMLIB_TRACE; //oser_close(&state->rigport); rig_close(rig); @@ -3759,6 +3763,7 @@ int newcat_get_powerstat(RIG *rig, powerstat_t *status) rig_flush(&rig->state.rigport); result = newcat_get_cmd(rig); + if (result != RIG_OK) { RETURNFUNC(result); @@ -4036,8 +4041,9 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) } err = check_level_param(rig, level, val, &level_info); - if (err != RIG_OK ) { RETURNFUNC(err); } - + + if (err != RIG_OK) { RETURNFUNC(err); } + switch (level) { case RIG_LEVEL_RFPOWER: @@ -4046,14 +4052,14 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) RETURNFUNC(-RIG_ENAVAIL); } - if ( is_ftdx3000dm ) /* No separate rig->caps for this rig :-( */ - { - fpf = (int)((val.f * 50.0f) + 0.5f); - } - else - { - fpf = (int)((val.f / level_info->step.f) + 0.5f ); - } + if (is_ftdx3000dm) /* No separate rig->caps for this rig :-( */ + { + fpf = (int)((val.f * 50.0f) + 0.5f); + } + else + { + fpf = (int)((val.f / level_info->step.f) + 0.5f); + } SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "PC%03d%c", fpf, cat_term); break; @@ -4193,7 +4199,8 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) } // Most Yaesu rigs seem to use range of 0-75 to represent pitch of 300..1050 Hz in 10 Hz steps - kp = (val.i - level_info->min.i + (level_info->step.i / 2)) / level_info->step.i; + kp = (val.i - level_info->min.i + (level_info->step.i / 2)) / + level_info->step.i; SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "KP%02d%c", kp, cat_term); break; @@ -4220,27 +4227,31 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) } rmode_t exclude = RIG_MODE_CW | RIG_MODE_CWR | RIG_MODE_RTTY | RIG_MODE_RTTYR; + if ((rig->state.tx_vfo == RIG_VFO_A && (rig->state.cache.modeMainA & exclude)) - ||(rig->state.tx_vfo == RIG_VFO_B && (rig->state.cache.modeMainB & exclude)) - ||(rig->state.tx_vfo == RIG_VFO_C && (rig->state.cache.modeMainC & exclude))) - { - rig_debug(RIG_DEBUG_VERBOSE, "%s: rig cannot set MG in CW/RTTY modes\n", __func__); - return RIG_OK; - } + || (rig->state.tx_vfo == RIG_VFO_B && (rig->state.cache.modeMainB & exclude)) + || (rig->state.tx_vfo == RIG_VFO_C && (rig->state.cache.modeMainC & exclude))) + { + rig_debug(RIG_DEBUG_VERBOSE, "%s: rig cannot set MG in CW/RTTY modes\n", + __func__); + return RIG_OK; + } - if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 || is_ftdx101d + if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 + || is_ftdx101d || is_ftdx101mp) { newcat_get_mode(rig, vfo, &mode, &width); } - fpf = (int) (( val.f / level_info->step.f ) + 0.5f ); + fpf = (int)((val.f / level_info->step.f) + 0.5f); SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MG%03d%c", fpf, cat_term); // Some Yaesu rigs reject this command in RTTY modes - if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 || is_ftdx101d + if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 + || is_ftdx101d || is_ftdx101mp) { if (mode & RIG_MODE_RTTY || mode & RIG_MODE_RTTYR) @@ -4422,6 +4433,7 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) } fpf = (int)((val.f / level_info->step.f) + 0.5); + if (newcat_is_rig(rig, RIG_MODEL_FT450)) { if (fpf < 1) @@ -4466,7 +4478,7 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) RETURNFUNC(-RIG_ENAVAIL); } - fpf = (int) ((val.f / level_info->step.f) + 0.5f); + fpf = (int)((val.f / level_info->step.f) + 0.5f); SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "PL%03d%c", fpf, cat_term); break; @@ -4574,7 +4586,7 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) RETURNFUNC(-RIG_ENAVAIL); } - fpf = (int) ((val.f / level_info->step.f) + 0.5f ); + fpf = (int)((val.f / level_info->step.f) + 0.5f); SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "SQ%c%03d%c", main_sub_vfo, fpf, cat_term); @@ -4609,7 +4621,8 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "VD%04d%c", val.i, cat_term); } - else if (is_ftdx101d || is_ftdx101mp || is_ftdx10 || is_ft710) // new lookup table argument + else if (is_ftdx101d || is_ftdx101mp || is_ftdx10 + || is_ft710) // new lookup table argument { rig_debug(RIG_DEBUG_TRACE, "%s: ft101 #1 val.i=%d\n", __func__, val.i); @@ -4651,12 +4664,13 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) RETURNFUNC(-RIG_ENAVAIL); } - fpf = (int) ((val.f / level_info->step.f) + 0.5f ); + fpf = (int)((val.f / level_info->step.f) + 0.5f); SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "VG%03d%c", fpf, cat_term); break; case RIG_LEVEL_ANTIVOX: - fpf = (int) (( val.f / level_info->step.f ) + 0.5f ); + fpf = (int)((val.f / level_info->step.f) + 0.5f); + if (is_ftdx101d || is_ftdx101mp || is_ftdx10 || is_ft710) { SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "AV%03d%c", fpf, cat_term); @@ -4818,32 +4832,44 @@ int newcat_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) case RIG_LEVEL_USB_AF: if (is_ftdx101d || is_ftdx101mp) { - rmode_t curmode = rig->state.current_vfo == RIG_VFO_A? rig->state.cache.modeMainA : rig->state.cache.modeMainB; + rmode_t curmode = rig->state.current_vfo == RIG_VFO_A ? + rig->state.cache.modeMainA : rig->state.cache.modeMainB; float valf = val.f / level_info->step.f; - switch(curmode) + + switch (curmode) { - case RIG_MODE_USB: - case RIG_MODE_LSB: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010113%03.0f%c", valf, cat_term); - break; - case RIG_MODE_AM: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010214%03.0f%c", valf, cat_term); - break; - case RIG_MODE_FM: - case RIG_MODE_FMN: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010313%03.0f%c", valf, cat_term); - break; - case RIG_MODE_PKTFM: // is this the right place for this? - case RIG_MODE_PKTFMN: // is this the right place for this? - case RIG_MODE_PKTUSB: - case RIG_MODE_PKTLSB: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010415%03.0f%c", valf, cat_term); - break; - default: - rig_debug(RIG_DEBUG_ERR, "%s: unknown how to set USB_AF for mode=%s\n", __func__, rig_strrmode(curmode)); - RETURNFUNC(-RIG_EINVAL); + case RIG_MODE_USB: + case RIG_MODE_LSB: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010113%03.0f%c", valf, + cat_term); + break; + + case RIG_MODE_AM: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010214%03.0f%c", valf, + cat_term); + break; + + case RIG_MODE_FM: + case RIG_MODE_FMN: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010313%03.0f%c", valf, + cat_term); + break; + + case RIG_MODE_PKTFM: // is this the right place for this? + case RIG_MODE_PKTFMN: // is this the right place for this? + case RIG_MODE_PKTUSB: + case RIG_MODE_PKTLSB: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010415%03.0f%c", valf, + cat_term); + break; + + default: + rig_debug(RIG_DEBUG_ERR, "%s: unknown how to set USB_AF for mode=%s\n", + __func__, rig_strrmode(curmode)); + RETURNFUNC(-RIG_EINVAL); } } + break; default: @@ -4885,7 +4911,7 @@ int newcat_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { main_sub_vfo = (RIG_VFO_B == vfo || RIG_VFO_SUB == vfo) ? '1' : '0'; } - + level_info = &rig->caps->level_gran[rig_setting2idx(level)]; switch (level) @@ -4920,6 +4946,7 @@ int newcat_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { RETURNFUNC(-RIG_ENAVAIL); } + if (is_ftdx10) { main_sub_vfo = '0'; } SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "AG%c%c", main_sub_vfo, @@ -5014,16 +5041,20 @@ int newcat_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { RETURNFUNC(-RIG_ENAVAIL); } - rmode_t exclude = RIG_MODE_CW | RIG_MODE_CWR | RIG_MODE_RTTY | RIG_MODE_RTTYR; - if ((rig->state.tx_vfo == RIG_VFO_A && (rig->state.cache.modeMainA & exclude)) - ||(rig->state.tx_vfo == RIG_VFO_B && (rig->state.cache.modeMainB & exclude)) - ||(rig->state.tx_vfo == RIG_VFO_C && (rig->state.cache.modeMainC & exclude))) - { - rig_debug(RIG_DEBUG_VERBOSE, "%s: rig cannot read MG in CW/RTTY modes\n", __func__); - return RIG_OK; - } - if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 || is_ftdx101d + rmode_t exclude = RIG_MODE_CW | RIG_MODE_CWR | RIG_MODE_RTTY | RIG_MODE_RTTYR; + + if ((rig->state.tx_vfo == RIG_VFO_A && (rig->state.cache.modeMainA & exclude)) + || (rig->state.tx_vfo == RIG_VFO_B && (rig->state.cache.modeMainB & exclude)) + || (rig->state.tx_vfo == RIG_VFO_C && (rig->state.cache.modeMainC & exclude))) + { + rig_debug(RIG_DEBUG_VERBOSE, "%s: rig cannot read MG in CW/RTTY modes\n", + __func__); + return RIG_OK; + } + + if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 + || is_ftdx101d || is_ftdx101mp) { newcat_get_mode(rig, vfo, &mode, &width); @@ -5032,7 +5063,8 @@ int newcat_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MG%c", cat_term); // Some Yaesu rigs reject this command in RTTY modes - if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 || is_ftdx101d + if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 + || is_ftdx101d || is_ftdx101mp) { if (mode & RIG_MODE_RTTY || mode & RIG_MODE_RTTYR) @@ -5174,6 +5206,7 @@ int newcat_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) { RETURNFUNC(-RIG_ENAVAIL); } + if (is_ftdx10) { main_sub_vfo = '0'; } SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "SM%c%c", main_sub_vfo, @@ -5395,76 +5428,95 @@ int newcat_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) case RIG_LEVEL_USB_AF_INPUT: if (is_ftdx101d || is_ftdx101mp) { - rmode_t curmode = rig->state.current_vfo == RIG_VFO_A? rig->state.cache.modeMainA : rig->state.cache.modeMainB; - switch(curmode) + rmode_t curmode = rig->state.current_vfo == RIG_VFO_A ? + rig->state.cache.modeMainA : rig->state.cache.modeMainB; + + switch (curmode) { - case RIG_MODE_LSB: - case RIG_MODE_USB: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010113%c", cat_term); - break; - case RIG_MODE_AM: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010214%c", cat_term); - break; - case RIG_MODE_FM: - case RIG_MODE_FMN: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010313%c", cat_term); - break; - case RIG_MODE_PKTFM: - case RIG_MODE_PKTFMN: - case RIG_MODE_PKTUSB: - case RIG_MODE_PKTLSB: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010415%c", cat_term); - break; - default: - rig_debug(RIG_DEBUG_ERR, "%s: unknown how to get USB_AF_INPUT for mode=%s\n", __func__, rig_strrmode(curmode)); - RETURNFUNC(-RIG_EINVAL); + case RIG_MODE_LSB: + case RIG_MODE_USB: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010113%c", cat_term); + break; + + case RIG_MODE_AM: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010214%c", cat_term); + break; + + case RIG_MODE_FM: + case RIG_MODE_FMN: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010313%c", cat_term); + break; + + case RIG_MODE_PKTFM: + case RIG_MODE_PKTFMN: + case RIG_MODE_PKTUSB: + case RIG_MODE_PKTLSB: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010415%c", cat_term); + break; + + default: + rig_debug(RIG_DEBUG_ERR, "%s: unknown how to get USB_AF_INPUT for mode=%s\n", + __func__, rig_strrmode(curmode)); + RETURNFUNC(-RIG_EINVAL); } } else { RETURNFUNC(-RIG_ENIMPL); } + break; case RIG_LEVEL_USB_AF: if (is_ftdx101d || is_ftdx101mp) { - rmode_t curmode = rig->state.current_vfo == RIG_VFO_A? rig->state.cache.modeMainA : rig->state.cache.modeMainB; - switch(curmode) + rmode_t curmode = rig->state.current_vfo == RIG_VFO_A ? + rig->state.cache.modeMainA : rig->state.cache.modeMainB; + + switch (curmode) { - case RIG_MODE_LSB: - case RIG_MODE_USB: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010109%c", cat_term); - break; - case RIG_MODE_AM: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010209%c", cat_term); - break; - case RIG_MODE_FM: - case RIG_MODE_FMN: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010309%c", cat_term); - break; - case RIG_MODE_PKTFM: - case RIG_MODE_PKTFMN: - case RIG_MODE_PKTUSB: - case RIG_MODE_PKTLSB: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010411%c", cat_term); - break; - case RIG_MODE_RTTY: - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010511%c", cat_term); - break; - // we have PSK level too but no means to have this mode yet - default: - rig_debug(RIG_DEBUG_ERR, "%s: unknown how to get USB_AF for mode=%s\n", __func__, rig_strrmode(curmode)); - RETURNFUNC(-RIG_EINVAL); + case RIG_MODE_LSB: + case RIG_MODE_USB: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010109%c", cat_term); + break; + + case RIG_MODE_AM: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010209%c", cat_term); + break; + + case RIG_MODE_FM: + case RIG_MODE_FMN: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010309%c", cat_term); + break; + + case RIG_MODE_PKTFM: + case RIG_MODE_PKTFMN: + case RIG_MODE_PKTUSB: + case RIG_MODE_PKTLSB: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010411%c", cat_term); + break; + + case RIG_MODE_RTTY: + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX010511%c", cat_term); + break; + + // we have PSK level too but no means to have this mode yet + default: + rig_debug(RIG_DEBUG_ERR, "%s: unknown how to get USB_AF for mode=%s\n", + __func__, rig_strrmode(curmode)); + RETURNFUNC(-RIG_EINVAL); } } else { RETURNFUNC(-RIG_ENIMPL); } + break; + default: - rig_debug(RIG_DEBUG_ERR, "%s: unknown level=%08llx\n", __func__, (long long unsigned int)level); + rig_debug(RIG_DEBUG_ERR, "%s: unknown level=%08llx\n", __func__, + (long long unsigned int)level); RETURNFUNC(-RIG_EINVAL); } @@ -5964,6 +6016,7 @@ int newcat_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) || is_ftdx101mp) { err = newcat_get_mode(rig, vfo, &mode, &width); + if (err != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: get_mode: %s\n", __func__, rigerror(err)); @@ -6005,6 +6058,7 @@ int newcat_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) || is_ftdx101mp) { err = newcat_get_mode(rig, vfo, &mode, &width); + if (err != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: get_mode: %s\n", __func__, rigerror(err)); @@ -6167,6 +6221,7 @@ int newcat_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) || is_ftdx101mp) { err = newcat_get_mode(rig, vfo, &mode, &width); + if (err != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: get_mode: %s\n", __func__, rigerror(err)); @@ -6204,17 +6259,20 @@ int newcat_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) RETURNFUNC(-RIG_ENAVAIL); } - if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 || is_ftdx101d + if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 + || is_ftdx101d || is_ftdx101mp) { err = newcat_get_mode(rig, vfo, &mode, &width); + if (err != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: get_mode: %s\n", __func__, rigerror(err)); } } - if (is_ft891 || is_ft991 || is_ft710 || is_ftdx1200 || is_ftdx3000 || is_ftdx3000dm + if (is_ft891 || is_ft991 || is_ft710 || is_ftdx1200 || is_ftdx3000 + || is_ftdx3000dm || is_ftdx101d || is_ftdx101mp) { @@ -6229,7 +6287,8 @@ int newcat_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) } // Some Yaesu rigs reject this command in AM/FM/RTTY modes - if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 || is_ftdx101d + if (is_ft991 || is_ft710 || is_ftdx3000 || is_ftdx3000dm || is_ftdx5000 + || is_ftdx101d || is_ftdx101mp) { if (mode & RIG_MODE_AM || mode & RIG_MODE_FM || mode & RIG_MODE_AMN @@ -6280,6 +6339,7 @@ int newcat_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "RT%d%c", status ? 1 : 0, cat_term); } + break; case RIG_FUNC_XIT: @@ -6297,6 +6357,7 @@ int newcat_set_func(RIG *rig, vfo_t vfo, setting_t func, int status) SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "XT%d%c", status ? 1 : 0, cat_term); } + break; case RIG_FUNC_APF: @@ -6379,6 +6440,7 @@ int newcat_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) || is_ftdx101mp) { err = newcat_get_mode(rig, vfo, &mode, &width); + if (err != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: get_mode: %s\n", __func__, rigerror(err)); @@ -6529,7 +6591,8 @@ int newcat_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) RETURNFUNC(-RIG_ENAVAIL); } - if (is_ftdx1200 || is_ftdx3000 || is_ftdx3000dm || is_ft891 || is_ft991 || is_ft710 + if (is_ftdx1200 || is_ftdx3000 || is_ftdx3000dm || is_ft891 || is_ft991 + || is_ft710 || is_ftdx101d || is_ftdx101mp) { @@ -6574,6 +6637,7 @@ int newcat_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "RT%c", cat_term); } + break; case RIG_FUNC_XIT: @@ -6590,6 +6654,7 @@ int newcat_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "XT%c", cat_term); } + break; case RIG_FUNC_APF: @@ -6717,7 +6782,8 @@ int newcat_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) break; case RIG_FUNC_APF: - if (is_ftdx101d || is_ftdx101mp || is_ftdx10 || is_ft991 || is_ft891 || is_ft710) + if (is_ftdx101d || is_ftdx101mp || is_ftdx10 || is_ft991 || is_ft891 + || is_ft710) { *status = (retfunc[last_char_index] == '1') ? 1 : 0; } @@ -6751,25 +6817,27 @@ int newcat_set_parm(RIG *rig, setting_t parm, value_t val) int band = 0; ENTERFUNC; - switch(parm) + switch (parm) { - case RIG_PARM_BANDSELECT: - if (!newcat_valid_command(rig, "BS")) - { - RETURNFUNC(-RIG_ENAVAIL); - } - // we should have a string for the desired band - band = rig_get_band_rig(rig, 0.0, val.s); + case RIG_PARM_BANDSELECT: + if (!newcat_valid_command(rig, "BS")) + { + RETURNFUNC(-RIG_ENAVAIL); + } - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "BS%02d%c", band, cat_term); + // we should have a string for the desired band + band = rig_get_band_rig(rig, 0.0, val.s); - retval = newcat_set_cmd(rig); + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "BS%02d%c", band, cat_term); - if (retval != RIG_OK) - { - RETURNFUNC(retval); - } - RETURNFUNC(RIG_OK); + retval = newcat_set_cmd(rig); + + if (retval != RIG_OK) + { + RETURNFUNC(retval); + } + + RETURNFUNC(RIG_OK); } RETURNFUNC(-RIG_ENIMPL); @@ -6781,26 +6849,29 @@ int newcat_get_parm(RIG *rig, setting_t parm, value_t *val) int retval; ENTERFUNC; - switch(parm) + switch (parm) { - case RIG_PARM_BANDSELECT: - if (!newcat_valid_command(rig, "BS")) - { - RETURNFUNC(-RIG_ENAVAIL); - } + case RIG_PARM_BANDSELECT: + if (!newcat_valid_command(rig, "BS")) + { + RETURNFUNC(-RIG_ENAVAIL); + } - freq_t freq; - retval = rig_get_freq(rig, RIG_VFO_A, &freq); - if (retval != RIG_OK) - { - RETURNFUNC(retval); - } - hamlib_band_t band = rig_get_band(rig, freq, 0); - val->cs = rig_get_band_str(rig, band, 0); + freq_t freq; + retval = rig_get_freq(rig, RIG_VFO_A, &freq); - RETURNFUNC(RIG_OK); - default: - RETURNFUNC(-RIG_EINVAL); + if (retval != RIG_OK) + { + RETURNFUNC(retval); + } + + hamlib_band_t band = rig_get_band(rig, freq, 0); + val->cs = rig_get_band_str(rig, band, 0); + + RETURNFUNC(RIG_OK); + + default: + RETURNFUNC(-RIG_EINVAL); } RETURNFUNC(-RIG_ENAVAIL); @@ -6819,37 +6890,53 @@ static int newcat_get_maxpower(RIG *rig, vfo_t vfo, token_t token, value_t *val) int offset = 0; val->i = 0; - if (newcat_is_rig(rig, RIG_MODEL_FT991)) + + if (newcat_is_rig(rig, RIG_MODEL_FT991)) { offset = 5; - switch(token) + + switch (token) { - case TOK_MAXPOWER_HF: code = 137; break; - case TOK_MAXPOWER_6M: code = 138; break; - case TOK_MAXPOWER_VHF: code = 139; break; - case TOK_MAXPOWER_UHF: code = 140; break; - default: return -RIG_EINVAL; + case TOK_MAXPOWER_HF: code = 137; break; + + case TOK_MAXPOWER_6M: code = 138; break; + + case TOK_MAXPOWER_VHF: code = 139; break; + + case TOK_MAXPOWER_UHF: code = 140; break; + + default: return -RIG_EINVAL; } + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX%03d%c", code, cat_term); } - else if (newcat_is_rig(rig, RIG_MODEL_FTDX101MP) || newcat_is_rig(rig, RIG_MODEL_FTDX101D)) + else if (newcat_is_rig(rig, RIG_MODEL_FTDX101MP) + || newcat_is_rig(rig, RIG_MODEL_FTDX101D)) { offset = 6; - switch(token) + + switch (token) { - case TOK_MAXPOWER_HF: code = 1; break; - case TOK_MAXPOWER_6M: code = 2; break; - case TOK_MAXPOWER_4M: code = 3; break; - case TOK_MAXPOWER_AM: code = 4; break; - default: return -RIG_EINVAL; + case TOK_MAXPOWER_HF: code = 1; break; + + case TOK_MAXPOWER_6M: code = 2; break; + + case TOK_MAXPOWER_4M: code = 3; break; + + case TOK_MAXPOWER_AM: code = 4; break; + + default: return -RIG_EINVAL; } + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "EX0304%02d%c", code, cat_term); } + retval = newcat_get_cmd(rig); if (retval == RIG_OK) { - rig_debug(RIG_DEBUG_ERR, "%s: offset=%d, scanning '%s'\n", __func__, offset, &priv->ret_data[offset]); + rig_debug(RIG_DEBUG_ERR, "%s: offset=%d, scanning '%s'\n", __func__, offset, + &priv->ret_data[offset]); sscanf(&priv->ret_data[offset], "%d", &val->i); } @@ -7080,7 +7167,7 @@ int newcat_send_morse(RIG *rig, vfo_t vfo, const char *msg) char chan = '1'; - if (newcat_is_rig(rig, RIG_MODEL_FT450) && strlen(msg)==1 && msg[0] > '4') + if (newcat_is_rig(rig, RIG_MODEL_FT450) && strlen(msg) == 1 && msg[0] > '4') { // 450 manual says 1/2/3 playback needs P1=6/7/8 rig_debug(RIG_DEBUG_ERR, "%s: only messages 1-3 accepted\n", __func__); @@ -7090,54 +7177,68 @@ int newcat_send_morse(RIG *rig, vfo_t vfo, const char *msg) { // 5-chan playback 6-A: FT-1200, FT-2000, FT-3000, FTDX-5000, FT-891, FT-9000, FT-950, FT-991, FTDX-101MP/D, FTDX10 // 5-chan but 1-5 playback: FT-710 - if (strlen(msg)==1 && (msg[0] < '1' || msg[0] > '5')) + if (strlen(msg) == 1 && (msg[0] < '1' || msg[0] > '5')) { rig_debug(RIG_DEBUG_ERR, "%s: only messages 1-5 accepted\n", __func__); RETURNFUNC(-RIG_EINVAL); } + if (!newcat_is_rig(rig, RIG_MODEL_FT710)) { chan += 5; // 6,7,8 needed for playback } } + char *msg2 = strdup(msg); // copy so we can modify it if needed - if (strlen(msg2)==1) + if (strlen(msg2) == 1) { - switch(*msg2) + switch (*msg2) { - // do all Yaeus rigs play back with chan+5? - case '1': msg2[0] = '6';break; - case '2': msg2[0] = '7';break; - case '3': msg2[0] = '8';break; - case '4': msg2[0] = '9';break; - case '5': msg2[0] = 'A';break; - case '6': // we'll let these pass - case '7': - case '8': - case '9': - case 'A': - case 'a': - break; - default: + // do all Yaeus rigs play back with chan+5? + case '1': msg2[0] = '6'; break; + + case '2': msg2[0] = '7'; break; + + case '3': msg2[0] = '8'; break; + + case '4': msg2[0] = '9'; break; + + case '5': msg2[0] = 'A'; break; + + case '6': // we'll let these pass + case '7': + case '8': + case '9': + case 'A': + case 'a': + break; + + default: RETURNFUNC(-RIG_EINVAL); } } else { - if (strlen(msg2)>50) { - msg2[50]=0; // truncate if too long - rig_debug(RIG_DEBUG_ERR, "%s: msg length of %d truncated to 50\n", __func__, (int)strlen(msg)); + if (strlen(msg2) > 50) + { + msg2[50] = 0; // truncate if too long + rig_debug(RIG_DEBUG_ERR, "%s: msg length of %d truncated to 50\n", __func__, + (int)strlen(msg)); } - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "KM1%s;",msg2); + + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "KM1%s;", msg2); rc = newcat_set_cmd(rig); + if (rc != RIG_OK) { free(msg2); RETURNFUNC(-RIG_EINVAL); } + chan = '6'; // the channel we use to key msg 1 } + free(msg2); SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "KY%c%c", chan, cat_term); @@ -7325,6 +7426,7 @@ int newcat_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) { SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "AC002%c", cat_term); } + break; case RIG_OP_CPY: @@ -7629,17 +7731,17 @@ int newcat_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan) if (priv->width_frequency == 9) { - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), - "MW%03d%09d%+.4d%c%c%c%c%c%02u%c%c", - chan->channel_num, (int)chan->freq, rxit, c_rit, c_xit, c_mode, c_vfo, - c_tone, tone, c_rptr_shift, cat_term); + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), + "MW%03d%09d%+.4d%c%c%c%c%c%02u%c%c", + chan->channel_num, (int)chan->freq, rxit, c_rit, c_xit, c_mode, c_vfo, + c_tone, tone, c_rptr_shift, cat_term); } else { - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), - "MW%03d%08d%+.4d%c%c%c%c%c%02u%c%c", - chan->channel_num, (int)chan->freq, rxit, c_rit, c_xit, c_mode, c_vfo, - c_tone, tone, c_rptr_shift, cat_term); + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), + "MW%03d%08d%+.4d%c%c%c%c%c%02u%c%c", + chan->channel_num, (int)chan->freq, rxit, c_rit, c_xit, c_mode, c_vfo, + c_tone, tone, c_rptr_shift, cat_term); } rig_debug(RIG_DEBUG_TRACE, "%s: cmd_str = %s\n", __func__, priv->cmd_str); @@ -7705,11 +7807,13 @@ int newcat_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only) if (is_ftdx101d || is_ftdx101mp || is_ft991 || is_ft710) { - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MT%03d%c", chan->channel_num, cat_term); + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MT%03d%c", chan->channel_num, + cat_term); } else { - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MR%03d%c", chan->channel_num, cat_term); + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "MR%03d%c", chan->channel_num, + cat_term); } rig_debug(RIG_DEBUG_TRACE, "%s: cmd_str = %s\n", __func__, priv->cmd_str); @@ -7732,7 +7836,9 @@ int newcat_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only) RETURNFUNC(err); } - int offset=0; + + int offset = 0; + if (priv->width_frequency == 9) { offset = 1; @@ -7829,12 +7935,14 @@ int newcat_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only) chan->freq = atof(retval); chan->tag[0] = '?'; // assume nothing + if (priv->ret_data[28] != ';') // must have TAG data? { // get the TAG data - sscanf(&priv->ret_data[28],"%32s",chan->tag); - char *p = strchr(chan->tag,';'); - if(p) *p = 0; + sscanf(&priv->ret_data[28], "%32s", chan->tag); + char *p = strchr(chan->tag, ';'); + + if (p) { *p = 0; } } if (!read_only) @@ -8088,7 +8196,8 @@ int newcat_set_tx_vfo(RIG *rig, vfo_t tx_vfo) p1 = p1 + 2; /* use non-Toggle commands */ // If VFOB is active then we change VFOB with FT3 instead of VFOA - if (rig->state.current_vfo == RIG_VFO_B || rig->state.current_vfo == RIG_VFO_SUB) { p1++; } + if (rig->state.current_vfo == RIG_VFO_B + || rig->state.current_vfo == RIG_VFO_SUB) { p1++; } } // this doesn't seem to work on FTDX101MP latest firmware as of 20230911 so we test once and disable if needed @@ -8099,7 +8208,9 @@ int newcat_set_tx_vfo(RIG *rig, vfo_t tx_vfo) command = "ST"; SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "%s%c%c", command, p1, cat_term); int retval = newcat_set_cmd(rig); - if (retval != RIG_OK) {priv->ftdx101_st_missing = 1;retval=RIG_OK;} + + if (retval != RIG_OK) {priv->ftdx101_st_missing = 1; retval = RIG_OK;} + RETURNFUNC(retval); } @@ -9322,7 +9433,8 @@ static int set_roofing_filter_for_width(RIG *rig, vfo_t vfo, int width) for (i = 0; i < priv_caps->roofing_filter_count; i++) { - const struct newcat_roofing_filter *current_filter = &priv_caps->roofing_filters[i]; + const struct newcat_roofing_filter *current_filter = + &priv_caps->roofing_filters[i]; char set_value = current_filter->set_value; // Skip get-only values and optional filters @@ -10294,9 +10406,9 @@ int newcat_get_rx_bandwidth(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t *width) case 21: *width = 4000; break; - default: - - RETURNFUNC(-RIG_EINVAL); + default: + + RETURNFUNC(-RIG_EINVAL); } break; @@ -10674,9 +10786,11 @@ int newcat_get_vfo_mode(RIG *rig, vfo_t vfo, rmode_t *vfo_mode) { RETURNFUNC(err); } + if (rig->state.powerstat == 0) { - rig_debug(RIG_DEBUG_WARN, "%s: Cannot get from rig when power is off\n", __func__); + rig_debug(RIG_DEBUG_WARN, "%s: Cannot get from rig when power is off\n", + __func__); return RIG_OK; // to prevent repeats } @@ -10772,7 +10886,8 @@ int newcat_get_cmd(RIG *rig) if (state->powerstat == 0 && !is_power_status_cmd) { - rig_debug(RIG_DEBUG_WARN, "%s: Cannot get from rig when power is off\n", __func__); + rig_debug(RIG_DEBUG_WARN, "%s: Cannot get from rig when power is off\n", + __func__); return RIG_OK; // to prevent repeats } @@ -10857,12 +10972,15 @@ int newcat_get_cmd(RIG *rig) while (rc != RIG_OK && retry_count++ <= state->rigport.retry) { rig_flush(&state->rigport); /* discard any unsolicited data */ + if (rc != -RIG_BUSBUSY) { /* send the command */ rig_debug(RIG_DEBUG_TRACE, "cmd_str = %s\n", priv->cmd_str); - rc = write_block(&state->rigport, (unsigned char *) priv->cmd_str, strlen(priv->cmd_str)); + rc = write_block(&state->rigport, (unsigned char *) priv->cmd_str, + strlen(priv->cmd_str)); + if (rc != RIG_OK) { RETURNFUNC(rc); @@ -10880,6 +10998,7 @@ int newcat_get_cmd(RIG *rig) rig_debug(RIG_DEBUG_WARN, "%s: rig power is off?\n", __func__); RETURNFUNC(rc); } + continue; /* usually a timeout - retry */ } @@ -11051,7 +11170,8 @@ int newcat_set_cmd_validate(RIG *rig) } else if ((strncmp(priv->cmd_str, "TX", 2) == 0) && (strlen(priv->cmd_str) > 3)) { - if (priv->cmd_str[2]=='1' && rig->caps->rig_model == RIG_MODEL_FT950) // FT950 didn't like TX; after TX1; + if (priv->cmd_str[2] == '1' + && rig->caps->rig_model == RIG_MODEL_FT950) // FT950 didn't like TX; after TX1; { valcmd[0] = 0; } @@ -11150,7 +11270,7 @@ int newcat_set_cmd_validate(RIG *rig) { int bytes; char cmd[256]; // big enough - repeat: +repeat: rig_flush(&state->rigport); /* discard any unsolicited data */ SNPRINTF(cmd, sizeof(cmd), "%s", priv->cmd_str); rc = write_block(&state->rigport, (unsigned char *) cmd, strlen(cmd)); @@ -11160,8 +11280,10 @@ int newcat_set_cmd_validate(RIG *rig) if (strlen(valcmd) == 0) { RETURNFUNC(RIG_OK); } SNPRINTF(cmd, sizeof(cmd), "%s", valcmd); + // some rigs like FT-450/Signalink need a little time before we can ask for TX status again - if (strncmp(valcmd,"TX",2)==0) hl_usleep(50*1000); + if (strncmp(valcmd, "TX", 2) == 0) { hl_usleep(50 * 1000); } + rc = write_block(&state->rigport, (unsigned char *) cmd, strlen(cmd)); if (rc != RIG_OK) { RETURNFUNC(-RIG_EIO); } @@ -11169,21 +11291,25 @@ int newcat_set_cmd_validate(RIG *rig) bytes = read_string(&state->rigport, (unsigned char *) priv->ret_data, sizeof(priv->ret_data), &cat_term, sizeof(cat_term), 0, 1); + // we're expecting a response so we'll repeat if needed - if (bytes == 0) goto repeat; + if (bytes == 0) { goto repeat; } // FA and FB success is now verified in rig.c with a followup query // so no validation is needed - if (strncmp(priv->cmd_str, "FA", 2) == 0 || strncmp(priv->cmd_str, "FB", 2) == 0) + if (strncmp(priv->cmd_str, "FA", 2) == 0 + || strncmp(priv->cmd_str, "FB", 2) == 0) { return RIG_OK; } if (strncmp(priv->cmd_str, "PC", 2) == 0 && priv->ret_data[0] == '?') { - rig_debug(RIG_DEBUG_ERR, "%s: Power level error, check if exceeding max power setting\n", __func__); + rig_debug(RIG_DEBUG_ERR, + "%s: Power level error, check if exceeding max power setting\n", __func__); RETURNFUNC(RIG_OK); } + if (strncmp(priv->cmd_str, "FT", 2) == 0 && strncmp(priv->ret_data, "FT", 2) == 0) { @@ -11194,7 +11320,8 @@ int newcat_set_cmd_validate(RIG *rig) if (strncmp(priv->cmd_str, "TX", 2) == 0 && strncmp(priv->ret_data, "TX", 2) == 0) { - if (strstr(priv->ret_data,"TX2")) goto repeat; + if (strstr(priv->ret_data, "TX2")) { goto repeat; } + // TX command does not echo what's sent so we just check the basic command RETURNFUNC(RIG_OK); } @@ -11210,7 +11337,7 @@ int newcat_set_cmd_validate(RIG *rig) if (strncmp(priv->cmd_str, "VS", 2) == 0 && strncmp(priv->cmd_str, priv->ret_data, 2) == 0) { RETURNFUNC(RIG_OK); } else if (strcmp(priv->cmd_str, priv->ret_data) == 0) { RETURNFUNC(RIG_OK); } - else if (priv->cmd_str[0] == ';' && priv->ret_data[0]=='?') { hl_usleep(50*1000);RETURNFUNC(RIG_OK); } + else if (priv->cmd_str[0] == ';' && priv->ret_data[0] == '?') { hl_usleep(50 * 1000); RETURNFUNC(RIG_OK); } else { rc = -RIG_EPROTO; } } @@ -11284,7 +11411,8 @@ int newcat_set_cmd(RIG *rig) if (strncmp(priv->cmd_str, "FA", 2) == 0 || strncmp(priv->cmd_str, "FB", 2) == 0 || strncmp(priv->cmd_str, "TX", 2) == 0 - || strncmp(priv->cmd_str, "MD", 2) == 0 // Win4Yaesu not responding fast enough on MD change + || strncmp(priv->cmd_str, "MD", + 2) == 0 // Win4Yaesu not responding fast enough on MD change || strncmp(priv->cmd_str, "ST", 2) == 0) { RETURNFUNC(RIG_OK); @@ -11518,7 +11646,7 @@ rmode_t newcat_rmode_width(RIG *rig, vfo_t vfo, char mode, pbwidth_t *width) } // don't use RETURNFUNC here as that macros expects an int for the return code - RETURNFUNC2 (newcat_mode_conv[i].mode); + RETURNFUNC2(newcat_mode_conv[i].mode); } } @@ -11564,12 +11692,14 @@ static int newcat_set_clarifier(RIG *rig, vfo_t vfo, int rx, int tx) { int current_rx, current_tx, result; result = newcat_get_clarifier(rig, vfo, ¤t_rx, ¤t_tx); + if (result == RIG_OK) { if (rx < 0) { rx = current_rx; } + if (tx < 0) { tx = current_tx; @@ -11581,6 +11711,7 @@ static int newcat_set_clarifier(RIG *rig, vfo_t vfo, int rx, int tx) { rx = 0; } + if (tx < 0) { tx = 0; @@ -11589,7 +11720,7 @@ static int newcat_set_clarifier(RIG *rig, vfo_t vfo, int rx, int tx) } SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c00%d%d000%c", main_sub_vfo, - rx ? 1 : 0, tx ? 1 : 0, cat_term); + rx ? 1 : 0, tx ? 1 : 0, cat_term); RETURNFUNC2(newcat_set_cmd(rig)); } @@ -11612,7 +11743,8 @@ static int newcat_get_clarifier(RIG *rig, vfo_t vfo, int *rx, int *tx) main_sub_vfo = (RIG_VFO_B == vfo || RIG_VFO_SUB == vfo) ? '1' : '0'; } - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c00%c", main_sub_vfo, cat_term); + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c00%c", main_sub_vfo, + cat_term); if ((err = newcat_get_cmd(rig)) != RIG_OK) { @@ -11631,6 +11763,7 @@ static int newcat_get_clarifier(RIG *rig, vfo_t vfo, int *rx, int *tx) { *rx = (ret_data[0] == '1') ? 1 : 0; } + if (tx != NULL) { *tx = (ret_data[1] == '1') ? 1 : 0; @@ -11655,7 +11788,7 @@ int newcat_set_clarifier_frequency(RIG *rig, vfo_t vfo, shortfreq_t freq) } SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c01%+05d%c", main_sub_vfo, - (int) freq, cat_term); + (int) freq, cat_term); RETURNFUNC2(newcat_set_cmd(rig)); } @@ -11680,7 +11813,8 @@ int newcat_get_clarifier_frequency(RIG *rig, vfo_t vfo, shortfreq_t *freq) main_sub_vfo = (RIG_VFO_B == vfo || RIG_VFO_SUB == vfo) ? '1' : '0'; } - SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c01%c", main_sub_vfo, cat_term); + SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "CF%c01%c", main_sub_vfo, + cat_term); if ((err = newcat_get_cmd(rig)) != RIG_OK) { @@ -11696,9 +11830,11 @@ int newcat_get_clarifier_frequency(RIG *rig, vfo_t vfo, shortfreq_t *freq) priv->ret_data[ret_data_len - 1] = '\0'; result = sscanf(ret_data, "%05d", &freq_result); + if (result != 1) { - rig_debug(RIG_DEBUG_ERR, "%s: error parsing clarifier frequency: %s\n", __func__, ret_data); + rig_debug(RIG_DEBUG_ERR, "%s: error parsing clarifier frequency: %s\n", + __func__, ret_data); RETURNFUNC2(-RIG_EPROTO); } diff --git a/rigs/yaesu/vx1700.c b/rigs/yaesu/vx1700.c index 59be678da..648caf9c3 100644 --- a/rigs/yaesu/vx1700.c +++ b/rigs/yaesu/vx1700.c @@ -759,7 +759,8 @@ static const char *vx1700_get_info(RIG *rig) static int vx1700_set_vfo(RIG *rig, vfo_t vfo) { - const struct vx1700_priv_data *priv = (struct vx1700_priv_data *)rig->state.priv; + const struct vx1700_priv_data *priv = (struct vx1700_priv_data *) + rig->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s, vfo=%s\n", __func__, rig_strvfo(vfo)); @@ -1178,7 +1179,8 @@ static int vx1700_get_mem(RIG *rig, vfo_t vfo, int *ch) static int vx1700_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) { - const struct vx1700_priv_data *priv = (struct vx1700_priv_data *)rig->state.priv; + const struct vx1700_priv_data *priv = (struct vx1700_priv_data *) + rig->state.priv; (void) rig; (void) vfo; diff --git a/rigs/yaesu/yaesu.c b/rigs/yaesu/yaesu.c index 3580aa674..eb27487e0 100644 --- a/rigs/yaesu/yaesu.c +++ b/rigs/yaesu/yaesu.c @@ -73,7 +73,7 @@ DECLARE_INITRIG_BACKEND(yaesu) ft450d_caps.rig_model = RIG_MODEL_FT450D; ft450d_caps.model_name = "FT-450D"; ft450d_caps.level_gran[LVL_RFPOWER].min.f = .05; - ft450d_caps.level_gran[LVL_RFPOWER].step.f = 1.0f/100.0f; + ft450d_caps.level_gran[LVL_RFPOWER].step.f = 1.0f / 100.0f; rig_register(&ft100_caps); rig_register(&ft450_caps); rig_register(&ft450d_caps); diff --git a/rotators/flir/flir.c b/rotators/flir/flir.c index d67c25474..7303675a0 100644 --- a/rotators/flir/flir.c +++ b/rotators/flir/flir.c @@ -93,6 +93,7 @@ static int flir_request(ROT *rot, char *request, char *response, { int retry_read = 0; int read_char; + while (retry_read < rot->state.rotport.retry) { memset(response, 0, (size_t)resp_size); @@ -185,6 +186,7 @@ static int flir_open(ROT *rot) // Disable ECHO return_value = flir_request(rot, "ED\n", NULL, MAXBUF); + if (return_value != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: ED: %s\n", __func__, rigerror(return_value)); @@ -193,6 +195,7 @@ static int flir_open(ROT *rot) // Disable Verbose Mode return_value = flir_request(rot, "FT\n", return_str, MAXBUF); + if (return_value != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: FT: %s\n", __func__, rigerror(return_value)); @@ -323,18 +326,22 @@ static int flir_stop(ROT *rot) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); return_value = flir_request(rot, "H\n", NULL, MAXBUF); + if (return_value != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: H: %s\n", __func__, rigerror(return_value)); return return_value; } + // Wait 2s until rotor has stopped (Needs to be refactored) hl_usleep(2000000); return_value = flir_get_position(rot, &az, &el); + if (return_value != RIG_OK) { - rig_debug(RIG_DEBUG_ERR, "%s: flrig_get_position: %s\n", __func__, rigerror(return_value)); + rig_debug(RIG_DEBUG_ERR, "%s: flrig_get_position: %s\n", __func__, + rigerror(return_value)); return return_value; } @@ -495,7 +502,7 @@ static int flir_get_ext_parm(ROT *rot, token_t token, value_t *val) static int flir_get_status(ROT *rot, rot_status_t *status) { const struct flir_priv_data *priv = (struct flir_priv_data *) - rot->state.priv; + rot->state.priv; *status = priv->status; return RIG_OK; diff --git a/rotators/fodtrack/fodtrack.c b/rotators/fodtrack/fodtrack.c index d901bdd03..1d570235f 100644 --- a/rotators/fodtrack/fodtrack.c +++ b/rotators/fodtrack/fodtrack.c @@ -52,7 +52,8 @@ static int setDirection(hamlib_port_t *port, unsigned char outputvalue, unsigned char outputstatus; retval = par_lock(port); - if (retval != RIG_OK) + + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): %s\n", __func__, __LINE__, rigerror(retval)); return retval; @@ -60,7 +61,8 @@ static int setDirection(hamlib_port_t *port, unsigned char outputvalue, // set the data bits retval = par_write_data(port, outputvalue); - if (retval != RIG_OK) + + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): %s\n", __func__, __LINE__, rigerror(retval)); return retval; @@ -77,11 +79,13 @@ static int setDirection(hamlib_port_t *port, unsigned char outputvalue, } retval = par_write_control(port, outputstatus ^ CP_ACTIVE_LOW_BITS); - if (retval != RIG_OK) + + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): %s\n", __func__, __LINE__, rigerror(retval)); return retval; } + // and now the strobe impulse hl_usleep(1); @@ -95,11 +99,13 @@ static int setDirection(hamlib_port_t *port, unsigned char outputvalue, } retval = par_write_control(port, outputstatus ^ CP_ACTIVE_LOW_BITS); - if (retval != RIG_OK) + + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): %s\n", __func__, __LINE__, rigerror(retval)); return retval; } + hl_usleep(1); if (direction) @@ -112,14 +118,16 @@ static int setDirection(hamlib_port_t *port, unsigned char outputvalue, } retval = par_write_control(port, outputstatus ^ CP_ACTIVE_LOW_BITS); - if (retval != RIG_OK) + + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): %s\n", __func__, __LINE__, rigerror(retval)); return retval; } retval = par_unlock(port); - if (retval != RIG_OK) + + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s(%d): %s\n", __func__, __LINE__, rigerror(retval)); return retval; diff --git a/rotators/gs232a/gs232b.c b/rotators/gs232a/gs232b.c index 614900566..a0872d44c 100644 --- a/rotators/gs232a/gs232b.c +++ b/rotators/gs232a/gs232b.c @@ -294,7 +294,8 @@ static int gs232b_rot_set_level(ROT *rot, setting_t level, value_t val) switch (level) { - int retval; + int retval; + case ROT_LEVEL_SPEED: { int speed = val.i; diff --git a/rotators/ioptron/rot_ioptron.c b/rotators/ioptron/rot_ioptron.c index 3336914ce..f46d58612 100644 --- a/rotators/ioptron/rot_ioptron.c +++ b/rotators/ioptron/rot_ioptron.c @@ -84,8 +84,9 @@ ioptron_transaction(ROT *rot, const char *cmdstr, char *data, size_t resp_len) } /** the answer */ - memset(data, 0, resp_len+1); + memset(data, 0, resp_len + 1); retval = read_block(&rs->rotport, (unsigned char *) data, resp_len); + /** if expected number of bytes received, return OK status */ if (retval == resp_len) { @@ -93,8 +94,9 @@ ioptron_transaction(ROT *rot, const char *cmdstr, char *data, size_t resp_len) } } - /** if got here, retry loop failed */ - rig_debug(RIG_DEBUG_ERR, "%s: unexpected response, len %d: '%s'\n", __func__, retval, data); + /** if got here, retry loop failed */ + rig_debug(RIG_DEBUG_ERR, "%s: unexpected response, len %d: '%s'\n", __func__, + retval, data); return -RIG_EPROTO; } @@ -129,10 +131,11 @@ ioptron_open(ROT *rot) const char *info; int retval; char retbuf[10]; - + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); info = ioptron_get_info(rot); + /* ioptron_get_info returns "MountInfo xxxx", check model number from string */ /* string of 4 numeric digits is likely model number */ if ((strlen(&info[10]) != 4) || (strspn(&info[10], "1234567890") != 4)) @@ -156,7 +159,7 @@ ioptron_open(ROT *rot) { return -RIG_EPROTO; } - + return RIG_OK; } @@ -246,7 +249,7 @@ ioptron_set_position(ROT *rot, azimuth_t az, elevation_t el) elevation_t curr_el; rig_debug(RIG_DEBUG_TRACE, "%s called: %f %f\n", __func__, az, el); - + /* units .01 arc sec */ faz = az * 360000; fel = el * 360000; @@ -269,13 +272,15 @@ ioptron_set_position(ROT *rot, azimuth_t az, elevation_t el) { /* make sure stopped */ retval = ioptron_stop(rot); + if (retval != RIG_OK) { return -RIG_EPROTO; } - + /* get current position */ retval = ioptron_get_position(rot, &curr_az, &curr_el); + if (retval != RIG_OK) { return -RIG_EPROTO; @@ -290,7 +295,7 @@ ioptron_set_position(ROT *rot, azimuth_t az, elevation_t el) faz = 129599999; /* needs double precision float */ } } - + /* set azmiuth, returns '1" if OK */ SNPRINTF(cmdstr, sizeof(cmdstr), ":Sz%09.0f#", faz); retval = ioptron_transaction(rot, cmdstr, retbuf, 1); diff --git a/rotators/spid/spid.c b/rotators/spid/spid.c index 90bcd0f42..d32e1a067 100644 --- a/rotators/spid/spid.c +++ b/rotators/spid/spid.c @@ -39,12 +39,14 @@ struct spid_rot2prog_priv_data int el_resolution; }; -enum spid_rot2prog_framemagic { +enum spid_rot2prog_framemagic +{ ROT2PROG_FRAME_START_BYTE = 'W', ROT2PROG_FRAME_END_BYTE = ' ', }; -enum r2p_frame_parser_state { +enum r2p_frame_parser_state +{ ROT2PROG_PARSER_EXPECT_FRAME_START, ROT2PROG_PARSER_EXPECT_CR, ROT2PROG_PARSER_EXPECT_LF, @@ -52,7 +54,7 @@ enum r2p_frame_parser_state { }; static int read_r2p_frame(hamlib_port_t *port, unsigned char *rxbuffer, - size_t count) + size_t count) { // Some MD-01 firmware can apparently print debug messages to the same // serial port that is used for the control protocol. This awkwardly @@ -108,31 +110,36 @@ static int read_r2p_frame(hamlib_port_t *port, unsigned char *rxbuffer, { case ROT2PROG_PARSER_EXPECT_FRAME_START: res = read_block(port, &peek, 1); - if (res < 0) return res; + + if (res < 0) { return res; } switch (peek) { - case ROT2PROG_FRAME_START_BYTE: - rxbuffer[0] = peek; - pstate = ROT2PROG_PARSER_EXPECT_FRAME_END; - break; + case ROT2PROG_FRAME_START_BYTE: + rxbuffer[0] = peek; + pstate = ROT2PROG_PARSER_EXPECT_FRAME_END; + break; - default: - pstate = ROT2PROG_PARSER_EXPECT_CR; - break; + default: + pstate = ROT2PROG_PARSER_EXPECT_CR; + break; } + break; case ROT2PROG_PARSER_EXPECT_CR: res = read_block(port, &peek, 1); - if (res < 0) return res; - if (peek == '\r') pstate = ROT2PROG_PARSER_EXPECT_LF; + if (res < 0) { return res; } + + if (peek == '\r') { pstate = ROT2PROG_PARSER_EXPECT_LF; } + break; case ROT2PROG_PARSER_EXPECT_LF: res = read_block(port, &peek, 1); - if (res < 0) return res; + + if (res < 0) { return res; } if (peek == '\n') { @@ -147,12 +154,14 @@ static int read_r2p_frame(hamlib_port_t *port, unsigned char *rxbuffer, // happen. return -RIG_EPROTO; } + break; case ROT2PROG_PARSER_EXPECT_FRAME_END: // we already read the frame start byte res = read_block(port, rxbuffer + 1, count - 1); - if (res < 0) return res; + + if (res < 0) { return res; } if (rxbuffer[count - 1] != ROT2PROG_FRAME_END_BYTE) { @@ -172,7 +181,9 @@ static int spid_write(hamlib_port_t *p, const unsigned char *txbuffer, size_t count) { int ret = rig_flush(p); - if (ret < 0) return ret; + + if (ret < 0) { return ret; } + return write_block(p, txbuffer, count); } @@ -230,7 +241,7 @@ static int spid_rot_cleanup(ROT *rot) static int spid_get_conf2(ROT *rot, token_t token, char *val, int val_len) { const struct spid_rot2prog_priv_data *priv = (struct spid_rot2prog_priv_data *) - rot->state.priv; + rot->state.priv; rig_debug(RIG_DEBUG_TRACE, "%s called %d\n", __func__, (int)token); @@ -333,7 +344,7 @@ static int spid_rot2prog_rot_set_position(ROT *rot, azimuth_t az, { struct rot_state *rs = &rot->state; const struct spid_rot2prog_priv_data *priv = (struct spid_rot2prog_priv_data *) - rs->priv; + rs->priv; int retval; int retry_read = 0; char cmdstr[13]; @@ -346,7 +357,7 @@ static int spid_rot2prog_rot_set_position(ROT *rot, azimuth_t az, do { retval = spid_write(&rs->rotport, - (unsigned char *) "\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1F\x20", 13); + (unsigned char *) "\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1F\x20", 13); if (retval != RIG_OK) { @@ -421,7 +432,7 @@ static int spid_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) do { retval = spid_write(&rs->rotport, - (unsigned char *) "\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1F\x20", 13); + (unsigned char *) "\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1F\x20", 13); if (retval != RIG_OK) { @@ -493,7 +504,7 @@ static int spid_rot_stop(ROT *rot) do { retval = spid_write(&rs->rotport, - (unsigned char *) "\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0F\x20", 13); + (unsigned char *) "\x57\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0F\x20", 13); if (retval != RIG_OK) { diff --git a/rotators/ts7400/ts7400.c b/rotators/ts7400/ts7400.c index 68ef8f1b0..f8abef74d 100644 --- a/rotators/ts7400/ts7400.c +++ b/rotators/ts7400/ts7400.c @@ -224,7 +224,7 @@ static int ts7400_rot_reset(ROT *rot, rot_reset_t reset) static int ts7400_rot_move(ROT *rot, int direction, int speed) { struct ts7400_rot_priv_data const *priv = (struct ts7400_rot_priv_data *) - rot->state.priv; + rot->state.priv; rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); rig_debug(RIG_DEBUG_TRACE, "%s: Direction = %d, Speed = %d\n", __func__, diff --git a/security/md5.c b/security/md5.c index c38ee3d64..b5ceb3883 100644 --- a/security/md5.c +++ b/security/md5.c @@ -3,7 +3,7 @@ char *make_digest(const unsigned char *digest, int len) /* {{{ */ { int md5len = sizeof(char) * (len * 2 + 1); - char *md5str = (char *) calloc(1, md5len); + char *md5str = (char *) calloc(1, md5len); static const char hexits[17] = "0123456789abcdef"; int i; diff --git a/security/password.c b/security/password.c index 51034682f..b45f3be1d 100644 --- a/security/password.c +++ b/security/password.c @@ -42,6 +42,7 @@ HAMLIB_EXPORT(void) rig_password_generate_secret(char *pass, product = pass[0]; int i; + for (i = 1; pass[i]; ++i) { product *= pass[i]; diff --git a/security/sha256.c b/security/sha256.c index c78c1d6f2..73224a3e9 100644 --- a/security/sha256.c +++ b/security/sha256.c @@ -342,6 +342,7 @@ int main(int argc, const char *argv[]) else { FILE *f; + if (!(f = fopen(argv[1], "rb"))) { perror("fopen"); diff --git a/simulators/simelecraft.c b/simulators/simelecraft.c index d047474c7..9296d7dbc 100644 --- a/simulators/simelecraft.c +++ b/simulators/simelecraft.c @@ -70,7 +70,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simft817.c b/simulators/simft817.c index a77fd3ddf..2d23edb04 100644 --- a/simulators/simft817.c +++ b/simulators/simft817.c @@ -122,10 +122,12 @@ again: case 0x88: printf("PTT OFF\n"); break; - case 0x07: - printf("MODE %0xx\n", buf[0]); - if (vfo == 0) modeA = buf[0]; - else modeB = buf[0]; + case 0x07: + printf("MODE %0xx\n", buf[0]); + + if (vfo == 0) { modeA = buf[0]; } + else { modeB = buf[0]; } + break; case 0x05: printf("CLAR ON\n"); break; @@ -134,10 +136,10 @@ again: case 0xF5: printf("FREQ\n"); break; - case 0x81: - vfo = !vfo; - printf("VFO TOGGLE, %s active\n", vfo==0?"VFOA":"VFOB"); - break; + case 0x81: + vfo = !vfo; + printf("VFO TOGGLE, %s active\n", vfo == 0 ? "VFOA" : "VFOB"); + break; case 0x02: printf("SPLIT ON\n"); break; diff --git a/simulators/simft818.c b/simulators/simft818.c index dda144558..97dee0891 100644 --- a/simulators/simft818.c +++ b/simulators/simft818.c @@ -63,7 +63,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simft991.c b/simulators/simft991.c index 3ce19996d..29644b7a4 100644 --- a/simulators/simft991.c +++ b/simulators/simft991.c @@ -63,7 +63,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } @@ -139,10 +140,11 @@ int main(int argc, char *argv[]) if (n <= 0) { perror("RM5"); } } - else if (strcmp(buf,"MR118;") == 0) + else if (strcmp(buf, "MR118;") == 0) { pbuf = "?;"; n = write(fd, pbuf, strlen(pbuf)); + if (n <= 0) { perror("MR118"); } } diff --git a/simulators/simftdx101.c b/simulators/simftdx101.c index 10e34e72f..361b1d152 100644 --- a/simulators/simftdx101.c +++ b/simulators/simftdx101.c @@ -32,11 +32,11 @@ int na = 0; int ex039 = 0; int keyspd = 20; int split = 0; -int power=50; -int rport_gain_ssb=50; -int rport_gain_am=50; -int rport_gain_fm=50; -int rport_gain_psk=50; +int power = 50; +int rport_gain_ssb = 50; +int rport_gain_am = 50; +int rport_gain_fm = 50; +int rport_gain_psk = 50; // ID 0310 == 310, Must drop leading zero typedef enum nc_rigid_e @@ -72,7 +72,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } @@ -332,13 +333,13 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "EX010415;") == 0) { - sprintf(buf,"EX010415%03d;", rport_gain_psk); + sprintf(buf, "EX010415%03d;", rport_gain_psk); n = write(fd, buf, strlen(buf)); } else if (strncmp(buf, "EX010415", 8) == 0) { printf("Here#1"); - sscanf(buf,"EX010415%d", &rport_gain_psk); + sscanf(buf, "EX010415%d", &rport_gain_psk); } else if (strlen(buf) > 0) diff --git a/simulators/simftdx1200.c b/simulators/simftdx1200.c index a5c948a78..0d710fa8d 100644 --- a/simulators/simftdx1200.c +++ b/simulators/simftdx1200.c @@ -65,7 +65,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simftdx3000.c b/simulators/simftdx3000.c index 361993dd9..71d154ba8 100644 --- a/simulators/simftdx3000.c +++ b/simulators/simftdx3000.c @@ -64,7 +64,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simftdx5000.c b/simulators/simftdx5000.c index a2560b4f9..16885a26c 100644 --- a/simulators/simftdx5000.c +++ b/simulators/simftdx5000.c @@ -66,7 +66,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simic7300.c b/simulators/simic7300.c index c49d0ea68..962269df4 100644 --- a/simulators/simic7300.c +++ b/simulators/simic7300.c @@ -72,7 +72,7 @@ again: while (read(fd, &c, 1) > 0) { buf[i++] = c; - printf("i=%d, c=0x%02x\n",i,c); + printf("i=%d, c=0x%02x\n", i, c); if (c == 0xfd) { @@ -141,7 +141,7 @@ void frameParse(int fd, unsigned char *frame, int len) if (powerstat) { - dump_hex(frame,11); + dump_hex(frame, 11); n = write(fd, frame, 11); if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } diff --git a/simulators/simic7610.c b/simulators/simic7610.c index 0640739b3..60ac213c1 100644 --- a/simulators/simic7610.c +++ b/simulators/simic7610.c @@ -398,42 +398,58 @@ void frameParse(int fd, unsigned char *frame, int len) frame[6] = satmode; frame[7] = 0xfd; n = write(fd, frame, 8); + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } break; + case 0x65: if (frame[6] == 0xfd) + { ipp = frame[6]; + } else { frame[6] = ipp; - frame[7]=0xfd; + frame[7] = 0xfd; n = write(fd, frame, 8); + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } + break; + case 0x66: if (frame[6] == 0xfd) + { tx_inhibit = frame[6]; + } else { frame[6] = tx_inhibit; - frame[7]=0xfd; + frame[7] = 0xfd; n = write(fd, frame, 8); + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } + break; + case 0x67: if (frame[6] == 0xfd) + { dpp = frame[6]; + } else { frame[6] = dpp; - frame[7]=0xfd; + frame[7] = 0xfd; n = write(fd, frame, 8); + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } } + break; } @@ -780,10 +796,11 @@ int main(int argc, char **argv) while (1) { int len = frameGet(fd, buf); -printf("#1 ========================================"); + printf("#1 ========================================"); + if (len <= 0) { -printf("#2 ========================================"); + printf("#2 ========================================"); close(fd); fd = openPort(argv[1]); } @@ -797,9 +814,9 @@ printf("#2 ========================================"); hl_usleep(100 * 1000); } -printf("#3 ========================================"); + printf("#3 ========================================"); rigStatus(); -printf("#3 ========================================"); + printf("#3 ========================================"); } return 0; diff --git a/simulators/simic9100.c b/simulators/simic9100.c index afd7e1587..ae62cb0e3 100644 --- a/simulators/simic9100.c +++ b/simulators/simic9100.c @@ -517,6 +517,7 @@ void frameParse(int fd, unsigned char *frame, int len) default: printf("cmd 0x%02x unknown\n", frame[4]); } + // don't care about the rig type yet } diff --git a/simulators/simic9700.c b/simulators/simic9700.c index 9c2763e4d..ec665a569 100644 --- a/simulators/simic9700.c +++ b/simulators/simic9700.c @@ -533,6 +533,7 @@ void frameParse(int fd, unsigned char *frame, int len) default: printf("cmd 0x%02x unknown\n", frame[4]); } + // don't care about the rig type yet } diff --git a/simulators/simkenwood.c b/simulators/simkenwood.c index 12d1d8ff4..2f27cba27 100644 --- a/simulators/simkenwood.c +++ b/simulators/simkenwood.c @@ -60,7 +60,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simpowersdr.c b/simulators/simpowersdr.c index fac5f2456..a84543a20 100644 --- a/simulators/simpowersdr.c +++ b/simulators/simpowersdr.c @@ -61,7 +61,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simqrplabs.c b/simulators/simqrplabs.c index c33612307..a1399cf9b 100644 --- a/simulators/simqrplabs.c +++ b/simulators/simqrplabs.c @@ -40,7 +40,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simrotorez.c b/simulators/simrotorez.c index fdd859ece..aa1ebc6ea 100644 --- a/simulators/simrotorez.c +++ b/simulators/simrotorez.c @@ -39,7 +39,8 @@ getmyline(int fd, char *buf) printf("\n"); } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return n; } diff --git a/simulators/simtmd700.c b/simulators/simtmd700.c index 67501b28b..e914645d2 100644 --- a/simulators/simtmd700.c +++ b/simulators/simtmd700.c @@ -60,7 +60,8 @@ getmyline(int fd, char *buf) buf[i++] = c; } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simtrusdx.c b/simulators/simtrusdx.c index 211f20d6e..951f340aa 100644 --- a/simulators/simtrusdx.c +++ b/simulators/simtrusdx.c @@ -42,7 +42,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simts450.c b/simulators/simts450.c index 853db5c85..52caf30da 100644 --- a/simulators/simts450.c +++ b/simulators/simts450.c @@ -42,7 +42,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simts590.c b/simulators/simts590.c index 08e444f11..4f6f350a1 100644 --- a/simulators/simts590.c +++ b/simulators/simts590.c @@ -41,14 +41,16 @@ getmyline(int fd, char *buf) int i = 0; memset(buf, 0, BUFSIZE); - hl_usleep(5*1000); + hl_usleep(5 * 1000); + while (read(fd, &c, 1) > 0) { buf[i++] = c; if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } @@ -160,20 +162,20 @@ int main(int argc, char *argv[]) } else if (strncmp(buf, "MG", 2) == 0) { - sscanf(buf,"MG%d", &mic_gain); + sscanf(buf, "MG%d", &mic_gain); } else if (strcmp(buf, "AG0;") == 0) { SNPRINTF(buf, sizeof(buf), "AG0%03d;", afgain); WRITE(fd, buf, strlen(buf)); } - else if (strncmp(buf, "AG0",3) == 0) + else if (strncmp(buf, "AG0", 3) == 0) { - sscanf(buf,"AG0%d",&afgain); + sscanf(buf, "AG0%d", &afgain); } - else if (strncmp(buf,"AG",2) == 0) + else if (strncmp(buf, "AG", 2) == 0) { - WRITE(fd,"?;",2); + WRITE(fd, "?;", 2); } else if (strcmp(buf, "FV;") == 0) { @@ -417,7 +419,7 @@ int main(int argc, char *argv[]) else if (strncmp(buf, "SH", 2) == 0) { SNPRINTF(buf, sizeof(buf), "SH%02d;", width_high); - WRITE(fd,buf,strlen(buf)); + WRITE(fd, buf, strlen(buf)); } else if (strncmp(buf, "SL", 2) == 0 && strlen(buf) > 4) { @@ -427,7 +429,7 @@ int main(int argc, char *argv[]) else if (strncmp(buf, "SL", 2) == 0) { SNPRINTF(buf, sizeof(buf), "SL%02d;", width_low); - WRITE(fd,buf,strlen(buf)); + WRITE(fd, buf, strlen(buf)); } else if (strlen(buf) > 0) diff --git a/simulators/simts950.c b/simulators/simts950.c index c9b9ba2ca..4ea2136d3 100644 --- a/simulators/simts950.c +++ b/simulators/simts950.c @@ -40,7 +40,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/simulators/simts990.c b/simulators/simts990.c index 9433aaa8b..4c5948c6c 100644 --- a/simulators/simts990.c +++ b/simulators/simts990.c @@ -80,19 +80,21 @@ getmyline(int fd, char *buf) memset(buf, 0, BUFSIZE); int retval; - while ((retval=read(fd, &c, 1)) > 0) + while ((retval = read(fd, &c, 1)) > 0) { buf[i++] = c; if (c == ';') { return strlen(buf); } } + if (retval != 0) { perror("read failed:"); close(fd); fd = openPort(""); } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } @@ -461,7 +463,7 @@ int main(int argc, char *argv[]) { sscanf(buf, "OM1%d", &modeSub); } - else if (strcmp(buf,"RM;") == 0) + else if (strcmp(buf, "RM;") == 0) { sprintf(buf, "RM2%04d;", 10); write(fd, buf, strlen(buf)); diff --git a/simulators/simyaesu.c b/simulators/simyaesu.c index 2759930ad..1f5f96e8c 100644 --- a/simulators/simyaesu.c +++ b/simulators/simyaesu.c @@ -69,7 +69,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } - if (strlen(buf)==0) hl_usleep(10*1000); + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } return strlen(buf); } diff --git a/src/amp_conf.c b/src/amp_conf.c index e47d7d1ef..ac5f5a8b2 100644 --- a/src/amp_conf.c +++ b/src/amp_conf.c @@ -268,6 +268,7 @@ int frontamp_set_conf(AMP *amp, token_t token, const char *val) } break; + case TOK_RTS_STATE: if (rs->ampport.type.rig != RIG_PORT_SERIAL) { diff --git a/src/amplifier.c b/src/amplifier.c index 8800851ab..318998594 100644 --- a/src/amplifier.c +++ b/src/amplifier.c @@ -418,7 +418,7 @@ int HAMLIB_API amp_open(AMP *amp) } } - if(rs->ampport.parm.serial.dtr_state == RIG_SIGNAL_ON) + if (rs->ampport.parm.serial.dtr_state == RIG_SIGNAL_ON) { ser_set_dtr(&rs->ampport, 1); } @@ -426,7 +426,8 @@ int HAMLIB_API amp_open(AMP *amp) { ser_set_dtr(&rs->ampport, 0); } - if(rs->ampport.parm.serial.rts_state == RIG_SIGNAL_ON) + + if (rs->ampport.parm.serial.rts_state == RIG_SIGNAL_ON) { ser_set_rts(&rs->ampport, 1); } @@ -471,6 +472,7 @@ int HAMLIB_API amp_close(AMP *amp) amp_debug(RIG_DEBUG_ERR, "%s: NULL ptr? amp=%p\n", __func__, amp); return -RIG_EINVAL; } + if (amp->caps == NULL) { amp_debug(RIG_DEBUG_ERR, "%s: NULL ptr? amp->caps=%p\n", __func__, amp->caps); diff --git a/src/cache.c b/src/cache.c index 75dea96a3..e976998f8 100644 --- a/src/cache.c +++ b/src/cache.c @@ -216,9 +216,10 @@ int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq) break; case RIG_VFO_OTHER: - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): ignoring VFO_OTHER\n", __func__, __LINE__); + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): ignoring VFO_OTHER\n", __func__, + __LINE__); break; - + default: rig_debug(RIG_DEBUG_WARN, "%s(%d): unknown vfo?, vfo=%s\n", __func__, __LINE__, rig_strvfo(vfo)); @@ -327,11 +328,13 @@ int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq, break; case RIG_VFO_NONE: - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): ignoring VFO_OTHER\n", __func__, __LINE__); + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): ignoring VFO_OTHER\n", __func__, + __LINE__); break; default: - rig_debug(RIG_DEBUG_WARN, "%s(%d): unknown vfo=%s, curr_vfo=%s\n", __func__, __LINE__, + rig_debug(RIG_DEBUG_WARN, "%s(%d): unknown vfo=%s, curr_vfo=%s\n", __func__, + __LINE__, rig_strvfo(vfo), rig_strvfo(rig->state.current_vfo)); } } diff --git a/src/conf.c b/src/conf.c index 6e5102de4..6ed087f6d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -274,8 +274,9 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) case TOK_POST_PTT_DELAY: if (1 != sscanf(val, "%ld", &val_i)) { - return -RIG_EINVAL; + return -RIG_EINVAL; } + rs->post_ptt_delay = val_i; break; @@ -662,6 +663,7 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) { return -RIG_EINVAL; } + rs->poll_interval = val_i; // Make sure cache times out before next poll cycle rig_set_cache_timeout_ms(rig, HAMLIB_CACHE_ALL, atol(val)); diff --git a/src/event.c b/src/event.c index 10ca23ab9..2a833fc4a 100644 --- a/src/event.c +++ b/src/event.c @@ -72,9 +72,12 @@ void *rig_poll_routine(void *arg) int update_occurred; vfo_t vfo = RIG_VFO_NONE, tx_vfo = RIG_VFO_NONE; - freq_t freq_main_a = 0, freq_main_b = 0, freq_main_c = 0, freq_sub_a = 0, freq_sub_b = 0, freq_sub_c = 0; - rmode_t mode_main_a = 0, mode_main_b = 0, mode_main_c = 0, mode_sub_a = 0, mode_sub_b = 0, mode_sub_c = 0; - pbwidth_t width_main_a = 0, width_main_b = 0, width_main_c = 0, width_sub_a = 0, width_sub_b = 0, width_sub_c = 0; + freq_t freq_main_a = 0, freq_main_b = 0, freq_main_c = 0, freq_sub_a = 0, + freq_sub_b = 0, freq_sub_c = 0; + rmode_t mode_main_a = 0, mode_main_b = 0, mode_main_c = 0, mode_sub_a = 0, + mode_sub_b = 0, mode_sub_c = 0; + pbwidth_t width_main_a = 0, width_main_b = 0, width_main_c = 0, width_sub_a = 0, + width_sub_b = 0, width_sub_c = 0; ptt_t ptt = RIG_PTT_OFF; split_t split = RIG_SPLIT_OFF; @@ -99,106 +102,127 @@ void *rig_poll_routine(void *arg) vfo = rig->state.current_vfo; update_occurred = 1; } + if (rig->state.tx_vfo != tx_vfo) { tx_vfo = rig->state.tx_vfo; update_occurred = 1; } + if (rig->state.cache.freqMainA != freq_main_a) { freq_main_a = rig->state.cache.freqMainA; update_occurred = 1; } + if (rig->state.cache.freqMainB != freq_main_b) { freq_main_b = rig->state.cache.freqMainB; update_occurred = 1; } + if (rig->state.cache.freqMainC != freq_main_c) { freq_main_b = rig->state.cache.freqMainC; update_occurred = 1; } + if (rig->state.cache.freqSubA != freq_sub_a) { freq_sub_a = rig->state.cache.freqSubA; update_occurred = 1; } + if (rig->state.cache.freqSubB != freq_sub_b) { freq_sub_b = rig->state.cache.freqSubB; update_occurred = 1; } + if (rig->state.cache.freqSubC != freq_sub_c) { freq_sub_c = rig->state.cache.freqSubC; update_occurred = 1; } + if (rig->state.cache.ptt != ptt) { ptt = rig->state.cache.ptt; update_occurred = 1; } + if (rig->state.cache.split != split) { split = rig->state.cache.split; update_occurred = 1; } + if (rig->state.cache.modeMainA != mode_main_a) { mode_main_a = rig->state.cache.modeMainA; update_occurred = 1; } + if (rig->state.cache.modeMainB != mode_main_b) { mode_main_b = rig->state.cache.modeMainB; update_occurred = 1; } + if (rig->state.cache.modeMainC != mode_main_c) { mode_main_c = rig->state.cache.modeMainC; update_occurred = 1; } + if (rig->state.cache.modeSubA != mode_sub_a) { mode_sub_a = rig->state.cache.modeSubA; update_occurred = 1; } + if (rig->state.cache.modeSubB != mode_sub_b) { mode_sub_b = rig->state.cache.modeSubB; update_occurred = 1; } + if (rig->state.cache.modeSubC != mode_sub_c) { mode_sub_c = rig->state.cache.modeSubC; update_occurred = 1; } + if (rig->state.cache.widthMainA != width_main_a) { width_main_a = rig->state.cache.widthMainA; update_occurred = 1; } + if (rig->state.cache.widthMainB != width_main_b) { width_main_b = rig->state.cache.widthMainB; update_occurred = 1; } + if (rig->state.cache.widthMainC != width_main_c) { width_main_c = rig->state.cache.widthMainC; update_occurred = 1; } + if (rig->state.cache.widthSubA != width_sub_a) { width_sub_a = rig->state.cache.widthSubA; update_occurred = 1; } + if (rig->state.cache.widthSubB != width_sub_b) { width_sub_b = rig->state.cache.widthSubB; update_occurred = 1; } + if (rig->state.cache.widthSubC != width_sub_c) { width_sub_c = rig->state.cache.widthSubC; @@ -588,9 +612,11 @@ int rig_fire_freq_event(RIG *rig, vfo_t vfo, freq_t freq) { ENTERFUNC; - rig_debug(RIG_DEBUG_TRACE, "Event: freq changed to %"PRIll"Hz on %s\n", (int64_t)freq, rig_strvfo(vfo)); + rig_debug(RIG_DEBUG_TRACE, "Event: freq changed to %"PRIll"Hz on %s\n", + (int64_t)freq, rig_strvfo(vfo)); rig_set_cache_freq(rig, vfo, freq); + // This doesn't work well for Icom rigs -- no way to tell which VFO we're on // Should work for most other rigs using AI1; mode if (RIG_BACKEND_NUM(rig->caps->rig_model) != RIG_ICOM) @@ -618,6 +644,7 @@ int rig_fire_mode_event(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) rig_strrmode(mode), width, rig_strvfo(vfo)); rig_set_cache_mode(rig, vfo, mode, width); + // This doesn't work well for Icom rigs -- no way to tell which VFO we're on // Should work for most other rigs using AI1; mode if (RIG_BACKEND_NUM(rig->caps->rig_model) != RIG_ICOM) diff --git a/src/fifo.c b/src/fifo.c index 489ec8884..8baf69d82 100644 --- a/src/fifo.c +++ b/src/fifo.c @@ -34,20 +34,23 @@ int push(FIFO_RIG *fifo, const char *msg) { // FIFO is meant for CW use only // So we skip some chars that don't work with CW - if (msg[i] & 0x80) continue; // drop any chars that have high bit set - switch(msg[i]) + if (msg[i] & 0x80) { continue; } // drop any chars that have high bit set + + switch (msg[i]) { - case 0x0d: - case 0x0a: + case 0x0d: + case 0x0a: continue; } + fifo->data[fifo->tail] = msg[i]; + if (isalnum(msg[i])) - rig_debug(RIG_DEBUG_VERBOSE, "%s: push %c (%d,%d)\n", __func__, msg[i], - fifo->head, fifo->tail); + rig_debug(RIG_DEBUG_VERBOSE, "%s: push %c (%d,%d)\n", __func__, msg[i], + fifo->head, fifo->tail); else - rig_debug(RIG_DEBUG_VERBOSE, "%s: push 0x%02x (%d,%d)\n", __func__, msg[i], - fifo->head, fifo->tail); + rig_debug(RIG_DEBUG_VERBOSE, "%s: push 0x%02x (%d,%d)\n", __func__, msg[i], + fifo->head, fifo->tail); if (fifo->tail + 1 == fifo->head) { return -RIG_EDOM; } @@ -62,22 +65,29 @@ int push(FIFO_RIG *fifo, const char *msg) int peek(FIFO_RIG *fifo) { - if (fifo == NULL) return -1; - if (fifo->tail < 0 || fifo->head < 0) return -1; - if (fifo->tail > 1023 || fifo->head > 1023) return -1; + if (fifo == NULL) { return -1; } + + if (fifo->tail < 0 || fifo->head < 0) { return -1; } + + if (fifo->tail > 1023 || fifo->head > 1023) { return -1; } + if (fifo->tail == fifo->head) { return -1; } + #ifdef _PTHREAD_H pthread_mutex_lock(&fifo->mutex); #endif char c = fifo->data[fifo->head]; #if 0 + if (isalnum(c)) - rig_debug(RIG_DEBUG_VERBOSE, "%s: peek %c (%d,%d)\n", __func__, c, fifo->head, - fifo->tail); + rig_debug(RIG_DEBUG_VERBOSE, "%s: peek %c (%d,%d)\n", __func__, c, fifo->head, + fifo->tail); else - rig_debug(RIG_DEBUG_VERBOSE, "%s: peek 0x%02x (%d,%d)\n", __func__, c, fifo->head, - fifo->tail); + rig_debug(RIG_DEBUG_VERBOSE, "%s: peek 0x%02x (%d,%d)\n", __func__, c, + fifo->head, + fifo->tail); + #endif #ifdef _PTHREAD_H pthread_mutex_unlock(&fifo->mutex); @@ -94,12 +104,15 @@ int pop(FIFO_RIG *fifo) #endif char c = fifo->data[fifo->head]; #if 0 + if (isalnum(c)) - rig_debug(RIG_DEBUG_VERBOSE, "%s: pop %c (%d,%d)\n", __func__, c, fifo->head, - fifo->tail); + rig_debug(RIG_DEBUG_VERBOSE, "%s: pop %c (%d,%d)\n", __func__, c, fifo->head, + fifo->tail); else - rig_debug(RIG_DEBUG_VERBOSE, "%s: pop 0x%02x (%d,%d)\n", __func__, c, fifo->head, - fifo->tail); + rig_debug(RIG_DEBUG_VERBOSE, "%s: pop 0x%02x (%d,%d)\n", __func__, c, + fifo->head, + fifo->tail); + #endif fifo->head = (fifo->head + 1) % HAMLIB_FIFO_SIZE; #ifdef _PTHREAD_H diff --git a/src/iofunc.c b/src/iofunc.c index 4d58694c4..82182a0e9 100644 --- a/src/iofunc.c +++ b/src/iofunc.c @@ -994,20 +994,24 @@ int HAMLIB_API port_flush_sync_pipes(hamlib_port_t *p) rig_debug(RIG_DEBUG_TRACE, "%s: flushing sync pipes\n", __func__); nbytes = 0; + while ((n = read(p->fd_sync_read, buf, sizeof(buf))) > 0) { nbytes += n; } - rig_debug(RIG_DEBUG_TRACE, "read flushed %d bytes from sync read pipe\n", nbytes); + rig_debug(RIG_DEBUG_TRACE, "read flushed %d bytes from sync read pipe\n", + nbytes); nbytes = 0; + while ((n = read(p->fd_sync_error_read, buf, sizeof(buf))) > 0) { nbytes += n; } - rig_debug(RIG_DEBUG_TRACE, "read flushed %d bytes from sync error read pipe\n", nbytes); + rig_debug(RIG_DEBUG_TRACE, "read flushed %d bytes from sync error read pipe\n", + nbytes); return RIG_OK; } @@ -1179,8 +1183,9 @@ static int read_block_generic(hamlib_port_t *p, unsigned char *rxbuffer, if (timeout_retries > 0) { timeout_retries--; - rig_debug(RIG_DEBUG_CACHE, "%s(%d): retrying read timeout %d/%d timeout=%dms\n", __func__, __LINE__, - p->timeout_retry - timeout_retries, p->timeout_retry, p->timeout); + rig_debug(RIG_DEBUG_CACHE, "%s(%d): retrying read timeout %d/%d timeout=%dms\n", + __func__, __LINE__, + p->timeout_retry - timeout_retries, p->timeout_retry, p->timeout); hl_usleep(10 * 1000); continue; } @@ -1335,6 +1340,7 @@ static int read_string_generic(hamlib_port_t *p, memset(rxbuffer, 0, rxmax); short timeout_retries = p->timeout_retry; + //HAMLIB_TRACE2; while (total_count < rxmax - 1) // allow 1 byte for end-of-string { @@ -1343,7 +1349,7 @@ static int read_string_generic(hamlib_port_t *p, int timeout_save = p->timeout; // p->timeout = 2; result = port_wait_for_data(p, direct); - //HAMLIB_TRACE2; + //HAMLIB_TRACE2; p->timeout = timeout_save; if (result == -RIG_ETIMEOUT) @@ -1351,10 +1357,11 @@ static int read_string_generic(hamlib_port_t *p, if (timeout_retries > 0) { timeout_retries--; - rig_debug(RIG_DEBUG_CACHE, "%s(%d): retrying read timeout %d/%d timeout=%d\n", __func__, __LINE__, - p->timeout_retry - timeout_retries, p->timeout_retry, p->timeout); + rig_debug(RIG_DEBUG_CACHE, "%s(%d): retrying read timeout %d/%d timeout=%d\n", + __func__, __LINE__, + p->timeout_retry - timeout_retries, p->timeout_retry, p->timeout); hl_usleep(10 * 1000); - //HAMLIB_TRACE2; + //HAMLIB_TRACE2; continue; } @@ -1403,7 +1410,8 @@ static int read_string_generic(hamlib_port_t *p, * read 1 character from the rig, (check if in stop set) * The file descriptor must have been set up non blocking. */ - do { + do + { #if 0 #ifndef __MINGW32__ // The ioctl works on Linux but not mingw @@ -1412,11 +1420,11 @@ static int read_string_generic(hamlib_port_t *p, //rig_debug(RIG_DEBUG_ERR, "xs: avail=%d expected_len=%d, minlen=%d, direct=%d\n", __func__, avail, expected_len, minlen, direct); #endif #endif - //HAMLIB_TRACE2; - shortcut: + //HAMLIB_TRACE2; +shortcut: rd_count = port_read_generic(p, &rxbuffer[total_count], expected_len == 1 ? 1 : minlen, direct); - //HAMLIB_TRACE2; + //HAMLIB_TRACE2; // rig_debug(RIG_DEBUG_VERBOSE, "%s: read %d bytes tot=%d\n", __func__, (int)rd_count, total_count); minlen -= rd_count; @@ -1426,24 +1434,27 @@ static int read_string_generic(hamlib_port_t *p, // rig_debug(RIG_DEBUG_WARN, "%s: port_read is busy? direct=%d\n", __func__, // direct); } - // special read for FLRig - if (stopset != NULL && strcmp(stopset, "") == 0) - { - if (strstr((char*)rxbuffer, stopset)) - { - HAMLIB_TRACE2; - } - else { - HAMLIB_TRACE2; - goto shortcut; - } - } + // special read for FLRig + if (stopset != NULL && strcmp(stopset, "") == 0) + { + if (strstr((char *)rxbuffer, stopset)) + { + HAMLIB_TRACE2; + } + + else + { + HAMLIB_TRACE2; + goto shortcut; + } + } } while (++i < 10 && errno == EBUSY); // 50ms should be enough - //HAMLIB_TRACE2; + + //HAMLIB_TRACE2; /* if we get 0 bytes or an error something is wrong */ if (rd_count <= 0) diff --git a/src/misc.c b/src/misc.c index dda492baf..2c72f2ed3 100644 --- a/src/misc.c +++ b/src/misc.c @@ -747,35 +747,35 @@ static const struct { setting_t bandselect; const char *str; - double start,stop; + double start, stop; } rig_bandselect_str[] = { { RIG_BANDSELECT_2200M, "BAND2200M", 135700, 137799 }, - { RIG_BANDSELECT_600M, "BAND600M" , 472000, 478999}, - { RIG_BANDSELECT_160M, "BAND160M" , 1800000, 1899999}, - { RIG_BANDSELECT_80M, "BAND80M" , 3400000, 4099999}, - { RIG_BANDSELECT_60M, "BAND60M" , 5250000, 5449999}, - { RIG_BANDSELECT_40M, "BAND40M" , 6900000, 7499999}, - { RIG_BANDSELECT_30M, "BAND30M" , 9900000, 10499999}, - { RIG_BANDSELECT_20M, "BAND20M" , 13900000, 14499999}, - { RIG_BANDSELECT_17M, "BAND17M" , 17900000, 18499999}, - { RIG_BANDSELECT_15M, "BAND15M" , 20900000, 21499999}, - { RIG_BANDSELECT_12M, "BAND10M" , 24400000, 25099999}, - { RIG_BANDSELECT_10M, "BAND10M" , 28000000, 29999999}, - { RIG_BANDSELECT_6M, "BAND6M" , 50000000, 53999999}, - { RIG_BANDSELECT_WFM, "BANDWFM" , 74800000, 107999999}, - { RIG_BANDSELECT_MW, "BANDMW" , 530000000, 1700999999}, - { RIG_BANDSELECT_AIR, "BANDAIR" , 108000000, 136999999}, - { RIG_BANDSELECT_2M, "BAND2M" , 144000000, 145999999}, - { RIG_BANDSELECT_1_25M, "BAND1_25M" , 219000000, 224999999}, - { RIG_BANDSELECT_70CM, "BAND70CM" , 420000000, 449999999}, - { RIG_BANDSELECT_33CM, "BAND33CM" , 902000000, 927999999}, - { RIG_BANDSELECT_23CM, "BAND23CM" , 1240000000, 1324999999}, - { RIG_BANDSELECT_13CM, "BAND13CM" , 2300000000, 2449999999}, - { RIG_BANDSELECT_9CM, "BAND9CM" , 3300000000, 3474999999}, - { RIG_BANDSELECT_5CM, "BAND5CM" , 5650000000, 5924999999}, + { RIG_BANDSELECT_600M, "BAND600M", 472000, 478999}, + { RIG_BANDSELECT_160M, "BAND160M", 1800000, 1899999}, + { RIG_BANDSELECT_80M, "BAND80M", 3400000, 4099999}, + { RIG_BANDSELECT_60M, "BAND60M", 5250000, 5449999}, + { RIG_BANDSELECT_40M, "BAND40M", 6900000, 7499999}, + { RIG_BANDSELECT_30M, "BAND30M", 9900000, 10499999}, + { RIG_BANDSELECT_20M, "BAND20M", 13900000, 14499999}, + { RIG_BANDSELECT_17M, "BAND17M", 17900000, 18499999}, + { RIG_BANDSELECT_15M, "BAND15M", 20900000, 21499999}, + { RIG_BANDSELECT_12M, "BAND10M", 24400000, 25099999}, + { RIG_BANDSELECT_10M, "BAND10M", 28000000, 29999999}, + { RIG_BANDSELECT_6M, "BAND6M", 50000000, 53999999}, + { RIG_BANDSELECT_WFM, "BANDWFM", 74800000, 107999999}, + { RIG_BANDSELECT_MW, "BANDMW", 530000000, 1700999999}, + { RIG_BANDSELECT_AIR, "BANDAIR", 108000000, 136999999}, + { RIG_BANDSELECT_2M, "BAND2M", 144000000, 145999999}, + { RIG_BANDSELECT_1_25M, "BAND1_25M", 219000000, 224999999}, + { RIG_BANDSELECT_70CM, "BAND70CM", 420000000, 449999999}, + { RIG_BANDSELECT_33CM, "BAND33CM", 902000000, 927999999}, + { RIG_BANDSELECT_23CM, "BAND23CM", 1240000000, 1324999999}, + { RIG_BANDSELECT_13CM, "BAND13CM", 2300000000, 2449999999}, + { RIG_BANDSELECT_9CM, "BAND9CM", 3300000000, 3474999999}, + { RIG_BANDSELECT_5CM, "BAND5CM", 5650000000, 5924999999}, { RIG_BANDSELECT_3CM, "BAND3CM", 10000000000, 10499999999 }, - { RIG_BANDSELECT_GEN, "BANDGEN" , 0, 1000000000000}, + { RIG_BANDSELECT_GEN, "BANDGEN", 0, 1000000000000}, { 0, NULL, 0, 0 } }; @@ -2009,15 +2009,18 @@ vfo_t HAMLIB_API vfo_fixup(RIG *rig, vfo_t vfo, split_t split) rig_strvfo(vfo), rig_strvfo(rig->state.current_vfo), split); if (rig->caps->rig_model == RIG_MODEL_ID5100 - || rig->caps->rig_model == RIG_MODEL_IC9700) + || rig->caps->rig_model == RIG_MODEL_IC9700) { struct rig_state *rs = &rig->state; + // dualwatch on ID5100 is TX=Main, RX=Sub if (rig->caps->rig_model == RIG_MODEL_ID5100 && rs->dual_watch) { - if (vfo == RIG_VFO_TX || vfo == RIG_VFO_MAIN) return RIG_VFO_MAIN; + if (vfo == RIG_VFO_TX || vfo == RIG_VFO_MAIN) { return RIG_VFO_MAIN; } + return RIG_VFO_SUB; } + return vfo; // no change to requested vfo } @@ -2356,7 +2359,8 @@ void *HAMLIB_API rig_get_function_ptr(rig_model_t rig_model, if (caps == NULL) { - rig_debug(RIG_DEBUG_ERR, "%s: caps == null for model %d??\n", __func__, rig_model); + rig_debug(RIG_DEBUG_ERR, "%s: caps == null for model %d??\n", __func__, + rig_model); return NULL; } @@ -2641,7 +2645,7 @@ void *HAMLIB_API rig_get_function_ptr(rig_model_t rig_model, * \return the corresponding long value -- -RIG_EINVAL is the only error possible */ uint64_t HAMLIB_API rig_get_caps_int(rig_model_t rig_model, - enum rig_caps_int_e rig_caps) + enum rig_caps_int_e rig_caps) { const struct rig_caps *caps = rig_get_caps(rig_model); #if 0 @@ -2676,7 +2680,8 @@ uint64_t HAMLIB_API rig_get_caps_int(rig_model_t rig_model, return caps->port_type; case RIG_CAPS_HAS_GET_LEVEL: - rig_debug(RIG_DEBUG_TRACE, "%s(%d): return %08"PRIll"\n", __func__, __LINE__, caps->has_get_level); + rig_debug(RIG_DEBUG_TRACE, "%s(%d): return %08"PRIll"\n", __func__, __LINE__, + caps->has_get_level); return caps->has_get_level; default: @@ -2816,7 +2821,7 @@ char *date_strget(char *buf, int buflen, int localtime) struct tm *mytm; time_t t; struct timeval tv; - struct tm result = { 0,0,0,0,0,0,0,0,0}; + struct tm result = { 0, 0, 0, 0, 0, 0, 0, 0, 0}; int mytimezone; t = time(NULL); @@ -2844,7 +2849,7 @@ char *date_strget(char *buf, int buflen, int localtime) char *rig_date_strget(char *buf, int buflen, int localtime) { - return date_strget(buf,buflen,localtime); + return date_strget(buf, buflen, localtime); } const char *spaces() @@ -2855,50 +2860,56 @@ const char *spaces() // if which==0 rig_band_select str will be returned // if which!=0 the rig_parm_gran band str will be returne -const char* rig_get_band_str(RIG *rig, hamlib_band_t band, int which) +const char *rig_get_band_str(RIG *rig, hamlib_band_t band, int which) { int i; if (which == 0) { - for (i = 0; rig_bandselect_str[i].str[0] != '\0'; i++) - { - if (rig_bandselect_str[i].bandselect == band) + for (i = 0; rig_bandselect_str[i].str[0] != '\0'; i++) { - return rig_bandselect_str[i].str; + if (rig_bandselect_str[i].bandselect == band) + { + return rig_bandselect_str[i].str; + } } } - } else { char bandlist[512]; - - rig_sprintf_parm_gran(bandlist, sizeof(bandlist)-1, RIG_PARM_BANDSELECT, rig->caps->parm_gran); + + rig_sprintf_parm_gran(bandlist, sizeof(bandlist) - 1, RIG_PARM_BANDSELECT, + rig->caps->parm_gran); rig_debug(RIG_DEBUG_VERBOSE, "%s: bandlist=%s\n", __func__, bandlist); int n = 0; - char *p = strchr(bandlist,'(')+1; + char *p = strchr(bandlist, '(') + 1; char *token; + if (p == NULL) { - rig_debug(RIG_DEBUG_ERR, "%s: unable to find open paren in '%s'\n", __func__, bandlist); + rig_debug(RIG_DEBUG_ERR, "%s: unable to find open paren in '%s'\n", __func__, + bandlist); return 0; } - while((token = strtok_r(p, ",", &p))) + + while ((token = strtok_r(p, ",", &p))) { - if (n == band) + if (n == band) { for (i = 0; rig_bandselect_str[i].str[0] != '\0'; i++) { - if (strcmp(rig_bandselect_str[i].str,token)==0) + if (strcmp(rig_bandselect_str[i].str, token) == 0) { return rig_bandselect_str[i].str; } } } + n++; } } + return "BANDGEN"; } // If freq==0 looks up using the band index (which is the rig's band reference index) @@ -2911,29 +2922,36 @@ hamlib_band_t rig_get_band(RIG *rig, freq_t freq, int band) rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - if (freq == 0) + if (freq == 0) { char bandlist[512]; - - rig_sprintf_parm_gran(bandlist, sizeof(bandlist)-1, RIG_PARM_BANDSELECT, rig->caps->parm_gran); + + rig_sprintf_parm_gran(bandlist, sizeof(bandlist) - 1, RIG_PARM_BANDSELECT, + rig->caps->parm_gran); rig_debug(RIG_DEBUG_VERBOSE, "%s: bandlist=%s\n", __func__, bandlist); // e.g. BANDSELECT(BAND160M,BAND80M,BANDUNUSED,BAND40M) - char *p = strchr(bandlist,'(')+1; + char *p = strchr(bandlist, '(') + 1; char *token; + if (p == NULL) { - rig_debug(RIG_DEBUG_ERR, "%s: unable to find open paren in '%s'\n", __func__, bandlist); + rig_debug(RIG_DEBUG_ERR, "%s: unable to find open paren in '%s'\n", __func__, + bandlist); return 0; } + int n = 0; - while((token = strtok_r(p, ",", &p))) + + while ((token = strtok_r(p, ",", &p))) { - if (n == band) return rig_bandselect_str[n].bandselect; + if (n == band) { return rig_bandselect_str[n].bandselect; } + n++; } return RIG_BAND_UNUSED; } + for (i = 0 ; rig_bandselect_str[i].str[0] != '\0'; i++) { if (freq >= rig_bandselect_str[i].start && freq <= rig_bandselect_str[i].stop) @@ -2950,28 +2968,36 @@ int rig_get_band_rig(RIG *rig, freq_t freq, const char *band) { char bandlist[512]; int i; - + if (freq == 0) { - rig_sprintf_parm_gran(bandlist, sizeof(bandlist)-1, RIG_PARM_BANDSELECT, rig->caps->parm_gran); + rig_sprintf_parm_gran(bandlist, sizeof(bandlist) - 1, RIG_PARM_BANDSELECT, + rig->caps->parm_gran); rig_debug(RIG_DEBUG_VERBOSE, "%s: bandlist=%s\n", __func__, bandlist); // e.g. BANDSELECT(BAND160M,BAND80M,BANDUNUSED,BAND40M) - char *p = strchr(bandlist,'(')+1; + char *p = strchr(bandlist, '(') + 1; char *token; + if (p == NULL) { - rig_debug(RIG_DEBUG_ERR, "%s: unable to find open paren in '%s'\n", __func__, bandlist); + rig_debug(RIG_DEBUG_ERR, "%s: unable to find open paren in '%s'\n", __func__, + bandlist); return 0; } + int n = 0; - while((token = strtok_r(p, ",", &p))) + + while ((token = strtok_r(p, ",", &p))) { - if (strcmp(token,band)==0) return n; + if (strcmp(token, band) == 0) { return n; } + n++; } + rig_debug(RIG_DEBUG_ERR, "%s: unknown band %s\n", __func__, band); return 0; } + for (i = 0 ; rig_bandselect_str[i].str[0] != '\0'; i++) { if (freq >= rig_bandselect_str[i].start && freq <= rig_bandselect_str[i].stop) @@ -2981,7 +3007,9 @@ int rig_get_band_rig(RIG *rig, freq_t freq, const char *band) return rig_get_band_rig(rig, 0.0, rig_bandselect_str[i].str); } } - rig_debug(RIG_DEBUG_ERR, "%s: unable to find band=%s, freq=%f\n", __func__, band, freq); + + rig_debug(RIG_DEBUG_ERR, "%s: unable to find band=%s, freq=%f\n", __func__, + band, freq); return 0; // just give a value for now of the 1st band -- this should be an error } diff --git a/src/multicast.c b/src/multicast.c index a9a8d29ca..f610cf067 100644 --- a/src/multicast.c +++ b/src/multicast.c @@ -306,7 +306,7 @@ static int multicast_send_json(RIG *rig) json_add_int(msg, "PTT", rig->state.cache.ptt, 1); json_add_int(msg, "Split", rig->state.cache.split, 1); rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list); - json_add_string(msg, "ModeList", buf,1); + json_add_string(msg, "ModeList", buf, 1); strcat(msg, "\"VFOs\": [\n"); json_add_vfoA(rig, msg); json_add_vfoB(rig, msg); @@ -339,7 +339,8 @@ void *multicast_thread_rx(void *vrig) while (rig->state.multicast->runflag) { #if 0 - ret = read_string(&rig->state.rigport, (unsigned char *) buf, sizeof(buf), "\n", 1, + ret = read_string(&rig->state.rigport, (unsigned char *) buf, sizeof(buf), "\n", + 1, 0, 1); #endif @@ -405,11 +406,13 @@ void *multicast_thread(void *vrig) || loopcount-- <= 0) { #if 0 + if (loopcount <= 0) { rig_debug(RIG_DEBUG_CACHE, "%s: sending multicast packet timeout\n", __func__); } else { rig_debug(RIG_DEBUG_ERR, "%s: sending multicast packet due to change\n", __func__); } + #endif // multicast_status_changed(rig); @@ -582,8 +585,8 @@ void multicast_close(RIG *rig) { // Leave the multicast group if (setsockopt(rig->state.multicast->sock, IPPROTO_IP, - IP_DROP_MEMBERSHIP, (char *)&rig->state.multicast->mreq, - sizeof(rig->state.multicast->mreq)) < 0) + IP_DROP_MEMBERSHIP, (char *)&rig->state.multicast->mreq, + sizeof(rig->state.multicast->mreq)) < 0) { rig_debug(RIG_DEBUG_ERR, "%s: setsockopt: %s\n", __func__, strerror(errno)); return; diff --git a/src/network.c b/src/network.c index e2272d627..867aa04ed 100644 --- a/src/network.c +++ b/src/network.c @@ -202,6 +202,7 @@ int network_init() { retval = RIG_OK; } + #else retval = RIG_OK; @@ -939,6 +940,7 @@ void *multicast_publisher(void *arg) result = multicast_publisher_read_packet(args, &packet_type, &spectrum_line, spectrum_data); + if (result != RIG_OK) { if (result == -RIG_ETIMEOUT) @@ -1049,7 +1051,7 @@ int is_wireless_linux(const char *ifname) int sock = socket(AF_INET, SOCK_DGRAM, 0); struct iwreq pwrq; memset(&pwrq, 0, sizeof(pwrq)); - strncpy(pwrq.ifr_name, ifname, IFNAMSIZ-1); + strncpy(pwrq.ifr_name, ifname, IFNAMSIZ - 1); if (ioctl(sock, SIOCGIWNAME, &pwrq) != -1) { @@ -1103,43 +1105,53 @@ void *multicast_receiver(void *arg) int socket_fd = args->socket_fd; rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Starting multicast receiver\n", __FILE__, - __LINE__); + __LINE__); int optval = 1; #ifdef __MINGW32__ - if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, (PCHAR)&optval, sizeof(optval)) < 0) + + if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, (PCHAR)&optval, + sizeof(optval)) < 0) #else - if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) + if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &optval, + sizeof(optval)) < 0) #endif { rig_debug(RIG_DEBUG_ERR, "%s: error enabling UDP address reuse: %s\n", __func__, - strerror(errno)); + strerror(errno)); return NULL; } // Windows does not have SO_REUSEPORT. However, SO_REUSEADDR works in a similar way. #if defined(SO_REUSEPORT) - if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)) < 0) + + if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEPORT, &optval, + sizeof(optval)) < 0) { rig_debug(RIG_DEBUG_ERR, "%s: error enabling UDP port reuse: %s\n", __func__, - strerror(errno)); + strerror(errno)); return NULL; } + #endif memset(&dest_addr, 0, sizeof(dest_addr)); dest_addr.sin_family = AF_INET; #ifdef __MINGW32__ + // Windows cannot bind to multicast group addresses for some unknown reason if (is_wireless()) { - rig_debug(RIG_DEBUG_VERBOSE, "%s: no wireless detect so INADDR_ANY is being used\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, + "%s: no wireless detect so INADDR_ANY is being used\n", __func__); } else { - rig_debug(RIG_DEBUG_VERBOSE, "%s: wireless detected so localhost is being used\n", __func__); + rig_debug(RIG_DEBUG_VERBOSE, + "%s: wireless detected so localhost is being used\n", __func__); dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); } + #else dest_addr.sin_addr.s_addr = inet_addr(args->multicast_addr); #endif @@ -1147,24 +1159,31 @@ void *multicast_receiver(void *arg) if (bind(socket_fd, (struct sockaddr *) &dest_addr, sizeof(dest_addr)) < 0) { - rig_debug(RIG_DEBUG_ERR, "%s: error binding UDP socket to %s:%d: %s\n", __func__, - args->multicast_addr, args->multicast_port, strerror(errno)); + rig_debug(RIG_DEBUG_ERR, "%s: error binding UDP socket to %s:%d: %s\n", + __func__, + args->multicast_addr, args->multicast_port, strerror(errno)); return NULL; } struct ip_mreq mreq; + memset(&mreq, 0, sizeof(mreq)); + mreq.imr_multiaddr.s_addr = inet_addr(args->multicast_addr); + mreq.imr_interface.s_addr = htonl(INADDR_ANY); #ifdef __MINGW32__ - if (setsockopt(socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (PCHAR)&mreq, sizeof(mreq)) < 0) + if (setsockopt(socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (PCHAR)&mreq, + sizeof(mreq)) < 0) #else - if (setsockopt(socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) + if (setsockopt(socket_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, + sizeof(mreq)) < 0) #endif { - rig_debug(RIG_DEBUG_ERR, "%s: error joining multicast group %s:%d: %s\n", __func__, - args->multicast_addr, args->multicast_port, strerror(errno)); + rig_debug(RIG_DEBUG_ERR, "%s: error joining multicast group %s:%d: %s\n", + __func__, + args->multicast_addr, args->multicast_port, strerror(errno)); return NULL; } @@ -1203,10 +1222,10 @@ void *multicast_receiver(void *arg) if (select_result <= 0) { rig_debug(RIG_DEBUG_ERR, - "%s((%d): select() failed when reading UDP multicast socket data: %s\n", - __func__, - __LINE__, - strerror(errno)); + "%s((%d): select() failed when reading UDP multicast socket data: %s\n", + __func__, + __LINE__, + strerror(errno)); break; } @@ -1214,11 +1233,13 @@ void *multicast_receiver(void *arg) if ((result = FD_ISSET(socket_fd, &efds))) { rig_debug(RIG_DEBUG_ERR, - "%s(%d): fd error when reading UDP multicast socket data: (%d)=%s\n", __func__, __LINE__, (int)result, strerror(errno)); + "%s(%d): fd error when reading UDP multicast socket data: (%d)=%s\n", __func__, + __LINE__, (int)result, strerror(errno)); break; } - result = recvfrom(socket_fd, data, sizeof(data), 0, (struct sockaddr *) &client_addr, &client_len); + result = recvfrom(socket_fd, data, sizeof(data), 0, + (struct sockaddr *) &client_addr, &client_len); if (result <= 0) { @@ -1228,22 +1249,27 @@ void *multicast_receiver(void *arg) { continue; } - rig_debug(RIG_DEBUG_ERR, "%s: error receiving from UDP socket %s:%d: %s\n", __func__, - args->multicast_addr, args->multicast_port, strerror(errno)); + + rig_debug(RIG_DEBUG_ERR, "%s: error receiving from UDP socket %s:%d: %s\n", + __func__, + args->multicast_addr, args->multicast_port, strerror(errno)); } + break; } // TODO: handle commands from multicast clients - rig_debug(RIG_DEBUG_VERBOSE, "%s: received %ld bytes of data: %.*s\n", __func__, (long) result, (int) result, data); + rig_debug(RIG_DEBUG_VERBOSE, "%s: received %ld bytes of data: %.*s\n", __func__, + (long) result, (int) result, data); // TODO: if a new snapshot needs to be sent, call network_publish_rig_poll_data() and the publisher routine will send out a snapshot // TODO: new logic in publisher needs to be written for other types of responses } + rs->multicast_receiver_run = 0; rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Stopping multicast receiver\n", __FILE__, - __LINE__); + __LINE__); return NULL; } @@ -1268,7 +1294,8 @@ int network_multicast_publisher_start(RIG *rig, const char *multicast_addr, ENTERFUNC; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): multicast publisher address=%s, port=%d\n", __FILE__, + rig_debug(RIG_DEBUG_VERBOSE, + "%s(%d): multicast publisher address=%s, port=%d\n", __FILE__, __LINE__, multicast_addr, multicast_port); @@ -1306,19 +1333,25 @@ int network_multicast_publisher_start(RIG *rig, const char *multicast_addr, // Enable non-blocking mode u_long mode = 1; #ifdef __MINGW32__ + if (ioctlsocket(socket_fd, FIONBIO, &mode) == SOCKET_ERROR) { - rig_debug(RIG_DEBUG_ERR, "%s: error enabling non-blocking mode for socket: %s", __func__, - strerror(errno)); + rig_debug(RIG_DEBUG_ERR, "%s: error enabling non-blocking mode for socket: %s", + __func__, + strerror(errno)); RETURNFUNC(-RIG_EIO); } + #else + if (ioctl(socket_fd, FIONBIO, &mode) < 0) { - rig_debug(RIG_DEBUG_ERR, "%s: error enabling non-blocking mode for socket: %s", __func__, - strerror(errno)); + rig_debug(RIG_DEBUG_ERR, "%s: error enabling non-blocking mode for socket: %s", + __func__, + strerror(errno)); RETURNFUNC(-RIG_EIO); } + #endif if (items & RIG_MULTICAST_TRANSCEIVE) @@ -1444,7 +1477,8 @@ int network_multicast_publisher_stop(RIG *rig) * \param multicast_port UDP socket port * \return RIG_OK or < 0 if error */ -int network_multicast_receiver_start(RIG *rig, const char *multicast_addr, int multicast_port) +int network_multicast_receiver_start(RIG *rig, const char *multicast_addr, + int multicast_port) { struct rig_state *rs = &rig->state; multicast_receiver_priv_data *mcast_receiver_priv; @@ -1453,7 +1487,8 @@ int network_multicast_receiver_start(RIG *rig, const char *multicast_addr, int m ENTERFUNC; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): multicast receiver address=%s, port=%d\n", __FILE__, + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): multicast receiver address=%s, port=%d\n", + __FILE__, __LINE__, multicast_addr, multicast_port); @@ -1491,19 +1526,25 @@ int network_multicast_receiver_start(RIG *rig, const char *multicast_addr, int m // Enable non-blocking mode u_long mode = 1; #ifdef __MINGW32__ + if (ioctlsocket(socket_fd, FIONBIO, &mode) == SOCKET_ERROR) { - rig_debug(RIG_DEBUG_ERR, "%s: error enabling non-blocking mode for socket: %s", __func__, - strerror(errno)); + rig_debug(RIG_DEBUG_ERR, "%s: error enabling non-blocking mode for socket: %s", + __func__, + strerror(errno)); RETURNFUNC(-RIG_EIO); } + #else + if (ioctl(socket_fd, FIONBIO, &mode) < 0) { - rig_debug(RIG_DEBUG_ERR, "%s: error enabling non-blocking mode for socket: %s", __func__, - strerror(errno)); + rig_debug(RIG_DEBUG_ERR, "%s: error enabling non-blocking mode for socket: %s", + __func__, + strerror(errno)); RETURNFUNC(-RIG_EIO); } + #endif rs->multicast_receiver_run = 1; @@ -1517,7 +1558,7 @@ int network_multicast_receiver_start(RIG *rig, const char *multicast_addr, int m } mcast_receiver_priv = (multicast_receiver_priv_data *) - rs->multicast_receiver_priv_data; + rs->multicast_receiver_priv_data; mcast_receiver_priv->args.socket_fd = socket_fd; mcast_receiver_priv->args.multicast_addr = multicast_addr; mcast_receiver_priv->args.multicast_port = multicast_port; @@ -1557,7 +1598,7 @@ int network_multicast_receiver_stop(RIG *rig) rs->multicast_receiver_run = 0; mcast_receiver_priv = (multicast_receiver_priv_data *) - rs->multicast_receiver_priv_data; + rs->multicast_receiver_priv_data; if (mcast_receiver_priv == NULL) { diff --git a/src/rig.c b/src/rig.c index 059911bb7..3f4d10168 100644 --- a/src/rig.c +++ b/src/rig.c @@ -101,7 +101,8 @@ const char *hamlib_version2 = "Hamlib " PACKAGE_VERSION " " HAMLIBDATETIME " " ARCHBITS; HAMLIB_EXPORT_VAR(int) cookie_use; HAMLIB_EXPORT_VAR(int) lock_mode; // for use by rigctld -HAMLIB_EXPORT_VAR(powerstat_t) rig_powerstat; // for use by both rigctld and rigctl +HAMLIB_EXPORT_VAR(powerstat_t) +rig_powerstat; // for use by both rigctld and rigctl //! @endcond struct rig_caps caps_test; @@ -380,8 +381,8 @@ void add2debugmsgsave(const char *s) if (p && strlen(p + 1) > 0) { - strcpy(stmp, p + 1); - strcpy(debugmsgsave, stmp); + strcpy(stmp, p + 1); + strcpy(debugmsgsave, stmp); } else { @@ -672,9 +673,11 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) rs->current_vfo = RIG_VFO_CURR; /* we don't know yet! */ rs->tx_vfo = RIG_VFO_CURR; /* we don't know yet! */ rs->poll_interval = 1000; // enable polling by default - rs->multicast_data_addr = "224.0.0.1"; // enable multicast data publishing by default + rs->multicast_data_addr = + "224.0.0.1"; // enable multicast data publishing by default rs->multicast_data_port = 4532; - rs->multicast_cmd_addr = "224.0.0.2"; // enable multicast command server by default + rs->multicast_cmd_addr = + "224.0.0.2"; // enable multicast command server by default rs->multicast_cmd_port = 4532; rs->lo_freq = 0; rs->cache.timeout_ms = 500; // 500ms cache timeout by default @@ -1333,7 +1336,8 @@ int HAMLIB_API rig_open(RIG *rig) rig_debug(RIG_DEBUG_VERBOSE, "%s: %p rs->comm_state==1?=%d\n", __func__, &rs->comm_state, rs->comm_state); - hl_usleep(100 * 1000); // wait a bit after opening to give some serial ports time + hl_usleep(100 * + 1000); // wait a bit after opening to give some serial ports time /* @@ -1350,7 +1354,8 @@ int HAMLIB_API rig_open(RIG *rig) powerstat_t powerflag; status = rig_get_powerstat(rig, &powerflag); - if (status == RIG_OK && (powerflag == RIG_POWER_OFF || powerflag == RIG_POWER_STANDBY) + if (status == RIG_OK && (powerflag == RIG_POWER_OFF + || powerflag == RIG_POWER_STANDBY) && rig->state.auto_power_on == 0) { // rig_open() should succeed even if the rig is powered off, so simply log power status @@ -1366,7 +1371,8 @@ int HAMLIB_API rig_open(RIG *rig) { // rig_open() should succeed even if get_powerstat() fails, // as many rigs cannot get power status while powered off - rig_debug(RIG_DEBUG_ERR, "%s: Some rigs cannot get_powerstat while off\n", __func__); + rig_debug(RIG_DEBUG_ERR, "%s: Some rigs cannot get_powerstat while off\n", + __func__); rig_debug(RIG_DEBUG_ERR, "%s: Known rigs: K3, K3S\n", __func__); } } @@ -1435,7 +1441,8 @@ int HAMLIB_API rig_open(RIG *rig) if (status < 0) { - rig_debug(RIG_DEBUG_ERR, "%s: cw_data_handler_start failed: %s\n", __func__, rigerror(status)); + rig_debug(RIG_DEBUG_ERR, "%s: cw_data_handler_start failed: %s\n", __func__, + rigerror(status)); port_close(&rs->rigport, rs->rigport.type.rig); RETURNFUNC2(status); } @@ -1495,31 +1502,35 @@ int HAMLIB_API rig_open(RIG *rig) rig_flush_force(&rs->rigport, 1); enum multicast_item_e items = RIG_MULTICAST_POLL | RIG_MULTICAST_TRANSCEIVE - | RIG_MULTICAST_SPECTRUM; + | RIG_MULTICAST_SPECTRUM; retval = network_multicast_publisher_start(rig, rs->multicast_data_addr, - rs->multicast_data_port, items); + rs->multicast_data_port, items); if (retval != RIG_OK) { - rig_debug(RIG_DEBUG_ERR, "%s: network_multicast_publisher_start failed: %s\n", __FILE__, + rig_debug(RIG_DEBUG_ERR, "%s: network_multicast_publisher_start failed: %s\n", + __FILE__, rigerror(retval)); // we will consider this non-fatal for now } - retval = network_multicast_receiver_start(rig, rs->multicast_cmd_addr, rs->multicast_cmd_port); + retval = network_multicast_receiver_start(rig, rs->multicast_cmd_addr, + rs->multicast_cmd_port); if (retval != RIG_OK) { - rig_debug(RIG_DEBUG_ERR, "%s: network_multicast_receiver_start failed: %s\n", __FILE__, - rigerror(retval)); + rig_debug(RIG_DEBUG_ERR, "%s: network_multicast_receiver_start failed: %s\n", + __FILE__, + rigerror(retval)); // we will consider this non-fatal for now } retval = rig_poll_routine_start(rig); + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: rig_poll_routine_start failed: %s\n", __FILE__, - rigerror(retval)); + rigerror(retval)); // we will consider this non-fatal for now } @@ -1551,7 +1562,7 @@ int HAMLIB_API rig_close(RIG *rig) if (!rig || !rig->caps) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -1759,7 +1770,7 @@ int HAMLIB_API rig_set_twiddle(RIG *rig, int seconds) { if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -1783,7 +1794,7 @@ int HAMLIB_API rig_set_uplink(RIG *rig, int val) { if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -1810,7 +1821,7 @@ int HAMLIB_API rig_get_twiddle(RIG *rig, int *seconds) { if (CHECK_RIG_ARG(rig) || !seconds) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps or seconds is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps or seconds is null\n", __func__); return -RIG_EINVAL; } @@ -1900,7 +1911,7 @@ int rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -1918,24 +1929,32 @@ int rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) if (rig->state.doppler == 0) { - if (vfo == RIG_VFO_A || vfo == RIG_VFO_MAIN || (vfo == RIG_VFO_CURR && rig->state.current_vfo == RIG_VFO_A)) - { - if (rig->state.cache.freqMainA != freq && (((int)freq % 10) != 0)) + if (vfo == RIG_VFO_A || vfo == RIG_VFO_MAIN || (vfo == RIG_VFO_CURR + && rig->state.current_vfo == RIG_VFO_A)) { - rig->state.doppler = 1; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): potential doppler detected because old freq %f != new && new freq has 1Hz or such values\n", __func__, __LINE__, rig->state.cache.freqMainA); - } - freq += rig->state.offset_vfoa; - } - else if (vfo == RIG_VFO_B || vfo == RIG_VFO_SUB || (vfo == RIG_VFO_CURR && rig->state.current_vfo == RIG_VFO_B)) - { - if (rig->state.cache.freqMainB != freq && ((int)freq % 10) != 0) + if (rig->state.cache.freqMainA != freq && (((int)freq % 10) != 0)) + { + rig->state.doppler = 1; + rig_debug(RIG_DEBUG_VERBOSE, + "%s(%d): potential doppler detected because old freq %f != new && new freq has 1Hz or such values\n", + __func__, __LINE__, rig->state.cache.freqMainA); + } + + freq += rig->state.offset_vfoa; + } + else if (vfo == RIG_VFO_B || vfo == RIG_VFO_SUB || (vfo == RIG_VFO_CURR + && rig->state.current_vfo == RIG_VFO_B)) { - rig->state.doppler = 1; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): potential doppler detected because old freq %f != new && new freq has 1Hz or such values\n", __func__, __LINE__, rig->state.cache.freqMainB); - } - freq += rig->state.offset_vfob; - } + if (rig->state.cache.freqMainB != freq && ((int)freq % 10) != 0) + { + rig->state.doppler = 1; + rig_debug(RIG_DEBUG_VERBOSE, + "%s(%d): potential doppler detected because old freq %f != new && new freq has 1Hz or such values\n", + __func__, __LINE__, rig->state.cache.freqMainB); + } + + freq += rig->state.offset_vfob; + } } if (vfo == RIG_VFO_A || vfo == RIG_VFO_MAIN) { freq += rig->state.offset_vfoa; } @@ -2053,6 +2072,7 @@ int rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) } } else { retry = 0; } + tfreq = freq; #endif } @@ -2129,6 +2149,7 @@ int rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) LOCK(0); RETURNFUNC(RIG_OK); } + // Unidirectional rigs do not reset cache if (rig->caps->rig_model != RIG_MODEL_FT736R) { @@ -2205,7 +2226,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -2311,11 +2332,12 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) rig_cache_show(rig, __func__, __LINE__); // WSJT-X senses rig precision with 55 and 56 Hz values - // We do not want to allow cache response with these values - int wsjtx_special = ((long)*freq % 100)==55 || ((long)*freq % 100)==56; + // We do not want to allow cache response with these values + int wsjtx_special = ((long) * freq % 100) == 55 || ((long) * freq % 100) == 56; + if (!wsjtx_special && *freq != 0 && (cache_ms_freq < rig->state.cache.timeout_ms - || (rig->state.cache.timeout_ms == HAMLIB_CACHE_ALWAYS - || rig->state.use_cached_freq))) + || (rig->state.cache.timeout_ms == HAMLIB_CACHE_ALWAYS + || rig->state.use_cached_freq))) { rig_debug(RIG_DEBUG_TRACE, "%s: %s cache hit age=%dms, freq=%.0f, use_cached_freq=%d\n", __func__, @@ -2350,7 +2372,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) if ((caps->targetable_vfo & RIG_TARGETABLE_FREQ) || vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo || (rig->state.vfo_opt == 1 && rig->caps->rig_model == RIG_MODEL_NETRIGCTL - && rig->state.doppler == 0)) + && rig->state.doppler == 0)) { // If rig does not have set_vfo we need to change vfo if (vfo == RIG_VFO_CURR && caps->set_vfo == NULL) @@ -2399,6 +2421,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) LOCK(0); RETURNFUNC(retcode); } + #endif retcode = caps->set_vfo(rig, vfo); @@ -2519,7 +2542,7 @@ int HAMLIB_API rig_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -2693,7 +2716,7 @@ int HAMLIB_API rig_get_mode(RIG *rig, if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -2860,8 +2883,8 @@ pbwidth_t HAMLIB_API rig_passband_normal(RIG *rig, rmode_t mode) if (!rig) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); - return(RIG_PASSBAND_NORMAL); /* huhu! */ + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); + return (RIG_PASSBAND_NORMAL); /* huhu! */ } ENTERFUNC; @@ -2913,8 +2936,8 @@ pbwidth_t HAMLIB_API rig_passband_narrow(RIG *rig, rmode_t mode) if (!rig) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); - return(0); /* huhu! */ + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); + return (0); /* huhu! */ } ENTERFUNC; @@ -2966,7 +2989,7 @@ pbwidth_t HAMLIB_API rig_passband_wide(RIG *rig, rmode_t mode) if (!rig) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return 0 ; /* huhu! */ } @@ -3027,7 +3050,7 @@ int HAMLIB_API rig_set_vfo(RIG *rig, vfo_t vfo) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -3188,7 +3211,7 @@ int HAMLIB_API rig_get_vfo(RIG *rig, vfo_t *vfo) if (CHECK_RIG_ARG(rig) || !vfo) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or *vfo is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or *vfo is null\n", __func__); return -RIG_EINVAL; } @@ -3269,7 +3292,7 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -3540,7 +3563,8 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) break; default: - rig_debug(RIG_DEBUG_WARN, "%s: unknown PTT type=%d\n", __func__, rig->state.pttport.type.ptt); + rig_debug(RIG_DEBUG_WARN, "%s: unknown PTT type=%d\n", __func__, + rig->state.pttport.type.ptt); ELAPSED2; RETURNFUNC(-RIG_EINVAL); } @@ -3562,7 +3586,9 @@ int HAMLIB_API rig_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) memcpy(&rig->state.pttport_deprecated, &rig->state.pttport, sizeof(rig->state.pttport_deprecated)); - if (rig->state.post_ptt_delay > 0) hl_usleep(rig->state.post_ptt_delay*1000); + + if (rig->state.post_ptt_delay > 0) { hl_usleep(rig->state.post_ptt_delay * 1000); } + ELAPSED2; RETURNFUNC(retcode); @@ -3596,7 +3622,7 @@ int HAMLIB_API rig_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -3909,7 +3935,7 @@ int HAMLIB_API rig_get_dcd(RIG *rig, vfo_t vfo, dcd_t *dcd) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -4050,7 +4076,7 @@ int HAMLIB_API rig_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t rptr_shift) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -4128,7 +4154,7 @@ int HAMLIB_API rig_get_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t *rptr_shift) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -4212,7 +4238,7 @@ int HAMLIB_API rig_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t rptr_offs) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -4290,7 +4316,7 @@ int HAMLIB_API rig_get_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t *rptr_offs) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -4374,7 +4400,7 @@ int HAMLIB_API rig_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -4538,7 +4564,7 @@ int HAMLIB_API rig_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -4699,7 +4725,7 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -4718,8 +4744,10 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, } else { - rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s mode %s is different from A=%s and B=%s\n", - __func__, rig_strvfo(vfo), rig_strrmode(tx_mode), rig_strrmode(rig->state.cache.modeMainA), + rig_debug(RIG_DEBUG_TRACE, + "%s: vfo=%s mode %s is different from A=%s and B=%s\n", + __func__, rig_strvfo(vfo), rig_strrmode(tx_mode), + rig_strrmode(rig->state.cache.modeMainA), rig_strrmode(rig->state.cache.modeMainB)); } @@ -4878,19 +4906,20 @@ int HAMLIB_API rig_set_split_mode(RIG *rig, rig_set_split_vfo(rig, rx_vfo, RIG_SPLIT_ON, tx_vfo); #if 0 + if (vfo == RIG_VFO_A || vfo == RIG_VFO_MAIN || vfo == RIG_VFO_MAIN_A) { rig->state.cache.modeMainA = tx_mode; } - else if (vfo == RIG_VFO_B || - { - rig->state.cache.modeMainB = tx_mode; - } + else if (vfo == RIG_VFO_B || +{ + rig->state.cache.modeMainB = tx_mode; +} #endif - ELAPSED2; - RETURNFUNC(retcode); +ELAPSED2; +RETURNFUNC(retcode); } @@ -4922,7 +4951,7 @@ int HAMLIB_API rig_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5066,7 +5095,7 @@ int HAMLIB_API rig_set_split_freq_mode(RIG *rig, if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5187,7 +5216,7 @@ int HAMLIB_API rig_get_split_freq_mode(RIG *rig, if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5249,7 +5278,7 @@ int HAMLIB_API rig_set_split_vfo(RIG *rig, if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5309,7 +5338,9 @@ int HAMLIB_API rig_set_split_vfo(RIG *rig, if ((!(caps->targetable_vfo & RIG_TARGETABLE_FREQ)) && (!(rig->caps->rig_model == RIG_MODEL_NETRIGCTL))) + { rig_set_vfo(rig, rx_vfo); + } if (rx_vfo == RIG_VFO_CURR || rx_vfo == rig->state.current_vfo) @@ -5418,7 +5449,7 @@ int HAMLIB_API rig_get_split_vfo(RIG *rig, if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5553,7 +5584,7 @@ int HAMLIB_API rig_set_rit(RIG *rig, vfo_t vfo, shortfreq_t rit) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5625,7 +5656,7 @@ int HAMLIB_API rig_get_rit(RIG *rig, vfo_t vfo, shortfreq_t *rit) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5703,7 +5734,7 @@ int HAMLIB_API rig_set_xit(RIG *rig, vfo_t vfo, shortfreq_t xit) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5775,7 +5806,7 @@ int HAMLIB_API rig_get_xit(RIG *rig, vfo_t vfo, shortfreq_t *xit) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5853,7 +5884,7 @@ int HAMLIB_API rig_set_ts(RIG *rig, vfo_t vfo, shortfreq_t ts) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -5925,7 +5956,7 @@ int HAMLIB_API rig_get_ts(RIG *rig, vfo_t vfo, shortfreq_t *ts) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -6007,7 +6038,7 @@ int HAMLIB_API rig_set_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t option) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -6088,7 +6119,7 @@ int HAMLIB_API rig_get_ant(RIG *rig, vfo_t vfo, ant_t ant, value_t *option, if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -6183,7 +6214,8 @@ int HAMLIB_API rig_power2mW(RIG *rig, if (!rig || !rig->caps || !mwpower || power < 0.0 || power > 1.0) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps or mwpower or power is funky\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps or mwpower or power is funky\n", + __func__); return -RIG_EINVAL; } @@ -6315,7 +6347,7 @@ shortfreq_t HAMLIB_API rig_get_resolution(RIG *rig, rmode_t mode) if (!rig || !rig->caps || !mode) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps or mode is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps or mode is null\n", __func__); return -RIG_EINVAL; } @@ -6358,16 +6390,18 @@ int HAMLIB_API rig_set_powerstat(RIG *rig, powerstat_t status) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } + ENTERFUNC; ELAPSED1; if (rig->caps->set_powerstat == NULL) { rig_debug(RIG_DEBUG_WARN, "%s set_powerstat not implemented\n", __func__); - rig->state.powerstat = RIG_POWER_ON; // assume we are on if we can't set_powerstat + rig->state.powerstat = + RIG_POWER_ON; // assume we are on if we can't set_powerstat RETURNFUNC(-RIG_ENAVAIL); } @@ -6461,7 +6495,7 @@ int HAMLIB_API rig_reset(RIG *rig, reset_t reset) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -6563,7 +6597,7 @@ vfo_op_t HAMLIB_API rig_has_vfo_op(RIG *rig, vfo_op_t op) if (!rig || !rig->caps) { - return(0); + return (0); } ENTERFUNC; @@ -6596,7 +6630,7 @@ int HAMLIB_API rig_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -6678,7 +6712,7 @@ scan_t HAMLIB_API rig_has_scan(RIG *rig, scan_t scan) if (!rig || !rig->caps) { rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is NULL\n", __func__); - return(0); + return (0); } ENTERFUNC; @@ -6712,7 +6746,7 @@ int HAMLIB_API rig_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -6784,7 +6818,7 @@ int HAMLIB_API rig_send_dtmf(RIG *rig, vfo_t vfo, const char *digits) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -6861,7 +6895,7 @@ int HAMLIB_API rig_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -6932,12 +6966,12 @@ int HAMLIB_API rig_recv_dtmf(RIG *rig, vfo_t vfo, char *digits, int *length) int HAMLIB_API rig_send_morse(RIG *rig, vfo_t vfo, const char *msg) { const struct rig_caps *caps; - int retcode=RIG_EINTERNAL, rc2; + int retcode = RIG_EINTERNAL, rc2; vfo_t curr_vfo; if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -6960,12 +6994,15 @@ int HAMLIB_API rig_send_morse(RIG *rig, vfo_t vfo, const char *msg) rig_debug(RIG_DEBUG_ERR, "%s: rig does not have get_mode\n", __func__); RETURNFUNC(-RIG_EINVAL); } + rmode_t mode; pbwidth_t width; rig_get_mode(rig, RIG_VFO_CURR, &mode, &width); + if ((mode & (RIG_MODE_CW | RIG_MODE_CWR)) == 0) { - rig_debug(RIG_DEBUG_ERR, "%s: rig is in mode %s, not in CW/CWR mode\n", __func__, rig_strrmode(mode)); + rig_debug(RIG_DEBUG_ERR, "%s: rig is in mode %s, not in CW/CWR mode\n", + __func__, rig_strrmode(mode)); RETURNFUNC(-RIG_EINVAL); } @@ -7028,7 +7065,7 @@ int HAMLIB_API rig_stop_morse(RIG *rig, vfo_t vfo) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -7042,6 +7079,7 @@ int HAMLIB_API rig_stop_morse(RIG *rig, vfo_t vfo) } resetFIFO(rig->state.fifo_morse); // clear out the CW queue + if (vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo) { @@ -7134,7 +7172,7 @@ int HAMLIB_API rig_wait_morse(RIG *rig, vfo_t vfo) if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -7199,7 +7237,7 @@ int HAMLIB_API rig_send_voice_mem(RIG *rig, vfo_t vfo, int ch) if CHECK_RIG_ARG(rig) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -7267,7 +7305,7 @@ int HAMLIB_API rig_stop_voice_mem(RIG *rig, vfo_t vfo) if CHECK_RIG_ARG(rig) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -7279,6 +7317,7 @@ int HAMLIB_API rig_stop_voice_mem(RIG *rig, vfo_t vfo) { RETURNFUNC(-RIG_ENAVAIL); } + retcode = caps->stop_voice_mem(rig, vfo); RETURNFUNC(retcode); } @@ -7339,7 +7378,7 @@ int HAMLIB_API rig_set_vfo_opt(RIG *rig, int status) if CHECK_RIG_ARG(rig) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -7451,7 +7490,7 @@ int HAMLIB_API rig_get_rig_info(RIG *rig, char *response, int max_response_len) if (CHECK_RIG_ARG(rig) || !response) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } @@ -7548,9 +7587,10 @@ int HAMLIB_API rig_get_vfo_info(RIG *rig, vfo_t vfo, freq_t *freq, if (CHECK_RIG_ARG(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } + ELAPSED1; ENTERFUNC; @@ -7620,9 +7660,10 @@ int HAMLIB_API rig_get_vfo_list(RIG *rig, char *buf, int buflen) { if (CHECK_RIG_CAPS(rig)) { - rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n",__func__); + rig_debug(RIG_DEBUG_ERR, "%s: rig or rig->caps is null\n", __func__); return -RIG_EINVAL; } + ENTERFUNC; rig_sprintf_vfo(buf, buflen - 1, rig->state.vfo_list); @@ -7913,6 +7954,7 @@ static int async_data_handler_start(RIG *rig) rs->async_data_enabled); RETURNFUNC(RIG_OK); } + sleep(2); // give other things a chance to finish opening up the rig #ifdef HAVE_PTHREAD @@ -7967,7 +8009,8 @@ static int morse_data_handler_start(RIG *rig) keyspd.i = 25; // default value if KEYSPD doesn't work rig_get_level(rig, RIG_VFO_CURR, RIG_LEVEL_KEYSPD, &keyspd); morse_data_handler_priv->keyspd = keyspd.i; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, keyspd.i); + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, + keyspd.i); int err = pthread_create(&morse_data_handler_priv->thread_id, NULL, morse_data_handler, &morse_data_handler_priv->args); @@ -8037,16 +8080,19 @@ static int morse_data_handler_stop(RIG *rig) // wait until fifo queue is flushed //HAMLIB_TRACE; - hl_usleep(100*1000); + hl_usleep(100 * 1000); + //HAMLIB_TRACE; - while(peek(rig->state.fifo_morse) >= 0) + while (peek(rig->state.fifo_morse) >= 0) { HAMLIB_TRACE; rig_debug(RIG_DEBUG_TRACE, "%s: waiting for fifo queue to flush\n", __func__); - hl_usleep(100*1000); + hl_usleep(100 * 1000); } + //HAMLIB_TRACE; - hl_usleep(100*1000); + hl_usleep(100 * 1000); + //HAMLIB_TRACE; if (morse_data_handler_priv != NULL) { @@ -8115,7 +8161,8 @@ void *async_data_handler(void *arg) __func__, result); hl_usleep(500 * 1000); } - hl_usleep(20*1000); + + hl_usleep(20 * 1000); continue; } @@ -8163,7 +8210,7 @@ void *async_data_handler(void *arg) void *morse_data_handler(void *arg) { struct morse_data_handler_args_s *args = - (struct morse_data_handler_args_s *) arg; + (struct morse_data_handler_args_s *) arg; RIG *rig = args->rig; const struct rig_state *rs = &rig->state; int result; @@ -8173,26 +8220,32 @@ void *morse_data_handler(void *arg) if (rig->state.fifo_morse == NULL) { - rig->state.fifo_morse = calloc(1,sizeof(FIFO_RIG)); + rig->state.fifo_morse = calloc(1, sizeof(FIFO_RIG)); } initFIFO(rig->state.fifo_morse); char *c; int qsize = rig->caps->morse_qsize; // if backend overrides qsize - if (qsize == 0) qsize = 20; // shortest length of any rig's CW morse capability - c = calloc(1,qsize+1); + + if (qsize == 0) { qsize = 20; } // shortest length of any rig's CW morse capability + + c = calloc(1, qsize + 1); + while (rs->morse_data_handler_thread_run || (peek(rig->state.fifo_morse) >= 0)) { int n = 0; - memset(c,0,qsize); + memset(c, 0, qsize); + for (n = 0; n < qsize; n++) { int d = peek(rig->state.fifo_morse); + if (d < 0) { break; } + d = pop(rig->state.fifo_morse); c[n] = (char) d; } @@ -8205,53 +8258,74 @@ void *morse_data_handler(void *arg) char *p; // if we have + or - we will adjust speed and send before/speed/after which hopefully works // I suspect some rigs will change speed immediately and not wait for queued character to flush - morse_data_handler_priv_data *morse_data_handler_priv = (morse_data_handler_priv_data *) rs->morse_data_handler_priv_data; + morse_data_handler_priv_data *morse_data_handler_priv = + (morse_data_handler_priv_data *) rs->morse_data_handler_priv_data; value_t keyspd; keyspd.i = morse_data_handler_priv->keyspd; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, keyspd.i); - if ((p=strchr(c,'+')) || (p=strchr(c,'-'))) + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, + keyspd.i); + + if ((p = strchr(c, '+')) || (p = strchr(c, '-'))) { HAMLIB_TRACE; char spdchg = *p; *p = 0; - if (strlen(c) > 0) rig->caps->send_morse(rig, RIG_VFO_CURR, c); - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, keyspd.i); - keyspd.i+=spdchg=='+'?5:-5; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, keyspd.i); - while(p[1] == '+' || p[1] == '-') { + + if (strlen(c) > 0) { rig->caps->send_morse(rig, RIG_VFO_CURR, c); } + + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, + keyspd.i); + keyspd.i += spdchg == '+' ? 5 : -5; + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, + keyspd.i); + + while (p[1] == '+' || p[1] == '-') + { HAMLIB_TRACE; - keyspd.i+=p[1]=='+'?5:-5; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, keyspd.i); + keyspd.i += p[1] == '+' ? 5 : -5; + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, + keyspd.i); p++; } + p++; - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, keyspd.i); + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): keyspd=%d\n", __func__, __LINE__, + keyspd.i); rig_set_level(rig, RIG_VFO_CURR, RIG_LEVEL_KEYSPD, keyspd); morse_data_handler_priv->keyspd = keyspd.i; - memmove(c,p,p-c+1); + memmove(c, p, p - c + 1); } + #endif + if (strlen(c) > 0) { - int nloops=10; - do + int nloops = 10; + + do { result = rig->caps->send_morse(rig, RIG_VFO_CURR, c); + if (result != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: error: %s\n", __func__, rigerror(result)); - if (result == -RIG_EINVAL) + + if (result == -RIG_EINVAL) { // severe error -- so flush it and stop resetFIFO(rig->state.fifo_morse); nloops = 0; } + hl_usleep(100 * 1000); } + //wait_morse_ptt(rig, RIG_VFO_CURR); nloops--; - - } while (result != RIG_OK && rig->state.fifo_morse->flush == 0 && --nloops > 0); + + } + while (result != RIG_OK && rig->state.fifo_morse->flush == 0 && --nloops > 0); + if (nloops == 0) { rig_debug(RIG_DEBUG_ERR, "%s: send_morse failed\n", __func__); @@ -8260,7 +8334,7 @@ void *morse_data_handler(void *arg) } rig->state.fifo_morse->flush = 0; // reset flush flag - hl_usleep(100*1000); + hl_usleep(100 * 1000); } free(rig->state.fifo_morse); @@ -8330,6 +8404,7 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send, if (reply) { unsigned char buf[200]; + if (simulate) { // Simulate a response by copying the command @@ -8442,7 +8517,8 @@ HAMLIB_EXPORT(int) rig_is_model(RIG *rig, rig_model_t model) int morse_data_handler_set_keyspd(RIG *rig, int keyspd) { struct rig_state *rs = &rig->state; - morse_data_handler_priv_data *morse_data_handler_priv = (morse_data_handler_priv_data *) rs->morse_data_handler_priv_data; + morse_data_handler_priv_data *morse_data_handler_priv = + (morse_data_handler_priv_data *) rs->morse_data_handler_priv_data; morse_data_handler_priv->keyspd = keyspd; rig_debug(RIG_DEBUG_VERBOSE, "%s: keyspd=%d\n", __func__, keyspd); return RIG_OK; diff --git a/src/rotator.c b/src/rotator.c index a2ccec07b..918fc5cb8 100644 --- a/src/rotator.c +++ b/src/rotator.c @@ -516,7 +516,8 @@ int HAMLIB_API rot_open(ROT *rot) return status; } } - if(rs->rotport.parm.serial.dtr_state == RIG_SIGNAL_ON) + + if (rs->rotport.parm.serial.dtr_state == RIG_SIGNAL_ON) { ser_set_dtr(&rs->rotport, 1); } @@ -524,7 +525,8 @@ int HAMLIB_API rot_open(ROT *rot) { ser_set_dtr(&rs->rotport, 0); } - if(rs->rotport.parm.serial.rts_state == RIG_SIGNAL_ON) + + if (rs->rotport.parm.serial.rts_state == RIG_SIGNAL_ON) { ser_set_rts(&rs->rotport, 1); } diff --git a/src/serial.c b/src/serial.c index 2d14b5852..447397220 100644 --- a/src/serial.c +++ b/src/serial.c @@ -227,7 +227,8 @@ int HAMLIB_API serial_open(hamlib_port_t *rp) if (fd == -1) // some serial ports fail to open 1st time for some unknown reason { - rig_debug(RIG_DEBUG_WARN, "%s(%d): open failed#%d %s\n", __func__, __LINE__, i, strerror(errno)); + rig_debug(RIG_DEBUG_WARN, "%s(%d): open failed#%d %s\n", __func__, __LINE__, i, + strerror(errno)); hl_usleep(500 * 1000); fd = OPEN(rp->pathname, O_RDWR | O_NOCTTY | O_NDELAY); } @@ -739,9 +740,10 @@ int HAMLIB_API serial_flush(hamlib_port_t *p) rig_debug(RIG_DEBUG_ERR, "%s: No WIN32 index for port???\n", __func__); return -1; } + PurgeComm(index->hComm, PURGE_RXCLEAR); return RIG_OK; - + #endif if (p->fd == uh_ptt_fd || p->fd == uh_radio_fd || p->flushx) @@ -776,7 +778,7 @@ int HAMLIB_API serial_flush(hamlib_port_t *p) timeout_retry_save = p->timeout_retry; p->timeout = 0; p->timeout_retry = 0; - + do { @@ -817,7 +819,7 @@ int HAMLIB_API serial_flush(hamlib_port_t *p) // rig_debug(RIG_DEBUG_VERBOSE, "tcflush%s\n", ""); // we also do this flush https://github.com/Hamlib/Hamlib/issues/1241 - tcflush(p->fd,TCIFLUSH); + tcflush(p->fd, TCIFLUSH); return RIG_OK; } diff --git a/src/settings.c b/src/settings.c index 28940ba17..57e9af282 100644 --- a/src/settings.c +++ b/src/settings.c @@ -96,9 +96,10 @@ int HAMLIB_API rig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) { if (level == RIG_LEVEL_KEYSPD) { - extern int morse_data_handler_set_keyspd(RIG *rig, int keyspd); + extern int morse_data_handler_set_keyspd(RIG * rig, int keyspd); morse_data_handler_set_keyspd(rig, val.i); } + return caps->set_level(rig, vfo, level, val); } @@ -1030,12 +1031,17 @@ HAMLIB_EXPORT(int) rig_settings_get_path(char *path, int pathlen) const char *xdgpath = getenv("XDG_CONFIG_HOME"); char *home = getenv("HOME"); - if (home == NULL) { + + if (home == NULL) + { home = getenv("HOMEPATH"); } - if (home == NULL) { + + if (home == NULL) + { home = "?HOME"; } + snprintf(path, pathlen, "%s/.config", home); if (xdgpath) diff --git a/src/sleep.c b/src/sleep.c index 054e935b6..b3d2d34a2 100644 --- a/src/sleep.c +++ b/src/sleep.c @@ -174,7 +174,8 @@ int usleep(rig_useconds_t usec) #ifdef TEST #include "misc.h" // cppcheck-suppress unusedFunction -double get_elapsed_time(struct tm start, struct tm end) { +double get_elapsed_time(struct tm start, struct tm end) +{ // Convert struct tm to time_t time_t start_seconds = mktime(&start); time_t end_seconds = mktime(&end); diff --git a/src/snapshot_data.c b/src/snapshot_data.c index 8d61ebe0b..52f9a1333 100644 --- a/src/snapshot_data.c +++ b/src/snapshot_data.c @@ -27,7 +27,8 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig) cJSON_AddStringToObject(id_node, "deviceId", rig->state.device_id); cJSON_AddItemToObject(rig_node, "id", id_node); - node = cJSON_AddStringToObject(rig_node, "status", rig_strcommstatus(rig->state.comm_status)); + node = cJSON_AddStringToObject(rig_node, "status", + rig_strcommstatus(rig->state.comm_status)); if (node == NULL) { @@ -76,15 +77,18 @@ static int snapshot_serialize_rig(cJSON *rig_node, RIG *rig) rig_sprintf_mode(buf, sizeof(buf), rig->state.mode_list); char *p; cJSON *modes_array = cJSON_CreateArray(); - for(p=strtok(buf," ");p;p=strtok(NULL, " ")) + + for (p = strtok(buf, " "); p; p = strtok(NULL, " ")) { - if (strlen(buf)>0) { + if (strlen(buf) > 0) + { cJSON *tmp = cJSON_CreateString(p); cJSON_AddItemToArray(modes_array, tmp); } } + cJSON_AddItemToObject(rig_node, "modes", modes_array); - + return RIG_OK; error: @@ -360,6 +364,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig, { goto error; } + date_strget(buf, sizeof(buf), 0); node = cJSON_AddStringToObject(root_node, "time", buf); @@ -404,6 +409,7 @@ int snapshot_serialize(size_t buffer_length, char *buffer, RIG *rig, for (i = 0; i < HAMLIB_MAX_VFOS; i++) { vfo_t vfo = rig->state.vfo_list & RIG_VFO_N(i); + if (!vfo) { continue; diff --git a/src/sprintflst.c b/src/sprintflst.c index 4eb35465d..5c57db5cd 100644 --- a/src/sprintflst.c +++ b/src/sprintflst.c @@ -100,7 +100,8 @@ int rig_sprintf_mode(char *str, int nlen, rmode_t mode) { continue; /* unknown, FIXME! */ } - if (i > 0) strcat(str, " "); + + if (i > 0) { strcat(str, " "); } strcat(str, ms); len += strlen(ms) + 1; @@ -576,11 +577,11 @@ int rig_sprintf_parm_gran(char *str, int nlen, setting_t parm, { if (gran[i].step.s) { - rig_debug(RIG_DEBUG_ERR, "%s: BAND_SELECT?\n", __func__); - len += sprintf(str + len, - "%s(%s) ", - ms, - gran[i].step.s); + rig_debug(RIG_DEBUG_ERR, "%s: BAND_SELECT?\n", __func__); + len += sprintf(str + len, + "%s(%s) ", + ms, + gran[i].step.s); } } else @@ -931,7 +932,7 @@ int rig_sprintf_agc_levels(RIG *rig, char *str, int lenstr) { for (i = 0; i <= HAMLIB_MAX_AGC_LEVELS && priv_caps->agc_levels[i].level != RIG_AGC_LAST - ;i++) + ; i++) { if (strlen(str) > 0) { strcat(str, " "); } diff --git a/tests/ampctl.c b/tests/ampctl.c index 5c75e5034..33b023585 100644 --- a/tests/ampctl.c +++ b/tests/ampctl.c @@ -298,27 +298,31 @@ int main(int argc, char *argv[]) exit(2); } - char *token=strtok(conf_parms,","); + char *token = strtok(conf_parms, ","); - while(token) + while (token) { char mytoken[100], myvalue[100]; token_t lookup; - sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + sscanf(token, "%99[^=]=%99s", mytoken, myvalue); //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); - lookup = amp_token_lookup(my_amp,mytoken); + lookup = amp_token_lookup(my_amp, mytoken); + if (lookup == 0) { rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s'\n", __func__, mytoken); token = strtok(NULL, ","); continue; } - retcode = amp_set_conf(my_amp, amp_token_lookup(my_amp,mytoken), myvalue); + + retcode = amp_set_conf(my_amp, amp_token_lookup(my_amp, mytoken), myvalue); + if (retcode != RIG_OK) { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } + token = strtok(NULL, ","); } diff --git a/tests/ampctl_parse.c b/tests/ampctl_parse.c index 41d080d7a..be88553e1 100644 --- a/tests/ampctl_parse.c +++ b/tests/ampctl_parse.c @@ -1623,6 +1623,7 @@ int set_conf(AMP *my_amp, char *conf_parms) if (token != 0) { ret = amp_set_conf(my_amp, token, q); + if (ret != RIG_OK) { return ret; diff --git a/tests/ampctld.c b/tests/ampctld.c index 8244a5441..eebf6251a 100644 --- a/tests/ampctld.c +++ b/tests/ampctld.c @@ -323,27 +323,31 @@ int main(int argc, char *argv[]) exit(2); } - char *token=strtok(conf_parms,","); + char *token = strtok(conf_parms, ","); - while(token) + while (token) { char mytoken[100], myvalue[100]; token_t lookup; - sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + sscanf(token, "%99[^=]=%99s", mytoken, myvalue); //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); - lookup = amp_token_lookup(my_amp,mytoken); + lookup = amp_token_lookup(my_amp, mytoken); + if (lookup == 0) { rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s'\n", __func__, mytoken); token = strtok(NULL, ","); continue; } - retcode = amp_set_conf(my_amp, amp_token_lookup(my_amp,mytoken), myvalue); + + retcode = amp_set_conf(my_amp, amp_token_lookup(my_amp, mytoken), myvalue); + if (retcode != RIG_OK) { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } + token = strtok(NULL, ","); } diff --git a/tests/dumpcaps.c b/tests/dumpcaps.c index db473caab..34cfef5ac 100644 --- a/tests/dumpcaps.c +++ b/tests/dumpcaps.c @@ -303,7 +303,8 @@ int dumpcaps(RIG *rig, FILE *fout) if (priv_caps && RIG_BACKEND_NUM(rig->caps->rig_model) == RIG_ICOM && priv_caps->agc_levels_present) { - for (i = 0; i < HAMLIB_MAX_AGC_LEVELS && priv_caps->agc_levels[i].level != RIG_AGC_LAST ; i++) + for (i = 0; i < HAMLIB_MAX_AGC_LEVELS + && priv_caps->agc_levels[i].level != RIG_AGC_LAST ; i++) { fprintf(fout, " %d=%s", priv_caps->agc_levels[i].level, rig_stragclevel(priv_caps->agc_levels[i].level)); diff --git a/tests/dumpstate.c b/tests/dumpstate.c index 58a5987f4..d2fb9a794 100644 --- a/tests/dumpstate.c +++ b/tests/dumpstate.c @@ -302,7 +302,8 @@ int dumpstate(RIG *rig, FILE *fout) if (priv_caps && RIG_BACKEND_NUM(rig->state.rig_model) == RIG_ICOM && priv_caps->agc_levels_present) { - for (i = 0; i < HAMLIB_MAX_AGC_LEVELS && priv_caps->agc_levels[i].level != RIG_AGC_LAST; i++) + for (i = 0; i < HAMLIB_MAX_AGC_LEVELS + && priv_caps->agc_levels[i].level != RIG_AGC_LAST; i++) { fprintf(fout, " %d=%s", priv_caps->agc_levels[i].level, rig_stragclevel(priv_caps->agc_levels[i].level)); @@ -326,7 +327,8 @@ int dumpstate(RIG *rig, FILE *fout) fprintf(fout, "CTCSS:"); - for (i = 0; rig->state.ctcss_list && i < 60 && rig->state.ctcss_list[i] != 0; i++) + for (i = 0; rig->state.ctcss_list && i < 60 + && rig->state.ctcss_list[i] != 0; i++) { fprintf(fout, " %u.%1u", @@ -648,7 +650,8 @@ int dumpstate(RIG *rig, FILE *fout) fprintf(fout, "Tuning steps:"); - for (i = 0; i < HAMLIB_TSLSTSIZ && !RIG_IS_TS_END(rig->state.tuning_steps[i]); i++) + for (i = 0; i < HAMLIB_TSLSTSIZ + && !RIG_IS_TS_END(rig->state.tuning_steps[i]); i++) { if (rig->state.tuning_steps[i].ts == RIG_TS_ANY) { @@ -757,7 +760,8 @@ int dumpstate(RIG *rig, FILE *fout) fprintf(fout, "Spectrum attenuator:"); - for (i = 0; i < HAMLIB_MAXDBLSTSIZ && rig->state.spectrum_attenuator[i] != 0; i++) + for (i = 0; i < HAMLIB_MAXDBLSTSIZ + && rig->state.spectrum_attenuator[i] != 0; i++) { fprintf(fout, " %ddB", rig->state.spectrum_attenuator[i]); } @@ -781,8 +785,10 @@ int dumpstate(RIG *rig, FILE *fout) fprintf(fout, "Has Close:\t%c\n", rig->caps->rig_close != NULL ? 'Y' : 'N'); fprintf(fout, "Can set Conf:\t%c\n", rig->caps->set_conf != NULL ? 'Y' : 'N'); fprintf(fout, "Can get Conf:\t%c\n", rig->caps->get_conf != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Frequency:\t%c\n", rig->caps->set_freq != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Frequency:\t%c\n", rig->caps->get_freq != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Frequency:\t%c\n", + rig->caps->set_freq != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Frequency:\t%c\n", + rig->caps->get_freq != NULL ? 'Y' : 'N'); fprintf(fout, "Can set Mode:\t%c\n", rig->caps->set_mode != NULL ? 'Y' : 'N'); fprintf(fout, "Can get Mode:\t%c\n", rig->caps->get_mode != NULL ? 'Y' : 'N'); fprintf(fout, "Can set VFO:\t%c\n", rig->caps->set_vfo != NULL ? 'Y' : 'N'); @@ -835,16 +841,22 @@ int dumpstate(RIG *rig, FILE *fout) "Can get Split VFO:\t%c\n", rig->caps->get_split_vfo != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set Tuning Step:\t%c\n", rig->caps->set_ts != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get Tuning Step:\t%c\n", rig->caps->get_ts != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set Tuning Step:\t%c\n", + rig->caps->set_ts != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Tuning Step:\t%c\n", + rig->caps->get_ts != NULL ? 'Y' : 'N'); fprintf(fout, "Can set RIT:\t%c\n", rig->caps->set_rit != NULL ? 'Y' : 'N'); fprintf(fout, "Can get RIT:\t%c\n", rig->caps->get_rit != NULL ? 'Y' : 'N'); fprintf(fout, "Can set XIT:\t%c\n", rig->caps->set_xit != NULL ? 'Y' : 'N'); fprintf(fout, "Can get XIT:\t%c\n", rig->caps->get_xit != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set CTCSS:\t%c\n", rig->caps->set_ctcss_tone != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get CTCSS:\t%c\n", rig->caps->get_ctcss_tone != NULL ? 'Y' : 'N'); - fprintf(fout, "Can set DCS:\t%c\n", rig->caps->set_dcs_code != NULL ? 'Y' : 'N'); - fprintf(fout, "Can get DCS:\t%c\n", rig->caps->get_dcs_code != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set CTCSS:\t%c\n", + rig->caps->set_ctcss_tone != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get CTCSS:\t%c\n", + rig->caps->get_ctcss_tone != NULL ? 'Y' : 'N'); + fprintf(fout, "Can set DCS:\t%c\n", + rig->caps->set_dcs_code != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get DCS:\t%c\n", + rig->caps->get_dcs_code != NULL ? 'Y' : 'N'); fprintf(fout, "Can set CTCSS Squelch:\t%c\n", @@ -876,9 +888,11 @@ int dumpstate(RIG *rig, FILE *fout) fprintf(fout, "Can set Transceive:\t%c\n", - rig->caps->set_trn != NULL ? 'Y' : rig->caps->transceive == RIG_TRN_RIG ? 'E' : 'N'); + rig->caps->set_trn != NULL ? 'Y' : rig->caps->transceive == RIG_TRN_RIG ? 'E' : + 'N'); - fprintf(fout, "Can get Transceive:\t%c\n", rig->caps->get_trn != NULL ? 'Y' : 'N'); + fprintf(fout, "Can get Transceive:\t%c\n", + rig->caps->get_trn != NULL ? 'Y' : 'N'); fprintf(fout, "Can set Func:\t%c\n", rig->caps->set_func != NULL ? 'Y' : 'N'); fprintf(fout, "Can get Func:\t%c\n", rig->caps->get_func != NULL ? 'Y' : 'N'); fprintf(fout, "Can set Level:\t%c\n", rig->caps->set_level != NULL ? 'Y' : 'N'); @@ -887,9 +901,12 @@ int dumpstate(RIG *rig, FILE *fout) fprintf(fout, "Can get Param:\t%c\n", rig->caps->get_parm != NULL ? 'Y' : 'N'); fprintf(fout, "Can send DTMF:\t%c\n", rig->caps->send_dtmf != NULL ? 'Y' : 'N'); fprintf(fout, "Can recv DTMF:\t%c\n", rig->caps->recv_dtmf != NULL ? 'Y' : 'N'); - fprintf(fout, "Can send Morse:\t%c\n", rig->caps->send_morse != NULL ? 'Y' : 'N'); - fprintf(fout, "Can stop Morse:\t%c\n", rig->caps->stop_morse != NULL ? 'Y' : 'N'); - fprintf(fout, "Can wait Morse:\t%c\n", rig->caps->wait_morse != NULL ? 'Y' : 'N'); + fprintf(fout, "Can send Morse:\t%c\n", + rig->caps->send_morse != NULL ? 'Y' : 'N'); + fprintf(fout, "Can stop Morse:\t%c\n", + rig->caps->stop_morse != NULL ? 'Y' : 'N'); + fprintf(fout, "Can wait Morse:\t%c\n", + rig->caps->wait_morse != NULL ? 'Y' : 'N'); fprintf(fout, "Can send Voice:\t%c\n", rig->caps->send_voice_mem != NULL ? 'Y' : 'N'); diff --git a/tests/memcsv.c b/tests/memcsv.c index 4e5cd087b..e4c24581a 100644 --- a/tests/memcsv.c +++ b/tests/memcsv.c @@ -700,10 +700,15 @@ int dump_csv_chan(RIG *rig, if (mem_caps->flags) { if (chan.tag[0] != 0) // then we need the seperator + { fprintf(f, "%x%c", chan.flags, csv_sep); + } else + { fprintf(f, "%x", chan.flags); + } } + if (chan.tag[0] != 0) { fprintf(f, "%s", chan.tag); diff --git a/tests/rig_tests.c b/tests/rig_tests.c index 3e5314b8d..bc4943b7b 100644 --- a/tests/rig_tests.c +++ b/tests/rig_tests.c @@ -19,7 +19,7 @@ int rig_test_cw(RIG *rig) cw[1] = '\0'; int retval = rig_send_morse(rig, RIG_VFO_CURR, cw); - hl_usleep(100*1000); + hl_usleep(100 * 1000); if (retval != RIG_OK) { diff --git a/tests/rigctl.c b/tests/rigctl.c index 73e5380ad..dcf24a16d 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -145,17 +145,17 @@ static void signal_handler(int sig) { switch (sig) { - case SIGINT: - case SIGTERM: - fprintf(stderr, "\nTerminating application, caught signal %d\n", sig); - // Close stdin to stop reading input - fclose(stdin); - ctrl_c = 1; - break; + case SIGINT: + case SIGTERM: + fprintf(stderr, "\nTerminating application, caught signal %d\n", sig); + // Close stdin to stop reading input + fclose(stdin); + ctrl_c = 1; + break; - default: - /* do nothing */ - break; + default: + /* do nothing */ + break; } } #endif @@ -555,27 +555,31 @@ int main(int argc, char *argv[]) exit(2); } - char *token=strtok(conf_parms,","); - - while(token) + char *token = strtok(conf_parms, ","); + + while (token) { char mytoken[100], myvalue[100]; token_t lookup; - sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + sscanf(token, "%99[^=]=%99s", mytoken, myvalue); //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); - lookup = rig_token_lookup(my_rig,mytoken); + lookup = rig_token_lookup(my_rig, mytoken); + if (lookup == 0) { rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s'\n", __func__, mytoken); token = strtok(NULL, ","); continue; } - retcode = rig_set_conf(my_rig, rig_token_lookup(my_rig,mytoken), myvalue); + + retcode = rig_set_conf(my_rig, rig_token_lookup(my_rig, mytoken), myvalue); + if (retcode != RIG_OK) { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } + token = strtok(NULL, ","); } diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 9908f0d72..7fe15672d 100644 --- a/tests/rigctl_parse.c +++ b/tests/rigctl_parse.c @@ -391,8 +391,8 @@ static struct test_table test_list[] = { 0xa7, "test", ACTION(test), ARG_NOVFO | ARG_IN, "routine" }, { 0xa8, "hamlib_version", ACTION(hamlib_version), ARG_NOVFO }, { 0xa9, "get_gpio", ACTION(cm108_get_bit), ARG_NOVFO | ARG_IN1 | ARG_OUT1, "GPIO#", "0/1" }, - { 0xaa, "set_gpio", ACTION(cm108_set_bit), ARG_NOVFO | ARG_IN , "GPIO#", "0/1" }, - { 0xac, "set_conf", ACTION(set_conf), ARG_NOVFO | ARG_IN , "Token", "Token Value" }, + { 0xaa, "set_gpio", ACTION(cm108_set_bit), ARG_NOVFO | ARG_IN, "GPIO#", "0/1" }, + { 0xac, "set_conf", ACTION(set_conf), ARG_NOVFO | ARG_IN, "Token", "Token Value" }, { 0xad, "get_conf", ACTION(get_conf), ARG_NOVFO | ARG_IN1 | ARG_OUT2, "Token", "Value"}, { 0x00, "", NULL }, }; @@ -566,9 +566,9 @@ static int scanfc(FILE *fin, const char *format, void *p) if (!feof(fin)) { - rig_debug(RIG_DEBUG_TRACE,"%s fscanf of:", __func__); + rig_debug(RIG_DEBUG_TRACE, "%s fscanf of:", __func__); dump_hex((unsigned char *)p, strlen(p)); - rig_debug(RIG_DEBUG_TRACE," failed with format '%s'\n", format); + rig_debug(RIG_DEBUG_TRACE, " failed with format '%s'\n", format); ret = 0x0a; } } @@ -720,18 +720,20 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc, { if ((retcode = scanfc(fin, "%c", &cmd)) < 1) { - if (last_cmd==0) + if (last_cmd == 0) { - rig_debug(RIG_DEBUG_WARN, "%s: nothing to scan#1? retcode=%d, last_cmd=[empty]\n", - __func__, - retcode); + rig_debug(RIG_DEBUG_WARN, + "%s: nothing to scan#1? retcode=%d, last_cmd=[empty]\n", + __func__, + retcode); } else { - rig_debug(RIG_DEBUG_WARN, "%s: nothing to scan#1? retcode=%d, last_cmd=%c\n", - __func__, - retcode, last_cmd); + rig_debug(RIG_DEBUG_WARN, "%s: nothing to scan#1? retcode=%d, last_cmd=%c\n", + __func__, + retcode, last_cmd); } + return (RIGCTL_PARSE_ERROR); } @@ -1713,11 +1715,12 @@ readline_repeat: " %s", rig_strvfo(vfo)); - p1 == NULL ? a1[0] = '\0' : snprintf(a1, sizeof(a1), "%c%s", *vfo_opt?',':' ',p1); + p1 == NULL ? a1[0] = '\0' : snprintf(a1, sizeof(a1), "%c%s", + *vfo_opt ? ',' : ' ', p1); p2 == NULL ? a2[0] = '\0' : snprintf(a2, sizeof(a2), " %s", p2); p3 == NULL ? a3[0] = '\0' : snprintf(a3, sizeof(a3), " %s", p3); - if (cmd == 'b') strtok(a1,"\r\n"); + if (cmd == 'b') { strtok(a1, "\r\n"); } fprintf(fout, "%s:%s%s%s%s%c", @@ -1760,7 +1763,8 @@ readline_repeat: else { // Allow only certain commands when the rig is powered off - if (my_rig->state.powerstat == RIG_POWER_OFF && (rig_powerstat == RIG_POWER_OFF || rig_powerstat == RIG_POWER_STANDBY) + if (my_rig->state.powerstat == RIG_POWER_OFF && (rig_powerstat == RIG_POWER_OFF + || rig_powerstat == RIG_POWER_STANDBY) && cmd_entry->cmd != '1' // dump_caps && cmd_entry->cmd != '3' // dump_conf && cmd_entry->cmd != 0x8f // dump_state @@ -1960,6 +1964,7 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) cfp->u.n.max, cfp->u.n.step); break; + case RIG_CONF_NUMERIC: printf("\tRange: %g..%g, step %.1f\n", cfp->u.n.min, @@ -2009,11 +2014,11 @@ int print_conf_list2(const struct confparams *cfp, rig_ptr_t data) char buf[128] = ""; rig_get_conf(rig, cfp->token, buf); - fprintf(stdout,"%s: \"%s\"\n" "\t" "Default: %s, Value: %s\n", - cfp->name, - cfp->tooltip, - cfp->dflt, - buf); + fprintf(stdout, "%s: \"%s\"\n" "\t" "Default: %s, Value: %s\n", + cfp->name, + cfp->tooltip, + cfp->dflt, + buf); return 1; /* !=0, we want them all ! */ } @@ -2439,12 +2444,14 @@ declare_proto_rig(get_vfo_list) declare_proto_rig(test) { ENTERFUNC2; + if (!strcmp(arg1, "?")) { fprintf(fout, "cw\n"); RETURNFUNC2(RIG_OK); } - if (strcmp(arg1, "cw")==0) rig_test_cw(rig); + + if (strcmp(arg1, "cw") == 0) { rig_test_cw(rig); } RETURNFUNC2(RIG_OK); } @@ -3255,7 +3262,7 @@ declare_proto_rig(set_level) level = rig_parse_level(arg1); - if ((!strcmp(arg2, "?") || arg2[0]==0) && level == RIG_LEVEL_METER) + if ((!strcmp(arg2, "?") || arg2[0] == 0) && level == RIG_LEVEL_METER) { fprintf(fout, "COMP ALC SWR ID/IC VDD DB PO TEMP%c", resp_sep); RETURNFUNC2(RIG_OK); @@ -3311,22 +3318,26 @@ declare_proto_rig(set_level) } int dummy; - if (level == RIG_LEVEL_METER && sscanf(arg2,"%d",&dummy)==0) + + if (level == RIG_LEVEL_METER && sscanf(arg2, "%d", &dummy) == 0) { - if (strcmp(arg2,"COMP")==0) arg2 = "2"; - else if (strcmp(arg2,"ALC")==0) arg2 = "4"; - else if (strcmp(arg2,"SWR")==0) arg2 = "1"; - else if (strcmp(arg2,"ID")==0 || strcmp(arg2,"IC")==0) arg2 = "8"; - else if (strcmp(arg2,"VDD")==0) arg2 = "64"; - else if (strcmp(arg2, "DB")==0) arg2 = "16"; - else if (strcmp(arg2, "PO")==0) arg2 = "32"; - else if (strcmp(arg2, "TEMP")==0) arg2 = "128"; + if (strcmp(arg2, "COMP") == 0) { arg2 = "2"; } + else if (strcmp(arg2, "ALC") == 0) { arg2 = "4"; } + else if (strcmp(arg2, "SWR") == 0) { arg2 = "1"; } + else if (strcmp(arg2, "ID") == 0 || strcmp(arg2, "IC") == 0) { arg2 = "8"; } + else if (strcmp(arg2, "VDD") == 0) { arg2 = "64"; } + else if (strcmp(arg2, "DB") == 0) { arg2 = "16"; } + else if (strcmp(arg2, "PO") == 0) { arg2 = "32"; } + else if (strcmp(arg2, "TEMP") == 0) { arg2 = "128"; } else { - rig_debug(RIG_DEBUG_ERR, "%s: unknown meter=%s, only know COMP,ALC,SWR,ID/IC,VDD,DB,PO,TEMP\n", __func__, arg2); + rig_debug(RIG_DEBUG_ERR, + "%s: unknown meter=%s, only know COMP,ALC,SWR,ID/IC,VDD,DB,PO,TEMP\n", __func__, + arg2); RETURNFUNC2(-RIG_EINVAL); } } + if (RIG_LEVEL_IS_FLOAT(level)) { CHKSCN1ARG(sscanf(arg2, "%f", &val.f)); @@ -3364,6 +3375,7 @@ declare_proto_rig(get_level) fputc('\n', fout); RETURNFUNC2(RIG_OK); } + level = rig_parse_level(arg1); if (!rig_has_get_level(rig, level)) @@ -3431,26 +3443,38 @@ declare_proto_rig(get_level) { fprintf(fout, "%s: ", cmd->arg2); } - if (level == RIG_LEVEL_METER && interactive && prompt) + + if (level == RIG_LEVEL_METER && interactive && prompt) + { + // we will show text answers as they make morse sense for rigtl + switch (val.i) { - // we will show text answers as they make morse sense for rigtl - switch(val.i) - { - case RIG_METER_COMP: fprintf(fout, "%d=%s%c", val.i, "COMP", resp_sep);break; - case RIG_METER_ALC: fprintf(fout, "%d=%s%c", val.i, "ALC", resp_sep);break; - case RIG_METER_SWR: fprintf(fout, "%d=%s%c", val.i, "SWR", resp_sep);break; - case RIG_METER_IC: fprintf(fout, "%d=%s%c", val.i, "IC", resp_sep);break; - case RIG_METER_VDD: fprintf(fout, "%d=%s%c", val.i, "VDD", resp_sep);break; - case RIG_METER_DB: fprintf(fout, "%d=%s%c", val.i, "DB", resp_sep);break; - case RIG_METER_PO: fprintf(fout, "%d=%s%c", val.i, "PO", resp_sep);break; - case RIG_METER_TEMP: fprintf(fout, "%d=%s%c", val.i, "TEMP", resp_sep);break; - default: - rig_debug(RIG_DEBUG_ERR, "%s: unknown meter=%d, only know COMP,ALC,SWR,ID/IC,VDD,DB,PO,TEMP\n", __func__, val.i); - RETURNFUNC2(-RIG_EINVAL); - } - RETURNFUNC(RIG_OK); + case RIG_METER_COMP: fprintf(fout, "%d=%s%c", val.i, "COMP", resp_sep); break; + + case RIG_METER_ALC: fprintf(fout, "%d=%s%c", val.i, "ALC", resp_sep); break; + + case RIG_METER_SWR: fprintf(fout, "%d=%s%c", val.i, "SWR", resp_sep); break; + + case RIG_METER_IC: fprintf(fout, "%d=%s%c", val.i, "IC", resp_sep); break; + + case RIG_METER_VDD: fprintf(fout, "%d=%s%c", val.i, "VDD", resp_sep); break; + + case RIG_METER_DB: fprintf(fout, "%d=%s%c", val.i, "DB", resp_sep); break; + + case RIG_METER_PO: fprintf(fout, "%d=%s%c", val.i, "PO", resp_sep); break; + + case RIG_METER_TEMP: fprintf(fout, "%d=%s%c", val.i, "TEMP", resp_sep); break; + + default: + rig_debug(RIG_DEBUG_ERR, + "%s: unknown meter=%d, only know COMP,ALC,SWR,ID/IC,VDD,DB,PO,TEMP\n", __func__, + val.i); + RETURNFUNC2(-RIG_EINVAL); } + RETURNFUNC(RIG_OK); + } + if (RIG_LEVEL_IS_FLOAT(level)) { @@ -3562,6 +3586,7 @@ declare_proto_rig(get_func) { fprintf(fout, "%s: ", cmd->arg1); } + fprintf(fout, "%d%c", func_stat, resp_sep); RETURNFUNC2(status); @@ -3583,29 +3608,35 @@ declare_proto_rig(set_parm) fprintf(fout, "%s\n", s); RETURNFUNC2(RIG_OK); } - if (strcmp(arg1,"BANDSELECT")==0 && !strcmp(arg2,"?")) + + if (strcmp(arg1, "BANDSELECT") == 0 && !strcmp(arg2, "?")) { char s[SPRINTF_MAX_SIZE]; - rig_sprintf_parm_gran(s, sizeof(s)-1, RIG_PARM_BANDSELECT, rig->caps->parm_gran); - char *p = strchr(s,')'); - if (p) *p = 0; - p = strchr(s,'('); + rig_sprintf_parm_gran(s, sizeof(s) - 1, RIG_PARM_BANDSELECT, + rig->caps->parm_gran); + char *p = strchr(s, ')'); + + if (p) { *p = 0; } + + p = strchr(s, '('); if (p) { char *comma; - while((comma=strchr(p,','))) *comma=' '; - fprintf(fout, "%s\n", p+1); + + while ((comma = strchr(p, ','))) { *comma = ' '; } + + fprintf(fout, "%s\n", p + 1); RETURNFUNC2(RIG_OK); } - else RETURNFUNC2(-RIG_EINTERNAL); + else { RETURNFUNC2(-RIG_EINTERNAL); } } - if (strcmp(arg1,"KEYERTYPE")==0 && strcmp(arg2,"?") != 0) + if (strcmp(arg1, "KEYERTYPE") == 0 && strcmp(arg2, "?") != 0) { - if (strcmp(arg2,"STRAIGHT")==0) {arg2 = "0";} - else if (strcmp(arg2,"BUG")==0) {arg2 = "1";} - else if (strcmp(arg2,"PADDLE")==0) {arg2 = "2";} + if (strcmp(arg2, "STRAIGHT") == 0) {arg2 = "0";} + else if (strcmp(arg2, "BUG") == 0) {arg2 = "1";} + else if (strcmp(arg2, "PADDLE") == 0) {arg2 = "2";} } parm = rig_parse_parm(arg1); @@ -3643,9 +3674,14 @@ declare_proto_rig(set_parm) case RIG_CONF_STRING: if (parm == RIG_PARM_KEYERTYPE) - val.i = atoi(arg2); + { + val.i = atoi(arg2); + } else - val.cs = arg2; + { + val.cs = arg2; + } + break; case RIG_CONF_BINARY: @@ -3666,9 +3702,13 @@ declare_proto_rig(set_parm) else if (RIG_PARM_IS_STRING(parm)) { if (parm == RIG_PARM_KEYERTYPE) - val.i = atoi(arg2); + { + val.i = atoi(arg2); + } else - val.cs = arg2; + { + val.cs = arg2; + } } else { @@ -3790,8 +3830,10 @@ declare_proto_rig(get_parm) if (parm == RIG_PARM_KEYERTYPE) { char *s = "STRAIGHT"; - if (val.i == 1) s = "BUG"; - else if (val.i == 2) s = "PADDLE"; + + if (val.i == 1) { s = "BUG"; } + else if (val.i == 2) { s = "PADDLE"; } + fprintf(fout, "%s%cv", s, resp_sep); } else if (RIG_PARM_IS_FLOAT(parm)) @@ -4480,6 +4522,7 @@ declare_proto_rig(dump_caps) ENTERFUNC2; #if 1 + if (rig->caps->rig_model == RIG_MODEL_NETRIGCTL) { char cmd[32]; @@ -4603,7 +4646,9 @@ declare_proto_rig(dump_state) // protocol 1 allows fields can be listed/processed in any order // protocol 1 fields can be multi-line -- just write the thing to allow for it // backward compatible as new values will just generate warnings - rig_debug(RIG_DEBUG_ERR, "%s: chk_vfo_executed=%d\n", __func__, chk_vfo_executed); + rig_debug(RIG_DEBUG_ERR, "%s: chk_vfo_executed=%d\n", __func__, + chk_vfo_executed); + if (chk_vfo_executed) // for 3.3 compatiblility { fprintf(fout, "vfo_ops=0x%x\n", rig->caps->vfo_ops); @@ -4692,8 +4737,9 @@ declare_proto_rig(dump_state) rig->state.level_gran[i].max.i, rig->state.level_gran[i].step.i); } } + fprintf(fout, "\n"); - + rig->state.rig_model = rig->caps->rig_model; fprintf(fout, "rig_model=%d\n", rig->state.rig_model); fprintf(fout, "hamlib_version=%s\n", hamlib_version2); @@ -5118,14 +5164,15 @@ declare_proto_rig(send_cmd) } int hexval; + if (arg2[0] == ';') { eom_buf[0] = ';'; } - else if (strstr(arg2,"fd")) eom_buf[0] = 0xfd; // ICOM answer terminator + else if (strstr(arg2, "fd")) { eom_buf[0] = 0xfd; } // ICOM answer terminator else - { - sscanf(arg2,"\\0x%2x", &hexval); + { + sscanf(arg2, "\\0x%2x", &hexval); eom_buf[0] = hexval; } - + if (simulate) { @@ -5237,7 +5284,8 @@ declare_proto_rig(chk_vfo) { ENTERFUNC2; -rig_debug(RIG_DEBUG_ERR, "%s: **********************************\n", __func__); + rig_debug(RIG_DEBUG_ERR, "%s: **********************************\n", __func__); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf(fout, "%s: ", cmd->arg1); /* i.e. "Frequency" */ @@ -5726,21 +5774,30 @@ declare_proto_rig(cm108_get_bit) int gpio = -1; int bit = -1; // try GPIO format first - int n = sscanf(arg1,"GPIO%d", &gpio); + int n = sscanf(arg1, "GPIO%d", &gpio); + if (n == 0) - n = sscanf(arg1,"%d", &gpio); - if (n != 1) return -RIG_EINVAL; + { + n = sscanf(arg1, "%d", &gpio); + } + + if (n != 1) { return -RIG_EINVAL; } + int retval = rig_cm108_get_bit(&rig->state.pttport, gpio, &bit); + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: %s\n", __func__, strerror(retval)); return retval; } + rig_debug(RIG_DEBUG_TRACE, "%s: gpio=%d\n", __func__, gpio); + if ((interactive && prompt) || (interactive && !prompt && ext_resp)) { fprintf(fout, "%s: ", cmd->arg2); } + fprintf(fout, "%d (simulated)\n", 1); @@ -5750,20 +5807,29 @@ declare_proto_rig(cm108_get_bit) declare_proto_rig(cm108_set_bit) { rig_debug(RIG_DEBUG_TRACE, "%s:\n", __func__); - int gpio, bit=-1; + int gpio, bit = -1; // try GPIO format first - int n = sscanf(arg1,"GPIO%d", &gpio); + int n = sscanf(arg1, "GPIO%d", &gpio); + if (n == 0) - n = sscanf(arg1,"%d", &gpio); - if (n != 1) return -RIG_EINVAL; + { + n = sscanf(arg1, "%d", &gpio); + } + + if (n != 1) { return -RIG_EINVAL; } + n = sscanf(arg2, "%d", &bit); - if (n != 1) return -RIG_EINVAL; + + if (n != 1) { return -RIG_EINVAL; } + rig_debug(RIG_DEBUG_TRACE, "%s: set gpio=%d, bit=%d\n", __func__, gpio, bit); int retval = rig_cm108_set_bit(&rig->state.pttport, gpio, bit); + if (retval != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: %s\n", __func__, strerror(retval)); } + return retval; } @@ -5771,6 +5837,7 @@ declare_proto_rig(get_conf) { int ret; rig_debug(RIG_DEBUG_ERR, "%s: \n", __func__); + if (arg1 == NULL || arg1[0] == '?') { dumpconf_list(rig, stdout); @@ -5778,20 +5845,25 @@ declare_proto_rig(get_conf) debugmsgsave2[0] = 0; return RIG_OK; } + token_t mytoken = rig_token_lookup(rig, arg1); + if (mytoken == 0) { - rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rig\n", __func__, arg1); + rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rig\n", __func__, + arg1); ret = -RIG_EINVAL; } else { char value[4096]; // no max value known -- should we limit it? ret = rig_get_conf(rig, mytoken, value); + if (ret != RIG_OK) { return ret; } + fprintf(fout, "%s=%s\n", arg1, value); } @@ -5811,10 +5883,13 @@ declare_proto_rig(set_conf) debugmsgsave2[0] = 0; return RIG_OK; } + token_t mytoken = rig_token_lookup(rig, arg1); + if (mytoken == 0) { - rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rig\n", __func__, arg1); + rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rig\n", __func__, + arg1); ret = -RIG_EINVAL; } else diff --git a/tests/rigctld.c b/tests/rigctld.c index ebdc2a2ab..7d6d3e196 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -659,27 +659,32 @@ int main(int argc, char *argv[]) fprintf(stderr, "Please check with --list option.\n"); exit(2); } - - char *token=strtok(conf_parms,","); - while(token) + + char *token = strtok(conf_parms, ","); + + while (token) { char mytoken[100], myvalue[100]; token_t lookup; - sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + sscanf(token, "%99[^=]=%99s", mytoken, myvalue); //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); - lookup = rig_token_lookup(my_rig,mytoken); + lookup = rig_token_lookup(my_rig, mytoken); + if (lookup == 0) { rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s'\n", __func__, mytoken); token = strtok(NULL, ","); continue; } - retcode = rig_set_conf(my_rig, rig_token_lookup(my_rig,mytoken), myvalue); + + retcode = rig_set_conf(my_rig, rig_token_lookup(my_rig, mytoken), myvalue); + if (retcode != RIG_OK) { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } + token = strtok(NULL, ","); } @@ -867,28 +872,36 @@ int main(int argc, char *argv[]) freeaddrinfo(saved_result); /* No longer needed */ exit(2); } - const int optval = 1; -#ifdef __MINGW32__ - if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, (PCHAR)&optval, sizeof(optval)) < 0) -#else - if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) < 0) -#endif - { - rig_debug(RIG_DEBUG_ERR, "%s: error enabling UDP address reuse: %s\n", __func__, - strerror(errno)); - } - // Windows does not have SO_REUSEPORT. However, SO_REUSEADDR works in a similar way. + const int optval = 1; +#ifdef __MINGW32__ + + if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, (PCHAR)&optval, + sizeof(optval)) < 0) +#else + if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, &optval, + sizeof(optval)) < 0) +#endif + { + rig_debug(RIG_DEBUG_ERR, "%s: error enabling UDP address reuse: %s\n", __func__, + strerror(errno)); + } + + // Windows does not have SO_REUSEPORT. However, SO_REUSEADDR works in a similar way. #if defined(SO_REUSEPORT) - if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval)) < 0) - { - rig_debug(RIG_DEBUG_ERR, "%s: error enabling UDP port reuse: %s\n", __func__, - strerror(errno)); - } + + if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEPORT, &optval, + sizeof(optval)) < 0) + { + rig_debug(RIG_DEBUG_ERR, "%s: error enabling UDP port reuse: %s\n", __func__, + strerror(errno)); + } + #endif #if 0 + if (setsockopt(sock_listen, SOL_SOCKET, SO_REUSEADDR, @@ -901,6 +914,7 @@ int main(int argc, char *argv[]) freeaddrinfo(saved_result); /* No longer needed */ exit(1); } + #endif #ifdef IPV6_V6ONLY @@ -928,18 +942,25 @@ int main(int argc, char *argv[]) #endif int retval = bind(sock_listen, result->ai_addr, result->ai_addrlen); + if (retval == 0) { break; } + { - rig_debug(RIG_DEBUG_ERR,"%s: bind: %s\n", __func__, strerror(errno)); + rig_debug(RIG_DEBUG_ERR, "%s: bind: %s\n", __func__, strerror(errno)); } if (bind_all) + { handle_error(RIG_DEBUG_WARN, "binding failed (trying next interface)"); + } else + { handle_error(RIG_DEBUG_WARN, "binding failed"); + } + #ifdef __MINGW32__ closesocket(sock_listen); #else @@ -1139,7 +1160,7 @@ int main(int argc, char *argv[]) #endif } } - while(!ctrl_c); + while (!ctrl_c); rig_debug(RIG_DEBUG_VERBOSE, "%s: while loop done\n", __func__); @@ -1151,6 +1172,7 @@ int main(int argc, char *argv[]) { rig_debug(RIG_DEBUG_WARN, "%u outstanding client(s)\n", client_count); } + #ifdef __MINGW__ closesocket(sock_listen); #else diff --git a/tests/rigfreqwalk.c b/tests/rigfreqwalk.c index d5d06ebf7..d5884c4f0 100644 --- a/tests/rigfreqwalk.c +++ b/tests/rigfreqwalk.c @@ -17,23 +17,28 @@ double history[HISTORYSIZE]; int nhistory; int historyinit = 1; -double compute_mean(const double arr[], int length) +double compute_mean(const double arr[], int length) { double sum = 0.0; - for (int i = 0; i < length; i++) { + + for (int i = 0; i < length; i++) + { sum += arr[i]; } + return sum / length; } -double sigma(double arr[], int length) { +double sigma(double arr[], int length) +{ double mean = compute_mean(arr, length); double sum_of_squares = 0.0; - - for (int i = 0; i < length; i++) { + + for (int i = 0; i < length; i++) + { sum_of_squares += pow(arr[i] - mean, 2); } - + return sqrt(sum_of_squares / length); } @@ -49,9 +54,10 @@ int main(int argc, const char *argv[]) if (argc != 8) { - fprintf(stderr,"%s: version 1.0\n", argv[0]); - fprintf(stderr,"Usage: %s [model#] [comport] [baud] [start freq] [stop_freq] [stepsize] [seconds/step]\n", - argv[0]); + fprintf(stderr, "%s: version 1.0\n", argv[0]); + fprintf(stderr, + "Usage: %s [model#] [comport] [baud] [start freq] [stop_freq] [stepsize] [seconds/step]\n", + argv[0]); return 1; } @@ -109,30 +115,38 @@ int main(int argc, const char *argv[]) for (long f = freq1; f <= freq2; f += stepsize) { retcode = rig_set_freq(my_rig, RIG_VFO_CURR, (freq_t)f); + if (retcode != RIG_OK) { fprintf(stderr, "%s: Error rig_set_freq: %s\n", __func__, rigerror(retcode)); return 1; } + sleep(seconds); retcode = rig_get_strength(my_rig, RIG_VFO_CURR, &strength); if (retcode != RIG_OK) { - int static once=1; + int static once = 1; + if (once) { once = 0; - fprintf(stderr,"rig_get_strength error: %s\n", rigerror(retcode)); + fprintf(stderr, "rig_get_strength error: %s\n", rigerror(retcode)); } + strength = 1; } + history[nhistory++] = strength; + if (historyinit) { - for(int i=0;ibmAttributes); } -static void print_ss_usb_cap(const struct libusb_ss_usb_device_capability_descriptor +static void print_ss_usb_cap(const struct + libusb_ss_usb_device_capability_descriptor *ss_usb_cap) { printf(" USB 3.0 Capabilities:\n"); diff --git a/tests/rotctl.c b/tests/rotctl.c index cdf2b7775..d7309a755 100644 --- a/tests/rotctl.c +++ b/tests/rotctl.c @@ -339,27 +339,32 @@ int main(int argc, char *argv[]) exit(2); } - char *token=strtok(conf_parms,","); + char *token = strtok(conf_parms, ","); - while(token) + while (token) { char mytoken[100], myvalue[100]; token_t lookup; - sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + sscanf(token, "%99[^=]=%99s", mytoken, myvalue); //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); - lookup = rot_token_lookup(my_rot,mytoken); + lookup = rot_token_lookup(my_rot, mytoken); + if (lookup == 0) { - rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s', use -L switch to see\n", __func__, mytoken); + rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s', use -L switch to see\n", + __func__, mytoken); token = strtok(NULL, ","); continue; } - retcode = rot_set_conf(my_rot, rot_token_lookup(my_rot,mytoken), myvalue); + + retcode = rot_set_conf(my_rot, rot_token_lookup(my_rot, mytoken), myvalue); + if (retcode != RIG_OK) { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } + token = strtok(NULL, ","); } @@ -479,7 +484,7 @@ int main(int argc, char *argv[]) do { - retcode = rotctl_parse(my_rot, stdin, stdout, (const char**)argv, argc, + retcode = rotctl_parse(my_rot, stdin, stdout, (const char **)argv, argc, interactive, prompt, send_cmd_term); if (retcode == 2) @@ -487,6 +492,7 @@ int main(int argc, char *argv[]) exitcode = 2; } } + // cppcheck-suppress knownConditionTrueFalse while (retcode == 0 || retcode == 2); diff --git a/tests/rotctl_parse.c b/tests/rotctl_parse.c index 4191c751a..032284353 100644 --- a/tests/rotctl_parse.c +++ b/tests/rotctl_parse.c @@ -187,8 +187,8 @@ declare_proto_rot(set_parm); declare_proto_rot(get_parm); declare_proto_rot(get_info); declare_proto_rot(get_status); -declare_proto_rot(set_conf); -declare_proto_rot(get_conf); +declare_proto_rot(set_conf); +declare_proto_rot(get_conf); declare_proto_rot(send_cmd); declare_proto_rot(dump_state); declare_proto_rot(dump_caps); @@ -409,9 +409,9 @@ static int scanfc(FILE *fin, const char *format, void *p) if (!feof(fin)) { - rig_debug(RIG_DEBUG_TRACE,"%s fscanf of:", __func__); + rig_debug(RIG_DEBUG_TRACE, "%s fscanf of:", __func__); dump_hex((unsigned char *)p, strlen(p)); - rig_debug(RIG_DEBUG_TRACE," failed with format '%s'\n", format); + rig_debug(RIG_DEBUG_TRACE, " failed with format '%s'\n", format); } } @@ -528,7 +528,8 @@ static int next_word(char *buffer, int argc, const char **argv, int newline) }) -int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, const char *argv[], int argc, +int rotctl_parse(ROT *my_rot, FILE *fin, FILE *fout, const char *argv[], + int argc, int interactive, int prompt, char send_cmd_term) { int retcode; /* generic return code from functions */ @@ -1576,23 +1577,23 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) char buf[128] = ""; rot_get_conf2(rot, cfp->token, buf, sizeof(buf)); - fprintf(stdout,"%s: \"%s\"\n" "\tDefault: %s, Value: %s\n", - cfp->name, - cfp->tooltip, - cfp->dflt, - buf); + fprintf(stdout, "%s: \"%s\"\n" "\tDefault: %s, Value: %s\n", + cfp->name, + cfp->tooltip, + cfp->dflt, + buf); switch (cfp->type) { case RIG_CONF_NUMERIC: - fprintf(stdout,"\tRange: %.1f..%.1f, step %.1f\n", - cfp->u.n.min, - cfp->u.n.max, - cfp->u.n.step); + fprintf(stdout, "\tRange: %.1f..%.1f, step %.1f\n", + cfp->u.n.min, + cfp->u.n.max, + cfp->u.n.step); break; case RIG_CONF_CHECKBUTTON: - fprintf(stdout,"\tCheckbox: 0,1\n"); + fprintf(stdout, "\tCheckbox: 0,1\n"); break; case RIG_CONF_COMBO: @@ -1601,14 +1602,14 @@ int print_conf_list(const struct confparams *cfp, rig_ptr_t data) break; } - fprintf(stdout,"\tCombo: %s", cfp->u.c.combostr[0]); + fprintf(stdout, "\tCombo: %s", cfp->u.c.combostr[0]); for (i = 1 ; i < RIG_COMBO_MAX && cfp->u.c.combostr[i]; i++) { - fprintf(stdout,", %s", cfp->u.c.combostr[i]); + fprintf(stdout, ", %s", cfp->u.c.combostr[i]); } - fprintf(stdout,"\n"); + fprintf(stdout, "\n"); break; default: @@ -1672,6 +1673,7 @@ declare_proto_rot(get_conf) { int ret; rig_debug(RIG_DEBUG_ERR, "%s: \n", __func__); + if (arg1 == NULL || arg1[0] == '?') { dumpconf_list(rot, fout); @@ -1679,20 +1681,25 @@ declare_proto_rot(get_conf) debugmsgsave2[0] = 0; return RIG_OK; } + token_t mytoken = rot_token_lookup(rot, arg1); + if (mytoken == 0) { - rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rot\n", __func__, arg1); + rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rot\n", __func__, + arg1); ret = -RIG_EINVAL; } else { char value[4096]; ret = rot_get_conf(rot, rot_token_lookup(rot, arg1), value); + if (ret != RIG_OK) { return ret; } + fprintf(fout, "%s=%s\n", arg1, value); } @@ -1715,9 +1722,11 @@ declare_proto_rot(set_conf) } token_t mytoken = rot_token_lookup(rot, arg1); + if (mytoken == 0) { - rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rot\n", __func__, arg1); + rig_debug(RIG_DEBUG_ERR, "%s: unknown token '%s' for this rot\n", __func__, + arg1); ret = -RIG_EINVAL; } else @@ -2891,11 +2900,11 @@ int print_conf_list2(const struct confparams *cfp, rig_ptr_t data, FILE *fout) char buf[128] = ""; rot_get_conf(rot, cfp->token, buf); - fprintf(fout,"%s: \"%s\"\n" "\t" "Default: %s, Value: %s\n", - cfp->name, - cfp->tooltip, - cfp->dflt, - buf); + fprintf(fout, "%s: \"%s\"\n" "\t" "Default: %s, Value: %s\n", + cfp->name, + cfp->tooltip, + cfp->dflt, + buf); return 1; /* !=0, we want them all ! */ } diff --git a/tests/rotctld.c b/tests/rotctld.c index e0a37ffe3..028652742 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -345,27 +345,32 @@ int main(int argc, char *argv[]) exit(2); } - char *token=strtok(conf_parms,","); + char *token = strtok(conf_parms, ","); - while(token) + while (token) { char mytoken[100], myvalue[100]; token_t lookup; - sscanf(token,"%99[^=]=%99s", mytoken, myvalue); + sscanf(token, "%99[^=]=%99s", mytoken, myvalue); //printf("mytoken=%s,myvalue=%s\n",mytoken, myvalue); - lookup = rot_token_lookup(my_rot,mytoken); + lookup = rot_token_lookup(my_rot, mytoken); + if (lookup == 0) { - rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s', use -L switch to see\n", __func__, mytoken); + rig_debug(RIG_DEBUG_ERR, "%s: no such token as '%s', use -L switch to see\n", + __func__, mytoken); token = strtok(NULL, ","); continue; } - retcode = rot_set_conf(my_rot, rot_token_lookup(my_rot,mytoken), myvalue); + + retcode = rot_set_conf(my_rot, rot_token_lookup(my_rot, mytoken), myvalue); + if (retcode != RIG_OK) { fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); exit(2); } + token = strtok(NULL, ","); } diff --git a/tests/testcache.c b/tests/testcache.c index 91d18fc69..d751eea15 100644 --- a/tests/testcache.c +++ b/tests/testcache.c @@ -72,6 +72,7 @@ int main(int argc, char *argv[]) vfo_t vfo; retcode = rig_get_vfo(my_rig, &vfo); + if (retcode != RIG_OK) { rig_debug(RIG_DEBUG_ERR, "%s: rig_get_vfo: %s\n", __func__, rigerror(retcode)); diff --git a/tests/testrig.c b/tests/testrig.c index f4b3b46ea..578ed7750 100644 --- a/tests/testrig.c +++ b/tests/testrig.c @@ -38,7 +38,8 @@ int main(int argc, const char *argv[]) * allocate memory, setup & open port */ - hamlib_port_t myport; + hamlib_port_t myport; + if (argc < 2) { /* may be overridden by backend probe */ @@ -77,16 +78,21 @@ int main(int argc, const char *argv[]) exit(2); } - uint64_t levels = rig_get_caps_int(my_rig->caps->rig_model, RIG_CAPS_HAS_GET_LEVEL); - printf("HAS_GET_LEVEL=0x%8llx, SWR=%8llx,true=%d\n", levels, levels & RIG_LEVEL_SWR, (levels & RIG_LEVEL_SWR) == RIG_LEVEL_SWR); + uint64_t levels = rig_get_caps_int(my_rig->caps->rig_model, + RIG_CAPS_HAS_GET_LEVEL); + printf("HAS_GET_LEVEL=0x%8llx, SWR=%8llx,true=%d\n", levels, + levels & RIG_LEVEL_SWR, (levels & RIG_LEVEL_SWR) == RIG_LEVEL_SWR); char val[256]; retcode = rig_get_conf2(my_rig, rig_token_lookup(my_rig, "write_delay"), val, sizeof(val)); + if (retcode != RIG_OK) { - rig_debug(RIG_DEBUG_ERR, "%s: rig_get_conf2: %s\n", __func__, rigerror(retcode)); + rig_debug(RIG_DEBUG_ERR, "%s: rig_get_conf2: %s\n", __func__, + rigerror(retcode)); } + printf("write_delay=%s\n", val); // printf("Port %s opened ok\n", SERIAL_PORT);