From df71a2226d9e534424ec73b4c4dc3b3727d719cc Mon Sep 17 00:00:00 2001 From: DL1YCF Date: Sat, 4 Dec 2021 18:05:08 +0100 Subject: [PATCH] ClientServer: make it compile at least --- Makefile | 2 +- client_server.c | 36 +++++++++++++++--------------------- client_server.h | 15 ++++++++++++--- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index d27d527..da4ca95 100644 --- a/Makefile +++ b/Makefile @@ -167,7 +167,7 @@ SERVER_OPTIONS=-D CLIENT_SERVER SERVER_SOURCES= \ client_server.c server_menu.c SERVER_HEADERS= \ -client_server.h +client_server.h server_menu.h SERVER_OBJS= \ client_server.o server_menu.o endif diff --git a/client_server.c b/client_server.c index 5692538..874f5dd 100644 --- a/client_server.c +++ b/client_server.c @@ -221,8 +221,7 @@ g_print("send_spectrum: no more receivers\n"); spectrum_data.vfo_b_ctun_freq=htonll(vfo[VFO_B].ctun_frequency); spectrum_data.vfo_a_offset=htonll(vfo[VFO_A].offset); spectrum_data.vfo_b_offset=htonll(vfo[VFO_B].offset); - s=(short)receiver[r]->meter; - spectrum_data.meter=htons(s); + spectrum_data.meter=htond(receiver[r]->meter); spectrum_data.samples=htons(rx->width); samples=rx->pixel_samples; for(int i=0;iwidth;i++) { @@ -291,7 +290,9 @@ void send_adc_data(REMOTE_CLIENT *client,int i) { adc_data.random=adc[i].random; adc_data.preamp=adc[i].preamp; adc_data.attenuation=htons(adc[i].attenuation); - adc_data.adc_attenuation=htons(adc_attenuation[i]); + adc_data.gain=htond(adc[i].gain); + adc_data.min_gain=htond(adc[i].min_gain); + adc_data.max_gain=htond(adc[i].max_gain); int bytes_sent=send_bytes(client->socket,(char *)&adc_data,sizeof(adc_data)); if(bytes_sent<0) { perror("send_adc_data"); @@ -339,12 +340,8 @@ void send_receiver_data(REMOTE_CLIENT *client,int rx) { receiver_data.height=htons(receiver[rx]->height); receiver_data.x=htons(receiver[rx]->x); receiver_data.y=htons(receiver[rx]->y); - s=(short)(receiver[rx]->volume*100.0); - receiver_data.volume=htons(s); - s=(short)receiver[rx]->rf_gain; - receiver_data.rf_gain=htons(s); - s=(short)receiver[rx]->agc_gain; - receiver_data.agc_gain=htons(s); + receiver_data.volume=htond(receiver[rx]->volume); + receiver_data.agc_gain=htond(receiver[rx]->agc_gain); int bytes_sent=send_bytes(client->socket,(char *)&receiver_data,sizeof(receiver_data)); if(bytes_sent<0) { @@ -1918,7 +1915,9 @@ g_print("INFO_ADC: %d\n",bytes_read); adc[i].random=adc_data.random; adc[i].preamp=adc_data.preamp; adc[i].attenuation=ntohs(adc_data.attenuation); - adc_attenuation[i]=ntohs(adc_data.adc_attenuation); + adc[i].gain=ntohd(adc_data.gain); + adc[i].min_gain=ntohd(adc_data.min_gain); + adc[i].max_gain=ntohd(adc_data.max_gain); } break; case INFO_RECEIVER: @@ -1976,18 +1975,14 @@ g_print("INFO_RECEIVER: %d\n",bytes_read); receiver[rx]->height=ntohs(receiver_data.height); receiver[rx]->x=ntohs(receiver_data.x); receiver[rx]->y=ntohs(receiver_data.y); - s=ntohs(receiver_data.volume); - receiver[rx]->volume=(double)s/100.0; - s=ntohs(receiver_data.rf_gain); - receiver[rx]->rf_gain=(double)s; - s=ntohs(receiver_data.agc_gain); - receiver[rx]->agc_gain=(double)s; + receiver[rx]->volume=ntohd(receiver_data.volume); + receiver[rx]->agc_gain=ntohd(receiver_data.agc_gain); // receiver[rx]->pixel_samples=NULL; g_mutex_init(&receiver[rx]->display_mutex); receiver[rx]->hz_per_pixel=(double)receiver[rx]->sample_rate/(double)receiver[rx]->pixels; - receiver[rx]->playback_handle=NULL; + //receiver[rx]->playback_handle=NULL; receiver[rx]->local_audio_buffer=NULL; receiver[rx]->local_audio_buffer_size=2048; receiver[rx]->local_audio=0; @@ -2059,8 +2054,7 @@ g_print("g_idle_add: ext_vfo_update\n"); long long ctun_frequency_b=ntohll(spectrum_data.vfo_b_ctun_freq); long long offset_a=ntohll(spectrum_data.vfo_a_offset); long long offset_b=ntohll(spectrum_data.vfo_b_offset); - short meter=ntohs(spectrum_data.meter); - receiver[r]->meter=(double)meter; + receiver[r]->meter=ntohd(spectrum_data.meter); short samples=ntohs(spectrum_data.samples); if(receiver[r]->pixel_samples==NULL) { receiver[r]->pixel_samples=g_new(float,(int)samples); @@ -2206,8 +2200,8 @@ g_print("AGC_COMMAND: rx=%d agc=%d\n",rx,a); } int rx=attenuation_cmd.id; short attenuation=ntohs(attenuation_cmd.attenuation); -g_print("CMD_RESP_RX_ATTENUATION: attenuation=%d adc_attenuation[rx[%d]->adc]=%d\n",attenuation,rx,adc_attenuation[receiver[rx]->adc]); - adc_attenuation[receiver[rx]->adc]=attenuation; +g_print("CMD_RESP_RX_ATTENUATION: attenuation=%d attenuation[rx[%d]->adc]=%d\n",attenuation,rx,adc[receiver[rx]->adc].attenuation); + adc[receiver[rx]->adc].attenuation=attenuation; } break; case CMD_RESP_RX_NOISE: diff --git a/client_server.h b/client_server.h index 926b93f..5a78441 100644 --- a/client_server.h +++ b/client_server.h @@ -25,6 +25,14 @@ #define ntohll be64toh #endif +/ +// Conversion of host(double) to/from network(unsigned int) +// Assume that double data is between -200 and 200, +// convert to uint16 via uint16 = 100.0*(double+200.0) (result in the range 0 to 40000) +// +#define htond(X) htons((uint16_6) ((X+200.0)*100.0) ) +#define ntohd(X) 0.01*ntohs(X)-200.0 + typedef enum { RECEIVER_DETACHED, RECEIVER_ATTACHED } CLIENT_STATE; @@ -112,7 +120,7 @@ typedef struct _remote_client { CLIENT_STATE state; gint receivers; gint spectrum_update_timer_id; - REMOTE_RX receiver[MAX_RECEIVERS]; + REMOTE_RX receiver[8]; void *next; } REMOTE_CLIENT; @@ -159,7 +167,9 @@ typedef struct __attribute__((__packed__)) _adc_data { uint8_t random; uint8_t preamp; uint16_t attenuation; - uint16_t adc_attenuation; + uint16_t gain; + uint16_t min_gain; + uint16_t max_gain; } ADC_DATA; typedef struct __attribute__((__packed__)) _receiver_data { @@ -196,7 +206,6 @@ typedef struct __attribute__((__packed__)) _receiver_data { uint16_t x; uint16_t y; uint16_t volume; - uint16_t rf_gain; uint16_t agc_gain; } RECEIVER_DATA; -- 2.45.2