Compare commits
5 commits
481a393167
...
1e247d1c89
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e247d1c89 | ||
|
|
14e5942df7 | ||
|
|
218e90587c | ||
|
|
a9abe76f5e | ||
|
|
c94ecf149b |
1 changed files with 54 additions and 13 deletions
67
irena.c
67
irena.c
|
|
@ -30,11 +30,29 @@ const char version[] = "$Id$";
|
||||||
|
|
||||||
FILE *mout;
|
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()
|
// replacement for perror()
|
||||||
void merror(const char *s)
|
void merror(const char *s)
|
||||||
{
|
{
|
||||||
int e = errno;
|
int e = errno;
|
||||||
fprintf(mout, "%s: %s\n", s, strerror(e));
|
if (verbose(-1))
|
||||||
|
fprintf(mout, "%s: %s\n", s, strerror(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
@ -1936,7 +1954,7 @@ int send_irena_command(const char *c)
|
||||||
{
|
{
|
||||||
static int no_uart;
|
static int no_uart;
|
||||||
if (i_buf.fd <= 0) {
|
if (i_buf.fd <= 0) {
|
||||||
if (!no_uart)
|
if (!no_uart && verbose(-1))
|
||||||
fprintf(mout, "irena: no uart: %s\n", c);
|
fprintf(mout, "irena: no uart: %s\n", c);
|
||||||
no_uart++;
|
no_uart++;
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -1948,6 +1966,8 @@ int send_irena_command(const char *c)
|
||||||
size_t sl = strlen(c);
|
size_t sl = strlen(c);
|
||||||
int n = write(i_buf.fd, c, sl);
|
int n = write(i_buf.fd, c, sl);
|
||||||
last_irena_command_sent = t;
|
last_irena_command_sent = t;
|
||||||
|
if (verbose(2))
|
||||||
|
fprintf(mout, "IRENA CMD sent: «%s»\n", c);
|
||||||
if (n==sl)
|
if (n==sl)
|
||||||
n += write(i_buf.fd, "\n", 1);
|
n += write(i_buf.fd, "\n", 1);
|
||||||
if (n != sl+1)
|
if (n != sl+1)
|
||||||
|
|
@ -1956,7 +1976,8 @@ int send_irena_command(const char *c)
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fprintf(mout, "incomplete write: %d/%lu %s\n", n, strlen(c), c);
|
if (verbose(-1))
|
||||||
|
fprintf(mout, "incomplete write: %d/%lu %s\n", n, strlen(c), c);
|
||||||
return -4;
|
return -4;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -1973,9 +1994,11 @@ int fct_min_data = 1;
|
||||||
time_t fct_last;
|
time_t fct_last;
|
||||||
char fct_cmd[16];
|
char fct_cmd[16];
|
||||||
static inline
|
static inline
|
||||||
void send_fct(time_t t) {
|
void send_fct(time_t t)
|
||||||
|
{
|
||||||
if (fct_status != fct_size) {
|
if (fct_status != fct_size) {
|
||||||
if (!fct_size) {
|
if (!fct_size) {
|
||||||
|
silent(4);
|
||||||
if (!send_irena_command("u/f=-2")) {
|
if (!send_irena_command("u/f=-2")) {
|
||||||
fct_ack = -1;
|
fct_ack = -1;
|
||||||
fct_status = fct_size;
|
fct_status = fct_size;
|
||||||
|
|
@ -1990,12 +2013,14 @@ void send_fct(time_t t) {
|
||||||
fct_status = -1;
|
fct_status = -1;
|
||||||
return;
|
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)) {
|
if (!send_irena_command(fct_cmd)) {
|
||||||
fct_last = t;
|
fct_last = t;
|
||||||
fct_got_data = 0;
|
fct_got_data = 0;
|
||||||
fct_sent++;
|
fct_sent++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_line(const char *l)
|
void process_line(const char *l)
|
||||||
|
|
@ -2006,14 +2031,19 @@ void process_line(const char *l)
|
||||||
if (!strncmp(l, "=B64 ", 5)) {
|
if (!strncmp(l, "=B64 ", 5)) {
|
||||||
fct_got_data++;
|
fct_got_data++;
|
||||||
fct_packets++;
|
fct_packets++;
|
||||||
|
if (verbose(3))
|
||||||
|
fprintf(mout, "DATA received: «%s»\n", l);
|
||||||
process_base64(l+5);
|
process_base64(l+5);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (*l && !strncmp(l+1, "FCT ", 4)) {
|
if (*l && !strncmp(l+1, "FCT ", 4)) {
|
||||||
fct_ack++;
|
fct_ack++;
|
||||||
|
if (verbose(4))
|
||||||
|
fprintf(mout, "FCT ACK received %d, «%s»\n", fct_ack, l);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fprintf(mout, "IRENA: %s\n", l);
|
if (verbose(1))
|
||||||
|
fprintf(mout, "IRENA: %s\n", l);
|
||||||
eprintf(EP_M, "I %s\n", l);
|
eprintf(EP_M, "I %s\n", l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2063,13 +2093,21 @@ int send_file(const char *fn)
|
||||||
unsigned char buf[512];
|
unsigned char buf[512];
|
||||||
int n;
|
int n;
|
||||||
while ((n = fread(buf, 1, sizeof(buf), f))) {
|
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; ) {
|
for (int i=0; i < n; ) {
|
||||||
char cmd[64];
|
char cmd[64];
|
||||||
int retry = 0;
|
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) {
|
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;
|
unsigned char a1, a2=0, a3=0;
|
||||||
int nn = n-i;
|
|
||||||
a1 = buf[i++];
|
a1 = buf[i++];
|
||||||
if (nn>1) a2 = buf[i++];
|
if (nn>1) a2 = buf[i++];
|
||||||
if (nn>2) a3 = buf[i++];
|
if (nn>2) a3 = buf[i++];
|
||||||
|
|
@ -2080,6 +2118,7 @@ int send_file(const char *fn)
|
||||||
}
|
}
|
||||||
cmd[c++] = 0;
|
cmd[c++] = 0;
|
||||||
while (retry<3) {
|
while (retry<3) {
|
||||||
|
loud(2);
|
||||||
while (-2==send_irena_command(cmd))
|
while (-2==send_irena_command(cmd))
|
||||||
poll_uart(1);
|
poll_uart(1);
|
||||||
char *res = poll_response(2);
|
char *res = poll_response(2);
|
||||||
|
|
@ -2425,6 +2464,7 @@ struct numbers {
|
||||||
{.name="time_resolution", .doc="seconds", .i=&time_resolution, .flags=NU_INT},
|
{.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="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="lowgain", .doc="ch#", .i=low_gain_ch, .flags=NU_INT, .size=18},
|
||||||
|
{.name="verbosity", .doc="int", .i=&verbosity, .flags=NU_INT},
|
||||||
{.name=0}
|
{.name=0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -2511,11 +2551,12 @@ int process_cmd(char *l)
|
||||||
int na = split(l, 10, av);
|
int na = split(l, 10, av);
|
||||||
if (!na)
|
if (!na)
|
||||||
return 0;
|
return 0;
|
||||||
fprintf(mout, "CMD:");
|
if (verbose(2) || !strcmp(av[0], "echo")) {
|
||||||
for (int i=0; i<na; i++)
|
fprintf(mout, "CMD:");
|
||||||
fprintf(mout, " «%s»", av[i]);
|
for (int i=0; i<na; i++)
|
||||||
fprintf(mout, "\n");
|
fprintf(mout, " «%s»", av[i]);
|
||||||
|
fprintf(mout, "\n");
|
||||||
|
}
|
||||||
if (!strcmp(av[0], "echo")) {
|
if (!strcmp(av[0], "echo")) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue