minisatip: set voltage for all tuners (at once), handle LEDs

This commit is contained in:
Jaroslav Kysela 2015-04-03 22:11:41 +02:00
parent 2f525be0dc
commit 7906071467
1 changed files with 204 additions and 39 deletions

View File

@ -1,8 +1,8 @@
diff --git a/adapter.c b/adapter.c
index 285faea..e07e8a3 100755
index 285faea..d1fcf93 100755
--- a/adapter.c
+++ b/adapter.c
@@ -29,10 +29,14 @@
@@ -29,10 +29,15 @@
#include <linux/dvb/dmx.h>
#include <poll.h>
#include <linux/ioctl.h>
@ -12,12 +12,13 @@ index 285faea..e07e8a3 100755
#include "dvb.h"
#include "adapter.h"
+#ifdef AXE
+#define AXE_MAIN 1
+#include "axe.h"
+#endif
adapter a[MAX_ADAPTERS];
extern struct struct_opts opts;
@@ -49,7 +53,12 @@ find_adapters ()
@@ -49,7 +54,12 @@ find_adapters ()
for (i = 0; i < 8; i++)
for (j = 0; j < 8; j++)
{
@ -30,11 +31,15 @@ index 285faea..e07e8a3 100755
fd = open (buf, O_RDONLY | O_NONBLOCK);
//LOG("testing device %s -> fd: %d",buf,fd);
if (fd >= 0)
@@ -61,6 +70,13 @@ find_adapters ()
@@ -61,6 +71,17 @@ find_adapters ()
if (na == MAX_ADAPTERS)
return;
}
+#ifdef AXE
+ if (i == 0)
+ axe_set_network_led(0);
+ if (i < 4)
+ axe_set_tuner_led(i + 1, 0);
+ if (i < 4 && fd < 0) {
+ LOGL(0, "AXE - cannot open %s: %i", buf, errno);
+ sleep(60);
@ -44,7 +49,7 @@ index 285faea..e07e8a3 100755
}
for (na; na < MAX_ADAPTERS; na++)
a[na].pa = a[na].fn = -1;
@@ -122,9 +138,18 @@ init_hw ()
@@ -122,9 +143,18 @@ init_hw ()
find_adapters ();
LOG ("trying to open [%d] adapter %d and frontend %d", i, a[i].pa,
a[i].fn);
@ -63,7 +68,7 @@ index 285faea..e07e8a3 100755
a[i].dvr = open (buf, O_RDONLY | O_NONBLOCK);
if (a[i].fe < 0 || a[i].dvr < 0)
{
@@ -151,10 +176,12 @@ init_hw ()
@@ -151,10 +181,12 @@ init_hw ()
num_adapters++;
LOG ("opened DVB adapter %d fe:%d dvr:%d", i, a[i].fe, a[i].dvr);
@ -76,7 +81,7 @@ index 285faea..e07e8a3 100755
init_dvb_parameters (&a[i].tp);
mark_pids_deleted (i, -1, NULL);
update_pids (i);
@@ -194,6 +221,22 @@ close_adapter (int na)
@@ -194,6 +226,24 @@ close_adapter (int na)
mark_pids_deleted (na, -1, NULL);
update_pids (na);
// if(a[na].dmx>0)close(a[na].dmx);
@ -85,21 +90,23 @@ index 285faea..e07e8a3 100755
+ int i;
+ axe_fe_reset(a[na].fe);
+ for (i = 0; i < 4; i++)
+ if (i != na && a[i].fe > 0) break;
+ if (i != na && a[i].sid_cnt > 0) break;
+ if (i >= 4) {
+ LOG("AXE standby");
+ axe_fe_standby(a[na].fe, -1);
+ for (i = 0; i < 4; i++) {
+ axe_fe_standby(a[i].fe, -1);
+ ioctl(a[i].fe, FE_SET_VOLTAGE, SEC_VOLTAGE_OFF);
+ a[i].tp.old_diseqc = a[i].tp.old_pol = a[i].tp.old_hiband = -1;
+ }
+ } else {
+ LOG("AXE standby: adapter %d busy, keeping", i);
+ LOG("AXE standby: adapter %d busy (%d), keeping", i, a[i].sid_cnt);
+ }
+ ioctl(a[na].fe, FE_SET_VOLTAGE, SEC_VOLTAGE_OFF);
+ a[na].tp.old_diseqc = a[na].tp.old_pol = a[na].tp.old_hiband = -1;
+ }
+#endif
if (a[na].fe > 0)
close (a[na].fe);
if (a[na].sock >= 0)
@@ -366,7 +409,30 @@ close_adapter_for_stream (int sid, int aid)
@@ -366,7 +416,33 @@ close_adapter_for_stream (int sid, int aid)
// delete the attached PIDs as well
mark_pids_deleted (aid, sid, NULL);
update_pids (aid);
@ -109,16 +116,19 @@ index 285faea..e07e8a3 100755
+ int i;
+ char buf[50];
+ axe_fe_reset(a[aid].fe);
+ axe_set_tuner_led(aid + 1, 0);
+ for (i = 0; i < 4; i++)
+ if (i != aid && a[i].sid_cnt > 0) break;
+ if (i >= 4) {
+ LOG("AXE standby");
+ axe_fe_standby(a[aid].fe, -1);
+ for (i = 0; i < 4; i++) {
+ axe_fe_standby(a[i].fe, -1);
+ ioctl(a[i].fe, FE_SET_VOLTAGE, SEC_VOLTAGE_OFF);
+ a[i].tp.old_diseqc = a[i].tp.old_pol = a[i].tp.old_hiband = -1;
+ }
+ } else {
+ LOG("AXE standby: adapter %d busy, keeping", i);
+ LOG("AXE standby: adapter %d busy (%d), keeping", i, a[i].sid_cnt);
+ }
+ ioctl(a[aid].fe, FE_SET_VOLTAGE, SEC_VOLTAGE_OFF);
+ a[aid].tp.old_diseqc = a[aid].tp.old_pol = a[aid].tp.old_hiband = -1;
+ sockets_del(a[aid].sock);
+ sprintf (buf, "/dev/axe/demuxts-%d", a[i].pa);
+ a[aid].dvr = open (buf, O_RDONLY | O_NONBLOCK);
@ -131,7 +141,18 @@ index 285faea..e07e8a3 100755
// close_adapter (aid);
}
@@ -684,7 +750,11 @@ describe_adapter (int sid, int aid)
@@ -419,6 +495,10 @@ int tune (int aid, int sid)
ad->tp.switch_type = ad->switch_type;
ad->tp.uslot = ad->uslot;
ad->tp.ufreq = ad->ufreq;
+
+#ifdef AXE
+ axe_set_tuner_led(aid + 1, 1);
+#endif
rv = tune_it_s2 (ad->fe, &ad->tp);
a[aid].status = 0;
@@ -684,7 +764,11 @@ describe_adapter (int sid, int aid)
memset (dad, 0, sizeof (dad));
x = 0;
// do just max 3 signal check 1s after tune
@ -143,7 +164,7 @@ index 285faea..e07e8a3 100755
{
int new_gs = 1;
ts = getTick ();
@@ -701,11 +771,20 @@ describe_adapter (int sid, int aid)
@@ -701,11 +785,20 @@ describe_adapter (int sid, int aid)
if (ad->max_snr <= ad->snr) ad->max_snr = (ad->snr>0)?ad->snr:1;
LOG ("get_signal%s took %d ms for adapter %d handle %d (status: %d, ber: %d, strength:%d, snr: %d, max_strength: %d, max_snr: %d %d)",
new_gs?"":"_new", getTick () - ts, aid, ad->fe, ad->status, ad->ber, ad->strength, ad->snr, ad->max_strength, ad->max_snr, opts.force_scan);
@ -164,7 +185,7 @@ index 285faea..e07e8a3 100755
}
if(use_ad)
{
@@ -715,14 +794,14 @@ describe_adapter (int sid, int aid)
@@ -715,14 +808,14 @@ describe_adapter (int sid, int aid)
}
if (t->sys == SYS_DVBS || t->sys == SYS_DVBS2)
sprintf (dad, "ver=1.0;src=%d;tuner=%d,%d,%d,%d,%d,%s,%s,%s,%s,%s,%d,%s;pids=",
@ -184,10 +205,10 @@ index 285faea..e07e8a3 100755
if (use_ad && ad->pids[i].flags == 1)
diff --git a/axe.h b/axe.h
new file mode 100644
index 0000000..5af4c73
index 0000000..c29131d
--- /dev/null
+++ b/axe.h
@@ -0,0 +1,59 @@
@@ -0,0 +1,113 @@
+#ifndef __AXE_H
+#define __AXE_H
+
@ -246,9 +267,63 @@ index 0000000..5af4c73
+ return ioctl(fd, DMXTS_REMOVE_PID, &pid);
+}
+
+#ifdef AXE_MAIN
+
+int axe_fp_fd = -1;
+
+static inline axe_fp_fd_open(void)
+{
+ if (axe_fp_fd < 0)
+ axe_fp_fd = open("/dev/axe/fp-0", O_WRONLY);
+}
+
+static inline axe_fp_fd_write(const char *s)
+{
+ const char *b;
+ size_t len;
+ ssize_t r;
+
+ axe_fp_fd_open();
+ len = strlen(b = s);
+ while (len > 0) {
+ r = write(axe_fp_fd, b, len);
+ if (r > 0) {
+ len -= r;
+ b += r;
+ }
+ }
+}
+
+void axe_set_tuner_led(int tuner, int on)
+{
+ static int state = -1;
+ char buf[16];
+ if (state != on) {
+ sprintf(buf, "T%d_LED %d\n", tuner, on ? 1 : 0);
+ axe_fp_fd_write(buf);
+ state = on;
+ }
+}
+
+void axe_set_network_led(int on)
+{
+ static int state = -1;
+ if (state != on) {
+ axe_fp_fd_write(on ? "NET_LED 1\n" : "NET_LED 0\n");
+ state = on;
+ }
+}
+
+#else
+
+void axe_set_tuner_led(int tuner, int on);
+void axe_set_network_led(int on);
+
+#endif
+
+#endif
diff --git a/dvb.c b/dvb.c
index 5701bd2..bfb1cdd 100755
index 5701bd2..3638836 100755
--- a/dvb.c
+++ b/dvb.c
@@ -41,6 +41,10 @@
@ -262,7 +337,67 @@ index 5701bd2..bfb1cdd 100755
extern struct struct_opts opts;
@@ -343,6 +347,13 @@ int setup_switch (int frontend_fd, transponder *tp)
@@ -215,6 +219,29 @@ msleep (uint32_t msec)
;
}
+#ifdef AXE
+void axe_wakeup(int voltage)
+{
+ int i;
+ adapter *a;
+ for (i = 0; i < 4; i++) {
+ a = get_adapter(i);
+ if (a == NULL || a->force_disable)
+ continue;
+ if (a->tp.old_pol >= 0)
+ return;
+ }
+ LOG("AXE wakeup");
+ for (i = 0; i < 4; i++) {
+ a = get_adapter(i);
+ if (a == NULL || a->force_disable)
+ continue;
+ if (ioctl(a->fe, FE_SET_VOLTAGE, voltage) == -1)
+ LOG("axe_wakeup: FE_SET_VOLTAGE failed fd %d: %s", a->fe, strerror(errno));
+ }
+}
+#endif
+
int send_diseqc(int fd, int pos, int pol, int hiband)
{
struct dvb_diseqc_master_cmd cmd = {
@@ -229,6 +256,9 @@ int send_diseqc(int fd, int pos, int pol, int hiband)
if (ioctl(fd, FE_SET_TONE, SEC_TONE_OFF) == -1)
LOG("send_diseqc: FE_SET_TONE failed for fd %d: %s", fd, strerror(errno));
+#ifdef AXE
+ axe_wakeup(pol ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13);
+#endif
if (ioctl(fd, FE_SET_VOLTAGE, pol ? SEC_VOLTAGE_18 : SEC_VOLTAGE_13) == -1)
LOG("send_diseqc: FE_SET_VOLTAGE failed for fd %d: %s", fd, strerror(errno));
@@ -262,6 +292,9 @@ int send_unicable(int fd, int freq, int pos, int pol, int hiband, int slot, int
LOGL(3, "send_unicable fd %d, freq %d, ufreq %d, pos = %d, pol = %d, hiband = %d, slot %d, diseqc => %02x %02x %02x %02x %02x",
fd, freq, ufreq, pos, pol, hiband, slot, cmd.msg[0], cmd.msg[1], cmd.msg[2], cmd.msg[3], cmd.msg[4]);
+#ifdef AXE
+ axe_wakeup(SEC_VOLTAGE_13);
+#endif
if (ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13) == -1)
LOG("send_unicable: pre voltage SEC_VOLTAGE_13 failed for fd %d: %s", fd, strerror(errno));
msleep(15);
@@ -295,6 +328,9 @@ int send_jess(int fd, int freq, int pos, int pol, int hiband, int slot, int ufre
LOGL(3, "send_jess fd %d, freq %d, ufreq %d, pos = %d, pol = %d, hiband = %d, slot %d, diseqc => %02x %02x %02x %02x %02x",
fd, freq, ufreq, pos, pol, hiband, slot, cmd.msg[0], cmd.msg[1], cmd.msg[2], cmd.msg[3], cmd.msg[4]);
+#ifdef AXE
+ axe_wakeup(SEC_VOLTAGE_13);
+#endif
if (ioctl(fd, FE_SET_VOLTAGE, SEC_VOLTAGE_13) == -1)
LOG("send_jess: pre voltage SEC_VOLTAGE_13 failed for fd %d: %s", fd, strerror(errno));
msleep(15);
@@ -343,6 +379,13 @@ int setup_switch (int frontend_fd, transponder *tp)
else
LOGL(3, "Skip sending diseqc commands since the switch position doesn't need to be changed: pol %d, hiband %d, switch position %d", pol, hiband, diseqc);
}
@ -276,7 +411,7 @@ index 5701bd2..bfb1cdd 100755
tp->old_pol = pol;
tp->old_hiband = hiband;
@@ -383,8 +394,10 @@ tune_it_s2 (int fd_frontend, transponder * tp)
@@ -383,8 +426,10 @@ tune_it_s2 (int fd_frontend, transponder * tp)
{.cmd = DTV_INVERSION,.u.data = 0},
{.cmd = DTV_SYMBOL_RATE,.u.data = 0},
{.cmd = DTV_INNER_FEC,.u.data = 0},
@ -287,7 +422,7 @@ index 5701bd2..bfb1cdd 100755
{.cmd = DTV_TUNE},
};
static struct dtv_properties dvbs2_cmdseq =
@@ -465,8 +478,10 @@ tune_it_s2 (int fd_frontend, transponder * tp)
@@ -465,8 +510,10 @@ tune_it_s2 (int fd_frontend, transponder * tp)
p = &dvbs2_cmdseq;
p->props[DELSYS].u.data = tp->sys;
p->props[MODULATION].u.data = tp->mtype;
@ -298,7 +433,7 @@ index 5701bd2..bfb1cdd 100755
p->props[INVERSION].u.data = tp->inversion;
p->props[SYMBOL_RATE].u.data = tp->sr;
p->props[FEC_INNER].u.data = tp->fec;
@@ -475,7 +490,12 @@ tune_it_s2 (int fd_frontend, transponder * tp)
@@ -475,7 +522,12 @@ tune_it_s2 (int fd_frontend, transponder * tp)
LOG("tuning to %d(%d) pol: %s (%d) sr:%d fec:%s delsys:%s mod:%s rolloff:%s pilot:%s, ts clear=%d, ts pol=%d",
tp->freq, p->props[FREQUENCY].u.data, get_pol(tp->pol), tp->pol, p->props[SYMBOL_RATE].u.data, fe_fec[p->props[FEC_INNER].u.data],
fe_delsys[p->props[DELSYS].u.data], fe_modulation[p->props[MODULATION].u.data],
@ -312,7 +447,7 @@ index 5701bd2..bfb1cdd 100755
break;
@@ -560,6 +580,20 @@ set_pid (int hw, int ad, uint16_t i_pid)
@@ -560,6 +612,20 @@ set_pid (int hw, int ad, uint16_t i_pid)
char buf[100];
int fd;
@ -333,7 +468,7 @@ index 5701bd2..bfb1cdd 100755
if ( i_pid > 8192 )
LOG_AND_RETURN(-1, "pid %d > 8192 for /dev/dvb/adapter%d/demux%d", i_pid, hw, ad);
@@ -585,6 +619,7 @@ set_pid (int hw, int ad, uint16_t i_pid)
@@ -585,6 +651,7 @@ set_pid (int hw, int ad, uint16_t i_pid)
}
LOG ("setting filter on PID %d for fd %d", i_pid, fd);
@ -341,7 +476,7 @@ index 5701bd2..bfb1cdd 100755
return fd;
}
@@ -592,6 +627,17 @@ set_pid (int hw, int ad, uint16_t i_pid)
@@ -592,6 +659,17 @@ set_pid (int hw, int ad, uint16_t i_pid)
int del_filters (int fd, int pid)
{
@ -359,7 +494,7 @@ index 5701bd2..bfb1cdd 100755
if (fd < 0)
LOG_AND_RETURN(0, "DMX_STOP on an invalid handle %d, pid %d", fd, pid);
if (ioctl (fd, DMX_STOP) < 0)
@@ -599,6 +645,7 @@ int del_filters (int fd, int pid)
@@ -599,6 +677,7 @@ int del_filters (int fd, int pid)
else
LOG ("clearing filters on PID %d FD %d", pid, fd);
close (fd);
@ -367,7 +502,7 @@ index 5701bd2..bfb1cdd 100755
return 0;
}
@@ -606,6 +653,15 @@ int del_filters (int fd, int pid)
@@ -606,6 +685,15 @@ int del_filters (int fd, int pid)
fe_delivery_system_t
dvb_delsys (int aid, int fd, fe_delivery_system_t *sys)
{
@ -383,7 +518,7 @@ index 5701bd2..bfb1cdd 100755
int i, res, rv = 0;
struct dvb_frontend_info fe_info;
@@ -703,6 +759,7 @@ dvb_delsys (int aid, int fd, fe_delivery_system_t *sys)
@@ -703,6 +791,7 @@ dvb_delsys (int aid, int fd, fe_delivery_system_t *sys)
LOG ("returning default from dvb_delsys => %s (count %d)", fe_delsys[rv] , nsys);
return (fe_delivery_system_t) rv;
@ -392,7 +527,7 @@ index 5701bd2..bfb1cdd 100755
}
diff --git a/minisatip.c b/minisatip.c
index d4076ba..06db623 100755
index d4076ba..4cc82dc 100755
--- a/minisatip.c
+++ b/minisatip.c
@@ -36,6 +36,7 @@
@ -455,7 +590,17 @@ index d4076ba..06db623 100755
{
if( s->rlen > RBUF - 10 )
{
@@ -726,8 +738,7 @@ read_http (sockets * s)
@@ -524,6 +536,9 @@ read_rtsp (sockets * s)
return 0;
}
+#ifdef AXE
+ axe_set_network_led(1);
+#endif
rlen = s->rlen;
s->rlen = 0;
@@ -726,8 +741,7 @@ read_http (sockets * s)
"%s"
"</device></root>";
@ -465,7 +610,27 @@ index d4076ba..06db623 100755
{
if( s->rlen > RBUF - 10 )
{
@@ -987,7 +998,13 @@ main (int argc, char *argv[])
@@ -749,6 +763,9 @@ read_http (sockets * s)
return 0;
}
+#ifdef AXE
+ axe_set_network_led(1);
+#endif
rlen = s->rlen;
s->rlen = 0;
@@ -904,6 +921,9 @@ ssdp_reply (sockets * s)
return 0;
}
+#ifdef AXE
+ axe_set_network_led(1);
+#endif
// not my uuid
LOG("Received SSDP packet from %s:%d -> handle %d", inet_ntoa(s->sa.sin_addr), ntohs(s->sa.sin_port), s->sock);
LOGL(3, "%s", s->buf);
@@ -987,7 +1007,13 @@ main (int argc, char *argv[])
set_options (argc, argv);
if (opts.daemon)
becomeDaemon ();
@ -479,7 +644,7 @@ index d4076ba..06db623 100755
readBootID();
if ((ssdp = udp_bind (NULL, 1900)) < 1)
FAIL ("SSDP: Could not bind on udp port 1900");
@@ -1021,7 +1038,9 @@ main (int argc, char *argv[])
@@ -1021,7 +1047,9 @@ main (int argc, char *argv[])
select_and_execute ();
unlink(PID_FILE);
free_all ();
@ -490,7 +655,7 @@ index d4076ba..06db623 100755
}
@@ -1247,12 +1266,16 @@ void _log(int level, char * file, int line, const char *fmt, ...) {
@@ -1247,12 +1275,16 @@ void _log(int level, char * file, int line, const char *fmt, ...) {
idx = 1;
else if ( idx < 0)
idx = 0;
@ -510,7 +675,7 @@ index d4076ba..06db623 100755
both = 0;
va_start(arg, fmt);
len += vsnprintf(output[idx] + len, sizeof(output[0]) - len, fmt, arg);
@@ -1271,9 +1294,9 @@ void _log(int level, char * file, int line, const char *fmt, ...) {
@@ -1271,9 +1303,9 @@ void _log(int level, char * file, int line, const char *fmt, ...) {
}
if(both){