Refactor to remove code duplication of one version of getmyline()

pull/1831/head
Daniele Forsi IU5HKX 2025-08-03 22:26:23 +02:00
rodzic 10f6504897
commit a5467f4033
10 zmienionych plików z 39 dodań i 212 usunięć

Wyświetl plik

@ -92,3 +92,25 @@ int openPort(char *comport) // doesn't matter for using pts devices
return fd;
}
#endif
// Size of command buffer
#define BUFSIZE 256
int
getmyline5(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;
}

Wyświetl plik

@ -5,7 +5,7 @@
#include <string.h>
#include <unistd.h>
#define BUFSIZE 256
#include "sim.h"
float freqA = 14074000;
float freqB = 14074500;
@ -17,28 +17,6 @@ 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;
}
#include "sim.h"
int main(int argc, char *argv[])
{
unsigned char buf[BUFSIZE];
@ -48,7 +26,7 @@ again:
while (1)
{
int bytes = getmyline(fd, buf);
int bytes = getmyline5(fd, buf);
if (bytes == 0)
{

Wyświetl plik

@ -5,7 +5,7 @@
#include <string.h>
#include <unistd.h>
#define BUFSIZE 256
#include "sim.h"
float freqA = 14074000;
float freqB = 14074500;
@ -17,28 +17,6 @@ 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;
}
#include "sim.h"
int main(int argc, char *argv[])
{
unsigned char buf[BUFSIZE];
@ -48,7 +26,7 @@ again:
while (1)
{
int bytes = getmyline(fd, buf);
int bytes = getmyline5(fd, buf);
if (bytes == 0)
{

Wyświetl plik

@ -7,7 +7,7 @@
#include <string.h>
#include <unistd.h>
#define BUFSIZE 256
#include "sim.h"
float freqA = 14074000;
float freqB = 14074500;
@ -19,28 +19,6 @@ 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;
}
#include "sim.h"
int main(int argc, char *argv[])
{
unsigned char buf[BUFSIZE];
@ -50,7 +28,7 @@ again:
while (1)
{
int bytes = getmyline(fd, buf);
int bytes = getmyline5(fd, buf);
if (bytes == 0)
{

Wyświetl plik

@ -5,7 +5,7 @@
#include <string.h>
#include <unistd.h>
#define BUFSIZE 256
#include "sim.h"
int vfo = 0; // 0=A, !0=B
float freqA = 14074000;
@ -18,28 +18,6 @@ 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;
}
#include "sim.h"
int main(int argc, char *argv[])
{
unsigned char buf[BUFSIZE];
@ -49,7 +27,7 @@ again:
while (1)
{
int bytes = getmyline(fd, buf);
int bytes = getmyline5(fd, buf);
if (bytes == 0)
{

Wyświetl plik

@ -6,7 +6,7 @@
#include <unistd.h>
//#include "hamlib/rig.h"
#define BUFSIZE 256
#include "sim.h"
/* In hono(u)r of the 10Hz resolution of the FT-847, vfo frequencies
* are stored in decaHertz(daHz)
@ -19,28 +19,6 @@ int width_sub = 700;
int vfo;
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;
}
#include "sim.h"
int main(int argc, char *argv[])
{
unsigned char buf[BUFSIZE];
@ -52,7 +30,7 @@ again:
while (1)
{
int bytes = getmyline(fd, buf);
int bytes = getmyline5(fd, buf);
if (bytes == 0)
{

Wyświetl plik

@ -8,7 +8,7 @@
#include <unistd.h>
#include "hamlib/rig.h"
#define BUFSIZE 256
#include "sim.h"
float freqA = 14074000;
float freqB = 14074500;
@ -20,28 +20,6 @@ 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;
}
#include "sim.h"
int main(int argc, char *argv[])
{
unsigned char buf[BUFSIZE];
@ -53,7 +31,7 @@ again:
while (1)
{
int bytes = getmyline(fd, buf);
int bytes = getmyline5(fd, buf);
if (bytes == 0)
{

Wyświetl plik

@ -49,25 +49,6 @@ static void load_dat(const char *filename, unsigned char buf[1492])
static unsigned char alldata[1492];
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;
}
#include "sim.h"
@ -80,7 +61,7 @@ int main(int argc, char *argv[])
while (1)
{
int bytes = getmyline(fd, buf);
int bytes = getmyline5(fd, buf);
if (bytes == 0) { continue; }

Wyświetl plik

@ -5,7 +5,7 @@
#include <string.h>
#include <unistd.h>
#define BUFSIZE 256
#include "sim.h"
float freqA = 14074000;
float freqB = 14074500;
@ -17,28 +17,6 @@ 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;
}
#include "sim.h"
int main(int argc, char *argv[])
{
unsigned char buf[BUFSIZE];
@ -48,7 +26,7 @@ again:
while (1)
{
int bytes = getmyline(fd, buf);
int bytes = getmyline5(fd, buf);
if (bytes == 0)
{

Wyświetl plik

@ -5,7 +5,7 @@
#include <string.h>
#include <unistd.h>
#define BUFSIZE 256
#include "sim.h"
float freqA = 14074000;
float freqB = 14074500;
@ -17,28 +17,6 @@ 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;
}
#include "sim.h"
int main(int argc, char *argv[])
{
unsigned char buf[BUFSIZE];
@ -49,7 +27,7 @@ again:
while (1)
{
int bytes = getmyline(fd, buf);
int bytes = getmyline5(fd, buf);
if (bytes == 0)
{