Compare commits

..

No commits in common. "1e247d1c89bd3b3266550a85e7c9db7c743a56da" and "481a393167563c5d0008e540da2032cbcb9a5b5b" have entirely different histories.

53
irena.c
View file

@ -30,28 +30,10 @@ const char version[] = "$Id$";
FILE *mout;
int verbosity = 1;
int next_verbosity = 1;
static inline void silent(int v) {
if (verbosity < v)
next_verbosity = 0;
}
static inline void loud(int v) {
if (v > verbosity)
next_verbosity = v;
}
static inline int verbose(int v)
{
v = next_verbosity >= v;
next_verbosity = verbosity;
return v;
}
// replacement for perror()
void merror(const char *s)
{
int e = errno;
if (verbose(-1))
fprintf(mout, "%s: %s\n", s, strerror(e));
}
@ -1954,7 +1936,7 @@ int send_irena_command(const char *c)
{
static int no_uart;
if (i_buf.fd <= 0) {
if (!no_uart && verbose(-1))
if (!no_uart)
fprintf(mout, "irena: no uart: %s\n", c);
no_uart++;
return -1;
@ -1966,8 +1948,6 @@ int send_irena_command(const char *c)
size_t sl = strlen(c);
int n = write(i_buf.fd, c, sl);
last_irena_command_sent = t;
if (verbose(2))
fprintf(mout, "IRENA CMD sent: «%s»\n", c);
if (n==sl)
n += write(i_buf.fd, "\n", 1);
if (n != sl+1)
@ -1976,7 +1956,6 @@ int send_irena_command(const char *c)
return -3;
}
else {
if (verbose(-1))
fprintf(mout, "incomplete write: %d/%lu %s\n", n, strlen(c), c);
return -4;
}
@ -1994,11 +1973,9 @@ int fct_min_data = 1;
time_t fct_last;
char fct_cmd[16];
static inline
void send_fct(time_t t)
{
void send_fct(time_t t) {
if (fct_status != fct_size) {
if (!fct_size) {
silent(4);
if (!send_irena_command("u/f=-2")) {
fct_ack = -1;
fct_status = fct_size;
@ -2013,15 +1990,13 @@ void send_fct(time_t t)
fct_status = -1;
return;
}
if (fct_got_data >= fct_min_data || fct_last + fct_max_cadence < t) {
silent(4);
if (fct_got_data >= fct_min_data || fct_last + fct_max_cadence < t)
if (!send_irena_command(fct_cmd)) {
fct_last = t;
fct_got_data = 0;
fct_sent++;
}
}
}
void process_line(const char *l)
{
@ -2031,18 +2006,13 @@ void process_line(const char *l)
if (!strncmp(l, "=B64 ", 5)) {
fct_got_data++;
fct_packets++;
if (verbose(3))
fprintf(mout, "DATA received: «%s»\n", l);
process_base64(l+5);
return;
}
if (*l && !strncmp(l+1, "FCT ", 4)) {
fct_ack++;
if (verbose(4))
fprintf(mout, "FCT ACK received %d, «%s»\n", fct_ack, l);
return;
}
if (verbose(1))
fprintf(mout, "IRENA: %s\n", l);
eprintf(EP_M, "I %s\n", l);
}
@ -2093,21 +2063,13 @@ int send_file(const char *fn)
unsigned char buf[512];
int n;
while ((n = fread(buf, 1, sizeof(buf), f))) {
if (n<sizeof(buf))
memset(buf+n, 0, sizeof(buf)-n);
n = sizeof(buf);
n = (n+3) & ~3; // NOP
for (int i=0; i < n; ) {
char cmd[64];
int retry = 0;
int c = snprintf(cmd, 64, "v f[%d]=:", i>>2);
int c = snprintf(cmd, 64, "v f[%d]=:", i);
while (c<58) {
int nn = -i & 3;
if (c < 54 || nn > n-i)
nn = n-i;
if (!nn)
break;
unsigned char a1, a2=0, a3=0;
int nn = n-i;
a1 = buf[i++];
if (nn>1) a2 = buf[i++];
if (nn>2) a3 = buf[i++];
@ -2118,7 +2080,6 @@ int send_file(const char *fn)
}
cmd[c++] = 0;
while (retry<3) {
loud(2);
while (-2==send_irena_command(cmd))
poll_uart(1);
char *res = poll_response(2);
@ -2464,7 +2425,6 @@ struct numbers {
{.name="time_resolution", .doc="seconds", .i=&time_resolution, .flags=NU_INT},
{.name="highgain", .doc="ch#", .i=high_gain_ch, .flags=NU_INT, .size=18},
{.name="lowgain", .doc="ch#", .i=low_gain_ch, .flags=NU_INT, .size=18},
{.name="verbosity", .doc="int", .i=&verbosity, .flags=NU_INT},
{.name=0}
};
@ -2551,12 +2511,11 @@ int process_cmd(char *l)
int na = split(l, 10, av);
if (!na)
return 0;
if (verbose(2) || !strcmp(av[0], "echo")) {
fprintf(mout, "CMD:");
for (int i=0; i<na; i++)
fprintf(mout, " «%s»", av[i]);
fprintf(mout, "\n");
}
if (!strcmp(av[0], "echo")) {
return 0;
}