From 1a41bc4a939990c180fd79f111e1cd9ff615da97 Mon Sep 17 00:00:00 2001 From: c vw Date: Fri, 17 Dec 2021 18:15:43 +0100 Subject: [PATCH] Added RFGAIN to client/server --- client_server.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ client_server.h | 8 ++++++++ ext.c | 7 +++++++ sliders.c | 6 ++++++ 4 files changed, 70 insertions(+) diff --git a/client_server.c b/client_server.c index 874f5dd..600eff7 100644 --- a/client_server.c +++ b/client_server.c @@ -622,6 +622,23 @@ g_print("server_client_thread: CMD_RESP_RX_AGC_GAIN\n"); g_idle_add(ext_remote_command,agc_gain_command); } break; + case CMD_RESP_RX_GAIN: +g_print("server_client_thread: CMD_RESP_RX_GAIN\n"); + { + RFGAIN_COMMAND *command=g_new(RFGAIN_COMMAND,1); + command->header.data_type=header.data_type; + command->header.version=header.version; + command->header.context.client=client; + bytes_read=recv_bytes(client->socket,(char *)&command->id,sizeof(RFGAIN_COMMAND)-sizeof(header)); + if(bytes_read<0) { + g_print("server_client_thread: read %d bytes for RFGAIN_COMMAND\n",bytes_read); + perror("server_client_thread"); + // dialog box? + return NULL; + } + g_idle_add(ext_remote_command,command); + } + break; case CMD_RESP_RX_ATTENUATION: g_print("server_client_thread: CMD_RESP_RX_ATTENUATION\n"); { @@ -1268,6 +1285,22 @@ g_print("send_agc_gain rx=%d gain=%d\n",rx,gain); } } +void send_rfgain(int s, int id, double gain) { + RFGAIN_COMMAND command; +g_print("send_rfgain rx=%d gain=%f\n",id,gain); + command.header.sync=REMOTE_SYNC; + command.header.data_type=htons(CMD_RESP_RX_GAIN); + command.header.version=htonl(CLIENT_SERVER_VERSION); + command.id=id; + command.gain=htond(gain); + int bytes_sent=send_bytes(s,(char *)&command,sizeof(command)); + if(bytes_sent<0) { + perror("send_command"); + } else { + g_print("send_command RFGAIN: %d\n",bytes_sent); + } +} + void send_attenuation(int s,int rx,int attenuation) { ATTENUATION_COMMAND command; short a=(short)attenuation; @@ -2188,6 +2221,22 @@ g_print("AGC_COMMAND: rx=%d agc=%d\n",rx,a); receiver[rx]->agc_thresh=(double)thresh; } break; + case CMD_RESP_RX_GAIN: + { + RFGAIN_COMMAND command; + bytes_read=recv_bytes(client_socket,(char *)&command.id,sizeof(command)-sizeof(header)); + if(bytes_read<0) { + g_print("client_thread: read %d bytes for RFGAIN_CMD\n",bytes_read); + perror("client_thread"); + // dialog box? + return NULL; + } + int rx=command.id; + double gain=ntohd(command.gain); +g_print("CMD_RESP_RX_GAIN: new=%f rx=%d old=%f\n",gain,rx,adc[receiver[rx]->adc].gain); + adc[receiver[rx]->adc].gain=gain; + } + break; case CMD_RESP_RX_ATTENUATION: { ATTENUATION_COMMAND attenuation_cmd; diff --git a/client_server.h b/client_server.h index c3a1ec0..f430911 100644 --- a/client_server.h +++ b/client_server.h @@ -69,6 +69,7 @@ enum { CMD_RESP_RX_VOLUME, CMD_RESP_RX_AGC_GAIN, CMD_RESP_RX_ATTENUATION, + CMD_RESP_RX_GAIN, CMD_RESP_RX_SQUELCH, CMD_RESP_RX_FPS, CMD_RESP_RX_SELECT, @@ -346,6 +347,12 @@ typedef struct __attribute__((__packed__)) _attenuation_command { uint16_t attenuation; } ATTENUATION_COMMAND; +typedef struct __attribute__((__packed__)) _rfgain_command { + HEADER header; + uint8_t id; + uint16_t gain; +} RFGAIN_COMMAND; + typedef struct __attribute__((__packed__)) _squelch_command { HEADER header; uint8_t id; @@ -495,6 +502,7 @@ extern void send_volume(int s,int rx,int volume); extern void send_agc(int s,int rx,int agc); extern void send_agc_gain(int s,int rx,int gain,int hang,int thresh); extern void send_attenuation(int s,int rx,int attenuation); +extern void send_rfgain(int s,int rx, double gain); extern void send_squelch(int s,int rx,int enable,int squelch); extern void send_noise(int s,int rx,int nb,int nb2,int nr,int nr2,int anf,int snb); extern void send_band(int s,int rx,int band); diff --git a/ext.c b/ext.c index d2af6e8..135a88b 100644 --- a/ext.c +++ b/ext.c @@ -812,6 +812,13 @@ g_print("AGC_COMMAND: set_agc id=%d agc=%d\n",rx->id,rx->agc); send_agc_gain(client->socket,rx->id,(int)rx->agc_gain,(int)rx->agc_hang,(int)rx->agc_thresh); } break; + case CMD_RESP_RX_GAIN: + { + RFGAIN_COMMAND *command=(RFGAIN_COMMAND *) data; + double td=ntohd(command->gain); + set_rf_gain(command->id, td); + } + break; case CMD_RESP_RX_ATTENUATION: { ATTENUATION_COMMAND *attenuation_command=(ATTENUATION_COMMAND *)data; diff --git a/sliders.c b/sliders.c index 365ba04..1631650 100644 --- a/sliders.c +++ b/sliders.c @@ -391,6 +391,12 @@ void set_af_gain(int rx,double value) { static void rf_gain_value_changed_cb(GtkWidget *widget, gpointer data) { adc[active_receiver->adc].gain=gtk_range_get_value(GTK_RANGE(rf_gain_scale)); +#ifdef CLIENT_SERVER + if (radio_is_remote) { + send_rfgain(client_socket, active_receiver->id, adc[active_receiver->adc].gain); + } + return; +#endif switch(protocol) { #ifdef SOAPYSDR case SOAPYSDR_PROTOCOL: -- 2.45.2