source: titan/titan/frontenddev.h @ 41146

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

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