Compare commits
5 commits
481a393167
...
1e247d1c89
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e247d1c89 | ||
|
|
14e5942df7 | ||
|
|
218e90587c | ||
|
|
a9abe76f5e | ||
|
|
c94ecf149b |
1 changed files with 54 additions and 13 deletions
53
irena.c
53
irena.c
|
|
@ -30,10 +30,28 @@ 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));
|
||||
}
|
||||
|
||||
|
|
@ -1936,7 +1954,7 @@ int send_irena_command(const char *c)
|
|||
{
|
||||
static int no_uart;
|
||||
if (i_buf.fd <= 0) {
|
||||
if (!no_uart)
|
||||
if (!no_uart && verbose(-1))
|
||||
fprintf(mout, "irena: no uart: %s\n", c);
|
||||
no_uart++;
|
||||
return -1;
|
||||
|
|
@ -1948,6 +1966,8 @@ 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)
|
||||
|
|
@ -1956,6 +1976,7 @@ 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;
|
||||
}
|
||||
|
|
@ -1973,9 +1994,11 @@ 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;
|
||||
|
|
@ -1990,13 +2013,15 @@ void send_fct(time_t t) {
|
|||
fct_status = -1;
|
||||
return;
|
||||
}
|
||||
if (fct_got_data >= fct_min_data || fct_last + fct_max_cadence < t)
|
||||
if (fct_got_data >= fct_min_data || fct_last + fct_max_cadence < t) {
|
||||
silent(4);
|
||||
if (!send_irena_command(fct_cmd)) {
|
||||
fct_last = t;
|
||||
fct_got_data = 0;
|
||||
fct_sent++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void process_line(const char *l)
|
||||
{
|
||||
|
|
@ -2006,13 +2031,18 @@ 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);
|
||||
}
|
||||
|
|
@ -2063,13 +2093,21 @@ 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);
|
||||
int c = snprintf(cmd, 64, "v f[%d]=:", i>>2);
|
||||
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++];
|
||||
|
|
@ -2080,6 +2118,7 @@ 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);
|
||||
|
|
@ -2425,6 +2464,7 @@ 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}
|
||||
};
|
||||
|
||||
|
|
@ -2511,11 +2551,12 @@ 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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue