linuxdvb: some simplications to EN50494 support

I've removed some of the bounds checking, not a bad thing to have it, but
in general we work on the principle that if the user really is trying hard
enough to pass broken values, then so be it!

Also correct some spelling mistakes and change UI refs to "Unicable" rather
than the standard "EN50494".
This commit is contained in:
Adam Sutton 2014-01-11 21:03:01 +00:00
parent 0fb3e9db94
commit 03caed6a10
3 changed files with 156 additions and 230 deletions

View file

@ -33,7 +33,6 @@
/* **************************************************************************
* Static definition
* *************************************************************************/
#define LINUXDVB_EN50494_NAME "en50494"
#define LINUXDVB_EN50494_NOPIN 256
@ -55,29 +54,47 @@
* Class definition
* *************************************************************************/
//typedef struct linuxdvb_en50494
//{
// linuxdvb_diseqc_t;
//
// /* en50494 configuration*/
// uint8_t le_position; /* satelitte A(0) or B(1) */
// uint16_t le_frequency; /* user band frequency in MHz */
// uint8_t le_id; /* user band id 0-7 */
// uint16_t le_pin; /* 0-255 or LINUXDVB_EN50494_NOPIN */
//
// /* runtime */
// uint32_t le_tune_freq; /* the real frequency to tune to */
//} linuxdvb_en50494_t;
/* prevention of self raised DiSEqC collisions */
static pthread_mutex_t linuxdvb_en50494_lock;
static const char *
linuxdvb_en50494_class_get_title ( idnode_t *o )
{
static char buf[256];
linuxdvb_diseqc_t *ld = (linuxdvb_diseqc_t*)o;
snprintf(buf, sizeof(buf), "%s: %s", LINUXDVB_EN50494_NAME, ld->ld_type);
return buf;
static const char *title = "Unicable";
return title;
}
htsmsg_t *
linuxdvb_en50494_id_list ( void *o )
{
uint32_t i;
htsmsg_t *m = htsmsg_create_list();
for (i = 0; i < 8; i++) {
htsmsg_add_u32(m, NULL, i);
}
return m;
}
htsmsg_t *
linuxdvb_en50494_pin_list ( void *o )
{
int32_t i;
htsmsg_t *m = htsmsg_create_list();
htsmsg_t *e;
e = htsmsg_create_map();
htsmsg_add_u32(e, "key", 256);
htsmsg_add_str(e, "val", "No pin");
htsmsg_add_msg(m, NULL, e);
for (i = 0; i < 256; i++) {
e = htsmsg_create_map();
htsmsg_add_u32(e, "key", i);
htsmsg_add_u32(e, "val", i);
htsmsg_add_msg(m, NULL, e);
}
return m;
}
extern const idclass_t linuxdvb_diseqc_class;
@ -85,7 +102,7 @@ const idclass_t linuxdvb_en50494_class =
{
.ic_super = &linuxdvb_diseqc_class,
.ic_class = "linuxdvb_en50494",
.ic_caption = LINUXDVB_EN50494_NAME,
.ic_caption = "en50494",
.ic_get_title = linuxdvb_en50494_class_get_title,
.ic_properties = (const property_t[]) {
{
@ -105,18 +122,19 @@ const idclass_t linuxdvb_en50494_class =
.id = "id",
.name = "ID",
.off = offsetof(linuxdvb_en50494_t, le_id),
.list = linuxdvb_en50494_id_list,
},
{
.type = PT_U16,
.id = "pin",
.name = "Pin",
.off = offsetof(linuxdvb_en50494_t, le_pin),
.list = linuxdvb_en50494_pin_list,
},
{}
}
};
/* **************************************************************************
* Class methods
* *************************************************************************/
@ -131,14 +149,14 @@ linuxdvb_en50494_tune
linuxdvb_lnb_t *lnb = sc->ls_lnb;
/* band & polarisation */
uint8_t pol = lnb->lnb_pol(lnb, lm);
uint8_t band = lnb->lnb_band(lnb, lm);
uint8_t pol = lnb->lnb_pol(lnb, lm);
uint8_t band = lnb->lnb_band(lnb, lm);
uint32_t freq = lnb->lnb_freq(lnb, lm);
/* transponder value - t*/
uint16_t t = round((( (freq / 1000) + 2 + le->le_frequency) / 4) - 350);
if ( t > 1024) {
tvherror(LINUXDVB_EN50494_NAME, "transponder value bigger then 1024");
tvherror("en50494", "transponder value bigger then 1024");
return -1;
}
@ -153,9 +171,10 @@ linuxdvb_en50494_tune
data1 |= band << 2; /* 1bit band lower(0)/upper(1) */
data1 |= t >> 8; /* 2bit transponder value bit 1-2 */
data2 = t & 0xFF; /* 8bit transponder value bit 3-10 */
tvhdebug(LINUXDVB_EN50494_NAME,
"lnb=%i, id=%i, freq=%i, pin=%i, v/h=%i, l/u=%i, f=%i, data=0x%02X%02X",
le->le_position, le->le_id, le->le_frequency, le->le_pin, pol, band, freq, data1, data2);
tvhdebug("en50494",
"lnb=%i id=%i freq=%i pin=%i v/h=%i l/u=%i f=%i, data=0x%02X%02X",
le->le_position, le->le_id, le->le_frequency, le->le_pin, pol,
band, freq, data1, data2);
pthread_mutex_lock(&linuxdvb_en50494_lock);
for (i = 0; i <= sc->ls_parent->ls_diseqc_repeats; i++) {
@ -168,7 +187,7 @@ linuxdvb_en50494_tune
/* use 18V */
ret = linuxdvb_diseqc_set_volt(fd, SEC_VOLTAGE_18);
if (ret) {
tvherror(LINUXDVB_EN50494_NAME, "error setting lnb voltage to 18V");
tvherror("en50494", "error setting lnb voltage to 18V");
break;
}
usleep(15000); /* standard: 4ms < x < 22ms */
@ -190,7 +209,7 @@ linuxdvb_en50494_tune
data1, data2);
}
if (ret != 0) {
tvherror(LINUXDVB_EN50494_NAME, "error send tune command");
tvherror("en50494", "error send tune command");
break;
}
usleep(50000); /* standard: 2ms < x < 60ms */
@ -198,7 +217,7 @@ linuxdvb_en50494_tune
/* return to 13V */
ret = linuxdvb_diseqc_set_volt(fd, SEC_VOLTAGE_13);
if (ret) {
tvherror(LINUXDVB_EN50494_NAME, "error setting lnb voltage back to 13V");
tvherror("en50494", "error setting lnb voltage back to 13V");
break;
}
}
@ -216,7 +235,7 @@ void
linuxdvb_en50494_init (void)
{
if (pthread_mutex_init(&linuxdvb_en50494_lock, NULL) != 0) {
tvherror(LINUXDVB_EN50494_NAME, "failed to init lock mutex");
tvherror("en50494", "failed to init lock mutex");
}
}
@ -225,7 +244,7 @@ linuxdvb_en50494_list ( void *o )
{
htsmsg_t *m = htsmsg_create_list();
htsmsg_add_str(m, NULL, "None");
htsmsg_add_str(m, NULL, "EN50494/UniCable");
htsmsg_add_str(m, NULL, "Generic");
return m;
}
@ -237,17 +256,13 @@ linuxdvb_en50494_create0
linuxdvb_en50494_t *le;
if (port > 1) {
tvherror(LINUXDVB_EN50494_NAME, "only 2 ports/positions are posible. given %i", port);
tvherror("en50494", "only 2 ports/positions are posible. given %i", port);
port = 0;
}
ld = linuxdvb_diseqc_create0(
calloc(1, sizeof(linuxdvb_en50494_t)),
NULL,
&linuxdvb_en50494_class,
conf,
LINUXDVB_EN50494_NAME,
ls);
ld = linuxdvb_diseqc_create0(calloc(1, sizeof(linuxdvb_en50494_t)),
NULL, &linuxdvb_en50494_class, conf,
"en50494", ls);
le = (linuxdvb_en50494_t*)ld;
if (ld) {
ld->ld_tune = linuxdvb_en50494_tune;

View file

@ -302,6 +302,9 @@ htsmsg_t *linuxdvb_switch_list ( void *o );
htsmsg_t *linuxdvb_rotor_list ( void *o );
htsmsg_t *linuxdvb_en50494_list ( void *o );
htsmsg_t *linuxdvb_en50494_id_list ( void *o );
htsmsg_t *linuxdvb_en50494_pin_list ( void *o );
void linuxdvb_en50494_init (void);
int

View file

@ -164,150 +164,6 @@ linuxdvb_satconf_class_orbitalpos_set
return 1;
}
static htsmsg_t *
linuxdvb_satconf_class_en50494_id_list ( void *o )
{
uint32_t i;
htsmsg_t *m = htsmsg_create_list();
for (i = 0; i < 8; i++) {
htsmsg_add_u32(m, NULL, i);
}
return m;
}
static const void *
linuxdvb_satconf_class_en50494_id_get ( void *p )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse = TAILQ_FIRST(&ls->ls_elements);
linuxdvb_en50494_t *le;
static uint16_t default_value = 0;
if (!lse && !lse->ls_en50494)
return &default_value;
le = (linuxdvb_en50494_t*)lse->ls_en50494;
return &le->le_id;
}
static int
linuxdvb_satconf_class_en50494_id_set
( void *p, const void *v )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse;
linuxdvb_en50494_t *le;
uint16_t new_value = *(uint16_t*)v;
if (new_value < 0 || new_value > 7)
return 1;
TAILQ_FOREACH(lse, &ls->ls_elements, ls_link) {
if (!lse && !lse->ls_en50494)
continue;
le = (linuxdvb_en50494_t*)lse->ls_en50494;
le->le_id = new_value;
}
return 0;
}
static const void *
linuxdvb_satconf_class_en50494_freq_get ( void *p )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse = TAILQ_FIRST(&ls->ls_elements);
linuxdvb_en50494_t *le;
static uint16_t default_value = 0;
if (!lse && !lse->ls_en50494)
return &default_value;
le = (linuxdvb_en50494_t*)lse->ls_en50494;
return &le->le_frequency;
}
static int
linuxdvb_satconf_class_en50494_freq_set
( void *p, const void *v )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse;
linuxdvb_en50494_t *le;
uint16_t new_value = *(uint16_t*)v;
TAILQ_FOREACH(lse, &ls->ls_elements, ls_link) {
if (!lse && !lse->ls_en50494)
continue;
le = (linuxdvb_en50494_t*)lse->ls_en50494;
le->le_frequency = new_value;
}
return 0;
}
static htsmsg_t *
linuxdvb_satconf_class_en50494_pin_list ( void *o )
{
int32_t i;
htsmsg_t *m = htsmsg_create_list();
htsmsg_t *e;
e = htsmsg_create_map();
htsmsg_add_u32(e, "key", 256);
htsmsg_add_str(e, "val", "no Pin");
htsmsg_add_msg(m, NULL, e);
for (i = 0; i < 256; i++) {
e = htsmsg_create_map();
htsmsg_add_u32(e, "key", i);
htsmsg_add_u32(e, "val", i);
htsmsg_add_msg(m, NULL, e);
}
return m;
}
static const void *
linuxdvb_satconf_class_en50494_pin_get ( void *p )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse = TAILQ_FIRST(&ls->ls_elements);
linuxdvb_en50494_t *le;
static uint16_t default_value = 256;
if (!lse && !lse->ls_en50494)
return &default_value;
le = (linuxdvb_en50494_t*)lse->ls_en50494;
return &le->le_pin;
}
static int
linuxdvb_satconf_class_en50494_pin_set
( void *p, const void *v )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse;
linuxdvb_en50494_t *le;
uint16_t new_value = *(uint16_t*)v;
if (new_value < 0 || new_value > 256)
return 1;
TAILQ_FOREACH(lse, &ls->ls_elements, ls_link) {
if (!lse && !lse->ls_en50494)
continue;
le = (linuxdvb_en50494_t*)lse->ls_en50494;
le->le_pin = new_value;
}
return 0;
}
static idnode_set_t *
linuxdvb_satconf_class_get_childs ( idnode_t *o )
{
@ -444,14 +300,97 @@ const idclass_t linuxdvb_satconf_4port_class =
};
/*
* en50494
* Unicable (EN50494)
*/
static const void *
linuxdvb_satconf_class_en50494_id_get ( void *p )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse = TAILQ_FIRST(&ls->ls_elements);
return &(((linuxdvb_en50494_t*)lse->ls_en50494)->le_id);
}
static int
linuxdvb_satconf_class_en50494_id_set
( void *p, const void *v )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse;
TAILQ_FOREACH(lse, &ls->ls_elements, ls_link)
(((linuxdvb_en50494_t*)lse->ls_en50494)->le_id) = *(uint16_t*)v;
return 0;
}
static const void *
linuxdvb_satconf_class_en50494_pin_get ( void *p )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse = TAILQ_FIRST(&ls->ls_elements);
return &(((linuxdvb_en50494_t*)lse->ls_en50494)->le_pin);
}
static int
linuxdvb_satconf_class_en50494_pin_set
( void *p, const void *v )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse;
TAILQ_FOREACH(lse, &ls->ls_elements, ls_link)
(((linuxdvb_en50494_t*)lse->ls_en50494)->le_pin) = *(uint16_t*)v;
return 0;
}
static const void *
linuxdvb_satconf_class_en50494_freq_get ( void *p )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse = TAILQ_FIRST(&ls->ls_elements);
return &(((linuxdvb_en50494_t*)lse->ls_en50494)->le_frequency);
}
static int
linuxdvb_satconf_class_en50494_freq_set
( void *p, const void *v )
{
linuxdvb_satconf_t *ls = p;
linuxdvb_satconf_ele_t *lse;
TAILQ_FOREACH(lse, &ls->ls_elements, ls_link)
(((linuxdvb_en50494_t*)lse->ls_en50494)->le_frequency) = *(uint16_t*)v;
return 0;
}
const idclass_t linuxdvb_satconf_en50494_class =
{
.ic_super = &linuxdvb_satconf_class,
.ic_class = "linuxdvb_satconf_en50494",
.ic_caption = "DVB-S EN50494 (UniCable)",
.ic_properties = (const property_t[]) {
{
.type = PT_U16,
.id = "id",
.name = "ID",
.get = linuxdvb_satconf_class_en50494_id_get,
.set = linuxdvb_satconf_class_en50494_id_set,
.list = linuxdvb_en50494_id_list,
.opts = PO_NOSAVE,
},
{
.type = PT_U16,
.id = "pin",
.name = "Pin",
.get = linuxdvb_satconf_class_en50494_pin_get,
.set = linuxdvb_satconf_class_en50494_pin_set,
.list = linuxdvb_en50494_pin_list,
.opts = PO_NOSAVE,
},
{
.type = PT_U16,
.id = "frequency",
.name = "Frequency (MHz)",
.get = linuxdvb_satconf_class_en50494_freq_get,
.set = linuxdvb_satconf_class_en50494_freq_set,
.opts = PO_NOSAVE,
},
{
.type = PT_STR,
.id = "network_a",
@ -470,32 +409,6 @@ const idclass_t linuxdvb_satconf_en50494_class =
.list = linuxdvb_satconf_ele_class_network_enum,
.opts = PO_NOSAVE,
},
{
.type = PT_U16,
.id = "id",
.name = "ID",
.get = linuxdvb_satconf_class_en50494_id_get,
.set = linuxdvb_satconf_class_en50494_id_set,
.list = linuxdvb_satconf_class_en50494_id_list,
.opts = PO_NOSAVE,
},
{
.type = PT_U16,
.id = "freqency",
.name = "Freqency (MHz)",
.get = linuxdvb_satconf_class_en50494_freq_get,
.set = linuxdvb_satconf_class_en50494_freq_set,
.opts = PO_NOSAVE,
},
{
.type = PT_U16,
.id = "pin",
.name = "Pin",
.get = linuxdvb_satconf_class_en50494_pin_get,
.set = linuxdvb_satconf_class_en50494_pin_set,
.list = linuxdvb_satconf_class_en50494_pin_list,
.opts = PO_NOSAVE,
},
{}
}
};
@ -548,7 +461,7 @@ static struct linuxdvb_satconf_type linuxdvb_satconf_types[] = {
},
{
.type = "en50494",
.name = "EN50494/UniCable Switch (Universal LNB)",
.name = "Unicable Switch (Universal LNB)",
.idc = &linuxdvb_satconf_en50494_class,
.ports = 2,
},
@ -632,30 +545,25 @@ linuxdvb_satconf_create
}
/* Create elements */
i = 0;
TAILQ_FOREACH(lse, &ls->ls_elements, ls_link) {
i = 0;
lse = TAILQ_FIRST(&ls->ls_elements);
while (i < lst->ports) {
if (!lse)
lse = linuxdvb_satconf_ele_create0(NULL, NULL, ls);
if (!lse->ls_lnb)
lse->ls_lnb = linuxdvb_lnb_create0(NULL, NULL, lse);
/* create multi port elements (2/4port & en50494) */
if (lst->ports > 1) {
if( !lse->ls_en50494 && !strcmp("en50494",lst->type))
lse->ls_en50494 = linuxdvb_en50494_create0("en50494", NULL, lse, i);
if( !lse->ls_switch && (!strcmp("2port",lst->type) || !strcmp("4port",lst->type)))
lse->ls_switch = linuxdvb_switch_create0("Generic", NULL, lse, i, -1);
if (!strcmp(lst->type, "en50494")) {
if (!lse->ls_en50494)
lse->ls_en50494 = linuxdvb_en50494_create0("Generic", NULL, lse, i);
} else {
if (!lse->ls_switch)
lse->ls_switch = linuxdvb_switch_create0("Generic", NULL, lse, i, -1);
}
}
lse = TAILQ_NEXT(lse, ls_link);
i++;
}
for (; i < lst->ports; i++) {
lse = linuxdvb_satconf_ele_create0(NULL, NULL, ls);
lse->ls_lnb = linuxdvb_lnb_create0(NULL, NULL, lse);
/* create multi port elements (2/4port & en50494) */
if (lst->ports > 1) {
if( !strcmp("en50494",lst->type))
lse->ls_en50494 = linuxdvb_en50494_create0("en50494", NULL, lse, i);
if( !strcmp("2port",lst->type) || !strcmp("4port",lst->type))
lse->ls_switch = linuxdvb_switch_create0("Generic", NULL, lse, i, -1);
}
}
return ls;
}
@ -927,7 +835,7 @@ const idclass_t linuxdvb_satconf_ele_class =
{
.type = PT_STR,
.id = "en50494_type",
.name = "EN50494 Type",
.name = "Unicable Type",
.set = linuxdvb_satconf_ele_class_en50494type_set,
.get = linuxdvb_satconf_ele_class_en50494type_get,
.list = linuxdvb_en50494_list,