source: titan/titan/frontenddev.h @ 41369

Last change on this file since 41369 was 41369, checked in by gost, 6 years ago

fix

File size: 66.2 KB
Line 
1#ifndef FRONTENDDEV_H
2#define FRONTENDDEV_H
3
4enum {
5                T_Bandwidth_8MHz, T_Bandwidth_7MHz, T_Bandwidth_6MHz, T_Bandwidth_Auto, T_Bandwidth_5MHz, T_Bandwidth_1_712MHz, T_Bandwidth_10MHz
6};
7
8enum {
9                T_FEC_1_2=0, T_FEC_2_3=1, T_FEC_3_4=2, T_FEC_5_6=3, T_FEC_7_8=4, T_FEC_Auto=5, T_FEC_6_7=6, T_FEC_8_9=7
10};
11
12enum {
13                System_DVB_T_T2 = -1, System_DVB_T, System_DVB_T2
14};
15
16enum {
17                T_TransmissionMode_2k, T_TransmissionMode_8k, T_TransmissionMode_Auto, T_TransmissionMode_4k, T_TransmissionMode_1k, T_TransmissionMode_16k, T_TransmissionMode_32k
18};
19
20enum {
21                T_GuardInterval_1_32, T_GuardInterval_1_16, T_GuardInterval_1_8, T_GuardInterval_1_4, T_GuardInterval_Auto, T_GuardInterval_1_128, T_GuardInterval_19_128, T_GuardInterval_19_256
22};
23
24enum {
25                T_Hierarchy_None, T_Hierarchy_1, T_Hierarchy_2, T_Hierarchy_4, T_Hierarchy_Auto
26};
27
28enum {
29                T_Modulation_QPSK, T_Modulation_QAM16, T_Modulation_QAM64, T_Modulation_Auto, T_Modulation_QAM256
30};
31
32enum {
33                T_Inversion_Off, T_Inversion_On, T_Inversion_Unknown
34};
35
36int calclof(struct dvbdev* node, struct transponder* tpnode, char* feaktnr, int flag)
37{
38        int loftype = 0;
39        int lofl, lofh, lofthreshold;
40        int satcrfrequ = 0;
41        char* tmpstr = NULL;
42
43        if(node == NULL || tpnode == NULL)
44        {
45                err("NULL detect");
46                return -1;
47        }
48
49        if(node->feinfo->type != FE_QPSK)
50                return 0;
51
52        unsigned int frequency = tpnode->frequency;
53        node->feunicable = 0;
54
55        if(feaktnr == NULL) feaktnr = node->feaktnr;
56
57        tmpstr = ostrcat(node->feshortname, "_lnb_loftype", 0, 0);
58        loftype = getconfigint(tmpstr, feaktnr);
59        free(tmpstr); tmpstr = NULL;
60        switch(loftype)
61        {
62                case 1: //c-band
63                        lofl = 5150 * 1000;
64                        lofh = 5150 * 1000;
65                        lofthreshold = 5150 * 1000;
66                        break;
67                case 2: //user
68                        tmpstr = ostrcat(node->feshortname, "_lnb_lofl", 0, 0);
69                        lofl = getconfigint(tmpstr, feaktnr) * 1000;
70                        free(tmpstr); tmpstr = NULL;
71                        tmpstr = ostrcat(node->feshortname, "_lnb_lofh", 0, 0);
72                        lofh = getconfigint(tmpstr, feaktnr) * 1000;
73                        free(tmpstr); tmpstr = NULL;
74                        tmpstr = ostrcat(node->feshortname, "_lnb_lofthreshold", 0, 0);
75                        lofthreshold = getconfigint(tmpstr, feaktnr) * 1000;
76                        free(tmpstr); tmpstr = NULL;
77                        break;
78                case 3: //unicable
79                case 4: //user unicable
80                        tmpstr = ostrcat(node->feshortname, "_lnb_lofl", 0, 0);
81                        lofl = getconfigint(tmpstr, feaktnr) * 1000;
82                        free(tmpstr); tmpstr = NULL;
83                        if(lofl == 0) lofl = 9750 * 1000;
84                        tmpstr = ostrcat(node->feshortname, "_lnb_lofh", 0, 0);
85                        lofh = getconfigint(tmpstr, feaktnr) * 1000;
86                        free(tmpstr); tmpstr = NULL;
87                        if(lofh == 0) lofh = 10600 * 1000;
88                        tmpstr = ostrcat(node->feshortname, "_lnb_lofthreshold", 0, 0);
89                        lofthreshold = getconfigint(tmpstr, feaktnr) * 1000;
90                        free(tmpstr); tmpstr = NULL;
91                        if(lofthreshold == 0) lofthreshold = 11700 * 1000;
92                        tmpstr = ostrcat(node->feshortname, "_lnb_satcrfrequ", 0, 0);
93                        satcrfrequ = getconfigint(tmpstr, feaktnr) * 1000;
94                        free(tmpstr); tmpstr = NULL;
95                        break;
96                default: //standard lnb
97                        lofl = 9750 * 1000;
98                        lofh = 10600 * 1000;
99                        lofthreshold = 11700 * 1000;
100        }
101
102        if(lofthreshold && lofh && frequency >= lofthreshold)
103        {
104                if(flag == 1) return 1;
105                node->feaktband = 1;
106        }
107        else
108        {
109                if(flag == 1) return 0;
110                node->feaktband = 0;
111        }
112
113        if(satcrfrequ == 0)
114        {
115                if(node->feaktband)
116                        node->feloffrequency = frequency - lofh;
117                else
118                {
119                        if(frequency < lofl)
120                                node->feloffrequency = lofl - frequency;
121                        else
122                                node->feloffrequency = frequency - lofl;
123                }
124        }
125        else
126        {
127                int lof = (node->feaktband & 1) ? lofh : lofl;
128                unsigned int tmp = (frequency - lof) + satcrfrequ;
129                node->feloffrequency = (tmp / 4) - 350000;
130                node->feunicable = 1;
131        }
132
133        debug(200, "tuning to freq %d (befor lof %d), band=%d, unicable=%d", node->feloffrequency, frequency, node->feaktband, node->feunicable);
134        return node->feaktband;
135}
136
137char* fegettypestr(struct dvbdev* dvbnode)
138{
139        char* text = NULL;
140
141        if(dvbnode == NULL)
142        {
143                err("NULL detect");
144                return NULL;
145        }
146
147        switch(dvbnode->feinfo->type)
148        {
149                case FE_QPSK: text = ostrcat(text, "DVB-S", 1, 0); break;
150                case FE_QAM: text = ostrcat(text, "DVB-C", 1, 0); break;
151                case FE_OFDM: text = ostrcat(text, "DVB-T", 1, 0); break;
152                default: text = ostrcat(text, "unknown", 1, 0);
153        }
154
155        return text;
156}
157
158struct dvbdev* fegetbyshortname(char* feshortname)
159{
160        struct dvbdev* dvbnode = dvbdev;
161       
162        while(dvbnode != NULL)
163        {
164                if(dvbnode->type == FRONTENDDEV && ostrcmp(dvbnode->feshortname, feshortname) == 0)
165                        return dvbnode;
166                dvbnode = dvbnode->next;
167        }
168        return NULL;
169}
170
171void fegetconfig(struct dvbdev *dvbnode, struct transponder *tpnode, char** aktnr, char* tmpnr)
172{
173        char* tmpstr = NULL;
174
175        if(dvbnode == NULL || tpnode == NULL)
176        {
177                err("NULL detect");
178                return;
179        }
180
181        tmpstr = ostrcat(dvbnode->feshortname, "_satnr", 0, 0);
182        *aktnr = getconfig(tmpstr, tmpnr);
183        free(tmpstr); tmpstr = NULL;
184}
185
186struct dvbdev* fegetdummy()
187{
188        struct dvbdev* dvbnode = dvbdev;
189
190        while(dvbnode != NULL)
191        {
192                if(dvbnode->type == FRONTENDDEVDUMMY)
193                        return dvbnode;
194                dvbnode = dvbnode->next;
195        }
196        return NULL;
197}
198
199void settunerstatus()
200{
201        struct dvbdev* dvbnode = dvbdev;
202        char *tmpstr = NULL;
203        char *buf = NULL;
204        int fbc = 0;
205        while(dvbnode != NULL)
206        {
207                //FRONTENDDEV first in the list
208                if(dvbnode->type != FRONTENDDEV) break;
209               
210                if(dvbnode != NULL && ostrstr(dvbnode->feinfo->name, "BCM45208") != NULL)
211                        fbc = 1;
212                else
213                        fbc = 0;
214
215                if((checkbox("DM900") == 1 || checkbox("DM520") == 1 || checkbox("DM525") == 1) && fbc != 1)
216                {
217                        if(ostrcmp("fe_01", dvbnode->feshortname) == 0)
218                        {
219                                if(ostrcmp("fe_00", getconfig(dvbnode->feshortname, NULL)) == 0)
220                                        system("echo internal > /proc/stb/frontend/1/rf_switch");
221                                else
222                                        system("echo external > /proc/stb/frontend/1/rf_switch");
223                        }
224                }
225                if(fbc == 1)
226                {
227                        buf = malloc(MINMALLOC);
228                        if(buf == NULL)
229                        {
230                                err("no memory");
231                                return;
232                        }
233                        sprintf(buf, "/proc/stb/frontend/%d/input",dvbnode->devnr);
234                        tmpstr = ostrcat(dvbnode->feshortname, "_fbc", 0, 0);
235                        if(ostrcmp("AM", getconfig(tmpstr, NULL)) == 0 || ostrcmp("AU", getconfig(tmpstr, NULL)) == 0 || ostrcmp("A", getconfig(tmpstr, NULL)) == 0)
236                                writesys(buf, "A", 1);
237                        else
238                                writesys(buf, "B", 1); 
239                        free(buf); buf = NULL;
240                        free(tmpstr); tmpstr = NULL;
241                }
242                //check if tuner is deactivate
243                if(ostrcmp("x", getconfig(dvbnode->feshortname, NULL)) == 0)
244                        dvbnode->deactive = 1;
245                else
246                        dvbnode->deactive = 0;
247
248                dvbnode = dvbnode->next;
249        }
250}
251
252//flag 0 = normal
253//flag 1 = check only
254//flag 2 = from record
255//flag 3 = from rectimer
256struct dvbdev* fegetfree(struct transponder* tpnode, int flag, struct dvbdev* dvbfirst)
257{
258        struct dvbdev* dvbnode = NULL;
259        struct dvbdev* tmpdvbnode = NULL;
260        char* tmpstr = NULL, *tmpnr = NULL, *aktnr = NULL;
261        int i, orbitalpos = 0, band = 0;
262        int found = 0;
263        //char *CharPtrTmp[20];
264        struct dvbdev* CharPtrTmp[20];
265       
266        if(dvbfirst != NULL)
267                dvbnode = dvbfirst;
268        else
269                dvbnode = dvbdev;
270
271        if(tpnode == NULL)
272        {
273                err("NULL detect");
274                return NULL;
275        }
276
277        //suche tuner der auf der gleichen orbitalpos/frequency/pol/band ist
278        while(dvbnode != NULL)
279        {
280                //FRONTENDDEV first in the list
281                if(dvbnode->type != FRONTENDDEV) break;
282
283                //check if tuner is deactivate
284                if(dvbnode->deactive == 1)
285                {
286                        dvbnode = dvbnode->next;
287                        continue;
288                }
289                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo->type == tpnode->fetype)
290                {
291                        if(dvbnode->feakttransponder != NULL && dvbnode->felock == 0 && status.aktservice->fedev != dvbnode)
292                        {
293                                if(flag != 1) debug(200, "clear tuner %s", dvbnode->feshortname);
294                                dvbnode->felasttransponder = dvbnode->feakttransponder;
295                                dvbnode->feakttransponder = NULL;
296                        }       
297                        if(dvbnode->feakttransponder != NULL && dvbnode->feakttransponder->orbitalpos == tpnode->orbitalpos && dvbnode->feakttransponder->frequency == tpnode->frequency && dvbnode->feaktpolarization == tpnode->polarization)
298                        {
299                                band = calclof(dvbnode, tpnode, dvbnode->feaktnr, 1);
300                                if(dvbnode->feaktband != band)
301                                {
302                                        dvbnode = dvbnode->next;
303                                        continue;
304                                }
305                                dvbnode->felasttransponder = dvbnode->feakttransponder;
306                                dvbnode->feakttransponder = tpnode;
307                                if(flag != 1) debug(200, "found tuner with same orbitalpos/frequency/pol/band %s", dvbnode->feshortname);
308                                return(dvbnode);
309                        }
310                }
311                dvbnode = dvbnode->next;
312        }
313        if(dvbfirst != NULL)
314                dvbnode = dvbfirst;
315        else
316                dvbnode = dvbdev;
317
318        //suche tuner der die gewuenschte orbitalpos kann und belegt ist und dessen looptuner es kann
319        while(dvbnode != NULL)
320        {
321                //FRONTENDDEV first in the list
322                if(dvbnode->type != FRONTENDDEV) break;
323
324                //check if tuner is deactivate
325                if(dvbnode->deactive == 1)
326                {
327                        dvbnode = dvbnode->next;
328                        continue;
329                }
330                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo->type == tpnode->fetype && (dvbnode->felock != 0 || (flag == 2 && status.aktservice->fedev == dvbnode)))
331                {
332                        //check if tuner is main tuner
333                        if(getconfig(dvbnode->feshortname, NULL) != NULL)
334                        {
335                                dvbnode = dvbnode->next;
336                                continue;                               
337                        }
338                        if(dvbnode->feaktpolarization != tpnode->polarization || dvbnode->feakttransponder->orbitalpos != tpnode->orbitalpos)
339                        {
340                                dvbnode = dvbnode->next;
341                                continue;                               
342                        }
343                        found = 0;
344                        //check looptuner is free
345                        tmpstr = getconfigbyval(dvbnode->feshortname, NULL);
346                        CharPtrTmp[0] = NULL;
347                        while(tmpstr != NULL) //found loop tuner
348                        {
349                                tmpdvbnode = fegetbyshortname(tmpstr);
350                                if(tmpdvbnode != NULL)
351                                {
352                                        if(tmpdvbnode->feakttransponder == NULL || (tmpdvbnode->felock == 0 && status.aktservice->fedev != tmpdvbnode))
353                                        {
354                                                found = 99;
355                                                break;
356                                        }
357                                        else
358                                        {
359                                                CharPtrTmp[found] = tmpdvbnode;
360                                                found = found + 1;
361                                        }
362                                }
363                                tmpstr = getconfigbyval(tmpstr, NULL); //loop tuner also loop  ?
364                        }
365                        CharPtrTmp[0] = NULL;
366                        if(found != 99)
367                        {
368                                dvbnode = dvbnode->next;
369                                continue;
370                        }
371                        tmpstr = ostrcat(dvbnode->feshortname, "_sat", 0, 0);
372                        for(i = 1; i <= getmaxsat(dvbnode->feshortname); i++)
373                        {
374                                tmpnr = oitoa(i);
375                                orbitalpos = getconfigint(tmpstr, tmpnr);
376                                if(orbitalpos == tpnode->orbitalpos)
377                                {
378                                        fegetconfig(dvbnode, tpnode, &aktnr, tmpnr);
379                                        if(flag == 3)
380                                                band = calclof(dvbnode, tpnode, aktnr, 0);
381                                        else
382                                                band = calclof(dvbnode, tpnode, aktnr, 1);
383                                        found = 0;
384                                        if(dvbnode->feaktband != band)
385                                        {
386                                                found = -1;
387                                                break;
388                                        }
389                                        if(flag == 1)
390                                        {
391                                                free(tmpstr); tmpstr = NULL;
392                                                free(tmpnr); tmpnr = NULL;
393                                                return tmpdvbnode;
394                                        }
395                                        if(tmpdvbnode->feakttransponder != NULL)
396                                                tmpdvbnode->felasttransponder = tmpdvbnode->feakttransponder;
397                                        tmpdvbnode->feakttransponder = tpnode;
398                                        tmpdvbnode->feaktpolarization = tpnode->polarization;
399                                        tmpdvbnode->feaktband = band;
400                                        free(tmpdvbnode->feaktnr);
401                                        if(aktnr != NULL)
402                                                tmpdvbnode->feaktnr = ostrcat(aktnr, NULL, 0, 0);
403                                        else
404                                                tmpdvbnode->feaktnr = NULL;
405
406                                        free(tmpstr); tmpstr = NULL;
407                                        free(tmpnr); tmpnr = NULL;
408                                        if(flag != 1) debug(200, "found free tuner witch same orbitalpos %s", dvbnode->feshortname);
409                                        return tmpdvbnode;
410                                }
411                                free(tmpnr); tmpnr = NULL;
412                        }
413                        free(tmpstr); tmpstr = NULL;
414                }
415                dvbnode = dvbnode->next;
416        }
417        if(dvbfirst != NULL)
418                dvbnode = dvbfirst;
419        else
420                dvbnode = dvbdev;
421
422        //suche tuner der die gewuenschte orbitalpos kann und nicht belegt ist
423        while(dvbnode != NULL)
424        {
425                //FRONTENDDEV first in the list
426                if(dvbnode->type != FRONTENDDEV) break;
427
428                //check if tuner is deactivate
429                if(dvbnode->deactive == 1)
430                {
431                        dvbnode = dvbnode->next;
432                        continue;
433                }
434                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo->type == tpnode->fetype && dvbnode->felock == 0)
435                {
436                        //check if tuner is main tuner
437                        if(getconfig(dvbnode->feshortname, NULL) != NULL)
438                        {
439                                dvbnode = dvbnode->next;
440                                continue;                               
441                        }
442                        if(flag == 2 && status.aktservice->fedev == dvbnode)
443                        {
444                                dvbnode = dvbnode->next;
445                                continue;
446                        }
447                        found = 0;
448                        //check if tuner is loop and looptuner is locked
449                        tmpstr = getconfigbyval(dvbnode->feshortname, NULL);
450                        CharPtrTmp[0] = NULL;
451                        while(tmpstr != NULL) //found loop tuner
452                        {
453                                tmpdvbnode = fegetbyshortname(tmpstr);
454                                if(tmpdvbnode != NULL)
455                                {
456                                        if(tmpdvbnode->feakttransponder != NULL && (tmpdvbnode->feaktpolarization != tpnode->polarization || tmpdvbnode->feakttransponder->orbitalpos != tpnode->orbitalpos) && (tmpdvbnode->felock != 0 || (flag == 2 && tmpdvbnode->felock == 0)))
457                                        {
458                                                found = -1;
459                                                break;
460                                        }
461                                        else
462                                        {
463                                                CharPtrTmp[found] = tmpdvbnode;
464                                                found = found + 1;
465                                        }
466                                }
467                                tmpstr = getconfigbyval(tmpstr, NULL); //loop tuner also loop  ?
468                        }
469                        if(found == -1)
470                        {
471                                dvbnode = dvbnode->next;
472                                continue;
473                        }
474                        CharPtrTmp[found] = NULL;
475                        tmpstr = ostrcat(dvbnode->feshortname, "_sat", 0, 0);
476                        for(i = 1; i <= getmaxsat(dvbnode->feshortname); i++)
477                        {
478                                tmpnr = oitoa(i);
479
480                                orbitalpos = getconfigint(tmpstr, tmpnr);
481                                if(orbitalpos == tpnode->orbitalpos)
482                                {
483                                        fegetconfig(dvbnode, tpnode, &aktnr, tmpnr);
484                                        if(flag == 3)
485                                                band = calclof(dvbnode, tpnode, aktnr, 0);
486                                        else
487                                                band = calclof(dvbnode, tpnode, aktnr, 1);
488                                        found = 0;
489                                        while(CharPtrTmp[found] != NULL)
490                                        {
491                                                if(CharPtrTmp[found]->feakttransponder != NULL)
492                                                {
493                                                        if(CharPtrTmp[found]->feaktband != band && (CharPtrTmp[found]->felock != 0 || (flag == 2 && CharPtrTmp[found]->felock == 0)))
494                                                        {
495                                                                found = 99;
496                                                                break;
497                                                        }
498                                                }
499                                                found = found + 1;
500                                        }
501                                        if(found == 99)
502                                        {
503                                                found = 0;
504                                                free(tmpnr); tmpnr = NULL;
505                                                continue;
506                                        }       
507                                        if(flag == 1)
508                                        {
509                                                free(tmpstr); tmpstr = NULL;
510                                                free(tmpnr); tmpnr = NULL;
511                                                return dvbnode;
512                                        }
513                                        found = 0;
514                                        while(CharPtrTmp[found] != NULL)
515                                        {
516                                                CharPtrTmp[found]->feaktband = band;
517                                                CharPtrTmp[found]->feaktpolarization = tpnode->polarization;
518                                                found = found + 1;
519                                        }
520                                        dvbnode->felasttransponder = dvbnode->feakttransponder;
521                                        dvbnode->feakttransponder = tpnode;
522                                        dvbnode->feaktpolarization = tpnode->polarization;
523                                        free(dvbnode->feaktnr);
524                                        if(aktnr != NULL)
525                                                dvbnode->feaktnr = ostrcat(aktnr, NULL, 0, 0);
526                                        else
527                                                dvbnode->feaktnr = NULL;
528                                        free(tmpstr); tmpstr = NULL;
529                                        free(tmpnr); tmpnr = NULL;
530                                        if(flag != 1) debug(200, "found free tuner witch same orbitalpos %s", dvbnode->feshortname);
531                                        return dvbnode;
532                                }
533                                free(tmpnr); tmpnr = NULL;
534                        }
535                        free(tmpstr); tmpstr = NULL;
536                }
537                dvbnode = dvbnode->next;
538        }
539        if(dvbfirst != NULL)
540                dvbnode = dvbfirst;
541        else
542                dvbnode = dvbdev;
543
544        //suche loop tuner, wo der haupttuner
545        //die gewuenschte orbitalpos kann, nicht belegt ist
546        //und auf der gleichen poarization/band ist, wo wir hintunen wollen
547        while(dvbnode != NULL)
548        {
549                //FRONTENDDEV first in the list
550                if(dvbnode->type != FRONTENDDEV) break;
551
552                //check if tuner is deactivate
553                if(dvbnode->deactive == 1)
554                {
555                        dvbnode = dvbnode->next;
556                        continue;
557                }
558                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo->type == tpnode->fetype && dvbnode->felock == 0)
559                {
560                        if(flag == 2 && status.aktservice->fedev == dvbnode)
561                        {
562                                dvbnode = dvbnode->next;
563                                continue;
564                        }
565                        if(getconfig(dvbnode->feshortname, NULL) == NULL)
566                        {
567                                dvbnode = dvbnode->next;
568                                continue;                               
569                        }
570                        //check if tuner is loop and an other loopt is locked
571                        found = 0;
572                        tmpstr = getconfigbyval(dvbnode->feshortname, NULL);
573                        while(tmpstr != NULL) //found loop tuner
574                        {
575                                tmpdvbnode = fegetbyshortname(tmpstr);
576                                if(tmpdvbnode != NULL)
577                                {
578                                        if(tmpdvbnode->feakttransponder != NULL && (tmpdvbnode->feaktpolarization != tpnode->polarization || tmpdvbnode->feakttransponder->orbitalpos != tpnode->orbitalpos) && (tmpdvbnode->felock != 0 || (flag == 2 && tmpdvbnode->felock == 0)))
579                                        {
580                                                found = -1;
581                                                break;
582                                        }
583                                        else
584                                        {
585                                                CharPtrTmp[found] = tmpdvbnode;
586                                                found = found + 1;
587                                        }
588                                }
589                                tmpstr = getconfigbyval(tmpstr, NULL); //loop tuner also loop  ?
590                        }
591                        if(found == -1)
592                        {
593                                dvbnode = dvbnode->next;
594                                continue;
595                        }       
596                        //check if tuner is loop an looptuner is locked
597                        tmpstr = getconfig(dvbnode->feshortname, NULL);
598                        while(tmpstr != NULL) //found loop tuner
599                        {
600                                tmpdvbnode = fegetbyshortname(tmpstr);
601                                if(tmpdvbnode != NULL)
602                                {
603                                        if(tmpdvbnode->feakttransponder != NULL && (tmpdvbnode->feaktpolarization != tpnode->polarization || tmpdvbnode->feakttransponder->orbitalpos != tpnode->orbitalpos) && (tmpdvbnode->felock != 0 || (flag == 2 && tmpdvbnode->felock == 0)))
604                                        {
605                                                found = -1;
606                                                break;
607                                        }
608                                        else
609                                        {
610                                                CharPtrTmp[found] = tmpdvbnode;
611                                                found = found + 1;
612                                        }
613                                }
614                                tmpstr = getconfig(tmpstr, NULL);
615                        }
616                        CharPtrTmp[found] = NULL;
617                        if(found == -1)
618                        {
619                                dvbnode = dvbnode->next;
620                                continue;
621                        }
622       
623                        tmpstr = ostrcat(tmpdvbnode->feshortname, "_sat", 0, 0);
624                        for(i = 1; i <= getmaxsat(tmpdvbnode->feshortname); i++)
625                        {
626                                tmpnr = oitoa(i);
627                                orbitalpos = getconfigint(tmpstr, tmpnr);
628                                if(orbitalpos == tpnode->orbitalpos)
629                                {
630                                        fegetconfig(tmpdvbnode, tpnode, &aktnr, tmpnr);
631                                        if(flag == 3)
632                                                band = calclof(dvbnode, tpnode, aktnr, 0);
633                                        else
634                                                band = calclof(dvbnode, tpnode, aktnr, 1);
635                                        found = 0;
636                                        while(CharPtrTmp[found] != NULL)
637                                        {
638                                                if(CharPtrTmp[found]->feakttransponder != NULL && CharPtrTmp[found]->feaktband != band && (CharPtrTmp[found]->felock != 0 || (flag >= 2 && CharPtrTmp[found]->felock == 0)))   
639                                                {
640                                                        found = 99;
641                                                        break;
642                                                }
643                                                found = found + 1;
644                                        }
645                                        if(found == 99)
646                                        {
647                                                found = 0;
648                                                free(tmpnr); tmpnr = NULL;
649                                                continue;
650                                        }
651                                               
652                                        if(flag == 1)
653                                        {
654                                                free(tmpstr); tmpstr = NULL;
655                                                free(tmpnr); tmpnr = NULL;
656                                                return dvbnode;
657                                        }
658                                        found = 0;
659                                        while(CharPtrTmp[found] != NULL)
660                                        {
661                                                CharPtrTmp[found]->feaktband = band;
662                                                CharPtrTmp[found]->feaktpolarization = tpnode->polarization;
663                                                found = found + 1;
664                                        }
665                                        dvbnode->felasttransponder = dvbnode->feakttransponder;
666                                        dvbnode->feakttransponder = tpnode;
667                                        dvbnode->feaktpolarization = tpnode->polarization;
668                                        free(dvbnode->feaktnr);
669                                        if(aktnr != NULL)
670                                                dvbnode->feaktnr = ostrcat(aktnr, NULL, 0, 0);
671                                        else
672                                                dvbnode->feaktnr = NULL;
673                                        free(tmpstr); tmpstr = NULL;
674                                        free(tmpnr); tmpnr = NULL;
675                                        if(flag != 1) debug(200, "found free looptuner witch same orbitalpos/polarization/band %s main: %s", dvbnode->feshortname, tmpdvbnode->feshortname);
676                                        return dvbnode;
677                                }
678                                free(tmpnr); tmpnr = NULL;
679                        }
680                        free(tmpstr); tmpstr = NULL;
681                }
682                dvbnode = dvbnode->next;
683        }
684
685        return NULL;
686}
687
688int feopen(struct dvbdev* node, char *fedev)
689{
690        int fd = -1;
691
692        if(node != NULL)
693        {       
694                if((fd = open(node->dev, O_RDWR | O_NONBLOCK)) < 0)
695                        debug(200, "open frontend failed %s", node->dev);
696                node->fd = fd;
697        }
698        else
699        {
700                if((fd = open(fedev, O_RDWR | O_NONBLOCK)) < 0)
701                        debug(200, "open frontend failed %s", fedev);
702        }
703
704        closeonexec(fd);
705        return fd;
706}
707
708void feclose(struct dvbdev* node, int fd)
709{
710        if(node != NULL)
711        {
712                close(node->fd);
713                node->fd = -1;
714        }
715        else
716                close(fd);
717}
718
719int fegetunlock(struct dvbdev* node)
720{
721        fe_status_t status;
722
723        if(node == NULL)
724        {
725                err("NULL detect");
726                return 1;
727        }
728
729#ifdef SIMULATE
730        return 0;
731#endif
732
733        if(ioctl(node->fd, FE_READ_STATUS, &status) == -1)
734                perr("FE_READ_STATUS");
735
736        if(status & FE_HAS_LOCK)
737                return 0;
738        else
739                return 1;
740}
741
742int fewait(struct dvbdev* node)
743{
744        //struct dvb_frontend_event ev;
745        fe_status_t status;
746        fe_status_t status_m = 0;
747
748        int count = 0;
749
750        if(node == NULL)
751        {
752                err("NULL detect");
753                return 1;
754        }
755
756#ifdef SIMULATE
757        return 0;
758#endif
759
760        int timer = 500;
761
762#ifdef MIPSEL
763        timer = 2000;
764#endif
765
766#ifdef ARM
767        timer = 300;
768#endif
769
770        //wait for tuner ready
771        debug(200, "wait for tuner start");
772        while(count <= timer)
773        {
774                count++;
775
776                //ioctl(node->fd, FE_GET_EVENT, &ev);
777                //if(ev.status & FE_HAS_LOCK)
778                //      return 0;
779                ioctl(node->fd, FE_READ_STATUS, &status);
780                if(status != 0)
781                {
782                        if(status_m != status)
783                        {
784                                debug(200, "status=%02x, fe_lock=%02x, count=%d", status, FE_HAS_LOCK, count);
785                                status_m = status;
786                        }
787                }
788
789                if(errno == ERANGE)
790                {
791                        usleep(1000);
792                        continue;
793                }
794
795                if(status & FE_HAS_LOCK)
796                {
797        //              if(FE_HAS_SYNC | FE_HAS_LOCK)
798                        debug(200, "wait for tuner end with 0");
799                        return 0;
800                }
801                if(node != NULL && ostrstr(node->feinfo->name, "BCM45208") != NULL)
802                {
803                        if(status & FE_TIMEDOUT)
804                        {
805                                debug(200, "wait for tuner end with FE_TIMEDOUT");
806                                return 1;
807                        }
808                }
809                usleep(1000);
810        }
811        debug(200, "wait for tuner end");
812        //if(ev.status & FE_HAS_LOCK)
813        //      return 0;
814        if(status & FE_HAS_LOCK)
815//      if(FE_HAS_SYNC | FE_HAS_LOCK)
816                return 0;
817        else
818                return 1;
819}
820
821void fegetfrontend(struct dvbdev* node)
822{
823        if(node == NULL)
824        {
825                err("NULL detect");
826                return;
827        }
828
829#if DVB_API_VERSION >= 5
830        struct dtv_property p[8];
831        struct dtv_properties cmdseq;
832        cmdseq.props = p;
833
834        p[0].cmd = DTV_DELIVERY_SYSTEM;
835        p[1].cmd = DTV_FREQUENCY;
836        p[2].cmd = DTV_MODULATION;
837        p[3].cmd = DTV_SYMBOL_RATE;
838        p[4].cmd = DTV_INNER_FEC;
839        p[5].cmd = DTV_INVERSION;
840        p[6].cmd = DTV_ROLLOFF;
841        p[7].cmd = DTV_PILOT;
842        cmdseq.num = 8;
843       
844        if(ioctl(node->fd, FE_GET_PROPERTY, &cmdseq) < 0)
845        {
846                perr("FE_GET_PROPERTY");
847        }
848        else
849        {
850                debug(200, "frontend akt delivery system = %d", p[0].u.data);
851                debug(200, "frontend akt frequency = %d", p[1].u.data);
852                debug(200, "frontend akt inversion = %d", p[5].u.data);
853                debug(200, "frontend akt symbol_rate = %d", p[3].u.data);
854                debug(200, "frontend akt fec_inner = %d", p[4].u.data);
855                debug(200, "frontend akt modulation = %d", p[2].u.data);
856                debug(200, "frontend akt rolloff = %d", p[6].u.data);
857                debug(200, "frontend akt pilot = %d", p[7].u.data);
858        }
859#else
860        struct dvb_frontend_parameters fe_param;
861
862        if(ioctl(node->fd, FE_GET_FRONTEND, &fe_param) < 0)
863        {
864                perr("FE_GET_FRONTEND");
865        }
866        else
867        {
868                debug(200, "frontend akt frequency = %d", fe_param.frequency);
869                debug(200, "frontend akt inversion = %d", fe_param.inversion);
870                debug(200, "frontend akt u.qpsk.symbol_rate = %d", fe_param.u.qpsk.symbol_rate);
871                debug(200, "frontend akt u.qam.symbol_rate = %d", fe_param.u.qam.symbol_rate);
872                debug(200, "frontend akt u.qpsk.fec_inner = %d", fe_param.u.qpsk.fec_inner);
873                debug(200, "frontend akt u.qam.fec_inner = %d", fe_param.u.qam.fec_inner);
874                debug(200, "frontend akt u.qam.modulation = %d", fe_param.u.qam.modulation);
875        }
876#endif
877}
878
879int fesettone(struct dvbdev* node, fe_sec_tone_mode_t tone, int wait)
880{
881        int ret = 0;
882       
883        if(node == NULL)
884        {
885                err("NULL detect");
886                return 1;
887        }
888
889        debug(200, "FE_SET_TONE: %d (%s)", tone, node->feshortname);
890        if(ioctl(node->fd, FE_SET_TONE, tone) == -1)
891        {
892                perr("FE_SET_TONE");
893                ret = 1;
894        }
895        else
896        {
897                node->feakttone = tone;
898                usleep(wait * 1000);
899        }
900       
901        return ret;
902}
903
904//flag 0: reset tuner params on volt off
905//flag 1: don't reset tuner params on volt off
906int fesetvoltage(struct dvbdev* node, fe_sec_voltage_t volt, int wait)
907{
908        int ret = 0;
909       
910        if(node == NULL)
911        {
912                err("NULL detect");
913                return 1;
914        }
915
916        debug(200, "FE_SET_VOLT: %d (%s)", volt, node->feshortname);
917        if(ioctl(node->fd, FE_SET_VOLTAGE, volt) == -1)
918        {
919                perr("FE_SET_VOLTAGE");
920                ret = 1;
921        }
922        else
923        {
924                node->feaktvolt = volt;
925                if(wait > 0) usleep(wait * 1000);
926
927                if(volt == SEC_VOLTAGE_OFF)
928                {
929                        node->feakttransponder = NULL;
930                        node->felasttransponder = NULL;
931                        node->feunicable = 0;
932                        node->feloffrequency = 0;
933                        node->feaktband = 0;
934                        node->feaktpolarization = 0;
935                        node->feakttone = 0;
936                }
937        }
938
939        return ret;
940}
941
942void fediseqcsendburst(struct dvbdev* node, fe_sec_mini_cmd_t burst, int wait)
943{
944        if(node == NULL)
945        {
946                err("NULL detect");
947                return;
948        }
949
950        debug(200, "FE_DISEQC_SEND_BURST: %d (%s)", burst, node->feshortname);
951        if(ioctl(node->fd, FE_DISEQC_SEND_BURST, burst) == -1)
952                perr("FE_DISEQC_SEND_BURST");
953        usleep(wait * 1000);
954}
955
956void fediseqcsendmastercmd(struct dvbdev* node, struct dvb_diseqc_master_cmd *cmd, int wait)
957{
958        int i, repeat = 0, imsg = 0;
959        char* tmpstr = NULL;
960
961        if(node == NULL)
962        {
963                err("NULL detect");
964                return;
965        }
966       
967        if(cmd == NULL) return;
968        if(cmd->msg_len == 0) return;
969
970        tmpstr = ostrcat(node->feshortname, "_diseqc_repeat", 0, 0);
971        repeat = getconfigint(tmpstr, node->feaktnr);
972        free(tmpstr); tmpstr = NULL;
973        if(repeat < 1) repeat = 1;
974
975        for(i = 0; i < repeat; i++)
976        {
977                if(ioctl(node->fd, FE_DISEQC_SEND_MASTER_CMD, cmd) == -1)
978                {
979                        perr("FE_DISEQC_SEND_MASTER_CMD");
980                }
981                usleep(wait * 1000);
982        }
983        imsg = (cmd->msg[0] << 24) | (cmd->msg[1] << 16) | (cmd->msg[2] << 8) | cmd->msg[3];
984        debug(200, "DISEQC Master cmd (%s -> %04X)", node->feshortname, imsg);
985}
986
987void fesdiseqcpoweron(struct dvbdev* node)
988{
989        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
990
991        if(node == NULL)
992        {
993                err("NULL detect");
994                return;
995        }
996
997        cmd.msg[0] = 0xE0;
998        cmd.msg[1] = 0x00;
999        cmd.msg[2] = 0x03;
1000        cmd.msg_len = 3;
1001
1002        debug(200, "DISEQC Power on (%s)", node->feshortname);
1003        fediseqcsendmastercmd(node, &cmd, 100);
1004}
1005
1006void fesdiseqcreset(struct dvbdev* node)
1007{
1008        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
1009       
1010        if(node == NULL)
1011        {
1012                err("NULL detect");
1013                return;
1014        }
1015
1016        cmd.msg[0] = 0xE0;
1017        cmd.msg[1] = 0x00;
1018        cmd.msg[2] = 0x00;
1019        cmd.msg_len = 3;
1020
1021        debug(200, "DISEQC Reset (%s)", node->feshortname);
1022        fediseqcsendmastercmd(node, &cmd, 100);
1023}
1024
1025void fesdiseqcstandby(struct dvbdev* node)
1026{
1027        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
1028       
1029        if(node == NULL)
1030        {
1031                err("NULL detect");
1032                return;
1033        }
1034       
1035        cmd.msg[0] = 0xE0;
1036        cmd.msg[1] = 0x00;
1037        cmd.msg[2] = 0x02;
1038        cmd.msg_len = 3;
1039
1040        debug(200, "DISEQC Standby (%s)", node->feshortname);
1041        fediseqcsendmastercmd(node, &cmd, 100);
1042}
1043
1044void fediseqcrotor(struct dvbdev* node, struct transponder* tpnode, int pos, int flag)
1045{
1046        int orbitalpos = 0;
1047        fe_sec_voltage_t oldvolt = 0;
1048        fe_sec_tone_mode_t oldtone = 0;
1049        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
1050       
1051        if(node == NULL)
1052        {
1053                err("NULL detect");
1054                return;
1055        }
1056       
1057        fesdiseqcpoweron(node);
1058       
1059        oldvolt = node->feaktvolt;
1060        oldtone = node->feakttone;
1061
1062        if(tpnode == NULL)
1063                orbitalpos = 0;
1064        else
1065                orbitalpos = tpnode->orbitalpos;
1066       
1067        //float speed13V = 1.5; //1.5 Grad pro sec
1068        float speed18V = 1; //2.4 Grad pro sek
1069        float degreesmov, waittime;
1070       
1071        switch(flag)
1072        {
1073                case 0: //stop move
1074                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x60; cmd.msg_len = 3;
1075                        debug(200, "DISEQC Rotorpos stop move (%s)", node->feshortname);
1076                        break;
1077                case 1: //disable limits
1078                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x63; cmd.msg_len = 3;
1079                        debug(200, "DISEQC Rotorpos disable limits (%s)", node->feshortname);
1080                        break;
1081                case 2: //enable limits
1082                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x6A; cmd.msg[3] = 0x00; cmd.msg_len = 4;
1083                        debug(200, "DISEQC Rotorpos enable limits (%s)", node->feshortname);
1084                        break;
1085                case 3: //set east limit
1086                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x66; cmd.msg_len = 3;
1087                        debug(200, "DISEQC Rotorpos set east limit (%s)", node->feshortname);
1088                        break;
1089                case 4: //set west limit
1090                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x67; cmd.msg_len = 3;
1091                        debug(200, "DISEQC Rotorpos set west limit (%s)", node->feshortname);
1092                        break;
1093                case 5: //move east cont.
1094                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x68; cmd.msg[3] = 0x00; cmd.msg_len = 4;
1095                        debug(200, "DISEQC Rotorpos move east cont. (%s)", node->feshortname);
1096                        break;
1097                case 6: //move west cont.
1098                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x69; cmd.msg[3] = 0x00; cmd.msg_len = 4;
1099                        debug(200, "DISEQC Rotorpos move west cont. (%s)", node->feshortname);
1100                        break;
1101                case 7: //store pos
1102                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x6A; cmd.msg[3] = pos; cmd.msg_len = 4;
1103                        debug(200, "DISEQC Rotorpos store pos=%d (%s)", pos, node->feshortname);
1104                        break;
1105                case 8: //goto pos
1106                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x6B; cmd.msg[3] = pos; cmd.msg_len = 4;
1107                        debug(200, "DISEQC Rotorpos goto pos=%d (%s)", pos, node->feshortname);
1108                        break;
1109                case 9: //step xx pos east
1110                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x68; cmd.msg[3] = 256 - pos; cmd.msg_len = 4;
1111                        debug(200, "DISEQC Rotorpos step east pos=%d (%s)", pos, node->feshortname);
1112                        break;
1113                case 10: //step xx pos west
1114                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x69; cmd.msg[3] = 256 - pos; cmd.msg_len = 4;
1115                        debug(200, "DISEQC Rotorpos step west pos=%d (%s)", pos, node->feshortname);
1116                        break;
1117                case 11: //goto xx
1118                        cmd.msg[0] = 0xE0; cmd.msg[1] = 0x31; cmd.msg[2] = 0x6E; cmd.msg[3] = (pos >> 8) & 0xff; cmd.msg[4] = pos & 0xff; cmd.msg_len = 5;
1119                        debug(200, "DISEQC Rotorpos goto xx pos=%d (%s)", pos, node->feshortname);
1120                        break;
1121        }
1122
1123        if(flag >= 0 && flag < 7)
1124        {
1125                fesetvoltage(node, SEC_VOLTAGE_18, 15);
1126                fesettone(node, SEC_TONE_OFF, 15);
1127                fediseqcsendmastercmd(node, &cmd, 100);
1128        }
1129
1130        if((flag == 7 || flag == 9 || flag == 10) && pos != 0)
1131        {
1132                fesetvoltage(node, SEC_VOLTAGE_18, 15);
1133                fesettone(node, SEC_TONE_OFF, 15);
1134                fediseqcsendmastercmd(node, &cmd, 100);
1135        }
1136
1137        if((flag == 8 || flag == 11) && (orbitalpos == 0 || status.rotoroldorbitalpos == 0 || orbitalpos != status.rotoroldorbitalpos))
1138        {
1139                fesetvoltage(node, SEC_VOLTAGE_18, 15);
1140                fesettone(node, SEC_TONE_OFF, 15);
1141                fediseqcsendmastercmd(node, &cmd, 100);
1142
1143                if(status.rotoroldorbitalpos == 0 || orbitalpos == 0)
1144                        waittime = 15;
1145                else
1146                {
1147                        degreesmov = abs(orbitalpos - status.rotoroldorbitalpos) / 10;
1148                        waittime = (int)ceil((float)degreesmov / (float)speed18V);
1149                }
1150
1151                status.rotoroldorbitalpos = orbitalpos;
1152                sleep(waittime);
1153        }
1154       
1155        fesetvoltage(node, oldvolt, 15);
1156        fesettone(node, oldtone, 15);
1157}
1158
1159void fesetunicable(struct dvbdev* node)
1160{
1161        int unicabletune = 0;
1162        char* tmpstr = NULL;
1163        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
1164
1165        if(node == NULL)
1166        {
1167                err("NULL detect");
1168                return;
1169        }
1170
1171        tmpstr = ostrcat(node->feshortname, "_lnb_satcr", 0, 0);
1172        int satcr = getconfigint(tmpstr, node->feaktnr) - 1;
1173        if(satcr < 0) satcr = 0;
1174        free(tmpstr); tmpstr = NULL;
1175
1176        tmpstr = ostrcat(node->feshortname, "_diseqc", 0, 0);
1177        int aktdiseqc = getconfigint(tmpstr, node->feaktnr);
1178        if(aktdiseqc < 1) aktdiseqc = 1;
1179        free(tmpstr); tmpstr = NULL;
1180
1181        unicabletune |= ((satcr & 0x7) << 13);
1182        unicabletune |= (((aktdiseqc - 1) & 0x1) << 12);
1183        unicabletune |= (((!node->feaktpolarization) & 0x1) << 11);
1184        unicabletune |= ((node->feaktband & 0x1) << 10);
1185        unicabletune |= ((node->feloffrequency / 1000) & 0x3ff);
1186
1187        debug(200, "unicabletune %04X", unicabletune);
1188       
1189        if(status.firstunicablewait == 0)
1190        {
1191                status.firstunicablewait = getconfigint("firstunicablewait", NULL);
1192                if(status.firstunicablewait == 0)
1193                        status.firstunicablewait = 1000;
1194        }               
1195       
1196        if(status.firstunicablewait > 0)
1197        {
1198                usleep(status.firstunicablewait * 1000);
1199                status.firstunicablewait = -1;
1200        }
1201       
1202        fesetvoltage(node, SEC_VOLTAGE_13, 15);
1203        fesetvoltage(node, SEC_VOLTAGE_18, 15);
1204        fesettone(node, SEC_TONE_OFF, 15);
1205
1206        //feunicable
1207        //byte1 (bit 7/6/5) -> satcr number
1208        //byte1 (bit 4/3/2) -> lnb number
1209        //byte1 (bit 1/0) -> frequ
1210        //byte0 -> frequ
1211       
1212        cmd.msg[0] = 0xE0;
1213        cmd.msg[1] = 0x10;
1214        cmd.msg[2] = 0x5A;
1215        cmd.msg[3] = (unicabletune >> 8) & 0xff;
1216        cmd.msg[4] = unicabletune & 0xff;
1217        cmd.msg_len = 5;
1218
1219        debug(200, "send diseqc unicable cmd (%s)", node->feshortname);
1220        fediseqcsendmastercmd(node, &cmd, 100);
1221        fesetvoltage(node, SEC_VOLTAGE_13, 15);
1222}
1223
1224void fediseqcset(struct dvbdev* node, struct transponder* tpnode)
1225{
1226        char* tmpstr = NULL;
1227        int toneburst = 0, cmdorder = 0, input = 0, uinput = 0, diseqmode = 0, rotorpos = 0, latpos = 0, longpos = 0;
1228        float latitude = 0, longitude = 0;
1229        fe_sec_mini_cmd_t mini = -1;
1230        struct dvb_diseqc_master_cmd cmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
1231        struct dvb_diseqc_master_cmd ucmd = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 0};
1232       
1233        if(node == NULL) return;
1234       
1235        tmpstr = ostrcat(node->feshortname, "_diseqc_committedcmd", 0, 0);
1236        input = getconfigint(tmpstr, node->feaktnr);
1237        free(tmpstr); tmpstr = NULL;
1238        tmpstr = ostrcat(node->feshortname, "_diseqc_uncommittedcmd", 0, 0);
1239        uinput = getconfigint(tmpstr, node->feaktnr);
1240        free(tmpstr); tmpstr = NULL;
1241        tmpstr = ostrcat(node->feshortname, "_diseqc_mode", 0, 0);
1242        diseqmode = getconfigint(tmpstr, node->feaktnr);
1243        free(tmpstr); tmpstr = NULL;
1244        tmpstr = ostrcat(node->feshortname, "_diseqc_cmdorder", 0, 0);
1245        cmdorder = getconfigint(tmpstr, node->feaktnr);
1246        free(tmpstr); tmpstr = NULL;
1247        tmpstr = ostrcat(node->feshortname, "_diseqc_toneburst", 0, 0);
1248        toneburst = getconfigint(tmpstr, node->feaktnr);
1249        free(tmpstr); tmpstr = NULL;
1250        tmpstr = ostrcat(node->feshortname, "_diseqc_rotorpos", 0, 0);
1251        rotorpos = getconfigint(tmpstr, node->feaktnr);
1252        free(tmpstr); tmpstr = NULL;
1253       
1254        latitude = getconfigfloat("latitude", NULL);
1255        longitude = getconfigfloat("longitude", NULL);
1256        latpos = getconfigint("latpos", NULL);
1257        longpos = getconfigint("longpos", NULL);
1258
1259        tmpstr = ostrcat(node->feshortname, "_diseqc", 0, 0);
1260        int aktdiseqc = getconfigint(tmpstr, node->feaktnr);
1261        if(aktdiseqc < 1) aktdiseqc = 1;
1262        free(tmpstr); tmpstr = NULL;
1263
1264        debug(200, "set diseqc: number=%d, band=%d, pol=%d, diseqmode=%d, input=%d, uinput=%d, cmdorder=%d, toneburst=%d (%s)", aktdiseqc, node->feaktband, node->feaktpolarization, diseqmode, input, uinput, cmdorder, toneburst, node->feshortname);
1265         
1266        switch(toneburst)
1267        {
1268                case 1: mini = SEC_MINI_A; break;
1269                case 2: mini = SEC_MINI_B; break;
1270        }
1271       
1272        if(diseqmode == 100) // Tonburst A/B
1273        {
1274                debug(200, "set diseqc: Tonburst A/B (%s)", node->feshortname);
1275                if(mini == -1)
1276                        mini = (aktdiseqc - 1) % 2 ? SEC_MINI_B : SEC_MINI_A;
1277                fediseqcsendburst(node, mini, 15);
1278                return;
1279        }
1280               
1281        if(diseqmode == 0 || diseqmode == 1) // Diseqc 1.0 + 1.1
1282        {
1283                debug(200, "set committed switch (%s)", node->feshortname);
1284                fesdiseqcpoweron(node);
1285                cmd.msg[0] = 0xE0;
1286                cmd.msg[1] = 0x10;
1287                cmd.msg[2] = 0x38;
1288
1289                if(input == 0)
1290                        cmd.msg[3] = 0xF0 | ((((aktdiseqc - 1) * 4) & 0x0F) | (node->feaktband ? 1 : 0) | (node->feaktpolarization ? 0 : 2));
1291                else
1292                        cmd.msg[3] = 0xF0 + ((input - 1) & 0x0F);
1293
1294                cmd.msg_len = 4;
1295        }
1296
1297        if(diseqmode == 1) // Diseqc 1.1
1298        {
1299                if(uinput > 0)
1300                {
1301                        debug(200, "set uncommitted switch (%s)", node->feshortname);
1302                        fesdiseqcpoweron(node);
1303                        ucmd.msg[0] = 0xE0;
1304                        ucmd.msg[1] = 0x10;
1305                        ucmd.msg[2] = 0x39;
1306                        ucmd.msg[3] = 0xF0 + ((uinput - 1) & 0x0F);
1307                        ucmd.msg_len = 4;
1308                }
1309        }
1310                 
1311        switch(cmdorder)
1312        {
1313                case 1:
1314                        if(mini != -1) fediseqcsendburst(node, mini, 15);
1315                        fediseqcsendmastercmd(node, &cmd, 100);
1316                        break;
1317                case 2:
1318                        fediseqcsendmastercmd(node, &cmd, 100);
1319                        if(uinput > 0) fediseqcsendmastercmd(node, &ucmd, 100);
1320                        if(mini != -1) fediseqcsendburst(node, mini, 15);
1321                        break;
1322                case 3:
1323                        if(mini != -1) fediseqcsendburst(node, mini, 15);
1324                        fediseqcsendmastercmd(node, &cmd, 100);
1325                        if(uinput > 0) fediseqcsendmastercmd(node, &ucmd, 100);
1326                        break;
1327                case 4:
1328                        if(uinput > 0) fediseqcsendmastercmd(node, &ucmd, 100);
1329                        fediseqcsendmastercmd(node, &cmd, 100);
1330                        if(mini != -1) fediseqcsendburst(node, mini, 15);
1331                        break;
1332                case 5:
1333                        if(mini != -1) fediseqcsendburst(node, mini, 15);
1334                        if(uinput > 0) fediseqcsendmastercmd(node, &ucmd, 100);
1335                        fediseqcsendmastercmd(node, &cmd, 100);
1336                        break;
1337                default:
1338                        fediseqcsendmastercmd(node, &cmd, 100);
1339                        if(mini != -1) fediseqcsendburst(node, mini, 15);
1340                        break;
1341        }
1342       
1343        if(diseqmode == 2) // Diseqc 1.2
1344        {
1345                fediseqcrotor(node, tpnode, rotorpos, 8);
1346        }
1347       
1348        if(diseqmode == 3) // Diseqc 1.3 (USALS)
1349        {
1350                double orbitalpos = tpnode->orbitalpos / 10.00;
1351
1352                if(latpos == 1) // south
1353                        latitude = -latitude;
1354
1355                if(longpos == 1) // west
1356                        longitude = 360 - longitude;
1357
1358                double satHourAngle = calcSatHourangle(orbitalpos, latitude, longitude);
1359                int gotoXTable[10] = {0x00, 0x02, 0x03, 0x05, 0x06, 0x08, 0x0A, 0x0B, 0x0D, 0x0E};
1360
1361                if(latitude >= 0) // Northern Hemisphere
1362                {
1363                        int tmp = (int)round(fabs(180 - satHourAngle) * 10.0);
1364                        rotorpos = (tmp / 10) * 0x10 + gotoXTable[tmp % 10];
1365
1366                        if(satHourAngle < 180) // the east
1367                                rotorpos |= 0xE000;
1368                        else // west
1369                                rotorpos |= 0xD000;
1370                }
1371                else // Southern Hemisphere
1372                {
1373                        if(satHourAngle < 180) // the east
1374                        {
1375                                int tmp = (int)round(fabs(satHourAngle) * 10.0);
1376                                rotorpos = (tmp / 10) * 0x10 + gotoXTable[tmp % 10];
1377                                rotorpos |= 0xD000;
1378                        }
1379                        else // west
1380                        {
1381                                int tmp = (int)round(fabs(360 - satHourAngle) * 10.0);
1382                                rotorpos = (tmp / 10) * 0x10 + gotoXTable[tmp % 10];
1383                                rotorpos |= 0xE000;
1384                        }
1385                }
1386                debug(200, "orbitalpos=%f, latitude=%f, longitude=%f, rotorpos=%04x", orbitalpos, latitude, longitude, rotorpos);
1387
1388                fediseqcrotor(node, tpnode, rotorpos, 11);
1389        }
1390}
1391
1392void feset(struct dvbdev* node, struct transponder* tpnode)
1393{
1394        int voltagemode = 0, tonemode = 0;
1395        fe_sec_tone_mode_t tone;
1396        fe_sec_voltage_t volt;
1397        struct dvbdev* dvbnode = dvbdev;
1398        char* tmpstr = NULL;
1399
1400        if(node == NULL)
1401        {
1402                err("NULL detect");
1403                return;
1404        }
1405
1406        // set volage off from other unused frontend
1407        while(dvbnode != NULL)
1408        {
1409                if(dvbnode->type != FRONTENDDEV) break;
1410                if(dvbnode->type == FRONTENDDEV && dvbnode != node && dvbnode->felock == 0 && dvbnode != status.aktservice->fedev)
1411                {
1412                        fesetvoltage(dvbnode, SEC_VOLTAGE_OFF, 0);
1413                }
1414                dvbnode = dvbnode->next;
1415        }
1416
1417        calclof(node, tpnode, NULL, 0);
1418
1419        tmpstr = ostrcat(node->feshortname, "lnb_voltagemode", 0, 0);
1420        voltagemode = getconfigint(tmpstr, node->feaktnr);
1421        free(tmpstr); tmpstr = NULL;
1422        switch(voltagemode)
1423        {
1424                case 1: volt = SEC_VOLTAGE_13; break;
1425                case 2: volt = SEC_VOLTAGE_18; break;
1426                default: volt = node->feaktpolarization ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18;
1427                         if(node->feunicable == 1) volt = SEC_VOLTAGE_13;
1428        }
1429        fesetvoltage(node, volt, 15);
1430
1431        tmpstr = ostrcat(node->feshortname, "_diseqc", 0, 0);
1432        if(getconfigint(tmpstr, node->feaktnr) == 0 || node->feunicable == 1)
1433        {
1434                debug(200, "don't use diseqc");
1435        }
1436        else
1437        {
1438                fesettone(node, SEC_TONE_OFF, 15);
1439                fediseqcset(node, tpnode);
1440        }
1441        free(tmpstr); tmpstr = NULL;
1442
1443        tmpstr = ostrcat(node->feshortname, "_lnb_tonemode", 0, 0);
1444        tonemode = getconfigint(tmpstr, node->feaktnr);
1445        free(tmpstr); tmpstr = NULL;
1446        switch(tonemode)
1447        {
1448                case 1: tone = SEC_TONE_ON; break;
1449                case 2: tone = SEC_TONE_OFF; break;
1450                default: tone = node->feaktband ? SEC_TONE_ON : SEC_TONE_OFF;
1451                         if(node->feunicable == 1) tone = SEC_TONE_OFF;
1452        }
1453        fesettone(node, tone, 15);
1454}
1455
1456void fediscard(struct dvbdev* node)
1457{
1458        struct dvb_frontend_event ev;
1459        int count = 0;
1460
1461        if(node == NULL)
1462        {
1463                err("NULL detect");
1464                return;
1465        }
1466
1467        /* discard stale QPSK events */
1468        while(count < 20)
1469        {
1470                count++;
1471                if(ioctl(node->fd, FE_GET_EVENT, &ev) == -1)
1472                        break;
1473        }
1474}
1475
1476uint16_t fereadsnr(struct dvbdev* node)
1477{
1478        uint16_t snr = 0;
1479        if(node == NULL)
1480        {
1481                err("NULL detect");
1482                return 0;
1483        }
1484        int signalquality = 0;
1485        int signalqualitydb = 0;
1486//#ifdef ARM
1487#ifdef MIPSEL
1488//#if DVB_API_VERSION >= 5
1489#if DVB_API_VERSION > 5 || DVB_API_VERSION == 5 && DVB_API_VERSION_MINOR >= 10
1490
1491        int test1 = 0;
1492        int test2 = 0;
1493        struct dtv_property prop[1];
1494        memset(prop, 0, sizeof(prop));
1495        prop[0].cmd = DTV_STAT_CNR;
1496        struct dtv_properties props;
1497        props.props = prop;
1498        props.num = 1;
1499       
1500        int wasopen = 0;
1501       
1502        if(node->fd == -1)
1503                node->fd = feopen(node, NULL);
1504        else
1505                wasopen = 1;
1506               
1507        if(ioctl(node->fd, FE_GET_PROPERTY,  &props) < 0 && errno != ERANGE)
1508        {
1509                perr("FE_GET_PROPERTY");
1510        }
1511        else
1512        {
1513                for(unsigned int i=0; i<prop[0].u.st.len; i++)
1514                {
1515                        if (prop[0].u.st.stat[i].scale == FE_SCALE_DECIBEL && test1 == 0)
1516                        {
1517                                test1 = 1;
1518                                signalqualitydb = prop[0].u.st.stat[i].svalue / 10;
1519                                printf("***** new snr signalqualitydb:%d\n", signalqualitydb);
1520                        }
1521                        else if (prop[0].u.st.stat[i].scale == FE_SCALE_RELATIVE && test2 == 0)
1522                        {
1523                                test2 = 1;
1524                                signalquality = prop[0].u.st.stat[i].svalue;
1525                                printf("***** new snr signalquality:%d\n", signalquality);
1526                        }
1527                }
1528        }
1529        if(wasopen != 1)
1530                feclose(node, -1);
1531#endif
1532        if(!signalquality && !signalqualitydb)
1533        {
1534                int ret = 0x12345678;
1535                int sat_max = 1600; // we assume a max of 16db here
1536                int ter_max = 2900; // we assume a max of 29db here
1537                int cab_max = 4200; // we assume a max of 42db here
1538                //int atsc_max = 4200; // we assume a max of 42db here
1539               
1540                ioctl(node->fd, FE_READ_SNR, &snr);
1541               
1542                printf("***** old snr signalquality\n");               
1543               
1544                if(ostrstr(node->feinfo->name, "Si2166B") != NULL)
1545                {
1546                        ret = (snr * 240) >> 8;
1547                }
1548                else if (ostrstr(node->feinfo->name, "ATBM781x") != NULL)
1549                {
1550                        ret = snr*10;
1551                }
1552                else if(ostrstr(node->feinfo->name, "BCM4506") != NULL || ostrstr(node->feinfo->name, "BCM4506 (internal)") != NULL || ostrstr(node->feinfo->name, "BCM4505") != NULL || ostrstr(node->feinfo->name, "BCM73625 (G3)") != NULL || ostrstr(node->feinfo->name, "BCM45208") != NULL)
1553                {
1554                        ret = (snr * 100) >> 8;
1555                }
1556                else if (ostrstr(node->feinfo->name, "Si216") != NULL) // all new Models with SI Tuners
1557                {
1558                        ret = snr;
1559                }
1560                signalqualitydb = ret;
1561                if (ret == 0x12345678) // no snr db calculation avail.. return untouched snr value..
1562                {
1563                        signalquality = snr;
1564                }
1565                else
1566                {
1567                        if(node->feinfo->type == FE_QPSK)
1568                                signalquality = (ret >= sat_max ? 65536 : ret * 65536 / sat_max);
1569                        else if(node->feinfo->type == FE_QAM)
1570                                signalquality = (ret >= cab_max ? 65536 : ret * 65536 / cab_max);
1571                        else if(node->feinfo->type == FE_OFDM)
1572                                signalquality = (ret >= ter_max ? 65536 : ret * 65536 / ter_max);
1573                }
1574        }
1575        debug(200, "frontend snr = %02x", signalquality );
1576        return signalquality;
1577#else
1578        ioctl(node->fd, FE_READ_SNR, &snr);
1579        debug(200, "frontend snr = %02x", (snr * 100) / 0xffff);
1580        return snr;
1581#endif
1582}
1583
1584uint16_t fereadsignalstrength(struct dvbdev* node)
1585{
1586        uint16_t signal = 0;
1587
1588        if(node == NULL)
1589        {
1590                err("NULL detect");
1591                return 0;
1592        }
1593//#ifdef ARM
1594//#ifdef MIPSEL
1595#if DVB_API_VERSION > 5 || DVB_API_VERSION == 5 && DVB_API_VERSION_MINOR >= 10
1596        struct dtv_property prop[1];
1597        memset(prop, 0, sizeof(prop));
1598        prop[0].cmd = DTV_STAT_SIGNAL_STRENGTH;
1599        struct dtv_properties props;
1600        props.props = prop;
1601        props.num = 1;
1602       
1603        int wasopen = 0;
1604       
1605        if(node->fd == -1)
1606                node->fd = feopen(node, NULL);
1607        else
1608                wasopen = 1;
1609       
1610        if (ioctl(node->fd, FE_GET_PROPERTY, &props) < 0 && errno != ERANGE)
1611        {
1612                debug(200, "DTV_STAT_SIGNAL_STRENGTH failed");
1613        }
1614        else
1615        {
1616                for(unsigned int i=0; i<prop[0].u.st.len; i++)
1617                {
1618                        if (prop[0].u.st.stat[i].scale == FE_SCALE_RELATIVE)
1619                                signal = prop[0].u.st.stat[i].uvalue;
1620                }
1621        }
1622        if (signal)
1623        {
1624                if(wasopen != 1)
1625                        feclose(node, -1);
1626                return signal;
1627        }
1628        // fallback to old DVB API
1629//#endif
1630#endif 
1631        if(ioctl(node->fd, FE_READ_SIGNAL_STRENGTH, &signal) < 0 && errno != ERANGE)
1632        {
1633                debug(200, "FE_READ_SIGNAL_STRENGTH failed");
1634        }
1635        else
1636        {
1637                if(ostrstr(node->feinfo->name, "Si2166B") != NULL || ostrstr(node->feinfo->name, "BCM45208") != NULL)
1638                        signal = signal * 1000;
1639                debug(200, "frontend signal = %02x", (signal * 100) / 0xffff);
1640        }
1641        if(signal == 0)
1642        {
1643                fe_status_t status = fereadstatus(node);
1644                if(status & FE_HAS_LOCK) signal = 1;
1645        }       
1646        return signal;
1647}
1648
1649uint32_t fereadber(struct dvbdev* node)
1650{
1651        uint32_t ber = 0;
1652
1653        if(node == NULL)
1654        {
1655                err("NULL detect");
1656                return 0;
1657        }
1658
1659        ioctl(node->fd, FE_READ_BER, &ber);
1660        debug(200, "frontend ber = %02x", ber);
1661        return ber;
1662}
1663
1664uint32_t fereaduncorrectedblocks(struct dvbdev* node)
1665{
1666        uint32_t unc = 0;
1667
1668        if(node == NULL)
1669        {
1670                err("NULL detect");
1671                return 0;
1672        }
1673
1674        ioctl(node->fd, FE_READ_UNCORRECTED_BLOCKS, &unc);
1675        debug(200, "frontend unc = %02x", unc);
1676        return unc;
1677}
1678
1679fe_status_t fereadstatus(struct dvbdev* node)
1680{
1681        fe_status_t status;
1682
1683        if(node == NULL)
1684        {
1685                err("NULL detect");
1686                return -1;
1687        }
1688
1689        if(ioctl(node->fd, FE_READ_STATUS, &status) == -1)
1690                perr("FE_READ_STATUS");
1691
1692        debug(200, "frontend status = %02x", status);
1693        if(status & FE_HAS_LOCK) debug(200, "frontend = FE_HAS_LOCK");
1694        if(status & FE_HAS_SIGNAL) debug(200, "frontend = FE_HAS_SIGNAL");
1695        if(status & FE_HAS_CARRIER) debug(200, "frontend = FE_HAS_CARRIER");
1696        if(status & FE_HAS_VITERBI) debug(200, "frontend = FE_HAS_VITERBI");
1697        if(status & FE_HAS_SYNC) debug(200, "frontend = FE_HAS_SYNC");
1698        if(status & FE_TIMEDOUT) debug(200, "frontend = FE_TIMEDOUT");
1699        if(status & FE_REINIT) debug(200, "frontend = FE_REINIT");
1700
1701        return status;
1702}
1703
1704int fetunedvbs(struct dvbdev* node, struct transponder* tpnode)
1705{
1706        if(node == NULL || tpnode == NULL)
1707        {
1708                err("NULL detect");
1709                return 1;
1710        }
1711       
1712        if(node->feunicable == 1)
1713        {
1714                fesetunicable(node);
1715                char* tmpstr = ostrcat(node->feshortname, "_lnb_satcrfrequ", 0, 0);
1716                node->feloffrequency = getconfigint(tmpstr, node->feaktnr) * 1000;
1717                free(tmpstr); tmpstr = NULL;
1718        }
1719
1720#if DVB_API_VERSION >= 5
1721        struct dtv_property p[10];
1722        struct dtv_properties cmdseq;
1723        cmdseq.props = p;
1724
1725        //convert transponderlist for dvbapi5
1726        int system = tpnode->system;
1727        switch(system)
1728        {
1729                case 0: system = SYS_DVBS; break;
1730                case 1: system = SYS_DVBS2; break;
1731                default: system = SYS_DVBS; break;
1732        }
1733
1734        int fec = tpnode->fec;
1735        switch(fec)
1736        {
1737                case 0: fec = FEC_AUTO; break;
1738                case 1: fec = FEC_1_2; break;
1739                case 2: fec = FEC_2_3; break;
1740                case 3: fec = FEC_3_4; break;
1741                case 4: fec = FEC_5_6; break;
1742                case 5: fec = FEC_7_8; break;
1743                case 6: fec = FEC_8_9; break;
1744                case 7: fec = FEC_3_5; break;
1745                case 8: fec = FEC_4_5; break;
1746                case 9: fec = FEC_9_10; break;
1747                case 15: fec = FEC_NONE; break;
1748                default: fec = FEC_AUTO; break;
1749        }
1750        int pilot = tpnode->pilot;
1751        switch(pilot)
1752        {
1753                case 0: pilot = PILOT_OFF; break;
1754                case 1: pilot = PILOT_ON; break;
1755                case 2: pilot = PILOT_AUTO; break;
1756                default: pilot = PILOT_AUTO; break;
1757        }
1758        int rolloff = tpnode->rolloff;
1759        switch(rolloff)
1760        {
1761                case 0: rolloff = ROLLOFF_35; break;
1762                case 1: rolloff = ROLLOFF_25; break;
1763                case 2: rolloff = ROLLOFF_20; break;
1764                default: rolloff = ROLLOFF_35; break;
1765        }
1766
1767        int modulation = tpnode->modulation;
1768        switch(modulation)
1769        {
1770                case 0: modulation = QPSK; break;
1771                case 1: modulation = QPSK; break;
1772                case 2: modulation = PSK_8; break;
1773                case 3: modulation = QAM_16; break;
1774                default: modulation = QPSK; break;
1775        }
1776
1777        p[0].cmd = DTV_CLEAR;
1778        p[1].cmd = DTV_DELIVERY_SYSTEM, p[1].u.data = system;
1779        p[2].cmd = DTV_FREQUENCY,       p[2].u.data = node->feloffrequency;
1780        p[3].cmd = DTV_MODULATION,      p[3].u.data = modulation;
1781        p[4].cmd = DTV_SYMBOL_RATE,     p[4].u.data = tpnode->symbolrate;
1782        p[5].cmd = DTV_INNER_FEC,       p[5].u.data = fec;
1783        p[6].cmd = DTV_INVERSION,       p[6].u.data = (fe_spectral_inversion_t) tpnode->inversion;
1784        if(system == SYS_DVBS2)
1785        {
1786                p[7].cmd = DTV_ROLLOFF,         p[7].u.data = rolloff;
1787                p[8].cmd = DTV_PILOT,           p[8].u.data = pilot;
1788                p[9].cmd = DTV_TUNE;
1789                cmdseq.num = 10;
1790        }
1791        else
1792        {
1793                p[7].cmd = DTV_TUNE;
1794                cmdseq.num = 8;
1795        }
1796
1797        debug(200, "new dvbapi: frequ=%d, inversion=%d, pilot=%d, rolloff=%d, fec=%d, sr=%d, modulation=%d, system=%d (%s)", node->feloffrequency, tpnode->inversion, pilot, rolloff, fec, tpnode->symbolrate, modulation, system, node->feshortname);
1798#else
1799        struct dvb_frontend_parameters tuneto;
1800        fe_spectral_inversion_t inversion = tpnode->inversion;
1801
1802        //convert transponderlist for dvbapi3
1803        int fec = tpnode->fec;
1804        if(tpnode->system == 1)
1805        {
1806                if(tpnode->modulation == 1) fec = fec + 9;
1807                if(tpnode->modulation == 2) fec = fec + 18;
1808        }
1809
1810        inversion |= (tpnode->rolloff << 2) | inversion; // use bit 2..3 of inversion for rolloff
1811        inversion |= (tpnode->pilot << 4) | inversion; // use bit 4..5 of inversion for pilot
1812
1813        tuneto.frequency = node->feloffrequency;
1814        tuneto.inversion = inversion;
1815        tuneto.u.qpsk.symbol_rate = tpnode->symbolrate;
1816        tuneto.u.qpsk.fec_inner = fec;
1817
1818        debug(200, "old dvbapi: frequ=%d, inversion=%d, pilot=%d, rolloff=%d, fec=%d, sr=%d modulation=%d, system=%d (%s)", node->feloffrequency, inversion, tpnode->pilot, tpnode->rolloff, fec, tpnode->symbolrate, tpnode->modulation, tpnode->system, node->feshortname);
1819#endif
1820
1821        fediscard(node);
1822
1823#if DVB_API_VERSION >= 5
1824        if((ioctl(node->fd, FE_SET_PROPERTY, &cmdseq)) == -1)
1825        {
1826                perr("FE_SET_PROPERTY");
1827                return 1;
1828        }
1829#else
1830        if(ioctl(node->fd, FE_SET_FRONTEND, &tuneto) == -1)
1831        {
1832                perr("FE_SET_FRONTEND");
1833                return 1;
1834        }
1835#endif
1836
1837        return 0;
1838}
1839
1840int fetunedvbc(struct dvbdev* node, struct transponder* tpnode)
1841{
1842        if(node == NULL || tpnode == NULL)
1843        {
1844                err("NULL detect");
1845                return 1;
1846        }
1847       
1848        int fec = tpnode->fec;
1849        switch(fec)
1850        {
1851                case 0: fec = FEC_AUTO; break;
1852                case 1: fec = FEC_1_2; break;
1853                case 2: fec = FEC_2_3; break;
1854                case 3: fec = FEC_3_4; break;
1855                case 4: fec = FEC_5_6; break;
1856                case 5: fec = FEC_7_8; break;
1857                case 6: fec = FEC_8_9; break;
1858                case 7: fec = FEC_3_5; break;
1859                case 8: fec = FEC_4_5; break;
1860                case 9: fec = FEC_9_10; break;
1861                case 15: fec = FEC_NONE; break;
1862                default: fec = FEC_AUTO; break;
1863        }
1864
1865        int modulation = tpnode->modulation;
1866        switch(modulation)
1867        {
1868                case 0: modulation = QAM_AUTO; break;
1869                case 1: modulation = QAM_16; break;
1870                case 2: modulation = QAM_32; break;
1871                case 3: modulation = QAM_64; break;
1872                case 4: modulation = QAM_128; break;
1873                case 5: modulation = QAM_256; break;
1874                default: modulation = QAM_AUTO; break;
1875        }
1876
1877#if DVB_API_VERSION >= 5
1878        struct dtv_property p[8];
1879        struct dtv_properties cmdseq;
1880        cmdseq.props = p;
1881       
1882        int system = tpnode->system;
1883       
1884#if DREAMBOX
1885        switch(system)
1886        {
1887                //case 0: system = SYS_DVBC_ANNEX_A; break;
1888                //case 1: system = SYS_DVBC_ANNEX_C; break;
1889                //default: system = SYS_DVBC_ANNEX_A; break;
1890                case 0: system = 1; break;
1891                case 1: system = 18; break;
1892                default: system = 1; break;
1893        }
1894#endif
1895        p[0].cmd = DTV_CLEAR;
1896        p[1].cmd = DTV_DELIVERY_SYSTEM, p[1].u.data = system;
1897        p[2].cmd = DTV_FREQUENCY,       p[2].u.data = tpnode->frequency;
1898        p[3].cmd = DTV_MODULATION,      p[3].u.data = modulation;
1899        p[4].cmd = DTV_SYMBOL_RATE,     p[4].u.data = tpnode->symbolrate;
1900        p[5].cmd = DTV_INVERSION,       p[5].u.data = (fe_spectral_inversion_t) tpnode->inversion;
1901        p[6].cmd = DTV_INNER_FEC,       p[6].u.data = fec;
1902        p[7].cmd = DTV_TUNE;
1903        cmdseq.num = 8;
1904
1905        debug(200, "new dvbapi: frequ=%d, inversion=%d, fec=%d, sr=%d, modulation=%d, system=%d (%s)", tpnode->frequency, tpnode->inversion, fec, tpnode->symbolrate, modulation, tpnode->system, node->feshortname);
1906#else
1907        struct dvb_frontend_parameters tuneto;
1908        tuneto.frequency = tpnode->frequency;
1909        tuneto.inversion = tpnode->inversion;
1910        tuneto.u.qam.symbol_rate = tpnode->symbolrate;
1911        tuneto.u.qam.fec_inner = tpnode->fec;
1912        tuneto.u.qam.modulation = tpnode->modulation;
1913
1914        debug(200, "old dvbapi: frequ=%d, inversion=%d, fec=%d, sr=%d, modulation=%d (%s)", tpnode->frequency, tpnode->inversion, fec, tpnode->symbolrate, modulation, node->feshortname);
1915#endif
1916
1917        fediscard(node);
1918
1919#if DVB_API_VERSION >= 5
1920        if((ioctl(node->fd, FE_SET_PROPERTY, &cmdseq)) == -1)
1921        {
1922                perr("FE_SET_PROPERTY");
1923                return 1;
1924        }
1925#else
1926        if(ioctl(node->fd, FE_SET_FRONTEND, &tuneto) == -1)
1927        {
1928                perr("FE_SET_FRONTEND");
1929                return 1;
1930        }
1931#endif
1932
1933        return 0;
1934}
1935
1936int fetunedvbt(struct dvbdev* node, struct transponder* tpnode)
1937{
1938        if(node == NULL || tpnode == NULL)
1939        {
1940                err("NULL detect");
1941                return 1;
1942        }
1943        debug(200, "transponder:frequ=%d, inversion=%d, bandwidth=%d, hp=%d, lp=%d, modulation=%d transmission=%d guardinterval=%d hierarchy=%d system=%d (%s)", tpnode->frequency, tpnode->inversion, tpnode->symbolrate, tpnode->fec, tpnode->polarization, tpnode->modulation, tpnode->pilot, tpnode->rolloff, tpnode->system, tpnode->system, node->feshortname);
1944       
1945        fe_delivery_system_t system = SYS_DVBT;
1946       
1947        int hp = tpnode->fec; //fec = hp on DVBT
1948        switch(hp)
1949        {
1950                case T_FEC_1_2: hp = FEC_1_2; break;
1951                case T_FEC_2_3: hp = FEC_2_3; break;
1952                case T_FEC_3_4: hp = FEC_3_4; break;
1953                case T_FEC_5_6: hp = FEC_5_6; break;
1954                case T_FEC_6_7: hp = FEC_6_7; break;   
1955                case T_FEC_7_8: hp = FEC_7_8; break;
1956                case T_FEC_8_9: hp = FEC_8_9; break;
1957                default: hp = FEC_AUTO; break;
1958        }
1959
1960        int lp = tpnode->polarization; //polarization = lp on DVBT
1961        switch(lp)
1962        {
1963                case T_FEC_1_2: lp = FEC_1_2; break;
1964                case T_FEC_2_3: lp = FEC_2_3; break;
1965                case T_FEC_3_4: lp = FEC_3_4; break;
1966                case T_FEC_5_6: lp = FEC_5_6; break;
1967                case T_FEC_6_7: lp = FEC_6_7; break;   
1968                case T_FEC_7_8: lp = FEC_7_8; break;
1969                case T_FEC_8_9: lp = FEC_8_9; break;
1970                default: lp = FEC_AUTO; break;
1971        }
1972
1973        int modulation = tpnode->modulation;
1974        switch(modulation)
1975        {
1976                case T_Modulation_QPSK: modulation = QPSK; break;
1977                case T_Modulation_QAM16: modulation = QAM_16; break;
1978                case T_Modulation_QAM64: modulation = QAM_64; break;
1979                case T_Modulation_QAM256: modulation = QAM_256; break;
1980                default: modulation = QAM_AUTO; break;
1981        }
1982
1983        int bandwidth = tpnode->symbolrate; //symbolrate = bandwidth on DVBT
1984        switch(bandwidth)
1985        {
1986                case T_Bandwidth_8MHz: bandwidth = 8000000; break;
1987                case T_Bandwidth_7MHz: bandwidth = 7000000; break;
1988                case T_Bandwidth_6MHz: bandwidth = 6000000; break;
1989                case T_Bandwidth_5MHz: bandwidth = 5000000; break;
1990                case T_Bandwidth_1_712MHz: bandwidth = 1712000; break;
1991                case T_Bandwidth_10MHz: bandwidth = 10000000; break;   
1992                case T_Bandwidth_Auto: bandwidth = 0; break;
1993                default: bandwidth = 0; break;
1994        }
1995       
1996        int transmission = tpnode->pilot; //pilot = transmission on DVBT
1997        switch(transmission)
1998        {
1999                case T_TransmissionMode_2k: transmission = TRANSMISSION_MODE_2K; break;
2000                case T_TransmissionMode_4k: transmission = TRANSMISSION_MODE_4K; break;
2001                case T_TransmissionMode_8k: transmission = TRANSMISSION_MODE_8K; break;
2002                case T_TransmissionMode_Auto: transmission = TRANSMISSION_MODE_AUTO; break;
2003#if defined TRANSMISSION_MODE_1K
2004                case T_TransmissionMode_1k: transmission = TRANSMISSION_MODE_1K; break;
2005                case T_TransmissionMode_16k: transmission = TRANSMISSION_MODE_16K; break;
2006                case T_TransmissionMode_32k: transmission = TRANSMISSION_MODE_32K; break;
2007#endif
2008                default: transmission = TRANSMISSION_MODE_AUTO; break;
2009        }
2010
2011        int guardinterval = tpnode->rolloff; //rolloff = guardinterval on DVBT
2012        switch(guardinterval)
2013        {
2014                case T_GuardInterval_1_32: guardinterval = GUARD_INTERVAL_1_32; break;
2015                case T_GuardInterval_1_16: guardinterval = GUARD_INTERVAL_1_16; break;
2016                case T_GuardInterval_1_8: guardinterval = GUARD_INTERVAL_1_8; break;
2017                case T_GuardInterval_1_4: guardinterval = GUARD_INTERVAL_1_4; break;
2018                case T_GuardInterval_Auto: guardinterval = GUARD_INTERVAL_AUTO; break;
2019#if defined GUARD_INTERVAL_1_128
2020                case T_GuardInterval_1_128: guardinterval = GUARD_INTERVAL_1_128; break;
2021                case T_GuardInterval_19_128: guardinterval = GUARD_INTERVAL_19_128; break;
2022                case T_GuardInterval_19_256: guardinterval = GUARD_INTERVAL_19_256; break;
2023#endif
2024                default: guardinterval = GUARD_INTERVAL_AUTO; break;
2025        }
2026       
2027        int hierarchy = tpnode->system; //system = hierarchy on DVBT
2028        if(tpnode->system == System_DVB_T2) //system = DVB-T2 then hierarchy = HIERARCHY_AUTO
2029                hierarchy = T_Hierarchy_Auto;
2030       
2031        switch(hierarchy)
2032        {
2033                case T_Hierarchy_None: hierarchy = HIERARCHY_NONE;
2034                case T_Hierarchy_1: hierarchy = HIERARCHY_1;
2035                case T_Hierarchy_2: hierarchy = HIERARCHY_2;
2036                case T_Hierarchy_4: hierarchy = HIERARCHY_4;
2037                case T_Hierarchy_Auto: hierarchy = HIERARCHY_AUTO;
2038                default: hierarchy = HIERARCHY_AUTO; break;
2039        }
2040       
2041        int inversion = tpnode->inversion;
2042        switch(inversion)
2043        {
2044                case T_Inversion_Off: inversion = INVERSION_OFF;
2045                case T_Inversion_ON: inversion = INVERSION_ON;
2046                default: inversion = INVERSION_AUTO; break;
2047        }
2048
2049        int ret = 0;
2050#ifndef ARM
2051        fediscard(node);
2052#endif
2053
2054#if DVB_API_VERSION >= 5
2055        struct dtv_property p[12];
2056        struct dtv_properties cmdseq;
2057        cmdseq.props = p;
2058
2059// suchlauf geht an nemesis mit system=0
2060#if DREAMBOX
2061        switch(system)
2062        {
2063                case System_DVB_T: system = SYS_DVBT; break; //3
2064                case System_DVB_T2: system = SYS_DVBT2; break; //16
2065                default: system = SYS_DVBT; break;
2066        }
2067#else
2068        switch(tpnode->system)
2069        {
2070                default:
2071                case System_DVB_T: system = SYS_DVBT; break; //3
2072                case System_DVB_T2: system = SYS_DVBT2; break; //16
2073        }
2074#endif
2075
2076        p[0].cmd = DTV_CLEAR;
2077        p[1].cmd = DTV_DELIVERY_SYSTEM, p[1].u.data = system;
2078        p[2].cmd = DTV_FREQUENCY,       p[2].u.data = tpnode->frequency;
2079        p[3].cmd = DTV_INVERSION,       p[3].u.data = (fe_spectral_inversion_t) inversion;
2080        p[4].cmd = DTV_BANDWIDTH_HZ, p[4].u.data = bandwidth;
2081        p[5].cmd = DTV_CODE_RATE_LP, p[5].u.data = (fe_code_rate_t) lp;
2082        p[6].cmd = DTV_CODE_RATE_HP, p[6].u.data = (fe_code_rate_t) hp;
2083        p[7].cmd = DTV_MODULATION, p[7].u.data = (fe_modulation_t) modulation;
2084        p[8].cmd = DTV_TRANSMISSION_MODE,       p[8].u.data = (fe_transmit_mode_t) transmission;
2085        p[9].cmd = DTV_GUARD_INTERVAL, p[9].u.data = (fe_guard_interval_t) guardinterval;
2086        p[10].cmd = DTV_HIERARCHY, p[10].u.data = (fe_hierarchy_t) hierarchy;
2087        p[11].cmd = DTV_TUNE;
2088        cmdseq.num = 12;
2089       
2090        if((ioctl(node->fd, FE_SET_PROPERTY, &cmdseq)) == -1)
2091        {
2092                perr("FE_SET_PROPERTY");
2093                ret = 1;
2094        }
2095
2096        debug(200, "new dvbapi 1: frequ=%d, inversion=%d, bandwidth=%d, hp=%d, lp=%d, modulation=%d transmission=%d guardinterval=%d hierarchy=%d system=%d (%s)", tpnode->frequency, tpnode->inversion, bandwidth, hp, lp, modulation, transmission, guardinterval, hierarchy, system, node->feshortname);
2097
2098#else
2099        struct dvb_frontend_parameters tuneto;
2100
2101        tuneto.frequency = tpnode->frequency;
2102        tuneto.inversion = tpnode->inversion;
2103        tuneto.u.ofdm.bandwidth = bandwidth;
2104        tuneto.u.ofdm.code_rate_HP = hp;
2105        tuneto.u.ofdm.code_rate_LP = lp;
2106        tuneto.u.ofdm.constellation = modulation;
2107        tuneto.u.ofdm.transmission_mode = transmission;
2108        tuneto.u.ofdm.guard_interval = guardinterval;
2109        tuneto.u.ofdm.hierarchy_information = hierarchy;
2110       
2111        if(ioctl(node->fd, FE_SET_FRONTEND, &tuneto) == -1)
2112        {
2113                perr("FE_SET_FRONTEND");
2114                ret = 1;
2115        }
2116
2117        debug(200, "old dvbapi 1: frequ=%d, inversion=%d, bandwidth=%d, hp=%d, lp=%d, modulation=%d transmission=%d guardinterval=%d hierarchy=%d system=%d (%s)", tpnode->frequency, tpnode->inversion, bandwidth, hp, lp, modulation, transmission, guardinterval, hierarchy, system, node->feshortname);
2118
2119#endif
2120        return ret;
2121}
2122
2123#ifdef SIMULATE
2124int tunercount = 0;
2125#endif
2126struct dvb_frontend_info* fegetinfo(struct dvbdev* node, int fd)
2127{
2128        struct dvb_frontend_info* feinfo = NULL;
2129        int tmpfd = -1;
2130
2131        if(node != NULL)
2132                tmpfd = node->fd;
2133        else
2134                tmpfd = fd;
2135
2136        feinfo = (struct dvb_frontend_info*)malloc(sizeof(struct dvb_frontend_info));
2137        if(feinfo == NULL)
2138        {
2139                err("no mem");
2140                return NULL;
2141        }
2142
2143#ifndef SIMULATE
2144        if(ioctl(tmpfd, FE_GET_INFO, feinfo) < 0)
2145        {
2146                perr("FE_GET_INFO");
2147                free(feinfo);
2148                return NULL;
2149        }
2150#else
2151        tunercount++;
2152        if(tunercount == 1)
2153        {
2154                sprintf(feinfo->name, "%s", "Conax 7500 DVB-C");
2155                feinfo->type = FE_QAM;
2156        }
2157        else
2158        {
2159                sprintf(feinfo->name, "%s", "Conax 7500 DVB-S");
2160                feinfo->type = FE_QPSK;
2161                //feinfo->type = FE_QAM;
2162        }
2163#endif
2164        return feinfo;
2165}
2166
2167#if defined DTV_ENUM_DELSYS
2168int fesetDeliverySystem(fe_delivery_system_t delsys, int fd)
2169{
2170        struct dtv_property p[2];
2171        memset(p, 0, sizeof(p));
2172        struct dtv_properties cmdseq;
2173        cmdseq.props = p;
2174        cmdseq.num = 2;
2175        p[0].cmd = DTV_CLEAR;
2176        p[1].cmd = DTV_DELIVERY_SYSTEM;
2177        p[1].u.data = delsys;
2178        if (ioctl(fd, FE_SET_PROPERTY, &cmdseq) == -1)
2179        {
2180                perr("[DTV_ENUM_DELSYS] FE_SET_PROPERTY failed");
2181                return 0;
2182        }
2183        return 1;
2184}
2185#endif
2186
2187int fegetdev()
2188{
2189        int i, y, fd = -1, count = 0;
2190        char *buf = NULL, *frontenddev = NULL, *fehyprid = NULL, *tmpstr = NULL, *tmpstr1 = NULL;
2191        struct dvb_frontend_info* feinfo = NULL;
2192        struct dvbdev* dvbnode = NULL;
2193
2194        frontenddev = getconfig("frontenddev", NULL);
2195        if(frontenddev == NULL)
2196        {
2197                err("NULL detect");
2198                return count;
2199        }
2200
2201        buf = malloc(MINMALLOC);
2202        if(buf == NULL)
2203        {
2204                err("no memory");
2205                return count;
2206        }
2207
2208#if defined DTV_ENUM_DELSYS     
2209        if(getconfig("tempnim", NULL) == NULL)
2210                addconfig("tempnim", "/tmp/tempnim");
2211        if(file_exist(getconfig("tempnim", NULL)) == 1)
2212                unlink(getconfig("tempnim", NULL));
2213#endif
2214       
2215        for(i = 0; i < MAXDVBADAPTER; i++)
2216        {
2217                for(y = 0; y < MAXFRONTENDDEV; y++)
2218                {
2219                        sprintf(buf, frontenddev, i, y);
2220                        fd = feopen(NULL, buf);
2221                        if(fd >= 0)
2222                        {
2223                               
2224#if defined DTV_ENUM_DELSYS
2225                                struct dtv_property p[1];
2226                                memset(p, 0, sizeof(p));
2227                                p[0].cmd = DTV_ENUM_DELSYS;
2228                                struct dtv_properties cmdseq;
2229                                cmdseq.num = 1;
2230                                cmdseq.props = p;
2231                                int type = -1;
2232                                int mz = -1;
2233                                struct dvb_frontend_info* t_feinfo = NULL;
2234                                       
2235                                //tricky... temporäre nim_sockets bauen da ansonsten viel im code geändert werden müßte
2236                                free(tmpstr); tmpstr= NULL;
2237                                free(tmpstr1); tmpstr1= NULL;
2238                                tmpstr = ostrcat("NIM Socket " , oitoa(y), 0, 1);
2239                                tmpstr = ostrcat(tmpstr , ":\n", 1, 0);
2240                               
2241                                t_feinfo = (struct dvb_frontend_info*)malloc(sizeof(struct dvb_frontend_info));
2242                                if (ioctl(fd, FE_GET_PROPERTY, &cmdseq) >= 0)
2243                                {
2244                                        for (; p[0].u.buffer.len > 0; p[0].u.buffer.len--)
2245                                        {
2246                                                memset(t_feinfo, 0, sizeof(struct dvb_frontend_info));
2247                                                fe_delivery_system_t delsys = (fe_delivery_system_t)p[0].u.buffer.data[p[0].u.buffer.len - 1];
2248                                                printf("--------> delsys %d devive: %d\n", delsys, y);
2249                                                fesetDeliverySystem(delsys, fd);
2250                                                if (ioctl(fd, FE_GET_INFO, t_feinfo) < 0)
2251                                                {
2252                                                perr("[DTV_ENUM_DELSYS] ioctl FE_GET_INFO failed");
2253                                        }
2254                                        else
2255                                        {
2256                                                printf("------> name %s %d\n", t_feinfo->name, t_feinfo->type);
2257                                                if(type != t_feinfo->type)
2258                                                {
2259                                                        type = t_feinfo->type;
2260                                                        mz = mz + 1;
2261                                                        switch (type)
2262                                                                {
2263                                                                        case FE_QPSK:
2264                                                                        {
2265                                                                                tmpstr = ostrcat(tmpstr , "        Mode ", 1, 0);
2266                                                                                tmpstr = ostrcat(tmpstr , oitoa(feSatellite), 1, 1);
2267                                                                                tmpstr = ostrcat(tmpstr , ": DVB-S/S2\n", 1, 0);
2268                                                                                //tmpstr1 = ostrcat(tmpstr1 , oitoa(feSatellite), 1, 1);
2269                                                                                //tmpstr1 = ostrcat(tmpstr1 , "\n", 1, 0);
2270                                                                                               
2271                                                                                break;
2272                                                                        }
2273                                                                        case FE_QAM:
2274                                                                        {
2275                                                                                tmpstr = ostrcat(tmpstr , "        Mode ", 1, 0);
2276                                                                                tmpstr = ostrcat(tmpstr , oitoa(feCable), 1, 1);
2277                                                                                tmpstr = ostrcat(tmpstr , ": DVB-C\n", 1, 0);
2278                                                                                //tmpstr1 = ostrcat(tmpstr1 , oitoa(feCable), 1, 1);
2279                                                                                //tmpstr1 = ostrcat(tmpstr1 , "\n", 1, 0);
2280                                                                                break;
2281                                                                        }
2282                                                                        case FE_OFDM:
2283                                                                        {
2284                                                                                tmpstr = ostrcat(tmpstr , "        Mode ", 1, 0);
2285                                                                                tmpstr = ostrcat(tmpstr , oitoa(feTerrestrial), 1, 1);
2286                                                                                tmpstr = ostrcat(tmpstr , ": DVB-T/T2\n", 1, 0);
2287                                                                                //tmpstr1 = ostrcat(tmpstr1 , oitoa(feTerrestrial), 1, 1);
2288                                                                                //tmpstr1 = ostrcat(tmpstr1 , "\n", 1, 0);
2289                                                                                break;
2290                                                                        }
2291                                                        }
2292                                                }
2293                                                }
2294                                        }
2295                                        if(mz > 0)
2296                                        {
2297                                                tmpstr = ostrcat(tmpstr , "        Frontend_Device: ", 1, 0);   
2298                                                tmpstr = ostrcat(tmpstr , oitoa(y), 1, 1);
2299                                                tmpstr = ostrcat(tmpstr , "\n", 1, 0);         
2300                                                tmpstr = ostrcat(tmpstr , "        I2C_Device: x\n", 1, 0);     
2301                                                writesys(getconfig("tempnim", NULL), tmpstr, 2);
2302                                                //fehyprid = ostrcat(tmpstr1 , NULL, 0, 0);     
2303                                        }
2304                                        free(tmpstr); tmpstr = NULL;
2305                                        free(tmpstr1); tmpstr1 = NULL;
2306                                }
2307                                else
2308                                {
2309                                        perr("[DTV_ENUM_DELSYS] ioctl FE_GET_PROPERTY failed");
2310                                }
2311                                free(t_feinfo); t_feinfo = NULL;
2312#endif                         
2313                               
2314                                fehyprid = gethypridtunerchoicesvalue(y);
2315                               
2316                                if(fehyprid != NULL)
2317                                {
2318                                        if(y < 10)
2319                                                tmpstr = ostrcat(tmpstr, "fe_0", 1, 0);
2320                                        else
2321                                                tmpstr = ostrcat(tmpstr, "fe_1", 1, 0);
2322
2323                                        tmpstr = ostrcat(tmpstr, oitoa(y), 1, 1);
2324                                        tmpstr = ostrcat(tmpstr, "_hyprid", 1, 0);
2325                                        tmpstr1 = ostrcat(tmpstr, "_last", 0, 0);
2326                                        addconfig(tmpstr1, "999"); //first set
2327                                        free(tmpstr1), tmpstr1 = NULL;
2328#ifndef MIPSEL
2329                                        if(getconfig(tmpstr, NULL) != NULL)
2330                                                sethypridtuner(y, getconfig(tmpstr, NULL));
2331                                        free(tmpstr), tmpstr = NULL;
2332#endif
2333                                }
2334                               
2335                                feinfo = fegetinfo(NULL, fd);
2336
2337                                if(feinfo != NULL)
2338                                {
2339                                        count++;
2340                                        dvbnode = adddvbdev(buf, i, y, fd, FRONTENDDEV, feinfo, NULL, fehyprid, 0);
2341#ifdef MIPSEL
2342                                        if(fehyprid != NULL && getconfig(tmpstr, NULL) != NULL)
2343                                        {
2344                                                sethypridtunernew(dvbnode, getconfig(tmpstr, NULL));
2345                                                feinfo = fegetinfo(NULL, fd);
2346                                                dvbnode->feinfo = feinfo;
2347                                        }
2348                                        free(tmpstr), tmpstr = NULL;
2349#endif                                 
2350                                        if(dvbnode->feinfo->type == FE_QPSK)
2351                                                fesetvoltage(dvbnode, SEC_VOLTAGE_OFF, 15);
2352                                               
2353                                        if(y < 10)
2354                                                tmpstr = ostrcat(tmpstr, "fe_0", 1, 0);
2355                                        else
2356                                                tmpstr = ostrcat(tmpstr, "fe_1", 1, 0);
2357                                        tmpstr = ostrcat(tmpstr, oitoa(y), 1, 1);
2358                                        tmpstr = ostrcat(tmpstr, "_fbc", 1, 0);
2359                                        if(ostrstr(feinfo->name, "BCM45208") != NULL) //fbc Tuner
2360                                        {
2361                                                if(getconfig(tmpstr, NULL) == NULL)
2362                                                        addconfig(tmpstr, "A");
2363                                        }
2364                                        else
2365                                                addconfig(tmpstr, "");
2366                                        free(tmpstr), tmpstr = NULL;
2367                                }
2368                                if(tmpstr != NULL)
2369                                        free(tmpstr), tmpstr = NULL;
2370                        }
2371                }
2372        }
2373
2374        free(buf);
2375        return count;
2376}
2377
2378int fecreatedummy()
2379{
2380        //create dummy frontend for playback
2381        char *buf = NULL, *frontenddev = NULL;
2382        struct dvbdev* dvbnode = NULL;
2383
2384        frontenddev = getconfig("frontenddev", NULL);
2385        if(frontenddev == NULL)
2386        {
2387                err("NULL detect");
2388                return 1;
2389        }
2390
2391        buf = malloc(MINMALLOC);
2392        if(buf == NULL)
2393        {
2394                err("no memory");
2395                return 1;
2396        }
2397
2398        dvbnode = dmxgetlast(0);
2399        if(dvbnode != NULL)
2400        {
2401                sprintf(buf, frontenddev, 0, dvbnode->devnr);
2402                adddvbdev(buf, 0, dvbnode->devnr, -1, FRONTENDDEVDUMMY, NULL, NULL, NULL, 0);
2403        }
2404
2405        free(buf);
2406        return 0;
2407}
2408
2409int fegetlock(int tunernr)
2410{
2411        struct dvbdev* dvbnode = NULL;
2412        dvbnode = dvbdev;
2413
2414        while(dvbnode != NULL)
2415        {
2416                if(dvbnode->deactive == 1)
2417                {
2418                        dvbnode = dvbnode->next;
2419                        continue;
2420                }
2421                if(dvbnode->type == FRONTENDDEV && dvbnode->devnr == tunernr)
2422                {
2423                        return dvbnode->felock;
2424                }
2425                dvbnode = dvbnode->next;
2426        }
2427        return -1;
2428}
2429
2430#ifdef MIPSEL
2431int fechangetype(struct dvbdev* tuner, char* value)
2432{
2433#if DVB_API_VERSION >= 5       
2434
2435        struct dtv_property p[2];
2436        memset(p, 0, sizeof(p));
2437        struct dtv_properties cmdseq;
2438        cmdseq.props = p;
2439        cmdseq.num = 2;
2440        p[0].cmd = DTV_CLEAR;
2441        p[1].cmd = DTV_DELIVERY_SYSTEM;
2442        p[1].u.data = SYS_UNDEFINED;
2443        char* buf = NULL, *hypridtuner = NULL;
2444        int type = 0;
2445        int ret = 0;
2446        int wasopen = 0;
2447        char* realname = gethypridtunerchoicesvaluename(tuner->devnr, value);
2448       
2449        if(tuner->fd == -1)
2450        {
2451                if(feopen(tuner, NULL) < 0)
2452                        err("open tuner dev");
2453        }
2454        else
2455                wasopen = 1;
2456       
2457        printf("**** > realname: %s\n", realname);
2458       
2459        if(realname != NULL && ostrstr(realname, "DVB-S") != NULL)
2460                type = feSatellite;
2461        else if(realname != NULL && ostrstr(realname, "DVB-C") != NULL)
2462                type = feCable;
2463        else if(realname != NULL && ostrstr(realname, "DVB-T") != NULL)
2464                type = feTerrestrial;
2465        else
2466                type = -1;
2467       
2468        switch (type)
2469        {
2470                case feSatellite:
2471                {
2472                        p[1].u.data = SYS_DVBS;
2473                        break;
2474                }
2475                case feTerrestrial:
2476                {
2477                        //fesetvoltage(tuner, SEC_VOLTAGE_OFF, 10);
2478                        //to do set voltage --> wenn der Tuner es kann
2479                        //fesetvoltage(tuner, SEC_VOLTAGE_13, 10);
2480                        //if(realname != NULL && ostrstr(realname, "DVB-T2") != NULL)
2481                        /*if(realname != NULL && ostrstr(realname, "T2") != NULL)
2482                                p[1].u.data = SYS_DVBT2;
2483                        else*/
2484                                p[1].u.data = SYS_DVBT;
2485                        break;
2486                }
2487                case feCable:
2488                {
2489                         fesetvoltage(tuner, SEC_VOLTAGE_OFF, 10);
2490#ifdef SYS_DVBC_ANNEX_A
2491                        p[1].u.data = SYS_DVBC_ANNEX_A;
2492#else
2493                        p[1].u.data = SYS_DVBC_ANNEX_AC;
2494#endif
2495                        break;
2496                }
2497#ifdef feATSC
2498                case feATSC:
2499                {
2500                        p[1].u.data = SYS_ATSC;
2501                        break;
2502                }
2503#endif
2504                default:
2505                        debug(200, "not supported delivery system type %i", type);
2506                        return 0; //false
2507        }
2508        debug(200, "data %d",p[1].u.data );
2509        ret = 0;
2510        if (ioctl(tuner->fd, FE_SET_PROPERTY, &cmdseq) == -1)
2511        {
2512                perr("FE_SET_PROPERTY");
2513                err("FE_SET_PROPERTY failed -> use procfs to switch delivery system tuner %d mode %s type %d",tuner->devnr ,value, type);
2514                ret = -1;
2515        }
2516        else
2517        {
2518                printf("fe set property value %s data %d ... RC:%i\n", value, p[1].u.data, ret);
2519        }
2520       
2521                if(wasopen != 1)
2522                        feclose(tuner, -1);
2523                hypridtuner = getconfig("hypridtuner", NULL);
2524                if(hypridtuner != NULL)
2525                {
2526                        buf = malloc(MINMALLOC);
2527                        if(buf == NULL)
2528                        {
2529                                err("no memory");
2530                                return 0;
2531                        }
2532                }
2533                sprintf(buf, hypridtuner, tuner->devnr);
2534                if(file_exist(buf))
2535                {
2536                        if(tuner->fd > -1)
2537                        {
2538                                feclose(tuner, -1);
2539                                ret = writesys(buf, value, 0);
2540                                tuner->fd = feopen(tuner, NULL);
2541                        }
2542                        else
2543                                ret = writesys(buf, value, 0);
2544                        printf("set %s to %s RC:%i\n", buf, value, ret);
2545                }
2546                else
2547                        printf("set system tuner to %s ... file not found -> %s\n", value, buf);
2548                free(buf); buf = NULL;
2549       
2550        if(ret > -1)
2551                return 1; //true
2552        else
2553                return 0; //false
2554
2555#else //if DVB_API_VERSION < 5
2556        printf("Hinweis -> DVB API kleiner Version 5\n");
2557        if(sethypridtuner(tuner, value) == 0)
2558                return 1;
2559        return 0; //false
2560#endif
2561}               
2562#endif
2563       
2564
2565#endif
Note: See TracBrowser for help on using the repository browser.