kopia lustrzana https://github.com/Hamlib/Hamlib
Add fifo routine to be used for CW queueing
rodzic
ce052db3a2
commit
4f3bdbdffe
|
@ -10,7 +10,7 @@ RIGSRC = hamlibdatetime.h rig.c serial.c serial.h misc.c misc.h register.c regis
|
|||
network.c network.h cm108.c cm108.h gpio.c gpio.h idx_builtin.h token.h \
|
||||
par_nt.h microham.c microham.h amplifier.c amp_reg.c amp_conf.c \
|
||||
amp_conf.h amp_settings.c extamp.c sleep.c sleep.h sprintflst.c \
|
||||
sprintflst.h cache.c cache.h snapshot_data.c snapshot_data.h multicast.c
|
||||
sprintflst.h cache.c cache.h snapshot_data.c snapshot_data.h multicast.c fifo.c
|
||||
|
||||
if VERSIONDLL
|
||||
RIGSRC += \
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
#include <hamlib/rig.h>
|
||||
#include <stdio.h>
|
||||
#include "fifo.h"
|
||||
|
||||
|
||||
void initFIFO(FIFO *fifo)
|
||||
{
|
||||
fifo->head = 0;
|
||||
fifo->tail = 0;
|
||||
}
|
||||
|
||||
// returns RIG_OK if added
|
||||
// return -RIG error if overflow
|
||||
int push(FIFO *fifo, const char *msg)
|
||||
{
|
||||
int len = strlen(msg);
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
{
|
||||
fifo->data[fifo->tail] = msg[i];
|
||||
fifo->tail = (fifo->tail + 1) % FIFO_SIZE;
|
||||
|
||||
if (fifo->tail == fifo->head) { return -RIG_EDOM; }
|
||||
}
|
||||
|
||||
return RIG_OK;
|
||||
}
|
||||
|
||||
char pop(FIFO *fifo)
|
||||
{
|
||||
if (fifo->tail == fifo->head) { return -1; }
|
||||
|
||||
char c = fifo->data[fifo->head];
|
||||
fifo->head = (fifo->head + 1) % FIFO_SIZE;
|
||||
return c;
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
int main()
|
||||
{
|
||||
FIFO fifo;
|
||||
initFIFO(&fifo);
|
||||
|
||||
const char *str = "Hello, World!\n";
|
||||
|
||||
// Pushing the string onto the FIFO
|
||||
push(&fifo, str);
|
||||
|
||||
// Popping and printing one character at a time
|
||||
int c;
|
||||
while ((c = pop(&fifo)) != -1)
|
||||
{
|
||||
printf("%c", c);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,12 @@
|
|||
#define FIFO_SIZE 1024
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char data[FIFO_SIZE];
|
||||
int head;
|
||||
int tail;
|
||||
} FIFO;
|
||||
|
||||
void initFIFO(FIFO *fifo);
|
||||
int push(FIFO *fifo, const char *msg);
|
||||
char pop(FIFO *fifo);
|
Ładowanie…
Reference in New Issue