source: titan/titan/frontenddev.h @ 41149

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

[titan] next fix fbc tuner

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