Fix FIFO pop() sign issue and clean up morse data handler code

pull/1336/head
Mikael Nousiainen 2023-07-12 10:52:42 +03:00
rodzic 5a8bd96427
commit c7e73ddf8f
3 zmienionych plików z 26 dodań i 11 usunięć

Wyświetl plik

@ -35,7 +35,7 @@ int push(FIFO_RIG *fifo, const char *msg)
return RIG_OK;
}
char pop(FIFO_RIG *fifo)
int pop(FIFO_RIG *fifo)
{
if (fifo->tail == fifo->head) { return -1; }

Wyświetl plik

@ -1,4 +1,4 @@
void initFIFO(FIFO_RIG *fifo);
void resetFIFO(FIFO_RIG *fifo);
int push(FIFO_RIG *fifo, const char *msg);
char pop(FIFO_RIG *fifo);
int pop(FIFO_RIG *fifo);

Wyświetl plik

@ -7980,8 +7980,8 @@ void *async_data_handler(void *arg)
void *morse_data_handler(void *arg)
{
struct morse_data_handler_args_s *args = (struct morse_data_handler_args_s *)
arg;
struct morse_data_handler_args_s *args =
(struct morse_data_handler_args_s *) arg;
RIG *rig = args->rig;
struct rig_state *rs = &rig->state;
int result;
@ -7989,16 +7989,29 @@ void *morse_data_handler(void *arg)
rig_debug(RIG_DEBUG_VERBOSE, "%s: Starting morse data handler thread\n",
__func__);
if (rig->state.fifo_morse == NULL) rig->state.fifo_morse = calloc(1,sizeof(FIFO_RIG));
if (rig->state.fifo_morse == NULL)
{
rig->state.fifo_morse = calloc(1,sizeof(FIFO_RIG));
}
initFIFO(rig->state.fifo_morse);
while (rs->morse_data_handler_thread_run)
{
char c[11]; // up to 10 chars to be sent
memset(c,0,sizeof(c));
int n=0;
for(n=0;n<sizeof(c)-1 && (c[n]=pop(rig->state.fifo_morse))!=-1;++n);
memset(c, 0, sizeof(c));
int n = 0;
for (n = 0; n < sizeof(c) - 1; n++)
{
int d = pop(rig->state.fifo_morse);
if (d < 0)
{
break;
}
c[n] = (char) d;
}
//while((c[0]=pop(rig->state.fifo_morse))!=-1)
if (n > 0)
{
do
@ -8007,13 +8020,15 @@ void *morse_data_handler(void *arg)
if (result != RIG_OK)
{
rig_debug(RIG_DEBUG_ERR, "%s: error: %s\n", __func__, rigerror(result));
hl_usleep(100*1000);
hl_usleep(100 * 1000);
}
} while (result != RIG_OK && rig->state.fifo_morse->flush==0);
} while (result != RIG_OK && rig->state.fifo_morse->flush == 0);
}
rig->state.fifo_morse->flush = 0; // reset flush flag
hl_usleep(10*1000);
}
free(rig->state.fifo_morse);
pthread_exit(NULL);
return NULL;