source: titan/titan/frontenddev.h @ 10801

Last change on this file since 10801 was 10801, checked in by nit, 12 years ago

[titan] change fec9 to fec11 if system=1 and dvbapi5 used

File size: 34.1 KB
Line 
1#ifndef FRONTENDDEV_H
2#define FRONTENDDEV_H
3
4int calclof(struct dvbdev* node, struct transponder* tpnode, char* feaktlnb, int flag)
5{
6        debug(1000, "in");
7        int loftype = 0;
8        int lofl, lofh, lofthreshold;
9
10        if(node == NULL || tpnode == NULL)
11        {
12                debug(1000, "out-> NULL detect");
13                return -1;
14        }
15
16        if(node->feinfo->type != FE_QPSK)
17                return 0;
18
19        int frequency = tpnode->frequency;
20
21        if(feaktlnb == NULL) feaktlnb = node->feaktlnb;
22
23        loftype = getconfigint("lnb_loftype", feaktlnb);
24        switch(loftype)
25        {
26                case 1: //c-band
27                        lofl = 5150 * 1000;
28                        lofh = 5150 * 1000;
29                        lofthreshold = 5150 * 1000;
30                        break;
31                case 2: //user
32                        lofl = getconfigint("lnb_lofl", feaktlnb) * 1000;
33                        lofh = getconfigint("lnb_lofh", feaktlnb) * 1000;
34                        lofthreshold = getconfigint("lnb_lofthreshold", feaktlnb) * 1000;
35                        break;
36                default: //standard lnb
37                        lofl = 9750 * 1000;
38                        lofh = 10600 * 1000;
39                        lofthreshold = 11700 * 1000;
40        }
41
42        if(lofthreshold && lofh && frequency >= lofthreshold)
43        {
44                if(flag == 1) return 1;
45                node->feaktband = 1;
46        }
47        else
48        {
49                if(flag == 1) return 0;
50                node->feaktband = 0;
51        }
52
53        if(node->feaktband)
54                node->feloffrequency = frequency - lofh;
55        else
56        {
57                if(frequency < lofl)
58                        node->feloffrequency = lofl - frequency;
59                else
60                        node->feloffrequency = frequency - lofl;
61        }
62
63        debug(200, "tuning to freq %d (befor lof %d), band=%d", node->feloffrequency, frequency, node->feaktband);
64        return node->feaktband;
65}
66
67char* fegettypestr(struct dvbdev* dvbnode)
68{
69        char* text = NULL;
70
71        if(dvbnode == NULL)
72        {
73                debug(1000, "out -> NULL detect");
74                return NULL;
75        }
76
77        switch(dvbnode->feinfo->type)
78        {
79                case FE_QPSK: text = ostrcat(text, "DVB-S", 1, 0); break;
80                case FE_QAM: text = ostrcat(text, "DVB-C", 1, 0); break;
81                case FE_OFDM: text = ostrcat(text, "DVB-T", 1, 0); break;
82                default: text = ostrcat(text, "unknown", 1, 0);
83        }
84
85        return text;
86}
87
88struct dvbdev* fegetbyshortname(char* feshortname)
89{
90        struct dvbdev* dvbnode = dvbdev;
91       
92        while(dvbnode != NULL)
93        {
94                if(dvbnode->type == FRONTENDDEV && ostrcmp(dvbnode->feshortname, feshortname) == 0)
95                        return dvbnode;
96                dvbnode = dvbnode->next;
97        }
98        return NULL;
99}
100
101void fegetconfig(struct dvbdev *dvbnode, struct transponder *tpnode, char** aktlnb, char** aktdiseqc, char* tmpnr)
102{
103        char* tmpstr = NULL;
104
105        if(dvbnode == NULL || tpnode == NULL)
106        {
107                debug(1000, "out-> NULL detect");
108                return;
109        }
110
111        tmpstr = ostrcat(dvbnode->feshortname, "_lnb", 0, 0);
112        *aktlnb = getconfig(tmpstr, tmpnr);
113
114        free(tmpstr); tmpstr = NULL;
115        tmpstr = ostrcat(dvbnode->feshortname, "_diseqc", 0, 0);
116        *aktdiseqc = getconfig(tmpstr, tmpnr);
117        free(tmpstr); tmpstr = NULL;
118}
119
120struct dvbdev* fegetdummy()
121{
122        struct dvbdev* dvbnode = dvbdev;
123
124        while(dvbnode != NULL)
125        {
126                if(dvbnode->type == FRONTENDDEVDUMMY)
127                        return dvbnode;
128                dvbnode = dvbnode->next;
129        }
130        return NULL;
131}
132
133//flag 0 = normal
134//flag 1 = check only
135//flag 2 = from record
136struct dvbdev* fegetfree(struct transponder* tpnode, int flag, struct dvbdev* dvbfirst)
137{
138        debug(1000, "in");
139        struct dvbdev* dvbnode = NULL;
140        struct dvbdev* tmpdvbnode = NULL;
141        char* tmpstr = NULL, *tmpnr = NULL, *aktlnb = NULL, *aktdiseqc = NULL;
142        int i, orbitalpos = 0, band = 0;
143
144        if(dvbfirst != NULL)
145                dvbnode = dvbfirst;
146        else
147                dvbnode = dvbdev;
148
149        if(tpnode == NULL)
150        {
151                debug(1000, "out -> NULL detect");
152                return NULL;
153        }
154
155        //suche tuner der auf der gleichen orbitalpos/frequency/pol/band ist
156        while(dvbnode != NULL)
157        {
158                //FRONTENDDEV first in the list
159                if(dvbnode->type != FRONTENDDEV) break;
160                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo->type == tpnode->fetype)
161                {
162                        if(dvbnode->feakttransponder != NULL && dvbnode->feakttransponder->orbitalpos == tpnode->orbitalpos && dvbnode->feakttransponder->frequency == tpnode->frequency && dvbnode->feaktpolarization == tpnode->polarization)
163                        {
164                                band = calclof(dvbnode, tpnode, dvbnode->feaktlnb, 1);
165                                if(dvbnode->feaktband != band)
166                                {
167                                        dvbnode = dvbnode->next;
168                                        continue;
169                                }
170                                dvbnode->felasttransponder = dvbnode->feakttransponder;
171                                dvbnode->feakttransponder = tpnode;
172                                if(flag != 1) debug(200, "found tuner with same orbitalpos/frequency/pol/band %s", dvbnode->feshortname);
173                                return(dvbnode);
174                        }
175                }
176                dvbnode = dvbnode->next;
177        }
178        if(dvbfirst != NULL)
179                dvbnode = dvbfirst;
180        else
181                dvbnode = dvbdev;
182
183        //suche tuner der die gewuenschte orbitalpos kann und nicht belegt ist
184        while(dvbnode != NULL)
185        {
186                //FRONTENDDEV first in the list
187                if(dvbnode->type != FRONTENDDEV) break;
188                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo->type == tpnode->fetype && dvbnode->felock == 0)
189                {
190                        if(flag == 2 && status.aktservice->fedev == dvbnode)
191                        {
192                                dvbnode = dvbnode->next;
193                                continue;
194                        }
195
196                        //check if tuner is loop and looptuner is locked
197                        tmpstr = getconfigbyval(dvbnode->feshortname, NULL);
198                        if(tmpstr != NULL) //found loop tuner
199                        {
200                                tmpdvbnode = fegetbyshortname(tmpstr);
201                                if(tmpdvbnode != NULL && tmpdvbnode->feakttransponder != NULL && tmpdvbnode->feaktpolarization != tpnode->polarization && (tmpdvbnode->felock != 0 || (flag == 2 && tmpdvbnode->felock == 0)))
202                                {
203                                        dvbnode = dvbnode->next;
204                                        continue;
205                                }
206                        }
207
208                        tmpstr = ostrcat(dvbnode->feshortname, "_sat", 0, 0);
209                        for(i = 1; i <= status.maxsat; i++)
210                        {
211                                tmpnr = oitoa(i);
212
213                                orbitalpos = getconfigint(tmpstr, tmpnr);
214                                if(orbitalpos == tpnode->orbitalpos)
215                                {
216                                        fegetconfig(dvbnode, tpnode, &aktlnb, &aktdiseqc, tmpnr);
217                                        band = calclof(dvbnode, tpnode, aktlnb, 1);
218                                        if(tmpdvbnode != NULL && tmpdvbnode->feaktband != band && (tmpdvbnode->felock != 0 || (flag == 2 && tmpdvbnode->felock == 0)))
219                                        {
220                                                free(tmpnr); tmpnr = NULL;
221                                                continue;
222                                        }
223                                        if(flag == 1)
224                                        {
225                                                free(tmpstr); tmpstr = NULL;
226                                                free(tmpnr); tmpnr = NULL;
227                                                return dvbnode;
228                                        }
229                                        if(tmpdvbnode != NULL)
230                                        {
231                                                tmpdvbnode->feaktband = band;
232                                                tmpdvbnode->feaktpolarization = tpnode->polarization;
233                                        }
234                                        dvbnode->felasttransponder = dvbnode->feakttransponder;
235                                        dvbnode->feakttransponder = tpnode;
236                                        dvbnode->feaktpolarization = tpnode->polarization;
237                                        free(dvbnode->feaktlnb);
238                                        if(aktlnb != NULL)
239                                                dvbnode->feaktlnb = ostrcat(aktlnb, "", 0, 0);
240                                        else
241                                                dvbnode->feaktlnb = NULL;
242                                        free(dvbnode->feaktdiseqc);
243                                        if(aktdiseqc != NULL)
244                                                dvbnode->feaktdiseqc = ostrcat(aktdiseqc, "", 0, 0);
245                                        else
246                                                dvbnode->feaktdiseqc = NULL;
247
248                                        free(tmpstr); tmpstr = NULL;
249                                        free(tmpnr); tmpnr = NULL;
250                                        if(flag != 1) debug(200, "found free tuner witch same orbitalpos %s", dvbnode->feshortname);
251                                        return dvbnode;
252                                }
253                                free(tmpnr); tmpnr = NULL;
254                        }
255                        free(tmpstr); tmpstr = NULL;
256                }
257                dvbnode = dvbnode->next;
258        }
259        if(dvbfirst != NULL)
260                dvbnode = dvbfirst;
261        else
262                dvbnode = dvbdev;
263
264        //suche loop tuner, wo der haupttuner
265        //die gewuenschte orbitalpos kann, nicht belegt ist
266        //und auf der gleichen poarization/band ist, wo wir hintunen wollen
267        while(dvbnode != NULL)
268        {
269                //FRONTENDDEV first in the list
270                if(dvbnode->type != FRONTENDDEV) break;
271                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo->type == tpnode->fetype && dvbnode->felock == 0)
272                {
273                        if(flag == 2 && status.aktservice->fedev == dvbnode)
274                        {
275                                dvbnode = dvbnode->next;
276                                continue;
277                        }
278
279                        //check if tuner is loop an looptuner is locked
280                        tmpstr = getconfig(dvbnode->feshortname, NULL);
281                        if(tmpstr != NULL) //found loop tuner
282                        {
283                                tmpdvbnode = fegetbyshortname(tmpstr);
284                                if(tmpdvbnode != NULL && tmpdvbnode->feakttransponder != NULL && tmpdvbnode->feaktpolarization != tpnode->polarization && (tmpdvbnode->felock != 0 || (flag == 2 && tmpdvbnode->felock == 0)))
285                                {
286                                        dvbnode = dvbnode->next;
287                                        continue;
288                                }
289                        }
290                        else
291                        {
292                                dvbnode = dvbnode->next;
293                                continue;
294                        }
295
296                        tmpstr = ostrcat(tmpdvbnode->feshortname, "_sat", 0, 0);
297                        for(i = 1; i <= status.maxsat; i++)
298                        {
299                                tmpnr = oitoa(i);
300                                orbitalpos = getconfigint(tmpstr, tmpnr);
301                                if(orbitalpos == tpnode->orbitalpos)
302                                {
303                                        fegetconfig(tmpdvbnode, tpnode, &aktlnb, &aktdiseqc, tmpnr);
304                                        band = calclof(dvbnode, tpnode, aktlnb, 1);
305                                        if(tmpdvbnode != NULL && tmpdvbnode->feaktband != band && (tmpdvbnode->felock != 0 || (flag == 2 && tmpdvbnode->felock == 0)))
306                                        {
307                                                free(tmpnr); tmpnr = NULL;
308                                                continue;
309                                        }
310                                        if(flag == 1)
311                                        {
312                                                free(tmpstr); tmpstr = NULL;
313                                                free(tmpnr); tmpnr = NULL;
314                                                return dvbnode;
315                                        }
316                                        if(tmpdvbnode != NULL)
317                                        {
318                                                tmpdvbnode->feaktband = band;
319                                                tmpdvbnode->feaktpolarization = tpnode->polarization;
320                                        }
321                                        dvbnode->felasttransponder = dvbnode->feakttransponder;
322                                        dvbnode->feakttransponder = tpnode;
323                                        dvbnode->feaktpolarization = tpnode->polarization;
324                                        free(dvbnode->feaktlnb);
325                                        if(aktlnb != NULL)
326                                                dvbnode->feaktlnb = ostrcat(aktlnb, "", 0, 0);
327                                        else
328                                                dvbnode->feaktlnb = NULL;
329                                        free(dvbnode->feaktdiseqc);
330                                        if(aktdiseqc != NULL)
331                                                dvbnode->feaktdiseqc = ostrcat(aktdiseqc, "", 0, 0);
332                                        else
333                                                dvbnode->feaktdiseqc = NULL;
334                                        free(tmpstr); tmpstr = NULL;
335                                        free(tmpnr); tmpnr = NULL;
336                                        if(flag != 1) debug(200, "found free looptuner witch same orbitalpos/polarization/band %s", dvbnode->feshortname);
337                                        return dvbnode;
338                                }
339                                free(tmpnr); tmpnr = NULL;
340                        }
341                        free(tmpstr); tmpstr = NULL;
342                }
343                dvbnode = dvbnode->next;
344        }
345
346        debug(1000, "out");
347        return NULL;
348}
349
350int feopen(struct dvbdev* node, char *fedev)
351{
352        debug(1000, "in");
353        int fd = -1;
354
355        if(node != NULL)
356        {       
357                if((fd = open(node->dev, O_RDWR | O_NONBLOCK)) < 0)
358                        debug(200, "open frontend failed %s", node->dev);
359                node->fd = fd;
360        }
361        else
362        {
363                if((fd = open(fedev, O_RDWR | O_NONBLOCK)) < 0)
364                        debug(200, "open frontend failed %s", fedev);
365        }
366
367        closeonexec(fd);
368        debug(1000, "out");
369        return fd;
370}
371
372void feclose(struct dvbdev* node, int fd)
373{
374        debug(1000, "in");
375
376        if(node != NULL)
377        {
378                close(node->fd);
379                node->fd = -1;
380        }
381        else
382                close(fd);
383
384        debug(1000, "out");
385}
386
387int fegetunlock(struct dvbdev* node)
388{
389        debug(1000, "in");
390        fe_status_t status;
391
392        if(node == NULL)
393        {
394                debug(1000, "out-> NULL detect");
395                return 1;
396        }
397
398#ifdef SIMULATE
399        return 0;
400#endif
401
402        if(ioctl(node->fd, FE_READ_STATUS, &status) == -1)
403                perr("FE_READ_STATUS");
404
405        debug(1000, "out");
406        if(status & FE_HAS_LOCK)
407                return 0;
408        else
409                return 1;
410}
411
412int fewait(struct dvbdev* node)
413{
414        debug(1000, "in");
415        //struct dvb_frontend_event ev;
416        fe_status_t status;
417
418        int count = 0;
419
420        if(node == NULL)
421        {
422                debug(1000, "out-> NULL detect");
423                return 1;
424        }
425
426#ifdef SIMULATE
427        return 0;
428#endif
429
430        //wait for tuner ready
431        debug(200, "wait for tuner");
432        while(count <= 200)
433        {
434                count++;
435                //ioctl(node->fd, FE_GET_EVENT, &ev);
436                //if(ev.status & FE_HAS_LOCK)
437                //      return 0;
438                ioctl(node->fd, FE_READ_STATUS, &status);
439                if(status & FE_HAS_LOCK)
440                        return 0;
441                usleep(1000);
442        }
443
444        debug(1000, "out");
445        //if(ev.status & FE_HAS_LOCK)
446        //      return 0;
447        if(status & FE_HAS_LOCK)
448                return 0;
449        else
450                return 1;
451}
452
453void fegetfrontend(struct dvbdev* node)
454{
455        debug(1000, "in");
456
457        if(node == NULL)
458        {
459                debug(1000, "out-> NULL detect");
460                return;
461        }
462
463#if DVB_API_VERSION >= 5
464        struct dtv_property p[8];
465        struct dtv_properties cmdseq;
466        cmdseq.props = p;
467
468        p[0].cmd = DTV_DELIVERY_SYSTEM;
469        p[1].cmd = DTV_FREQUENCY;
470        p[2].cmd = DTV_MODULATION;
471        p[3].cmd = DTV_SYMBOL_RATE;
472        p[4].cmd = DTV_INNER_FEC;
473        p[5].cmd = DTV_INVERSION;
474        p[6].cmd = DTV_ROLLOFF;
475        p[7].cmd = DTV_PILOT;
476        cmdseq.num = 8;
477       
478        if(ioctl(node->fd, FE_GET_PROPERTY, &cmdseq) < 0)
479        {
480                perr("FE_GET_PROPERTY");
481        }
482        else
483        {
484                debug(200, "frontend akt delivery system = %d", p[0].u.data);
485                debug(200, "frontend akt frequency = %d", p[1].u.data);
486                debug(200, "frontend akt inversion = %d", p[5].u.data);
487                debug(200, "frontend akt symbol_rate = %d", p[3].u.data);
488                debug(200, "frontend akt fec_inner = %d", p[4].u.data);
489                debug(200, "frontend akt modulation = %d", p[2].u.data);
490                debug(200, "frontend akt rolloff = %d", p[6].u.data);
491                debug(200, "frontend akt pilot = %d", p[7].u.data);
492        }
493#else
494        struct dvb_frontend_parameters fe_param;
495
496        if(ioctl(node->fd, FE_GET_FRONTEND, &fe_param) < 0)
497        {
498                perr("FE_GET_FRONTEND");
499        }
500        else
501        {
502                debug(200, "frontend akt frequency = %d", fe_param.frequency);
503                debug(200, "frontend akt inversion = %d", fe_param.inversion);
504                debug(200, "frontend akt u.qpsk.symbol_rate = %d", fe_param.u.qpsk.symbol_rate);
505                debug(200, "frontend akt u.qam.symbol_rate = %d", fe_param.u.qam.symbol_rate);
506                debug(200, "frontend akt u.qpsk.fec_inner = %d", fe_param.u.qpsk.fec_inner);
507                debug(200, "frontend akt u.qam.fec_inner = %d", fe_param.u.qam.fec_inner);
508                debug(200, "frontend akt u.qam.modulation = %d", fe_param.u.qam.modulation);
509        }
510#endif
511
512        debug(1000, "out");
513}
514
515void fesettone(struct dvbdev* node, fe_sec_tone_mode_t tone, int wait)
516{
517        if(node == NULL)
518        {
519                debug(1000, "out-> NULL detect");
520                return;
521        }
522
523        debug(200, "FE_SET_TONE: %d", tone);
524        if(ioctl(node->fd, FE_SET_TONE, tone) == -1)
525                perr("FE_SET_TONE");
526        usleep(wait * 1000);
527        debug(1000, "out");
528}
529
530void fesetvoltage(struct dvbdev* node, fe_sec_voltage_t volt, int wait)
531{
532        debug(1000, "in");
533        if(node == NULL)
534        {
535                debug(1000, "out-> NULL detect");
536                return;
537        }
538
539        debug(200, "FE_SET_VOLT: %d", volt);
540        if(ioctl(node->fd, FE_SET_VOLTAGE, volt) == -1)
541                perr("FE_SET_VOLTAGE");
542        usleep(wait * 1000);
543        debug(1000, "out");
544}
545
546void fediseqcsendburst(struct dvbdev* node, fe_sec_mini_cmd_t burst, int wait)
547{
548        debug(1000, "in");
549        if(node == NULL)
550        {
551                debug(1000, "out-> NULL detect");
552                return;
553        }
554
555        debug(200, "FE_DISEQC_SEND_BURST: %d", burst);
556        if(ioctl(node->fd, FE_DISEQC_SEND_BURST, burst) == -1)
557                perr("FE_DISEQC_SEND_BURST");
558        usleep(wait * 1000);
559        debug(1000, "out");
560}
561
562void fediseqcsendmastercmd(struct dvbdev* node, struct dvb_diseqc_master_cmd *cmd, int wait)
563{
564        debug(1000, "in");
565        int i, repeat = 0;
566
567        if(node == NULL)
568        {
569                debug(1000, "out-> NULL detect");
570                return;
571        }
572
573        repeat = getconfigint("diseqc_repeat", node->feaktdiseqc);
574        if(repeat < 1) repeat = 1;
575
576        for(i = 0; i < repeat; i++)
577        {
578                if(ioctl(node->fd, FE_DISEQC_SEND_MASTER_CMD, cmd) == -1)
579                {
580                        perr("FE_DISEQC_SEND_MASTER_CMD");
581                }
582                usleep(wait * 1000);
583        }
584        debug(1000, "out");
585}
586
587void fesdiseqcpoweron(struct dvbdev* node)
588{
589        debug(1000, "in");
590        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
591
592        cmd.msg[0] = 0xE0;
593        cmd.msg[1] = 0x00;
594        cmd.msg[2] = 0x03;
595        cmd.msg_len = 3;
596
597        debug(200, "DISEQC Power on");
598        fediseqcsendmastercmd(node, &cmd, 100);
599        debug(1000, "out");
600}
601
602void fesdiseqcreset(struct dvbdev* node)
603{
604        debug(1000, "in");
605        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
606
607        cmd.msg[0] = 0xE0;
608        cmd.msg[1] = 0x00;
609        cmd.msg[2] = 0x00;
610        cmd.msg_len = 3;
611
612        debug(200, "DISEQC Reset");
613        fediseqcsendmastercmd(node, &cmd, 100);
614        debug(1000, "out");
615}
616
617void fesdiseqcstandby(struct dvbdev* node)
618{
619        debug(1000, "in");
620        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
621       
622        cmd.msg[0] = 0xE0;
623        cmd.msg[1] = 0x00;
624        cmd.msg[2] = 0x02;
625        cmd.msg_len = 3;
626
627        debug(200, "DISEQC Standby");
628        fediseqcsendmastercmd(node, &cmd, 100);
629        debug(1000, "out");
630}
631
632float ferotorangle(int pos)
633{
634        int val = 0, orbitalpos = 0;
635        char* tmpnr = NULL;
636        float angle = -1;
637
638        tmpnr = oitoa(pos);
639        val = getconfigint("rotorpos", tmpnr);
640        free(tmpnr); tmpnr = NULL;
641
642        if(val != 0)
643        {
644                orbitalpos = val & 0xffff;
645                if(((val >> 24) & 0xff) == 0) //west
646                        angle = 360 - orbitalpos / 10;
647                else //east
648                        angle = orbitalpos / 10;
649        }
650
651        return angle;
652}
653
654void fediseqcrotor(struct dvbdev* node, int pos, int oldpos, int flag)
655{
656        debug(1000, "in");
657        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
658        //float speed13V = 1.5;
659        float speed18V = 2.4;
660        float degreesmov, a1, a2, waittime;
661        int i;
662       
663        switch(flag)
664        {
665                case 0: //stop move
666                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x60; cmd.msg_len = 3;
667                        debug(200, "DISEQC Rotorpos (stop move)");
668                        break;
669                case 1: //disable limits
670                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x63; cmd.msg_len = 3;
671                        debug(200, "DISEQC Rotorpos (disable limits)");
672                        break;
673                case 2: //enable limits
674                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x6A; cmd.msg[3] = 0x00; cmd.msg_len = 4;
675                        debug(200, "DISEQC Rotorpos (enable limits)");
676                        break;
677                case 3: //set east limit
678                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x66; cmd.msg_len = 3;
679                        debug(200, "DISEQC Rotorpos (set east limit)");
680                        break;
681                case 4: //set west limit
682                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x67; cmd.msg_len = 3;
683                        debug(200, "DISEQC Rotorpos (set west limit)");
684                        break;
685                case 5: //move east cont.
686                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x68; cmd.msg[3] = 0x00; cmd.msg_len = 4;
687                        debug(200, "DISEQC Rotorpos (move east cont.)");
688                        break;
689                case 6: //move west cont.
690                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x69; cmd.msg[3] = 0x00; cmd.msg_len = 4;
691                        debug(200, "DISEQC Rotorpos (move west cont.)");
692                        break;
693                case 7: //store pos
694                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x6A; cmd.msg[3] = pos; cmd.msg_len = 4;
695                        debug(200, "DISEQC Rotorpos (store pos)");
696                        break;
697                case 8: //goto pos
698                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x6B; cmd.msg[3] = pos; cmd.msg_len = 4;
699                        debug(200, "DISEQC Rotorpos (goto pos)");
700                        break;
701        }
702
703        if(flag >= 0 && flag < 7)
704        {
705                fesettone(node, SEC_VOLTAGE_18, 15);
706                fesettone(node, SEC_TONE_OFF, 15);
707                fediseqcsendmastercmd(node, &cmd, 100);
708        }
709
710        if(flag == 7 && pos != 0)
711        {
712                fesettone(node, SEC_VOLTAGE_18, 15);
713                fesettone(node, SEC_TONE_OFF, 15);
714                fediseqcsendmastercmd(node, &cmd, 100);
715        }
716
717        if(flag == 8 && pos != 0 && pos != oldpos)
718        {
719                fesettone(node, SEC_VOLTAGE_18, 15);
720                fesettone(node, SEC_TONE_OFF, 15);
721                fediseqcsendmastercmd(node, &cmd, 100);
722
723                if(oldpos == 0)
724                        waittime = 15;
725                else
726                {
727                        a1 = ferotorangle(pos);
728                        a2 = ferotorangle(oldpos);
729                        degreesmov = abs(a1 - a2);
730                        if(degreesmov > 180) degreesmov = 360 - degreesmov;
731                        waittime = degreesmov / speed18V;
732                }
733
734                for(i = 0; i < 10; i++)
735                        usleep(waittime * 100000);
736        }
737        debug(1000, "out");
738}
739
740//TODO
741#if 0
742void CFrontend::sendMotorCommand(uint8_t cmdtype, uint8_t address, uint8_t command, uint8_t num_parameters, uint8_t parameter1, uint8_t parameter2, int repeat)
743{
744        struct dvb_diseqc_master_cmd cmd;
745        int i;
746
747        printf("[fe%d] sendMotorCommand: cmdtype   = %x, address = %x, cmd   = %x\n", fenumber, cmdtype, address, command);
748        printf("[fe%d] sendMotorCommand: num_parms = %d, parm1   = %x, parm2 = %x\n", fenumber, num_parameters, parameter1, parameter2);
749
750        cmd.msg[0] = cmdtype;   //command type
751        cmd.msg[1] = address;   //address
752        cmd.msg[2] = command;   //command
753        cmd.msg[3] = parameter1;
754        cmd.msg[4] = parameter2;
755        cmd.msg_len = 3 + num_parameters;
756        secSetVoltage(SEC_VOLTAGE_13, 15);
757        secSetTone(SEC_TONE_OFF, 25);
758
759        for(i = 0; i <= repeat; i++)
760                sendDiseqcCommand(&cmd, 50);
761
762        printf("[fe%d] motor command sent.\n", fenumber);
763
764}
765
766void CFrontend::sendDiseqcSmatvRemoteTuningCommand(const uint32_t frequency)
767{
768        /* [0] from master, no reply, 1st transmission
769         * [1] intelligent slave interface for multi-master bus
770         * [2] write channel frequency
771         * [3] frequency
772         * [4] frequency
773         * [5] frequency */
774
775        struct dvb_diseqc_master_cmd cmd = {
776                {0xe0, 0x71, 0x58, 0x00, 0x00, 0x00}, 6
777        };
778
779        cmd.msg[3] = (((frequency / 10000000) << 4) & 0xF0) | ((frequency / 1000000) & 0x0F);
780        cmd.msg[4] = (((frequency / 100000) << 4) & 0xF0) | ((frequency / 10000) & 0x0F);
781        cmd.msg[5] = (((frequency / 1000) << 4) & 0xF0) | ((frequency / 100) & 0x0F);
782
783        sendDiseqcCommand(&cmd, 15);
784}
785
786int CFrontend::driveToSatellitePosition(t_satellite_position satellitePosition, bool from_scan)
787{
788        int waitForMotor = 0;
789        int new_position = 0, old_position = 0;
790        bool use_usals = 0;
791
792        //if(diseqcType == DISEQC_ADVANCED) //FIXME testing
793        {
794                printf("[fe0] SatellitePosition %d -> %d\n", currentSatellitePosition, satellitePosition);
795                bool moved = false;
796
797                sat_iterator_t sit = satellitePositions.find(satellitePosition);
798                if (sit == satellitePositions.end()) {
799                        printf("[fe0] satellite position %d not found!\n", satellitePosition);
800                        return 0;
801                } else {
802                        new_position = sit->second.motor_position;
803                        use_usals = sit->second.use_usals;
804                }
805                sit = satellitePositions.find(currentSatellitePosition);
806                if (sit != satellitePositions.end())
807                        old_position = sit->second.motor_position;
808
809                printf("[fe0] motorPosition %d -> %d usals %s\n", old_position, new_position, use_usals ? "on" : "off");
810
811                if (currentSatellitePosition == satellitePosition)
812                        return 0;
813
814                if (use_usals) {
815                        gotoXX(satellitePosition);
816                        moved = true;
817                } else {
818                        if (new_position > 0) {
819                                positionMotor(new_position);
820                                moved = true;
821                        }
822                }
823
824                if (from_scan || (new_position > 0 && old_position > 0)) {
825                        waitForMotor = motorRotationSpeed ? 2 + abs(satellitePosition - currentSatellitePosition) / motorRotationSpeed : 0;
826                }
827                if (moved) {
828                        //currentSatellitePosition = satellitePosition;
829                        waitForMotor = motorRotationSpeed ? 2 + abs(satellitePosition - currentSatellitePosition) / motorRotationSpeed : 0;
830                        currentSatellitePosition = satellitePosition;
831                }
832        }
833        //currentSatellitePosition = satellitePosition;
834
835        return waitForMotor;
836}
837#endif
838
839void fediseqcset(struct dvbdev* node, struct transponder* tpnode)
840{
841        debug(1000, "in");
842        int toneburst = 0, cmdorder = 0, aktlnb = 1, input = 0, uinput = 0, diseqmode = 0;
843        fe_sec_mini_cmd_t mini = -1;
844        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
845        struct dvb_diseqc_master_cmd ucmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
846       
847        if(node == NULL) return;
848       
849        input = getconfigint("diseqc_committedcmd", node->feaktdiseqc);
850        uinput = getconfigint("diseqc_uncommittedcmd", node->feaktdiseqc);
851        diseqmode = getconfigint("diseqc_mode", node->feaktdiseqc);
852        cmdorder = getconfigint("diseqc_cmdorder", node->feaktdiseqc);
853        toneburst = getconfigint("diseqc_toneburst", node->feaktdiseqc);
854
855        if(node->feaktlnb != NULL)
856                aktlnb = atoi(node->feaktlnb);
857
858        debug(200, "set diseqc: number=%d, band=%d, pol=%d", aktlnb, node->feaktband, node->feaktpolarization);
859        debug(200, "set diseqc: diseqmode=%d, input=%d, uinput=%d, cmdorder=%d, toneburst=%d", diseqmode, input, uinput, cmdorder, toneburst);
860         
861        switch(toneburst)
862        {
863                case 1: mini = SEC_MINI_A; break;
864                case 2: mini = SEC_MINI_B; break;
865        }
866       
867        if(diseqmode == 100) // Tonburst A/B
868        {
869                debug(200, "set diseqc: Tonburst A/B");
870                if(mini == -1)
871                        mini = (aktlnb - 1) % 2 ? SEC_MINI_B : SEC_MINI_A;
872                fediseqcsendburst(node, mini, 15);
873                return;
874        }
875               
876        if(diseqmode == 0 || diseqmode == 1) // Diseqc 1.0 + 1.1
877        {
878                debug(200, "set committed switch");
879                cmd.msg[0] = 0xE0;
880                cmd.msg[1] = 0x10;
881                cmd.msg[2] = 0x38;
882
883                if(input == 0)
884                        cmd.msg[3] = 0xF0 | ((((aktlnb - 1) * 4) & 0x0F) | (node->feaktband ? 1 : 0) | (node->feaktpolarization ? 0 : 2));
885                else
886                        cmd.msg[3] = 0xF0 + ((input - 1) & 0x0F);
887
888                cmd.msg_len = 4;
889        }
890
891        if(diseqmode == 1) // Diseqc 1.1
892        {
893                if(uinput > 0)
894                {
895                        debug(200, "set uncommitted switch");
896                        ucmd.msg[0] = 0xE0;
897                        ucmd.msg[1] = 0x10;
898                        ucmd.msg[2] = 0x39;
899                        ucmd.msg[3] = 0xF0 + ((uinput - 1) & 0x0F);
900                        ucmd.msg_len = 4;
901                }
902        }
903                 
904        switch(cmdorder)
905        {
906                case 1:
907                        if(mini != -1) fediseqcsendburst(node, mini, 15);
908                        fediseqcsendmastercmd(node, &cmd, 100);
909                        break;
910                case 2:
911                        fediseqcsendmastercmd(node, &cmd, 100);
912                        if(uinput > 0) fediseqcsendmastercmd(node, &ucmd, 100);
913                        if(mini != -1) fediseqcsendburst(node, mini, 15);
914                        break;
915                case 3:
916                        if(mini != -1) fediseqcsendburst(node, mini, 15);
917                        fediseqcsendmastercmd(node, &cmd, 100);
918                        if(uinput > 0) fediseqcsendmastercmd(node, &ucmd, 100);
919                        break;
920                case 4:
921                        if(uinput > 0) fediseqcsendmastercmd(node, &ucmd, 100);
922                        fediseqcsendmastercmd(node, &cmd, 100);
923                        if(mini != -1) fediseqcsendburst(node, mini, 15);
924                        break;
925                case 5:
926                        if(mini != -1) fediseqcsendburst(node, mini, 15);
927                        if(uinput > 0) fediseqcsendmastercmd(node, &ucmd, 100);
928                        fediseqcsendmastercmd(node, &cmd, 100);
929                        break;
930                default:
931                        fediseqcsendmastercmd(node, &cmd, 100);
932                        if(mini != -1) fediseqcsendburst(node, mini, 15);
933                        break;
934        }
935
936        debug(1000, "out");
937}
938
939void feset(struct dvbdev* node, struct transponder* tpnode)
940{
941        debug(1000, "in");
942        int voltagemode = 0, tonemode = 0;
943        fe_sec_tone_mode_t tone;
944        fe_sec_voltage_t volt;
945        struct dvbdev* dvbnode = dvbdev;
946
947        if(node == NULL)
948        {
949                debug(1000, "out-> NULL detect");
950                return;
951        }
952
953        // set volage off from other unused frontend
954        while(dvbnode != NULL)
955        {
956                if(dvbnode->type != FRONTENDDEV) break;
957                if(dvbnode->type == FRONTENDDEV && dvbnode != node && dvbnode->felock == 0 && dvbnode != status.aktservice->fedev)
958                {
959                        fesetvoltage(dvbnode, SEC_VOLTAGE_OFF, 15);
960                }
961                dvbnode = dvbnode->next;
962        }
963
964        calclof(node, tpnode, NULL, 0);
965
966        voltagemode = getconfigint("lnb_voltagemode", node->feaktlnb);
967        switch(voltagemode)
968        {
969                case 1: volt = SEC_VOLTAGE_13; break;
970                case 2: volt = SEC_VOLTAGE_18; break;
971                default: volt = node->feaktpolarization ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18;
972        }
973        fesetvoltage(node, volt, 15);
974
975        if(node->feaktdiseqc == NULL)
976        {
977                debug(200, "don't use diseqc");
978        }
979        else
980        {
981                fesettone(node, SEC_TONE_OFF, 15);
982                fediseqcset(node, tpnode);
983        }
984
985        tonemode = getconfigint("lnb_tonemode", node->feaktlnb);
986        switch(tonemode)
987        {
988                case 1: tone = SEC_TONE_ON; break;
989                case 2: tone = SEC_TONE_OFF; break;
990                default: tone = node->feaktband ? SEC_TONE_ON : SEC_TONE_OFF;
991        }
992        fesettone(node, tone, 15);
993        debug(1000, "out");
994}
995
996void fediscard(struct dvbdev* node)
997{
998        debug(1000, "in");
999        struct dvb_frontend_event ev;
1000        int count = 0;
1001
1002        if(node == NULL)
1003        {
1004                debug(1000, "out-> NULL detect");
1005                return;
1006        }
1007
1008        /* discard stale QPSK events */
1009        while(count < 20)
1010        {
1011                count++;
1012                if(ioctl(node->fd, FE_GET_EVENT, &ev) == -1)
1013                        break;
1014        }
1015
1016        debug(1000, "out");
1017}
1018
1019uint16_t fereadsnr(struct dvbdev* node)
1020{
1021        debug(1000, "in");
1022        uint16_t snr = 0;
1023
1024        if(node == NULL)
1025        {
1026                debug(1000, "out-> NULL detect");
1027                return 0;
1028        }
1029
1030        ioctl(node->fd, FE_READ_SNR, &snr);
1031        debug(200, "frontend snr = %02x", (snr * 100) / 0xffff);
1032        debug(1000, "out");
1033        return snr;
1034}
1035
1036uint16_t fereadsignalstrength(struct dvbdev* node)
1037{
1038        debug(1000, "in");
1039        uint16_t signal = 0;
1040
1041        if(node == NULL)
1042        {
1043                debug(1000, "out-> NULL detect");
1044                return 0;
1045        }
1046
1047        ioctl(node->fd, FE_READ_SIGNAL_STRENGTH, &signal);
1048        debug(200, "frontend signal = %02x", (signal * 100) / 0xffff);
1049        debug(1000, "out");
1050        return signal;
1051}
1052
1053uint32_t fereadber(struct dvbdev* node)
1054{
1055        debug(1000, "in");
1056        uint32_t ber = 0;
1057
1058        if(node == NULL)
1059        {
1060                debug(1000, "out-> NULL detect");
1061                return 0;
1062        }
1063
1064        ioctl(node->fd, FE_READ_BER, &ber);
1065        debug(200, "frontend ber = %02x", ber);
1066        debug(1000, "out");
1067        return ber;
1068}
1069
1070uint32_t fereaduncorrectedblocks(struct dvbdev* node)
1071{
1072        debug(1000, "in");
1073        uint32_t unc = 0;
1074
1075        if(node == NULL)
1076        {
1077                debug(1000, "out-> NULL detect");
1078                return 0;
1079        }
1080
1081        ioctl(node->fd, FE_READ_UNCORRECTED_BLOCKS, &unc);
1082        debug(200, "frontend unc = %02x", unc);
1083        debug(1000, "out");
1084        return unc;
1085}
1086
1087fe_status_t fereadstatus(struct dvbdev* node)
1088{
1089        debug(1000, "in");
1090        fe_status_t status;
1091
1092        if(node == NULL)
1093        {
1094                debug(1000, "out-> NULL detect");
1095                return -1;
1096        }
1097
1098        if(ioctl(node->fd, FE_READ_STATUS, &status) == -1)
1099                perr("FE_READ_STATUS");
1100
1101        debug(200, "frontend status = %02x", status);
1102        if(status & FE_HAS_LOCK) debug(200, "frontend = FE_HAS_LOCK");
1103        if(status & FE_HAS_SIGNAL) debug(200, "frontend = FE_HAS_SIGNAL");
1104        if(status & FE_HAS_CARRIER) debug(200, "frontend = FE_HAS_CARRIER");
1105        if(status & FE_HAS_VITERBI) debug(200, "frontend = FE_HAS_VITERBI");
1106        if(status & FE_HAS_SYNC) debug(200, "frontend = FE_HAS_SYNC");
1107        if(status & FE_TIMEDOUT) debug(200, "frontend = FE_TIMEDOUT");
1108        if(status & FE_REINIT) debug(200, "frontend = FE_REINIT");
1109
1110        debug(1000, "out");
1111        return status;
1112}
1113
1114void fetunedvbs(struct dvbdev* node, struct transponder* tpnode)
1115{
1116        debug(1000, "in");
1117        if(node == NULL || tpnode == NULL)
1118        {
1119                debug(1000, "out-> NULL detect");
1120                return;
1121        }
1122
1123#if DVB_API_VERSION >= 5
1124        struct dtv_property p[10];
1125        struct dtv_properties cmdseq;
1126        cmdseq.props = p;
1127
1128        //convert transponderlist for dvbapi5
1129        int fec = tpnode->fec;
1130        int system = tpnode->system;
1131        if(system == 0) system = SYS_DVBS;
1132        if(system == 1)
1133        {
1134                system = SYS_DVBS2;
1135                if(fec == 9) fec = 11;
1136        }
1137
1138        int modulation = tpnode->modulation;
1139        if(modulation == 0) modulation = QPSK;
1140        if(modulation == 1) modulation = QPSK;
1141        if(modulation == 2) modulation = PSK_8;
1142        if(modulation == 3) modulation = QAM_16;
1143
1144        p[0].cmd = DTV_CLEAR;
1145        p[1].cmd = DTV_DELIVERY_SYSTEM, p[1].u.data = system;
1146        p[2].cmd = DTV_FREQUENCY,       p[2].u.data = node->feloffrequency;
1147        p[3].cmd = DTV_MODULATION,      p[3].u.data = modulation;
1148        p[4].cmd = DTV_SYMBOL_RATE,     p[4].u.data = tpnode->symbolrate;
1149        p[5].cmd = DTV_INNER_FEC,       p[5].u.data = fec;
1150        p[6].cmd = DTV_INVERSION,       p[6].u.data = (fe_spectral_inversion_t) tpnode->inversion;
1151        if(system == SYS_DVBS2)
1152        {
1153                p[7].cmd = DTV_ROLLOFF,         p[7].u.data = tpnode->rolloff;
1154                p[8].cmd = DTV_PILOT,           p[8].u.data = tpnode->pilot;
1155                p[9].cmd = DTV_TUNE;
1156                cmdseq.num = 10;
1157        }
1158        else
1159        {
1160                p[7].cmd = DTV_TUNE;
1161                cmdseq.num = 8;
1162        }
1163
1164        debug(200, "frequ=%d, inversion=%d, pilot=%d, rolloff=%d, fec=%d, sr=%d, modulation=%d, system=%d", node->feloffrequency, tpnode->inversion, tpnode->pilot, tpnode->rolloff, fec, tpnode->symbolrate, modulation, system);
1165#else
1166        struct dvb_frontend_parameters tuneto;
1167        fe_spectral_inversion_t inversion = tpnode->inversion;
1168
1169        //convert transponderlist for dvbapi3
1170        int fec = tpnode->fec;
1171        if(tpnode->system == 1)
1172        {
1173                if(tpnode->modulation == 1) fec = fec + 9;
1174                if(tpnode->modulation == 2) fec = fec + 18;
1175        }
1176
1177        inversion |= (tpnode->rolloff << 2) | inversion; // use bit 2..3 of inversion for rolloff
1178        inversion |= (tpnode->pilot << 4) | inversion; // use bit 4..5 of inversion for pilot
1179
1180        tuneto.frequency = node->feloffrequency;
1181        tuneto.inversion = inversion;
1182        tuneto.u.qpsk.symbol_rate = tpnode->symbolrate;
1183        tuneto.u.qpsk.fec_inner = fec;
1184
1185        debug(200, "frequ=%d, inversion=%d, pilot=%d, rolloff=%d, fec=%d, sr=%d modulation=%d, system=%d", node->feloffrequency, inversion, tpnode->pilot, tpnode->rolloff, fec, tpnode->symbolrate, tpnode->modulation, tpnode->system);
1186#endif
1187
1188        fediscard(node);
1189
1190#if DVB_API_VERSION >= 5
1191        if((ioctl(node->fd, FE_SET_PROPERTY, &cmdseq)) == -1)
1192        {
1193                perr("FE_SET_PROPERTY");
1194        }
1195#else
1196        if(ioctl(node->fd, FE_SET_FRONTEND, &tuneto) == -1)
1197        {
1198                perr("FE_SET_FRONTEND");
1199        }
1200#endif
1201        debug(1000, "out");
1202}
1203
1204void fetunedvbc(struct dvbdev* node, struct transponder* tpnode)
1205{
1206        debug(1000, "in");
1207
1208        if(node == NULL || tpnode == NULL)
1209        {
1210                debug(1000, "out-> NULL detect");
1211                return;
1212        }
1213
1214#if DVB_API_VERSION >= 5
1215        struct dtv_property p[8];
1216        struct dtv_properties cmdseq;
1217        cmdseq.props = p;
1218
1219        p[0].cmd = DTV_CLEAR;
1220        p[1].cmd = DTV_DELIVERY_SYSTEM, p[1].u.data = tpnode->system;
1221        p[2].cmd = DTV_FREQUENCY,       p[2].u.data = tpnode->frequency;
1222        p[3].cmd = DTV_MODULATION,      p[3].u.data = tpnode->modulation;
1223        p[4].cmd = DTV_SYMBOL_RATE,     p[4].u.data = tpnode->symbolrate;
1224        p[5].cmd = DTV_INVERSION,       p[5].u.data = (fe_spectral_inversion_t) tpnode->inversion;
1225        p[6].cmd = DTV_INNER_FEC,       p[6].u.data = tpnode->fec;
1226        p[7].cmd = DTV_TUNE;
1227        cmdseq.num = 8;
1228
1229        debug(200, "frequ=%d, inversion=%d, fec=%d, sr=%d, modulation=%d, system=%d", tpnode->frequency, tpnode->inversion, tpnode->fec, tpnode->symbolrate, tpnode->modulation, tpnode->system);
1230#else
1231        struct dvb_frontend_parameters tuneto;
1232
1233        tuneto.frequency = tpnode->frequency;
1234        tuneto.inversion = tpnode->inversion;
1235        tuneto.u.qam.symbol_rate = tpnode->symbolrate;
1236        tuneto.u.qam.fec_inner = tpnode->fec;
1237        tuneto.u.qam.modulation = tpnode->modulation;
1238
1239        debug(200, "frequ=%d, inversion=%d, fec=%d, sr=%d, modulation=%d", tpnode->frequency, tpnode->inversion, tpnode->fec, tpnode->symbolrate, tpnode->modulation);
1240#endif
1241
1242        fediscard(node);
1243
1244#if DVB_API_VERSION >= 5
1245        if((ioctl(node->fd, FE_SET_PROPERTY, &cmdseq)) == -1)
1246        {
1247                perr("FE_SET_PROPERTY");
1248        }
1249#else
1250        if(ioctl(node->fd, FE_SET_FRONTEND, &tuneto) == -1)
1251        {
1252                perr("FE_SET_FRONTEND");
1253        }
1254#endif
1255        debug(1000, "out");
1256}
1257
1258void fetunedvbt(struct dvbdev* node, struct transponder* tpnode)
1259{
1260        debug(1000, "in");
1261        struct dvb_frontend_parameters tuneto;
1262
1263        if(node == NULL || tpnode == NULL)
1264        {
1265                debug(1000, "out-> NULL detect");
1266                return;
1267        }
1268
1269        tuneto.frequency = tpnode->frequency;
1270        tuneto.inversion = tpnode->inversion;
1271        tuneto.u.ofdm.bandwidth = 0;
1272        tuneto.u.ofdm.code_rate_HP = 0;
1273        tuneto.u.ofdm.code_rate_LP = 0;
1274        tuneto.u.ofdm.constellation = 0;
1275        tuneto.u.ofdm.transmission_mode = 0;
1276        tuneto.u.ofdm.guard_interval = 0;
1277        tuneto.u.ofdm.hierarchy_information = 0;
1278
1279        fediscard(node);
1280
1281        if(ioctl(node->fd, FE_SET_FRONTEND, &tuneto) == -1)
1282        {
1283                perr("FE_SET_FRONTEND");
1284        }
1285        debug(1000, "out");
1286}
1287
1288#ifdef SIMULATE
1289int tunercount = 0;
1290#endif
1291struct dvb_frontend_info* fegetinfo(struct dvbdev* node, int fd)
1292{
1293        debug(1000, "in");
1294        struct dvb_frontend_info* feinfo = NULL;
1295        int tmpfd = -1;
1296
1297        if(node != NULL)
1298                tmpfd = node->fd;
1299        else
1300                tmpfd = fd;
1301
1302        feinfo = (struct dvb_frontend_info*)malloc(sizeof(struct dvb_frontend_info));
1303        if(feinfo == NULL)
1304        {
1305                err("no mem");
1306                return NULL;
1307        }
1308
1309#ifndef SIMULATE
1310        if(ioctl(tmpfd, FE_GET_INFO, feinfo) < 0)
1311        {
1312                perr("FE_GET_INFO");
1313                free(feinfo);
1314                return NULL;
1315        }
1316#else
1317        tunercount++;
1318        if(tunercount == 1)
1319        {
1320                sprintf(feinfo->name, "%s", "Conax 7500 DVB-C");
1321                feinfo->type = FE_QAM;
1322        }
1323        else
1324        {
1325                sprintf(feinfo->name, "%s", "Conax 7500 DVB-S");
1326                feinfo->type = FE_QPSK;
1327                //feinfo->type = FE_QAM;
1328        }
1329#endif
1330        debug(1000, "out");
1331        return feinfo;
1332}
1333
1334int fegetdev()
1335{
1336        debug(1000, "in");
1337        int i, y, fd = -1, count = 0;
1338        char *buf = NULL, *frontenddev = NULL;
1339        struct dvb_frontend_info* feinfo = NULL;
1340        struct dvbdev* dvbnode = NULL;
1341
1342        frontenddev = getconfig("frontenddev", NULL);
1343        if(frontenddev == NULL)
1344        {
1345                debug(1000, "out -> NULL detect");
1346                return count;
1347        }
1348
1349        buf = malloc(MINMALLOC);
1350        if(buf == NULL)
1351        {
1352                err("no memory");
1353                return count;
1354        }
1355
1356        for(i = 0; i < MAXDVBADAPTER; i++)
1357        {
1358                for(y = 0; y < MAXFRONTENDDEV; y++)
1359                {
1360                        sprintf(buf, frontenddev, i, y);
1361                        fd = feopen(NULL, buf);
1362                        if(fd >= 0)
1363                        {
1364                                feinfo = fegetinfo(NULL, fd);
1365                                if(feinfo != NULL)
1366                                {
1367                                        count++;
1368                                        dvbnode = adddvbdev(buf, i, y, fd, FRONTENDDEV, feinfo, NULL);
1369                                        if(dvbnode->feinfo->type == FE_QPSK)
1370                                                fesetvoltage(dvbnode, SEC_VOLTAGE_OFF, 15);
1371                                }
1372                        }
1373                }
1374        }
1375
1376        free(buf);
1377        debug(1000, "out");
1378        return count;
1379}
1380
1381int fecreatedummy()
1382{
1383        //create dummy frontend for playback
1384        char *buf = NULL, *frontenddev = NULL;
1385        struct dvbdev* dvbnode = NULL;
1386
1387        frontenddev = getconfig("frontenddev", NULL);
1388        if(frontenddev == NULL)
1389        {
1390                debug(1000, "out -> NULL detect");
1391                return 1;
1392        }
1393
1394        buf = malloc(MINMALLOC);
1395        if(buf == NULL)
1396        {
1397                err("no memory");
1398                return 1;
1399        }
1400
1401        dvbnode = dmxgetlast(0);
1402        if(dvbnode != NULL)
1403        {
1404                sprintf(buf, frontenddev, 0, dvbnode->devnr);
1405                adddvbdev(buf, 0, dvbnode->devnr, -1, FRONTENDDEVDUMMY, NULL, NULL);
1406        }
1407
1408        free(buf);
1409        return 0;
1410}
1411
1412#endif
Note: See TracBrowser for help on using the repository browser.