diff --git a/NEWS b/NEWS index 5409bba58..9fadc11a2 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,15 @@ Version 5.x -- future * Change FT1000MP Mark V model names to align with FT1000MP Version 4.6 + * Add -# --skip_init option to rigctl to skip rig initialization -- useful for executing commands quickly + * rig_caps is no longer constant -- this may break some 3rd party relying on the "const" declaration. Here's an example of how to handle compatiblity. +#ifdef RIGCAPS_NOT_CONST +static int add_to_list(struct rig_caps* rc, void*) +#else +static int add_to_list(const struct rig_caps* rc, void*) +#endif + + * IC7610 now has IPP, DPP, and TX_INHIBIT functions set/get * Hamlib now starts a multicast server that sends out rig information. Does not receive commands yet. See README.multicast 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/bindings/csharp/hamlibgui/MainWindow.cs b/bindings/csharp/hamlibgui/MainWindow.cs deleted file mode 100644 index 827011930..000000000 --- a/bindings/csharp/hamlibgui/MainWindow.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using Gtk; -using UI = Gtk.Builder.ObjectAttribute; - -namespace hamlibgui -{ -class MainWindow : Window -{ - [UI] private Label _label1 = null; - [UI] private Button _button1 = null; - - private bool connectFlag; - - public MainWindow() : this(new Builder("MainWindow.glade")) { } - - private MainWindow(Builder builder) : base( - builder.GetRawOwnedObject("MainWindow")) - { - builder.Autoconnect(this); - - DeleteEvent += Window_DeleteEvent; - _button1.Clicked += Button1_Clicked; - } - - private void Window_DeleteEvent(object sender, DeleteEventArgs a) - { - Application.Quit(); - } - - private void Button1_Clicked(object sender, EventArgs a) - { - connectFlag = !connectFlag; - - if (connectFlag) - { - String mytext = "Rig Connected (not really)"; - _label1.Text = mytext; - _button1.Label = "Disconnect Rig"; - } - else - { - String mytext = "Rig not Connected "; - _label1.Text = mytext; - _button1.Label = "Connect to Rig"; - } - } -} -} diff --git a/bindings/csharp/hamlibgui/MainWindow.glade b/bindings/csharp/hamlibgui/MainWindow.glade deleted file mode 100755 index abc5b731a..000000000 --- a/bindings/csharp/hamlibgui/MainWindow.glade +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - False - Hamlib Control - 480 - 240 - - - True - False - 4 - 4 - 4 - 4 - vertical - - - True - False - Hamlib controller to go here - - - True - True - 0 - - - - - Connect to Rig - True - False - True - Click to connect/disconnect rig - - - False - True - 1 - - - - - - diff --git a/bindings/csharp/hamlibgui/Program.cs b/bindings/csharp/hamlibgui/Program.cs deleted file mode 100755 index 1bad8e7a9..000000000 --- a/bindings/csharp/hamlibgui/Program.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using Gtk; - -namespace hamlibgui -{ - class Program - { - [STAThread] - public static void Main(string[] args) - { - Application.Init(); - - var app = new Application("org.hamlibgui.hamlibgui", GLib.ApplicationFlags.None); - app.Register(GLib.Cancellable.Current); - - var win = new MainWindow(); - app.AddWindow(win); - - win.Show(); - Application.Run(); - } - } -} diff --git a/bindings/csharp/hamlibgui/README.txt b/bindings/csharp/hamlibgui/README.txt deleted file mode 100644 index 9d01e25fd..000000000 --- a/bindings/csharp/hamlibgui/README.txt +++ /dev/null @@ -1,18 +0,0 @@ -This is a test of creating a portable Hamlib GUI controller using dotnet and GTK -Should be able to compile on Windows, Linux, and MacOS -No guarantee this will go anywhere depending on ability to talk to Hamlib via C# - -On Windows -dotnet new install GtkSharp.Template.CSharp -dotnet build - - - - -On Ubuntu I don't see the GtkSharp package -- but you can build the code generated on the Windows side. -apt install dotnet-sdk-6.0 -dotnet build - - -Note: On Windows you can create a skeleton GTK app -dotnet new gtkapp diff --git a/bindings/csharp/hamlibgui/hamlibgui.csproj b/bindings/csharp/hamlibgui/hamlibgui.csproj deleted file mode 100755 index 459dedc85..000000000 --- a/bindings/csharp/hamlibgui/hamlibgui.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - WinExe - net6.0 - - - - - - %(Filename)%(Extension) - - - - - - - - diff --git a/doc/man1/rigctl.1 b/doc/man1/rigctl.1 index 771051601..baf5b8fa8 100644 --- a/doc/man1/rigctl.1 +++ b/doc/man1/rigctl.1 @@ -81,8 +81,7 @@ Use .I device as the file name of the port connected to the radio. .IP -Often a serial port, but could be a USB to serial adapter. Typically -.IR /dev/ttyS0 ", " /dev/ttyS1 ", " /dev/ttyUSB0 , +Typically /dev/ttyS0 ", " /dev/ttyS1 ", " /dev/ttyUSB0 , etc. on Linux, .IR COM1 ", " COM2 , etc. on MS Windows. The BSD flavors and Mac OS/X have their own designations. @@ -1425,6 +1424,11 @@ Can also use 1,2,3,4 Reads GPIO1, GPIO2, GPIO3, GPIO4 on the GPIO ptt port Can also use 1,2,3,4 . +.TP +.BR skip_init +.EX +Skips rig initialization -- useful when executing commands with rigctl to speed up things +. .SH READLINE . If diff --git a/doc/man1/rigctld.1 b/doc/man1/rigctld.1 index 56b08109b..fa8277a4e 100644 --- a/doc/man1/rigctld.1 +++ b/doc/man1/rigctld.1 @@ -127,8 +127,7 @@ Use .I device as the file name of the port connected to the radio. .IP -Often a serial port, but could be a USB to serial adapter. Typically -.IR /dev/ttyS0 ", " /dev/ttyS1 ", " /dev/ttyUSB0 , +Typically /dev/ttyS0 ", " /dev/ttyS1 ", " /dev/ttyUSB0 , etc. on Linux, .IR COM1 ", " COM2 , etc. on MS Windows. The BSD flavors and Mac OS/X have their own designations. diff --git a/extra/gnuradio/gnuradio.h b/extra/gnuradio/gnuradio.h index c76aea712..a071b0906 100644 --- a/extra/gnuradio/gnuradio.h +++ b/extra/gnuradio/gnuradio.h @@ -61,10 +61,10 @@ int graudioiq_open(RIG *rig); extern const struct confparams gnuradio_cfg_params[]; -extern const struct rig_caps gr_caps; -extern const struct rig_caps mc4020_caps; -extern const struct rig_caps graudio_caps; -extern const struct rig_caps graudioiq_caps; +extern struct rig_caps gr_caps; +extern struct rig_caps mc4020_caps; +extern struct rig_caps graudio_caps; +extern struct rig_caps graudioiq_caps; __END_DECLS diff --git a/extra/gnuradio/gr.c b/extra/gnuradio/gr.c index d392d818b..3e73c87ae 100644 --- a/extra/gnuradio/gr.c +++ b/extra/gnuradio/gr.c @@ -49,7 +49,7 @@ static const struct gnuradio_priv_caps gr_priv_caps = .IF_center_freq = MHz(5.75), }; -const struct rig_caps gr_caps = +struct rig_caps gr_caps = { .rig_model = RIG_MODEL_GNURADIO, .model_name = "GNU Radio dev", diff --git a/extra/gnuradio/graudio.c b/extra/gnuradio/graudio.c index d033d0d56..5cbf75d43 100644 --- a/extra/gnuradio/graudio.c +++ b/extra/gnuradio/graudio.c @@ -52,7 +52,7 @@ static const struct gnuradio_priv_caps graudio_priv_caps = }; -const struct rig_caps graudio_caps = +struct rig_caps graudio_caps = { .rig_model = RIG_MODEL_GRAUDIO, .model_name = "GNU Radio GrAudio", @@ -126,7 +126,7 @@ const struct rig_caps graudio_caps = .vfo_op = gnuradio_vfo_op, }; -const struct rig_caps graudioiq_caps = +struct rig_caps graudioiq_caps = { .rig_model = RIG_MODEL_GRAUDIOIQ, .model_name = "GNU Radio GrAudio I&Q", diff --git a/extra/gnuradio/mc4020.c b/extra/gnuradio/mc4020.c index 93a069bd5..eee1e3d61 100644 --- a/extra/gnuradio/mc4020.c +++ b/extra/gnuradio/mc4020.c @@ -49,7 +49,7 @@ static const struct gnuradio_priv_caps mc4020_priv_caps = }; -const struct rig_caps mc4020_caps = +struct rig_caps mc4020_caps = { .rig_model = RIG_MODEL_MC4020, .model_name = "GNU Radio MC4020", diff --git a/include/hamlib/rig.h b/include/hamlib/rig.h index baa97b536..9f88d520a 100644 --- a/include/hamlib/rig.h +++ b/include/hamlib/rig.h @@ -24,6 +24,10 @@ #ifndef _RIG_H #define _RIG_H 1 +// as of 2023-11-23 rig_caps is no longer constant +// this #define allows clients to test which declaration to use for backwards compatibility +#define RIGCAPS_NOT_CONST 1 + #define BUILTINFUNC 0 // Our shared secret password @@ -152,6 +156,7 @@ typedef struct // cookie is 26-char time code plus 10-char (2^31-1) random number #define HAMLIB_COOKIE_SIZE 37 extern int cookie_use; // this is global as once one client requests it everybody needs to honor it +extern int skip_init; // allow rigctl to skip any radio commands at startup //! @cond Doxygen_Suppress extern HAMLIB_EXPORT_VAR(const char) hamlib_version[]; @@ -287,6 +292,8 @@ typedef unsigned int tone_t; /** * \brief Port type + * + * Note: All rigs may use a network:port address ( e.g. tcp/serial adapter) */ typedef enum rig_port_e { RIG_PORT_NONE = 0, /*!< No port */ @@ -1642,7 +1649,9 @@ typedef enum { RIG_MTYPE_MEMOPAD, /*!< Memory pad */ RIG_MTYPE_SAT, /*!< Satellite */ RIG_MTYPE_BAND, /*!< VFO/Band channel */ - RIG_MTYPE_PRIO /*!< Priority channel */ + RIG_MTYPE_PRIO, /*!< Priority channel */ + RIG_MTYPE_VOICE, /*!< Stored Voice Message */ + RIG_MTYPE_MORSE /*!< Morse Message */ } chan_type_t; @@ -2381,7 +2390,7 @@ typedef struct hamlib_port { int fd_sync_error_read; /*!< file descriptor for reading synchronous data error codes */ #endif short timeout_retry; /*!< number of retries to make in case of read timeout errors, some serial interfaces may require this, 0 to disable */ - int post_ptt_delay; /*!< delay after PTT to allow for relays and such */ +// DO NOT ADD ANYTHING HERE UNTIL 5.0!! } hamlib_port_t; @@ -2779,6 +2788,9 @@ struct rig_state { void *multicast_receiver_priv_data; rig_comm_status_t comm_status; /*!< Detailed rig control status */ char device_id[HAMLIB_RIGNAMSIZ]; + int dual_watch; /*!< Boolean DUAL_WATCH status */ + int post_ptt_delay; /*!< delay after PTT to allow for relays and such */ +// New rig_state items go before this line ============================================ }; /** @@ -2791,7 +2803,7 @@ struct rig_state { * It is NOT fine to touch this struct AT ALL!!! */ struct rig_state_deprecated { - /********* ENSURE YOU DO NOT EVERY MODIFY THIS STRUCTURE *********/ + /********* ENSURE YOU DO NOT EVER MODIFY THIS STRUCTURE *********/ /********* It will remain forever to provide DLL backwards compatiblity ******/ /* * overridable fields @@ -3592,7 +3604,7 @@ rig_set_uplink HAMLIB_PARAMS((RIG *rig, extern HAMLIB_EXPORT(const char *) rig_get_info HAMLIB_PARAMS((RIG *rig)); -extern HAMLIB_EXPORT(const struct rig_caps *) +extern HAMLIB_EXPORT(struct rig_caps *) rig_get_caps HAMLIB_PARAMS((rig_model_t rig_model)); extern HAMLIB_EXPORT(const freq_range_t *) @@ -3673,13 +3685,13 @@ extern HAMLIB_EXPORT(FILE *) rig_set_debug_file HAMLIB_PARAMS((FILE *stream)); extern HAMLIB_EXPORT(int) -rig_register HAMLIB_PARAMS((const struct rig_caps *caps)); +rig_register HAMLIB_PARAMS((struct rig_caps *caps)); extern HAMLIB_EXPORT(int) rig_unregister HAMLIB_PARAMS((rig_model_t rig_model)); extern HAMLIB_EXPORT(int) -rig_list_foreach HAMLIB_PARAMS((int (*cfunc)(const struct rig_caps *, rig_ptr_t), +rig_list_foreach HAMLIB_PARAMS((int (*cfunc)(struct rig_caps *, rig_ptr_t), rig_ptr_t data)); extern HAMLIB_EXPORT(int) diff --git a/include/hamlib/rigclass.h b/include/hamlib/rigclass.h index 2ae21403b..e65f839ea 100644 --- a/include/hamlib/rigclass.h +++ b/include/hamlib/rigclass.h @@ -46,7 +46,7 @@ public: #endif - const struct rig_caps *caps; + struct rig_caps *caps; // This method opens the communication port to the rig void open(void); 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/adat/adat.h b/rigs/adat/adat.h index 542559e21..8a69f5848 100644 --- a/rigs/adat/adat.h +++ b/rigs/adat/adat.h @@ -610,7 +610,7 @@ int adat_power2mW(RIG *, unsigned int *, float, freq_t, rmode_t); int adat_get_powerstat(RIG *, powerstat_t *); -extern const struct rig_caps adt_200a_caps; +extern struct rig_caps adt_200a_caps; // --------------------------------------------------------------------------- // END OF FILE diff --git a/rigs/adat/adt_200a.c b/rigs/adat/adt_200a.c index 9ce965e0b..5b12c593c 100644 --- a/rigs/adat/adt_200a.c +++ b/rigs/adat/adt_200a.c @@ -48,7 +48,7 @@ // ADT-200A HAMLIB CAPS / DESCRIPTION // --------------------------------------------------------------------------- -const struct rig_caps adt_200a_caps = +struct rig_caps adt_200a_caps = { RIG_MODEL(RIG_MODEL_ADT_200A), .model_name = "ADT-200A", diff --git a/rigs/alinco/alinco.h b/rigs/alinco/alinco.h index 14bbc628d..42294e51e 100644 --- a/rigs/alinco/alinco.h +++ b/rigs/alinco/alinco.h @@ -26,8 +26,8 @@ #define BACKEND_VER "20200323" -extern const struct rig_caps dx77_caps; -extern const struct rig_caps dxsr8_caps; +extern struct rig_caps dx77_caps; +extern struct rig_caps dxsr8_caps; #define BUFSZ 32 diff --git a/rigs/alinco/dx77.c b/rigs/alinco/dx77.c index 75287f59f..133dc8cfd 100644 --- a/rigs/alinco/dx77.c +++ b/rigs/alinco/dx77.c @@ -150,7 +150,7 @@ int dx77_get_mem(RIG *rig, vfo_t vfo, int *ch); * - up/down * - scan */ -const struct rig_caps dx77_caps = +struct rig_caps dx77_caps = { RIG_MODEL(RIG_MODEL_DX77), .model_name = "DX-77", @@ -1260,7 +1260,7 @@ int dx77_set_parm(RIG *rig, setting_t parm, value_t val) */ int dx77_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) { - const struct rig_caps *caps; + struct rig_caps *caps; unsigned char tonebuf[BUFSZ]; int i; diff --git a/rigs/alinco/dxsr8.c b/rigs/alinco/dxsr8.c index b6e6dd57d..ad774fc7d 100644 --- a/rigs/alinco/dxsr8.c +++ b/rigs/alinco/dxsr8.c @@ -75,7 +75,7 @@ int dxsr8_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt); * https://yo5ptd.wordpress.com/2017/02/12/alinco-dx-sr8/ * for a partially documented protocol */ -const struct rig_caps dxsr8_caps = +struct rig_caps dxsr8_caps = { RIG_MODEL(RIG_MODEL_DXSR8), .model_name = "DX-SR8", 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/anytone/anytone.h b/rigs/anytone/anytone.h index bca5a4e77..d8ca681dc 100644 --- a/rigs/anytone/anytone.h +++ b/rigs/anytone/anytone.h @@ -7,7 +7,7 @@ #define ANYTONE_RESPSZ 64 -extern const struct rig_caps anytone_d578_caps; +extern struct rig_caps anytone_d578_caps; #ifdef PTHREAD #include diff --git a/rigs/anytone/d578.c b/rigs/anytone/d578.c index 2493e8ab5..cf7ec4214 100644 --- a/rigs/anytone/d578.c +++ b/rigs/anytone/d578.c @@ -26,7 +26,7 @@ #define D578_VFO (RIG_VFO_A|RIG_VFO_B) #define D578_MODES (RIG_MODE_USB|RIG_MODE_AM) -const struct rig_caps anytone_d578_caps = +struct rig_caps anytone_d578_caps = { RIG_MODEL(RIG_MODEL_ATD578UVIII), .model_name = "D578A", diff --git a/rigs/aor/aor.h b/rigs/aor/aor.h index d11556d3a..9b0da4c31 100644 --- a/rigs/aor/aor.h +++ b/rigs/aor/aor.h @@ -64,16 +64,16 @@ int aor_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only); int aor_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan); int aor_get_chan_all_cb (RIG * rig, vfo_t vfo, chan_cb_t chan_cb, rig_ptr_t); -extern const struct rig_caps ar2700_caps; -extern const struct rig_caps ar8200_caps; -extern const struct rig_caps ar8000_caps; -extern const struct rig_caps ar8600_caps; -extern const struct rig_caps ar5000_caps; -extern const struct rig_caps ar3000a_caps; -extern const struct rig_caps ar7030_caps; -extern const struct rig_caps ar3030_caps; -extern const struct rig_caps ar5000a_caps; -extern const struct rig_caps ar7030p_caps; -extern const struct rig_caps sr2200_caps; +extern struct rig_caps ar2700_caps; +extern struct rig_caps ar8200_caps; +extern struct rig_caps ar8000_caps; +extern struct rig_caps ar8600_caps; +extern struct rig_caps ar5000_caps; +extern struct rig_caps ar3000a_caps; +extern struct rig_caps ar7030_caps; +extern struct rig_caps ar3030_caps; +extern struct rig_caps ar5000a_caps; +extern struct rig_caps ar7030p_caps; +extern struct rig_caps sr2200_caps; #endif /* _AOR_H */ diff --git a/rigs/aor/ar2700.c b/rigs/aor/ar2700.c index 9b57a3bd3..161ee0ebe 100644 --- a/rigs/aor/ar2700.c +++ b/rigs/aor/ar2700.c @@ -80,7 +80,7 @@ static const struct aor_priv_caps ar2700_priv_caps = * part of info from http://www.aoruk.com/2700.htm * Interface unit: CU-8232 (or equivalent) */ -const struct rig_caps ar2700_caps = +struct rig_caps ar2700_caps = { RIG_MODEL(RIG_MODEL_AR2700), .model_name = "AR2700", diff --git a/rigs/aor/ar3000.c b/rigs/aor/ar3000.c index 1954d4b28..806be82dc 100644 --- a/rigs/aor/ar3000.c +++ b/rigs/aor/ar3000.c @@ -62,7 +62,7 @@ static int ar3k_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); * TODO: * set_channel, get_channel, set_func MUTE,SQL, get_dcd, ... */ -const struct rig_caps ar3000a_caps = +struct rig_caps ar3000a_caps = { RIG_MODEL(RIG_MODEL_AR3000A), .model_name = "AR3000A", diff --git a/rigs/aor/ar3030.c b/rigs/aor/ar3030.c index b21cf4259..ded41f433 100644 --- a/rigs/aor/ar3030.c +++ b/rigs/aor/ar3030.c @@ -93,7 +93,7 @@ struct ar3030_priv_data * * ar3030 rig capabilities. */ -const struct rig_caps ar3030_caps = +struct rig_caps ar3030_caps = { RIG_MODEL(RIG_MODEL_AR3030), .model_name = "AR3030", @@ -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/ar5000.c b/rigs/aor/ar5000.c index c010f5204..73a8ffd9c 100644 --- a/rigs/aor/ar5000.c +++ b/rigs/aor/ar5000.c @@ -99,7 +99,7 @@ static const struct aor_priv_caps ar5k_priv_caps = * * TODO: retrieve BW info, and rest of commands */ -const struct rig_caps ar5000_caps = +struct rig_caps ar5000_caps = { RIG_MODEL(RIG_MODEL_AR5000), .model_name = "AR5000", @@ -245,7 +245,7 @@ const struct rig_caps ar5000_caps = * * TODO: retrieve BW info, and rest of commands */ -const struct rig_caps ar5000a_caps = +struct rig_caps ar5000a_caps = { RIG_MODEL(RIG_MODEL_AR5000A), .model_name = "AR5000A", diff --git a/rigs/aor/ar7030.c b/rigs/aor/ar7030.c index cd4183a74..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 @@ -772,7 +773,7 @@ static int ar7030_reset(RIG *rig, reset_t reset) -const struct rig_caps ar7030_caps = +struct rig_caps ar7030_caps = { RIG_MODEL(RIG_MODEL_AR7030), .model_name = "AR7030", diff --git a/rigs/aor/ar7030p.c b/rigs/aor/ar7030p.c index b2b17dc1d..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++) { @@ -483,7 +483,7 @@ static int ar7030p_set_freq(RIG *rig, vfo_t vfo, freq_t freq) if (RIG_OK == rc) { - const struct rig_caps *caps = rig->caps; + struct rig_caps *caps = rig->caps; if ((caps->rx_range_list1[ 0 ].endf > freq) && (caps->rx_range_list1[ 0 ].startf < freq)) @@ -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); @@ -1770,7 +1773,7 @@ static int ar7030p_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, return (rc); } -const struct rig_caps ar7030p_caps = +struct rig_caps ar7030p_caps = { RIG_MODEL(RIG_MODEL_AR7030P), .model_name = "AR7030 Plus", diff --git a/rigs/aor/ar8000.c b/rigs/aor/ar8000.c index d2bccd95b..4cc825231 100644 --- a/rigs/aor/ar8000.c +++ b/rigs/aor/ar8000.c @@ -60,7 +60,7 @@ static const struct aor_priv_caps ar8000_priv_caps = * * part of info from http://www.aoruk.com/8000.htm */ -const struct rig_caps ar8000_caps = +struct rig_caps ar8000_caps = { RIG_MODEL(RIG_MODEL_AR8000), .model_name = "AR8000", diff --git a/rigs/aor/ar8200.c b/rigs/aor/ar8200.c index 9f8e99275..c1a640fd3 100644 --- a/rigs/aor/ar8200.c +++ b/rigs/aor/ar8200.c @@ -84,7 +84,7 @@ static const struct aor_priv_caps ar8k_priv_caps = * * part of info from http://www.aoruk.com/8200.htm */ -const struct rig_caps ar8200_caps = +struct rig_caps ar8200_caps = { RIG_MODEL(RIG_MODEL_AR8200), .model_name = "AR8200", diff --git a/rigs/aor/ar8600.c b/rigs/aor/ar8600.c index da81b881b..20b2a018f 100644 --- a/rigs/aor/ar8600.c +++ b/rigs/aor/ar8600.c @@ -86,7 +86,7 @@ static const struct aor_priv_caps ar8600_priv_caps = * * part of info from http://www.aoruk.com/8600.htm */ -const struct rig_caps ar8600_caps = +struct rig_caps ar8600_caps = { RIG_MODEL(RIG_MODEL_AR8600), .model_name = "AR8600", diff --git a/rigs/aor/sr2200.c b/rigs/aor/sr2200.c index e8b081fa5..25a3c988c 100644 --- a/rigs/aor/sr2200.c +++ b/rigs/aor/sr2200.c @@ -119,7 +119,7 @@ static const struct aor_priv_caps sr2200_priv_caps = * * TODO: retrieve BW info, and rest of commands */ -const struct rig_caps sr2200_caps = +struct rig_caps sr2200_caps = { RIG_MODEL(RIG_MODEL_SR2200), .model_name = "SR2200", diff --git a/rigs/barrett/4050.c b/rigs/barrett/4050.c index 24ea62ebb..6bd44ef56 100644 --- a/rigs/barrett/4050.c +++ b/rigs/barrett/4050.c @@ -94,7 +94,7 @@ static int barrett4050_open(RIG *rig) RETURNFUNC(RIG_OK); } -const struct rig_caps barrett4050_caps = +struct rig_caps barrett4050_caps = { RIG_MODEL(RIG_MODEL_BARRETT_4050), .model_name = "4050", diff --git a/rigs/barrett/950.c b/rigs/barrett/950.c index 250b7966d..1c6e40045 100644 --- a/rigs/barrett/950.c +++ b/rigs/barrett/950.c @@ -66,7 +66,7 @@ static struct chan_map_s chan_map[] = { 28.0, 30.0, 9} }; -const struct rig_caps barrett950_caps = +struct rig_caps barrett950_caps = { RIG_MODEL(RIG_MODEL_BARRETT_950), .model_name = "950", @@ -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 40f930abe..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; } @@ -756,7 +759,7 @@ int barrett_open(RIG *rig) } -const struct rig_caps barrett_caps = +struct rig_caps barrett_caps = { RIG_MODEL(RIG_MODEL_BARRETT_2050), .model_name = "2050", diff --git a/rigs/barrett/barrett.h b/rigs/barrett/barrett.h index 5d5998048..633560593 100644 --- a/rigs/barrett/barrett.h +++ b/rigs/barrett/barrett.h @@ -36,9 +36,9 @@ // RET_LEN is # of max channels times the per-channel response length #define BARRETT_RET_LEN 24*1000 -extern const struct rig_caps barrett_caps; -extern const struct rig_caps barrett950_caps; -extern const struct rig_caps barrett4050_caps; +extern struct rig_caps barrett_caps; +extern struct rig_caps barrett950_caps; +extern struct rig_caps barrett4050_caps; struct barrett_priv_data { char cmd_str[BARRETT_DATA_LEN]; /* command string buffer */ diff --git a/rigs/codan/codan.c b/rigs/codan/codan.c index ba3eabf82..f419b61b9 100644 --- a/rigs/codan/codan.c +++ b/rigs/codan/codan.c @@ -410,7 +410,7 @@ int codan_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) -const struct rig_caps envoy_caps = +struct rig_caps envoy_caps = { RIG_MODEL(RIG_MODEL_CODAN_ENVOY), .model_name = "Envoy", @@ -475,7 +475,7 @@ const struct rig_caps envoy_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps ngs_caps = +struct rig_caps ngs_caps = { RIG_MODEL(RIG_MODEL_CODAN_NGT), .model_name = "NGT", diff --git a/rigs/codan/codan.h b/rigs/codan/codan.h index a3af29dbc..cd02ac1c0 100644 --- a/rigs/codan/codan.h +++ b/rigs/codan/codan.h @@ -34,8 +34,8 @@ // But that would 9999*41 or 406KB so didn't do that right now #define CODAN_DATA_LEN 64 -extern const struct rig_caps envoy_caps; -extern const struct rig_caps ngs_caps; +extern struct rig_caps envoy_caps; +extern struct rig_caps ngs_caps; struct codan_priv_data { char cmd_str[CODAN_DATA_LEN]; /* command string buffer */ diff --git a/rigs/dorji/dorji.h b/rigs/dorji/dorji.h index 001620660..86482881d 100644 --- a/rigs/dorji/dorji.h +++ b/rigs/dorji/dorji.h @@ -24,7 +24,7 @@ #include "hamlib/rig.h" -extern const struct rig_caps dra818u_caps; -extern const struct rig_caps dra818v_caps; +extern struct rig_caps dra818u_caps; +extern struct rig_caps dra818v_caps; #endif /* _DORJI_H */ diff --git a/rigs/dorji/dra818.c b/rigs/dorji/dra818.c index a856a5fab..df1106122 100644 --- a/rigs/dorji/dra818.c +++ b/rigs/dorji/dra818.c @@ -519,7 +519,7 @@ int dra818_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) return RIG_OK; } -const struct rig_caps dra818u_caps = +struct rig_caps dra818u_caps = { RIG_MODEL(RIG_MODEL_DORJI_DRA818U), .model_name = "DRA818U", @@ -623,7 +623,7 @@ const struct rig_caps dra818u_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps dra818v_caps = +struct rig_caps dra818v_caps = { RIG_MODEL(RIG_MODEL_DORJI_DRA818V), .model_name = "DRA818V", diff --git a/rigs/drake/drake.h b/rigs/drake/drake.h index f6f9d1d26..58e404933 100644 --- a/rigs/drake/drake.h +++ b/rigs/drake/drake.h @@ -53,8 +53,8 @@ int drake_set_powerstat (RIG * rig, powerstat_t status); int drake_get_powerstat (RIG * rig, powerstat_t *status); const char *drake_get_info(RIG *rig); -extern const struct rig_caps r8a_caps; -extern const struct rig_caps r8b_caps; +extern struct rig_caps r8a_caps; +extern struct rig_caps r8b_caps; #endif /* _DRAKE_H */ diff --git a/rigs/drake/r8a.c b/rigs/drake/r8a.c index 0980362b6..87475a968 100644 --- a/rigs/drake/r8a.c +++ b/rigs/drake/r8a.c @@ -78,7 +78,7 @@ * */ -const struct rig_caps r8a_caps = +struct rig_caps r8a_caps = { RIG_MODEL(RIG_MODEL_DKR8A), .model_name = "R-8A", diff --git a/rigs/drake/r8b.c b/rigs/drake/r8b.c index e114cf5ea..11fa4f1fe 100644 --- a/rigs/drake/r8b.c +++ b/rigs/drake/r8b.c @@ -78,7 +78,7 @@ * */ -const struct rig_caps r8b_caps = +struct rig_caps r8b_caps = { RIG_MODEL(RIG_MODEL_DKR8B), .model_name = "R-8B", diff --git a/rigs/dummy/aclog.c b/rigs/dummy/aclog.c index 5384037f7..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), @@ -933,7 +935,7 @@ static int aclog_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) } -const struct rig_caps aclog_caps = +struct rig_caps aclog_caps = { RIG_MODEL(RIG_MODEL_ACLOG), .model_name = "ACLog", 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 7e635dfdb..fe54e696a 100644 --- a/rigs/dummy/dummy.c +++ b/rigs/dummy/dummy.c @@ -451,7 +451,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); @@ -1613,9 +1615,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 { @@ -2382,10 +2385,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/dummy.h b/rigs/dummy/dummy.h index 919712188..bf269ea61 100644 --- a/rigs/dummy/dummy.h +++ b/rigs/dummy/dummy.h @@ -42,11 +42,11 @@ extern struct rig_caps dummy_caps; extern struct rig_caps dummy_no_vfo_caps; extern struct rig_caps netrigctl_caps; -extern const struct rig_caps flrig_caps; -extern const struct rig_caps trxmanager_caps; -extern const struct rig_caps tci1x_caps; -extern const struct rig_caps aclog_caps; -extern const struct rig_caps sdrsharp_caps; +extern struct rig_caps flrig_caps; +extern struct rig_caps trxmanager_caps; +extern struct rig_caps tci1x_caps; +extern struct rig_caps aclog_caps; +extern struct rig_caps sdrsharp_caps; extern struct rig_caps quisk_caps; int netrigctl_get_vfo_mode(RIG *); diff --git a/rigs/dummy/flrig.c b/rigs/dummy/flrig.c index ef2160bce..f3c02ea3a 100644 --- a/rigs/dummy/flrig.c +++ b/rigs/dummy/flrig.c @@ -50,7 +50,7 @@ RIG_MODE_PKTLSB | RIG_MODE_PKTUSB |\ RIG_MODE_SSB | RIG_MODE_LSB | RIG_MODE_USB |\ RIG_MODE_FM | RIG_MODE_WFM | RIG_MODE_FMN | RIG_MODE_PKTFM |\ - RIG_MODE_C4FM) + RIG_MODE_C4FM | RIG_MODE_DSTAR) #define FLRIG_LEVELS (RIG_LEVEL_AF | RIG_LEVEL_RF | RIG_LEVEL_MICGAIN | RIG_LEVEL_STRENGTH | RIG_LEVEL_RFPOWER_METER | RIG_LEVEL_RFPOWER_METER_WATTS | RIG_LEVEL_RFPOWER | RIG_LEVEL_SWR) @@ -138,12 +138,12 @@ static const struct confparams flrig_ext_parms[] = { RIG_CONF_END, NULL, } }; -const struct rig_caps flrig_caps = +struct rig_caps flrig_caps = { RIG_MODEL(RIG_MODEL_FLRIG), .model_name = "FLRig", .mfg_name = "FLRig", - .version = "20231113.0", + .version = "20231216.0", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -242,6 +242,7 @@ static struct s_modeMap modeMap[] = {RIG_MODE_RTTY, NULL}, {RIG_MODE_RTTYR, NULL}, {RIG_MODE_C4FM, NULL}, + {RIG_MODE_DSTAR, NULL}, {0, NULL} }; @@ -894,11 +895,15 @@ static int flrig_open(RIG *rig) /* see if get_bwA is available */ retval = flrig_transaction(rig, "rig.get_bwA", NULL, value, sizeof(value)); + int dummy; - if (retval == RIG_ENAVAIL) // 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 + priv->has_set_bwA = 0; // and we don't have set functions either + priv->has_set_bwB = 0; rig_debug(RIG_DEBUG_VERBOSE, "%s: get_bwA/B is not available=%s\n", __func__, value); } @@ -1088,6 +1093,7 @@ static int flrig_open(RIG *rig) else if (streq(p, "UCW")) { modeMapAdd(&modes, RIG_MODE_CW, p); } else if (streq(p, "C4FM")) { modeMapAdd(&modes, RIG_MODE_C4FM, p); } else if (streq(p, "SPEC")) { modeMapAdd(&modes, RIG_MODE_SPEC, p); } + else if (streq(p, "DV")) { modeMapAdd(&modes, RIG_MODE_DSTAR, p); } else if (streq(p, "DRM")) // we don't support DRM yet (or maybe ever) { rig_debug(RIG_DEBUG_VERBOSE, "%s: no mapping for mode %s\n", __func__, p); @@ -1209,6 +1215,9 @@ static int flrig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) *freq = atof(value); + +#if 0 // zero is actually valid for PowerSDR + if (*freq == 0) { rig_debug(RIG_DEBUG_ERR, "%s: freq==0??\nvalue=%s\n", __func__, @@ -1216,6 +1225,7 @@ static int flrig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) RETURNFUNC(-RIG_EPROTO); } else +#endif { rig_debug(RIG_DEBUG_TRACE, "%s: freq=%.0f\n", __func__, *freq); } @@ -1750,14 +1760,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); } @@ -1767,7 +1778,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; @@ -2515,8 +2527,8 @@ HAMLIB_EXPORT(int) flrig_cat_string(RIG *rig, const char *arg) return retval; } -HAMLIB_EXPORT(int) flrig_set_func(RIG *rig, vfo_t vfo, setting_t func, - int status) +int flrig_set_func(RIG *rig, vfo_t vfo, setting_t func, + int status) { int retval; char cmd_arg[MAXARGLEN]; diff --git a/rigs/dummy/flrig.h b/rigs/dummy/flrig.h index 0e297944b..520143df5 100644 --- a/rigs/dummy/flrig.h +++ b/rigs/dummy/flrig.h @@ -28,6 +28,6 @@ #define TRUE 1 #define FALSE 0 -extern const struct rig_caps flrig_caps; +extern struct rig_caps flrig_caps; #endif /* _FLRIG_H */ 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 dea95497f..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); @@ -519,7 +521,7 @@ static int sdrsharp_get_vfo(RIG *rig, vfo_t *vfo) RETURNFUNC(RIG_OK); } -const struct rig_caps sdrsharp_caps = +struct rig_caps sdrsharp_caps = { RIG_MODEL(RIG_MODEL_SDRSHARP), .model_name = "SDR#/gpredict", diff --git a/rigs/dummy/tci1x.c b/rigs/dummy/tci1x.c index 409c1d5a1..86284fbe1 100644 --- a/rigs/dummy/tci1x.c +++ b/rigs/dummy/tci1x.c @@ -132,7 +132,7 @@ static const struct confparams tci1x_ext_parms[] = { RIG_CONF_END, NULL, } }; -const struct rig_caps tci1x_caps = +struct rig_caps tci1x_caps = { RIG_MODEL(RIG_MODEL_TCI1X), .model_name = "TCI1.X", 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 30832b79f..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; @@ -2468,7 +2471,7 @@ int elad_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) */ int elad_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) { - const struct rig_caps *caps; + struct rig_caps *caps; char tonebuf[16]; int i; @@ -2498,7 +2501,7 @@ int elad_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) int elad_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) { - const struct rig_caps *caps = rig->caps; + struct rig_caps *caps = rig->caps; char buf[16]; int i; @@ -2560,7 +2563,7 @@ int elad_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) int elad_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) { const struct elad_priv_data *priv = rig->state.priv; - const struct rig_caps *caps; + struct rig_caps *caps; char tonebuf[3]; int i, retval; unsigned int tone_idx; @@ -2637,7 +2640,7 @@ int elad_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) int elad_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) { - const struct rig_caps *caps = rig->caps; + struct rig_caps *caps = rig->caps; char buf[16]; int i; @@ -2693,7 +2696,7 @@ int elad_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) int elad_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) { - const struct rig_caps *caps; + struct rig_caps *caps; char cmd[4]; char tonebuf[6]; int offs; diff --git a/rigs/elad/elad.h b/rigs/elad/elad.h index 39cac3627..aa689cc5d 100644 --- a/rigs/elad/elad.h +++ b/rigs/elad/elad.h @@ -164,7 +164,7 @@ int elad_get_trn(RIG *rig, int *trn); int get_elad_level(RIG *rig, const char *cmd, float *f); int get_elad_func(RIG *rig, const char *cmd, int *status); -extern const struct rig_caps fdm_duo_caps; +extern struct rig_caps fdm_duo_caps; #if 0 /* use when not interested in the answer, but want to check its len */ diff --git a/rigs/elad/fdm_duo.c b/rigs/elad/fdm_duo.c index db60fcc71..bb077b994 100644 --- a/rigs/elad/fdm_duo.c +++ b/rigs/elad/fdm_duo.c @@ -328,7 +328,7 @@ static struct elad_priv_caps fdm_duo_priv_caps = * Notice that some rigs share the same functions. * Also this struct is READONLY! */ -const struct rig_caps fdm_duo_caps = +struct rig_caps fdm_duo_caps = { RIG_MODEL(RIG_MODEL_ELAD_FDM_DUO), .model_name = "FDM-DUO", diff --git a/rigs/flexradio/dttsp.c b/rigs/flexradio/dttsp.c index 0e03f2dfa..748e43a18 100644 --- a/rigs/flexradio/dttsp.c +++ b/rigs/flexradio/dttsp.c @@ -155,7 +155,7 @@ static const struct hamlib_vs_dttsp { 50, 40 }, /* +40 */ \ } } -const struct rig_caps dttsp_rig_caps = +struct rig_caps dttsp_rig_caps = { RIG_MODEL(RIG_MODEL_DTTSP), .model_name = "DttSP IPC", @@ -241,7 +241,7 @@ const struct rig_caps dttsp_rig_caps = /* * The same as the previous IPC, but of type RIG_PORT_UDP_NETWORK */ -const struct rig_caps dttsp_udp_rig_caps = +struct rig_caps dttsp_udp_rig_caps = { RIG_MODEL(RIG_MODEL_DTTSP_UDP), .model_name = "DttSP UDP", diff --git a/rigs/flexradio/flexradio.h b/rigs/flexradio/flexradio.h index 446b3feb6..dd666605e 100644 --- a/rigs/flexradio/flexradio.h +++ b/rigs/flexradio/flexradio.h @@ -24,9 +24,9 @@ #include "hamlib/rig.h" -extern const struct rig_caps sdr1k_rig_caps; -extern const struct rig_caps sdr1krfe_rig_caps; -extern const struct rig_caps dttsp_rig_caps; -extern const struct rig_caps dttsp_udp_rig_caps; +extern struct rig_caps sdr1k_rig_caps; +extern struct rig_caps sdr1krfe_rig_caps; +extern struct rig_caps dttsp_rig_caps; +extern struct rig_caps dttsp_udp_rig_caps; #endif /* _FLEXRADIO_H */ diff --git a/rigs/flexradio/sdr1k.c b/rigs/flexradio/sdr1k.c index 86bb8fdda..c644e52dd 100644 --- a/rigs/flexradio/sdr1k.c +++ b/rigs/flexradio/sdr1k.c @@ -110,7 +110,7 @@ struct sdr1k_priv_data * What about IOUD_Clock? */ -const struct rig_caps sdr1k_rig_caps = +struct rig_caps sdr1k_rig_caps = { RIG_MODEL(RIG_MODEL_SDR1000), .model_name = "SDR-1000", 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/gomspace/gs100.h b/rigs/gomspace/gs100.h index 2372499c1..6bd5f3be3 100644 --- a/rigs/gomspace/gs100.h +++ b/rigs/gomspace/gs100.h @@ -47,8 +47,8 @@ /* RIG capabilities descriptions */ extern struct rig_caps gs100_caps; extern struct rig_caps netrigctl_caps; -extern const struct rig_caps flrig_caps; -extern const struct rig_caps trxmanager_caps; +extern struct rig_caps flrig_caps; +extern struct rig_caps trxmanager_caps; /*----------------------------------------------------------------------------*/ diff --git a/rigs/icmarine/icm700pro.c b/rigs/icmarine/icm700pro.c index d8b5a6304..681ea4785 100644 --- a/rigs/icmarine/icm700pro.c +++ b/rigs/icmarine/icm700pro.c @@ -49,7 +49,7 @@ static const struct icmarine_priv_caps icm700pro_priv_caps = .default_remote_id = 2, }; -const struct rig_caps icm700pro_caps = +struct rig_caps icm700pro_caps = { RIG_MODEL(RIG_MODEL_IC_M700PRO), .model_name = "IC-M700PRO", diff --git a/rigs/icmarine/icm710.c b/rigs/icmarine/icm710.c index f576c4c17..88587c71f 100644 --- a/rigs/icmarine/icm710.c +++ b/rigs/icmarine/icm710.c @@ -57,7 +57,7 @@ static const struct icm710_priv_caps icm710_priv_caps = }; -const struct rig_caps icm710_caps = +struct rig_caps icm710_caps = { RIG_MODEL(RIG_MODEL_IC_M710), .model_name = "IC-M710", @@ -251,7 +251,7 @@ int icm710_init(RIG *rig) { struct icm710_priv_data *priv; const struct icm710_priv_caps *priv_caps; - const struct rig_caps *caps; + struct rig_caps *caps; if (!rig || !rig->caps) { diff --git a/rigs/icmarine/icm710.h b/rigs/icmarine/icm710.h index edda6e455..73efd3ffb 100644 --- a/rigs/icmarine/icm710.h +++ b/rigs/icmarine/icm710.h @@ -75,8 +75,8 @@ int icm710_set_conf(RIG *rig, token_t token, const char *val); int icm710_get_conf(RIG *rig, token_t token, char *val); int icm710_get_conf2(RIG *rig, token_t token, char *val, int val_len); -extern const struct rig_caps icm700pro_caps; -extern const struct rig_caps icm710_caps; -extern const struct rig_caps icm802_caps; +extern struct rig_caps icm700pro_caps; +extern struct rig_caps icm710_caps; +extern struct rig_caps icm802_caps; #endif /* _ICM710_H */ diff --git a/rigs/icmarine/icm802.c b/rigs/icmarine/icm802.c index 9165a5b3e..c42957f3e 100644 --- a/rigs/icmarine/icm802.c +++ b/rigs/icmarine/icm802.c @@ -50,7 +50,7 @@ static const struct icmarine_priv_caps icm802_priv_caps = }; -const struct rig_caps icm802_caps = +struct rig_caps icm802_caps = { RIG_MODEL(RIG_MODEL_IC_M802), .model_name = "IC-M802", diff --git a/rigs/icmarine/icm803.c b/rigs/icmarine/icm803.c index b9d3d4f68..c1ef49564 100644 --- a/rigs/icmarine/icm803.c +++ b/rigs/icmarine/icm803.c @@ -50,7 +50,7 @@ static const struct icmarine_priv_caps icm803_priv_caps = }; -const struct rig_caps icm803_caps = +struct rig_caps icm803_caps = { RIG_MODEL(RIG_MODEL_IC_M803), .model_name = "IC-M803", diff --git a/rigs/icmarine/icmarine.c b/rigs/icmarine/icmarine.c index 6c7bc8eae..5cc804336 100644 --- a/rigs/icmarine/icmarine.c +++ b/rigs/icmarine/icmarine.c @@ -113,7 +113,7 @@ int icmarine_init(RIG *rig) { struct icmarine_priv_data *priv; const struct icmarine_priv_caps *priv_caps; - const struct rig_caps *caps; + struct rig_caps *caps; if (!rig || !rig->caps) { diff --git a/rigs/icmarine/icmarine.h b/rigs/icmarine/icmarine.h index 8508389de..a1c0415e0 100644 --- a/rigs/icmarine/icmarine.h +++ b/rigs/icmarine/icmarine.h @@ -65,9 +65,9 @@ int icmarine_set_conf(RIG *rig, token_t token, const char *val); int icmarine_get_conf(RIG *rig, token_t token, char *val); int icmarine_get_conf2(RIG *rig, token_t token, char *val, int val_len); -extern const struct rig_caps icm700pro_caps; -extern const struct rig_caps icm710_caps; -extern const struct rig_caps icm802_caps; -extern const struct rig_caps icm803_caps; +extern struct rig_caps icm700pro_caps; +extern struct rig_caps icm710_caps; +extern struct rig_caps icm802_caps; +extern struct rig_caps icm803_caps; #endif /* _ICMARINE_H */ diff --git a/rigs/icom/delta2.c b/rigs/icom/delta2.c index 349186cb2..ec43e8ab0 100644 --- a/rigs/icom/delta2.c +++ b/rigs/icom/delta2.c @@ -52,7 +52,7 @@ static const struct icom_priv_caps delta2_priv_caps = ic737_ts_sc_list /* TODO: ts_sc_list */ }; -const struct rig_caps delta2_caps = +struct rig_caps delta2_caps = { RIG_MODEL(RIG_MODEL_DELTAII), .model_name = "Delta II", 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/ic1275.c b/rigs/icom/ic1275.c index 3d991ae36..0e3ae6585 100644 --- a/rigs/icom/ic1275.c +++ b/rigs/icom/ic1275.c @@ -40,7 +40,7 @@ static const struct icom_priv_caps ic1275_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic1275_caps = +struct rig_caps ic1275_caps = { RIG_MODEL(RIG_MODEL_IC1275), .model_name = "IC-1275", diff --git a/rigs/icom/ic271.c b/rigs/icom/ic271.c index 26d7f4d99..dfa8d732a 100644 --- a/rigs/icom/ic271.c +++ b/rigs/icom/ic271.c @@ -49,7 +49,7 @@ static const struct icom_priv_caps ic271_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic271_caps = +struct rig_caps ic271_caps = { RIG_MODEL(RIG_MODEL_IC271), .model_name = "IC-271", diff --git a/rigs/icom/ic2730.c b/rigs/icom/ic2730.c index acec5bc32..16ed41b01 100644 --- a/rigs/icom/ic2730.c +++ b/rigs/icom/ic2730.c @@ -59,7 +59,7 @@ static const struct icom_priv_caps ic2730_priv_caps = 1, /* no XCHG */ }; -const struct rig_caps ic2730_caps = +struct rig_caps ic2730_caps = { RIG_MODEL(RIG_MODEL_IC2730), .model_name = "IC-2730", diff --git a/rigs/icom/ic275.c b/rigs/icom/ic275.c index 89a4c330a..372fcf349 100644 --- a/rigs/icom/ic275.c +++ b/rigs/icom/ic275.c @@ -52,7 +52,7 @@ static const struct icom_priv_caps ic375_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic275_caps = +struct rig_caps ic275_caps = { RIG_MODEL(RIG_MODEL_IC275), .model_name = "IC-275", @@ -151,7 +151,7 @@ const struct rig_caps ic275_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps ic375_caps = +struct rig_caps ic375_caps = { RIG_MODEL(RIG_MODEL_IC375), .model_name = "IC-375", diff --git a/rigs/icom/ic471.c b/rigs/icom/ic471.c index bd543b133..b1e1ec20c 100644 --- a/rigs/icom/ic471.c +++ b/rigs/icom/ic471.c @@ -48,7 +48,7 @@ static const struct icom_priv_caps ic471_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic471_caps = +struct rig_caps ic471_caps = { RIG_MODEL(RIG_MODEL_IC471), .model_name = "IC-471", diff --git a/rigs/icom/ic475.c b/rigs/icom/ic475.c index 83dfbe1d4..f07dd22e5 100644 --- a/rigs/icom/ic475.c +++ b/rigs/icom/ic475.c @@ -44,7 +44,7 @@ static const struct icom_priv_caps ic475_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic475_caps = +struct rig_caps ic475_caps = { RIG_MODEL(RIG_MODEL_IC475), .model_name = "IC-475", @@ -150,7 +150,7 @@ static const struct icom_priv_caps ic575_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic575_caps = +struct rig_caps ic575_caps = { RIG_MODEL(RIG_MODEL_IC575), .model_name = "IC-575", diff --git a/rigs/icom/ic7000.c b/rigs/icom/ic7000.c index 19304ddd8..780353345 100644 --- a/rigs/icom/ic7000.c +++ b/rigs/icom/ic7000.c @@ -190,7 +190,7 @@ static const struct icom_priv_caps IC7000_priv_caps = .r2i_mode = ic7000_r2i_mode }; -const struct rig_caps ic7000_caps = +struct rig_caps ic7000_caps = { RIG_MODEL(RIG_MODEL_IC7000), .model_name = "IC-7000", @@ -221,8 +221,6 @@ const struct rig_caps ic7000_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, diff --git a/rigs/icom/ic703.c b/rigs/icom/ic703.c index 56f1ff134..fa1f16d39 100644 --- a/rigs/icom/ic703.c +++ b/rigs/icom/ic703.c @@ -81,7 +81,7 @@ static const struct icom_priv_caps ic703_priv_caps = ic706_ts_sc_list }; -const struct rig_caps ic703_caps = +struct rig_caps ic703_caps = { RIG_MODEL(RIG_MODEL_IC703), .model_name = "IC-703", @@ -112,7 +112,6 @@ const struct rig_caps ic703_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .ctcss_list = common_ctcss_list, diff --git a/rigs/icom/ic706.c b/rigs/icom/ic706.c index fef2775fc..bc1cfe9ec 100644 --- a/rigs/icom/ic706.c +++ b/rigs/icom/ic706.c @@ -144,7 +144,7 @@ static const struct icom_priv_caps ic706_priv_caps = .r2i_mode = ic706_r2i_mode }; -const struct rig_caps ic706_caps = +struct rig_caps ic706_caps = { RIG_MODEL(RIG_MODEL_IC706), .model_name = "IC-706", @@ -292,7 +292,7 @@ static const struct icom_priv_caps ic706mkii_priv_caps = .r2i_mode = ic706_r2i_mode }; -const struct rig_caps ic706mkii_caps = +struct rig_caps ic706mkii_caps = { RIG_MODEL(RIG_MODEL_IC706MKII), .model_name = "IC-706MkII", @@ -463,7 +463,7 @@ static const struct icom_priv_caps ic706mkiig_priv_caps = .r2i_mode = ic706_r2i_mode }; -const struct rig_caps ic706mkiig_caps = +struct rig_caps ic706mkiig_caps = { RIG_MODEL(RIG_MODEL_IC706MKIIG), .model_name = "IC-706MkIIG", diff --git a/rigs/icom/ic707.c b/rigs/icom/ic707.c index 83d8828c3..4376094a4 100644 --- a/rigs/icom/ic707.c +++ b/rigs/icom/ic707.c @@ -54,7 +54,7 @@ static const struct icom_priv_caps ic707_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic707_caps = +struct rig_caps ic707_caps = { RIG_MODEL(RIG_MODEL_IC707), .model_name = "IC-707", diff --git a/rigs/icom/ic7100.c b/rigs/icom/ic7100.c index 954ed15a0..1bf8013eb 100644 --- a/rigs/icom/ic7100.c +++ b/rigs/icom/ic7100.c @@ -288,10 +288,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; @@ -300,10 +302,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); @@ -318,7 +322,7 @@ int ic7100_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, return retval; } -const struct rig_caps ic7100_caps = +struct rig_caps ic7100_caps = { RIG_MODEL(RIG_MODEL_IC7100), .model_name = "IC-7100", @@ -349,8 +353,6 @@ const struct rig_caps ic7100_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, diff --git a/rigs/icom/ic718.c b/rigs/icom/ic718.c index b4f1d11e2..363748305 100644 --- a/rigs/icom/ic718.c +++ b/rigs/icom/ic718.c @@ -72,7 +72,7 @@ static const struct icom_priv_caps IC718_priv_caps = ic718_ts_sc_list }; -const struct rig_caps ic718_caps = +struct rig_caps ic718_caps = { RIG_MODEL(RIG_MODEL_IC718), .model_name = "IC-718", @@ -103,7 +103,6 @@ const struct rig_caps ic718_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .str_cal = IC718_STR_CAL, diff --git a/rigs/icom/ic7200.c b/rigs/icom/ic7200.c index e1df13752..0a09baf33 100644 --- a/rigs/icom/ic7200.c +++ b/rigs/icom/ic7200.c @@ -125,7 +125,7 @@ static const struct icom_priv_caps IC7200_priv_caps = .data_mode_supported = 1 }; -const struct rig_caps ic7200_caps = +struct rig_caps ic7200_caps = { RIG_MODEL(RIG_MODEL_IC7200), .model_name = "IC-7200", @@ -156,8 +156,6 @@ const struct rig_caps ic7200_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, diff --git a/rigs/icom/ic725.c b/rigs/icom/ic725.c index 983269b3c..6bdf868db 100644 --- a/rigs/icom/ic725.c +++ b/rigs/icom/ic725.c @@ -52,7 +52,7 @@ static const struct icom_priv_caps ic725_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic725_caps = +struct rig_caps ic725_caps = { RIG_MODEL(RIG_MODEL_IC725), .model_name = "IC-725", diff --git a/rigs/icom/ic726.c b/rigs/icom/ic726.c index 911332105..c2125b9fa 100644 --- a/rigs/icom/ic726.c +++ b/rigs/icom/ic726.c @@ -54,7 +54,7 @@ static const struct icom_priv_caps ic726_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic726_caps = +struct rig_caps ic726_caps = { RIG_MODEL(RIG_MODEL_IC726), .model_name = "IC-726", diff --git a/rigs/icom/ic728.c b/rigs/icom/ic728.c index 980c367d9..964b013ae 100644 --- a/rigs/icom/ic728.c +++ b/rigs/icom/ic728.c @@ -54,7 +54,7 @@ static const struct icom_priv_caps ic728_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic728_caps = +struct rig_caps ic728_caps = { RIG_MODEL(RIG_MODEL_IC728), .model_name = "IC-728", @@ -173,7 +173,7 @@ static const struct icom_priv_caps ic729_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic729_caps = +struct rig_caps ic729_caps = { RIG_MODEL(RIG_MODEL_IC729), .model_name = "IC-729", diff --git a/rigs/icom/ic7300.c b/rigs/icom/ic7300.c index aae35ee9b..8fef4e62f 100644 --- a/rigs/icom/ic7300.c +++ b/rigs/icom/ic7300.c @@ -715,7 +715,7 @@ static const struct icom_priv_caps IC905_priv_caps = .data_mode_supported = 1 }; -const struct rig_caps ic7300_caps = +struct rig_caps ic7300_caps = { RIG_MODEL(RIG_MODEL_IC7300), .model_name = "IC-7300", @@ -745,8 +745,6 @@ const struct rig_caps ic7300_caps = .has_set_parm = RIG_PARM_SET(IC7300_PARMS), .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = {.min = {.i = 0}, .max = {.i = 255}}, - [LVL_VOXDELAY] = {.min = {.i = 0}, .max = {.i = 20}, .step = {.i = 1}}, [LVL_KEYSPD] = {.min = {.i = 6}, .max = {.i = 48}, .step = {.i = 1}}, [LVL_CWPITCH] = {.min = {.i = 300}, .max = {.i = 900}, .step = {.i = 1}}, [LVL_SPECTRUM_SPEED] = {.min = {.i = 0}, .max = {.i = 2}, .step = {.i = 1}}, @@ -784,6 +782,8 @@ const struct rig_caps ic7300_caps = .chan_list = { { 1, 99, RIG_MTYPE_MEM }, + { 1, 8, RIG_MTYPE_VOICE }, + { 1, 8, RIG_MTYPE_MORSE }, RIG_CHAN_END, }, @@ -966,7 +966,7 @@ struct rig_caps ic9700_caps = RIG_MODEL(RIG_MODEL_IC9700), .model_name = "IC-9700", .mfg_name = "Icom", - .version = BACKEND_VER ".18", + .version = BACKEND_VER ".19", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -991,8 +991,6 @@ struct rig_caps ic9700_caps = .has_set_parm = RIG_PARM_SET(IC9700_PARMS), .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = {.min = {.i = 6}, .max = {.i = 48}, .step = {.i = 1}}, [LVL_CWPITCH] = {.min = {.i = 300}, .max = {.i = 900}, .step = {.i = 1}}, [LVL_SPECTRUM_SPEED] = {.min = {.i = 0}, .max = {.i = 2}, .step = {.i = 1}}, @@ -1006,7 +1004,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, @@ -1027,6 +1025,8 @@ struct rig_caps ic9700_caps = .chan_list = { { 1, 99, RIG_MTYPE_MEM }, + { 1, 8, RIG_MTYPE_VOICE }, + { 1, 8, RIG_MTYPE_MORSE }, RIG_CHAN_END, }, @@ -1285,7 +1285,7 @@ struct rig_caps ic9700_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps ic705_caps = +struct rig_caps ic705_caps = { RIG_MODEL(RIG_MODEL_IC705), .model_name = "IC-705", @@ -1315,8 +1315,6 @@ const struct rig_caps ic705_caps = .has_set_parm = RIG_PARM_SET(IC7300_PARMS), .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = {.min = {.i = 0}, .max = {.i = 255}}, - [LVL_VOXDELAY] = {.min = {.i = 0}, .max = {.i = 20}, .step = {.i = 1}}, [LVL_KEYSPD] = {.min = {.i = 6}, .max = {.i = 48}, .step = {.i = 1}}, [LVL_CWPITCH] = {.min = {.i = 300}, .max = {.i = 900}, .step = {.i = 1}}, [LVL_SPECTRUM_SPEED] = {.min = {.i = 0}, .max = {.i = 2}, .step = {.i = 1}}, @@ -1329,7 +1327,7 @@ const 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, @@ -1350,6 +1348,8 @@ const struct rig_caps ic705_caps = .chan_list = { { 1, 99, RIG_MTYPE_MEM }, + { 1, 8, RIG_MTYPE_VOICE }, + { 1, 8, RIG_MTYPE_MORSE }, RIG_CHAN_END, }, @@ -1558,7 +1558,7 @@ const struct rig_caps ic705_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps ic905_caps = +struct rig_caps ic905_caps = { RIG_MODEL(RIG_MODEL_IC905), .model_name = "IC-905", @@ -1588,8 +1588,6 @@ const struct rig_caps ic905_caps = .has_set_parm = RIG_PARM_SET(IC7300_PARMS), .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = {.min = {.i = 0}, .max = {.i = 255}}, - [LVL_VOXDELAY] = {.min = {.i = 0}, .max = {.i = 20}, .step = {.i = 1}}, [LVL_KEYSPD] = {.min = {.i = 6}, .max = {.i = 48}, .step = {.i = 1}}, [LVL_CWPITCH] = {.min = {.i = 300}, .max = {.i = 900}, .step = {.i = 1}}, [LVL_SPECTRUM_SPEED] = {.min = {.i = 0}, .max = {.i = 2}, .step = {.i = 1}}, @@ -1603,7 +1601,7 @@ const 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, @@ -1624,6 +1622,8 @@ const struct rig_caps ic905_caps = .chan_list = { { 1, 99, RIG_MTYPE_MEM }, + { 1, 8, RIG_MTYPE_VOICE }, + { 1, 8, RIG_MTYPE_MORSE }, RIG_CHAN_END, }, @@ -1924,6 +1924,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 @@ -1956,6 +1957,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; @@ -2050,10 +2052,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; @@ -2062,10 +2066,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); @@ -2158,10 +2164,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; @@ -2170,10 +2178,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); @@ -2193,11 +2203,30 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) unsigned char ackbuf[MAXFRAMELEN]; int ack_len = sizeof(ackbuf); int retval; + int vfo_is_main_or_sub = (vfo == RIG_VFO_MAIN) || (vfo == RIG_VFO_SUB); ENTERFUNC; rig_debug(RIG_DEBUG_VERBOSE, "%s: vfo=%s\n", __func__, rig_strvfo(vfo)); + if (rig->state.cache.satmode && !vfo_is_main_or_sub) + { + // Translate VFO A/B to Main/Sub in satellite mode + 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: Invalid VFO %s in satellite mode\n", __func__, rig_strvfo(vfo)); + return -RIG_EINVAL; + } + } + if (vfo == RIG_VFO_A) { retval = icom_transaction(rig, C_SET_VFO, S_VFOA, NULL, 0, ackbuf, &ack_len); @@ -2206,7 +2235,8 @@ 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; } @@ -2260,6 +2290,10 @@ int ic9700_set_vfo(RIG *rig, vfo_t vfo) retval = icom_transaction(rig, C_SET_VFO, subcmd, NULL, 0, ackbuf, &ack_len); } } + else if (vfo == RIG_VFO_MEM) + { + return icom_set_vfo(rig, vfo); + } else { // Unsupported VFO diff --git a/rigs/icom/ic735.c b/rigs/icom/ic735.c index 46a8f05a1..9b6cf3952 100644 --- a/rigs/icom/ic735.c +++ b/rigs/icom/ic735.c @@ -51,7 +51,7 @@ static const struct icom_priv_caps ic735_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic735_caps = +struct rig_caps ic735_caps = { RIG_MODEL(RIG_MODEL_IC735), .model_name = "IC-735", diff --git a/rigs/icom/ic736.c b/rigs/icom/ic736.c index 52d0a5e57..979c336b6 100644 --- a/rigs/icom/ic736.c +++ b/rigs/icom/ic736.c @@ -58,7 +58,7 @@ static const struct icom_priv_caps ic736_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic736_caps = +struct rig_caps ic736_caps = { RIG_MODEL(RIG_MODEL_IC736), .model_name = "IC-736", diff --git a/rigs/icom/ic737.c b/rigs/icom/ic737.c index 0d45770c4..e04ea3b3d 100644 --- a/rigs/icom/ic737.c +++ b/rigs/icom/ic737.c @@ -56,7 +56,7 @@ static const struct icom_priv_caps ic737_priv_caps = .ant_count = 2 }; -const struct rig_caps ic737_caps = +struct rig_caps ic737_caps = { RIG_MODEL(RIG_MODEL_IC737), .model_name = "IC-737", diff --git a/rigs/icom/ic738.c b/rigs/icom/ic738.c index 254d6217c..09d646c28 100644 --- a/rigs/icom/ic738.c +++ b/rigs/icom/ic738.c @@ -58,7 +58,7 @@ static const struct icom_priv_caps ic738_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic738_caps = +struct rig_caps ic738_caps = { RIG_MODEL(RIG_MODEL_IC738), .model_name = "IC-738", diff --git a/rigs/icom/ic7410.c b/rigs/icom/ic7410.c index a4e2da2c4..56c3e5e25 100644 --- a/rigs/icom/ic7410.c +++ b/rigs/icom/ic7410.c @@ -119,7 +119,7 @@ static const struct icom_priv_caps ic7410_priv_caps = }; -const struct rig_caps ic7410_caps = +struct rig_caps ic7410_caps = { RIG_MODEL(RIG_MODEL_IC7410), .model_name = "IC-7410", @@ -150,8 +150,6 @@ const struct rig_caps ic7410_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, diff --git a/rigs/icom/ic746.c b/rigs/icom/ic746.c index d2191fc88..5ae9fdc01 100644 --- a/rigs/icom/ic746.c +++ b/rigs/icom/ic746.c @@ -176,7 +176,7 @@ static const struct icom_priv_caps ic746_priv_caps = }, }; -const struct rig_caps ic746_caps = +struct rig_caps ic746_caps = { RIG_MODEL(RIG_MODEL_IC746), .model_name = "IC-746", @@ -207,7 +207,6 @@ const struct rig_caps ic746_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, @@ -412,7 +411,7 @@ static const struct icom_priv_caps ic746pro_priv_caps = }, }; -const struct rig_caps ic746pro_caps = +struct rig_caps ic746pro_caps = { RIG_MODEL(RIG_MODEL_IC746PRO), .model_name = "IC-746PRO", @@ -443,7 +442,6 @@ const struct rig_caps ic746pro_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = { [PARM_BACKLIGHT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.f = 1.0f / 255.0f}}, diff --git a/rigs/icom/ic751.c b/rigs/icom/ic751.c index 7cefc4bcf..a1352f616 100644 --- a/rigs/icom/ic751.c +++ b/rigs/icom/ic751.c @@ -79,7 +79,7 @@ static const struct icom_priv_caps ic751_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic751_caps = +struct rig_caps ic751_caps = { RIG_MODEL(RIG_MODEL_IC751), .model_name = "IC-751", @@ -111,7 +111,6 @@ const struct rig_caps ic751_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .ctcss_list = NULL, diff --git a/rigs/icom/ic756.c b/rigs/icom/ic756.c index ca78cd6c1..9e7a57bd0 100644 --- a/rigs/icom/ic756.c +++ b/rigs/icom/ic756.c @@ -135,7 +135,7 @@ static const struct icom_priv_caps ic756_priv_caps = }, }; -const struct rig_caps ic756_caps = +struct rig_caps ic756_caps = { RIG_MODEL(RIG_MODEL_IC756), .model_name = "IC-756", @@ -166,7 +166,6 @@ const struct rig_caps ic756_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .ctcss_list = common_ctcss_list, @@ -300,7 +299,7 @@ static const struct icom_priv_caps ic756pro_priv_caps = }, }; -const struct rig_caps ic756pro_caps = +struct rig_caps ic756pro_caps = { RIG_MODEL(RIG_MODEL_IC756PRO), .model_name = "IC-756PRO", @@ -331,7 +330,6 @@ const struct rig_caps ic756pro_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, @@ -542,7 +540,7 @@ static int ic756pro2_get_ext_parm(RIG *rig, token_t token, value_t *val); #define IC756PROII_PARMS (RIG_PARM_ANN|RIG_PARM_BEEP|RIG_PARM_BACKLIGHT|RIG_PARM_TIME) -const struct rig_caps ic756pro2_caps = +struct rig_caps ic756pro2_caps = { RIG_MODEL(RIG_MODEL_IC756PROII), .model_name = "IC-756PROII", @@ -573,8 +571,6 @@ const struct rig_caps ic756pro2_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, @@ -979,7 +975,7 @@ static const struct icom_priv_caps ic756pro3_priv_caps = { 241, 30.0f } \ } } -const struct rig_caps ic756pro3_caps = +struct rig_caps ic756pro3_caps = { RIG_MODEL(RIG_MODEL_IC756PROIII), .model_name = "IC-756PROIII", @@ -1010,8 +1006,6 @@ const struct rig_caps ic756pro3_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, diff --git a/rigs/icom/ic7600.c b/rigs/icom/ic7600.c index 4a5efed67..804716c99 100644 --- a/rigs/icom/ic7600.c +++ b/rigs/icom/ic7600.c @@ -249,10 +249,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; @@ -261,10 +263,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); @@ -310,8 +314,6 @@ struct rig_caps ic7600_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, diff --git a/rigs/icom/ic761.c b/rigs/icom/ic761.c index 21f13db45..4a73b7a12 100644 --- a/rigs/icom/ic761.c +++ b/rigs/icom/ic761.c @@ -51,7 +51,7 @@ static const struct icom_priv_caps ic761_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic761_caps = +struct rig_caps ic761_caps = { RIG_MODEL(RIG_MODEL_IC761), .model_name = "IC-761", diff --git a/rigs/icom/ic7610.c b/rigs/icom/ic7610.c index 4da3a6dfc..0be895c8e 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_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 }; @@ -330,10 +330,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; @@ -342,10 +344,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); @@ -408,6 +412,7 @@ struct rig_caps ic7610_caps = }, .ext_tokens = ic7610_ext_tokens, + .extfuncs = icom_ext_funcs, .extlevels = icom_ext_levels, .ctcss_list = common_ctcss_list, .dcs_list = NULL, @@ -583,6 +588,8 @@ struct rig_caps ic7610_caps = .get_ext_level = icom_get_ext_level, .set_func = icom_set_func, .get_func = icom_get_func, + .set_ext_func = icom_set_ext_func, + .get_ext_func = icom_get_ext_func, .set_parm = icom_set_parm, .get_parm = icom_get_parm, .set_mem = icom_set_mem, diff --git a/rigs/icom/ic765.c b/rigs/icom/ic765.c index eca4708c6..64fb8daf6 100644 --- a/rigs/icom/ic765.c +++ b/rigs/icom/ic765.c @@ -54,7 +54,7 @@ static const struct icom_priv_caps ic765_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic765_caps = +struct rig_caps ic765_caps = { RIG_MODEL(RIG_MODEL_IC765), .model_name = "IC-765", diff --git a/rigs/icom/ic7700.c b/rigs/icom/ic7700.c index b42d42172..72baa5f31 100644 --- a/rigs/icom/ic7700.c +++ b/rigs/icom/ic7700.c @@ -230,10 +230,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; @@ -242,10 +244,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); @@ -260,7 +264,7 @@ int ic7700_get_clock(RIG *rig, int *year, int *month, int *day, int *hour, return retval; } -const struct rig_caps ic7700_caps = +struct rig_caps ic7700_caps = { RIG_MODEL(RIG_MODEL_IC7700), .model_name = "IC-7700", @@ -291,8 +295,6 @@ const struct rig_caps ic7700_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, diff --git a/rigs/icom/ic775.c b/rigs/icom/ic775.c index 496a2755c..33d10113a 100644 --- a/rigs/icom/ic775.c +++ b/rigs/icom/ic775.c @@ -51,7 +51,7 @@ static const struct icom_priv_caps ic775_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic775_caps = +struct rig_caps ic775_caps = { RIG_MODEL(RIG_MODEL_IC775), .model_name = "IC-775", diff --git a/rigs/icom/ic78.c b/rigs/icom/ic78.c index 79ea1b95d..977e0ee2a 100644 --- a/rigs/icom/ic78.c +++ b/rigs/icom/ic78.c @@ -62,7 +62,7 @@ static const struct icom_priv_caps ic78_priv_caps = ic706_ts_sc_list }; -const struct rig_caps ic78_caps = +struct rig_caps ic78_caps = { RIG_MODEL(RIG_MODEL_IC78), .model_name = "IC-78", @@ -93,7 +93,6 @@ const struct rig_caps ic78_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .preamp = { 10, 20, RIG_DBLST_END, }, diff --git a/rigs/icom/ic7800.c b/rigs/icom/ic7800.c index d8a2996c7..4be33da94 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 @@ -160,7 +162,7 @@ static const struct icom_priv_caps ic7800_priv_caps = .data_mode_supported = 1 }; -const struct rig_caps ic7800_caps = +struct rig_caps ic7800_caps = { RIG_MODEL(RIG_MODEL_IC7800), .model_name = "IC-7800", @@ -191,8 +193,6 @@ const struct rig_caps ic7800_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, [LVL_KEYSPD] = { .min = { .i = 6 }, .max = { .i = 48 }, .step = { .i = 1 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 1 } }, }, @@ -501,10 +501,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; @@ -513,10 +515,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/ic781.c b/rigs/icom/ic781.c index 3811c0ecc..2eab2ce8b 100644 --- a/rigs/icom/ic781.c +++ b/rigs/icom/ic781.c @@ -55,7 +55,7 @@ static const struct icom_priv_caps ic781_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic781_caps = +struct rig_caps ic781_caps = { RIG_MODEL(RIG_MODEL_IC781), .model_name = "IC-781", diff --git a/rigs/icom/ic785x.c b/rigs/icom/ic785x.c index 398dffd6d..a2d225bb6 100644 --- a/rigs/icom/ic785x.c +++ b/rigs/icom/ic785x.c @@ -244,7 +244,7 @@ static struct icom_priv_caps ic785x_priv_caps = .data_mode_supported = 1 }; -const struct rig_caps ic785x_caps = +struct rig_caps ic785x_caps = { RIG_MODEL(RIG_MODEL_IC785x), .model_name = "IC-7850/7851", diff --git a/rigs/icom/ic820h.c b/rigs/icom/ic820h.c index 0ef357e5c..e81dc1637 100644 --- a/rigs/icom/ic820h.c +++ b/rigs/icom/ic820h.c @@ -50,7 +50,7 @@ static const struct icom_priv_caps ic820h_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic820h_caps = +struct rig_caps ic820h_caps = { RIG_MODEL(RIG_MODEL_IC820), .model_name = "IC-820H", diff --git a/rigs/icom/ic821h.c b/rigs/icom/ic821h.c index 4b8b4c1b4..e8f4d33ea 100644 --- a/rigs/icom/ic821h.c +++ b/rigs/icom/ic821h.c @@ -87,7 +87,7 @@ int ic821h_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) RETURNFUNC(retval); } -const struct rig_caps ic821h_caps = +struct rig_caps ic821h_caps = { RIG_MODEL(RIG_MODEL_IC821H), .model_name = "IC-821H", diff --git a/rigs/icom/ic910.c b/rigs/icom/ic910.c index aa2a703f5..67c10ade9 100644 --- a/rigs/icom/ic910.c +++ b/rigs/icom/ic910.c @@ -196,7 +196,7 @@ int ic910_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } } -const struct rig_caps ic910_caps = +struct rig_caps ic910_caps = { RIG_MODEL(RIG_MODEL_IC910), .model_name = "IC-910", @@ -227,8 +227,6 @@ const struct rig_caps ic910_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, }, .parm_gran = {}, .ctcss_list = common_ctcss_list, diff --git a/rigs/icom/ic9100.c b/rigs/icom/ic9100.c index 4dbd17168..eab9239e4 100644 --- a/rigs/icom/ic9100.c +++ b/rigs/icom/ic9100.c @@ -111,7 +111,7 @@ static const struct icom_priv_caps ic9100_priv_caps = .data_mode_supported = 1 }; -const struct rig_caps ic9100_caps = +struct rig_caps ic9100_caps = { RIG_MODEL(RIG_MODEL_IC9100), .model_name = "IC-9100", @@ -142,8 +142,6 @@ const struct rig_caps ic9100_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 20 }, .step = { .i = 1 } }, }, .parm_gran = { [PARM_BACKLIGHT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.f = 1.0f / 255.0f}}, diff --git a/rigs/icom/ic92d.c b/rigs/icom/ic92d.c index 0c9480bf2..b0f3b6753 100644 --- a/rigs/icom/ic92d.c +++ b/rigs/icom/ic92d.c @@ -93,7 +93,7 @@ static const struct icom_priv_caps ic92d_priv_caps = .serial_full_duplex = 1 }; -const struct rig_caps ic92d_caps = +struct rig_caps ic92d_caps = { RIG_MODEL(RIG_MODEL_IC92D), .model_name = "IC-92D", /* IC-E92D/IC-92AD */ @@ -124,7 +124,6 @@ const struct rig_caps ic92d_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .ctcss_list = common_ctcss_list, diff --git a/rigs/icom/ic970.c b/rigs/icom/ic970.c index 286f983af..333eb6337 100644 --- a/rigs/icom/ic970.c +++ b/rigs/icom/ic970.c @@ -45,7 +45,7 @@ static const struct icom_priv_caps ic970_priv_caps = ic737_ts_sc_list }; -const struct rig_caps ic970_caps = +struct rig_caps ic970_caps = { RIG_MODEL(RIG_MODEL_IC970), .model_name = "IC-970", diff --git a/rigs/icom/icf8101.c b/rigs/icom/icf8101.c index 42a915e23..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]) @@ -380,7 +384,7 @@ int icf8101_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) } -const struct rig_caps icf8101_caps = +struct rig_caps icf8101_caps = { RIG_MODEL(RIG_MODEL_ICF8101), .model_name = "IC-F8101", diff --git a/rigs/icom/icom.c b/rigs/icom/icom.c index 7ff78ddcc..ef4ccd68e 100644 --- a/rigs/icom/icom.c +++ b/rigs/icom/icom.c @@ -462,6 +462,10 @@ const struct confparams icom_cfg_params[] = const struct confparams icom_ext_funcs[] = { { TOK_DIGI_SEL_FUNC, "digi_sel", "DIGI-SEL enable", "", "", RIG_CONF_CHECKBUTTON, {} }, + { TOK_IPP_FUNC, "IPP", "IP Plus", "", "", RIG_CONF_CHECKBUTTON, {} }, + { TOK_TX_INHIBIT_FUNC, "TX_INHIBIT", "TX Inhibit", "", "", RIG_CONF_CHECKBUTTON, {} }, + { TOK_DPP_FUNC, "DPP", "Digital Pre Distortion-SEL enable", "", "", RIG_CONF_CHECKBUTTON, {} }, + { TOK_ICPW2_FUNC, "ICPW2", "Icom PW2 enable", "", "", RIG_CONF_CHECKBUTTON, {} }, { RIG_CONF_END, NULL, } }; @@ -521,6 +525,10 @@ const struct cmdparams icom_ext_cmd[] = { {.t = TOK_DRIVE_GAIN}, CMD_PARAM_TYPE_TOKEN, C_CTL_LVL, S_LVL_DRIVE, SC_MOD_RW, 0, {0}, CMD_DAT_FLT, 2 }, { {.t = TOK_DIGI_SEL_FUNC}, CMD_PARAM_TYPE_TOKEN, C_CTL_FUNC, S_FUNC_DIGISEL, SC_MOD_RW, 0, {0}, CMD_DAT_BOL, 1 }, { {.t = TOK_DIGI_SEL_LEVEL}, CMD_PARAM_TYPE_TOKEN, C_CTL_LVL, S_LVL_DIGI, SC_MOD_RW, 0, {0}, CMD_DAT_FLT, 2 }, + { {.t = TOK_IPP_FUNC}, CMD_PARAM_TYPE_TOKEN, C_CTL_FUNC, S_FUNC_IPP, SC_MOD_RW, 0, {0}, CMD_DAT_BOL, 1 }, + { {.t = TOK_TX_INHIBIT_FUNC}, CMD_PARAM_TYPE_TOKEN, C_CTL_FUNC, S_FUNC_TX_INHIBIT, SC_MOD_RW, 0, {0}, CMD_DAT_BOL, 1 }, + { {.t = TOK_DPP_FUNC}, CMD_PARAM_TYPE_TOKEN, C_CTL_FUNC, S_FUNC_DPP, SC_MOD_RW, 0, {0}, CMD_DAT_BOL, 1 }, + { {.t = TOK_ICPW2_FUNC}, CMD_PARAM_TYPE_TOKEN, C_CTL_MEM, 0x05, SC_MOD_RW, 2, {0x03, 0x10}, CMD_DAT_BOL, 1 }, { {0} } }; @@ -1010,6 +1018,12 @@ static vfo_t icom_current_vfo(RIG *rig) } rig_debug(RIG_DEBUG_TRACE, "%s: vfo_current=%s\n", __func__, rig_strvfo(vfo_current)); + + if (vfo_current == RIG_VFO_NONE && rs->current_vfo != RIG_VFO_NONE) + { + vfo_current = rs->current_vfo; + } + return vfo_current; } @@ -1039,7 +1053,7 @@ static void icom_satmode_fix(RIG *rig, int satmode) */ int icom_rig_open(RIG *rig) { - int retval, retval_echo; + int retval, retval_echo, value; int satmode = 0; struct rig_state *rs = &rig->state; struct icom_priv_data *priv = (struct icom_priv_data *) rs->priv; @@ -1083,6 +1097,16 @@ retry_open: if (retval == RIG_OK) // then we know our echo status { + // we need to know about dual watch for later use + rs->dual_watch = 0; + retval = rig_get_func(rig, RIG_VFO_CURR, RIG_FUNC_DUAL_WATCH, &value); + + 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_TRACE, "%s: echo status known, getting frequency\n", __func__); rs->rigport.retry = 0; @@ -1170,6 +1194,7 @@ retry_open: #endif rs->rigport.retry = retry_save; + RETURNFUNC(RIG_OK); } @@ -1222,6 +1247,7 @@ static int icom_set_default_vfo(RIG *rig) rig_debug(RIG_DEBUG_TRACE, "%s: called, curr_vfo=%s\n", __func__, rig_strvfo(rig->state.current_vfo)); + // we need to know if dual watch is on if (VFO_HAS_MAIN_SUB_A_B_ONLY) { rig_debug(RIG_DEBUG_TRACE, "%s: setting default as MAIN/VFOA\n", @@ -1487,21 +1513,28 @@ int icom_set_freq(RIG *rig, vfo_t vfo, freq_t freq) cmd = C_SET_FREQ; subcmd = -1; - if (ICOM_IS_ID5100 || ICOM_IS_ID4100 || ICOM_IS_ID31 || ICOM_IS_ID51) +#if 0 + if (rig->state.cache.ptt && (ICOM_IS_ID5100 || ICOM_IS_ID4100 || ICOM_IS_ID31 + || ICOM_IS_ID51)) { - // for these rigs C_SND_FREQ (0x00) is setting the freq and 0x03 is just for reading - cmd = C_SND_FREQ; + 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 + cmd = 0x00; // 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)); - RETURNFUNC2(retval); + rig_debug(RIG_DEBUG_ERR, "%s: set_freq failed: %s\n", __func__, + rigerror(retval)); + return retval; } - RETURNFUNC2(RIG_OK); + + return RIG_OK; } else +#endif { retval = icom_transaction(rig, cmd, subcmd, freqbuf, freq_len, ackbuf, &ack_len); @@ -1726,7 +1759,15 @@ int icom_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) if (vfo == RIG_VFO_MEM && civ_731_mode_save) { priv->civ_731_mode = 1; } - RETURNFUNC(-RIG_ERJCTED); + 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__); + return -RIG_ETRUNC; + } + + RETURNFUNC(-RIG_ENAVAIL); } if (freq_len != 3 && freq_len != 6 && freq_len != (priv->civ_731_mode ? 4 : 5)) @@ -2143,15 +2184,16 @@ static int icom_set_mode_x26(RIG *rig, vfo_t vfo, rmode_t mode, int datamode, buf[0] = mode; buf[1] = datamode; - // filter fixed to filter 1 due to IC7300 bug defaulting to filter 2 on mode changed -- yuck!! - // buf[2] = filter // if Icom ever fixed this - buf[2] = 1; + // Skip filter selection, because at least IC-7300 has a bug defaulting to filter 2 when changing mode + // Tested on IC-7300 and IC-9700 + // buf[2] = filter + // buf[2] = 1; int vfo_number = icom_get_vfo_number_x25x26(rig, vfo); rig_debug(RIG_DEBUG_TRACE, "%s: vfo=%s, vfo_number=%d\n", __func__, rig_strvfo(vfo), vfo_number); - retval = icom_transaction(rig, C_SEND_SEL_MODE, vfo_number, buf, 3, ackbuf, &ack_len); + retval = icom_transaction(rig, C_SEND_SEL_MODE, vfo_number, buf, 2, ackbuf, &ack_len); if (priv->x26cmdfails < 0 || priv_caps->x25x26_always) { @@ -2459,7 +2501,8 @@ static int icom_get_mode_without_data(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidt 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); } @@ -3462,7 +3505,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) { @@ -6959,8 +7003,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; @@ -7120,10 +7164,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); @@ -7154,11 +7198,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); } } @@ -7597,29 +7643,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); @@ -7633,11 +7686,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) @@ -7646,13 +7703,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; @@ -7784,6 +7842,7 @@ int icom_get_powerstat(RIG *rig, powerstat_t *status) } HAMLIB_TRACE; + if (RIG_IS_IC2730 || RIG_IS_IC705 || RIG_IS_IC7100 @@ -8455,6 +8514,8 @@ int icom_mW2power(RIG *rig, float *power, unsigned int mwpower, freq_t freq, RETURNFUNC(RIG_OK); } + +#if defined(HAVE_PTHREAD) static int icom_parse_spectrum_frame(RIG *rig, size_t length, const unsigned char *frame_data) { @@ -8592,13 +8653,16 @@ static int icom_parse_spectrum_frame(RIG *rig, size_t length, .spectrum_data = cache->spectrum_data, }; +#if defined(HAVE_PTHREAD) rig_fire_spectrum_event(rig, &spectrum_line); +#endif cache->spectrum_metadata_valid = 0; } RETURNFUNC(RIG_OK); } +#endif int icom_is_async_frame(RIG *rig, size_t frame_length, const unsigned char *frame) @@ -8639,7 +8703,9 @@ int icom_process_async_frame(RIG *rig, size_t frame_length, // TODO: Disable cache timeout for frequency after first transceive packet once we figure out how to get active VFO reliably with transceive updates // TODO: rig_set_cache_timeout_ms(rig, HAMLIB_CACHE_FREQ, HAMLIB_CACHE_ALWAYS); freq_t freq = (freq_t) from_bcd(frame + 5, (priv->civ_731_mode ? 4 : 5) * 2); +#if defined(HAVE_PTHREAD) rig_fire_freq_event(rig, RIG_VFO_CURR, freq); +#endif #if 0 @@ -8659,7 +8725,9 @@ int icom_process_async_frame(RIG *rig, size_t frame_length, // TODO: Disable cache timeout for frequency after first transceive packet once we figure out how to get active VFO reliably with transceive updates // TODO: rig_set_cache_timeout_ms(rig, HAMLIB_CACHE_MODE, HAMLIB_CACHE_ALWAYS); icom2rig_mode(rig, frame[5], frame[6], &mode, &width); +#if defined(HAVE_PTHREAD) rig_fire_mode_event(rig, RIG_VFO_CURR, mode, width); +#endif if (rs->use_cached_mode != 1) { @@ -8670,6 +8738,8 @@ int icom_process_async_frame(RIG *rig, size_t frame_length, break; +#if defined(HAVE_PTHREAD) + case C_CTL_SCP: if (frame[5] == S_SCP_DAT) { @@ -8677,6 +8747,7 @@ int icom_process_async_frame(RIG *rig, size_t frame_length, } break; +#endif default: rig_debug(RIG_DEBUG_VERBOSE, "%s: transceive cmd unsupported %#2.2x\n", diff --git a/rigs/icom/icom.h b/rigs/icom/icom.h index 0fab04512..754b31666 100644 --- a/rigs/icom/icom.h +++ b/rigs/icom/icom.h @@ -35,7 +35,7 @@ #include #endif -#define BACKEND_VER "20231116" +#define BACKEND_VER "20231209" #define ICOM_IS_ID31 rig_is_model(rig, RIG_MODEL_ID31) #define ICOM_IS_ID51 rig_is_model(rig, RIG_MODEL_ID51) @@ -291,7 +291,7 @@ struct icom_priv_data struct icom_spectrum_scope_cache spectrum_scope_cache[HAMLIB_MAX_SPECTRUM_SCOPES]; /*!< Cached Icom spectrum scope data used during reception of the data. The array index must match the scope ID. */ freq_t other_freq_deprecated; /*!< @deprecated Use rig_cache.freqOther - Our other freq depending on which vfo is selected */ int vfo_flag; // used to skip vfo check when frequencies are equal - int dual_watch; // dual watch mode on status + int dual_watch_main_sub; // 0=main, 1=sub }; extern const struct ts_sc_list r8500_ts_sc_list[]; @@ -427,94 +427,94 @@ extern const struct confparams icom_ext_funcs[]; extern const struct confparams icom_ext_parms[]; extern const struct cmdparams icom_ext_cmds[]; -extern const struct rig_caps ic703_caps; -extern const struct rig_caps ic705_caps; -extern const struct rig_caps ic706_caps; -extern const struct rig_caps ic706mkii_caps; -extern const struct rig_caps ic706mkiig_caps; -extern const struct rig_caps ic707_caps; -extern const struct rig_caps ic718_caps; -extern const struct rig_caps ic725_caps; -extern const struct rig_caps ic726_caps; -extern const struct rig_caps ic728_caps; -extern const struct rig_caps ic729_caps; -extern const struct rig_caps ic735_caps; -extern const struct rig_caps ic736_caps; -extern const struct rig_caps ic737_caps; -extern const struct rig_caps ic738_caps; -extern const struct rig_caps ic746_caps; -extern const struct rig_caps ic7410_caps; -extern const struct rig_caps ic746pro_caps; -extern const struct rig_caps ic756_caps; -extern const struct rig_caps ic756pro_caps; -extern const struct rig_caps ic756pro2_caps; -extern const struct rig_caps ic756pro3_caps; -extern const struct rig_caps ic751_caps; +extern struct rig_caps ic703_caps; +extern struct rig_caps ic705_caps; +extern struct rig_caps ic706_caps; +extern struct rig_caps ic706mkii_caps; +extern struct rig_caps ic706mkiig_caps; +extern struct rig_caps ic707_caps; +extern struct rig_caps ic718_caps; +extern struct rig_caps ic725_caps; +extern struct rig_caps ic726_caps; +extern struct rig_caps ic728_caps; +extern struct rig_caps ic729_caps; +extern struct rig_caps ic735_caps; +extern struct rig_caps ic736_caps; +extern struct rig_caps ic737_caps; +extern struct rig_caps ic738_caps; +extern struct rig_caps ic746_caps; +extern struct rig_caps ic7410_caps; +extern struct rig_caps ic746pro_caps; +extern struct rig_caps ic756_caps; +extern struct rig_caps ic756pro_caps; +extern struct rig_caps ic756pro2_caps; +extern struct rig_caps ic756pro3_caps; +extern struct rig_caps ic751_caps; extern struct rig_caps ic7600_caps; // need to modify targetable_vfo depending on response to 0x25 cmd extern struct rig_caps ic7610_caps; -extern const struct rig_caps ic761_caps; -extern const struct rig_caps ic765_caps; -extern const struct rig_caps ic7700_caps; -extern const struct rig_caps ic775_caps; -extern const struct rig_caps ic78_caps; -extern const struct rig_caps ic7800_caps; -extern const struct rig_caps ic785x_caps; -extern const struct rig_caps ic7000_caps; -extern const struct rig_caps ic7100_caps; -extern const struct rig_caps ic7200_caps; -extern const struct rig_caps ic7300_caps; -extern const struct rig_caps ic781_caps; -extern const struct rig_caps ic820h_caps; -extern const struct rig_caps ic821h_caps; -extern const struct rig_caps ic905_caps; -extern const struct rig_caps ic910_caps; -extern const struct rig_caps ic9100_caps; -extern const struct rig_caps ic970_caps; +extern struct rig_caps ic761_caps; +extern struct rig_caps ic765_caps; +extern struct rig_caps ic7700_caps; +extern struct rig_caps ic775_caps; +extern struct rig_caps ic78_caps; +extern struct rig_caps ic7800_caps; +extern struct rig_caps ic785x_caps; +extern struct rig_caps ic7000_caps; +extern struct rig_caps ic7100_caps; +extern struct rig_caps ic7200_caps; +extern struct rig_caps ic7300_caps; +extern struct rig_caps ic781_caps; +extern struct rig_caps ic820h_caps; +extern struct rig_caps ic821h_caps; +extern struct rig_caps ic905_caps; +extern struct rig_caps ic910_caps; +extern struct rig_caps ic9100_caps; +extern struct rig_caps ic970_caps; extern struct rig_caps ic9700_caps; -extern const struct rig_caps icrx7_caps; -extern const struct rig_caps icr10_caps; -extern const struct rig_caps icr20_caps; -extern const struct rig_caps icr6_caps; -extern const struct rig_caps icr71_caps; -extern const struct rig_caps icr72_caps; -extern const struct rig_caps icr75_caps; -extern const struct rig_caps icr7000_caps; -extern const struct rig_caps icr7100_caps; -extern const struct rig_caps icr8500_caps; -extern const struct rig_caps icr9000_caps; -extern const struct rig_caps icr9500_caps; -extern const struct rig_caps ic271_caps; -extern const struct rig_caps ic275_caps; -extern const struct rig_caps ic375_caps; -extern const struct rig_caps ic471_caps; -extern const struct rig_caps ic475_caps; -extern const struct rig_caps ic575_caps; -extern const struct rig_caps ic1275_caps; -extern const struct rig_caps icf8101_caps; +extern struct rig_caps icrx7_caps; +extern struct rig_caps icr10_caps; +extern struct rig_caps icr20_caps; +extern struct rig_caps icr6_caps; +extern struct rig_caps icr71_caps; +extern struct rig_caps icr72_caps; +extern struct rig_caps icr75_caps; +extern struct rig_caps icr7000_caps; +extern struct rig_caps icr7100_caps; +extern struct rig_caps icr8500_caps; +extern struct rig_caps icr9000_caps; +extern struct rig_caps icr9500_caps; +extern struct rig_caps ic271_caps; +extern struct rig_caps ic275_caps; +extern struct rig_caps ic375_caps; +extern struct rig_caps ic471_caps; +extern struct rig_caps ic475_caps; +extern struct rig_caps ic575_caps; +extern struct rig_caps ic1275_caps; +extern struct rig_caps icf8101_caps; -extern const struct rig_caps omnivip_caps; -extern const struct rig_caps delta2_caps; +extern struct rig_caps omnivip_caps; +extern struct rig_caps delta2_caps; -extern const struct rig_caps os456_caps; -extern const struct rig_caps os535_caps; +extern struct rig_caps os456_caps; +extern struct rig_caps os535_caps; -extern const struct rig_caps ic92d_caps; -extern const struct rig_caps id1_caps; -extern const struct rig_caps id31_caps; -extern const struct rig_caps id51_caps; -extern const struct rig_caps id4100_caps; -extern const struct rig_caps id5100_caps; -extern const struct rig_caps ic2730_caps; +extern struct rig_caps ic92d_caps; +extern struct rig_caps id1_caps; +extern struct rig_caps id31_caps; +extern struct rig_caps id51_caps; +extern struct rig_caps id4100_caps; +extern struct rig_caps id5100_caps; +extern struct rig_caps ic2730_caps; -extern const struct rig_caps perseus_caps; +extern struct rig_caps perseus_caps; -extern const struct rig_caps x108g_caps; -extern const struct rig_caps x6100_caps; -extern const struct rig_caps g90_caps; -extern const struct rig_caps x5105_caps; +extern struct rig_caps x108g_caps; +extern struct rig_caps x6100_caps; +extern struct rig_caps g90_caps; +extern struct rig_caps x5105_caps; -extern const struct rig_caps icr8600_caps; -extern const struct rig_caps icr30_caps; +extern struct rig_caps icr8600_caps; +extern struct rig_caps icr30_caps; #define RIG_IS_IC1271 (rig->state.rig_model == RIG_MODEL_IC1271) #define RIG_IS_IC1275 (rig->state.rig_model == RIG_MODEL_IC1275) diff --git a/rigs/icom/icom_defs.h b/rigs/icom/icom_defs.h index 226108a2c..7ac84f8e2 100644 --- a/rigs/icom/icom_defs.h +++ b/rigs/icom/icom_defs.h @@ -349,6 +349,8 @@ #define S_FUNC_NXENC 0x63 /* NXDN encryption */ #define S_FUNC_DCENC 0x64 /* DCR encryption */ #define S_FUNC_IPP 0x65 /* IP+ setting */ +#define S_FUNC_TX_INHIBIT 0x66 /* TX inhibit setting */ +#define S_FUNC_DPP 0x67 /* DPP setting */ /* * Set Power On/Off (C_SET_PWR) subcommands @@ -569,6 +571,10 @@ #define TOK_SCOPE_FEF TOKEN_BACKEND(146) #define TOK_SCOPE_RBW TOKEN_BACKEND(147) #define TOK_SCOPE_MKP TOKEN_BACKEND(148) +#define TOK_IPP_FUNC TOKEN_BACKEND(149) +#define TOK_TX_INHIBIT_FUNC TOKEN_BACKEND(150) +#define TOK_DPP_FUNC TOKEN_BACKEND(151) +#define TOK_ICPW2_FUNC TOKEN_BACKEND(152) /* * icom_ext_parm table subcommand modifiers diff --git a/rigs/icom/icr10.c b/rigs/icom/icr10.c index b67f9ccb9..aaa180125 100644 --- a/rigs/icom/icr10.c +++ b/rigs/icom/icr10.c @@ -51,7 +51,7 @@ static struct icom_priv_caps icr10_priv_caps = r8500_ts_sc_list /* wrong, but don't have set_ts anyway */ }; -const struct rig_caps icr10_caps = +struct rig_caps icr10_caps = { RIG_MODEL(RIG_MODEL_ICR10), .model_name = "IC-R10", @@ -82,7 +82,6 @@ const struct rig_caps icr10_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .ctcss_list = NULL, diff --git a/rigs/icom/icr20.c b/rigs/icom/icr20.c index 4952c49f8..0f755a906 100644 --- a/rigs/icom/icr20.c +++ b/rigs/icom/icr20.c @@ -51,7 +51,7 @@ static struct icom_priv_caps icr20_priv_caps = r8500_ts_sc_list /* wrong, but don't have set_ts anyway */ }; -const struct rig_caps icr20_caps = +struct rig_caps icr20_caps = { RIG_MODEL(RIG_MODEL_ICR20), .model_name = "IC-R20", @@ -82,7 +82,6 @@ const struct rig_caps icr20_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .ctcss_list = NULL, diff --git a/rigs/icom/icr30.c b/rigs/icom/icr30.c index 9c61121ac..7ce95a322 100644 --- a/rigs/icom/icr30.c +++ b/rigs/icom/icr30.c @@ -124,7 +124,7 @@ static struct icom_priv_caps icr30_priv_caps = .extcmds = icr30_extcmds /* Custom ext_parm parameters */ }; -const struct rig_caps icr30_caps = +struct rig_caps icr30_caps = { RIG_MODEL(RIG_MODEL_ICR30), .model_name = "IC-R30", diff --git a/rigs/icom/icr6.c b/rigs/icom/icr6.c index 2f44357c2..eab519902 100644 --- a/rigs/icom/icr6.c +++ b/rigs/icom/icr6.c @@ -51,7 +51,7 @@ static struct icom_priv_caps icr6_priv_caps = .ant_count = 2 }; -const struct rig_caps icr6_caps = +struct rig_caps icr6_caps = { RIG_MODEL(RIG_MODEL_ICR6), .model_name = "IC-R6", diff --git a/rigs/icom/icr7000.c b/rigs/icom/icr7000.c index 028c45d0f..3636046b8 100644 --- a/rigs/icom/icr7000.c +++ b/rigs/icom/icr7000.c @@ -51,7 +51,7 @@ static struct icom_priv_caps icr7000_priv_caps = /* * ICR7000 rigs capabilities. */ -const struct rig_caps icr7000_caps = +struct rig_caps icr7000_caps = { RIG_MODEL(RIG_MODEL_ICR7000), .model_name = "IC-R7000", @@ -174,7 +174,7 @@ static struct icom_priv_caps icr7100_priv_caps = /* * ICR7100A rig capabilities. */ -const struct rig_caps icr7100_caps = +struct rig_caps icr7100_caps = { RIG_MODEL(RIG_MODEL_ICR7100), .model_name = "IC-R7100", diff --git a/rigs/icom/icr71.c b/rigs/icom/icr71.c index d933be0c6..660fba2e8 100644 --- a/rigs/icom/icr71.c +++ b/rigs/icom/icr71.c @@ -44,7 +44,7 @@ static struct icom_priv_caps icr71_priv_caps = ic737_ts_sc_list /* none actually */ }; -const struct rig_caps icr71_caps = +struct rig_caps icr71_caps = { RIG_MODEL(RIG_MODEL_ICR71), .model_name = "IC-R71", diff --git a/rigs/icom/icr72.c b/rigs/icom/icr72.c index 6708b53a2..115a2abd5 100644 --- a/rigs/icom/icr72.c +++ b/rigs/icom/icr72.c @@ -45,7 +45,7 @@ static struct icom_priv_caps icr72_priv_caps = ic737_ts_sc_list }; -const struct rig_caps icr72_caps = +struct rig_caps icr72_caps = { RIG_MODEL(RIG_MODEL_ICR72), .model_name = "IC-R72", diff --git a/rigs/icom/icr75.c b/rigs/icom/icr75.c index 9c044b87b..d866eceb1 100644 --- a/rigs/icom/icr75.c +++ b/rigs/icom/icr75.c @@ -103,7 +103,7 @@ static struct icom_priv_caps icr75_priv_caps = .ant_count = 2 }; -const struct rig_caps icr75_caps = +struct rig_caps icr75_caps = { RIG_MODEL(RIG_MODEL_ICR75), .model_name = "IC-R75", @@ -134,11 +134,9 @@ const struct rig_caps icr75_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, [LVL_PBT_IN] = { .min = { .f = -1280 }, .max = { .f = +1280 }, .step = { .f = 15 } }, [LVL_PBT_OUT] = { .min = { .f = -1280 }, .max = { .f = +1280 }, .step = { .f = 15 } }, [LVL_CWPITCH] = { .min = { .i = 300 }, .max = { .i = 900 }, .step = { .i = 10 } }, - [LVL_NR] = { .min = { .f = 0.0 }, .max = { .f = 1.0 }, .step = { .f = 0.066666667 } }, }, .parm_gran = { [PARM_APO] = { .min = { .i = 1 }, .max = { .i = 1439} }, diff --git a/rigs/icom/icr8500.c b/rigs/icom/icr8500.c index 187062db6..61cc33f2e 100644 --- a/rigs/icom/icr8500.c +++ b/rigs/icom/icr8500.c @@ -70,7 +70,7 @@ static struct icom_priv_caps icr8500_priv_caps = /* * IC-R8500 rig capabilities. */ -const struct rig_caps icr8500_caps = +struct rig_caps icr8500_caps = { RIG_MODEL(RIG_MODEL_ICR8500), .model_name = "ICR-8500", @@ -102,8 +102,6 @@ const struct rig_caps icr8500_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, - [LVL_IF] = { .min = { .i = 0 }, .max = { .i = 255 }, .step = { .i = 1 } }, }, .parm_gran = {}, .ctcss_list = NULL, /* FIXME: CTCSS/DCS list */ diff --git a/rigs/icom/icr8600.c b/rigs/icom/icr8600.c index da932200d..e3a012b4c 100644 --- a/rigs/icom/icr8600.c +++ b/rigs/icom/icr8600.c @@ -128,7 +128,7 @@ static struct icom_priv_caps icr8600_priv_caps = .extcmds = icr8600_extcmds /* Custom ext_cmd parameters */ }; -const struct rig_caps icr8600_caps = +struct rig_caps icr8600_caps = { RIG_MODEL(RIG_MODEL_ICR8600), .model_name = "IC-R8600", diff --git a/rigs/icom/icr9000.c b/rigs/icom/icr9000.c index ecb88d523..33e9f4887 100644 --- a/rigs/icom/icr9000.c +++ b/rigs/icom/icr9000.c @@ -62,7 +62,7 @@ static struct icom_priv_caps icr9000_priv_caps = /* * ICR9000A rig capabilities. */ -const struct rig_caps icr9000_caps = +struct rig_caps icr9000_caps = { RIG_MODEL(RIG_MODEL_ICR9000), .model_name = "IC-R9000", @@ -94,7 +94,6 @@ const struct rig_caps icr9000_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = { [PARM_BANDSELECT] = {.step = {.s = "BANDUNUSED,BAND160M,BAND80M,BAND40M,BAND30M,BAND20M,BAND17M,BAND15M,BAND12M,BAND10M,BAND6M,BANDGEN"}}, diff --git a/rigs/icom/icr9500.c b/rigs/icom/icr9500.c index 741306019..e8bb4977b 100644 --- a/rigs/icom/icr9500.c +++ b/rigs/icom/icr9500.c @@ -76,7 +76,7 @@ static struct icom_priv_caps icr9500_priv_caps = /* * ICR9500A rig capabilities. */ -const struct rig_caps icr9500_caps = +struct rig_caps icr9500_caps = { RIG_MODEL(RIG_MODEL_ICR9500), .model_name = "IC-R9500", @@ -108,7 +108,6 @@ const struct rig_caps icr9500_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = { [PARM_BACKLIGHT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.f = 1.0f / 255.0f}}, diff --git a/rigs/icom/icrx7.c b/rigs/icom/icrx7.c index 42af41238..089c1d6b5 100644 --- a/rigs/icom/icrx7.c +++ b/rigs/icom/icrx7.c @@ -49,7 +49,7 @@ static struct icom_priv_caps icrx7_priv_caps = r8500_ts_sc_list /* wrong, but don't have set_ts anyway */ }; -const struct rig_caps icrx7_caps = +struct rig_caps icrx7_caps = { RIG_MODEL(RIG_MODEL_ICRX7), .model_name = "IC-RX7", @@ -80,7 +80,6 @@ const struct rig_caps icrx7_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .ctcss_list = NULL, diff --git a/rigs/icom/id1.c b/rigs/icom/id1.c index 414541154..81004a411 100644 --- a/rigs/icom/id1.c +++ b/rigs/icom/id1.c @@ -67,7 +67,7 @@ static struct icom_priv_caps id1_priv_caps = id1_ts_sc_list }; -const struct rig_caps id1_caps = +struct rig_caps id1_caps = { RIG_MODEL(RIG_MODEL_ICID1), .model_name = "IC ID-1", @@ -98,7 +98,6 @@ const struct rig_caps id1_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .parm_gran = {}, .ctcss_list = common_ctcss_list, diff --git a/rigs/icom/id31.c b/rigs/icom/id31.c index d243b4af3..3de602f9d 100644 --- a/rigs/icom/id31.c +++ b/rigs/icom/id31.c @@ -75,7 +75,7 @@ static struct icom_priv_caps id31_priv_caps = 1, /* no XCHG */ }; -const struct rig_caps id31_caps = +struct rig_caps id31_caps = { RIG_MODEL(RIG_MODEL_ID31), .model_name = "ID-31", diff --git a/rigs/icom/id4100.c b/rigs/icom/id4100.c index a126a909b..c04c9ec55 100644 --- a/rigs/icom/id4100.c +++ b/rigs/icom/id4100.c @@ -79,7 +79,7 @@ static struct icom_priv_caps id4100_priv_caps = 1, /* no XCHG */ }; -const struct rig_caps id4100_caps = +struct rig_caps id4100_caps = { RIG_MODEL(RIG_MODEL_ID4100), .model_name = "ID-4100", diff --git a/rigs/icom/id51.c b/rigs/icom/id51.c index 13fe98e01..729312a85 100644 --- a/rigs/icom/id51.c +++ b/rigs/icom/id51.c @@ -82,7 +82,7 @@ static struct icom_priv_caps id51_priv_caps = 1, /* no XCHG */ }; -const struct rig_caps id51_caps = +struct rig_caps id51_caps = { RIG_MODEL(RIG_MODEL_ID51), .model_name = "ID-51", diff --git a/rigs/icom/id5100.c b/rigs/icom/id5100.c index 637fe7afc..b1e114843 100644 --- a/rigs/icom/id5100.c +++ b/rigs/icom/id5100.c @@ -27,6 +27,12 @@ #include "frame.h" #include "misc.h" +enum +{ + MAIN_ON_LEFT, + MAIN_ON_RIGHT +}; + /* * Specs and protocol details comes from the chapter 13 of ID-5100_Full-Inst_Manual.pdf * @@ -65,6 +71,284 @@ #define ID5100_PARM_ALL RIG_PARM_NONE +int id5100_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo); + +int id5100_set_vfo(RIG *rig, vfo_t vfo) +{ + struct rig_state *rs = &rig->state; + struct icom_priv_data *priv = (struct icom_priv_data *) rs->priv; + unsigned char ackbuf[MAXFRAMELEN]; + int ack_len = sizeof(ackbuf), retval; + + ENTERFUNC; + + if (vfo == RIG_VFO_CURR) { vfo = rig->state.current_vfo; } + + // if user requests VFOA/B we automatically turn of dual watch mode + // if user requests Main/Sub we automatically turn on dual watch mode + // hopefully this is a good idea and just prevents users/clients from having set the mode themselves +#if 0 + + if (vfo == RIG_VFO_A || vfo == RIG_VFO_B) + { + // and 0x25 works in this mode + priv->x25cmdfails = 1; + + if (priv->dual_watch) + { + // then we need to turn off dual watch + if (RIG_OK != (retval = icom_set_func(rig, RIG_VFO_CURR, RIG_FUNC_DUAL_WATCH, + 0))) + { + RETURNFUNC2(retval); + } + + priv->dual_watch = 0; + } + } + else if (vfo == RIG_VFO_MAIN || vfo == RIG_VFO_SUB) + { + // x25 does not work in DUAL_WATCH mode + priv->x25cmdfails = 1; + + if (priv->dual_watch == 0) + { + if (RIG_OK != (retval = icom_set_func(rig, RIG_VFO_CURR, RIG_FUNC_DUAL_WATCH, + 1))) + { + RETURNFUNC2(retval); + } + + priv->dual_watch = 1; + } + } + +#endif + + int myvfo = S_MAIN; + priv->dual_watch_main_sub = MAIN_ON_LEFT; + rig->state.current_vfo = RIG_VFO_A; + + if (vfo == RIG_VFO_B || vfo == RIG_VFO_SUB) + { + myvfo = S_SUB; + priv->dual_watch_main_sub = MAIN_ON_RIGHT; + rig->state.current_vfo = vfo; + } + + if (RIG_OK != (retval = icom_transaction(rig, C_SET_VFO, myvfo, NULL, 0, ackbuf, + &ack_len))) + { + RETURNFUNC2(retval); + } + + return retval; +} + + +int id5100_set_freq(RIG *rig, vfo_t vfo, freq_t freq) +{ + int cmd = C_SET_FREQ; + int subcmd = -1; + unsigned char freqbuf[MAXFRAMELEN]; + int freq_len = 5; + int retval; + struct rig_state *rs = &rig->state; + //struct icom_priv_data *priv = (struct icom_priv_data *) rs->priv; + + vfo_t currvfo = rig->state.current_vfo; + + if (vfo == RIG_VFO_CURR) { vfo = rig->state.current_vfo; } + + if (rs->dual_watch == 0 && (vfo == RIG_VFO_MAIN || vfo == RIG_VFO_SUB)) { id5100_set_split_vfo(rig, RIG_VFO_SUB, 1, RIG_VFO_MAIN); } + + if (rs->dual_watch == 1 && (vfo == RIG_VFO_A || vfo == RIG_VFO_B)) { id5100_set_split_vfo(rig, RIG_VFO_A, 0, RIG_VFO_A); } + + if (vfo != currvfo) { id5100_set_vfo(rig, vfo); } + + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): vfo=%s\n", __func__, __LINE__, + rig_strvfo(vfo)); + + to_bcd(freqbuf, freq, freq_len * 2); + retval = icom_transaction(rig, cmd, subcmd, freqbuf, freq_len, NULL, + NULL); + + if (vfo != currvfo) { id5100_set_vfo(rig, currvfo); } + + if (retval != RIG_OK) + { + rig_debug(RIG_DEBUG_ERR, "%s: set_freq failed: %s\n", __func__, + rigerror(retval)); + return retval; + } + + return RIG_OK; +} + + +static int id5100_get_freq2(RIG *rig, vfo_t vfo, freq_t *freq) +{ + unsigned char freqbuf[MAXFRAMELEN]; + int freq_len = 5; + int retval; + int freqbuf_offset = 1; + int cmd = 0x03; + int subcmd = -1; + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): vfo=%s\n", __func__, __LINE__, + rig_strvfo(vfo)); + retval = icom_transaction(rig, cmd, subcmd, NULL, 0, freqbuf, &freq_len); + + if (retval != RIG_OK) + { + return -retval; + } + + *freq = from_bcd(freqbuf + freqbuf_offset, freq_len * 2); + return RIG_OK; +} + +int id5100_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) +{ + struct rig_state *rs = &rig->state; + struct icom_priv_data *priv = (struct icom_priv_data *) rs->priv; + int retval; + + vfo_t currvfo = rig->state.current_vfo; + + if (rs->dual_watch == 1 && rig->state.current_vfo != RIG_VFO_SUB) { id5100_set_split_vfo(rig, RIG_VFO_SUB, 0, RIG_VFO_MAIN); } + + if (rs->dual_watch) // dual watch is different + { + rig_debug(RIG_DEBUG_VERBOSE, "%s: Dual watch is on\n", __func__); + + if (priv->dual_watch_main_sub == MAIN_ON_LEFT + || currvfo == RIG_VFO_A) // Then Main is on left + { + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Main on left\n", __func__, __LINE__); + + if (vfo == RIG_VFO_A || vfo == RIG_VFO_MAIN) + { + rig_debug(RIG_DEBUG_ERR, "%s: Method#1\n", __func__); + id5100_set_vfo(rig, RIG_VFO_A); + retval = id5100_get_freq2(rig, vfo, freq); + id5100_set_vfo(rig, RIG_VFO_B); + return retval; + } + else // Sub read -- don't need to do anything as it's on the left side + { + rig_debug(RIG_DEBUG_ERR, "%s: Method#2\n", __func__); + retval = id5100_get_freq2(rig, vfo, freq); + return retval; + } + } + + else // + { + 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)) + { + rig_debug(RIG_DEBUG_ERR, "%s: Method#3\n", __func__); + id5100_set_vfo(rig, RIG_VFO_MAIN); + retval = id5100_get_freq2(rig, vfo, freq); + id5100_set_vfo(rig, RIG_VFO_SUB); + return retval; + } + else + { + rig_debug(RIG_DEBUG_ERR, "%s: Method#4\n", __func__); + retval = id5100_get_freq2(rig, vfo, freq); + return retval; + } + } + } + else // not dual watch + { + if (currvfo != vfo) + { + id5100_set_vfo(rig, vfo); + } + + retval = id5100_get_freq2(rig, vfo, freq); + + if (currvfo != vfo) + { + id5100_set_vfo(rig, currvfo); + } + + return retval; + } + +#if 0 + else if ((vfo == RIG_VFOvfo == RIG_VFO_SUB + && rs->dual_watch_main_sub == MAIN_ON_RIGHT) +{ + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Sub/A vfo=%s\n", __func__, __LINE__, + rig_strvfo(vfo)); + *freq = rig->state.cache.freqSubA; + int cache_ms_freq, cache_ms_mode, cache_ms_width; + pbwidth_t width; + freq_t tfreq; + rmode_t mode; + retval = rig_get_cache(rig, RIG_VFO_SUB, &tfreq, &cache_ms_freq, &mode, + &cache_ms_mode, + } + else + { + rig_debug(RIG_DEBUG_VERBOSE, "%s: Dual watch is off\n", __func__); + } + if (vfo == RIG_VFO_CURR) { vfo = rig->state.current_vfo; } +if (vfo == RIG_VFO_MAIN && priv->dual_watch_main_sub == MAIN_ON_LEFT) +{ + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Main/A vfo=%s\n", __func__, __LINE__, + rig_strvfo(vfo)); + } + if (priv->dual_watch_main_sub == MAIN_ON_LEFT || currvfo == RIG_VFO_A + || currvfo == RIG_VFO_MAIN) // Then Main is on left +{ + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Main on left\n", __func__, __LINE__); + + if (vfo == RIG_VFO_A || vfo == RIG_VFO_MAIN) + { + return id5100_get_freq2(rig, vfo, freq); + } + else + { + id5100_set_vfo(rig, RIG_VFO_B); + hl_usleep(50 * 1000); + retval = id5100_get_freq2(rig, vfo, freq); + id5100_set_vfo(rig, RIG_VFO_A); + return retval; + } + } + else // MAIN_ON_RIGHT + { + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Sub on left\n", __func__, __LINE__); + + if (vfo == RIG_VFO_B || vfo == RIG_VFO_SUB) + { + if (rs->dual_watch) + { + id5100_set_vfo(rig, RIG_VFO_A); + } + + id5100_get_freq2(rig, vfo, freq); + + if (rs->dual_watch) + { + id5100_set_vfo(rig, RIG_VFO_B); + } + } + else + { + retval = id5100_get_freq2(rig, vfo, freq); + return retval; + } + } +#endif + return RIG_OK; +} /* * FIXME: real measurement @@ -136,110 +420,99 @@ int id5100_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) return RIG_OK; } -int id5100_set_vfo(RIG *rig, vfo_t vfo) -{ - unsigned char ackbuf[MAXFRAMELEN]; - int ack_len = sizeof(ackbuf), retval; - struct rig_state *rs = &rig->state; - struct icom_priv_data *priv = (struct icom_priv_data *) rs->priv; - - ENTERFUNC; - - if (vfo == RIG_VFO_CURR) { vfo = rig->state.current_vfo; } - - // if user requests VFOA/B we automatically turn of dual watch mode - // if user requests Main/Sub we automatically turn on dual watch mode - // hopefully this is a good idea and just prevents users/clients from having set the mode themselves - - if (vfo == RIG_VFO_A || vfo == RIG_VFO_B) - { - // and 0x25 works in this mode - priv->x25cmdfails = 1; - - if (priv->dual_watch) - { - // then we need to turn off dual watch - if (RIG_OK != (retval = icom_set_func(rig, RIG_VFO_CURR, RIG_FUNC_DUAL_WATCH, - 0))) - { - RETURNFUNC2(retval); - } - priv->dual_watch = 0; - } - } - else if (vfo == RIG_VFO_MAIN || vfo == RIG_VFO_SUB) - { - // x25 does not work in DUAL_WATCH mode - priv->x25cmdfails = 1; - - if (priv->dual_watch == 0) - { - if (RIG_OK != (retval = icom_set_func(rig, RIG_VFO_CURR, RIG_FUNC_DUAL_WATCH, - 1))) - { - RETURNFUNC2(retval); - } - priv->dual_watch = 1; - } - } - - int myvfo = S_MAIN; - - if (vfo == RIG_VFO_B || vfo == RIG_VFO_SUB) - { - myvfo = S_SUB; - } - - if (RIG_OK != (retval = icom_transaction(rig, C_SET_VFO, myvfo, NULL, 0, ackbuf, - &ack_len))) - { - RETURNFUNC2(retval); - } - - return retval; -} - int id5100_set_split_vfo(RIG *rig, vfo_t vfo, split_t split, vfo_t tx_vfo) { + struct rig_state *rs = &rig->state; + struct icom_priv_data *priv = (struct icom_priv_data *) rs->priv; int retval; rig_debug(RIG_DEBUG_VERBOSE, "%s called vfo=%s\n", __func__, rig_strvfo(vfo)); - // ID5100 puts tx on Main an rx on Sub - if (tx_vfo == RIG_VFO_A || tx_vfo == RIG_VFO_MAIN) + if (tx_vfo != RIG_VFO_MAIN) { - // we must set RX vfo to SUB - retval = rig_set_vfo(rig, RIG_VFO_SUB); + rig_debug(RIG_DEBUG_ERR, "%s Split VFO must be Main\n", __func__); + return -RIG_EINVAL; + } + + if (rs->dual_watch == 0 || split == RIG_SPLIT_OFF) + { + if (RIG_OK != (retval = icom_set_func(rig, RIG_VFO_CURR, RIG_FUNC_DUAL_WATCH, + split))) + { + RETURNFUNC2(retval); + } + + rs->dual_watch = split; + +// if (split == RIG_SPLIT_OFF) { rig_set_vfo(rig, RIG_VFO_A); } + + return RIG_OK; + } + + priv->dual_watch_main_sub = MAIN_ON_LEFT; + + // ID5100 puts tx on Main and rx on Left side + // So we put Main on right side to match gpredict positions + // we must set RX vfo to SUB + retval = id5100_set_vfo(rig, RIG_VFO_SUB); + rs->current_vfo = RIG_VFO_SUB; + priv->dual_watch_main_sub = MAIN_ON_RIGHT; + + return retval; +} + + +int id5100_set_split_freq(RIG *rig, vfo_t vfo, freq_t tx_freq) +{ + int freq_len = 5; + int retval; + int cmd; + int subcmd; + unsigned char freqbuf[MAXFRAMELEN]; + + + ENTERFUNC; + + to_bcd(freqbuf, tx_freq, freq_len * 2); + + cmd = 0x0; + subcmd = -1; + // Main is always TX + retval = icom_transaction(rig, cmd, subcmd, freqbuf, freq_len, NULL, NULL); + + RETURNFUNC(retval); +} + +int id5100_get_split_freq(RIG *rig, vfo_t vfo, freq_t *tx_freq) +{ + int retval; + //struct rig_state *rs = &rig->state; + //struct icom_priv_data *priv = (struct icom_priv_data *) rs->priv; + //vfo_t currvfo; + + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): vfo=%s\n", __func__, __LINE__, + rig_strvfo(vfo)); +#if 0 + currvfo = rig->state.current_vfo; + + if (priv->dual_watch_main_sub == MAIN_ON_LEFT && (currvfo == RIG_VFO_MAIN + || currvfo == RIG_VFO_A) && vfo == RIG_VFO_TX) + { + rig_set_vfo(rig, RIG_VFO_SUB); + retval = rig_get_freq(rig, RIG_VFO_CURR, tx_freq); + rig_set_vfo(rig, RIG_VFO_MAIN); } else +#endif { - rig_debug(RIG_DEBUG_ERR, - "%s: ID5100 split must have Tx=Main=Tx, Rx=Sub, got Tx=%s, Rx=%s\n", __func__, - rig_strvfo(tx_vfo), rig_strvfo(vfo)); - retval = -RIG_EINVAL; + retval = rig_get_freq(rig, RIG_VFO_CURR, tx_freq); } return retval; } -int id5100_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) -{ - unsigned char ackbuf[MAXFRAMELEN]; - int ack_len = sizeof(ackbuf), retval; - int fct_cn, fct_sc; /* Command Number, Subcommand */ - unsigned char fctbuf[MAXFRAMELEN]; - int fct_len = 0; - const struct icom_priv_caps *priv_caps = rig->caps->priv; - const struct cmdparams *extcmds = priv_caps->extcmds; - int i; - rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - ENTERFUNC; - - value_t value; - RETURNFUNC(icom_get_func(rig, vfo, func, status)); -} /* */ static struct icom_priv_caps id5100_priv_caps = @@ -250,14 +523,14 @@ static struct icom_priv_caps id5100_priv_caps = .dualwatch_split = 1 }; -const struct rig_caps id5100_caps = +struct rig_caps id5100_caps = { RIG_MODEL(RIG_MODEL_ID5100), .model_name = "ID-5100", .mfg_name = "Icom", - .version = BACKEND_VER ".7", + .version = BACKEND_VER ".9", .copyright = "LGPL", - .status = RIG_STATUS_STABLE, + .status = RIG_STATUS_BETA, .rig_type = RIG_TYPE_MOBILE, .ptt_type = RIG_PTT_RIG, .dcd_type = RIG_DCD_RIG, @@ -281,7 +554,6 @@ const struct rig_caps id5100_caps = .level_gran = { #include "level_gran_icom.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, }, .extparms = icom_ext_parms, .parm_gran = {}, @@ -350,8 +622,10 @@ const struct rig_caps id5100_caps = .rig_open = icom_rig_open, .rig_close = icom_rig_close, - .set_freq = icom_set_freq, - .get_freq = icom_get_freq, + .set_freq = id5100_set_freq, + .get_freq = id5100_get_freq, + .get_split_freq = id5100_get_split_freq, + .set_split_freq = id5100_set_split_freq, .set_mode = id5100_set_mode, .get_mode = id5100_get_mode, .set_vfo = id5100_set_vfo, @@ -362,7 +636,7 @@ const struct rig_caps id5100_caps = .decode_event = icom_decode_event, .set_func = icom_set_func, - .get_func = id5100_get_func, + .get_func = icom_get_func, .set_level = icom_set_level, .get_level = icom_get_level, .set_parm = icom_set_parm, diff --git a/rigs/icom/omni.c b/rigs/icom/omni.c index 7dd077b85..14eb87af3 100644 --- a/rigs/icom/omni.c +++ b/rigs/icom/omni.c @@ -59,7 +59,7 @@ static struct icom_priv_caps omnivip_priv_caps = NULL /* TODO */ }; -const struct rig_caps omnivip_caps = +struct rig_caps omnivip_caps = { RIG_MODEL(RIG_MODEL_OMNIVIP), .model_name = "Omni VI Plus", diff --git a/rigs/icom/os456.c b/rigs/icom/os456.c index 21bcfb3bd..cc9dc4aaf 100644 --- a/rigs/icom/os456.c +++ b/rigs/icom/os456.c @@ -68,7 +68,7 @@ static struct icom_priv_caps os456_priv_caps = .settle_time = 20, }; -const struct rig_caps os456_caps = +struct rig_caps os456_caps = { RIG_MODEL(RIG_MODEL_OS456), .model_name = "OptoScan456", diff --git a/rigs/icom/os535.c b/rigs/icom/os535.c index df4bd61cb..26575c4d8 100644 --- a/rigs/icom/os535.c +++ b/rigs/icom/os535.c @@ -61,7 +61,7 @@ static struct icom_priv_caps os535_priv_caps = .settle_time = 12, }; -const struct rig_caps os535_caps = +struct rig_caps os535_caps = { RIG_MODEL(RIG_MODEL_OS535), .model_name = "OptoScan535", diff --git a/rigs/icom/perseus.c b/rigs/icom/perseus.c index 095a786d4..65b5a9c47 100644 --- a/rigs/icom/perseus.c +++ b/rigs/icom/perseus.c @@ -71,7 +71,7 @@ static struct icom_priv_caps perseus_priv_caps = * PERSEUS Receiver CAT Interface Reference Manual (Revision EN03) : * http://microtelecom.it/perseus/PERSEUS_CI-V_Interface-EN03.pdf */ -const struct rig_caps perseus_caps = +struct rig_caps perseus_caps = { RIG_MODEL(RIG_MODEL_PERSEUS), .model_name = "Perseus", diff --git a/rigs/icom/xiegu.c b/rigs/icom/xiegu.c index 5e0c223f1..e3959e9ee 100644 --- a/rigs/icom/xiegu.c +++ b/rigs/icom/xiegu.c @@ -145,7 +145,7 @@ static struct icom_priv_caps x108g_priv_caps = }; -const struct rig_caps x108g_caps = +struct rig_caps x108g_caps = { RIG_MODEL(RIG_MODEL_X108G), .model_name = "X108G", @@ -336,7 +336,7 @@ static struct icom_priv_caps x6100_priv_caps = .data_mode_supported = 1 }; -const struct rig_caps x6100_caps = +struct rig_caps x6100_caps = { RIG_MODEL(RIG_MODEL_X6100), .model_name = "X6100", @@ -512,12 +512,12 @@ const struct rig_caps x6100_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps g90_caps = +struct rig_caps g90_caps = { RIG_MODEL(RIG_MODEL_G90), .model_name = "G90", .mfg_name = "Xiegu", - .version = BACKEND_VER ".5", + .version = BACKEND_VER ".6", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -551,7 +551,6 @@ const struct rig_caps g90_caps = .max_rit = Hz(9999), .max_xit = Hz(9999), .max_ifshift = Hz(0), /* TODO */ - .targetable_vfo = 0, .vfo_ops = X108G_VFO_OPS, .targetable_vfo = RIG_TARGETABLE_FREQ | RIG_TARGETABLE_MODE, .scan_ops = X108G_SCAN_OPS, @@ -688,7 +687,7 @@ const struct rig_caps g90_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps x5105_caps = +struct rig_caps x5105_caps = { RIG_MODEL(RIG_MODEL_X5105), .model_name = "X5105", diff --git a/rigs/jrc/jrc.h b/rigs/jrc/jrc.h index ef8d80a4d..e494a3499 100644 --- a/rigs/jrc/jrc.h +++ b/rigs/jrc/jrc.h @@ -64,11 +64,11 @@ int jrc_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op); int jrc_scan(RIG *rig, vfo_t vfo, scan_t scan, int ch); int jrc_decode_event(RIG *rig); -extern const struct rig_caps nrd535_caps; -extern const struct rig_caps nrd545_caps; -extern const struct rig_caps nrd525_caps; -extern const struct rig_caps jst145_caps; -extern const struct rig_caps jst245_caps; +extern struct rig_caps nrd535_caps; +extern struct rig_caps nrd545_caps; +extern struct rig_caps nrd525_caps; +extern struct rig_caps jst145_caps; +extern struct rig_caps jst245_caps; #endif /* _JRC_H */ diff --git a/rigs/jrc/jst145.c b/rigs/jrc/jst145.c index b316b6db0..7f36b80a6 100644 --- a/rigs/jrc/jst145.c +++ b/rigs/jrc/jst145.c @@ -73,7 +73,7 @@ struct jst145_priv_data * JST-145 rig capabilities. * */ -const struct rig_caps jst145_caps = +struct rig_caps jst145_caps = { RIG_MODEL(RIG_MODEL_JST145), .model_name = "JST-145", @@ -174,7 +174,7 @@ const struct rig_caps jst145_caps = * JST-245 rig capabilities. * */ -const struct rig_caps jst245_caps = +struct rig_caps jst245_caps = { RIG_MODEL(RIG_MODEL_JST245), .model_name = "JST-245", diff --git a/rigs/jrc/nrd525.c b/rigs/jrc/nrd525.c index 2bd6aaf64..39213c5cd 100644 --- a/rigs/jrc/nrd525.c +++ b/rigs/jrc/nrd525.c @@ -54,7 +54,7 @@ static int nrd525_set_mem(RIG *rig, vfo_t vfo, int ch); * NRD-525 rig capabilities. * */ -const struct rig_caps nrd525_caps = +struct rig_caps nrd525_caps = { RIG_MODEL(RIG_MODEL_NRD525), .model_name = "NRD-525", diff --git a/rigs/jrc/nrd535.c b/rigs/jrc/nrd535.c index aae04ff9e..e5eabb598 100644 --- a/rigs/jrc/nrd535.c +++ b/rigs/jrc/nrd535.c @@ -89,7 +89,7 @@ static const struct jrc_priv_caps nrd535_priv_caps = * NRD-535 rig capabilities. * */ -const struct rig_caps nrd535_caps = +struct rig_caps nrd535_caps = { RIG_MODEL(RIG_MODEL_NRD535), .model_name = "NRD-535D", diff --git a/rigs/jrc/nrd545.c b/rigs/jrc/nrd545.c index 5e3a35dda..60ba7604f 100644 --- a/rigs/jrc/nrd545.c +++ b/rigs/jrc/nrd545.c @@ -87,7 +87,7 @@ static const struct jrc_priv_caps nrd545_priv_caps = * NRD-545 rig capabilities. * */ -const struct rig_caps nrd545_caps = +struct rig_caps nrd545_caps = { RIG_MODEL(RIG_MODEL_NRD545), .model_name = "NRD-545 DSP", diff --git a/rigs/kachina/505dsp.c b/rigs/kachina/505dsp.c index 6c5fe45fd..36e6ad37b 100644 --- a/rigs/kachina/505dsp.c +++ b/rigs/kachina/505dsp.c @@ -53,7 +53,7 @@ * TODO: * - so many ... */ -const struct rig_caps k505dsp_caps = +struct rig_caps k505dsp_caps = { RIG_MODEL(RIG_MODEL_505DSP), .model_name = "505DSP", diff --git a/rigs/kachina/kachina.h b/rigs/kachina/kachina.h index 05fa3eb9c..4fafe56a1 100644 --- a/rigs/kachina/kachina.h +++ b/rigs/kachina/kachina.h @@ -30,7 +30,7 @@ int kachina_set_freq(RIG *rig, vfo_t vfo, freq_t freq); int kachina_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); int kachina_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); -extern const struct rig_caps k505dsp_caps; +extern struct rig_caps k505dsp_caps; #endif /* _KACHINA_H */ 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 0510ceac8..50e21d15b 100644 --- a/rigs/kenwood/flex6xxx.c +++ b/rigs/kenwood/flex6xxx.c @@ -839,21 +839,26 @@ 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 = 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 + 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 +944,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 = 0; + 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 +1144,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 +1169,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); } @@ -1207,7 +1236,7 @@ int powersdr_get_parm(RIG *rig, setting_t parm, value_t *val) /* * F6K rig capabilities. */ -const struct rig_caps f6k_caps = +struct rig_caps f6k_caps = { RIG_MODEL(RIG_MODEL_F6K), .model_name = "6xxx", @@ -1233,9 +1262,9 @@ const 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, @@ -1340,7 +1369,7 @@ const struct rig_caps f6k_caps = /* * PowerSDR rig capabilities. */ -const struct rig_caps powersdr_caps = +struct rig_caps powersdr_caps = { RIG_MODEL(RIG_MODEL_POWERSDR), .model_name = "PowerSDR/Thetis", @@ -1373,16 +1402,15 @@ const 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 } }, }, /* FIXME: granularity */ - .parm_gran = {}, .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/k2.c b/rigs/kenwood/k2.c index bca431dde..7d8f4d6d7 100644 --- a/rigs/kenwood/k2.c +++ b/rigs/kenwood/k2.c @@ -113,7 +113,7 @@ int k2_pop_fw_lst(RIG *rig, const char *cmd); * Part of info comes from http://www.elecraft.com/K2_Manual_Download_Page.htm#K2 * look for KIO2 Programmer's Reference PDF */ -const struct rig_caps k2_caps = +struct rig_caps k2_caps = { RIG_MODEL(RIG_MODEL_K2), .model_name = "K2", diff --git a/rigs/kenwood/k3.c b/rigs/kenwood/k3.c index c81c3550f..586272b19 100644 --- a/rigs/kenwood/k3.c +++ b/rigs/kenwood/k3.c @@ -191,7 +191,7 @@ int k4_stop_morse(RIG *rig, vfo_t vfo); * look for K3 Programmer's Reference PDF * */ -const struct rig_caps k3_caps = +struct rig_caps k3_caps = { RIG_MODEL(RIG_MODEL_K3), .model_name = "K3", @@ -347,7 +347,7 @@ const struct rig_caps k3_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps k3s_caps = +struct rig_caps k3s_caps = { RIG_MODEL(RIG_MODEL_K3S), .model_name = "K3S", @@ -504,7 +504,7 @@ const struct rig_caps k3s_caps = }; // How similar is this to the K3S? -const struct rig_caps k4_caps = +struct rig_caps k4_caps = { RIG_MODEL(RIG_MODEL_K4), .model_name = "K4", @@ -665,7 +665,7 @@ const struct rig_caps k4_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps kx3_caps = +struct rig_caps kx3_caps = { RIG_MODEL(RIG_MODEL_KX3), .model_name = "KX3", @@ -820,7 +820,7 @@ const struct rig_caps kx3_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps kx2_caps = +struct rig_caps kx2_caps = { RIG_MODEL(RIG_MODEL_KX2), .model_name = "KX2", @@ -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 9ff8b125c..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); @@ -4371,7 +4385,7 @@ int kenwood_get_func(RIG *rig, vfo_t vfo, setting_t func, int *status) */ int kenwood_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) { - const struct rig_caps *caps; + struct rig_caps *caps; char tonebuf[16]; int i; @@ -4400,7 +4414,7 @@ int kenwood_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) int kenwood_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) { - const struct rig_caps *caps = rig->caps; + struct rig_caps *caps = rig->caps; char buf[16]; int i; @@ -4461,7 +4475,7 @@ int kenwood_set_ctcss_tone_tn(RIG *rig, vfo_t vfo, tone_t tone) int kenwood_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) { struct kenwood_priv_data *priv = rig->state.priv; - const struct rig_caps *caps; + struct rig_caps *caps; char tonebuf[3]; int i, retval; unsigned int tone_idx; @@ -4543,7 +4557,7 @@ int kenwood_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) int kenwood_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) { - const struct rig_caps *caps = rig->caps; + struct rig_caps *caps = rig->caps; char buf[16]; int i; @@ -4599,7 +4613,7 @@ int kenwood_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) int kenwood_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) { - const struct rig_caps *caps; + struct rig_caps *caps; char cmd[4]; char tonebuf[6]; int offs; @@ -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/kenwood.h b/rigs/kenwood/kenwood.h index 6d2062dc1..ec88254f8 100644 --- a/rigs/kenwood/kenwood.h +++ b/rigs/kenwood/kenwood.h @@ -266,63 +266,63 @@ int get_kenwood_level(RIG *rig, const char *cmd, float *fval, int *ival); int get_kenwood_func(RIG *rig, const char *cmd, int *status); int get_kenwood_meter_reading(RIG *rig, char meter, int *pips); -extern const struct rig_caps ts950s_caps; -extern const struct rig_caps ts950sdx_caps; -extern const struct rig_caps ts50s_caps; -extern const struct rig_caps ts140_caps; -extern const struct rig_caps ts450s_caps; -extern const struct rig_caps ts570d_caps; -extern const struct rig_caps ts570s_caps; -extern const struct rig_caps ts680s_caps; -extern const struct rig_caps ts690s_caps; -extern const struct rig_caps ts790_caps; -extern const struct rig_caps ts850_caps; -extern const struct rig_caps ts870s_caps; -extern const struct rig_caps ts930_caps; -extern const struct rig_caps ts2000_caps; -extern const struct rig_caps k2_caps; -extern const struct rig_caps k3_caps; -extern const struct rig_caps k3s_caps; -extern const struct rig_caps kx2_caps; -extern const struct rig_caps kx3_caps; -extern const struct rig_caps k4_caps; -extern const struct rig_caps xg3_caps; -extern const struct rig_caps trc80_caps; +extern struct rig_caps ts950s_caps; +extern struct rig_caps ts950sdx_caps; +extern struct rig_caps ts50s_caps; +extern struct rig_caps ts140_caps; +extern struct rig_caps ts450s_caps; +extern struct rig_caps ts570d_caps; +extern struct rig_caps ts570s_caps; +extern struct rig_caps ts680s_caps; +extern struct rig_caps ts690s_caps; +extern struct rig_caps ts790_caps; +extern struct rig_caps ts850_caps; +extern struct rig_caps ts870s_caps; +extern struct rig_caps ts930_caps; +extern struct rig_caps ts2000_caps; +extern struct rig_caps k2_caps; +extern struct rig_caps k3_caps; +extern struct rig_caps k3s_caps; +extern struct rig_caps kx2_caps; +extern struct rig_caps kx3_caps; +extern struct rig_caps k4_caps; +extern struct rig_caps xg3_caps; +extern struct rig_caps trc80_caps; -extern const struct rig_caps thd7a_caps; -extern const struct rig_caps thd72a_caps; -extern const struct rig_caps thd74_caps; -extern const struct rig_caps tmd700_caps; -extern const struct rig_caps thf7a_caps; -extern const struct rig_caps thf7e_caps; -extern const struct rig_caps thg71_caps; -extern const struct rig_caps tmv7_caps; -extern const struct rig_caps tmv71_caps; -extern const struct rig_caps tmd710_caps; +extern struct rig_caps thd7a_caps; +extern struct rig_caps thd72a_caps; +extern struct rig_caps thd74_caps; +extern struct rig_caps tmd700_caps; +extern struct rig_caps thf7a_caps; +extern struct rig_caps thf7e_caps; +extern struct rig_caps thg71_caps; +extern struct rig_caps tmv7_caps; +extern struct rig_caps tmv71_caps; +extern struct rig_caps tmd710_caps; -extern const struct rig_caps ts440_caps; -extern const struct rig_caps ts940_caps; -extern const struct rig_caps ts711_caps; -extern const struct rig_caps ts811_caps; -extern const struct rig_caps r5000_caps; +extern struct rig_caps ts440_caps; +extern struct rig_caps ts940_caps; +extern struct rig_caps ts711_caps; +extern struct rig_caps ts811_caps; +extern struct rig_caps r5000_caps; -extern const struct rig_caps ts480_caps; -extern const struct rig_caps ts590_caps; -extern const struct rig_caps ts590sg_caps; -extern const struct rig_caps thf6a_caps; +extern struct rig_caps ts480_caps; +extern struct rig_caps ts590_caps; +extern struct rig_caps ts590sg_caps; +extern struct rig_caps thf6a_caps; -extern const struct rig_caps transfox_caps; +extern struct rig_caps transfox_caps; -extern const struct rig_caps f6k_caps; -extern const struct rig_caps powersdr_caps; -extern const struct rig_caps pihpsdr_caps; -extern const struct rig_caps ts890s_caps; -extern const struct rig_caps pt8000a_caps; -extern const struct rig_caps malachite_caps; -extern const struct rig_caps tx500_caps; -extern const struct rig_caps sdruno_caps; -extern const struct rig_caps qrplabs_caps; -extern const struct rig_caps fx4_caps; +extern struct rig_caps f6k_caps; +extern struct rig_caps powersdr_caps; +extern struct rig_caps pihpsdr_caps; +extern struct rig_caps ts890s_caps; +extern struct rig_caps pt8000a_caps; +extern struct rig_caps malachite_caps; +extern struct rig_caps tx500_caps; +extern struct rig_caps sdruno_caps; +extern struct rig_caps qrplabs_caps; +extern struct rig_caps fx4_caps; /* use when not interested in the answer, but want to check its len */ static int inline kenwood_simple_transaction(RIG *rig, const char *cmd, diff --git a/rigs/kenwood/pihpsdr.c b/rigs/kenwood/pihpsdr.c index 5922b5087..b802f3d5a 100644 --- a/rigs/kenwood/pihpsdr.c +++ b/rigs/kenwood/pihpsdr.c @@ -94,7 +94,7 @@ static struct kenwood_priv_caps ts2000_priv_caps = /* * PiHPSDR rig capabilities. (Emulates Kenwood TS-2000) */ -const struct rig_caps pihpsdr_caps = +struct rig_caps pihpsdr_caps = { RIG_MODEL(RIG_MODEL_HPSDR), .model_name = "PiHPSDR", @@ -122,7 +122,6 @@ const struct rig_caps pihpsdr_caps = .has_set_level = RIG_LEVEL_SET(PIHPSDR_LEVEL_ALL), .has_get_parm = RIG_PARM_NONE, .has_set_parm = RIG_PARM_NONE, /* FIXME: parms */ - .level_gran = {}, /* FIXME: granularity */ .parm_gran = {}, .vfo_ops = PIHPSDR_VFO_OP, .scan_ops = PIHPSDR_SCAN_OP, @@ -833,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/r5000.c b/rigs/kenwood/r5000.c index b9041db2c..324ff87b8 100644 --- a/rigs/kenwood/r5000.c +++ b/rigs/kenwood/r5000.c @@ -53,7 +53,7 @@ static struct kenwood_priv_caps r5000_priv_caps = * * TODO: scan, get/set_channel, RIT */ -const struct rig_caps r5000_caps = +struct rig_caps r5000_caps = { RIG_MODEL(RIG_MODEL_R5000), .model_name = "R-5000", diff --git a/rigs/kenwood/th.c b/rigs/kenwood/th.c index 3a72d5e83..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) { @@ -1392,7 +1392,7 @@ int th_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) int th_set_ctcss_tone(RIG *rig, vfo_t vfo, tone_t tone) { - const struct rig_caps *caps; + struct rig_caps *caps; char tonebuf[16]; int i; @@ -1470,7 +1470,7 @@ th_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) int th_set_ctcss_sql(RIG *rig, vfo_t vfo, tone_t tone) { - const struct rig_caps *caps; + struct rig_caps *caps; char tonebuf[16]; int i; @@ -1552,7 +1552,7 @@ th_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) int th_set_dcs_sql(RIG *rig, vfo_t vfo, tone_t code) { - const struct rig_caps *caps; + struct rig_caps *caps; char codebuf[16]; int i, retval; diff --git a/rigs/kenwood/thd7.c b/rigs/kenwood/thd7.c index 4a6cb48ba..d8a60aeef 100644 --- a/rigs/kenwood/thd7.c +++ b/rigs/kenwood/thd7.c @@ -77,7 +77,7 @@ static struct kenwood_priv_caps thd7_priv_caps = * * http://www.qsl.net/ta1dx/kenwood/thd7kom.htm */ -const struct rig_caps thd7a_caps = +struct rig_caps thd7a_caps = { RIG_MODEL(RIG_MODEL_THD7A), .model_name = "TH-D7A", diff --git a/rigs/kenwood/thd72.c b/rigs/kenwood/thd72.c index f53a0a67d..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 @@ -1644,7 +1652,7 @@ int thd72_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) /* * th-d72a rig capabilities. */ -const struct rig_caps thd72a_caps = +struct rig_caps thd72a_caps = { RIG_MODEL(RIG_MODEL_THD72A), .model_name = "TH-D72A", diff --git a/rigs/kenwood/thd74.c b/rigs/kenwood/thd74.c index a46a892aa..01b5e89b3 100644 --- a/rigs/kenwood/thd74.c +++ b/rigs/kenwood/thd74.c @@ -1644,7 +1644,7 @@ int thd74_get_chan_all_cb(RIG *rig, chan_cb_t chan_cb, rig_ptr_t arg) /* * th-d74 rig capabilities. */ -const struct rig_caps thd74_caps = +struct rig_caps thd74_caps = { RIG_MODEL(RIG_MODEL_THD74), .model_name = "TH-D74", diff --git a/rigs/kenwood/thf6a.c b/rigs/kenwood/thf6a.c index 4f1a07bc6..7b1bdacf8 100644 --- a/rigs/kenwood/thf6a.c +++ b/rigs/kenwood/thf6a.c @@ -112,7 +112,7 @@ static int thf6a_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op); * - set/get_ctcss_tone/sql through set/get_channel() and VR/VW * - emulate RIG_FUNC_TONE|RIG_FUNC_TSQL by setting ctcss_tone/sql to 0/non zero? */ -const struct rig_caps thf6a_caps = +struct rig_caps thf6a_caps = { RIG_MODEL(RIG_MODEL_THF6A), .model_name = "TH-F6A", diff --git a/rigs/kenwood/thf7.c b/rigs/kenwood/thf7.c index a9f74d276..68520cb39 100644 --- a/rigs/kenwood/thf7.c +++ b/rigs/kenwood/thf7.c @@ -106,7 +106,7 @@ static int thf7e_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op); * - set/get_ctcss_tone/sql through set/get_channel() and VR/VW * - emulate RIG_FUNC_TONE|RIG_FUNC_TSQL by setting ctcss_tone/sql to 0/non zero? */ -const struct rig_caps thf7e_caps = +struct rig_caps thf7e_caps = { RIG_MODEL(RIG_MODEL_THF7E), .model_name = "TH-F7E", diff --git a/rigs/kenwood/thg71.c b/rigs/kenwood/thg71.c index 016c1a5cf..57302725c 100644 --- a/rigs/kenwood/thg71.c +++ b/rigs/kenwood/thg71.c @@ -80,7 +80,7 @@ static int thg71_set_func(RIG *rig, vfo_t vfo, setting_t func, int status); * * http://www.iw5edi.com/ham-radio/files/TH-G71_Serial_Protocol.pdf */ -const struct rig_caps thg71_caps = +struct rig_caps thg71_caps = { RIG_MODEL(RIG_MODEL_THG71), .model_name = "TH-G71", diff --git a/rigs/kenwood/tmd700.c b/rigs/kenwood/tmd700.c index 5df1ac358..abac90100 100644 --- a/rigs/kenwood/tmd700.c +++ b/rigs/kenwood/tmd700.c @@ -88,7 +88,7 @@ static struct kenwood_priv_caps tmd700_priv_caps = * specs: http://www.geocities.jp/hkwatarin/TM-D700/English/spec.htm * protocol: http://www.qsl.net/k/k7jar//pages/D700Cmds.html */ -const struct rig_caps tmd700_caps = +struct rig_caps tmd700_caps = { RIG_MODEL(RIG_MODEL_TMD700), .model_name = "TM-D700", diff --git a/rigs/kenwood/tmd710.c b/rigs/kenwood/tmd710.c index 2fdb385aa..64d99cbbf 100644 --- a/rigs/kenwood/tmd710.c +++ b/rigs/kenwood/tmd710.c @@ -250,7 +250,7 @@ const struct confparams tmd710_ext_levels[] = { RIG_CONF_END, NULL, } }; -const struct rig_caps tmd710_caps = +struct rig_caps tmd710_caps = { .rig_model = RIG_MODEL_TMD710, .model_name = "TM-D710(G)", @@ -408,7 +408,7 @@ const struct rig_caps tmd710_caps = .decode_event = th_decode_event, }; -const struct rig_caps tmv71_caps = +struct rig_caps tmv71_caps = { RIG_MODEL(RIG_MODEL_TMV71), .model_name = "TM-V71(A)", @@ -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, @@ -1367,7 +1367,7 @@ int tmd710_get_ctcss_tone(RIG *rig, vfo_t vfo, tone_t *tone) tmd710_fo fo_struct; int retval; - const struct rig_caps *caps; + struct rig_caps *caps; caps = rig->caps; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -1421,7 +1421,7 @@ int tmd710_get_ctcss_sql(RIG *rig, vfo_t vfo, tone_t *tone) tmd710_fo fo_struct; int retval; - const struct rig_caps *caps; + struct rig_caps *caps; caps = rig->caps; rig_debug(RIG_DEBUG_TRACE, "%s: called\n", __func__); @@ -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/tmv7.c b/rigs/kenwood/tmv7.c index 92fc8272e..06899d424 100644 --- a/rigs/kenwood/tmv7.c +++ b/rigs/kenwood/tmv7.c @@ -89,7 +89,7 @@ static int tmv7_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan); /* * tm-v7 rig capabilities. */ -const struct rig_caps tmv7_caps = +struct rig_caps tmv7_caps = { RIG_MODEL(RIG_MODEL_TMV7), .model_name = "TM-V7", diff --git a/rigs/kenwood/transfox.c b/rigs/kenwood/transfox.c index 289add0d2..ccdafb88d 100644 --- a/rigs/kenwood/transfox.c +++ b/rigs/kenwood/transfox.c @@ -63,7 +63,7 @@ static int transfox_get_level(RIG *rig, vfo_t vfo, setting_t level, * * Part of info comes from http://www.sigfox-system.com/TransFox-FE?lang=en */ -const struct rig_caps transfox_caps = +struct rig_caps transfox_caps = { RIG_MODEL(RIG_MODEL_TRANSFOX), .model_name = "Transfox", diff --git a/rigs/kenwood/trc80.c b/rigs/kenwood/trc80.c index 0b353c055..c6872330d 100644 --- a/rigs/kenwood/trc80.c +++ b/rigs/kenwood/trc80.c @@ -60,7 +60,7 @@ static struct kenwood_priv_caps trc80_priv_caps = /* * TRC-80/TK-80 rig capabilities. */ -const struct rig_caps trc80_caps = +struct rig_caps trc80_caps = { RIG_MODEL(RIG_MODEL_TRC80), .model_name = "TRC-80", diff --git a/rigs/kenwood/ts140.c b/rigs/kenwood/ts140.c index 2fd411591..884f841d0 100644 --- a/rigs/kenwood/ts140.c +++ b/rigs/kenwood/ts140.c @@ -76,7 +76,7 @@ static int ts140_set_vfo(RIG *rig, vfo_t vfo) * GW0VNR 09042006 */ -const struct rig_caps ts140_caps = +struct rig_caps ts140_caps = { RIG_MODEL(RIG_MODEL_TS140S), .model_name = "TS-140S", diff --git a/rigs/kenwood/ts2000.c b/rigs/kenwood/ts2000.c index 9e62a0817..bf98856dd 100644 --- a/rigs/kenwood/ts2000.c +++ b/rigs/kenwood/ts2000.c @@ -1671,7 +1671,7 @@ int ts2000_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan) /* * TS-2000 rig capabilities */ -const struct rig_caps ts2000_caps = +struct rig_caps ts2000_caps = { RIG_MODEL(RIG_MODEL_TS2000), .model_name = "TS-2000", @@ -1703,7 +1703,6 @@ const struct rig_caps ts2000_caps = .level_gran = { #include "level_gran_kenwood.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 30 }, .step = { .i = 1 } }, [LVL_KEYSPD] = {.min = {.i = 10}, .max = {.i = 60}, .step = {.i = 1}}, [LVL_CWPITCH] = {.min = {.i = 400}, .max = {.i = 1000}, .step = {.i = 50}}, diff --git a/rigs/kenwood/ts440.c b/rigs/kenwood/ts440.c index cebde83e1..b6c7d9f8d 100644 --- a/rigs/kenwood/ts440.c +++ b/rigs/kenwood/ts440.c @@ -53,7 +53,7 @@ static struct kenwood_priv_caps ts440_priv_caps = * .http = //www.ifrance.fr/clucas/modposte/ts440/mod440.htm * */ -const struct rig_caps ts440_caps = +struct rig_caps ts440_caps = { RIG_MODEL(RIG_MODEL_TS440), .model_name = "TS-440S", diff --git a/rigs/kenwood/ts450s.c b/rigs/kenwood/ts450s.c index 1a68566a1..6a5a43b4d 100644 --- a/rigs/kenwood/ts450s.c +++ b/rigs/kenwood/ts450s.c @@ -117,7 +117,7 @@ int ts450_open(RIG *rig) * specs: http://www.qsl.net/sm7vhs/radio/kenwood/ts450/specs.htm * infos comes from http://www.cnham.com/ts450/ts_450_ex_control.pdf */ -const struct rig_caps ts450s_caps = +struct rig_caps ts450s_caps = { RIG_MODEL(RIG_MODEL_TS450S), .model_name = "TS-450S", diff --git a/rigs/kenwood/ts480.c b/rigs/kenwood/ts480.c index d7f211021..96a904805 100644 --- a/rigs/kenwood/ts480.c +++ b/rigs/kenwood/ts480.c @@ -1244,7 +1244,7 @@ int qdx_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) * TS-480 rig capabilities * Notice that some rigs share the same functions. */ -const struct rig_caps ts480_caps = +struct rig_caps ts480_caps = { RIG_MODEL(RIG_MODEL_TS480), .model_name = "TS-480", @@ -1378,7 +1378,6 @@ const struct rig_caps ts480_caps = .level_gran = { #include "level_gran_kenwood.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 30 }, .step = { .i = 1 } }, [LVL_KEYSPD] = {.min = {.i = 10}, .max = {.i = 60}, .step = {.i = 1}}, [LVL_CWPITCH] = {.min = {.i = 400}, .max = {.i = 1000}, .step = {.i = 50}}, @@ -1443,7 +1442,7 @@ const struct rig_caps ts480_caps = * QRPLabs TS-480 emulation rig capabilities * Notice that some rigs share the same functions. */ -const struct rig_caps qrplabs_caps = +struct rig_caps qrplabs_caps = { RIG_MODEL(RIG_MODEL_QRPLABS), .model_name = "QCX/QDX", @@ -1577,7 +1576,6 @@ const struct rig_caps qrplabs_caps = .level_gran = { #include "level_gran_kenwood.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 30 }, .step = { .i = 1 } }, [LVL_KEYSPD] = {.min = {.i = 10}, .max = {.i = 60}, .step = {.i = 1}}, [LVL_CWPITCH] = {.min = {.i = 400}, .max = {.i = 1000}, .step = {.i = 50}}, @@ -1635,7 +1633,7 @@ const struct rig_caps qrplabs_caps = * Hilberling PS8000A TS480 emulation * Notice that some rigs share the same functions. */ -const struct rig_caps pt8000a_caps = +struct rig_caps pt8000a_caps = { RIG_MODEL(RIG_MODEL_PT8000A), .model_name = "PT-8000A", @@ -1757,7 +1755,6 @@ const struct rig_caps pt8000a_caps = .level_gran = { #include "level_gran_kenwood.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 30 }, .step = { .i = 1 } }, [LVL_KEYSPD] = {.min = {.i = 10}, .max = {.i = 60}, .step = {.i = 1}}, [LVL_CWPITCH] = {.min = {.i = 400}, .max = {.i = 1000}, .step = {.i = 50}}, @@ -1806,7 +1803,7 @@ const struct rig_caps pt8000a_caps = * SDRPlay SDRUno rig capabilities * Notice that some rigs share the same functions. */ -const struct rig_caps sdruno_caps = +struct rig_caps sdruno_caps = { RIG_MODEL(RIG_MODEL_SDRUNO), .model_name = "SDRUno", @@ -1938,7 +1935,6 @@ const struct rig_caps sdruno_caps = .vfo_ops = TS480_VFO_OPS, .level_gran = { #include "level_gran_kenwood.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, [LVL_VOXDELAY] = { .min = { .i = 0 }, .max = { .i = 30 }, .step = { .i = 1 } }, [LVL_KEYSPD] = {.min = {.i = 10}, .max = {.i = 60}, .step = {.i = 1}}, [LVL_CWPITCH] = {.min = {.i = 400}, .max = {.i = 1000}, .step = {.i = 50}}, @@ -2079,7 +2075,7 @@ int malachite_set_freq(RIG *rig, vfo_t vfo, freq_t freq) * Notice that some rigs share the same functions. * Also this struct is READONLY! */ -const struct rig_caps malachite_caps = +struct rig_caps malachite_caps = { RIG_MODEL(RIG_MODEL_MALACHITE), .model_name = "DSP", diff --git a/rigs/kenwood/ts50s.c b/rigs/kenwood/ts50s.c index 527aaab58..b2c7b1415 100644 --- a/rigs/kenwood/ts50s.c +++ b/rigs/kenwood/ts50s.c @@ -46,7 +46,7 @@ static struct kenwood_priv_caps ts50_priv_caps = * * part of infos comes from .http = //www.kenwood.net/ */ -const struct rig_caps ts50s_caps = +struct rig_caps ts50s_caps = { RIG_MODEL(RIG_MODEL_TS50), .model_name = "TS-50S", diff --git a/rigs/kenwood/ts570.c b/rigs/kenwood/ts570.c index 772599269..6e8df8b64 100644 --- a/rigs/kenwood/ts570.c +++ b/rigs/kenwood/ts570.c @@ -896,7 +896,7 @@ int ts570_set_xit(RIG *rig, vfo_t vfo, shortfreq_t rit) * * part of infos comes from .http = //www.kenwood.net/ */ -const struct rig_caps ts570s_caps = +struct rig_caps ts570s_caps = { RIG_MODEL(RIG_MODEL_TS570S), .model_name = "TS-570S", @@ -1083,7 +1083,7 @@ const struct rig_caps ts570s_caps = * * part of infos comes from .http = //www.kenwood.net/ */ -const struct rig_caps ts570d_caps = +struct rig_caps ts570d_caps = { RIG_MODEL(RIG_MODEL_TS570D), .model_name = "TS-570D", diff --git a/rigs/kenwood/ts590.c b/rigs/kenwood/ts590.c index 9a4c1dc48..e2cf81415 100644 --- a/rigs/kenwood/ts590.c +++ b/rigs/kenwood/ts590.c @@ -44,7 +44,7 @@ #define TS590_LEVEL_SET (RIG_LEVEL_RFPOWER|RIG_LEVEL_AF|RIG_LEVEL_RF|RIG_LEVEL_SQL|RIG_LEVEL_AGC|RIG_LEVEL_MICGAIN|RIG_LEVEL_KEYSPD|RIG_LEVEL_CWPITCH| \ RIG_LEVEL_MONITOR_GAIN|RIG_LEVEL_NB|RIG_LEVEL_NR|RIG_LEVEL_PREAMP|RIG_LEVEL_COMP|RIG_LEVEL_ATT|RIG_LEVEL_VOXDELAY|RIG_LEVEL_VOXGAIN|RIG_LEVEL_BKIN_DLYMS| \ - RIG_LEVEL_METER|RIG_LEVEL_SLOPE_HIGH|RIG_LEVEL_SLOPE_LOW|RIG_LEVEL_USB_AF|RIG_LEVEL_USB_AF_INPUT) + RIG_LEVEL_METER|RIG_LEVEL_RFPOWER_METER_WATTS|RIG_LEVEL_SLOPE_HIGH|RIG_LEVEL_SLOPE_LOW|RIG_LEVEL_USB_AF|RIG_LEVEL_USB_AF_INPUT) #define TS590_FUNC_ALL (RIG_FUNC_NB|RIG_FUNC_COMP|RIG_FUNC_VOX|RIG_FUNC_NR|RIG_FUNC_NR|RIG_FUNC_BC|RIG_FUNC_BC2|RIG_FUNC_RIT|RIG_FUNC_XIT| \ RIG_FUNC_TUNER|RIG_FUNC_MON|RIG_FUNC_FBKIN|RIG_FUNC_LOCK) @@ -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; @@ -894,6 +908,7 @@ static int ts590_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) } case RIG_LEVEL_RFPOWER_METER: + case RIG_LEVEL_RFPOWER_METER_WATTS: { int raw_value; @@ -913,6 +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; } @@ -1567,12 +1588,12 @@ static struct kenwood_priv_caps ts590_priv_caps = /** * TS-590 rig capabilities */ -const struct rig_caps ts590_caps = +struct rig_caps ts590_caps = { RIG_MODEL(RIG_MODEL_TS590S), .model_name = "TS-590S", .mfg_name = "Kenwood", - .version = BACKEND_VER ".10", + .version = BACKEND_VER ".11", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, @@ -1765,7 +1786,7 @@ const struct rig_caps ts590_caps = * Supposed to be 590S compatible * Separate entry allows for customization */ -const struct rig_caps fx4_caps = +struct rig_caps fx4_caps = { RIG_MODEL(RIG_MODEL_FX4), .model_name = "FX4/C/CR/L", @@ -1959,12 +1980,12 @@ const struct rig_caps fx4_caps = /** * TS-590SG rig capabilities */ -const struct rig_caps ts590sg_caps = +struct rig_caps ts590sg_caps = { RIG_MODEL(RIG_MODEL_TS590SG), .model_name = "TS-590SG", .mfg_name = "Kenwood", - .version = BACKEND_VER ".7", + .version = BACKEND_VER ".8", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rig_type = RIG_TYPE_TRANSCEIVER, diff --git a/rigs/kenwood/ts680.c b/rigs/kenwood/ts680.c index 5bc778e25..48685eb7e 100644 --- a/rigs/kenwood/ts680.c +++ b/rigs/kenwood/ts680.c @@ -76,7 +76,7 @@ static int ts680_set_vfo(RIG *rig, vfo_t vfo) * GW0VNR 09042006 */ -const struct rig_caps ts680s_caps = +struct rig_caps ts680s_caps = { RIG_MODEL(RIG_MODEL_TS680S), .model_name = "TS-680S", diff --git a/rigs/kenwood/ts690.c b/rigs/kenwood/ts690.c index d6179e71c..26a130926 100644 --- a/rigs/kenwood/ts690.c +++ b/rigs/kenwood/ts690.c @@ -66,7 +66,7 @@ static struct kenwood_priv_caps ts690_priv_caps = * - how to set_split in vfo mode? * - ... */ -const struct rig_caps ts690s_caps = +struct rig_caps ts690s_caps = { RIG_MODEL(RIG_MODEL_TS690S), .model_name = "TS-690S", diff --git a/rigs/kenwood/ts711.c b/rigs/kenwood/ts711.c index fd572d720..6c0ebaef9 100644 --- a/rigs/kenwood/ts711.c +++ b/rigs/kenwood/ts711.c @@ -93,7 +93,7 @@ ts711_set_vfo(RIG *rig, vfo_t vfo) /* * ts711 rig capabilities. */ -const struct rig_caps ts711_caps = +struct rig_caps ts711_caps = { RIG_MODEL(RIG_MODEL_TS711), .model_name = "TS-711", diff --git a/rigs/kenwood/ts790.c b/rigs/kenwood/ts790.c index 8db9c89df..20d84196f 100644 --- a/rigs/kenwood/ts790.c +++ b/rigs/kenwood/ts790.c @@ -63,7 +63,7 @@ static struct kenwood_priv_caps ts790_priv_caps = * * part of infos comes from http://www.kenwood.net/ */ -const struct rig_caps ts790_caps = +struct rig_caps ts790_caps = { RIG_MODEL(RIG_MODEL_TS790), .model_name = "TS-790", diff --git a/rigs/kenwood/ts811.c b/rigs/kenwood/ts811.c index 00646cfb3..88edac4c1 100644 --- a/rigs/kenwood/ts811.c +++ b/rigs/kenwood/ts811.c @@ -79,7 +79,7 @@ ts811_set_vfo(RIG *rig, vfo_t vfo) /* * ts811 rig capabilities. */ -const struct rig_caps ts811_caps = +struct rig_caps ts811_caps = { RIG_MODEL(RIG_MODEL_TS811), .model_name = "TS-811", diff --git a/rigs/kenwood/ts850.c b/rigs/kenwood/ts850.c index 219e64847..f829934ee 100644 --- a/rigs/kenwood/ts850.c +++ b/rigs/kenwood/ts850.c @@ -96,7 +96,7 @@ static const struct confparams ts850_ext_parms[] = * Notice that some rigs share the same functions. * Also this struct is READONLY! */ -const struct rig_caps ts850_caps = +struct rig_caps ts850_caps = { RIG_MODEL(RIG_MODEL_TS850), .model_name = "TS-850", diff --git a/rigs/kenwood/ts870s.c b/rigs/kenwood/ts870s.c index da45bff2d..55e0550c6 100644 --- a/rigs/kenwood/ts870s.c +++ b/rigs/kenwood/ts870s.c @@ -533,7 +533,7 @@ static int ts870s_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val) * * part of infos comes from .http = //www.kenwood.net/ */ -const struct rig_caps ts870s_caps = +struct rig_caps ts870s_caps = { RIG_MODEL(RIG_MODEL_TS870S), .model_name = "TS-870S", @@ -565,7 +565,7 @@ const 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 f71d009fb..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; @@ -383,7 +391,7 @@ static struct kenwood_priv_caps ts890s_priv_caps = * Copied from ts480_caps, many of the values have not been verified. * Notice that some rigs share the same functions. */ -const struct rig_caps ts890s_caps = +struct rig_caps ts890s_caps = { RIG_MODEL(RIG_MODEL_TS890S), .model_name = "TS-890S", @@ -542,8 +550,8 @@ const 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 aa839acb0..72f3c9088 100644 --- a/rigs/kenwood/ts930.c +++ b/rigs/kenwood/ts930.c @@ -48,7 +48,7 @@ static struct kenwood_priv_caps ts930_priv_caps = * * part of infos comes from .http = //www.kenwood.net/ */ -const struct rig_caps ts930_caps = +struct rig_caps ts930_caps = { RIG_MODEL(RIG_MODEL_TS930), .model_name = "TS-930", @@ -80,7 +80,7 @@ const 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/ts940.c b/rigs/kenwood/ts940.c index 7fb1b7e55..009691fa1 100644 --- a/rigs/kenwood/ts940.c +++ b/rigs/kenwood/ts940.c @@ -73,7 +73,7 @@ static struct kenwood_priv_caps ts940_priv_caps = * * TODO: protocol to be check with manual! */ -const struct rig_caps ts940_caps = +struct rig_caps ts940_caps = { RIG_MODEL(RIG_MODEL_TS940), .model_name = "TS-940S", diff --git a/rigs/kenwood/ts950.c b/rigs/kenwood/ts950.c index 79639a36c..69cbfac65 100644 --- a/rigs/kenwood/ts950.c +++ b/rigs/kenwood/ts950.c @@ -61,7 +61,7 @@ static struct kenwood_priv_caps ts950_priv_caps = * * Reference: TS-950 series External Control Instruction Manual (1992) */ -const struct rig_caps ts950s_caps = +struct rig_caps ts950s_caps = { RIG_MODEL(RIG_MODEL_TS950S), .model_name = "TS-950S", @@ -208,7 +208,7 @@ const struct rig_caps ts950s_caps = }; -const struct rig_caps ts950sdx_caps = +struct rig_caps ts950sdx_caps = { RIG_MODEL(RIG_MODEL_TS950SDX), .model_name = "TS-950SDX", diff --git a/rigs/kenwood/ts990s.c b/rigs/kenwood/ts990s.c index 112c3cba3..c5fc7eb5a 100644 --- a/rigs/kenwood/ts990s.c +++ b/rigs/kenwood/ts990s.c @@ -128,7 +128,7 @@ static struct kenwood_priv_caps ts990s_priv_caps = * * part of infos comes from http://www.kenwood.net/ */ -const struct rig_caps ts990s_caps = +struct rig_caps ts990s_caps = { RIG_MODEL(RIG_MODEL_TS990S), .model_name = "TS-990S", @@ -162,7 +162,7 @@ const 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/kenwood/ts990s.h b/rigs/kenwood/ts990s.h index 9245beac7..4c6b12090 100644 --- a/rigs/kenwood/ts990s.h +++ b/rigs/kenwood/ts990s.h @@ -24,6 +24,6 @@ #include "hamlib/rig.h" -extern const struct rig_caps ts990s_caps; +extern struct rig_caps ts990s_caps; #endif diff --git a/rigs/kenwood/tx500.c b/rigs/kenwood/tx500.c index c1e494ee2..260016e34 100644 --- a/rigs/kenwood/tx500.c +++ b/rigs/kenwood/tx500.c @@ -121,7 +121,7 @@ static struct kenwood_priv_caps tx500_priv_caps = * TX-500 rig capabilities. * */ -const struct rig_caps tx500_caps = +struct rig_caps tx500_caps = { RIG_MODEL(RIG_MODEL_LAB599_TX500), .model_name = "TX-500", diff --git a/rigs/kenwood/xg3.c b/rigs/kenwood/xg3.c index 3b0fb9b7d..4a149e2c7 100644 --- a/rigs/kenwood/xg3.c +++ b/rigs/kenwood/xg3.c @@ -100,7 +100,7 @@ int xg3_get_parm(RIG *rig, setting_t parm, value_t *val); * Part of info comes from http://www.elecraft.com/K2_Manual_Download_Page.htm#K2 * look for KIO2 Programmer's Reference PDF */ -const struct rig_caps xg3_caps = +struct rig_caps xg3_caps = { RIG_MODEL(RIG_MODEL_XG3), .model_name = "XG3", diff --git a/rigs/kit/dds60.c b/rigs/kit/dds60.c index a8a838d57..ccd6acb38 100644 --- a/rigs/kit/dds60.c +++ b/rigs/kit/dds60.c @@ -93,7 +93,7 @@ static int dds60_get_conf(RIG *rig, token_t token, char *val); * The receiver is controlled via the parallel port (D0,D1,D2). */ -const struct rig_caps dds60_caps = +struct rig_caps dds60_caps = { RIG_MODEL(RIG_MODEL_DDS60), .model_name = "DDS-60", diff --git a/rigs/kit/drt1.c b/rigs/kit/drt1.c index b177bbc32..2780e9c5d 100644 --- a/rigs/kit/drt1.c +++ b/rigs/kit/drt1.c @@ -88,7 +88,7 @@ static int drt1_get_conf(RIG *rig, token_t token, char *val); * The receiver is controlled via the TX, RTS and DTR pins of the serial port. */ -const struct rig_caps drt1_caps = +struct rig_caps drt1_caps = { RIG_MODEL(RIG_MODEL_DRT1), .model_name = "DRT1", diff --git a/rigs/kit/dwt.c b/rigs/kit/dwt.c index 9cc5d7c8d..f10e2b399 100644 --- a/rigs/kit/dwt.c +++ b/rigs/kit/dwt.c @@ -142,7 +142,7 @@ static const char *dwtdll_get_info(RIG *rig); * see Winradio G303 as an example */ -const struct rig_caps dwt_caps = +struct rig_caps dwt_caps = { RIG_MODEL(RIG_MODEL_DWT), .model_name = "Digital World Traveller", @@ -542,7 +542,7 @@ static const char *dwt_get_info(RIG *rig); * see dsbr100.c as an example */ -const struct rig_caps dwt_caps = +struct rig_caps dwt_caps = { RIG_MODEL(RIG_MODEL_DWT), .model_name = "Digital World Traveller", diff --git a/rigs/kit/elektor304.c b/rigs/kit/elektor304.c index 64e21465a..d676b9d82 100644 --- a/rigs/kit/elektor304.c +++ b/rigs/kit/elektor304.c @@ -80,7 +80,7 @@ static int elektor304_get_conf(RIG *rig, token_t token, char *val); * The receiver is controlled via the TX, RTS and DTR pins of the serial port. */ -const struct rig_caps elektor304_caps = +struct rig_caps elektor304_caps = { RIG_MODEL(RIG_MODEL_ELEKTOR304), .model_name = "Elektor 3/04", diff --git a/rigs/kit/elektor507.c b/rigs/kit/elektor507.c index 5afdd513e..5d095bd4d 100644 --- a/rigs/kit/elektor507.c +++ b/rigs/kit/elektor507.c @@ -553,7 +553,7 @@ int elektor507_ftdi_write_data(RIG *rig, void *FTOutBuf, * http://www.b-kainka.de/sdrusb.html */ -const struct rig_caps elektor507_caps = +struct rig_caps elektor507_caps = { RIG_MODEL(RIG_MODEL_ELEKTOR507), .model_name = "Elektor SDR-USB", @@ -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 1c86770e3..70e7c07bb 100644 --- a/rigs/kit/fifisdr.c +++ b/rigs/kit/fifisdr.c @@ -122,7 +122,7 @@ struct fifisdr_priv_instance_data /** FiFi-SDR receiver description. */ -const struct rig_caps fifisdr_caps = +struct rig_caps fifisdr_caps = { RIG_MODEL(RIG_MODEL_FIFISDR), .model_name = "FiFi-SDR", @@ -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 67bcd9a0e..0f28484ab 100644 --- a/rigs/kit/funcube.c +++ b/rigs/kit/funcube.c @@ -94,7 +94,7 @@ struct funcube_priv_data * */ -const struct rig_caps funcube_caps = +struct rig_caps funcube_caps = { RIG_MODEL(RIG_MODEL_FUNCUBEDONGLE), .model_name = "FUNcube Dongle", @@ -159,7 +159,7 @@ const struct rig_caps funcube_caps = }; -const struct rig_caps funcubeplus_caps = +struct rig_caps funcubeplus_caps = { RIG_MODEL(RIG_MODEL_FUNCUBEDONGLEPLUS), .model_name = "FUNcube Dongle Pro+", @@ -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 0ba1bfc89..0215d8f39 100644 --- a/rigs/kit/hiqsdr.c +++ b/rigs/kit/hiqsdr.c @@ -98,7 +98,7 @@ const struct confparams hiqsdr_cfg_params[] = #define HIQSDR_MODES (RIG_MODE_CW|RIG_MODE_DSB) -const struct rig_caps hiqsdr_caps = +struct rig_caps hiqsdr_caps = { RIG_MODEL(RIG_MODEL_HIQSDR), .model_name = "HiQSDR", @@ -188,7 +188,8 @@ const 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/kit.h b/rigs/kit/kit.h index 9aecf8c4b..8c59207c3 100644 --- a/rigs/kit/kit.h +++ b/rigs/kit/kit.h @@ -25,24 +25,24 @@ #include "hamlib/rig.h" #include "rotator.h" -extern const struct rig_caps elektor304_caps; -extern const struct rig_caps elektor507_caps; -extern const struct rig_caps si570avrusb_caps; -extern const struct rig_caps si570picusb_caps; -extern const struct rig_caps si570peaberry1_caps; -extern const struct rig_caps si570peaberry2_caps; -extern const struct rig_caps drt1_caps; -extern const struct rig_caps dwt_caps; -extern const struct rig_caps usrp0_caps; -extern const struct rig_caps usrp_caps; -extern const struct rig_caps dds60_caps; -extern const struct rig_caps miniVNA_caps; -extern const struct rig_caps funcube_caps; -extern const struct rig_caps funcubeplus_caps; -extern const struct rig_caps fifisdr_caps; -extern const struct rig_caps hiqsdr_caps; -extern const struct rig_caps fasdr_caps; -extern const struct rig_caps rshfiq_caps; +extern struct rig_caps elektor304_caps; +extern struct rig_caps elektor507_caps; +extern struct rig_caps si570avrusb_caps; +extern struct rig_caps si570picusb_caps; +extern struct rig_caps si570peaberry1_caps; +extern struct rig_caps si570peaberry2_caps; +extern struct rig_caps drt1_caps; +extern struct rig_caps dwt_caps; +extern struct rig_caps usrp0_caps; +extern struct rig_caps usrp_caps; +extern struct rig_caps dds60_caps; +extern struct rig_caps miniVNA_caps; +extern struct rig_caps funcube_caps; +extern struct rig_caps funcubeplus_caps; +extern struct rig_caps fifisdr_caps; +extern struct rig_caps hiqsdr_caps; +extern struct rig_caps fasdr_caps; +extern struct rig_caps rshfiq_caps; extern const struct rot_caps pcrotor_caps; diff --git a/rigs/kit/miniVNA.c b/rigs/kit/miniVNA.c index e2196218c..63ae146d5 100644 --- a/rigs/kit/miniVNA.c +++ b/rigs/kit/miniVNA.c @@ -54,7 +54,7 @@ static int miniVNA_set_freq(RIG *rig, vfo_t vfo, freq_t freq) return RIG_OK; } -const struct rig_caps miniVNA_caps = +struct rig_caps miniVNA_caps = { RIG_MODEL(RIG_MODEL_MINIVNA), .model_name = "miniVNA", diff --git a/rigs/kit/rs_hfiq.c b/rigs/kit/rs_hfiq.c index 8267971ac..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]; @@ -355,7 +356,7 @@ static int rshfiq_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) } -const struct rig_caps rshfiq_caps = +struct rig_caps rshfiq_caps = { RIG_MODEL(RIG_MODEL_RSHFIQ), .model_name = "RS-HFIQ", diff --git a/rigs/kit/si570avrusb.c b/rigs/kit/si570avrusb.c index 487656c1b..50e0ca89e 100644 --- a/rigs/kit/si570avrusb.c +++ b/rigs/kit/si570avrusb.c @@ -151,7 +151,7 @@ struct si570xxxusb_priv_data * */ -const struct rig_caps si570avrusb_caps = +struct rig_caps si570avrusb_caps = { RIG_MODEL(RIG_MODEL_SI570AVRUSB), .model_name = "Si570 AVR-USB", @@ -228,7 +228,7 @@ const struct rig_caps si570avrusb_caps = * Peaberry V1 * http://www.ae9rb.com */ -const struct rig_caps si570peaberry1_caps = +struct rig_caps si570peaberry1_caps = { RIG_MODEL(RIG_MODEL_SI570PEABERRY1), .model_name = "Si570 Peaberry V1", @@ -305,7 +305,7 @@ const struct rig_caps si570peaberry1_caps = * Peaberry V2 * http://www.ae9rb.com */ -const struct rig_caps si570peaberry2_caps = +struct rig_caps si570peaberry2_caps = { RIG_MODEL(RIG_MODEL_SI570PEABERRY2), .model_name = "Si570 Peaberry V2", @@ -387,7 +387,7 @@ const struct rig_caps si570peaberry2_caps = * * http://home.kpn.nl/rw.engberts/sdr_kth.htm */ -const struct rig_caps si570picusb_caps = +struct rig_caps si570picusb_caps = { RIG_MODEL(RIG_MODEL_SI570PICUSB), .model_name = "Si570 PIC-USB", @@ -468,7 +468,7 @@ const struct rig_caps si570picusb_caps = * ( BX- 200 ) */ -const struct rig_caps fasdr_caps = +struct rig_caps fasdr_caps = { RIG_MODEL(RIG_MODEL_FASDR), .model_name = "FA-SDR", @@ -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/kit/usrp.c b/rigs/kit/usrp.c index bf072d3b9..d389f2ca3 100644 --- a/rigs/kit/usrp.c +++ b/rigs/kit/usrp.c @@ -60,7 +60,7 @@ static const struct confparams usrp_cfg_params[] = * */ -const struct rig_caps usrp_caps = +struct rig_caps usrp_caps = { RIG_MODEL(RIG_MODEL_USRP), .model_name = "USRP", diff --git a/rigs/kit/usrp_impl.h b/rigs/kit/usrp_impl.h index 461f1d1a3..a29ecb19a 100644 --- a/rigs/kit/usrp_impl.h +++ b/rigs/kit/usrp_impl.h @@ -41,8 +41,8 @@ int usrp_get_conf(RIG *rig, token_t token, char *val); const char * usrp_get_info(RIG *rig); -extern const struct rig_caps usrp0_caps; -extern const struct rig_caps usrp_caps; +extern struct rig_caps usrp0_caps; +extern struct rig_caps usrp_caps; __END_DECLS diff --git a/rigs/lowe/hf235.c b/rigs/lowe/hf235.c index 961f59577..ad7426db2 100644 --- a/rigs/lowe/hf235.c +++ b/rigs/lowe/hf235.c @@ -43,7 +43,7 @@ * */ -const struct rig_caps hf235_caps = +struct rig_caps hf235_caps = { RIG_MODEL(RIG_MODEL_HF235), .model_name = "HF-235", diff --git a/rigs/lowe/lowe.h b/rigs/lowe/lowe.h index e628f718b..e1e2f4973 100644 --- a/rigs/lowe/lowe.h +++ b/rigs/lowe/lowe.h @@ -34,6 +34,6 @@ int lowe_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); int lowe_reset(RIG *rig, reset_t reset); const char *lowe_get_info(RIG *rig); -extern const struct rig_caps hf235_caps; +extern struct rig_caps hf235_caps; #endif /* _LOWE_H */ diff --git a/rigs/mds/4710.c b/rigs/mds/4710.c index 879bf38a3..d1cfacac7 100644 --- a/rigs/mds/4710.c +++ b/rigs/mds/4710.c @@ -1,6 +1,6 @@ #include "mds.h" -const struct rig_caps mds_4710_caps = +struct rig_caps mds_4710_caps = { RIG_MODEL(RIG_MODEL_MDS4710), .model_name = "4710", diff --git a/rigs/mds/9710.c b/rigs/mds/9710.c index f380dbc79..b83a8c6d2 100644 --- a/rigs/mds/9710.c +++ b/rigs/mds/9710.c @@ -1,6 +1,6 @@ #include "mds.h" -const struct rig_caps mds_9710_caps = +struct rig_caps mds_9710_caps = { RIG_MODEL(RIG_MODEL_MDS9710), .model_name = "9710", diff --git a/rigs/mds/mds.c b/rigs/mds/mds.c index 0ff267c6c..eda3796d9 100644 --- a/rigs/mds/mds.c +++ b/rigs/mds/mds.c @@ -32,8 +32,8 @@ #define MAXCMDLEN 32 -extern const struct rig_caps mds_4710_caps; -extern const struct rig_caps mds_9710_caps; +extern struct rig_caps mds_4710_caps; +extern struct rig_caps mds_9710_caps; DECLARE_INITRIG_BACKEND(mds) { @@ -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/mds/mds.h b/rigs/mds/mds.h index 2b985eb80..2274b97f8 100644 --- a/rigs/mds/mds.h +++ b/rigs/mds/mds.h @@ -15,8 +15,8 @@ struct mds_priv_data { char ret_data[MDS_RET_LEN]; /* returned data--max value, most are less */ }; -extern const struct rig_caps mds_4710_caps; -extern const struct rig_caps mds_9710_caps; +extern struct rig_caps mds_4710_caps; +extern struct rig_caps mds_9710_caps; int mds_init(RIG *rig); int mds_open(RIG *rig); 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/pcr/pcr.h b/rigs/pcr/pcr.h index 89714f1f1..9c35466e0 100644 --- a/rigs/pcr/pcr.h +++ b/rigs/pcr/pcr.h @@ -121,9 +121,9 @@ int pcr_get_dcd(RIG * rig, vfo_t vfo, dcd_t *dcd); // int pcr_get_param(RIG *rig, setting_t parm, value_t *val); // int pcr_set_param(RIG *rig, setting_t parm, value_t *val); -extern const struct rig_caps pcr1000_caps; -extern const struct rig_caps pcr100_caps; -extern const struct rig_caps pcr1500_caps; -extern const struct rig_caps pcr2500_caps; +extern struct rig_caps pcr1000_caps; +extern struct rig_caps pcr100_caps; +extern struct rig_caps pcr1500_caps; +extern struct rig_caps pcr2500_caps; #endif /* _PCR_H */ diff --git a/rigs/pcr/pcr100.c b/rigs/pcr/pcr100.c index 2bcd2c245..bb6a568e0 100644 --- a/rigs/pcr/pcr100.c +++ b/rigs/pcr/pcr100.c @@ -53,7 +53,7 @@ static const struct pcr_priv_caps pcr100_priv = /* * IC PCR100 rigs capabilities. */ -const struct rig_caps pcr100_caps = +struct rig_caps pcr100_caps = { RIG_MODEL(RIG_MODEL_PCR100), .model_name = "IC-PCR100", diff --git a/rigs/pcr/pcr1000.c b/rigs/pcr/pcr1000.c index db680eec1..398568204 100644 --- a/rigs/pcr/pcr1000.c +++ b/rigs/pcr/pcr1000.c @@ -46,7 +46,7 @@ static const struct pcr_priv_caps pcr1000_priv = /* * IC PCR1000 rigs capabilities. */ -const struct rig_caps pcr1000_caps = +struct rig_caps pcr1000_caps = { RIG_MODEL(RIG_MODEL_PCR1000), .model_name = "IC-PCR1000", diff --git a/rigs/pcr/pcr1500.c b/rigs/pcr/pcr1500.c index 4cb08a94f..1012353f7 100644 --- a/rigs/pcr/pcr1500.c +++ b/rigs/pcr/pcr1500.c @@ -49,7 +49,7 @@ static const struct pcr_priv_caps pcr1500_priv = /* * IC PCR1500 rigs capabilities. */ -const struct rig_caps pcr1500_caps = +struct rig_caps pcr1500_caps = { RIG_MODEL(RIG_MODEL_PCR1500), .model_name = "IC-PCR1500", diff --git a/rigs/pcr/pcr2500.c b/rigs/pcr/pcr2500.c index 520ab89db..c946991da 100644 --- a/rigs/pcr/pcr2500.c +++ b/rigs/pcr/pcr2500.c @@ -58,7 +58,7 @@ static const struct pcr_priv_caps pcr2500_priv = /* * IC PCR2500 rigs capabilities. */ -const struct rig_caps pcr2500_caps = +struct rig_caps pcr2500_caps = { RIG_MODEL(RIG_MODEL_PCR2500), .model_name = "IC-PCR2500", diff --git a/rigs/prm80/prm80.h b/rigs/prm80/prm80.h index 0984ea799..43efda3b5 100644 --- a/rigs/prm80/prm80.h +++ b/rigs/prm80/prm80.h @@ -65,6 +65,6 @@ int prm80_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt); const char *prm80_get_info(RIG *rig); -extern const struct rig_caps prm8060_caps; +extern struct rig_caps prm8060_caps; #endif /* _PRM80_H */ diff --git a/rigs/prm80/prm8060.c b/rigs/prm80/prm8060.c index c249c5dc3..2df73290f 100644 --- a/rigs/prm80/prm8060.c +++ b/rigs/prm80/prm8060.c @@ -61,7 +61,7 @@ * http://prm80.sourceforge.net/ * https://github.com/f4fez/prm80 */ -const struct rig_caps prm8060_caps = +struct rig_caps prm8060_caps = { RIG_MODEL(RIG_MODEL_PRM8060), .model_name = "PRM8060", diff --git a/rigs/racal/ra3702.c b/rigs/racal/ra3702.c index 3fbdb78e4..5ed8aa3b2 100644 --- a/rigs/racal/ra3702.c +++ b/rigs/racal/ra3702.c @@ -44,7 +44,7 @@ * Required A6A1 serial asynchronous interface * */ -const struct rig_caps ra3702_caps = +struct rig_caps ra3702_caps = { RIG_MODEL(RIG_MODEL_RA3702), .model_name = "RA3702", 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/racal/ra6790.c b/rigs/racal/ra6790.c index f82769b21..74817ece5 100644 --- a/rigs/racal/ra6790.c +++ b/rigs/racal/ra6790.c @@ -41,7 +41,7 @@ * Required A6A1 serial asynchronous interface * */ -const struct rig_caps ra6790_caps = +struct rig_caps ra6790_caps = { RIG_MODEL(RIG_MODEL_RA6790), .model_name = "RA6790/GM", diff --git a/rigs/racal/racal.h b/rigs/racal/racal.h index 863dda9c4..d8ea7c102 100644 --- a/rigs/racal/racal.h +++ b/rigs/racal/racal.h @@ -53,8 +53,8 @@ int racal_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); int racal_reset(RIG *rig, reset_t reset); const char* racal_get_info(RIG *rig); -extern const struct rig_caps ra6790_caps; -extern const struct rig_caps ra3702_caps; +extern struct rig_caps ra6790_caps; +extern struct rig_caps ra3702_caps; #endif /* _RACAL_H */ diff --git a/rigs/rft/ekd500.c b/rigs/rft/ekd500.c index cb0d7db66..70fb13525 100644 --- a/rigs/rft/ekd500.c +++ b/rigs/rft/ekd500.c @@ -45,7 +45,7 @@ * http://www.premium-rx.org/ekd500.htm */ -const struct rig_caps ekd500_caps = +struct rig_caps ekd500_caps = { RIG_MODEL(RIG_MODEL_EKD500), .model_name = "EKD-500", diff --git a/rigs/rft/rft.h b/rigs/rft/rft.h index 0b934710d..01b8834b3 100644 --- a/rigs/rft/rft.h +++ b/rigs/rft/rft.h @@ -28,6 +28,6 @@ int rft_set_freq(RIG *rig, vfo_t vfo, freq_t freq); -extern const struct rig_caps ekd500_caps; +extern struct rig_caps ekd500_caps; #endif /* _RFT_H */ diff --git a/rigs/rs/eb200.c b/rigs/rs/eb200.c index f1a2431a8..7ae7f0ad8 100644 --- a/rigs/rs/eb200.c +++ b/rigs/rs/eb200.c @@ -64,7 +64,7 @@ * - set_ant */ -const struct rig_caps eb200_caps = +struct rig_caps eb200_caps = { RIG_MODEL(RIG_MODEL_EB200), .model_name = "EB200", diff --git a/rigs/rs/ek89x.c b/rigs/rs/ek89x.c index 47409a47b..8b84df973 100644 --- a/rigs/rs/ek89x.c +++ b/rigs/rs/ek89x.c @@ -513,7 +513,7 @@ ek89x_get_info(RIG *rig) * - set/get_channels */ -const struct rig_caps ek89x_caps = +struct rig_caps ek89x_caps = { RIG_MODEL(RIG_MODEL_EK89X), .model_name = "EK895/6", diff --git a/rigs/rs/ek89x.h b/rigs/rs/ek89x.h index 58c86d3fe..24591be65 100644 --- a/rigs/rs/ek89x.h +++ b/rigs/rs/ek89x.h @@ -41,6 +41,6 @@ int ek89x_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); int ek89x_reset(RIG *rig, reset_t reset); const char * gek89x_get_info(RIG *rig); -extern const struct rig_caps ek89x_caps; +extern struct rig_caps ek89x_caps; #endif /* EK89X_H */ diff --git a/rigs/rs/esmc.c b/rigs/rs/esmc.c index d627b3d90..94dfea7f1 100644 --- a/rigs/rs/esmc.c +++ b/rigs/rs/esmc.c @@ -58,7 +58,7 @@ * http://www2.rohde-schwarz.com/file/ESMC_25.pdf */ -const struct rig_caps esmc_caps = +struct rig_caps esmc_caps = { RIG_MODEL(RIG_MODEL_ESMC), .model_name = "ESMC", diff --git a/rigs/rs/gp2000.h b/rigs/rs/gp2000.h index 848f1ca00..0e7e20ee9 100644 --- a/rigs/rs/gp2000.h +++ b/rigs/rs/gp2000.h @@ -43,6 +43,6 @@ int gp2000_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); int gp2000_reset(RIG *rig, reset_t reset); const char * gp2000_get_info(RIG *rig); -extern const struct rig_caps xk2100_caps; +extern struct rig_caps xk2100_caps; #endif /* XK2000_H */ diff --git a/rigs/rs/rs.h b/rigs/rs/rs.h index f7baa4477..729f1ddf5 100644 --- a/rigs/rs/rs.h +++ b/rigs/rs/rs.h @@ -37,7 +37,7 @@ int rs_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); int rs_reset(RIG *rig, reset_t reset); const char * rs_get_info(RIG *rig); -extern const struct rig_caps esmc_caps; -extern const struct rig_caps eb200_caps; +extern struct rig_caps esmc_caps; +extern struct rig_caps eb200_caps; #endif /* _RS_H */ diff --git a/rigs/rs/xk2100.c b/rigs/rs/xk2100.c index 2355be89f..c97dd04a4 100644 --- a/rigs/rs/xk2100.c +++ b/rigs/rs/xk2100.c @@ -66,7 +66,7 @@ * - set/get_channels */ -const struct rig_caps xk2100_caps = +struct rig_caps xk2100_caps = { RIG_MODEL(RIG_MODEL_XK2100), .model_name = "XK2100", diff --git a/rigs/skanti/skanti.h b/rigs/skanti/skanti.h index acf0ac4c2..4993900ef 100644 --- a/rigs/skanti/skanti.h +++ b/rigs/skanti/skanti.h @@ -34,7 +34,7 @@ int skanti_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val); int skanti_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt); int skanti_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op); -extern const struct rig_caps trp8000_caps; -extern const struct rig_caps trp8255_caps; +extern struct rig_caps trp8000_caps; +extern struct rig_caps trp8255_caps; #endif /* _SKANTI_H */ diff --git a/rigs/skanti/trp8000.c b/rigs/skanti/trp8000.c index 1c8bc6afa..1e45a1069 100644 --- a/rigs/skanti/trp8000.c +++ b/rigs/skanti/trp8000.c @@ -44,7 +44,7 @@ * * TODO: TUNING, BFO, SENSITIVITY(RF gain?) */ -const struct rig_caps trp8000_caps = +struct rig_caps trp8000_caps = { RIG_MODEL(RIG_MODEL_TRP8000), .model_name = "TRP8000", diff --git a/rigs/skanti/trp8255.c b/rigs/skanti/trp8255.c index 40ccb8d0b..c5b67f1c8 100644 --- a/rigs/skanti/trp8255.c +++ b/rigs/skanti/trp8255.c @@ -79,7 +79,7 @@ static int cu_vfo_op(RIG *rig, vfo_t vfo, vfo_op_t op); * because the TRP8255 has the "CU" (Control Unit). * */ -const struct rig_caps trp8255_caps = +struct rig_caps trp8255_caps = { RIG_MODEL(RIG_MODEL_TRP8255), .model_name = "TRP 8255 S R", diff --git a/rigs/tapr/dsp10.c b/rigs/tapr/dsp10.c index 9b8ade444..73094eab2 100644 --- a/rigs/tapr/dsp10.c +++ b/rigs/tapr/dsp10.c @@ -52,7 +52,7 @@ * * */ -const struct rig_caps dsp10_caps = +struct rig_caps dsp10_caps = { RIG_MODEL(RIG_MODEL_DSP10), .model_name = "DSP-10", diff --git a/rigs/tapr/tapr.h b/rigs/tapr/tapr.h index 10ccdecfe..7921766d2 100644 --- a/rigs/tapr/tapr.h +++ b/rigs/tapr/tapr.h @@ -28,6 +28,6 @@ int tapr_set_freq(RIG *rig, vfo_t vfo, freq_t freq); int tapr_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); -extern const struct rig_caps dsp10_caps; +extern struct rig_caps dsp10_caps; #endif /* _TAPR_H */ diff --git a/rigs/tentec/argonaut.c b/rigs/tentec/argonaut.c index 19f43fc6e..2a9c0ee8b 100644 --- a/rigs/tentec/argonaut.c +++ b/rigs/tentec/argonaut.c @@ -71,7 +71,7 @@ * http://www.rfsquared.com/ * */ -const struct rig_caps tt516_caps = +struct rig_caps tt516_caps = { RIG_MODEL(RIG_MODEL_TT516), .model_name = "TT-516 Argonaut V", diff --git a/rigs/tentec/jupiter.c b/rigs/tentec/jupiter.c index 230bb3243..cc056855a 100644 --- a/rigs/tentec/jupiter.c +++ b/rigs/tentec/jupiter.c @@ -123,7 +123,7 @@ static int tt538_set_func(RIG *rig, vfo_t vfo, setting_t func, int status); * Protocol is documented at * http://www.rfsquared.com/ */ -const struct rig_caps tt538_caps = +struct rig_caps tt538_caps = { RIG_MODEL(RIG_MODEL_TT538), .model_name = "TT-538 Jupiter", diff --git a/rigs/tentec/omnivii.c b/rigs/tentec/omnivii.c index ddf00ad56..c82830846 100644 --- a/rigs/tentec/omnivii.c +++ b/rigs/tentec/omnivii.c @@ -119,7 +119,7 @@ static int tt588_set_ant(RIG *rig, vfo_t vfo, ant_t ant); * * Protocol is documented at the tentec site */ -const struct rig_caps tt588_caps = +struct rig_caps tt588_caps = { RIG_MODEL(RIG_MODEL_TT588), .model_name = "TT-588 Omni VII", diff --git a/rigs/tentec/orion.h b/rigs/tentec/orion.h index 778a47f3d..f138c8d3d 100644 --- a/rigs/tentec/orion.h +++ b/rigs/tentec/orion.h @@ -196,7 +196,7 @@ struct tt565_priv_data { * Protocol is documented at Tentec's firmware site * http://www.rfsquared.com/ */ -const struct rig_caps tt565_caps = { +struct rig_caps tt565_caps = { RIG_MODEL(RIG_MODEL_TT565), .model_name = "TT-565 Orion", .mfg_name = "Ten-Tec", @@ -414,7 +414,7 @@ RIG_MODEL(RIG_MODEL_TT565), * http://www.tentec.com/index.php?id=360#down * */ -const struct rig_caps tt599_caps = { +struct rig_caps tt599_caps = { RIG_MODEL(RIG_MODEL_TT599), .model_name = "TT-599 Eagle", .mfg_name = "Ten-Tec", diff --git a/rigs/tentec/paragon.c b/rigs/tentec/paragon.c index cb639b8db..10a8949cc 100644 --- a/rigs/tentec/paragon.c +++ b/rigs/tentec/paragon.c @@ -92,7 +92,7 @@ static int tt585_get_status_data(RIG *rig); * tt585 transceiver capabilities, * with the optional model 258 RS232 Interface board. */ -const struct rig_caps tt585_caps = +struct rig_caps tt585_caps = { RIG_MODEL(RIG_MODEL_TT585), .model_name = "TT-585 Paragon", diff --git a/rigs/tentec/pegasus.c b/rigs/tentec/pegasus.c index d3f8753c2..fb664a7c0 100644 --- a/rigs/tentec/pegasus.c +++ b/rigs/tentec/pegasus.c @@ -60,7 +60,7 @@ * * TODO: */ -const struct rig_caps tt550_caps = +struct rig_caps tt550_caps = { RIG_MODEL(RIG_MODEL_TT550), .model_name = "TT-550", diff --git a/rigs/tentec/rx320.c b/rigs/tentec/rx320.c index 060e86190..b84deac38 100644 --- a/rigs/tentec/rx320.c +++ b/rigs/tentec/rx320.c @@ -66,7 +66,7 @@ * * TODO: */ -const struct rig_caps rx320_caps = +struct rig_caps rx320_caps = { RIG_MODEL(RIG_MODEL_RX320), .model_name = "RX-320", diff --git a/rigs/tentec/rx331.c b/rigs/tentec/rx331.c index 8b9e038e6..9afa54a75 100644 --- a/rigs/tentec/rx331.c +++ b/rigs/tentec/rx331.c @@ -88,7 +88,7 @@ static const char *rx331_get_info(RIG *rig); * * TODO: from/to memory */ -const struct rig_caps rx331_caps = +struct rig_caps rx331_caps = { RIG_MODEL(RIG_MODEL_RX331), .model_name = "RX-331", diff --git a/rigs/tentec/rx340.c b/rigs/tentec/rx340.c index 6ee0bec70..604253e84 100644 --- a/rigs/tentec/rx340.c +++ b/rigs/tentec/rx340.c @@ -77,7 +77,7 @@ static const char *rx340_get_info(RIG *rig); * TODO: from/to memory, scan, get_level, .. * supposes non-multidrop */ -const struct rig_caps rx340_caps = +struct rig_caps rx340_caps = { RIG_MODEL(RIG_MODEL_RX340), .model_name = "RX-340", diff --git a/rigs/tentec/rx350.c b/rigs/tentec/rx350.c index c3904a650..3322bec76 100644 --- a/rigs/tentec/rx350.c +++ b/rigs/tentec/rx350.c @@ -75,7 +75,7 @@ * Only set_freq is supposed to work. * This is a skeleton. */ -const struct rig_caps rx350_caps = +struct rig_caps rx350_caps = { RIG_MODEL(RIG_MODEL_RX350), .model_name = "RX-350", 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/tentec/tentec.h b/rigs/tentec/tentec.h index 2989d1b3f..9e48697f5 100644 --- a/rigs/tentec/tentec.h +++ b/rigs/tentec/tentec.h @@ -70,17 +70,17 @@ 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 char* tentec_get_info(RIG *rig); -extern const struct rig_caps rx320_caps; -extern const struct rig_caps rx340_caps; -extern const struct rig_caps rx350_caps; -extern const struct rig_caps tt516_caps; -extern const struct rig_caps tt538_caps; -extern const struct rig_caps tt585_caps; -extern const struct rig_caps tt588_caps; -extern const struct rig_caps tt550_caps; -extern const struct rig_caps tt565_caps; -extern const struct rig_caps tt599_caps; -extern const struct rig_caps rx331_caps; +extern struct rig_caps rx320_caps; +extern struct rig_caps rx340_caps; +extern struct rig_caps rx350_caps; +extern struct rig_caps tt516_caps; +extern struct rig_caps tt538_caps; +extern struct rig_caps tt585_caps; +extern struct rig_caps tt588_caps; +extern struct rig_caps tt550_caps; +extern struct rig_caps tt565_caps; +extern struct rig_caps tt599_caps; +extern struct rig_caps rx331_caps; #endif /* _TENTEC_H */ diff --git a/rigs/tuner/tuner.h b/rigs/tuner/tuner.h index 883bd4c77..fd02dd92a 100644 --- a/rigs/tuner/tuner.h +++ b/rigs/tuner/tuner.h @@ -33,7 +33,7 @@ #include "hamlib/rig.h" -extern const struct rig_caps v4l_caps; -extern const struct rig_caps v4l2_caps; +extern struct rig_caps v4l_caps; +extern struct rig_caps v4l2_caps; #endif /* _TUNER_H */ diff --git a/rigs/tuner/v4l.c b/rigs/tuner/v4l.c index 888c3517c..4f2345626 100644 --- a/rigs/tuner/v4l.c +++ b/rigs/tuner/v4l.c @@ -63,7 +63,7 @@ static const char *v4l_get_info(RIG *rig); * * */ -const struct rig_caps v4l_caps = +struct rig_caps v4l_caps = { RIG_MODEL(RIG_MODEL_V4L), .model_name = "SW/FM radio", diff --git a/rigs/tuner/v4l2.c b/rigs/tuner/v4l2.c index 868f1821d..5bd53d6ec 100644 --- a/rigs/tuner/v4l2.c +++ b/rigs/tuner/v4l2.c @@ -63,7 +63,7 @@ static const char *v4l2_get_info(RIG *rig); * * */ -const struct rig_caps v4l2_caps = +struct rig_caps v4l2_caps = { RIG_MODEL(RIG_MODEL_V4L2), .model_name = "SW/FM radio", diff --git a/rigs/uniden/bc245.c b/rigs/uniden/bc245.c index ab6e49c44..40a96dd46 100644 --- a/rigs/uniden/bc245.c +++ b/rigs/uniden/bc245.c @@ -41,7 +41,7 @@ * * TODO: check this with manual or web site. */ -const struct rig_caps bc245_caps = +struct rig_caps bc245_caps = { RIG_MODEL(RIG_MODEL_BC245), .model_name = "BC245xlt", diff --git a/rigs/uniden/bc250.c b/rigs/uniden/bc250.c index b6002cb9e..bcfc89754 100644 --- a/rigs/uniden/bc250.c +++ b/rigs/uniden/bc250.c @@ -50,7 +50,7 @@ * * TODO: check this with manual or web site. */ -const struct rig_caps bc250_caps = +struct rig_caps bc250_caps = { RIG_MODEL(RIG_MODEL_BC250), .model_name = "BC250D", diff --git a/rigs/uniden/bc780.c b/rigs/uniden/bc780.c index f4d75c3f4..4a826b1db 100644 --- a/rigs/uniden/bc780.c +++ b/rigs/uniden/bc780.c @@ -50,7 +50,7 @@ * * TODO: check this with manual or web site. */ -const struct rig_caps bc780_caps = +struct rig_caps bc780_caps = { RIG_MODEL(RIG_MODEL_BC780), .model_name = "BC780xlt", diff --git a/rigs/uniden/bc895.c b/rigs/uniden/bc895.c index bb19ad8e4..46709c980 100644 --- a/rigs/uniden/bc895.c +++ b/rigs/uniden/bc895.c @@ -56,7 +56,7 @@ * * TODO: check this with manual or web site. */ -const struct rig_caps bc895_caps = +struct rig_caps bc895_caps = { RIG_MODEL(RIG_MODEL_BC895), .model_name = "BC895xlt", diff --git a/rigs/uniden/bc898.c b/rigs/uniden/bc898.c index b199ddd31..bbbc30985 100644 --- a/rigs/uniden/bc898.c +++ b/rigs/uniden/bc898.c @@ -67,7 +67,7 @@ static tone_t bc898_ctcss_list[] = * TODO: check this with manual or web site. * http://www.uniden.com/products/productdetail.cfm?product=BC898T&filter=Mobile */ -const struct rig_caps bc898_caps = +struct rig_caps bc898_caps = { RIG_MODEL(RIG_MODEL_BC898), .model_name = "BC898T", diff --git a/rigs/uniden/bcd396t.c b/rigs/uniden/bcd396t.c index b36b80e65..01c17553f 100644 --- a/rigs/uniden/bcd396t.c +++ b/rigs/uniden/bcd396t.c @@ -48,7 +48,7 @@ * * TODO: check this with manual or web site. */ -const struct rig_caps bcd396t_caps = +struct rig_caps bcd396t_caps = { RIG_MODEL(RIG_MODEL_BCD396T), .model_name = "BCD-396T", diff --git a/rigs/uniden/bcd996t.c b/rigs/uniden/bcd996t.c index 9a494dce4..385b81055 100644 --- a/rigs/uniden/bcd996t.c +++ b/rigs/uniden/bcd996t.c @@ -48,7 +48,7 @@ * * TODO: check this with manual or web site. */ -const struct rig_caps bcd996t_caps = +struct rig_caps bcd996t_caps = { RIG_MODEL(RIG_MODEL_BCD996T), .model_name = "BCD-996T", diff --git a/rigs/uniden/pro2052.c b/rigs/uniden/pro2052.c index 42971f109..b35b30703 100644 --- a/rigs/uniden/pro2052.c +++ b/rigs/uniden/pro2052.c @@ -53,7 +53,7 @@ * * TODO: check this with manual or web site. */ -const struct rig_caps pro2052_caps = +struct rig_caps pro2052_caps = { RIG_MODEL(RIG_MODEL_PRO2052), .model_name = "PRO-2052", 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/uniden/uniden.h b/rigs/uniden/uniden.h index e5cc7d63d..085e25c25 100644 --- a/rigs/uniden/uniden.h +++ b/rigs/uniden/uniden.h @@ -71,14 +71,14 @@ int uniden_get_channel(RIG *rig, vfo_t vfo, channel_t *chan, int read_only); int uniden_set_channel(RIG *rig, vfo_t vfo, const channel_t *chan); const char* uniden_get_info(RIG *rig); -extern const struct rig_caps bc895_caps; -extern const struct rig_caps bc898_caps; -extern const struct rig_caps bc245_caps; -extern const struct rig_caps bc780_caps; -extern const struct rig_caps bc250_caps; -extern const struct rig_caps pro2052_caps; +extern struct rig_caps bc895_caps; +extern struct rig_caps bc898_caps; +extern struct rig_caps bc245_caps; +extern struct rig_caps bc780_caps; +extern struct rig_caps bc250_caps; +extern struct rig_caps pro2052_caps; -extern const struct rig_caps bcd396t_caps; -extern const struct rig_caps bcd996t_caps; +extern struct rig_caps bcd396t_caps; +extern struct rig_caps bcd996t_caps; #endif /* _UNIDEN_H */ diff --git a/rigs/winradio/g303.c b/rigs/winradio/g303.c index 96f1ef8c7..6fcd1a793 100644 --- a/rigs/winradio/g303.c +++ b/rigs/winradio/g303.c @@ -120,7 +120,7 @@ struct g3_priv_data }; -const struct rig_caps g303_caps = +struct rig_caps g303_caps = { RIG_MODEL(RIG_MODEL_G303), .model_name = "WR-G303", diff --git a/rigs/winradio/g305.c b/rigs/winradio/g305.c index 92abc1dfb..d962d41fe 100644 --- a/rigs/winradio/g305.c +++ b/rigs/winradio/g305.c @@ -121,7 +121,7 @@ struct g3_priv_data }; -const struct rig_caps g305_caps = +struct rig_caps g305_caps = { RIG_MODEL(RIG_MODEL_G305), .model_name = "WR-G305", diff --git a/rigs/winradio/g313-posix.c b/rigs/winradio/g313-posix.c index 6903011b7..a79787f7a 100644 --- a/rigs/winradio/g313-posix.c +++ b/rigs/winradio/g313-posix.c @@ -643,7 +643,7 @@ static void g313_spectrum_callback(float *buffer, int count, void *arg) #pragma GCC diagnostic pop } -const struct rig_caps g313_caps = +struct rig_caps g313_caps = { RIG_MODEL(RIG_MODEL_G313), .model_name = "WR-G313", diff --git a/rigs/winradio/g313-win.c b/rigs/winradio/g313-win.c index 1c32faf72..f4916d318 100644 --- a/rigs/winradio/g313-win.c +++ b/rigs/winradio/g313-win.c @@ -157,7 +157,7 @@ struct g313_priv_data }; -const struct rig_caps g313_caps = +struct rig_caps g313_caps = { RIG_MODEL(RIG_MODEL_G313), .model_name = "WR-G313", diff --git a/rigs/winradio/winradio.h b/rigs/winradio/winradio.h index 1f6766b6d..57e609e2b 100644 --- a/rigs/winradio/winradio.h +++ b/rigs/winradio/winradio.h @@ -48,17 +48,17 @@ int wr_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val); int wr_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); const char *wr_get_info(RIG *rig); -extern const struct rig_caps wr1000_caps; -extern const struct rig_caps wr1500_caps; -extern const struct rig_caps wr1550_caps; -extern const struct rig_caps wr3100_caps; -extern const struct rig_caps wr3150_caps; -extern const struct rig_caps wr3500_caps; -extern const struct rig_caps wr3700_caps; -extern const struct rig_caps g303_caps; -extern const struct rig_caps g305_caps; +extern struct rig_caps wr1000_caps; +extern struct rig_caps wr1500_caps; +extern struct rig_caps wr1550_caps; +extern struct rig_caps wr3100_caps; +extern struct rig_caps wr3150_caps; +extern struct rig_caps wr3500_caps; +extern struct rig_caps wr3700_caps; +extern struct rig_caps g303_caps; +extern struct rig_caps g305_caps; #if defined( _WIN32) || !defined(OTHER_POSIX) -extern const struct rig_caps g313_caps; +extern struct rig_caps g313_caps; #endif #endif /* _WINRADIO_H */ diff --git a/rigs/winradio/wr1000.c b/rigs/winradio/wr1000.c index 8b1852b77..293d323c8 100644 --- a/rigs/winradio/wr1000.c +++ b/rigs/winradio/wr1000.c @@ -38,7 +38,7 @@ #define WR1000_MODES (RIG_MODE_AM | \ RIG_MODE_USB | RIG_MODE_LSB | RIG_MODE_FM) -const struct rig_caps wr1000_caps = +struct rig_caps wr1000_caps = { RIG_MODEL(RIG_MODEL_WR1000), .model_name = "WR-1000", diff --git a/rigs/winradio/wr1500.c b/rigs/winradio/wr1500.c index a4d1c1ee4..4502d4c96 100644 --- a/rigs/winradio/wr1500.c +++ b/rigs/winradio/wr1500.c @@ -37,7 +37,7 @@ #define WR1500_MODES (RIG_MODE_AM | RIG_MODE_CW | \ RIG_MODE_USB | RIG_MODE_LSB | RIG_MODE_FM) -const struct rig_caps wr1500_caps = +struct rig_caps wr1500_caps = { RIG_MODEL(RIG_MODEL_WR1500), .model_name = "WR-1500", diff --git a/rigs/winradio/wr1550.c b/rigs/winradio/wr1550.c index 45dee1bea..023b2f8d3 100644 --- a/rigs/winradio/wr1550.c +++ b/rigs/winradio/wr1550.c @@ -37,7 +37,7 @@ #define WR1550_MODES (RIG_MODE_AM | RIG_MODE_CW | \ RIG_MODE_USB | RIG_MODE_LSB | RIG_MODE_FM) -const struct rig_caps wr1550_caps = +struct rig_caps wr1550_caps = { RIG_MODEL(RIG_MODEL_WR1550), .model_name = "WR-1550", diff --git a/rigs/winradio/wr3100.c b/rigs/winradio/wr3100.c index ee83831a8..842cd1662 100644 --- a/rigs/winradio/wr3100.c +++ b/rigs/winradio/wr3100.c @@ -37,7 +37,7 @@ #define WR3100_MODES (RIG_MODE_AM | RIG_MODE_CW | \ RIG_MODE_USB | RIG_MODE_LSB | RIG_MODE_FM) -const struct rig_caps wr3100_caps = +struct rig_caps wr3100_caps = { RIG_MODEL(RIG_MODEL_WR3100), .model_name = "WR-3100", diff --git a/rigs/winradio/wr3150.c b/rigs/winradio/wr3150.c index 10decc413..c7c2e6b3f 100644 --- a/rigs/winradio/wr3150.c +++ b/rigs/winradio/wr3150.c @@ -37,7 +37,7 @@ #define WR3150_MODES (RIG_MODE_AM | RIG_MODE_CW | \ RIG_MODE_USB | RIG_MODE_LSB | RIG_MODE_FM) -const struct rig_caps wr3150_caps = +struct rig_caps wr3150_caps = { RIG_MODEL(RIG_MODEL_WR3150), .model_name = "WR-3150", diff --git a/rigs/winradio/wr3500.c b/rigs/winradio/wr3500.c index d5310c89d..a52d4c355 100644 --- a/rigs/winradio/wr3500.c +++ b/rigs/winradio/wr3500.c @@ -37,7 +37,7 @@ #define WR3500_MODES (RIG_MODE_AM | RIG_MODE_CW | \ RIG_MODE_USB | RIG_MODE_LSB | RIG_MODE_FM) -const struct rig_caps wr3500_caps = +struct rig_caps wr3500_caps = { RIG_MODEL(RIG_MODEL_WR3500), .model_name = "WR-3500", diff --git a/rigs/winradio/wr3700.c b/rigs/winradio/wr3700.c index 4d1e8440c..5b932b6d2 100644 --- a/rigs/winradio/wr3700.c +++ b/rigs/winradio/wr3700.c @@ -37,7 +37,7 @@ #define WR3700_MODES (RIG_MODE_AM | RIG_MODE_CW | \ RIG_MODE_USB | RIG_MODE_LSB | RIG_MODE_FM) -const struct rig_caps wr3700_caps = +struct rig_caps wr3700_caps = { RIG_MODEL(RIG_MODEL_WR3700), .model_name = "WR-3700", diff --git a/rigs/wj/wj.h b/rigs/wj/wj.h index 6d77213f8..7813520a8 100644 --- a/rigs/wj/wj.h +++ b/rigs/wj/wj.h @@ -53,6 +53,6 @@ int wj_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width); int wj_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val); int wj_get_level(RIG *rig, vfo_t vfo, setting_t level, value_t *val); -extern const struct rig_caps wj8888_caps; +extern struct rig_caps wj8888_caps; #endif /* _WJ_H */ diff --git a/rigs/wj/wj8888.c b/rigs/wj/wj8888.c index 879dfe995..06a5980e5 100644 --- a/rigs/wj/wj8888.c +++ b/rigs/wj/wj8888.c @@ -49,7 +49,7 @@ * * TODO: BFO */ -const struct rig_caps wj8888_caps = +struct rig_caps wj8888_caps = { RIG_MODEL(RIG_MODEL_WJ8888), .model_name = "WJ-8888", diff --git a/rigs/yaesu/frg100.c b/rigs/yaesu/frg100.c index 8932dd108..f03702b54 100644 --- a/rigs/yaesu/frg100.c +++ b/rigs/yaesu/frg100.c @@ -147,7 +147,7 @@ static int mode2rig(RIG *rig, rmode_t mode, pbwidth_t width); * - Dim */ -const struct rig_caps frg100_caps = +struct rig_caps frg100_caps = { RIG_MODEL(RIG_MODEL_FRG100), .model_name = "FRG-100", diff --git a/rigs/yaesu/frg8800.c b/rigs/yaesu/frg8800.c index a4c2f0cf4..79091efe3 100644 --- a/rigs/yaesu/frg8800.c +++ b/rigs/yaesu/frg8800.c @@ -49,7 +49,7 @@ static int frg8800_set_powerstat(RIG *rig, powerstat_t status); * */ -const struct rig_caps frg8800_caps = +struct rig_caps frg8800_caps = { RIG_MODEL(RIG_MODEL_FRG8800), .model_name = "FRG-8800", diff --git a/rigs/yaesu/frg9600.c b/rigs/yaesu/frg9600.c index 4f6002b1c..376b730dc 100644 --- a/rigs/yaesu/frg9600.c +++ b/rigs/yaesu/frg9600.c @@ -44,7 +44,7 @@ static int frg9600_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); * */ -const struct rig_caps frg9600_caps = +struct rig_caps frg9600_caps = { RIG_MODEL(RIG_MODEL_FRG9600), .model_name = "FRG-9600", diff --git a/rigs/yaesu/ft100.c b/rigs/yaesu/ft100.c index d43c25df9..082a67cdf 100644 --- a/rigs/yaesu/ft100.c +++ b/rigs/yaesu/ft100.c @@ -309,7 +309,7 @@ static tone_t ft100_dcs_list[] = { 200, -54 } /* S0 */ \ } } -const struct rig_caps ft100_caps = +struct rig_caps ft100_caps = { RIG_MODEL(RIG_MODEL_FT100), .model_name = "FT-100", diff --git a/rigs/yaesu/ft1000d.c b/rigs/yaesu/ft1000d.c index 9cd013f6a..2c232f06c 100644 --- a/rigs/yaesu/ft1000d.c +++ b/rigs/yaesu/ft1000d.c @@ -115,13 +115,18 @@ static int ft1000d_open(RIG *rig); static int ft1000d_close(RIG *rig); static int ft1000d_set_freq(RIG *rig, vfo_t vfo, freq_t freq); static int ft1000d_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); +static int ft1000_get_freq(RIG *rig, vfo_t vfo, freq_t *freq); static int ft1000d_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width); static int ft1000d_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width); +static int ft1000_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, + pbwidth_t *width); static int ft1000d_set_vfo(RIG *rig, vfo_t vfo); static int ft1000d_get_vfo(RIG *rig, vfo_t *vfo); +static int ft1000_get_vfo(RIG *rig, vfo_t *vfo); static int ft1000d_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt); static int ft1000d_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt); +static int ft1000_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt); static int ft1000d_set_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t rptr_shift); static int ft1000d_get_rptr_shift(RIG *rig, vfo_t vfo, rptr_shift_t *rptr_shift); @@ -262,7 +267,7 @@ struct ft1000d_priv_data .flags = 1, \ } -const struct rig_caps ft1000d_caps = +struct rig_caps ft1000d_caps = { RIG_MODEL(RIG_MODEL_FT1000D), @@ -410,6 +415,152 @@ const struct rig_caps ft1000d_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; +struct rig_caps ft1000_caps = +{ + + RIG_MODEL(RIG_MODEL_FT1000), + .model_name = "FT-1000", + .mfg_name = "Yaesu", + .version = "20231124.0", + .copyright = "LGPL", + .status = RIG_STATUS_ALPHA, + .rig_type = RIG_TYPE_TRANSCEIVER, + .ptt_type = RIG_PTT_RIG, + .dcd_type = RIG_DCD_NONE, + .port_type = RIG_PORT_SERIAL, + .serial_rate_min = 4800, + .serial_rate_max = 4800, + .serial_data_bits = 8, + .serial_stop_bits = 2, + .serial_parity = RIG_PARITY_NONE, + .serial_handshake = RIG_HANDSHAKE_NONE, + .write_delay = FT1000D_WRITE_DELAY, + .post_write_delay = FT1000D_POST_WRITE_DELAY, + .timeout = 500, + .retry = 2, +// .has_get_func = RIG_FUNC_LOCK | RIG_FUNC_TUNER | RIG_FUNC_MON, +// .has_set_func = RIG_FUNC_LOCK | RIG_FUNC_TUNER, +// .has_get_level = RIG_LEVEL_STRENGTH | RIG_LEVEL_SWR | RIG_LEVEL_ALC | RIG_LEVEL_RFPOWER | RIG_LEVEL_COMP, +// .has_set_level = RIG_LEVEL_BAND_SELECT, + .has_get_parm = RIG_PARM_NONE, +// .has_set_parm = RIG_PARM_BACKLIGHT, +// .level_gran = +// { +//#include "level_gran_yaesu.h" +// }, +// .parm_gran = { +// [PARM_BACKLIGHT] = {.min = {.f = 0.0f}, .max = {.f = 1.0f}, .step = {.f = 1.0f / 13.0f}}, +// }, + .ctcss_list = NULL, + .dcs_list = NULL, + .preamp = { RIG_DBLST_END, }, + .attenuator = { RIG_DBLST_END, }, + .max_rit = Hz(9999), + .max_xit = Hz(9999), + .max_ifshift = Hz(1200), +// .vfo_ops = RIG_OP_CPY | RIG_OP_FROM_VFO | RIG_OP_TO_VFO | +// RIG_OP_UP | RIG_OP_DOWN | RIG_OP_TUNE | RIG_OP_TOGGLE, + .targetable_vfo = RIG_TARGETABLE_ALL, + .transceive = RIG_TRN_OFF, /* Yaesus have to be polled, sigh */ + .bank_qty = 0, + .chan_desc_sz = 0, +// .chan_list = { +// {1, 90, RIG_MTYPE_MEM, FT1000D_MEM_CAP}, +// RIG_CHAN_END, +// }, + .rx_range_list1 = { + {kHz(100), MHz(30), FT1000D_ALL_RX_MODES, -1, -1, FT1000D_VFO_ALL, FT1000D_ANTS}, /* General coverage + ham */ + RIG_FRNG_END, + }, + + .tx_range_list1 = { + FRQ_RNG_HF(1, FT1000D_OTHER_TX_MODES, W(5), W(100), FT1000D_VFO_ALL, FT1000D_ANTS), + FRQ_RNG_HF(1, FT1000D_AM_TX_MODES, W(2), W(25), FT1000D_VFO_ALL, FT1000D_ANTS), /* AM class */ + RIG_FRNG_END, + }, + + .rx_range_list2 = { + {kHz(100), MHz(30), FT1000D_ALL_RX_MODES, -1, -1, FT1000D_VFO_ALL, FT1000D_ANTS}, + RIG_FRNG_END, + }, + + .tx_range_list2 = { + FRQ_RNG_HF(2, FT1000D_OTHER_TX_MODES, W(5), W(100), FT1000D_VFO_ALL, FT1000D_ANTS), + FRQ_RNG_HF(2, FT1000D_AM_TX_MODES, W(2), W(25), FT1000D_VFO_ALL, FT1000D_ANTS), /* AM class */ + + RIG_FRNG_END, + }, + + .tuning_steps = { + {FT1000D_SSB_CW_RX_MODES, Hz(10)}, /* Normal */ + {FT1000D_SSB_CW_RX_MODES, Hz(100)}, /* Fast */ + + {FT1000D_AM_RX_MODES, Hz(100)}, /* Normal */ + {FT1000D_AM_RX_MODES, kHz(1)}, /* Fast */ + + {FT1000D_FM_RX_MODES, Hz(100)}, /* Normal */ + {FT1000D_FM_RX_MODES, kHz(1)}, /* Fast */ + + {FT1000D_RTTY_RX_MODES, Hz(10)}, /* Normal */ + {FT1000D_RTTY_RX_MODES, Hz(100)}, /* Fast */ + + RIG_TS_END, + + }, + + /* mode/filter list, .remember = order matters! */ + .filters = { + {RIG_MODE_SSB, RIG_FLT_ANY}, /* Enable all filters for SSB */ + {RIG_MODE_CW, RIG_FLT_ANY}, /* Enable all filters for CW */ + {RIG_MODE_RTTY, RIG_FLT_ANY}, /* Enable all filters for RTTY */ + {RIG_MODE_RTTYR, RIG_FLT_ANY}, /* Enable all filters for Reverse RTTY */ + {RIG_MODE_PKTLSB, RIG_FLT_ANY}, /* Enable all filters for Packet Radio LSB */ + {RIG_MODE_AM, kHz(6)}, /* normal AM filter */ + {RIG_MODE_AM, kHz(2.4)}, /* narrow AM filter */ + {RIG_MODE_FM, kHz(8)}, /* FM standard filter */ + {RIG_MODE_PKTFM, kHz(8)}, /* FM standard filter for Packet Radio FM */ + RIG_FLT_END, + }, + + .priv = NULL, /* private data FIXME: */ + + .rig_init = ft1000d_init, + .rig_cleanup = ft1000d_cleanup, + .rig_open = ft1000d_open, /* port opened */ + .rig_close = ft1000d_close, /* port closed */ + + .set_freq = ft1000d_set_freq, + .get_freq = ft1000_get_freq, + .set_mode = ft1000d_set_mode, + .get_mode = ft1000_get_mode, + .set_vfo = ft1000d_set_vfo, + .get_vfo = ft1000_get_vfo, + .set_ptt = ft1000d_set_ptt, + .get_ptt = ft1000_get_ptt, +// .set_rptr_shift = ft1000d_set_rptr_shift, +// .get_rptr_shift = ft1000d_get_rptr_shift, +// .set_rptr_offs = ft1000d_set_rptr_offs, +// .set_split_freq = ft1000d_set_split_freq, /* Added December 2016 to expand range of FT1000D functions. */ +// .get_split_freq = ft1000d_get_split_freq, /* Added December 2016 to expand range of FT1000D functions. */ +// .set_split_mode = ft1000d_set_split_mode, /* Added December 2016 to expand range of FT1000D functions. */ +// .get_split_mode = ft1000d_get_split_mode, /* Added December 2016 to expand range of FT1000D functions. */ +// .set_split_vfo = ft1000d_set_split_vfo, /* Changed in December 2016 so that vfos toggle back and forth like pressing Split button on rig */ +// .get_split_vfo = ft1000d_get_split_vfo, +// .set_rit = ft1000d_set_rit, +// .get_rit = ft1000d_get_rit, +// .set_xit = ft1000d_set_xit, +// .get_xit = ft1000d_get_xit, +// .set_func = ft1000d_set_func, +// .get_func = ft1000d_get_func, +// .set_parm = ft1000d_set_parm, +// .get_level = ft1000d_get_level, +// .set_mem = ft1000d_set_mem, +// .get_mem = ft1000d_get_mem, +// .vfo_op = ft1000d_vfo_op, +// .set_channel = ft1000d_set_channel, +// .get_channel = ft1000d_get_channel, + .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS +}; /* * ************************************ @@ -513,11 +664,14 @@ static int ft1000d_open(RIG *rig) // Get current rig settings and status - err = ft1000d_get_update_data(rig, FT1000D_NATIVE_UPDATE_OP_DATA, 0); - - if (err != RIG_OK) + if (rig->caps->rig_model != RIG_MODEL_FT1000) { - return err; + err = ft1000d_get_update_data(rig, FT1000D_NATIVE_UPDATE_OP_DATA, 0); + + if (err != RIG_OK) + { + return err; + } } return RIG_OK; @@ -3959,5 +4113,46 @@ static int ft1000d_get_split_mode(RIG *rig, vfo_t vfo, rmode_t *tx_mode, return RIG_OK; } +static int ft1000_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) +{ + if (vfo == RIG_VFO_A) + { + *freq = rig->state.cache.freqMainA; + } + else + { + *freq = rig->state.cache.freqMainB; + } + + return RIG_OK; +} + +static int ft1000_get_mode(RIG *rig, vfo_t vfo, rmode_t *mode, pbwidth_t *width) +{ + if (vfo == RIG_VFO_A) + { + *mode = rig->state.cache.modeMainA; + } + else + { + *mode = rig->state.cache.modeMainB; + } + + return RIG_OK; +} + +static int ft1000_get_vfo(RIG *rig, vfo_t *vfo) +{ + *vfo = rig->state.current_vfo; + return RIG_OK; +} + +static int ft1000_get_ptt(RIG *rig, vfo_t vfo, ptt_t *ptt) +{ + *ptt = rig->state.cache.ptt; + return RIG_OK; +} + + diff --git a/rigs/yaesu/ft1000mp.c b/rigs/yaesu/ft1000mp.c index f54790452..ae14a1548 100644 --- a/rigs/yaesu/ft1000mp.c +++ b/rigs/yaesu/ft1000mp.c @@ -308,7 +308,7 @@ struct ft1000mp_priv_data * */ -const struct rig_caps ft1000mp_caps = +struct rig_caps ft1000mp_caps = { RIG_MODEL(RIG_MODEL_FT1000MP), .model_name = "FT-1000MP", @@ -451,7 +451,7 @@ const struct rig_caps ft1000mp_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps ft1000mpmkv_caps = +struct rig_caps ft1000mpmkv_caps = { RIG_MODEL(RIG_MODEL_FT1000MPMKV), .model_name = "MARK-V FT-1000MP", @@ -594,7 +594,7 @@ const struct rig_caps ft1000mpmkv_caps = /* TODO: the remaining ... */ }; -const struct rig_caps ft1000mpmkvfld_caps = +struct rig_caps ft1000mpmkvfld_caps = { RIG_MODEL(RIG_MODEL_FT1000MPMKVFLD), .model_name = "MARK-V Field FT-1000MP", diff --git a/rigs/yaesu/ft1200.c b/rigs/yaesu/ft1200.c index eca6c098f..417d1de8e 100644 --- a/rigs/yaesu/ft1200.c +++ b/rigs/yaesu/ft1200.c @@ -142,7 +142,7 @@ int ftdx1200_ext_tokens[] = /* * FTDX 1200 rig capabilities */ -const struct rig_caps ftdx1200_caps = +struct rig_caps ftdx1200_caps = { RIG_MODEL(RIG_MODEL_FTDX1200), .model_name = "FTDX-1200", @@ -174,13 +174,13 @@ const 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 c8fc41cbd..b66c67094 100644 --- a/rigs/yaesu/ft2000.c +++ b/rigs/yaesu/ft2000.c @@ -127,7 +127,7 @@ int ft2000_ext_tokens[] = /* * FT-2000 rig capabilities */ -const struct rig_caps ft2000_caps = +struct rig_caps ft2000_caps = { RIG_MODEL(RIG_MODEL_FT2000), .model_name = "FT-2000", @@ -159,12 +159,12 @@ const 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 7774b7895..6c041925e 100644 --- a/rigs/yaesu/ft3000.c +++ b/rigs/yaesu/ft3000.c @@ -237,7 +237,7 @@ int ft3000_get_ant(RIG *rig, vfo_t vfo, ant_t dummy, value_t *option, * so this is just a copy of the FTDX 5000 caps. * It really needs to be reviewed for accuracy, but it works for WSJT-X. */ -const struct rig_caps ftdx3000_caps = +struct rig_caps ftdx3000_caps = { RIG_MODEL(RIG_MODEL_FTDX3000), .model_name = "FTDX-3000", @@ -270,13 +270,13 @@ const 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 5377211b9..e33d9b611 100644 --- a/rigs/yaesu/ft450.c +++ b/rigs/yaesu/ft450.c @@ -34,7 +34,7 @@ /* * FT-450 rig capabilities */ -const struct rig_caps ft450_caps = +struct rig_caps ft450_caps = { RIG_MODEL(RIG_MODEL_FT450), .model_name = "FT-450", @@ -67,12 +67,12 @@ const 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 d7421b280..759c68f23 100644 --- a/rigs/yaesu/ft5000.c +++ b/rigs/yaesu/ft5000.c @@ -133,7 +133,7 @@ int ftdx5000_ext_tokens[] = TOK_BACKEND_NONE }; -const struct rig_caps ftdx5000_caps = +struct rig_caps ftdx5000_caps = { RIG_MODEL(RIG_MODEL_FTDX5000), .model_name = "FTDX-5000", @@ -165,12 +165,12 @@ const 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/ft600.c b/rigs/yaesu/ft600.c index e1dfdd851..2e0d3aa24 100644 --- a/rigs/yaesu/ft600.c +++ b/rigs/yaesu/ft600.c @@ -219,7 +219,7 @@ static const yaesu_cmd_set_t ncmd[] = { 246, 60 } /* S9+60dB */ \ }} -const struct rig_caps ft600_caps = +struct rig_caps ft600_caps = { RIG_MODEL(RIG_MODEL_FT600), .model_name = "FT-600", diff --git a/rigs/yaesu/ft710.c b/rigs/yaesu/ft710.c index 792350806..37d07f617 100644 --- a/rigs/yaesu/ft710.c +++ b/rigs/yaesu/ft710.c @@ -114,7 +114,7 @@ int ft710_ext_tokens[] = TOK_BACKEND_NONE }; -const struct rig_caps ft710_caps = +struct rig_caps ft710_caps = { RIG_MODEL(RIG_MODEL_FT710), .model_name = "FT-710", @@ -145,14 +145,14 @@ const 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/ft736.c b/rigs/yaesu/ft736.c index d37685036..f4bf6f4ea 100644 --- a/rigs/yaesu/ft736.c +++ b/rigs/yaesu/ft736.c @@ -92,7 +92,7 @@ static tone_t ft736_ctcss_list[] = * - AQS */ -const struct rig_caps ft736_caps = +struct rig_caps ft736_caps = { RIG_MODEL(RIG_MODEL_FT736R), .model_name = "FT-736R", diff --git a/rigs/yaesu/ft747.c b/rigs/yaesu/ft747.c index d5c5f0f0f..5c5231606 100644 --- a/rigs/yaesu/ft747.c +++ b/rigs/yaesu/ft747.c @@ -296,7 +296,7 @@ struct ft747_priv_data * Also this struct is READONLY! */ -const struct rig_caps ft747_caps = +struct rig_caps ft747_caps = { RIG_MODEL(RIG_MODEL_FT747), .model_name = "FT-747GX", diff --git a/rigs/yaesu/ft757gx.c b/rigs/yaesu/ft757gx.c index 583795491..67f1d36d3 100644 --- a/rigs/yaesu/ft757gx.c +++ b/rigs/yaesu/ft757gx.c @@ -108,7 +108,7 @@ const struct confparams ft757gx_cfg_params[] = * ft757gx rig capabilities. * Also this struct is READONLY! */ -const struct rig_caps ft757gx_caps = +struct rig_caps ft757gx_caps = { RIG_MODEL(RIG_MODEL_FT757), .model_name = "FT-757GX", @@ -225,7 +225,7 @@ const struct rig_caps ft757gx_caps = * ft757gx2 rig capabilities. * Also this struct is READONLY! */ -const struct rig_caps ft757gx2_caps = +struct rig_caps ft757gx2_caps = { RIG_MODEL(RIG_MODEL_FT757GXII), .model_name = "FT-757GXII", diff --git a/rigs/yaesu/ft767gx.c b/rigs/yaesu/ft767gx.c index 1b8ee0ae2..a5df97fa0 100644 --- a/rigs/yaesu/ft767gx.c +++ b/rigs/yaesu/ft767gx.c @@ -254,7 +254,7 @@ tone_t static_767gx_ctcss_list[] = * Also this struct is READONLY! */ -const struct rig_caps ft767gx_caps = +struct rig_caps ft767gx_caps = { RIG_MODEL(RIG_MODEL_FT767), .model_name = "FT-767GX", @@ -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 86258ddb2..95e579fdd 100644 --- a/rigs/yaesu/ft817.c +++ b/rigs/yaesu/ft817.c @@ -289,7 +289,7 @@ enum ft817_digi } } -const struct rig_caps ft817_caps = +struct rig_caps ft817_caps = { RIG_MODEL(RIG_MODEL_FT817), .model_name = "FT-817", @@ -439,7 +439,7 @@ const struct rig_caps ft817_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps ft818_caps = +struct rig_caps ft818_caps = { RIG_MODEL(RIG_MODEL_FT818), .model_name = "FT-818", @@ -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/ft840.c b/rigs/yaesu/ft840.c index dc686e12a..ea68c868e 100644 --- a/rigs/yaesu/ft840.c +++ b/rigs/yaesu/ft840.c @@ -239,7 +239,7 @@ struct ft840_priv_data * */ -const struct rig_caps ft840_caps = +struct rig_caps ft840_caps = { RIG_MODEL(RIG_MODEL_FT840), .model_name = "FT-840", diff --git a/rigs/yaesu/ft847.c b/rigs/yaesu/ft847.c index d6ee0f66b..1eb4d293f 100644 --- a/rigs/yaesu/ft847.c +++ b/rigs/yaesu/ft847.c @@ -379,7 +379,7 @@ static tone_t ft650_ctcss_list[] = * Notice that some rigs share the same functions. */ -const struct rig_caps ft847_caps = +struct rig_caps ft847_caps = { RIG_MODEL(RIG_MODEL_FT847), .model_name = "FT-847", @@ -537,7 +537,7 @@ const struct rig_caps ft847_caps = * Notice that some rigs share the same functions. */ -const struct rig_caps ft650_caps = +struct rig_caps ft650_caps = { RIG_MODEL(RIG_MODEL_FT650), .model_name = "FT-650", @@ -675,7 +675,7 @@ const struct rig_caps ft650_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps mchfqrp_caps = +struct rig_caps mchfqrp_caps = { RIG_MODEL(RIG_MODEL_MCHFQRP), .model_name = "mcHF QRP", @@ -848,7 +848,7 @@ improvements. This version was made in May 1998. Later serial numbers (e.g., 8L09nnnn) all seem to have incorporated the earlier improvements plus new ones...." */ -const struct rig_caps ft847uni_caps = +struct rig_caps ft847uni_caps = { RIG_MODEL(RIG_MODEL_FT847UNI), .model_name = "FT-847UNI", diff --git a/rigs/yaesu/ft857.c b/rigs/yaesu/ft857.c index d3d2981dd..09dbbe861 100644 --- a/rigs/yaesu/ft857.c +++ b/rigs/yaesu/ft857.c @@ -239,7 +239,7 @@ enum ft857_digi static int ft857_send_icmd(RIG *rig, int index, const unsigned char *data); -const struct rig_caps ft857_caps = +struct rig_caps ft857_caps = { RIG_MODEL(RIG_MODEL_FT857), .model_name = "FT-857", @@ -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; @@ -635,14 +636,7 @@ int ft857_set_vfo(RIG *rig, vfo_t vfo) rig_debug(RIG_DEBUG_VERBOSE, "%s: called \n", __func__); - int retval = ft857_get_vfo(rig, &curvfo); - - if (retval != RIG_OK) - { - rig_debug(RIG_DEBUG_ERR, "%s: error get_vfo '%s'\n", __func__, - rigerror(retval)); - return retval; - } + ft857_get_vfo(rig, &curvfo); // retval is always RIG_OK so ignore it if (curvfo == vfo) { @@ -673,7 +667,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/ft890.c b/rigs/yaesu/ft890.c index 20f999ad3..e62abe350 100644 --- a/rigs/yaesu/ft890.c +++ b/rigs/yaesu/ft890.c @@ -391,7 +391,7 @@ struct ft890_priv_data * */ -const struct rig_caps ft890_caps = +struct rig_caps ft890_caps = { RIG_MODEL(RIG_MODEL_FT890), .model_name = "FT-890", diff --git a/rigs/yaesu/ft891.c b/rigs/yaesu/ft891.c index 2d5309344..dcd8b9b18 100644 --- a/rigs/yaesu/ft891.c +++ b/rigs/yaesu/ft891.c @@ -125,7 +125,7 @@ int ft891_ext_tokens[] = /* * FT-891 rig capabilities */ -const struct rig_caps ft891_caps = +struct rig_caps ft891_caps = { RIG_MODEL(RIG_MODEL_FT891), .model_name = "FT-891", @@ -156,15 +156,15 @@ const 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 026e7ea26..be2144890 100644 --- a/rigs/yaesu/ft897.c +++ b/rigs/yaesu/ft897.c @@ -245,7 +245,7 @@ enum ft897_digi #define FT897_VFO_ALL (RIG_VFO_A|RIG_VFO_B) #define FT897_ANTS 0 -const struct rig_caps ft897_caps = +struct rig_caps ft897_caps = { RIG_MODEL(RIG_MODEL_FT897), .model_name = "FT-897", @@ -393,7 +393,7 @@ const struct rig_caps ft897_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps ft897d_caps = +struct rig_caps ft897d_caps = { RIG_MODEL(RIG_MODEL_FT897D), .model_name = "FT-897D", @@ -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/ft900.c b/rigs/yaesu/ft900.c index 36aeca19e..cbeddefda 100644 --- a/rigs/yaesu/ft900.c +++ b/rigs/yaesu/ft900.c @@ -413,7 +413,7 @@ struct ft900_priv_data * */ -const struct rig_caps ft900_caps = +struct rig_caps ft900_caps = { RIG_MODEL(RIG_MODEL_FT900), .model_name = "FT-900", diff --git a/rigs/yaesu/ft9000.c b/rigs/yaesu/ft9000.c index 7f5b61f85..3760a772b 100644 --- a/rigs/yaesu/ft9000.c +++ b/rigs/yaesu/ft9000.c @@ -41,7 +41,7 @@ * */ -const struct rig_caps ft9000_caps = +struct rig_caps ft9000_caps = { RIG_MODEL(RIG_MODEL_FT9000), .model_name = "FTDX-9000", @@ -74,8 +74,8 @@ const 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, @@ -217,7 +217,7 @@ const struct rig_caps ft9000_caps = .hamlib_check_rig_caps = HAMLIB_CHECK_RIG_CAPS }; -const struct rig_caps ft9000Old_caps = +struct rig_caps ft9000Old_caps = { RIG_MODEL(RIG_MODEL_FT9000OLD), .model_name = "FTDX-9000 Old", @@ -250,8 +250,8 @@ const 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 68cc18877..fda80d7f1 100644 --- a/rigs/yaesu/ft920.c +++ b/rigs/yaesu/ft920.c @@ -402,7 +402,7 @@ struct ft920_priv_data * */ -const struct rig_caps ft920_caps = +struct rig_caps ft920_caps = { RIG_MODEL(RIG_MODEL_FT920), .model_name = "FT-920", @@ -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 2ee973d55..5d48226ac 100644 --- a/rigs/yaesu/ft950.c +++ b/rigs/yaesu/ft950.c @@ -77,7 +77,7 @@ int ft950_ext_tokens[] = /* * FT-950 rig capabilities */ -const struct rig_caps ft950_caps = +struct rig_caps ft950_caps = { RIG_MODEL(RIG_MODEL_FT950), .model_name = "FT-950", @@ -108,15 +108,14 @@ const struct rig_caps ft950_caps = .level_gran = { #include "level_gran_yaesu.h" - [LVL_RAWSTR] = { .min = { .i = 0 }, .max = { .i = 255 } }, [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/ft980.h b/rigs/yaesu/ft980.h index 18192ec65..3d2b3f400 100644 --- a/rigs/yaesu/ft980.h +++ b/rigs/yaesu/ft980.h @@ -141,7 +141,7 @@ static int ft980_set_rptr_offs(RIG *rig, vfo_t vfo, shortfreq_t offs); .width = 1, \ } -const struct rig_caps ft980_caps = +struct rig_caps ft980_caps = { RIG_MODEL(RIG_MODEL_FT980), .model_name = "FT-980", diff --git a/rigs/yaesu/ft990.c b/rigs/yaesu/ft990.c index 5a2c9c5ce..ea64e44d5 100755 --- a/rigs/yaesu/ft990.c +++ b/rigs/yaesu/ft990.c @@ -230,7 +230,7 @@ struct ft990_priv_data .flags = 1, \ } -const struct rig_caps ft990_caps = +struct rig_caps ft990_caps = { RIG_MODEL(RIG_MODEL_FT990), .model_name = "FT-990", diff --git a/rigs/yaesu/ft990v12.c b/rigs/yaesu/ft990v12.c index eb445fad2..80fc2ef88 100644 --- a/rigs/yaesu/ft990v12.c +++ b/rigs/yaesu/ft990v12.c @@ -249,7 +249,7 @@ struct ft990v12_priv_data // Old FT990 ROM has to read all 1492 to get frequency // So for this model we just use the cache to read freq -const struct rig_caps ft990uni_caps = +struct rig_caps ft990uni_caps = { RIG_MODEL(RIG_MODEL_FT990UNI), .model_name = "FT-990 Old Rom", diff --git a/rigs/yaesu/ft991.c b/rigs/yaesu/ft991.c index cd5ef0503..fe1a00076 100644 --- a/rigs/yaesu/ft991.c +++ b/rigs/yaesu/ft991.c @@ -170,7 +170,7 @@ int ft991_ext_tokens[] = /* * FT-991 rig capabilities */ -const struct rig_caps ft991_caps = +struct rig_caps ft991_caps = { RIG_MODEL(RIG_MODEL_FT991), .model_name = "FT-991", @@ -200,14 +200,14 @@ const 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 65e9dade9..32493b843 100644 --- a/rigs/yaesu/ftdx10.c +++ b/rigs/yaesu/ftdx10.c @@ -130,7 +130,7 @@ int ftdx10_ext_tokens[] = TOK_BACKEND_NONE }; -const struct rig_caps ftdx10_caps = +struct rig_caps ftdx10_caps = { RIG_MODEL(RIG_MODEL_FTDX10), .model_name = "FTDX-10", @@ -161,14 +161,14 @@ const 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 0473b7b85..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", @@ -168,7 +168,7 @@ int ftdx101d_ext_tokens[] = TOK_BACKEND_NONE }; -const struct rig_caps ftdx101d_caps = +struct rig_caps ftdx101d_caps = { RIG_MODEL(RIG_MODEL_FTDX101D), .model_name = "FTDX-101D", @@ -199,16 +199,16 @@ const 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 bf0cd4a0a..e7561dbfe 100644 --- a/rigs/yaesu/ftdx101mp.c +++ b/rigs/yaesu/ftdx101mp.c @@ -71,7 +71,7 @@ int ftdx101mp_ext_tokens[] = TOK_ROOFING_FILTER, TOK_BACKEND_NONE }; -const struct rig_caps ftdx101mp_caps = +struct rig_caps ftdx101mp_caps = { RIG_MODEL(RIG_MODEL_FTDX101MP), .model_name = "FTDX-101MP", @@ -101,16 +101,16 @@ const 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 = .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 = .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 2014e567d..f2805836d 100644 --- a/rigs/yaesu/newcat.c +++ b/rigs/yaesu/newcat.c @@ -705,7 +705,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 @@ -895,6 +896,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 (channel < 0) { rig_debug(RIG_DEBUG_ERR, @@ -929,7 +932,7 @@ int newcat_set_freq(RIG *rig, vfo_t vfo, freq_t freq) char c; char target_vfo; int err; - const struct rig_caps *caps; + struct rig_caps *caps; struct newcat_priv_data *priv; int special_60m = 0; vfo_t vfo_mode; @@ -1165,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); @@ -1589,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 } @@ -1963,7 +1968,7 @@ int newcat_set_ptt(RIG *rig, vfo_t vfo, ptt_t ptt) } } - break; + break; default: RETURNFUNC(-RIG_EINVAL); @@ -3651,12 +3656,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); @@ -3792,6 +3797,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); @@ -4069,8 +4075,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: @@ -4079,14 +4086,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; @@ -4226,7 +4233,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; @@ -4253,27 +4261,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) @@ -4455,6 +4467,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) @@ -4499,7 +4512,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; @@ -4607,7 +4620,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); @@ -4642,7 +4655,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); @@ -4684,12 +4698,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); @@ -4851,32 +4866,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: @@ -4918,7 +4945,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) @@ -4953,6 +4980,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, @@ -5047,16 +5075,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); @@ -5065,7 +5097,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) @@ -5207,6 +5240,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, @@ -5428,76 +5462,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); } @@ -5997,6 +6050,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)); @@ -6038,6 +6092,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)); @@ -6200,6 +6255,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)); @@ -6237,17 +6293,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) { @@ -6262,7 +6321,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 @@ -6313,6 +6373,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: @@ -6330,6 +6391,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: @@ -6412,6 +6474,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)); @@ -6562,7 +6625,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) { @@ -6607,6 +6671,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: @@ -6623,6 +6688,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: @@ -6750,7 +6816,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; } @@ -6784,25 +6851,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); @@ -6814,26 +6883,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); @@ -6852,37 +6924,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); } @@ -7113,7 +7201,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__); @@ -7123,54 +7211,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); @@ -7358,6 +7460,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: @@ -7496,7 +7599,7 @@ int newcat_get_trn(RIG *rig, int *trn) SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "%s%c", command, cat_term); /* Get Auto Information */ - if (RIG_OK != (err = newcat_get_cmd(rig))) + if (RIG_OK != newcat_get_cmd(rig)) { // if we failed to get AI we turn it off and try again SNPRINTF(priv->cmd_str, sizeof(priv->cmd_str), "%s0%c", command, cat_term); @@ -7662,17 +7765,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); @@ -7738,11 +7841,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); @@ -7765,7 +7870,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; @@ -7862,12 +7969,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) @@ -7918,7 +8027,7 @@ const char *newcat_get_info(RIG *rig) ncboolean newcat_valid_command(RIG *rig, char const *const command) { - const struct rig_caps *caps; + struct rig_caps *caps; int search_high; int search_low; @@ -9488,7 +9597,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 @@ -10460,9 +10570,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; @@ -10840,9 +10950,11 @@ int newcat_get_vfo_mode(RIG *rig, vfo_t vfo, vfo_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 } @@ -10938,7 +11050,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 } @@ -11023,12 +11136,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); @@ -11046,6 +11162,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 */ } @@ -11217,7 +11334,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; } @@ -11316,7 +11434,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)); @@ -11326,8 +11444,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); } @@ -11335,21 +11455,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) { @@ -11360,7 +11484,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); } @@ -11376,7 +11501,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; } } @@ -11450,7 +11575,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); @@ -11684,7 +11810,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); } } @@ -11730,12 +11856,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; @@ -11747,6 +11875,7 @@ static int newcat_set_clarifier(RIG *rig, vfo_t vfo, int rx, int tx) { rx = 0; } + if (tx < 0) { tx = 0; @@ -11755,7 +11884,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)); } @@ -11778,7 +11907,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) { @@ -11797,6 +11927,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; @@ -11821,7 +11952,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)); } @@ -11846,7 +11977,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) { @@ -11862,9 +11994,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/newcat.h b/rigs/yaesu/newcat.h index 75cd82df3..31897206d 100644 --- a/rigs/yaesu/newcat.h +++ b/rigs/yaesu/newcat.h @@ -50,7 +50,7 @@ typedef char ncboolean; /* shared function version */ -#define NEWCAT_VER "20231101" +#define NEWCAT_VER "20231204" /* Hopefully large enough for future use, 128 chars plus '\0' */ #define NEWCAT_DATA_LEN 129 diff --git a/rigs/yaesu/vr5000.c b/rigs/yaesu/vr5000.c index ba434c4aa..5de58053d 100644 --- a/rigs/yaesu/vr5000.c +++ b/rigs/yaesu/vr5000.c @@ -122,7 +122,7 @@ static int check_tuning_step(RIG *rig, vfo_t vfo, rmode_t mode, * vr5000 rigs capabilities. */ -const struct rig_caps vr5000_caps = +struct rig_caps vr5000_caps = { RIG_MODEL(RIG_MODEL_VR5000), .model_name = "VR-5000", diff --git a/rigs/yaesu/vx1700.c b/rigs/yaesu/vx1700.c index 9a50d09f5..648caf9c3 100644 --- a/rigs/yaesu/vx1700.c +++ b/rigs/yaesu/vx1700.c @@ -207,7 +207,7 @@ struct vx1700_priv_data .width = 1, \ } -const struct rig_caps vx1700_caps = +struct rig_caps vx1700_caps = { RIG_MODEL(RIG_MODEL_VX1700), .model_name = "VX-1700", @@ -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 19aec375e..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); @@ -95,6 +95,7 @@ DECLARE_INITRIG_BACKEND(yaesu) rig_register(&ft980_caps); rig_register(&ft990_caps); rig_register(&ft990uni_caps); + rig_register(&ft1000_caps); rig_register(&ft1000d_caps); rig_register(&ft1000mp_caps); rig_register(&ft1000mpmkv_caps); diff --git a/rigs/yaesu/yaesu.h b/rigs/yaesu/yaesu.h index 52b58775e..088943620 100644 --- a/rigs/yaesu/yaesu.h +++ b/rigs/yaesu/yaesu.h @@ -45,52 +45,53 @@ struct yaesu_cmd_set { typedef struct yaesu_cmd_set yaesu_cmd_set_t; -extern const struct rig_caps ft100_caps; -extern const struct rig_caps ft450_caps; +extern struct rig_caps ft100_caps; +extern struct rig_caps ft450_caps; extern struct rig_caps ft450d_caps; -extern const struct rig_caps ft736_caps; -extern const struct rig_caps ft747_caps; -extern const struct rig_caps ft757gx_caps; -extern const struct rig_caps ft757gx2_caps; -extern const struct rig_caps ft600_caps; -extern const struct rig_caps ft767gx_caps; -extern const struct rig_caps ft817_caps; -extern const struct rig_caps ft857_caps; -extern const struct rig_caps ft897_caps; -extern const struct rig_caps ft897d_caps; -extern const struct rig_caps ft847_caps; -extern const struct rig_caps ft840_caps; -extern const struct rig_caps ft890_caps; -extern const struct rig_caps ft891_caps; -extern const struct rig_caps ft900_caps; -extern const struct rig_caps ft920_caps; -extern const struct rig_caps ft950_caps; -extern const struct rig_caps ft980_caps; -extern const struct rig_caps ft990_caps; -extern const struct rig_caps ft990uni_caps; -extern const struct rig_caps ft991_caps; -extern const struct rig_caps ft1000mp_caps; -extern const struct rig_caps ft1000mpmkv_caps; -extern const struct rig_caps ft1000mpmkvfld_caps; -extern const struct rig_caps ft1000d_caps; -extern const struct rig_caps ft2000_caps; -extern const struct rig_caps ftdx3000_caps; -extern const struct rig_caps ftdx5000_caps; -extern const struct rig_caps ft9000_caps; -extern const struct rig_caps frg100_caps; -extern const struct rig_caps frg8800_caps; -extern const struct rig_caps frg9600_caps; -extern const struct rig_caps vr5000_caps; -extern const struct rig_caps vx1700_caps; -extern const struct rig_caps ftdx1200_caps; -extern const struct rig_caps ft847uni_caps; -extern const struct rig_caps ftdx101d_caps; -extern const struct rig_caps ft818_caps; -extern const struct rig_caps ftdx10_caps; -extern const struct rig_caps ftdx101mp_caps; -extern const struct rig_caps mchfqrp_caps; -extern const struct rig_caps ft650_caps; -extern const struct rig_caps ft710_caps; -extern const struct rig_caps ft9000Old_caps; +extern struct rig_caps ft736_caps; +extern struct rig_caps ft747_caps; +extern struct rig_caps ft757gx_caps; +extern struct rig_caps ft757gx2_caps; +extern struct rig_caps ft600_caps; +extern struct rig_caps ft767gx_caps; +extern struct rig_caps ft817_caps; +extern struct rig_caps ft857_caps; +extern struct rig_caps ft897_caps; +extern struct rig_caps ft897d_caps; +extern struct rig_caps ft847_caps; +extern struct rig_caps ft840_caps; +extern struct rig_caps ft890_caps; +extern struct rig_caps ft891_caps; +extern struct rig_caps ft900_caps; +extern struct rig_caps ft920_caps; +extern struct rig_caps ft950_caps; +extern struct rig_caps ft980_caps; +extern struct rig_caps ft990_caps; +extern struct rig_caps ft990uni_caps; +extern struct rig_caps ft991_caps; +extern struct rig_caps ft1000mp_caps; +extern struct rig_caps ft1000mpmkv_caps; +extern struct rig_caps ft1000mpmkvfld_caps; +extern struct rig_caps ft1000_caps; +extern struct rig_caps ft1000d_caps; +extern struct rig_caps ft2000_caps; +extern struct rig_caps ftdx3000_caps; +extern struct rig_caps ftdx5000_caps; +extern struct rig_caps ft9000_caps; +extern struct rig_caps frg100_caps; +extern struct rig_caps frg8800_caps; +extern struct rig_caps frg9600_caps; +extern struct rig_caps vr5000_caps; +extern struct rig_caps vx1700_caps; +extern struct rig_caps ftdx1200_caps; +extern struct rig_caps ft847uni_caps; +extern struct rig_caps ftdx101d_caps; +extern struct rig_caps ft818_caps; +extern struct rig_caps ftdx10_caps; +extern struct rig_caps ftdx101mp_caps; +extern struct rig_caps mchfqrp_caps; +extern struct rig_caps ft650_caps; +extern struct rig_caps ft710_caps; +extern struct rig_caps ft9000Old_caps; #endif /* _YAESU_H */ diff --git a/rotators/easycomm/easycomm.c b/rotators/easycomm/easycomm.c index af3a9ae69..419c16fd8 100644 --- a/rotators/easycomm/easycomm.c +++ b/rotators/easycomm/easycomm.c @@ -50,6 +50,7 @@ easycomm_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) { struct rot_state *rs; int retval; + int retry = rot->caps->retry; rig_debug(RIG_DEBUG_TRACE, "%s called: %s\n", __func__, cmdstr); @@ -59,33 +60,39 @@ easycomm_transaction(ROT *rot, const char *cmdstr, char *data, size_t data_len) } rs = &rot->state; - rig_flush(&rs->rotport); - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); - if (retval != RIG_OK) + do { - goto transaction_quit; - } + rig_flush(&rs->rotport); + retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); - if (data == NULL) - { - return RIG_OK; /* don't want a reply */ - } + if (retval != RIG_OK) + { + goto transaction_quit; + } - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, - "\n", 1, 0, 1); + if (data == NULL) + { + return RIG_OK; /* don't want a reply */ + } - if (retval < 0) - { - rig_debug(RIG_DEBUG_TRACE, "%s read_string failed with status %d\n", __func__, - retval); - goto transaction_quit; - } - else - { - rig_debug(RIG_DEBUG_TRACE, "%s read_string: %s\n", __func__, data); - retval = RIG_OK; + retval = read_string(&rs->rotport, (unsigned char *) data, data_len, + "\n", 1, 0, 1); + + if (retval < 0) + { + rig_debug(RIG_DEBUG_TRACE, "%s read_string failed with status %d:%s\n", + __func__, + retval, strerror(retval)); + goto transaction_quit; + } + else + { + rig_debug(RIG_DEBUG_TRACE, "%s read_string: %s\n", __func__, data); + retval = RIG_OK; + } } + while (--retry && retval != RIG_OK); transaction_quit: return retval; @@ -520,7 +527,7 @@ const struct rot_caps easycomm1_rot_caps = ROT_MODEL(ROT_MODEL_EASYCOMM1), .model_name = "EasycommI", .mfg_name = "Hamlib", - .version = "20220109.0", + .version = "20231218.0", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rot_type = ROT_TYPE_OTHER, @@ -556,7 +563,7 @@ const struct rot_caps easycomm2_rot_caps = ROT_MODEL(ROT_MODEL_EASYCOMM2), .model_name = "EasycommII", .mfg_name = "Hamlib", - .version = "20191206.0", + .version = "20231218.0", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rot_type = ROT_TYPE_OTHER, @@ -602,7 +609,7 @@ const struct rot_caps easycomm3_rot_caps = ROT_MODEL(ROT_MODEL_EASYCOMM3), .model_name = "EasycommIII", .mfg_name = "Hamlib", - .version = "20201203.0", + .version = "2022312180", .copyright = "LGPL", .status = RIG_STATUS_STABLE, .rot_type = ROT_TYPE_OTHER, 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/grbltrk/grbltrk.c b/rotators/grbltrk/grbltrk.c index 100ca0728..0c81a54fe 100644 --- a/rotators/grbltrk/grbltrk.c +++ b/rotators/grbltrk/grbltrk.c @@ -376,7 +376,7 @@ grbltrk_rot_get_position(ROT *rot, azimuth_t *az, elevation_t *el) /* grbl 1.3a esp32 */ // - sscanf(rsp, "%[^'|']|MPos:%f,%f,%256s", dummy0, &mpos[0], &mpos[1], dummy1); + sscanf(rsp, "%[^'|']|MPos:%f,%f,%255s", dummy0, &mpos[0], &mpos[1], dummy1); //rot_debug(RIG_DEBUG_ERR, "%s: (%.3f, %.3f) (%.3f, %.3f)\n", __func__, mpos[0], mpos[1], wpos[0], wpos[1]); 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 ef4abbf15..f46d58612 100644 --- a/rotators/ioptron/rot_ioptron.c +++ b/rotators/ioptron/rot_ioptron.c @@ -38,10 +38,9 @@ * ioptron_transaction * * cmdstr - Command to be sent to the rig. - * data - Buffer for reply string. Can be NULL, indicating that no reply is - * is needed, but answer will still be read. - * data_len - in: Size of buffer. It is the caller's responsibily to provide - * a large enough buffer for all possible replies for a command. + * data - Buffer for reply string. + * resp_len - in: Expected length of response. It is the caller's responsibily to + * provide a buffer at least 1 byte larger than this for null terminator. * * COMMANDS note: as of 12/2018 a mixture of V2 and V3 * | TTTTTTTT(T) .01 arc seconds @@ -62,136 +61,106 @@ */ static int -ioptron_transaction(ROT *rot, const char *cmdstr, - char *data, size_t data_len) +ioptron_transaction(ROT *rot, const char *cmdstr, char *data, size_t resp_len) { struct rot_state *rs; - int retval; - int retry_read = 0; - char replybuf[BUFSZ]; + int retval = 0; + int retry_read; rs = &rot->state; -transaction_write: - - rig_flush(&rs->rotport); - - if (cmdstr) + for (retry_read = 0; retry_read <= rot->state.rotport.retry; retry_read++) { - retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + rig_flush(&rs->rotport); - if (retval != RIG_OK) + if (cmdstr) { - goto transaction_quit; + retval = write_block(&rs->rotport, (unsigned char *) cmdstr, strlen(cmdstr)); + + if (retval != RIG_OK) + { + return retval; + } + } + + /** the answer */ + 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) + { + return RIG_OK; } } - /** Always read the reply to know whether the cmd went OK */ - if (!data) - { - data = replybuf; - } + /** if got here, retry loop failed */ + rig_debug(RIG_DEBUG_ERR, "%s: unexpected response, len %d: '%s'\n", __func__, + retval, data); - if (!data_len) - { - data_len = BUFSZ; - } + return -RIG_EPROTO; +} - /** the answer */ - memset(data, 0, data_len); - retval = read_string(&rs->rotport, (unsigned char *) data, data_len, ACK, - strlen(ACK), 0, 1); +/** get mount type code, initializes mount */ +static const char * +ioptron_get_info(ROT *rot) +{ + static char info[32]; + char str[6]; + int retval; - if (retval < 0) - { - if (retry_read++ < rot->state.rotport.retry) - { - goto transaction_write; - } + rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); - goto transaction_quit; - } + retval = ioptron_transaction(rot, ":MountInfo#", str, 4); - /** check for acknowledge */ - if (retval < 1) - { - rig_debug(RIG_DEBUG_ERR, "%s: unexpected response, len %d: '%s'\n", __func__, - retval, data); - return -RIG_EPROTO; - } + rig_debug(RIG_DEBUG_TRACE, "retval, RIG_OK str %d %d %str\n", retval, RIG_OK, + str); - retval = RIG_OK; -transaction_quit: - return retval; + SNPRINTF(info, sizeof(info), "MountInfo %s", str); + + return info; } /** * Opens the Port and sets all needed parameters for operation * as of 12/2018 initiates mount with V3 :MountInfo# */ -static int ioptron_open(ROT *rot) +static int +ioptron_open(ROT *rot) { + const char *info; + int retval; + char retbuf[10]; + rig_debug(RIG_DEBUG_VERBOSE, "%s called\n", __func__); - return ioptron_transaction(rot, ":Mountinfo#", NULL, 0); -} + info = ioptron_get_info(rot); -/** sets mount position, requires 4 steps - * set azmiuth - * set altitude - * goto set - * stop tracking - mount starts tracking after goto - */ -static int -ioptron_set_position(ROT *rot, azimuth_t az, elevation_t el) -{ - char cmdstr[32]; - char retbuf[10]; - int retval; - float faz, fel; + /* 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)) + { + return -RIG_ETIMEOUT; + } - rig_debug(RIG_DEBUG_TRACE, "%s called: %f %f\n", __func__, az, el); - - /* units .01 arc sec */ - faz = az * 360000; - fel = el * 360000; - /* set azmiuth, returns '1" if OK */ - SNPRINTF(cmdstr, sizeof(cmdstr), ":Sz%09.0f#", faz); - retval = ioptron_transaction(rot, cmdstr, retbuf, sizeof(retbuf)); + /** stops tracking, returns "1" if OK */ + retval = ioptron_transaction(rot, ":ST0#", retbuf, 1); if (retval != RIG_OK || retbuf[0] != ACK1) { return -RIG_EPROTO; } - /* set altitude, returns '1" if OK */ - SNPRINTF(cmdstr, sizeof(cmdstr), ":Sa+%08.0f#", fel); - retval = ioptron_transaction(rot, cmdstr, retbuf, sizeof(retbuf)); + /** set alt limit to -1 since firmware bug sometimes doesn't allow alt of 0 when limit is 0 */ + /** returns "1" if OK */ + retval = ioptron_transaction(rot, ":SAL-01#", retbuf, 1); if (retval != RIG_OK || retbuf[0] != ACK1) { return -RIG_EPROTO; } - /* move to set target, V2 command, returns '1" if OK */ - SNPRINTF(cmdstr, sizeof(cmdstr), ":MS#"); // - retval = ioptron_transaction(rot, cmdstr, retbuf, sizeof(retbuf)); - - if (retval != RIG_OK || retbuf[0] != ACK1) - { - return -RIG_EPROTO; - } - - /* stop tracking, V2 command, returns '1" if OK */ - SNPRINTF(cmdstr, sizeof(cmdstr), ":ST0#"); - retval = ioptron_transaction(rot, cmdstr, retbuf, sizeof(retbuf)); - - if (retval != RIG_OK || retbuf[0] != ACK1) - { - return -RIG_EPROTO; - } - - return retval; + return RIG_OK; } /** gets current position */ @@ -205,9 +174,9 @@ ioptron_get_position(ROT *rot, azimuth_t *az, elevation_t *el) rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); /** Get Az-Alt */ - retval = ioptron_transaction(rot, ":GAC#", posbuf, sizeof(posbuf)); + retval = ioptron_transaction(rot, ":GAC#", posbuf, 19); - if (retval != RIG_OK || strlen(posbuf) < 18) + if (retval != RIG_OK || strlen(posbuf) < 19) { return retval < 0 ? retval : -RIG_EPROTO; } @@ -218,6 +187,8 @@ ioptron_get_position(ROT *rot, azimuth_t *az, elevation_t *el) } /** convert from .01 arc sec to degrees */ + /** note that firmware only reports alt between -90 and +90 */ + /** e.g. both 80 and 100 degrees are read as 80 degrees */ *el = ((elevation_t)w / 360000.); if (sscanf(posbuf + 9, "%9f", &w) != 1) @@ -243,7 +214,7 @@ ioptron_stop(ROT *rot) rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); /** stop slew, returns "1" if OK */ - retval = ioptron_transaction(rot, ":Q#", retbuf, 10); + retval = ioptron_transaction(rot, ":Q#", retbuf, 1); if (retval != RIG_OK || retbuf[0] != ACK1) { @@ -251,7 +222,110 @@ ioptron_stop(ROT *rot) } /** stops tracking returns "1" if OK */ - retval = ioptron_transaction(rot, ":ST0#", retbuf, 10); + retval = ioptron_transaction(rot, ":ST0#", retbuf, 1); + + if (retval != RIG_OK || retbuf[0] != ACK1) + { + return -RIG_EPROTO; + } + + return RIG_OK; +} + +/** sets mount position, requires 4 steps + * set azmiuth + * set altitude + * goto set + * stop tracking - mount starts tracking after goto + */ +static int +ioptron_set_position(ROT *rot, azimuth_t az, elevation_t el) +{ + char cmdstr[32]; + char retbuf[10]; + int retval; + double faz, fel; + azimuth_t curr_az; + 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; + + /** Firmware bug: (at least for AZ Mount Pro as of FW 20200305) + * azimuth has problems going to 0 + * going to 0 from <=180 causes it to overshoot 0 and never stop + * going to 0 from >180 causes it to make a hard stop at 0 and a following + * command to <= 180 will make it rotate forever until manually stopped, + * and require resetting the mount for azimuth to work correctly again + * similar behavior is seen the other direction (>180 to 360 goes past 360, + * <=180 to 360 makes a hard stop with the possibility of loss of + * azimuth control) + * Workaround: + * get current position, if 0 is requested, go to 0.01 arcseconds away from + * 0 from the same direction (e.g. go to 0.01 arcseconds if currently <= 180, + * 129599999 arcseconds if currently > 180) + */ + if (faz == 0) + { + /* 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; + } + + if (curr_az <= 180) + { + faz = 1; + } + else + { + 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); + + if (retval != RIG_OK || retbuf[0] != ACK1) + { + return -RIG_EPROTO; + } + + /* set altitude, returns '1" if OK */ + SNPRINTF(cmdstr, sizeof(cmdstr), ":Sa+%08.0f#", fel); + retval = ioptron_transaction(rot, cmdstr, retbuf, 1); + + if (retval != RIG_OK || retbuf[0] != ACK1) + { + return -RIG_EPROTO; + } + + /* move to set target, V2 command, returns '1" if OK */ + SNPRINTF(cmdstr, sizeof(cmdstr), ":MS#"); // + retval = ioptron_transaction(rot, cmdstr, retbuf, 1); + + if (retval != RIG_OK || retbuf[0] != ACK1) + { + return -RIG_EPROTO; + } + + /* stop tracking, V2 command, returns '1" if OK */ + SNPRINTF(cmdstr, sizeof(cmdstr), ":ST0#"); + retval = ioptron_transaction(rot, cmdstr, retbuf, 1); if (retval != RIG_OK || retbuf[0] != ACK1) { @@ -261,25 +335,6 @@ ioptron_stop(ROT *rot) return retval; } -/** get mount type code, initializes mount */ -static const char * -ioptron_get_info(ROT *rot) -{ - static char info[32]; - char str[6]; - int retval; - - rig_debug(RIG_DEBUG_TRACE, "%s called\n", __func__); - - retval = ioptron_transaction(rot, ":MountInfo#", str, sizeof(str)); - - rig_debug(RIG_DEBUG_TRACE, "retval, RIG_OK str %d %d %str\n", retval, RIG_OK, - str); - - SNPRINTF(info, sizeof(info), "MountInfo %s", str); - - return info; -} @@ -304,7 +359,7 @@ const struct rot_caps ioptron_rot_caps = .rot_type = ROT_TYPE_AZEL, .port_type = RIG_PORT_SERIAL, .serial_rate_min = 9600, - .serial_rate_max = 9600, + .serial_rate_max = 115200, .serial_data_bits = 8, .serial_stop_bits = 1, .serial_parity = RIG_PARITY_NONE, 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/sctest.c b/security/sctest.c index 4d1adf5bf..2c4e2b6fc 100644 --- a/security/sctest.c +++ b/security/sctest.c @@ -129,7 +129,7 @@ int main(int argc, char *argv[]) */ strcpy(plaintext, pass_input); printf("Plaintext: %s\n", plaintext); - printf("Plaintext length: %ld\n", strlen(plaintext)); + printf("Plaintext length: %d\n", (int)strlen(plaintext)); /* * Encrypt the string 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/Makefile.am b/simulators/Makefile.am index f383f5ce7..9b0412412 100644 --- a/simulators/Makefile.am +++ b/simulators/Makefile.am @@ -8,7 +8,7 @@ DISTCLEANFILES = bin_PROGRAMS = -check_PROGRAMS = simelecraft simicgeneric simkenwood simyaesu simic9100 simic9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simic7300 simic7000 simic7100 simic7200 simatd578 simic905 simts450 simic7600 simic7610 simic705 simts950 simts990 simic7851 simftdx101 simxiegug90 simqrplabs simft818 simic275 +check_PROGRAMS = simelecraft simicgeneric simkenwood simyaesu simic9100 simic9700 simft991 simftdx1200 simftdx3000 simjupiter simpowersdr simid5100 simft736 simftdx5000 simtmd700 simrotorez simspid simft817 simts590 simft847 simic7300 simic7000 simic7100 simic7200 simatd578 simic905 simts450 simic7600 simic7610 simic705 simts950 simts990 simic7851 simftdx101 simxiegug90 simqrplabs simft818 simic275 simtrusdx simft1000 simelecraft_SOURCES = simelecraft.c simkenwood_SOURCES = simkenwood.c diff --git a/simulators/simelecraft.c b/simulators/simelecraft.c index 7a9e84c47..9296d7dbc 100644 --- a/simulators/simelecraft.c +++ b/simulators/simelecraft.c @@ -71,6 +71,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simft1000.c b/simulators/simft1000.c new file mode 100644 index 000000000..a5073172e --- /dev/null +++ b/simulators/simft1000.c @@ -0,0 +1,162 @@ +// can run this using rigctl/rigctld and socat pty devices +// gcc -o simft1000 simft1000.c +#define _XOPEN_SOURCE 700 +// since we are POSIX here we need this +#if 0 +struct ip_mreq +{ + int dummy; +}; +#endif + +#include +#include +#include +#include +#include +#include "../include/hamlib/rig.h" + +#define BUFSIZE 256 + +float freqA = 14074000; +float freqB = 14074500; +char tx_vfo = '0'; +char rx_vfo = '0'; +char modeA = '1'; +char modeB = '1'; +int width_main = 500; +int width_sub = 700; + + +int +getmyline(int fd, unsigned char *buf) +{ + unsigned char c; + int i = 0; + int n = 0; + memset(buf, 0, BUFSIZE); + + while (i < 5 && read(fd, &c, 1) > 0) + { + buf[i++] = c; + n++; + } + + printf("n=%d %02x %02x %02x %02x %02x\n", n, buf[0], buf[1], buf[2], buf[3], + buf[4]); + return n; +} + +#if defined(WIN32) || defined(_WIN32) +int openPort(char *comport) // doesn't matter for using pts devices +{ + int fd; + fd = open(comport, O_RDWR); + + if (fd < 0) + { + perror(comport); + } + + return fd; +} + +#else +int openPort(char *comport) // doesn't matter for using pts devices +{ + int fd = posix_openpt(O_RDWR); + char *name = ptsname(fd); + + if (name == NULL) + { + perror("pstname"); + return -1; + } + + printf("name=%s\n", name); + + if (fd == -1 || grantpt(fd) == -1 || unlockpt(fd) == -1) + { + perror("posix_openpt"); + return -1; + } + + return fd; +} +#endif + + + +int main(int argc, char *argv[]) +{ + unsigned char buf[256]; + +again: + int fd = openPort(argv[1]); + + while (1) + { + int bytes = getmyline(fd, buf); + + if (bytes == 0) + { + close(fd); + goto again; + } + + if (bytes != 5) + { + printf("Not 5 bytes? bytes=%d\n", bytes); + continue; + } + + switch (buf[4]) + { + case 0x01: + printf("Split\n"); + break; + + case 0x05: + printf("Select VFO\n"); + break; + + case 0x0a: + printf("Set Main freq\n"); + break; + + case 0x0c: + printf("Set mode\n"); + break; + + case 0x0e: + printf("Pacing\n"); + break; + + case 0x0f: + printf("Tx\n"); + break; + + case 0x83: + printf("Full Duplex Rx Mode\n"); + break; + + case 0x8a: + printf("Set Sub freq\n"); + break; + + case 0x8b: + printf("Bandwidth\n"); + break; + + case 0xf7: + printf("Read meter\n"); + break; + + default: printf("Unknown cmd=%02x\n", buf[4]); + } + + fflush(stdout); + } + + return 0; +} 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 a2bafe672..97dee0891 100644 --- a/simulators/simft818.c +++ b/simulators/simft818.c @@ -64,6 +64,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simft991.c b/simulators/simft991.c index d2f5b1eb2..29644b7a4 100644 --- a/simulators/simft991.c +++ b/simulators/simft991.c @@ -64,6 +64,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } @@ -138,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 f12cbdaac..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 @@ -73,6 +73,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } @@ -331,13 +333,13 @@ int main(int argc, char *argv[]) } else if (strcmp(buf, "EX010415;") == 0) { - sprintf(buf,"EX010415%03d;", rport_gain); + 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); + sscanf(buf, "EX010415%d", &rport_gain_psk); } else if (strlen(buf) > 0) diff --git a/simulators/simftdx1200.c b/simulators/simftdx1200.c index 2aa814b70..0d710fa8d 100644 --- a/simulators/simftdx1200.c +++ b/simulators/simftdx1200.c @@ -66,6 +66,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simftdx3000.c b/simulators/simftdx3000.c index 23a1ae999..71d154ba8 100644 --- a/simulators/simftdx3000.c +++ b/simulators/simftdx3000.c @@ -65,6 +65,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simftdx5000.c b/simulators/simftdx5000.c index 25450001d..16885a26c 100644 --- a/simulators/simftdx5000.c +++ b/simulators/simftdx5000.c @@ -67,6 +67,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simic275.c b/simulators/simic275.c index 388ddd2f7..6f4b3ccc0 100644 --- a/simulators/simic275.c +++ b/simulators/simic275.c @@ -103,7 +103,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -113,6 +113,12 @@ void frameParse(int fd, unsigned char *frame, int len) double freq; int n = 0; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) diff --git a/simulators/simic7000.c b/simulators/simic7000.c index 388ddd2f7..6f4b3ccc0 100644 --- a/simulators/simic7000.c +++ b/simulators/simic7000.c @@ -103,7 +103,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -113,6 +113,12 @@ void frameParse(int fd, unsigned char *frame, int len) double freq; int n = 0; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) diff --git a/simulators/simic705.c b/simulators/simic705.c index 5b270ed1a..a281ed618 100644 --- a/simulators/simic705.c +++ b/simulators/simic705.c @@ -94,7 +94,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -104,6 +104,12 @@ void frameParse(int fd, unsigned char *frame, int len) double freq; int n = 0; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) diff --git a/simulators/simic7100.c b/simulators/simic7100.c index a7494c9be..afeae7de2 100644 --- a/simulators/simic7100.c +++ b/simulators/simic7100.c @@ -101,7 +101,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -111,6 +111,12 @@ void frameParse(int fd, unsigned char *frame, int len) double freq; int n = 0; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) diff --git a/simulators/simic7200.c b/simulators/simic7200.c index 927df1f86..6acbcb4c1 100644 --- a/simulators/simic7200.c +++ b/simulators/simic7200.c @@ -115,7 +115,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -125,6 +125,12 @@ void frameParse(int fd, unsigned char *frame, int len) double freq; int n = 0; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) diff --git a/simulators/simic7300.c b/simulators/simic7300.c index c74ea71fb..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) { @@ -96,7 +96,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -106,6 +106,12 @@ void frameParse(int fd, unsigned char *frame, int len) double freq; int n = 0; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) @@ -135,6 +141,7 @@ void frameParse(int fd, unsigned char *frame, int len) if (powerstat) { + 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/simic7600.c b/simulators/simic7600.c index 2089e7085..9d625e072 100644 --- a/simulators/simic7600.c +++ b/simulators/simic7600.c @@ -94,7 +94,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -104,6 +104,12 @@ void frameParse(int fd, unsigned char *frame, int len) double freq; int n = 0; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) diff --git a/simulators/simic7610.c b/simulators/simic7610.c index d8dd118e0..60ac213c1 100644 --- a/simulators/simic7610.c +++ b/simulators/simic7610.c @@ -50,6 +50,9 @@ int ovf_status = 0; int powerstat = 1; int datamode = 0; int keyspd = 130; // 130=20WPM +int ipp = 0; +int tx_inhibit = 0; +int dpp = 0; void dumphex(const unsigned char *buf, int n) { @@ -94,7 +97,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -104,6 +107,12 @@ void frameParse(int fd, unsigned char *frame, int len) double freq; int n = 0; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) @@ -380,7 +389,7 @@ void frameParse(int fd, unsigned char *frame, int len) switch (frame[5]) { case 0x5a: - if (frame[6] == 0xfe) + if (frame[6] == 0xfd) { satmode = frame[6]; } @@ -393,6 +402,54 @@ void frameParse(int fd, unsigned char *frame, int len) 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; + 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; + 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; + n = write(fd, frame, 8); + + if (n <= 0) { fprintf(stderr, "%s(%d) write error %s\n", __func__, __LINE__, strerror(errno)); } + } + break; } @@ -739,9 +796,11 @@ int main(int argc, char **argv) while (1) { int len = frameGet(fd, buf); + printf("#1 ========================================"); if (len <= 0) { + printf("#2 ========================================"); close(fd); fd = openPort(argv[1]); } @@ -752,10 +811,12 @@ int main(int argc, char **argv) } else { - hl_usleep(1000 * 1000); + hl_usleep(100 * 1000); } + printf("#3 ========================================"); rigStatus(); + printf("#3 ========================================"); } return 0; diff --git a/simulators/simic7851.c b/simulators/simic7851.c index 0986741fe..3c62339a6 100644 --- a/simulators/simic7851.c +++ b/simulators/simic7851.c @@ -69,7 +69,7 @@ frameGet(int fd, unsigned char *buf) { int i = 0; memset(buf, 0, BUFSIZE); - unsigned char c; + unsigned char c = 0xff; again: @@ -101,7 +101,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -111,7 +111,18 @@ void frameParse(int fd, unsigned char *frame, int len) double freq; int n = 0; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + //dumphex(frame, len); + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } if (frame[0] != 0xfe && frame[1] != 0xfe) { diff --git a/simulators/simic905.c b/simulators/simic905.c index 9ee8ced5a..9038f09c8 100644 --- a/simulators/simic905.c +++ b/simulators/simic905.c @@ -99,7 +99,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -108,6 +108,12 @@ void frameParse(int fd, unsigned char *frame, int len) { double freq; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) diff --git a/simulators/simic9100.c b/simulators/simic9100.c index 6ab0aeed6..ae62cb0e3 100644 --- a/simulators/simic9100.c +++ b/simulators/simic9100.c @@ -93,7 +93,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -102,6 +102,12 @@ void frameParse(int fd, unsigned char *frame, int len) { double freq; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) @@ -511,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 96ce3c1af..ec665a569 100644 --- a/simulators/simic9700.c +++ b/simulators/simic9700.c @@ -95,7 +95,7 @@ again: } } - printf("Error??? c=x%02x\n", c); + printf("Error %s\n", strerror(errno)); return 0; } @@ -104,6 +104,12 @@ void frameParse(int fd, unsigned char *frame, int len) { double freq; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) @@ -527,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/simicgeneric.c b/simulators/simicgeneric.c index 45ae53a0d..0fb95584d 100644 --- a/simulators/simicgeneric.c +++ b/simulators/simicgeneric.c @@ -69,7 +69,7 @@ frameGet(int fd, unsigned char *buf) } } - printf("Error???\n"); + printf("Error %s\n", strerror(errno)); return 0; } @@ -78,6 +78,12 @@ void frameParse(int fd, unsigned char *frame, int len) { double freq; + if (len == 0) + { + printf("%s: len==0\n", __func__); + return; + } + dumphex(frame, len); if (frame[0] != 0xfe && frame[1] != 0xfe) diff --git a/simulators/simid5100.c b/simulators/simid5100.c index 5d270e03d..9fe31f3ec 100644 --- a/simulators/simid5100.c +++ b/simulators/simid5100.c @@ -90,7 +90,7 @@ again: } } - printf("Error???\n"); + printf("Error %s\n", strerror(errno)); return 0; } diff --git a/simulators/simkenwood.c b/simulators/simkenwood.c index fabff7b43..2f27cba27 100644 --- a/simulators/simkenwood.c +++ b/simulators/simkenwood.c @@ -61,6 +61,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simpowersdr.c b/simulators/simpowersdr.c index 3dedd8fb7..a84543a20 100644 --- a/simulators/simpowersdr.c +++ b/simulators/simpowersdr.c @@ -62,6 +62,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simqrplabs.c b/simulators/simqrplabs.c index 39372c75c..a1399cf9b 100644 --- a/simulators/simqrplabs.c +++ b/simulators/simqrplabs.c @@ -41,6 +41,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simrotorez.c b/simulators/simrotorez.c index 51101ae4d..aa1ebc6ea 100644 --- a/simulators/simrotorez.c +++ b/simulators/simrotorez.c @@ -40,6 +40,8 @@ getmyline(int fd, char *buf) printf("\n"); } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return n; } diff --git a/simulators/simtmd700.c b/simulators/simtmd700.c index e82aa49e9..e914645d2 100644 --- a/simulators/simtmd700.c +++ b/simulators/simtmd700.c @@ -61,6 +61,8 @@ getmyline(int fd, char *buf) buf[i++] = c; } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simtrusdx.c b/simulators/simtrusdx.c new file mode 100644 index 000000000..951f340aa --- /dev/null +++ b/simulators/simtrusdx.c @@ -0,0 +1,360 @@ +// can run this using rigctl/rigctld and socat pty devices +// gcc -o simyaesu simyaesu.c +#define _XOPEN_SOURCE 700 +// since we are POSIX here we need this +#if 0 +struct ip_mreq +{ + int dummy; +}; +#endif + +#include +#include +#include +#include +#include +#include +#include "sim.h" + +#define BUFSIZE 256 + +int mysleep = 20; + +float freqA = 14074000; +float freqB = 14074500; +int filternum = 7; +int datamode = 0; +int vfo, vfo_tx, ptt, ptt_data, ptt_mic, ptt_tune; +int tomode = 0; +int keyspd = 25; + +int +getmyline(int fd, char *buf) +{ + char c; + int i = 0; + memset(buf, 0, BUFSIZE); + + while (read(fd, &c, 1) > 0) + { + buf[i++] = c; + + if (c == ';') { return strlen(buf); } + } + + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + + return strlen(buf); +} + +#if defined(WIN32) || defined(_WIN32) +int openPort(char *comport) // doesn't matter for using pts devices +{ + int fd; + fd = open(comport, O_RDWR); + + if (fd < 0) + { + perror(comport); + } + + return fd; +} + +#else +int openPort(char *comport) // doesn't matter for using pts devices +{ + int fd = posix_openpt(O_RDWR); + char *name = ptsname(fd); + + if (name == NULL) + { + perror("pstname"); + return -1; + } + + printf("name=%s\n", name); + + if (fd == -1 || grantpt(fd) == -1 || unlockpt(fd) == -1) + { + perror("posix_openpt"); + return -1; + } + + return fd; +} +#endif + + + +int main(int argc, char *argv[]) +{ + char buf[256]; + char *pbuf; + int fd = openPort(argv[1]); + int freqa = 14074000, freqb = 140735000; + int modeA = 1, modeB = 2; + + while (1) + { + buf[0] = 0; + + if (getmyline(fd, buf) > 0) { printf("Cmd:%s\n", buf); } + +// else { return 0; } + + if (strcmp(buf, "RM5;") == 0) + { + printf("%s\n", buf); + hl_usleep(mysleep * 1000); + pbuf = "RM5100000;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + + else if (strcmp(buf, "AN0;") == 0) + { + printf("%s\n", buf); + hl_usleep(mysleep * 1000); + pbuf = "AN030;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + else if (strcmp(buf, "IF;") == 0) + { + char ifbuf[256]; + printf("%s\n", buf); + hl_usleep(mysleep * 1000); + pbuf = "IF000503130001000+0000000000030000000;"; + sprintf(ifbuf, "IF%011d0001000+0000000000030000000;", freqa); + //pbuf = "IF00010138698 +00000000002000000 ; + WRITE(fd, ifbuf, strlen(ifbuf)); + } + else if (strcmp(buf, "NB;") == 0) + { + hl_usleep(mysleep * 1000); + pbuf = "NB0;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + else if (strcmp(buf, "RA;") == 0) + { + hl_usleep(mysleep * 1000); + pbuf = "RA01;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + else if (strcmp(buf, "RG;") == 0) + { + hl_usleep(mysleep * 1000); + pbuf = "RG055;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + else if (strcmp(buf, "MG;") == 0) + { + hl_usleep(mysleep * 1000); + pbuf = "MG050;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + else if (strcmp(buf, "AG;") == 0) + { + hl_usleep(mysleep * 1000); + pbuf = "AG100;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + else if (strcmp(buf, "FV;") == 0) + { + hl_usleep(mysleep * 1000); + pbuf = "FV1.2;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + else if (strncmp(buf, "IS;", 3) == 0) + { + SNPRINTF(buf, sizeof(buf), "IS+0000;"); + WRITE(fd, buf, strlen(buf)); + printf("%s\n", buf); + } + else if (strncmp(buf, "IS", 2) == 0) + { + } + else if (strncmp(buf, "SM;", 3) == 0) + { + SNPRINTF(buf, sizeof(buf), "SM0035;"); + WRITE(fd, buf, strlen(buf)); + printf("%s\n", buf); + } + else if (strncmp(buf, "PC;", 3) == 0) + { + SNPRINTF(buf, sizeof(buf), "PC100;"); + WRITE(fd, buf, strlen(buf)); + printf("%s\n", buf); + } + else if (strcmp(buf, "FW;") == 0) + { + //usleep(mysleep * 1000); + pbuf = "FW240"; + WRITE(fd, pbuf, strlen(pbuf)); + hl_usleep(20 * 1000); + pbuf = "0;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + else if (strncmp(buf, "FW", 2) == 0) + { + } + else if (strcmp(buf, "ID;") == 0) + { + printf("%s\n", buf); + hl_usleep(mysleep * 1000); + SNPRINTF(buf, sizeof(buf), "ID%03d;", 20); + WRITE(fd, buf, strlen(buf)); + } + + else if (strcmp(buf, "VS;") == 0) + { + printf("%s\n", buf); + hl_usleep(mysleep * 1000); + pbuf = "VS0;"; + WRITE(fd, pbuf, strlen(pbuf)); + } + else if (strcmp(buf, "EX032;") == 0) + { + static int ant = 0; + ant = (ant + 1) % 3; + printf("%s\n", buf); + hl_usleep(mysleep * 1000); + SNPRINTF(buf, sizeof(buf), "EX032%1d;", ant); + WRITE(fd, buf, strlen(buf)); + } + else if (strncmp(buf, "EX", 2) == 0) + { + } + else if (strcmp(buf, "FA;") == 0) + { + SNPRINTF(buf, sizeof(buf), "FA%011d;", freqa); + WRITE(fd, buf, strlen(buf)); + } + else if (strcmp(buf, "FB;") == 0) + { + SNPRINTF(buf, sizeof(buf), "FB%011d;", freqb); + WRITE(fd, buf, strlen(buf)); + } + else if (strncmp(buf, "FA", 2) == 0) + { + sscanf(buf, "FA%d", &freqa); + } + else if (strncmp(buf, "FB", 2) == 0) + { + sscanf(buf, "FB%d", &freqb); + } + else if (strncmp(buf, "AI", 2) == 0) + { + // nothing to do yet + } + + else if (strncmp(buf, "PS;", 3) == 0) + { + SNPRINTF(buf, sizeof(buf), "PS1;"); + WRITE(fd, buf, strlen(buf)); + } + else if (strncmp(buf, "SA;", 3) == 0) + { + SNPRINTF(buf, sizeof(buf), "SA0;"); + WRITE(fd, buf, strlen(buf)); + } + else if (buf[3] == ';' && strncmp(buf, "SF", 2) == 0) + { + SNPRINTF(buf, sizeof(buf), "SF%c%011.0f%c;", buf[2], + buf[2] == '0' ? freqA : freqB, + buf[2] == '0' ? modeA + '0' : modeB + '0'); + WRITE(fd, buf, strlen(buf)); + } + else if (strncmp(buf, "SF", 2) == 0) + { + mode_t tmpmode = buf[14]; + + if (buf[2] == '0') { modeA = tmpmode - '0'; } + else { modeB = tmpmode - '0'; } + + printf("modeA=%c, modeB=%c\n", modeA, modeB); + + } + else if (strncmp(buf, "MD;", 3) == 0) + { + SNPRINTF(buf, sizeof(buf), "MD%d;", + modeA); // not worried about modeB yet for simulator + WRITE(fd, buf, strlen(buf)); + } + else if (strncmp(buf, "MD", 2) == 0) + { + sscanf(buf, "MD%d", &modeA); // not worried about modeB yet for simulator + } + else if (strncmp(buf, "FL;", 3) == 0) + { + SNPRINTF(buf, sizeof(buf), "FL%03d;", filternum); + WRITE(fd, buf, strlen(buf)); + } + else if (strncmp(buf, "FL", 2) == 0) + { + sscanf(buf, "FL%d", &filternum); + } + else if (strcmp(buf, "FR;") == 0) + { + SNPRINTF(buf, sizeof(buf), "FR%d;", vfo); + WRITE(fd, buf, strlen(buf)); + } + else if (strncmp(buf, "FR", 2) == 0) + { + sscanf(buf, "FR%d", &vfo); + } + else if (strcmp(buf, "FT;") == 0) + { + SNPRINTF(buf, sizeof(buf), "FT%d;", vfo_tx); + WRITE(fd, buf, strlen(buf)); + } + else if (strncmp(buf, "FT", 2) == 0) + { + sscanf(buf, "FT%d", &vfo_tx); + } + else if (strncmp(buf, "DA;", 3) == 0) + { + SNPRINTF(buf, sizeof(buf), "DA%d;", datamode); + WRITE(fd, buf, strlen(buf)); + printf("%s\n", buf); + } + else if (strncmp(buf, "DA", 2) == 0) + { + sscanf(buf, "DA%d", &datamode); + printf("%s\n", buf); + } + else if (strncmp(buf, "TO;", 3) == 0) + { + SNPRINTF(buf, sizeof(buf), "TO%d;", tomode); + } + else if (strncmp(buf, "BD;", 3) == 0) + { + } + else if (strncmp(buf, "BU;", 3) == 0) + { + } + else if (strncmp(buf, "TX", 2) == 0) + { + ptt = ptt_mic = ptt_data = ptt_tune = 0; + + switch (buf[2]) + { + case ';': ptt = 1; + + case '0': ptt_mic = 1; + + case '1': ptt_data = 1; + + case '2': ptt_tune = 1; + } + + } + + else if (strlen(buf) > 0) + { + fprintf(stderr, "Unknown command: %s\n", buf); + } + } + + return 0; +} diff --git a/simulators/simts450.c b/simulators/simts450.c index 08ab439bb..52caf30da 100644 --- a/simulators/simts450.c +++ b/simulators/simts450.c @@ -43,6 +43,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simts590.c b/simulators/simts590.c index 699d6e266..4f6f350a1 100644 --- a/simulators/simts590.c +++ b/simulators/simts590.c @@ -41,7 +41,8 @@ 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; @@ -49,6 +50,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } @@ -159,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) { @@ -416,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) { @@ -426,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 c0296fce6..4ea2136d3 100644 --- a/simulators/simts950.c +++ b/simulators/simts950.c @@ -41,6 +41,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } diff --git a/simulators/simts990.c b/simulators/simts990.c index 24d265e9b..4c5948c6c 100644 --- a/simulators/simts990.c +++ b/simulators/simts990.c @@ -80,12 +80,13 @@ 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:"); @@ -93,6 +94,8 @@ getmyline(int fd, char *buf) fd = openPort(""); } + if (strlen(buf) == 0) { hl_usleep(10 * 1000); } + return strlen(buf); } @@ -460,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/simxiegug90.c b/simulators/simxiegug90.c index ff4bd4cad..390854b03 100644 --- a/simulators/simxiegug90.c +++ b/simulators/simxiegug90.c @@ -69,7 +69,7 @@ frameGet(int fd, unsigned char *buf) } } - printf("Error???\n"); + printf("Error %s\n", strerror(errno)); return 0; } diff --git a/simulators/simyaesu.c b/simulators/simyaesu.c index 550108f89..1f5f96e8c 100644 --- a/simulators/simyaesu.c +++ b/simulators/simyaesu.c @@ -70,6 +70,8 @@ getmyline(int fd, char *buf) if (c == ';') { return strlen(buf); } } + 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 2600b12d1..a6db507bb 100644 --- a/src/cache.c +++ b/src/cache.c @@ -258,6 +258,11 @@ int rig_set_cache_freq(RIG *rig, vfo_t vfo, freq_t freq) elapsed_ms(&rig->state.cache.time_freqMem, flag); break; + case RIG_VFO_OTHER: + 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)); @@ -365,8 +370,14 @@ int rig_get_cache(RIG *rig, vfo_t vfo, freq_t *freq, int *cache_ms_freq, vfo = RIG_VFO_SUB_A; break; + case RIG_VFO_NONE: + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): ignoring VFO_NONE\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 ab9f6a1b3..6ed087f6d 100644 --- a/src/conf.c +++ b/src/conf.c @@ -268,7 +268,16 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) } rs->rigport.post_write_delay = val_i; - rs->rigport_deprecated.timeout = val_i; + rs->rigport_deprecated.post_write_delay = val_i; + break; + + case TOK_POST_PTT_DELAY: + if (1 != sscanf(val, "%ld", &val_i)) + { + return -RIG_EINVAL; + } + + rs->post_ptt_delay = val_i; break; case TOK_TIMEOUT: @@ -519,27 +528,27 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) else if (!strcmp(val, "RIGMICDATA")) { rs->pttport.type.ptt = RIG_PTT_RIG_MICDATA; - rig->caps->ptt_type = RIG_PTT_RIG_MICDATA; + caps->ptt_type = RIG_PTT_RIG_MICDATA; } else if (!strcmp(val, "DTR")) { rs->pttport.type.ptt = RIG_PTT_SERIAL_DTR; - rig->caps->ptt_type = RIG_PTT_SERIAL_DTR; + caps->ptt_type = RIG_PTT_SERIAL_DTR; } else if (!strcmp(val, "RTS")) { rs->pttport.type.ptt = RIG_PTT_SERIAL_RTS; - rig->caps->ptt_type = RIG_PTT_SERIAL_RTS; + caps->ptt_type = RIG_PTT_SERIAL_RTS; } else if (!strcmp(val, "Parallel")) { rs->pttport.type.ptt = RIG_PTT_PARALLEL; - rig->caps->ptt_type = RIG_PTT_PARALLEL; + caps->ptt_type = RIG_PTT_PARALLEL; } else if (!strcmp(val, "CM108")) { rs->pttport.type.ptt = RIG_PTT_CM108; - rig->caps->ptt_type = RIG_PTT_CM108; + caps->ptt_type = RIG_PTT_CM108; } else if (!strcmp(val, "GPIO")) { @@ -548,11 +557,12 @@ static int frontend_set_conf(RIG *rig, token_t token, const char *val) else if (!strcmp(val, "GPION")) { rs->pttport.type.ptt = RIG_PTT_GPION; - rig->caps->ptt_type = RIG_PTT_GPION; + caps->ptt_type = RIG_PTT_GPION; } else if (!strcmp(val, "None")) { rs->pttport.type.ptt = RIG_PTT_NONE; + caps->ptt_type = RIG_PTT_NONE; } else { @@ -653,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)); @@ -840,7 +851,7 @@ static int frontend_get_conf2(RIG *rig, token_t token, char *val, int val_len) break; case TOK_POST_PTT_DELAY: - SNPRINTF(val, val_len, "%d", rs->rigport.post_ptt_delay); + SNPRINTF(val, val_len, "%d", rs->post_ptt_delay); break; case TOK_TIMEOUT: diff --git a/src/event.c b/src/event.c index 10ca23ab9..342186db9 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; @@ -584,13 +608,16 @@ int HAMLIB_API rig_get_trn(RIG *rig, int *trn) RETURNFUNC(-RIG_EDEPRECATED); } +#if defined(HAVE_PTHREAD) 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) @@ -608,8 +635,9 @@ int rig_fire_freq_event(RIG *rig, vfo_t vfo, freq_t freq) RETURNFUNC(0); } +#endif - +#if defined(HAVE_PTHREAD) int rig_fire_mode_event(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) { ENTERFUNC; @@ -618,6 +646,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) @@ -634,8 +663,10 @@ int rig_fire_mode_event(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width) RETURNFUNC(0); } +#endif +#if defined(HAVE_PTHREAD) int rig_fire_vfo_event(RIG *rig, vfo_t vfo) { ENTERFUNC; @@ -654,8 +685,10 @@ int rig_fire_vfo_event(RIG *rig, vfo_t vfo) RETURNFUNC(0); } +#endif +#if defined(HAVE_PTHREAD) int rig_fire_ptt_event(RIG *rig, vfo_t vfo, ptt_t ptt) { ENTERFUNC; @@ -675,8 +708,10 @@ int rig_fire_ptt_event(RIG *rig, vfo_t vfo, ptt_t ptt) RETURNFUNC(0); } +#endif +#if defined(HAVE_PTHREAD) int rig_fire_dcd_event(RIG *rig, vfo_t vfo, dcd_t dcd) { ENTERFUNC; @@ -693,8 +728,10 @@ int rig_fire_dcd_event(RIG *rig, vfo_t vfo, dcd_t dcd) RETURNFUNC(0); } +#endif +#if defined(HAVE_PTHREAD) int rig_fire_pltune_event(RIG *rig, vfo_t vfo, freq_t *freq, rmode_t *mode, pbwidth_t *width) { @@ -712,8 +749,10 @@ int rig_fire_pltune_event(RIG *rig, vfo_t vfo, freq_t *freq, rmode_t *mode, RETURNFUNC(RIG_OK); } +#endif +#if defined(HAVE_PTHREAD) static int print_spectrum_line(char *str, size_t length, struct rig_spectrum_line *line) { @@ -771,8 +810,10 @@ static int print_spectrum_line(char *str, size_t length, return c; } +#endif +#if defined(HAVE_PTHREAD) int rig_fire_spectrum_event(RIG *rig, struct rig_spectrum_line *line) { ENTERFUNC; @@ -794,5 +835,6 @@ int rig_fire_spectrum_event(RIG *rig, struct rig_spectrum_line *line) RETURNFUNC(RIG_OK); } +#endif /** @} */ 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 459f72275..1b355ea1e 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; } @@ -1347,8 +1352,9 @@ 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); continue; } @@ -1398,7 +1404,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 @@ -1407,7 +1414,7 @@ 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 - shortcut: +shortcut: rd_count = port_read_generic(p, &rxbuffer[total_count], expected_len == 1 ? 1 : minlen, direct); // rig_debug(RIG_DEBUG_VERBOSE, "%s: read %d bytes tot=%d\n", __func__, (int)rd_count, total_count); @@ -1419,19 +1426,21 @@ 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; + } + } } diff --git a/src/misc.c b/src/misc.c index d17dd9e54..d204886bf 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 - struct icom_priv_data *icom_priv = (struct icom_priv_data *)rig->caps->priv; - if (rig->caps->rig_model == RIG_MODEL_ID5100 && icom_priv->dual_watch) + if (rig->caps->rig_model == RIG_MODEL_ID5100 && rs->dual_watch) { - if (vfo == RIG_VFO_TX) 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 } @@ -2331,7 +2334,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; } @@ -2616,7 +2620,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 @@ -2651,7 +2655,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: @@ -2791,7 +2796,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); @@ -2819,7 +2824,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() @@ -2830,50 +2835,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) @@ -2886,29 +2897,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_BANDSELECT_UNUSED; + 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) @@ -2917,7 +2935,7 @@ hamlib_band_t rig_get_band(RIG *rig, freq_t freq, int band) } } - return RIG_BANDSELECT_GEN; + return RIG_BAND_UNUSED; } // Gets the rig's band index from the hamlib_band_t @@ -2925,28 +2943,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) @@ -2956,7 +2982,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/misc.h b/src/misc.h index f2d135c94..98c130d45 100644 --- a/src/misc.h +++ b/src/misc.h @@ -166,8 +166,7 @@ void errmsg(int err, char *s, const char *func, const char *file, int line); // could be a function call #define RETURNFUNC(rc) {do { \ int rctmp = rc; \ - rig_debug(RIG_DEBUG_VERBOSE, "%.*s%d:%s(%d):%s returning(%ld) %s\n", rig->state.depth-1, spaces(), rig->state.depth, __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \ - if (rig->state.depth == 0) rig_debug(RIG_DEBUG_ERR, "%s(%d) depth=0 ******************\n", __func__, __LINE__); \ + rig_debug(RIG_DEBUG_VERBOSE, "%.*s%d:%s(%d):%s returning(%ld) %s\n", rig->state.depth, spaces(), rig->state.depth, __FILENAME__, __LINE__, __func__, (long int) (rctmp), rctmp<0?rigerror2(rctmp):""); \ --rig->state.depth; \ return (rctmp); \ } while(0);} 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 bb129472c..08842348d 100644 --- a/src/network.c +++ b/src/network.c @@ -206,6 +206,7 @@ int network_init() { retval = RIG_OK; } + #else retval = RIG_OK; @@ -473,6 +474,7 @@ extern void sync_callback(int lock); //! @cond Doxygen_Suppress #define MULTICAST_DATA_PIPE_TIMEOUT_MILLIS 1000 +#define MULTICAST_DATA_PIPE_TIMEOUT_USEC 100000 #if defined(WIN32) && defined(HAVE_WINDOWS_H) @@ -538,8 +540,7 @@ static int multicast_publisher_read_data(multicast_publisher_args { ssize_t result; - result = async_pipe_wait_for_data(mcast_publisher_args->data_pipe, - MULTICAST_DATA_PIPE_TIMEOUT_MILLIS); + result = async_pipe_wait_for_data(mcast_publisher_args->data_pipe, 100); if (result < 0) { @@ -683,8 +684,8 @@ static int multicast_publisher_read_data(const multicast_publisher_args size_t length_left = length; retry: - timeout.tv_sec = MULTICAST_DATA_PIPE_TIMEOUT_MILLIS / 1000; - timeout.tv_usec = 0; + timeout.tv_sec = 0; + timeout.tv_usec = MULTICAST_DATA_PIPE_TIMEOUT_USEC; FD_ZERO(&rfds); FD_SET(fd, &rfds); @@ -710,7 +711,10 @@ retry: if (FD_ISSET(fd, &efds)) { rig_debug(RIG_DEBUG_ERR, - "%s(): fd error when reading multicast publisher data\n", __func__); + "%s(): fd error when reading multicast publisher data: %s\n", + __func__, + strerror(errno)); + return -RIG_EIO; } @@ -966,6 +970,9 @@ void *multicast_publisher(void *arg) struct rig_state *rs = &rig->state; struct rig_spectrum_line spectrum_line; uint8_t packet_type = MULTICAST_PUBLISHER_DATA_PACKET_TYPE_SPECTRUM; + multicast_publisher_priv_data *mcast_publisher_priv = + (multicast_publisher_priv_data *) + rs->multicast_publisher_priv_data; struct sockaddr_in dest_addr; int socket_fd = args->socket_fd; @@ -983,12 +990,13 @@ void *multicast_publisher(void *arg) rs->multicast_publisher_run = 1; - while (rs->multicast_publisher_run == 1) + while (rs->multicast_publisher_run) { int result; result = multicast_publisher_read_packet(args, &packet_type, &spectrum_line, spectrum_data); + if (result != RIG_OK) { if (result == -RIG_ETIMEOUT) @@ -1032,7 +1040,10 @@ void *multicast_publisher(void *arg) } } - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Stopping multicast publisher\n", __FILE__, + rs->multicast_publisher_run = 0; + mcast_publisher_priv->thread_id = 0; + + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Stopped multicast publisher\n", __FILE__, __LINE__); return NULL; } @@ -1100,7 +1111,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); + strncpy(pwrq.ifr_name, ifname, IFNAMSIZ - 1); if (ioctl(sock, SIOCGIWNAME, &pwrq) != -1) { @@ -1141,7 +1152,6 @@ int is_wireless() #endif #endif - void *multicast_receiver(void *arg) { char data[4096]; @@ -1150,48 +1160,61 @@ void *multicast_receiver(void *arg) arg; RIG *rig = args->rig; struct rig_state *rs = &rig->state; + multicast_receiver_priv_data *mcast_receiver_priv = + (multicast_receiver_priv_data *) + rs->multicast_receiver_priv_data; struct sockaddr_in dest_addr; 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 + + // Windows wireless 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: wireless detected so localhost is being used\n", __func__); + dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); } else { - 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"); + rig_debug(RIG_DEBUG_VERBOSE, + "%s: no wireless detect so INADDR_ANY is being used\n", __func__); } + #else dest_addr.sin_addr.s_addr = inet_addr(args->multicast_addr); #endif @@ -1199,30 +1222,37 @@ 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; } rs->multicast_receiver_run = 1; - while (rs->multicast_receiver_run == 1) + while (rs->multicast_receiver_run) { struct sockaddr_in client_addr; socklen_t client_len = sizeof(client_addr); @@ -1231,38 +1261,48 @@ void *multicast_receiver(void *arg) int select_result; ssize_t result; - timeout.tv_sec = 1; - timeout.tv_usec = 0; - + timeout.tv_sec = 0; + timeout.tv_usec = MULTICAST_DATA_PIPE_TIMEOUT_USEC; FD_ZERO(&rfds); FD_SET(socket_fd, &rfds); efds = rfds; select_result = select(socket_fd + 1, &rfds, NULL, &efds, &timeout); + + if (!rs->multicast_receiver_run) + { + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): pselect signal\n", __func__, __LINE__); + break; + } + if (select_result == 0) { // Select timed out + //rig_debug(RIG_DEBUG_ERR, "%s: select timeout\n", __FILE__); continue; } - if (select_result < 0) + if (select_result <= 0) { rig_debug(RIG_DEBUG_ERR, - "%s(): select() failed when reading UDP multicast socket data: %s\n", - __func__, - strerror(errno)); + "%s((%d): select() failed when reading UDP multicast socket data: %s\n", + __func__, + __LINE__, + strerror(errno)); break; } - if (FD_ISSET(socket_fd, &efds)) + if ((result = FD_ISSET(socket_fd, &efds))) { rig_debug(RIG_DEBUG_ERR, - "%s(): fd error when reading UDP multicast socket data\n", __func__); + "%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) { @@ -1272,21 +1312,28 @@ 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 } - rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Stopping multicast receiver\n", __FILE__, - __LINE__); + rs->multicast_receiver_run = 0; + mcast_receiver_priv->thread_id = 0; + + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): Stopped multicast receiver\n", __FILE__, + __LINE__); return NULL; } @@ -1312,7 +1359,15 @@ 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__, + if (rs->multicast_publisher_priv_data != NULL) + { + rig_debug(RIG_DEBUG_WARN, "%s(%d): multicast publisher already running\n", + __FILE__, __LINE__); + RETURNFUNC(-RIG_EINVAL); + } + + rig_debug(RIG_DEBUG_VERBOSE, + "%s(%d): multicast publisher address=%s, port=%d\n", __FILE__, __LINE__, multicast_addr, multicast_port); @@ -1323,21 +1378,17 @@ int network_multicast_publisher_start(RIG *rig, const char *multicast_addr, return RIG_OK; } - if (rs->multicast_publisher_priv_data != NULL) - { - rig_debug(RIG_DEBUG_ERR, "%s(%d): multicast publisher already running\n", - __FILE__, - __LINE__); - RETURNFUNC(-RIG_EINVAL); - } - status = network_init(); +#ifdef __MINGW32__ // always RIG_OK if not Windows + if (status != RIG_OK) { RETURNFUNC(status); } +#endif + socket_fd = socket(AF_INET, SOCK_DGRAM, 0); if (socket_fd < 0) @@ -1350,19 +1401,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) @@ -1378,7 +1435,7 @@ int network_multicast_publisher_start(RIG *rig, const char *multicast_addr, } rs->snapshot_packet_sequence_number = 0; - rs->multicast_publisher_run = 1; + rs->multicast_publisher_run = 0; rs->multicast_publisher_priv_data = calloc(1, sizeof(multicast_publisher_priv_data)); @@ -1492,7 +1549,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; @@ -1501,7 +1559,16 @@ 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__, + if (rs->multicast_receiver_priv_data != NULL) + { + rig_debug(RIG_DEBUG_ERR, "%s(%d): multicast receiver already running\n", + __FILE__, + __LINE__); + RETURNFUNC(-RIG_EINVAL); + } + + rig_debug(RIG_DEBUG_VERBOSE, "%s(%d): multicast receiver address=%s, port=%d\n", + __FILE__, __LINE__, multicast_addr, multicast_port); @@ -1509,15 +1576,7 @@ int network_multicast_receiver_start(RIG *rig, const char *multicast_addr, int m { rig_debug(RIG_DEBUG_TRACE, "%s(%d): not starting multicast receiver\n", __FILE__, __LINE__); - return RIG_OK; - } - - if (rs->multicast_receiver_priv_data != NULL) - { - rig_debug(RIG_DEBUG_ERR, "%s(%d): multicast receiver already running\n", - __FILE__, - __LINE__); - RETURNFUNC(-RIG_EINVAL); + RETURNFUNC(RIG_OK); } status = network_init(); @@ -1539,22 +1598,28 @@ 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; + rs->multicast_receiver_run = 0; rs->multicast_receiver_priv_data = calloc(1, sizeof(multicast_receiver_priv_data)); @@ -1565,7 +1630,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; @@ -1605,7 +1670,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/register.c b/src/register.c index 2808a797a..a47adf10d 100644 --- a/src/register.c +++ b/src/register.c @@ -161,7 +161,7 @@ static struct //! @cond Doxygen_Suppress struct rig_list { - const struct rig_caps *caps; + struct rig_caps *caps; struct rig_list *next; }; //! @endcond @@ -189,7 +189,7 @@ static int rig_lookup_backend(rig_model_t rig_model); * Basically, this is a hash insert function that doesn't check for dup! */ //! @cond Doxygen_Suppress -int HAMLIB_API rig_register(const struct rig_caps *caps) +int HAMLIB_API rig_register(struct rig_caps *caps) { int hval; struct rig_list *p; @@ -239,7 +239,7 @@ int HAMLIB_API rig_register(const struct rig_caps *caps) */ //! @cond Doxygen_Suppress -const struct rig_caps *HAMLIB_API rig_get_caps(rig_model_t rig_model) +struct rig_caps *HAMLIB_API rig_get_caps(rig_model_t rig_model) { struct rig_list *p; @@ -389,7 +389,7 @@ int HAMLIB_API rig_unregister(rig_model_t rig_model) * executes cfunc on all the elements stored in the rig hash list */ //! @cond Doxygen_Suppress -int HAMLIB_API rig_list_foreach(int (*cfunc)(const struct rig_caps *, +int HAMLIB_API rig_list_foreach(int (*cfunc)(struct rig_caps *, rig_ptr_t), rig_ptr_t data) { diff --git a/src/rig.c b/src/rig.c index d44700daa..d128e3ab4 100644 --- a/src/rig.c +++ b/src/rig.c @@ -60,7 +60,7 @@ #include #include #include -#ifdef HAVE_PTHREAD +#if defined(HAVE_PTHREAD) #include #endif @@ -100,8 +100,10 @@ const char hamlib_version[21] = "Hamlib " PACKAGE_VERSION; const char *hamlib_version2 = "Hamlib " PACKAGE_VERSION " " HAMLIBDATETIME " " ARCHBITS; HAMLIB_EXPORT_VAR(int) cookie_use; +HAMLIB_EXPORT_VAR(int) skip_init; 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; @@ -224,7 +226,7 @@ static const char *const rigerror_table[] = #define ERROR_TBL_SZ (sizeof(rigerror_table)/sizeof(char *)) -#ifdef HAVE_PTHREAD +#if defined(HAVE_PTHREAD) typedef struct async_data_handler_args_s { RIG *rig; @@ -241,6 +243,7 @@ static int async_data_handler_stop(RIG *rig); void *async_data_handler(void *arg); #endif +#if defined(HAVE_PTHREAD) typedef struct morse_data_handler_args_s { RIG *rig; @@ -258,6 +261,7 @@ static int morse_data_handler_start(RIG *rig); static int morse_data_handler_stop(RIG *rig); int morse_data_handler_set_keyspd(RIG *rig, int keyspd); void *morse_data_handler(void *arg); +#endif /* * track which rig is opened (with rig_open) @@ -380,8 +384,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 { @@ -573,7 +577,7 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) * TODO: read the Preferences here! */ rs = &rig->state; -#ifdef HAVE_PTHREAD +#if defined(HAVE_PTHREAD) pthread_mutex_init(&rs->mutex_set_transaction, NULL); #endif @@ -673,9 +677,11 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) rs->rx_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 @@ -881,7 +887,7 @@ RIG *HAMLIB_API rig_init(rig_model_t rig_model) */ int HAMLIB_API rig_open(RIG *rig) { - const struct rig_caps *caps; + struct rig_caps *caps; struct rig_state *rs; int status = RIG_OK; value_t parm_value; @@ -1321,6 +1327,9 @@ int HAMLIB_API rig_open(RIG *rig) RETURNFUNC2(status); } +#if defined(HAVE_PTHREAD) + if (!skip_init) + { status = async_data_handler_start(rig); if (status < 0) @@ -1329,12 +1338,15 @@ int HAMLIB_API rig_open(RIG *rig) rig->state.comm_status = RIG_COMM_STATUS_ERROR; RETURNFUNC2(status); } + } +#endif rs->comm_state = 1; 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 /* @@ -1346,12 +1358,13 @@ int HAMLIB_API rig_open(RIG *rig) if (caps->rig_open != NULL) { - if (caps->get_powerstat != NULL) + if (caps->get_powerstat != NULL && !skip_init) { 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 @@ -1367,7 +1380,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__); } } @@ -1377,8 +1391,13 @@ int HAMLIB_API rig_open(RIG *rig) if (status != RIG_OK) { remove_opened_rig(rig); +#if defined(HAVE_PTHREAD) + if (!skip_init) + { async_data_handler_stop(rig); morse_data_handler_stop(rig); + } +#endif port_close(&rs->rigport, rs->rigport.type.rig); memcpy(&rs->rigport_deprecated, &rs->rigport, sizeof(hamlib_port_t_deprecated)); rs->comm_state = 0; @@ -1419,16 +1438,21 @@ int HAMLIB_API rig_open(RIG *rig) rig_strvfo(rs->current_vfo)); } } + if (skip_init) return RIG_OK; +#if defined(HAVE_PTHREAD) status = morse_data_handler_start(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); } +#endif + if (rs->auto_disable_screensaver) { // try to turn off the screensaver if possible @@ -1478,35 +1502,42 @@ int HAMLIB_API rig_open(RIG *rig) memcpy(&rs->dcdport_deprecated, &rs->dcdport, sizeof(hamlib_port_t_deprecated)); rig_flush_force(&rs->rigport, 1); +#if defined(HAVE_PTHREAD) 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 } +#endif + rig->state.comm_status = RIG_COMM_STATUS_OK; add_opened_rig(rig); @@ -1535,7 +1566,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; } @@ -1554,11 +1585,16 @@ int HAMLIB_API rig_close(RIG *rig) rig->state.comm_status = RIG_COMM_STATUS_DISCONNECTED; +#if defined(HAVE_PTHREAD) + if (!skip_init) + { morse_data_handler_stop(rig); async_data_handler_stop(rig); rig_poll_routine_stop(rig); network_multicast_receiver_stop(rig); network_multicast_publisher_stop(rig); + } +#endif /* * Let the backend say 73s to the rig. @@ -1743,7 +1779,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; } @@ -1767,7 +1803,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; } @@ -1794,7 +1830,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; } @@ -1884,7 +1920,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; } @@ -1902,22 +1938,30 @@ 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 (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)) { 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); + 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)) + 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) { 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); + 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; } } @@ -2042,6 +2086,7 @@ int rig_set_freq(RIG *rig, vfo_t vfo, freq_t freq) } } else { retry = 0; } + tfreq = freq; #endif } @@ -2118,6 +2163,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) { @@ -2194,7 +2240,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; } @@ -2300,11 +2346,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__, @@ -2339,7 +2386,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) @@ -2378,6 +2425,7 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) RETURNFUNC(-RIG_ENAVAIL); } +#if 1 // this seems redundant as we ask for freq a few lines below HAMLIB_TRACE; retcode = caps->get_freq(rig, vfo, freq); @@ -2388,6 +2436,8 @@ int HAMLIB_API rig_get_freq(RIG *rig, vfo_t vfo, freq_t *freq) RETURNFUNC(retcode); } +#endif + retcode = caps->set_vfo(rig, vfo); if (retcode != RIG_OK) @@ -2505,7 +2555,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; } @@ -2691,7 +2741,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; } @@ -2843,8 +2893,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; @@ -2896,8 +2946,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; @@ -2949,7 +2999,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! */ } @@ -3010,7 +3060,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; } @@ -3150,7 +3200,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; } @@ -3231,7 +3281,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; } @@ -3502,7 +3552,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); } @@ -3524,7 +3575,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.rigport.post_ptt_delay > 0) hl_usleep(rig->state.rigport.post_ptt_delay*1000); + + if (rig->state.post_ptt_delay > 0) { hl_usleep(rig->state.post_ptt_delay * 1000); } + ELAPSED2; RETURNFUNC(retcode); @@ -3558,7 +3611,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; } @@ -3871,7 +3924,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; } @@ -4012,7 +4065,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; } @@ -4090,7 +4143,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; } @@ -4174,7 +4227,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; } @@ -4252,7 +4305,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; } @@ -4339,7 +4392,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; } @@ -4519,7 +4572,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; } @@ -4696,7 +4749,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; } @@ -4912,7 +4965,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; } @@ -5072,7 +5125,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; } @@ -5206,7 +5259,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; } @@ -5288,7 +5341,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; } @@ -5534,7 +5587,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; } @@ -5622,7 +5675,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; } @@ -5694,7 +5747,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; } @@ -5772,7 +5825,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; } @@ -5844,7 +5897,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; } @@ -5922,7 +5975,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; } @@ -5994,7 +6047,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; } @@ -6076,7 +6129,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; } @@ -6157,7 +6210,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; } @@ -6252,7 +6305,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; } @@ -6384,7 +6438,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; } @@ -6427,16 +6481,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); } @@ -6530,7 +6586,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; } @@ -6632,7 +6688,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; @@ -6665,7 +6721,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; } @@ -6747,7 +6803,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; @@ -6781,7 +6837,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; } @@ -6853,7 +6909,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; } @@ -6930,7 +6986,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; } @@ -7001,12 +7057,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; } @@ -7029,12 +7085,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); } @@ -7097,7 +7156,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; } @@ -7111,6 +7170,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) { @@ -7203,7 +7263,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; } @@ -7268,7 +7328,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; } @@ -7336,7 +7396,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; } @@ -7348,6 +7408,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); } @@ -7408,7 +7469,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; } @@ -7520,7 +7581,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; } @@ -7617,9 +7678,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; @@ -7689,9 +7751,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,11 +7976,13 @@ int HAMLIB_API rig_cookie(RIG *rig, enum cookie_e cookie_cmd, char *cookie, return ret; } +#if defined(HAVE_PTHREAD) static pthread_mutex_t initializer = PTHREAD_MUTEX_INITIALIZER; +#endif HAMLIB_EXPORT(void) sync_callback(int lock) { -#ifdef HAVE_PTHREAD +#if defined(HAVE_PTHREAD) pthread_mutex_t client_lock = initializer; if (lock) @@ -7936,7 +8001,7 @@ HAMLIB_EXPORT(void) sync_callback(int lock) void rig_lock(RIG *rig, int lock) { -#ifdef HAVE_PTHREAD +#if defined(HAVE_PTHREAD) if (rig->state.multicast == NULL) { return; } // not initialized yet @@ -7964,10 +8029,10 @@ void rig_lock(RIG *rig, int lock) /*! @} */ -#ifdef HAVE_PTHREAD #define MAX_FRAME_LENGTH 1024 +#if defined(HAVE_PTHREAD) static int async_data_handler_start(RIG *rig) { struct rig_state *rs = &rig->state; @@ -7982,9 +8047,8 @@ 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 + sleep(2); // give other things a chance to finish opening up the rig rs->async_data_handler_thread_run = 1; rs->async_data_handler_priv_data = calloc(1, @@ -8008,11 +8072,11 @@ static int async_data_handler_start(RIG *rig) RETURNFUNC(-RIG_EINTERNAL); } -#endif // HAVE_PTHREAD - RETURNFUNC(RIG_OK); } +#endif +#if defined(HAVE_PTHREAD) static int morse_data_handler_start(RIG *rig) { struct rig_state *rs = &rig->state; @@ -8036,7 +8100,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); @@ -8049,8 +8114,10 @@ static int morse_data_handler_start(RIG *rig) RETURNFUNC(RIG_OK); } +#endif +#if defined(HAVE_PTHREAD) static int async_data_handler_stop(RIG *rig) { struct rig_state *rs = &rig->state; @@ -8058,7 +8125,6 @@ static int async_data_handler_stop(RIG *rig) ENTERFUNC; -#ifdef HAVE_PTHREAD rs->async_data_handler_thread_run = 0; async_data_handler_priv = (async_data_handler_priv_data *) @@ -8087,11 +8153,12 @@ static int async_data_handler_stop(RIG *rig) rs->async_data_handler_priv_data = NULL; } -#endif RETURNFUNC(RIG_OK); } +#endif +#if defined(HAVE_PTHREAD) static int morse_data_handler_stop(RIG *rig) { struct rig_state *rs = &rig->state; @@ -8106,16 +8173,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) { @@ -8142,8 +8212,9 @@ static int morse_data_handler_stop(RIG *rig) RETURNFUNC(RIG_OK); } +#endif - +#if defined(HAVE_PTHREAD) void *async_data_handler(void *arg) { struct async_data_handler_args_s *args = (struct async_data_handler_args_s *) @@ -8184,7 +8255,8 @@ void *async_data_handler(void *arg) __func__, result); hl_usleep(500 * 1000); } - hl_usleep(20*1000); + + hl_usleep(20 * 1000); continue; } @@ -8229,10 +8301,11 @@ void *async_data_handler(void *arg) } #endif +#if defined(HAVE_PTHREAD) 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; @@ -8242,26 +8315,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; } @@ -8274,53 +8353,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__); @@ -8329,7 +8429,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); @@ -8338,6 +8438,7 @@ void *morse_data_handler(void *arg) pthread_exit(NULL); return NULL; } +#endif HAMLIB_EXPORT(int) rig_password(RIG *rig, const char *key1) @@ -8399,6 +8500,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 @@ -8508,11 +8610,14 @@ HAMLIB_EXPORT(int) rig_is_model(RIG *rig, rig_model_t model) } +#if defined(HAVE_PTHREAD) 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; } +#endif 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 7c46b0b0e..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\n", __func__, __LINE__, i); + 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 e51803741..efa6f1677 100644 --- a/src/settings.c +++ b/src/settings.c @@ -94,11 +94,16 @@ int HAMLIB_API rig_set_level(RIG *rig, vfo_t vfo, setting_t level, value_t val) || vfo == RIG_VFO_CURR || vfo == rig->state.current_vfo) { +#if defined(HAVE_PTHREAD) + 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); } + +#endif + return caps->set_level(rig, vfo, level, val); } @@ -1030,7 +1035,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) home = "?HOME"; + + if (home == NULL) + { + home = getenv("HOMEPATH"); + } + + 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 54eb797f6..8da913dc6 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; @@ -577,9 +578,9 @@ int rig_sprintf_parm_gran(char *str, int nlen, setting_t parm, if (gran[i].step.s) { len += sprintf(str + len, - "%s(%s) ", - ms, - gran[i].step.s); + "%s(%s) ", + ms, + gran[i].step.s); } } else @@ -935,7 +936,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 4d6adb175..b8bba6bde 100644 --- a/tests/dumpcaps.c +++ b/tests/dumpcaps.c @@ -320,7 +320,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/hamlibmodels.c b/tests/hamlibmodels.c index a7cfac7f0..0a5e21596 100644 --- a/tests/hamlibmodels.c +++ b/tests/hamlibmodels.c @@ -7,7 +7,7 @@ char *list[1000]; // as of 2023-01-17 we have 275 rigs so this should cover us f int nmodels = 0; -static int hash_model_list(const struct rig_caps *caps, void *data) +static int hash_model_list(struct rig_caps *caps, void *data) { char s[256]; sprintf(s, "%s %s", caps->mfg_name, caps->model_name); diff --git a/tests/listrigs.c b/tests/listrigs.c index 230b1c413..65300d25f 100644 --- a/tests/listrigs.c +++ b/tests/listrigs.c @@ -27,7 +27,7 @@ #include -int print_caps_sum(const struct rig_caps *caps, void *data) +int print_caps_sum(struct rig_caps *caps, void *data) { const char *fmt1 = "%-13s"; printf("%6u \t%-22s \t%-23s\t%-8s \t", 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 619f92213..f898c75cd 100644 --- a/tests/rigctl.c +++ b/tests/rigctl.c @@ -79,7 +79,7 @@ static void usage(void); * NB: do NOT use -W since it's reserved by POSIX. * TODO: add an option to read from a file */ -#define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhVYZ!" +#define SHORT_OPTIONS "+m:r:p:d:P:D:s:c:t:lC:LuonvhVYZ!#" static struct option long_options[] = { {"model", 1, 0, 'm'}, @@ -107,6 +107,7 @@ static struct option long_options[] = {"help", 0, 0, 'h'}, {"version", 0, 0, 'V'}, {"cookie", 0, 0, '!'}, + {"skipinit", 0, 0, '#'}, {0, 0, 0, 0} }; @@ -145,17 +146,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 @@ -255,6 +256,9 @@ int main(int argc, char *argv[]) switch (c) { + case '#': + skip_init = 1; + break; case '!': cookie_use = 1; break; @@ -556,27 +560,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, ","); } @@ -676,7 +684,7 @@ int main(int argc, char *argv[]) my_rig->caps->model_name); } - if (my_rig->caps->get_powerstat) + if (!skip_init && my_rig->caps->get_powerstat) { rig_get_powerstat(my_rig, &rig_powerstat); my_rig->state.powerstat = rig_powerstat; diff --git a/tests/rigctl_parse.c b/tests/rigctl_parse.c index 23f0cd830..b99c782af 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 @@ -1961,6 +1965,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, @@ -2010,16 +2015,16 @@ 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 ! */ } -static int hash_model_list(const struct rig_caps *caps, void *data) +static int hash_model_list(struct rig_caps *caps, void *data) { hash_add_model(caps->rig_model, caps->mfg_name, @@ -2440,12 +2445,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); } @@ -3256,7 +3263,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); @@ -3312,22 +3319,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)); @@ -3365,6 +3376,7 @@ declare_proto_rig(get_level) fputc('\n', fout); RETURNFUNC2(RIG_OK); } + level = rig_parse_level(arg1); if (!rig_has_get_level(rig, level)) @@ -3432,26 +3444,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)) { @@ -3563,6 +3587,7 @@ declare_proto_rig(get_func) { fprintf(fout, "%s: ", cmd->arg1); } + fprintf(fout, "%d%c", func_stat, resp_sep); RETURNFUNC2(status); @@ -3584,29 +3609,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); @@ -3644,9 +3675,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: @@ -3667,9 +3703,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 { @@ -3791,8 +3831,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)) @@ -4481,6 +4523,7 @@ declare_proto_rig(dump_caps) ENTERFUNC2; #if 1 + if (rig->caps->rig_model == RIG_MODEL_NETRIGCTL) { char cmd[32]; @@ -4604,7 +4647,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); @@ -4693,8 +4738,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); @@ -5119,14 +5165,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) { @@ -5238,7 +5285,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" */ @@ -5727,21 +5775,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); @@ -5751,20 +5808,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; } @@ -5772,6 +5838,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); @@ -5779,20 +5846,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); } @@ -5812,10 +5884,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 f06856725..9f18d61b4 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); } - 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 @@ -1363,7 +1385,12 @@ void *handle_socket(void *arg) } while (!ctrl_c && (retcode == RIG_OK || RIG_IS_SOFT_ERRCODE(-retcode))); +#if defined(HAVE_PTHREAD) + if (rigctld_idle && client_count == 1) +#else + if (rigctld_idle) +#endif { rig_close(my_rig); diff --git a/tests/rigctltcp.c b/tests/rigctltcp.c index 51beb5433..207de3a19 100644 --- a/tests/rigctltcp.c +++ b/tests/rigctltcp.c @@ -1416,7 +1416,12 @@ void *handle_socket(void *arg) client_done: +#if defined(HAVE_PTHREAD) + if (rigctld_idle && client_count == 1) +#else + if (rigctld_idle) +#endif { rig_close(my_rig); 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/testmW2power.c b/tests/testmW2power.c index 9e910e95c..88c38b6ed 100644 --- a/tests/testmW2power.c +++ b/tests/testmW2power.c @@ -13,7 +13,7 @@ int nrigs = 0; -int callback(const struct rig_caps *caps, rig_ptr_t rigp) +int callback(struct rig_caps *caps, rig_ptr_t rigp) { RIG *rig = (RIG *) rigp; diff --git a/tests/testrig.c b/tests/testrig.c index 19701f49c..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%8lx, 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); diff --git a/tests/testrigopen.c b/tests/testrigopen.c index 18b8e13ed..76d535332 100644 --- a/tests/testrigopen.c +++ b/tests/testrigopen.c @@ -16,7 +16,7 @@ #define SERIAL_PORT "/dev/ttyUSB0" -int callback(const struct rig_caps *caps, rig_ptr_t rigp) +int callback(struct rig_caps *caps, rig_ptr_t rigp) { RIG *rig = (RIG *) rigp;