source: titan/titan/scan.h @ 38791

Last change on this file since 38791 was 36820, checked in by Stephan, 8 years ago

better text

File size: 71.2 KB
Line 
1#ifndef SCAN_H
2#define SCAN_H
3
4uint8_t changeservicetype(uint8_t type)
5{
6        int ret = type;
7
8        switch(type)
9        {
10                case 0x01:
11                case 0x06:
12                case 0x0B:
13                case 0x11:
14                case 0x16:
15                case 0x19:
16                case 0x1C:
17                case 0x9A:
18                case 0x86:
19                case 0xC3:
20                case 0xC5:
21                case 0xC6:
22                        ret = 0;
23                        break;
24                case 0x02:
25                case 0x07:
26                case 0x0A:
27                        ret = 1;
28                        break;
29        }
30
31        return ret;
32}
33
34struct transponder* satsystemdesc(unsigned char* buf, uint64_t transportid, unsigned short onid, int orbitalpos)
35{
36        int polarization = 0, modulation = 0, system = 0;
37        int rolloff = 0, fec = 0;
38        unsigned int frequency = 0, symbolrate = 0;
39        uint64_t id = 0;
40        struct transponder *tpnode = NULL;
41
42        if(buf == NULL) return NULL;
43
44        frequency = (
45                ((buf[2] >> 4) * 100000000) +
46                ((buf[2] & 0x0F) * 10000000) +
47                ((buf[3] >> 4) * 1000000) +
48                ((buf[3] & 0x0F) * 100000) +
49                ((buf[4] >> 4) * 10000) +
50                ((buf[4] & 0x0F) * 1000) +
51                ((buf[5] >> 4) * 100) +
52                ((buf[5] & 0x0F) * 10)
53        );
54
55        rolloff = (buf[8] >> 4) & 0x03; //0=rolloff_0_35, 1=rolloff_0_25, 2=rolloff_0_20, 3=rolloff_auto
56        system = (buf[8] >> 2) & 0x01; //0=DVB_S, 1=DVB_S2
57        modulation = (buf[8]) & 0x03; //1=QPSK, 2=PSK_8, 3=QAM_16
58
59        symbolrate = (
60                ((buf[9] >> 4) * 100000000) +
61                ((buf[9] & 0x0F) * 10000000) +
62                ((buf[10] >> 4) * 1000000) +
63                ((buf[10] & 0x0F) * 100000) +
64                ((buf[11] >> 4) * 10000) +
65                ((buf[11] & 0x0F) * 1000) +
66                ((buf[12] >> 4) * 100)
67        );
68
69        fec = (buf[12]) & 0x0F;
70
71        switch(fec)
72        {
73                case 0x01:
74                        fec = FEC_1_2;
75                        break;
76                case 0x02:
77                        fec = FEC_2_3;
78                        break;
79                case 0x03:
80                        fec = FEC_3_4;
81                        break;
82                case 0x04:
83                        fec = FEC_5_6;
84                        break;
85                case 0x05:
86                        fec = FEC_7_8;
87                        break;
88                case 0x06:
89                        fec = FEC_8_9;
90                        break;
91                case 0x07:
92                        fec = FEC_3_5;
93                        break;
94                case 0x08:
95                        fec = FEC_4_5;
96                        break;
97                case 0x09:
98                        fec = FEC_9_10;
99                        break;
100                case 0x0F:
101                        fec = FEC_NONE;
102                        break;
103                default:
104                        fec = FEC_AUTO;
105                        break;
106        }
107
108        polarization = (buf[8] >> 5) & 0x03; //0=H, 1=V
109
110        //workarounds for braindead broadcasters (e.g. on Telstar 12 at 15.0W)
111        if(frequency >= 100000000) frequency /= 10;
112        if(symbolrate >= 50000000) symbolrate /= 10;
113
114        frequency = (int)1000 * (int)round((double)frequency / (double)1000);
115
116        if(frequency > 15000000) return NULL;
117
118        id = ((onid << 16) | transportid) & 0xffffffff;
119
120        if(gettransponder(id) == NULL)
121        {
122                tpnode = createtransponder(id, FE_QPSK, orbitalpos, frequency, INVERSION_AUTO, symbolrate, polarization, fec, modulation, rolloff, 0, system);
123                status.writetransponder = 1;
124        }
125
126        debug(500, "nitscan: id=%llu freq=%d sr=%d fec=%d pol=%d modulation=%d system=%d tpnode=%p", id, frequency, symbolrate, fec, polarization, modulation, system, tpnode);
127
128        return tpnode;
129}
130
131struct transponder* cablesystemdesc(unsigned char* buf, uint64_t transportid, unsigned short onid, int orbitalpos)
132{
133        int modulation = 0, fec = 0;
134        unsigned int frequency = 0, symbolrate = 0;
135        uint64_t id = 0;
136        struct transponder *tpnode = NULL;
137
138        if(buf == NULL) return NULL;
139
140        frequency = (
141                ((buf[2] >> 4) * 1000000000) +
142                ((buf[2] & 0x0F) * 100000000) +
143                ((buf[3] >> 4) * 10000000) +
144                ((buf[3] & 0x0F) * 1000000) +
145                ((buf[4] >> 4) * 100000) +
146                ((buf[4] & 0x0F) * 10000) +
147                ((buf[5] >> 4) * 1000) +
148                ((buf[5] & 0x0F) * 100)
149        );
150
151        modulation = buf[8]; //0=QAM_AUTO, 1=QAM_16, 2=QAM_32, 3=QAM_64, 4=QAM_128, 5=QAM_256
152
153        symbolrate = (
154                ((buf[9] >> 4) * 100000000) +
155                ((buf[9] & 0x0F) * 10000000) +
156                ((buf[10] >> 4) * 1000000) +
157                ((buf[10] & 0x0F) * 100000) +
158                ((buf[11] >> 4) * 10000) +
159                ((buf[11] & 0x0F) * 1000) +
160                ((buf[12] >> 4) * 100)
161        );
162
163        fec = (buf[12]) & 0x0F;
164
165        switch(fec)
166        {
167                case 0x01:
168                        fec = FEC_1_2;
169                        break;
170                case 0x02:
171                        fec = FEC_2_3;
172                        break;
173                case 0x03:
174                        fec = FEC_3_4;
175                        break;
176                case 0x04:
177                        fec = FEC_5_6;
178                        break;
179                case 0x05:
180                        fec = FEC_7_8;
181                        break;
182                case 0x06:
183                        fec = FEC_8_9;
184                        break;
185                case 0x07:
186                        fec = FEC_3_5;
187                        break;
188                case 0x08:
189                        fec = FEC_4_5;
190                        break;
191                case 0x09:
192                        fec = FEC_9_10;
193                        break;
194                case 0x0F:
195                        fec = FEC_NONE;
196                        break;
197                default:
198                        fec = FEC_AUTO;
199                        break;
200        }
201
202        id = ((onid << 16) | transportid) & 0xffffffff;
203        id = id | ((uint64_t)1 << 32);
204
205        if(gettransponder(id) == NULL)
206        //if(gettransponderbydetail(id, FE_QAM, orbitalpos, frequency, INVERSION_AUTO, symbolrate, 0, fec, modulation, 0, 0, 0, 0) == NULL)
207        {
208                tpnode = createtransponder(id, FE_QAM, orbitalpos, frequency, INVERSION_AUTO, symbolrate, 0, fec, modulation, 0, 0, 0);
209                status.writetransponder = 1;
210        }
211
212        debug(500, "nitscan: id=%llu freq=%d sr=%d fec=%d modulation=%d tpnode=%p", id, frequency, symbolrate, fec, modulation, tpnode);
213
214        return tpnode;
215}
216
217struct transponder* terrsystemdesc(unsigned char* buf, uint64_t transportid, unsigned short onid, int orbitalpos)
218{
219        int modulation = 0, hp = 0, lp = 0;
220        int bandwidth = 0, hierarchy = 0, guardinterval = 0;
221        int transmission = 0;
222        unsigned int frequency = 0;
223        uint64_t id = 0;
224        struct transponder *tpnode = NULL;
225
226        if(buf == NULL) return NULL;
227
228        frequency = (buf[2] << 24) | (buf[3] << 16);
229        frequency |= (buf[4] << 8) | buf[5];
230        frequency *= 10;
231
232        bandwidth = BANDWIDTH_8_MHZ + ((buf[6] >> 5) & 0x3);
233        modulation = (buf[7] >> 6) & 0x3;
234        hierarchy = HIERARCHY_NONE + ((buf[7] >> 3) & 0x3);
235
236        hp = (buf[7] & 0x7);
237        switch(hp)
238        {
239                case 0x00:
240                        hp = FEC_1_2;
241                        break;
242                case 0x01:
243                        hp = FEC_2_3;
244                        break;
245                case 0x02:
246                        hp = FEC_3_4;
247                        break;
248                case 0x03:
249                        hp = FEC_5_6;
250                        break;
251                case 0x04:
252                        hp = FEC_7_8;
253                        break;
254                default:
255                        hp = FEC_AUTO;
256                        break;
257        }
258
259        lp = ((buf[8] >> 5) & 0x7);
260        switch(lp)
261        {
262                case 0x00:
263                        lp = FEC_1_2;
264                        break;
265                case 0x01:
266                        lp = FEC_2_3;
267                        break;
268                case 0x02:
269                        lp = FEC_3_4;
270                        break;
271                case 0x03:
272                        lp = FEC_5_6;
273                        break;
274                case 0x04:
275                        lp = FEC_7_8;
276                        break;
277                default:
278                        lp = FEC_AUTO;
279                        break;
280        }
281
282        guardinterval = GUARD_INTERVAL_1_32 + ((buf[8] >> 3) & 0x3);
283
284        transmission = (buf[8] & 0x2);
285        switch(transmission)
286        {
287                case 0x00:
288                        transmission = TRANSMISSION_MODE_2K;
289                        break;
290                case 0x01:
291                        transmission = TRANSMISSION_MODE_8K;
292                        break;
293                case 0x02:
294                        transmission = TRANSMISSION_MODE_AUTO;
295                        break;
296                default:
297                        transmission = TRANSMISSION_MODE_AUTO;
298                        break;
299        }
300
301        //other_frequency_flag = (buf[8] & 0x01);
302
303        id = ((onid << 16) | transportid) & 0xffffffff;
304        id = id | ((uint64_t)2 << 32);
305
306        if(gettransponder(id) == NULL)
307        {
308                tpnode = createtransponder(id, FE_OFDM, orbitalpos, frequency, INVERSION_AUTO, bandwidth, lp, hp, modulation, guardinterval, transmission, hierarchy);
309                status.writetransponder = 1;
310        }
311
312        debug(500, "nitscan: id=%llu freq=%d bandwidth=%d hp=%d lp=%d modulation=%d guard=%d trans=%d hierarchy=%d tpnode=%p", id, frequency, bandwidth, hp, lp, modulation, guardinterval, transmission, hierarchy, tpnode);
313
314        return tpnode;
315}
316
317int parsenit(unsigned char* buf, uint8_t* lastsecnr, int orbitalpos)
318{
319        int ret = 0;
320
321        if(buf == NULL) return ret;
322
323        //unsigned char buf[MINMALLOC];
324
325        // position in buffer
326        unsigned short pos = 0;
327        unsigned short pos2 = 0;
328
329        // network_information_section elements
330        unsigned short seclen = 0;
331        unsigned short desclen = 0;
332        unsigned short tdesclen = 0;
333        unsigned short looplen = 0;
334        uint64_t transponderid = 0;
335        unsigned short onid = 0;
336        unsigned short nid = 0;
337        unsigned char secnr = 0;
338
339        seclen = ((buf[1] & 0x0F) << 8) + buf[2];
340        nid = ((buf[3] << 8)| buf[4]);
341        desclen = ((buf[8] & 0x0F) << 8) | buf[9];
342        secnr = buf[6];
343        *lastsecnr = buf[7];
344        debug(500, "nitscan: section %d last %d nid %d", secnr, *lastsecnr, nid);
345
346        for(pos = 10; pos < desclen + 10; pos += buf[pos + 1] + 2)
347        {
348                switch(buf[pos])
349                {
350                        case 0x0F:
351                                //private_data_indicator_desc(buf + pos);
352                                break;
353                        case 0x40:
354                                //network_name_desc(buf + pos);
355                                break;
356                        case 0x4A:
357                                //linkage_desc(buf + pos);
358                                break;
359                        case 0x5B:
360                                //multilingual_networkname_desc(buf + pos);
361                                break;
362                        case 0x5F:
363                                //private_data_specifier_desc(buf + pos);
364                                break;
365                        case 0x80:
366                                break;
367                        case 0x90:
368                                break;
369                }
370        }
371
372        looplen = ((buf[pos] & 0x0F) << 8) | buf[pos + 1];
373        if (!looplen) return ret;
374
375        for(pos += 2; pos < seclen - 3; pos += tdesclen + 6)
376        {
377                transponderid = (buf[pos] << 8) | buf[pos + 1];
378                onid = (buf[pos + 2] << 8) | buf[pos + 3];
379                tdesclen = ((buf[pos + 4] & 0x0F) << 8) | buf[pos + 5];
380
381                for(pos2 = pos + 6; pos2 < pos + tdesclen + 6; pos2 += buf[pos2 + 1] + 2)
382                {
383                        switch(buf[pos2])
384                        {
385                                case 0x41:
386                                        //servicelistdesc(buf + pos2, transponderid, onid);
387                                        break;
388                                case 0x43:
389                                        if(satsystemdesc(buf + pos2, transponderid, onid, orbitalpos) != NULL)
390                                        {
391                                                scaninfo.tpnew++;
392                                                if(scaninfo.scantype != 0)
393                                                        scaninfo.tpmax++;
394                                        }
395                                        break;
396                                case 0x44:
397                                        if(cablesystemdesc(buf + pos2, transponderid, onid, orbitalpos) != NULL)
398                                        {
399                                                scaninfo.tpnew++;
400                                                if(scaninfo.scantype != 0)
401                                                        scaninfo.tpmax++;
402                                        }
403                                        break;
404                                case 0x5A:
405                                        if(terrsystemdesc(buf + pos2, transponderid, onid, orbitalpos) != NULL)
406                                        {
407                                                scaninfo.tpnew++;
408                                                if(scaninfo.scantype != 0)
409                                                        scaninfo.tpmax++;
410                                        }
411                                        break;
412                                case 0x62:
413                                        //frequencylistdesc(buf + pos2);
414                                        break;
415                        }
416                }
417        }
418
419        return ret;
420}
421
422//flag 0: from scan
423//flag 1: from update channelname
424int findchannel(struct dvbdev* fenode, struct transponder* tpnode, unsigned char *buf, uint8_t* lastsecnr, struct skin* scan, struct skin* listbox, int ichangename, int flag)
425{
426        int ret = -1, changed = 0;
427        uint64_t transponderid = 0;
428        struct skin* node = NULL;
429        struct channel* chnode = NULL;
430
431        // position in buffer
432        unsigned short pos;
433        unsigned short pos2;
434
435        // service_description_section elements
436        unsigned short seclen;
437        uint8_t secnr;
438        unsigned short onid, tid;
439        unsigned short serviceid;
440        unsigned short desclooplen;
441        unsigned short running;
442        int eitscheduleflag;
443        int eitpresentfollowingflag;
444        int camode;
445        uint8_t servicetype = 0;
446        uint8_t providerlen = 0;
447        char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL;
448        uint64_t* tmpuint64 = NULL;
449
450        struct transponder* tphelp = NULL;
451
452        if(buf == NULL || fenode == NULL || fenode->feinfo == NULL) return ret;
453
454        seclen = ((buf[1] & 0x0F) << 8) | buf[2];
455        secnr = buf[6];
456        *lastsecnr = buf[7];
457        tid = (buf[3] << 8) | buf[4];
458        onid = (buf[8] << 8) | buf[9];
459
460        transponderid = ((onid << 16) | tid) & 0xffffffff;
461        if(fenode->feinfo->type == FE_QAM)
462                transponderid = transponderid | ((uint64_t)1 << 32);
463        else if(fenode->feinfo->type == FE_OFDM)
464                transponderid = transponderid | ((uint64_t)2 << 32);
465
466        //if(tpnode != NULL && (tpnode->id != transponderid || scaninfo.fenode->feinfo->type == FE_QAM || scaninfo.fenode->feinfo->type == FE_OFDM) && tpnode->id != 99)
467        if(tpnode != NULL && tpnode->id != transponderid && tpnode->id != 99)
468        {
469                tphelp = gettransponder(transponderid);
470                if(tphelp != NULL)
471                {
472                        deltranspondercache(tphelp->id, tphelp);
473                        tphelp->id = 0;
474                        modifytranspondercache(tphelp->id, tphelp);
475                        debug(500, "set old tid: %llu to 0", transponderid);
476
477                        //changetransponderid(tphelp, 0);
478                        //debug(500, "set old tid: %llu to 0", transponderid);
479                }
480                changetransponderid(tpnode, transponderid);
481                status.writetransponder = 1;
482        }
483
484        debug(500, "SDT nr: %d, lastnr: %d, len: %d, tid: %d, onid: %d, transponderid: %llu", secnr, *lastsecnr, seclen, tid, onid, transponderid);
485
486        for(pos = 11; pos < seclen - 1; pos += desclooplen + 5)
487        {
488                serviceid = (buf[pos] << 8) | buf[pos + 1];
489                eitscheduleflag = buf[pos + 2] & 0x02;
490                eitpresentfollowingflag = buf[pos + 2] & 0x01;
491                running = buf[pos + 3] & 0xE0;
492                camode = buf[pos + 3] & 0x10;
493                desclooplen = ((buf[pos + 3] & 0x0F) << 8) | buf[pos + 4];
494                if(flag == 0 && scaninfo.onlyfree == 1 && camode > 0) continue;
495
496                for(pos2 = pos + 5; pos2 < pos + desclooplen + 5; pos2 += buf[pos2 + 1] + 2)
497                {
498                        switch(buf[pos2])
499                        {
500                                case 0x48:
501                                        servicetype = buf[pos2 + 2];
502                                        servicetype = changeservicetype(servicetype);
503                                        providerlen = buf[pos2 + 3];
504
505                                        //providername
506                                        tmpstr1 = strndup((char*)&(buf[pos2 + 4]), providerlen);
507                                        //channelname
508                                        tmpstr2 = strndup((char*)&(buf[pos2 + 4 + providerlen + 1]), (2 + buf[pos2 + 1]) - (4 + providerlen + 1));
509
510                                        tmpstr1 = string_strip_whitechars(tmpstr1);
511                                        tmpstr2 = string_strip_whitechars(tmpstr2);
512                                        if(tmpstr1 == NULL || strlen(tmpstr1) == 0) tmpstr1 = ostrcat(tmpstr1, "unknown", 1, 0);
513                                        if(tmpstr2 == NULL || strlen(tmpstr2) == 0) tmpstr2 = ostrcat(tmpstr2, "unknown", 1, 0);
514
515                                        tmpstr1 = strutf8(tpnode, tmpstr1, strlen(tmpstr1), 0, 1, 0);
516                                        tmpstr1 = stringreplacechar(tmpstr1, '#', '_');
517                                        tmpstr2 = strutf8(tpnode, tmpstr2, strlen(tmpstr2), 0, 1, 1);
518                                        tmpstr2 = stringreplacechar(tmpstr2, '#', '_');
519
520                                        //add to listbox
521                                        chnode = getchannel(serviceid, transponderid);
522                                        if(flag == 0) node = addlistbox(scan, listbox, node, 1);
523                                        if(node != NULL)
524                                        {
525                                                switch(servicetype)
526                                                {
527                                                        case 0:
528                                                                scaninfo.tvcount++;
529                                                                if(chnode == NULL) scaninfo.newtvcount++;
530                                                                break;
531                                                        case 1:
532                                                                scaninfo.radiocount++;
533                                                                if(chnode == NULL) scaninfo.newradiocount++;
534                                                                break;
535                                                        default:
536                                                                scaninfo.datacount++;
537                                                                if(chnode == NULL) scaninfo.newdatacount++;
538                                                                break;
539                                                }
540                                                tmpstr = ostrcat(tmpstr2, " (", 0, 0);
541                                                tmpstr = ostrcat(tmpstr, tmpstr1, 1, 0);
542                                                tmpstr = ostrcat(tmpstr, " - ", 1, 0);
543                                                if(servicetype == 0)
544                                                        tmpstr = ostrcat(tmpstr, _("TV"), 1, 0);
545                                                else if(servicetype == 1)
546                                                        tmpstr = ostrcat(tmpstr, _("Radio"), 1, 0);
547                                                else
548                                                        tmpstr = ostrcat(tmpstr, _("Data"), 1, 0);
549
550                                                changed = 0;
551                                                if(chnode != NULL && chnode->name != NULL && strlen(chnode->name) > 0 && ostrcmp(tmpstr2, chnode->name) != 0)
552                                                {
553                                                        tmpstr = ostrcat(tmpstr, " - ", 1, 0);
554                                                        tmpstr = ostrcat(tmpstr, chnode->name, 1, 0);
555                                                        if(ichangename == 1) changed = 1;
556                                                }
557                                                tmpstr = ostrcat(tmpstr, ")", 1, 0);
558                                                changetext(node, tmpstr);
559
560                                                if(chnode != NULL && chnode->transponder != NULL && changed == 0)
561                                                        node->fontcol = convertcol("deaktivcol");
562
563                                                changeparam1(node, tmpstr1);
564                                                changeparam2(node, tmpstr2);
565                                                tmpuint64 = (uint64_t*)calloc(1, sizeof(uint64_t) * 3);
566                                                if(tmpuint64 != NULL)
567                                                {
568                                                        tmpuint64[0] = serviceid;
569                                                        tmpuint64[1] = transponderid;
570                                                        tmpuint64[2] = servicetype;
571                                                }
572                                                free(node->name);
573                                                node->name = (char*)tmpuint64;
574                                        }
575
576                                        if(flag == 1 && chnode != NULL && ostrcmp(chnode->name, tmpstr2) != 0)
577                                        {
578                                                free(chnode->name);
579                                                chnode->name = ostrcat(tmpstr2, NULL, 0, 0);
580                                                status.writechannel = 1;
581                                        }
582
583                                        free(tmpstr); tmpstr = NULL;
584                                        free(tmpstr1); tmpstr1 = NULL;
585                                        free(tmpstr2); tmpstr2 = NULL;
586
587                                        ret = 0;
588                                        break;
589                        }
590                }
591        }
592
593        return ret;
594}
595
596uint64_t findtransponderid(struct dvbdev* fenode, unsigned char *buf)
597{
598        uint64_t transponderid = 0;
599        unsigned short onid, tid;
600
601        if(buf == NULL || fenode == NULL || fenode->feinfo == NULL) return 0;
602
603        tid = (buf[3] << 8) | buf[4];
604        onid = (buf[8] << 8) | buf[9];
605
606        transponderid = ((onid << 16) | tid) & 0xffffffff;
607
608        if(fenode->feinfo->type == FE_QAM)
609                transponderid = transponderid | ((uint64_t)1 << 32);
610        else if(fenode->feinfo->type == FE_OFDM)
611                transponderid = transponderid | ((uint64_t)2 << 32);
612
613        debug(500, "found SDT transponderid: %llu", transponderid);
614
615        return transponderid;
616}
617
618unsigned int satblindscan(struct stimerthread* timernode, int onlycalc)
619{
620        int festatus = 0;
621        uint64_t transponderid = 0;
622        unsigned char* buf = NULL;
623        struct dvbdev* fenode = NULL;
624        struct transponder* tpnode = NULL;
625
626        unsigned int frequency = 0, symbolrate = 0;
627        int polarization = 0, modulation = 0, system = 0, fec = 0;
628
629        unsigned int minfrequency = getconfigint("blindminfrequency", NULL) * 1000;
630        unsigned int maxfrequency = getconfigint("blindmaxfrequency", NULL) * 1000;
631        unsigned int stepfrequency = getconfigint("blindstepfrequency", NULL) * 1000;
632        unsigned int minsymbolrate = getconfigint("blindminsignalrate", NULL) * 1000;
633        unsigned int maxsymbolrate = getconfigint("blindmaxsignalrate", NULL) * 1000;
634        unsigned int stepsymbolrate = getconfigint("blindstepsignalrate", NULL) * 1000;
635        unsigned int usedefaultsr = getconfigint("blindusedefaultsr", NULL);
636        unsigned int onlydvbs = getconfigint("blindonlydvbs", NULL);
637        unsigned int usedefaultfec = getconfigint("blindusedefaultfec", NULL);
638
639        int minmodulation = 1, maxmodulation = 2, stepmodulation = 1;
640        int minpolarization = 0, maxpolarization = 1, steppolarization = 1;
641        int minsystem = 0, maxsystem = 1, stepsystem = 1;
642        int minfec = 0, maxfec = 8, stepfec = 1;
643
644        if(onlydvbs == 1)
645        {
646                maxmodulation = 0;
647                maxsystem = 0;
648        }
649
650        if(usedefaultsr == 1)
651        {
652                minsymbolrate = 0;
653                maxsymbolrate = 3;
654                stepsymbolrate = 1;
655        }
656
657        if(usedefaultfec == 1)
658                maxfec = 6;
659
660        int countfrequency = ((maxfrequency + stepfrequency) - minfrequency) / stepfrequency;
661        int countsymbolrate = ((maxsymbolrate + stepsymbolrate) - minsymbolrate) / stepsymbolrate;
662        int countmodulation = ((maxmodulation + stepmodulation) - minmodulation) / stepmodulation;
663        int countpolarization = ((maxpolarization + steppolarization) - minpolarization) / steppolarization;
664        int countfec = ((maxfec + stepfec) - minfec) / stepfec;
665        int systemcount = ((maxsystem + stepsystem) - minsystem) / stepsystem;
666
667        if(onlycalc == 1) return systemcount * countpolarization * countmodulation * countsymbolrate * countfrequency * countfec;
668
669        if(scaninfo.fenode == NULL || timernode == NULL) return -1;
670        int timeout = scaninfo.timeout / 5;
671        if(timeout < 1000000) timeout = 1000000;
672        scaninfo.blindmax += systemcount * countpolarization * countmodulation * countsymbolrate * countfrequency * countfec;
673
674        for(frequency = minfrequency; frequency <= maxfrequency; frequency += stepfrequency)
675        {
676
677                int csymbolrate = 0;
678                for(csymbolrate = minsymbolrate; csymbolrate <= maxsymbolrate; csymbolrate += stepsymbolrate)
679                {
680                        if(usedefaultsr == 1)
681                        {
682                                switch(csymbolrate)
683                                {
684                                        case 0:
685                                                symbolrate = 22000 * 1000;
686                                                break;
687                                        case 1:
688                                                symbolrate = 27500 * 1000;
689                                                break;
690                                        case 2:
691                                                symbolrate = 30000 * 1000;
692                                                break;
693                                }
694                        }
695                        else
696                                symbolrate = csymbolrate;
697
698                        for(modulation = minmodulation; modulation <= maxmodulation; modulation += stepmodulation)
699                        {
700
701                                for(polarization = minpolarization; polarization <= maxpolarization; polarization += steppolarization)
702                                {
703
704                                        for(fec = minfec; fec <= maxfec; fec += stepfec)
705                                        {
706
707                                                for(system = minsystem; system <= maxsystem; system += stepsystem)
708                                                {
709                                                        scaninfo.blindcount++;
710
711                                                        tpnode = createtransponder(99, scaninfo.fenode->feinfo->type, scaninfo.orbitalpos, frequency, INVERSION_AUTO, symbolrate, polarization, fec, modulation, 0, 0, system);
712
713                                                        debug(500, "blindscan: frequ=%d, sr=%d, modulation=%d, fec=%d, system=%d, orbitalpos=%d", frequency, symbolrate, modulation, fec, system, scaninfo.orbitalpos);
714
715                                                        if(tpnode != NULL)
716                                                        {
717
718                                                                fenode = fegetfree(tpnode, 0, scaninfo.fenode);
719                                                                if(fenode == NULL )
720                                                                {
721                                                                        debug(500, "Frontend for scan not free");
722                                                                        deltransponderbyid(99);
723                                                                        continue;
724                                                                }
725
726                                                                //frontend tune
727                                                                if(fenode->feinfo->type == FE_QPSK)
728                                                                {
729                                                                        feset(fenode, tpnode);
730                                                                        fetunedvbs(fenode, tpnode);
731                                                                }
732                                                                else
733                                                                {
734                                                                        debug(500, "Frontend type unknown");
735                                                                        deltransponderbyid(99);
736                                                                        continue;
737                                                                }
738
739                                                                festatus = fewait(fenode);
740                                                                if(debug_level == 200) fereadstatus(fenode);
741                                                                if(festatus != 0)
742                                                                {
743                                                                        debug(500, "tuning failed");
744                                                                        deltransponderbyid(99);
745                                                                        continue;
746                                                                }
747
748                                                                buf = dvbgetsdt(fenode, 0, timeout);
749                                                                transponderid = findtransponderid(fenode, buf);
750                                                                free(buf); buf = NULL;
751
752                                                                if(transponderid == 0 || gettransponder(transponderid) != NULL)
753                                                                {
754                                                                        deltransponderbyid(99);
755                                                                        continue;
756                                                                }
757
758                                                                if(tpnode->id != transponderid)
759                                                                {
760                                                                        struct transponder* tphelp = gettransponder(transponderid);
761                                                                        if(tphelp != NULL)
762                                                                        {
763                                                                                deltransponderbyid(transponderid);
764                                                                                debug(500, "delete old tid: %llu", transponderid);
765                                                                        }
766                                                                        scaninfo.newblindcount++;
767                                                                        changetransponderid(tpnode, transponderid);
768                                                                        status.writetransponder = 1;
769                                                                }
770                                                        }
771                                                        deltransponderbyid(99);
772                                                        if(timernode->aktion != START) break;
773                                                }
774                                                if(timernode->aktion != START) break;
775                                        }
776                                        if(timernode->aktion != START) break;
777                                }
778                                if(timernode->aktion != START) break;
779                        }
780                        if(timernode->aktion != START) break;
781                }
782                if(timernode->aktion != START) break;
783        }
784
785        return 0;
786}
787
788unsigned int cableblindscan(struct stimerthread* timernode, int onlycalc)
789{
790        int festatus = 0;
791        uint64_t transponderid = 0;
792        unsigned char* buf = NULL;
793        struct dvbdev* fenode = NULL;
794        struct transponder* tpnode = NULL;
795
796        unsigned int frequency = 0, symbolrate = 0;
797        int modulation = 0, fec = 0;
798
799        unsigned int minfrequency = getconfigint("cblindminfrequency", NULL) * 1000;
800        unsigned int maxfrequency = getconfigint("cblindmaxfrequency", NULL) * 1000;
801        unsigned int stepfrequency = getconfigint("cblindstepfrequency", NULL) * 1000;
802        unsigned int minsymbolrate = getconfigint("cblindminsignalrate", NULL) * 1000;
803        unsigned int maxsymbolrate = getconfigint("cblindmaxsignalrate", NULL) * 1000;
804        unsigned int stepsymbolrate = getconfigint("cblindstepsignalrate", NULL) * 1000;
805        unsigned int usedefaultsr = getconfigint("cblindusedefaultsr", NULL);
806        unsigned int usedefaultfec = getconfigint("cblindusedefaultfec", NULL);
807
808        int minmodulation = 0, maxmodulation = 4, stepmodulation = 1;
809        int minfec = 0, maxfec = 8, stepfec = 1;
810
811        if(usedefaultsr == 1)
812        {
813                minsymbolrate = 0;
814                maxsymbolrate = 3;
815                stepsymbolrate = 1;
816        }
817
818        if(usedefaultfec == 1)
819                maxfec = 6;
820
821        int countfrequency = ((maxfrequency + stepfrequency) - minfrequency) / stepfrequency;
822        int countsymbolrate = ((maxsymbolrate + stepsymbolrate) - minsymbolrate) / stepsymbolrate;
823        int countmodulation = ((maxmodulation + stepmodulation) - minmodulation) / stepmodulation;
824        int countfec = ((maxfec + stepfec) - minfec) / stepfec;
825
826        if(onlycalc == 1) return countmodulation * countsymbolrate * countfrequency * countfec;
827
828        if(scaninfo.fenode == NULL || timernode == NULL) return -1;
829        int timeout = scaninfo.timeout / 5;
830        if(timeout < 1000000) timeout = 1000000;
831        scaninfo.blindmax += countmodulation * countsymbolrate * countfrequency * countfec;
832
833        for(frequency = minfrequency; frequency <= maxfrequency; frequency += stepfrequency)
834        {
835
836                int csymbolrate = 0;
837                for(csymbolrate = minsymbolrate; csymbolrate <= maxsymbolrate; csymbolrate += stepsymbolrate)
838                {
839                        if(usedefaultsr == 1)
840                        {
841                                switch(csymbolrate)
842                                {
843                                        case 0:
844                                                symbolrate = 22000 * 1000;
845                                                break;
846                                        case 1:
847                                                symbolrate = 27500 * 1000;
848                                                break;
849                                        case 2:
850                                                symbolrate = 30000 * 1000;
851                                                break;
852                                }
853                        }
854                        else
855                                symbolrate = csymbolrate;
856
857                        for(modulation = minmodulation; modulation <= maxmodulation; modulation += stepmodulation)
858                        {
859
860                                for(fec = minfec; fec <= maxfec; fec += stepfec)
861                                {
862                                        scaninfo.blindcount++;
863
864                                        tpnode = createtransponder(99, scaninfo.fenode->feinfo->type, scaninfo.orbitalpos, frequency, INVERSION_AUTO, symbolrate, 0, fec, modulation, 0, 0, 0);
865
866                                        debug(500, "blindscan: frequ=%d, sr=%d, modulation=%d, fec=%d, orbitalpos=%d", frequency, symbolrate, modulation, fec, scaninfo.orbitalpos);
867
868                                        if(tpnode != NULL)
869                                        {
870
871                                                fenode = fegetfree(tpnode, 0, scaninfo.fenode);
872                                                if(fenode == NULL )
873                                                {
874                                                        debug(500, "Frontend for scan not free");
875                                                        deltransponderbyid(99);
876                                                        continue;
877                                                }
878
879                                                //frontend tune
880                                                if(fenode->feinfo->type == FE_QAM)
881                                                        fetunedvbc(fenode, tpnode);
882                                                else
883                                                {
884                                                        debug(500, "Frontend type unknown");
885                                                        deltransponderbyid(99);
886                                                        continue;
887                                                }
888
889                                                festatus = fewait(fenode);
890                                                if(debug_level == 200) fereadstatus(fenode);
891                                                if(festatus != 0)
892                                                {
893                                                        debug(500, "tuning failed");
894                                                        deltransponderbyid(99);
895                                                        continue;
896                                                }
897
898                                                buf = dvbgetsdt(fenode, 0, timeout);
899                                                transponderid = findtransponderid(fenode, buf);
900                                                free(buf); buf = NULL;
901
902                                                if(transponderid == 0 || gettransponder(transponderid) != NULL)
903                                                {
904                                                        deltransponderbyid(99);
905                                                        continue;
906                                                }
907
908                                                if(tpnode->id != transponderid)
909                                                {
910                                                        struct transponder* tphelp = gettransponder(transponderid);
911                                                        if(tphelp != NULL)
912                                                        {
913                                                                deltransponderbyid(transponderid);
914                                                                debug(500, "delete old tid: %llu", transponderid);
915                                                        }
916                                                        scaninfo.newblindcount++;
917                                                        changetransponderid(tpnode, transponderid);
918                                                        status.writetransponder = 1;
919                                                }
920                                        }
921                                        deltransponderbyid(99);
922                                        if(timernode->aktion != START) break;
923                                }
924                                if(timernode->aktion != START) break;
925                        }
926                        if(timernode->aktion != START) break;
927                }
928                if(timernode->aktion != START) break;
929        }
930
931        return 0;
932}
933
934unsigned int terrblindscan(struct stimerthread* timernode, int onlycalc)
935{
936        int festatus = 0;
937        uint64_t transponderid = 0;
938        unsigned char* buf = NULL;
939        struct dvbdev* fenode = NULL;
940        struct transponder* tpnode = NULL;
941
942        unsigned int frequency = 0;
943        int hp = 0, lp = 0, modulation = 0, bandwidth = 0, transmission = 0, guardinterval = 0, hierarchy = 0;
944
945        unsigned int minfrequency = getconfigint("tblindminfrequency", NULL) * 1000;
946        unsigned int maxfrequency = getconfigint("tblindmaxfrequency", NULL) * 1000;
947        unsigned int stepfrequency = getconfigint("tblindstepfrequency", NULL) * 1000;
948
949        int minhp = 0, maxhp = 3, stephp = 1;
950        int minlp = 0, maxlp = 3, steplp = 1;
951        int minmodulation = 0, maxmodulation = 2, stepmodulation = 1;
952        int minbandwidth = 0, maxbandwidth = 2, stepbandwidth = 1;
953        int mintransmission = 0, maxtransmission = 1, steptransmission = 1;
954        int minguardinterval = 0, maxguardinterval = 3, stepguardinterval = 1;
955        int minhierarchy = 0, maxhierarchy = 3, stephierarchy = 1;
956
957        int countfrequency = ((maxfrequency + stepfrequency) - minfrequency) / stepfrequency;
958        int counthp = ((maxhp + stephp) - minhp) / stephp;
959        int countlp = ((maxlp + steplp) - minlp) / steplp;
960        int countmodulation = ((maxmodulation + stepmodulation) - minmodulation) / stepmodulation;
961        int countbandwidth = ((maxbandwidth + stepbandwidth) - minbandwidth) / stepbandwidth;
962        int counttransmission = ((maxtransmission + steptransmission) - mintransmission) / steptransmission;
963        int countguardinterval = ((maxguardinterval + stepguardinterval) - minguardinterval) / stepguardinterval;
964        int counthierarchy = ((maxhierarchy + stephierarchy) - minhierarchy) / stephierarchy;
965
966        if(onlycalc == 1) return counthierarchy * countguardinterval * countmodulation * counttransmission * countfrequency * countbandwidth * countlp * counthp;
967
968        if(scaninfo.fenode == NULL || timernode == NULL) return -1;
969        int timeout = scaninfo.timeout / 5;
970        if(timeout < 1000000) timeout = 1000000;
971        scaninfo.blindmax += counthierarchy * countguardinterval * countmodulation * counttransmission * countfrequency * countbandwidth * countlp * counthp;
972
973        for(frequency = minfrequency; frequency <= maxfrequency; frequency += stepfrequency)
974        {
975
976                for(hp = minhp; hp <= maxhp; hp += stephp)
977                {
978
979                        for(lp = minlp; lp <= maxlp; lp += steplp)
980                        {
981
982                                for(modulation = minmodulation; modulation <= maxmodulation; modulation += stepmodulation)
983                                {
984
985                                        for(bandwidth = minbandwidth; bandwidth <= maxbandwidth; bandwidth += stepbandwidth)
986                                        {
987
988                                                for(transmission = mintransmission; transmission <= maxtransmission; transmission += steptransmission)
989                                                {
990
991                                                        for(guardinterval = minguardinterval; guardinterval <= maxguardinterval; guardinterval += stepguardinterval)
992                                                        {
993
994                                                                for(hierarchy = minhierarchy; hierarchy <= maxhierarchy; hierarchy += stephierarchy)
995                                                                {
996                                                                        scaninfo.blindcount++;
997
998                                                                        tpnode = createtransponder(99, scaninfo.fenode->feinfo->type, scaninfo.orbitalpos, frequency, INVERSION_AUTO, bandwidth, lp, hp, modulation, guardinterval, transmission, hierarchy);
999
1000                                                                        debug(500, "blindscan: frequ=%d, modulation=%d, hp=%d, lp=%d, bandwidth=%d, guardinterval=%d, transmission=%d, hierarchy=%d, orbitalpos=%d", frequency, modulation, hp, lp, bandwidth, guardinterval, transmission, hierarchy, scaninfo.orbitalpos);
1001
1002                                                                        if(tpnode != NULL)
1003                                                                        {
1004
1005                                                                                fenode = fegetfree(tpnode, 0, scaninfo.fenode);
1006                                                                                if(fenode == NULL )
1007                                                                                {
1008                                                                                        debug(500, "Frontend for scan not free");
1009                                                                                        deltransponderbyid(99);
1010                                                                                        continue;
1011                                                                                }
1012
1013                                                                                //frontend tune
1014                                                                                if(fenode->feinfo->type == FE_OFDM)
1015                                                                                {
1016                                                                                        feset(fenode, tpnode);
1017                                                                                        fetunedvbs(fenode, tpnode);
1018                                                                                }
1019                                                                                else
1020                                                                                {
1021                                                                                        debug(500, "Frontend type unknown");
1022                                                                                        deltransponderbyid(99);
1023                                                                                        continue;
1024                                                                                }
1025
1026                                                                                festatus = fewait(fenode);
1027                                                                                if(debug_level == 200) fereadstatus(fenode);
1028                                                                                if(festatus != 0)
1029                                                                                {
1030                                                                                        debug(500, "tuning failed");
1031                                                                                        deltransponderbyid(99);
1032                                                                                        continue;
1033                                                                                }
1034
1035                                                                                buf = dvbgetsdt(fenode, 0, timeout);
1036                                                                                transponderid = findtransponderid(fenode, buf);
1037                                                                                free(buf); buf = NULL;
1038
1039                                                                                if(transponderid == 0 || gettransponder(transponderid) != NULL)
1040                                                                                {
1041                                                                                        deltransponderbyid(99);
1042                                                                                        continue;
1043                                                                                }
1044
1045                                                                                if(tpnode->id != transponderid)
1046                                                                                {
1047                                                                                        struct transponder* tphelp = gettransponder(transponderid);
1048                                                                                        if(tphelp != NULL)
1049                                                                                        {
1050                                                                                                deltransponderbyid(transponderid);
1051                                                                                                debug(500, "delete old tid: %llu", transponderid);
1052                                                                                        }
1053                                                                                        scaninfo.newblindcount++;
1054                                                                                        changetransponderid(tpnode, transponderid);
1055                                                                                        status.writetransponder = 1;
1056                                                                                }
1057                                                                        }
1058                                                                        deltransponderbyid(99);
1059                                                                        if(timernode->aktion != START) break;
1060                                                                }
1061                                                                if(timernode->aktion != START) break;
1062                                                        }
1063                                                        if(timernode->aktion != START) break;
1064                                                }
1065                                                if(timernode->aktion != START) break;
1066                                        }
1067                                        if(timernode->aktion != START) break;
1068                                }
1069                                if(timernode->aktion != START) break;
1070                        }
1071                        if(timernode->aktion != START) break;
1072                }
1073                if(timernode->aktion != START) break;
1074        }
1075
1076        return 0;
1077}
1078
1079void blindscan(struct stimerthread* timernode)
1080{
1081        if(scaninfo.fenode == NULL) return;
1082
1083        if(scaninfo.fenode->feinfo->type == FE_QPSK)
1084                satblindscan(timernode, 0);
1085        else if(scaninfo.fenode->feinfo->type == FE_QAM)
1086                cableblindscan(timernode, 0);
1087        else if(scaninfo.fenode->feinfo->type == FE_OFDM)
1088                terrblindscan(timernode, 0);
1089}
1090
1091void doscan(struct stimerthread* timernode)
1092{
1093        int festatus = 0, secnr = 0;
1094        uint8_t lastsecnr = 0xff;
1095        unsigned char* buf = NULL;
1096        struct transponder* tpnode = NULL;
1097        struct dvbdev* fenode = NULL;
1098        //struct channel* chnode = NULL;
1099        struct sat* satnode = sat;
1100        int nitscan = 1;
1101
1102        if(scaninfo.fenode == NULL || scaninfo.tpnode == NULL || timernode == NULL)
1103        {
1104                scaninfo.threadend = 1;
1105                return;
1106        }
1107
1108        debug(500, "channel scan thread start");
1109
1110        //sat loop
1111        satnode = sat;
1112        while(satnode != NULL && timernode->aktion == START)
1113        {
1114                if(satnode->scan == 0)
1115                {
1116                        satnode = satnode->next;
1117                        continue;
1118                }
1119                scaninfo.satname = satnode->name;
1120
1121                if(scaninfo.scantype == 0)
1122                        tpnode = scaninfo.tpnode;
1123                else if(scaninfo.scantype == 1)
1124                        tpnode = transponder;
1125                else if(scaninfo.scantype == 2 || scaninfo.scantype == 3)
1126                {
1127                        tpnode = transponder;
1128                        scaninfo.orbitalpos = satnode->orbitalpos;
1129                }
1130
1131                if(scaninfo.blindscan == 1) blindscan(timernode);
1132
1133                nitscan = 1;
1134                //transponder loop
1135                while(tpnode != NULL && timernode->aktion == START)
1136                {
1137                        if(scaninfo.orbitalpos != tpnode->orbitalpos)
1138                        {
1139                                tpnode = tpnode->next;
1140                                if(scaninfo.scantype == 0) break;
1141                                continue;
1142                        }
1143
1144                        fenode = fegetfree(tpnode, 0, scaninfo.fenode);
1145                        if(fenode == NULL || (scaninfo.scantype != 3 && fenode != scaninfo.fenode))
1146                        {
1147                                scaninfo.tpcount++;
1148                                tpnode = tpnode->next;
1149                                debug(500, "Frontend for scan not free");
1150                                if(scaninfo.scantype == 0) break;
1151                                continue;
1152                        }
1153
1154                        //frontend tune
1155                        if(fenode->feinfo->type == FE_QPSK)
1156                        {
1157                                feset(fenode, tpnode);
1158                                if(fetunedvbs(fenode, tpnode) != 0)
1159                                {
1160                                        scaninfo.tpcount++;
1161                                        if(scaninfo.cleartransponder == 1)
1162                                        {
1163                                                debug(500, "delete tuning failed id=%llu freq=%d orbitalpos=%d tpnode=%p", tpnode->id, tpnode->frequency, tpnode->orbitalpos, tpnode);
1164                                                deltransponderonscan(tpnode->id, tpnode->frequency, tpnode->orbitalpos);
1165                                        }
1166                                        tpnode = tpnode->next;
1167                                        debug(500, "tuning failed");
1168                                        if(scaninfo.scantype == 0) break;
1169                                        continue;
1170                                }
1171                        }
1172                        else if(fenode->feinfo->type == FE_QAM)
1173                        {
1174                                if(fetunedvbc(fenode, tpnode) != 0)
1175                                {
1176                                        scaninfo.tpcount++;
1177                                        if(scaninfo.cleartransponder == 1)
1178                                        {
1179                                                debug(500, "delete tuning failed id=%llu freq=%d orbitalpos=%d tpnode=%p", tpnode->id, tpnode->frequency, tpnode->orbitalpos, tpnode);
1180                                                deltransponderonscan(tpnode->id, tpnode->frequency, tpnode->orbitalpos);
1181                                        }
1182                                        tpnode = tpnode->next;
1183                                        debug(500, "tuning failed");
1184                                        if(scaninfo.scantype == 0) break;
1185                                        continue;
1186                                }
1187                        }
1188                        else if(fenode->feinfo->type == FE_OFDM)
1189                        {
1190                                if(fetunedvbt(fenode, tpnode) != 0)
1191                                {
1192                                        scaninfo.tpcount++;
1193                                        if(scaninfo.cleartransponder == 1)
1194                                        {
1195                                                debug(500, "delete tuning failed id=%llu freq=%d orbitalpos=%d tpnode=%p", tpnode->id, tpnode->frequency, tpnode->orbitalpos, tpnode);
1196                                                deltransponderonscan(tpnode->id, tpnode->frequency, tpnode->orbitalpos);
1197                                        }
1198                                        tpnode = tpnode->next;
1199                                        debug(500, "tuning failed");
1200                                        if(scaninfo.scantype == 0) break;
1201                                        continue;
1202                                }
1203                        }
1204                        else
1205                        {
1206                                scaninfo.tpcount++;
1207                                tpnode = tpnode->next;
1208                                debug(500, "Frontend type unknown");
1209                                if(scaninfo.scantype == 0) break;
1210                                continue;
1211                        }
1212
1213                        festatus = fewait(fenode);
1214                        if(debug_level == 200) fereadstatus(fenode);
1215                        if(festatus != 0)
1216                        {
1217                                scaninfo.tpcount++;
1218                                if(scaninfo.cleartransponder == 1)
1219                                {
1220                                        debug(500, "delete tuning failed id=%llu freq=%d orbitalpos=%d tpnode=%p", tpnode->id, tpnode->frequency, tpnode->orbitalpos, tpnode);
1221                                        deltransponderonscan(tpnode->id, tpnode->frequency, tpnode->orbitalpos);
1222                                }
1223                                tpnode = tpnode->next;
1224                                debug(500, "tuning failed last");
1225                                if(scaninfo.scantype == 0) break;
1226                                continue;
1227                        }
1228
1229                        //del channels from transponder if selected
1230                        //if(scaninfo.scantype != 3 && scaninfo.clear == 1)
1231                        //{
1232                        //      struct channel* tmpchannel = NULL;
1233                        //      chnode = channel;
1234                        //      while(chnode != NULL)
1235                        //      {
1236                        //              tmpchannel = chnode->next;
1237                        //              if(chnode->transponder == tpnode)
1238                        //                      delchannel(chnode->serviceid, chnode->transponderid, 1);
1239                        //              chnode = tmpchannel;
1240                        //      }
1241                        //}
1242
1243                        //get nit
1244                        if(scaninfo.networkscan == 1 && nitscan == 1)
1245                        {
1246                                lastsecnr = 0xff;
1247                                secnr = 0;
1248                                while(secnr <= lastsecnr && secnr <= 256)
1249                                {
1250                                        if(timernode->aktion != START) break;
1251                                        buf = dvbgetnit(fenode, secnr, scaninfo.timeout * 2);
1252                                        if(buf != NULL)
1253                                        {
1254                                                parsenit(buf, &lastsecnr, satnode->orbitalpos);
1255                                                nitscan = 1; //1 = scan all transponder for nit / 0 = scan only first transponder for nit
1256                                        }
1257                                        else
1258                                                break;
1259                                        free(buf); buf = NULL;
1260                                        secnr++;
1261                                }
1262                        }
1263
1264                        lastsecnr = 0xff;
1265                        secnr = 0;
1266                        while(secnr <= lastsecnr && secnr <= 256)
1267                        {
1268                                if(timernode->aktion != START) break;
1269#ifndef SIMULATE
1270                                buf = dvbgetsdt(fenode, secnr, scaninfo.timeout);
1271#endif
1272                                if(buf != NULL)
1273                                        findchannel(fenode, tpnode, buf, &lastsecnr, scaninfo.scanscreen, scaninfo.listbox, scaninfo.changename, 0);
1274                                else
1275                                        break;
1276                                free(buf); buf = NULL;
1277                                secnr++;
1278                        }
1279
1280                        scaninfo.tpcount++;
1281                        if(scaninfo.scantype == 0) break;
1282                        tpnode = tpnode->next;
1283                }
1284                if(scaninfo.scantype == 0 || scaninfo.scantype == 1) break;
1285                satnode = satnode->next;
1286        }
1287        scaninfo.threadend = 1;
1288        debug(500, "channel scan thread end");
1289}
1290
1291void scanaddchannel(struct skin* node, int scantype, struct transponder* tp1, int ichangename)
1292{
1293        int serviceid = 0;
1294        uint64_t transponderid = 0;
1295        int servicetype = 0;
1296        int providerid = 0;
1297        struct provider* providernode = NULL;
1298        char* tmpstr = NULL;
1299        struct transponder* tp2 = NULL;
1300        struct channel* chnode = NULL;
1301
1302        if(node == NULL || node->name == NULL) return;
1303
1304        serviceid = ((uint64_t*)node->name)[0];
1305        transponderid = ((uint64_t*)node->name)[1];
1306        servicetype = ((uint64_t*)node->name)[2];
1307
1308        chnode = getchannel(serviceid, transponderid);
1309        if(chnode == NULL || (chnode != NULL && chnode->transponder == NULL))
1310        {
1311                //check if provider valid
1312                providernode = getproviderbyname(node->param1);
1313                if(providernode != NULL)
1314                        providerid = providernode->providerid;
1315                else
1316                {
1317                        providerid = getlastproviderid() + 1;
1318                        tmpstr = ostrcat(tmpstr, oitoa(providerid), 1, 1);
1319                        tmpstr = ostrcat(tmpstr, "#", 1, 0);
1320                        tmpstr = ostrcat(tmpstr, node->param1, 1, 0);
1321                        tmpstr = ostrcat(tmpstr, "#0", 1, 0);
1322                        addprovider(tmpstr, 1, NULL);
1323                        free(tmpstr); tmpstr = NULL;
1324                }
1325
1326                //check if transponder valid
1327                if(scantype == 0)
1328                {
1329                        tp2 = gettransponder(transponderid);
1330
1331                        if(tp2 == NULL && tp1 != NULL)
1332                        {
1333                                tp2 = gettransponderbydetail(0, tp1->fetype, tp1->orbitalpos, tp1->frequency, tp1->inversion, tp1->symbolrate, tp1->polarization, tp1->fec, tp1->modulation, tp1->rolloff, tp1->pilot, tp1->system, 1);
1334                                if(tp2 != NULL)
1335                                        changetransponderid(tp2, transponderid);
1336                        }
1337
1338                        if(tp2 == NULL) //create new transponder
1339                                copytransponder(tp1, tp2, transponderid);
1340                        else //change transponder
1341                                copytransponder(tp1, tp2, 99);
1342                }
1343
1344                if(servicetype != 0 && servicetype != 1)
1345                        servicetype = 0;
1346
1347                if(chnode == NULL)
1348                {
1349                        if(createchannel(node->param2, transponderid, providerid, serviceid, servicetype, 0, -1, -1, -1, -1, 0, -1) != NULL)
1350                                node->fontcol = convertcol("deaktivcol");
1351                }
1352                else
1353                        node->fontcol = convertcol("deaktivcol");
1354        }
1355        else
1356        {
1357                node->fontcol = convertcol("deaktivcol");
1358                //change channel name if selected
1359                if(ichangename == 1 && node->param2 != NULL && strlen(node->param2) > 0 && ostrcmp(node->param2, chnode->name) != 0)
1360                {
1361                        free(chnode->name);
1362                        chnode->name = ostrcat(node->param2, NULL, 0, 0);
1363                        status.writetransponder = 1;
1364                }
1365        }
1366}
1367
1368void scansetallsat(int fetype)
1369{
1370        int i = 0, orbitalpos = 0;
1371        struct sat* satnode = NULL;
1372        struct dvbdev* dvbnode = dvbdev;
1373        char* tmpstr = NULL, *tmpnr = NULL;
1374
1375        while(dvbnode != NULL)
1376        {
1377                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL && dvbnode->felock < 1 && dvbnode->deactive == 0 && (fetype == -1 || dvbnode->feinfo->type == fetype))
1378                {
1379
1380                        tmpstr = ostrcat(dvbnode->feshortname, "_sat", 0, 0);
1381                        for(i = 1; i <= getmaxsat(dvbnode->feshortname); i++)
1382                        {
1383                                tmpnr = oitoa(i);
1384                                orbitalpos = getconfigint(tmpstr, tmpnr);
1385                                free(tmpnr); tmpnr = NULL;
1386
1387                                satnode = getsatbyorbitalpos(orbitalpos);
1388                                if(satnode != NULL && (fetype == -1 || satnode->fetype == fetype))
1389                                        satnode->scan = 1;
1390                        }
1391                        free(tmpstr); tmpstr = NULL;
1392                }
1393                dvbnode = dvbnode->next;
1394        }
1395}
1396
1397void scansetmultisat(struct skin* scan)
1398{
1399        struct skin* node = scan;
1400        struct sat* satnode = NULL;
1401
1402        while(node != NULL && node->name != NULL)
1403        {
1404                if(ostrcmp(node->ret, "1") == 0)
1405                {
1406                        satnode = getsatbyorbitalpos(atoi(node->name));
1407                        if(satnode != NULL)
1408                                satnode->scan = 1;
1409                }
1410                node = node->next;
1411        }
1412}
1413
1414void delchannelbysat(int orbitalpos)
1415{
1416        struct transponder* transpondernode = transponder;
1417        struct channel* chnode = NULL;
1418
1419        while(transpondernode != NULL)
1420        {
1421                if(transpondernode->orbitalpos == orbitalpos)
1422                {
1423                        struct channel* tmpchannel = NULL;
1424                        chnode = channel;
1425                        while(chnode != NULL)
1426                        {
1427                                tmpchannel = chnode->next;
1428                                if(chnode->transponder == transpondernode)
1429                                        delchannel(chnode->serviceid, chnode->transponderid, 1);
1430                                chnode = tmpchannel;
1431                        }
1432                }
1433                transpondernode = transpondernode->next;
1434        }
1435}
1436
1437void delchannelbymultisat()
1438{
1439        struct sat* satnode = sat;
1440
1441        while(satnode != NULL)
1442        {
1443                if(satnode->scan == 1)
1444                        delchannelbysat(satnode->orbitalpos);
1445                satnode = satnode->next;
1446        }
1447}
1448
1449void screenscan(struct transponder* transpondernode, struct skin* mscan, char* tuner, int scantype, int orbitalpos, unsigned int frequency, int inversion, unsigned int symbolrate, int polarization, int fec, int modulation, int rolloff, int pilot, int networkscan, int onlyfree, int clear, int blindscan, int ichangename, int system, int favtype, int emptybouquet, int unusedbouquetchannels, int unusedsatprovider, int cleartransponder, int timeout, int flag)
1450{
1451        int rcret = 0, tpmax = 0, i = 0, alladded = 0, endmsgshow = 0, tpdel = 0;
1452
1453        struct skin* scan = NULL;
1454        if(flag == 1)
1455                scan = getscreen("scanauto");
1456        else
1457                scan = getscreen("scanmanual");
1458
1459        struct skin* progress = getscreennode(scan, "progress");
1460        struct skin* listbox = getscreennode(scan, "listbox");
1461        struct skin* satname = getscreennode(scan, "satname");
1462        struct skin* tpcount = getscreennode(scan, "tpcount");
1463        struct skin* foundtv = getscreennode(scan, "foundtv");
1464        struct skin* foundradio = getscreennode(scan, "foundradio");
1465        struct skin* founddata = getscreennode(scan, "founddata");
1466        struct skin* foundblind = getscreennode(scan, "foundblind");
1467        struct skin* b2 = getscreennode(scan, "b2");
1468        struct skin* b3 = getscreennode(scan, "b3");
1469        struct skin* load = getscreen("loading");
1470        struct transponder* tpnode = NULL;
1471        struct dvbdev* fenode = NULL, *dvbnode = dvbdev;
1472        struct stimerthread* timernode = NULL;
1473        struct sat* satnode = NULL;
1474        struct channel* chnode = NULL;
1475        char* tmpstr = NULL;
1476
1477        listbox->aktline = 1;
1478        listbox->aktpage = -1;
1479        progress->progresssize = 0;
1480        memset(&scaninfo, 0, sizeof(struct scaninfo));
1481
1482        b2->hidden = NO;
1483        b3->hidden = NO;
1484
1485        addscreenrc(scan, listbox);
1486        if(scantype != 3)
1487        {
1488                while(dvbnode != NULL)
1489                {
1490                        if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL && dvbnode->felock < 1)
1491                        {
1492                                if(ostrcmp(dvbnode->feshortname, tuner) == 0)
1493                                {
1494                                        fenode = dvbnode;
1495                                        break;
1496                                }
1497                        }
1498                        dvbnode = dvbnode->next;
1499                }
1500                if(fenode == NULL) return;
1501        }
1502        else if(scantype == 3)
1503                fenode = dvbdev;
1504
1505        if(scantype == 0) //single transponder
1506        {
1507                if(fenode != NULL && fenode->feinfo != NULL)
1508                {
1509                        //del channels from transponder if selected
1510                        if(clear == 1)
1511                        {
1512                                struct channel* tmpchannel = NULL;
1513                                chnode = channel;
1514                                while(chnode != NULL)
1515                                {
1516                                        tmpchannel = chnode->next;
1517                                        if(chnode->transponder == transpondernode)
1518                                                delchannel(chnode->serviceid, chnode->transponderid, 1);
1519                                        chnode = tmpchannel;
1520                                }
1521                        }
1522
1523                        debug(500, "fetype=%d, orbitalpos=%d, frequ=%d, inverion=%d, symbolrate=%d, polarization=%d, fec=%d, modulation=%d, rolloff=%d, pilot=%d, system=%d", fenode->feinfo->type, orbitalpos, frequency, inversion, symbolrate, polarization, fec, modulation, rolloff, pilot, system);
1524                        tpnode = createtransponder(99, fenode->feinfo->type, orbitalpos, frequency, inversion, symbolrate, polarization, fec, modulation, rolloff, pilot, system);
1525                }
1526                if(tpnode != NULL)
1527                {
1528                        tpmax = 1;
1529                        satnode = getsatbyorbitalpos(tpnode->orbitalpos);
1530                        if(satnode != NULL) satnode->scan = 1;
1531                }
1532        }
1533        else if(scantype == 1) //single sat
1534        {
1535                if(clear == 1) delchannelbysat(orbitalpos);
1536                tpnode = transponder;
1537                while(tpnode != NULL)
1538                {
1539                        if(tpnode->orbitalpos == orbitalpos)
1540                                tpmax++;
1541                        tpnode = tpnode->next;
1542                }
1543                tpnode = transponder;
1544                satnode = getsatbyorbitalpos(orbitalpos);
1545                if(satnode != NULL) satnode->scan = 1;
1546        }
1547        else if(scantype == 2 || scantype == 3) //2: multi sat, 3: all
1548        {
1549                if(scantype == 2)
1550                {
1551                        scansetmultisat(mscan);
1552                        if(clear == 1) delchannelbymultisat();
1553                }
1554                if(scantype == 3)
1555                {
1556                        scansetallsat(-1);
1557                        b2->hidden = YES;
1558                        b3->hidden = YES;
1559                        //del all channel for auto. search
1560                        if(clear == 1)
1561                        {
1562                                freechannel(1);
1563                                if(unusedsatprovider == 1)
1564                                {
1565                                        delunusedsat();
1566                                        delunusedtransponder();
1567                                        delunusedchannel();
1568                                        //delunusedepgchannel();
1569                                        delunusedprovider();
1570                                }
1571                        }
1572                }
1573
1574                satnode = sat;
1575                while(satnode != NULL)
1576                {
1577                        if(satnode->scan != 0)
1578                        {
1579                                tpnode = transponder;
1580                                while(tpnode != NULL)
1581                                {
1582                                        if(tpnode->orbitalpos == satnode->orbitalpos)
1583                                                tpmax++;
1584                                        tpnode = tpnode->next;
1585                                }
1586                        }
1587                        satnode = satnode->next;
1588                }
1589                tpnode = transponder;
1590        }
1591
1592        scaninfo.fenode = fenode;
1593        scaninfo.tpnode = tpnode;
1594        scaninfo.scanscreen = scan;
1595        scaninfo.listbox = listbox;
1596        scaninfo.timeout = timeout;
1597        scaninfo.scantype = scantype;
1598        scaninfo.orbitalpos = orbitalpos;
1599        scaninfo.onlyfree = onlyfree;
1600        scaninfo.networkscan = networkscan;
1601        scaninfo.blindscan = blindscan;
1602        scaninfo.changename = ichangename;
1603        scaninfo.clear = clear;
1604        scaninfo.tpmax = tpmax;
1605        scaninfo.tpdel = tpdel;
1606        scaninfo.cleartransponder = cleartransponder;
1607        timernode = addtimer(&doscan, START, 1000, 1, NULL, NULL, NULL);
1608
1609        while(1)
1610        {
1611                //satname
1612                tmpstr = ostrcat(tmpstr, _("Sat/Provider: "), 1, 0);
1613                tmpstr = ostrcat(tmpstr, scaninfo.satname, 1, 0);
1614                changetext(satname, tmpstr);
1615                free(tmpstr); tmpstr = NULL;
1616
1617                //transpondercount
1618                tmpstr = ostrcat(tmpstr, _("Transponder: "), 1, 0);
1619                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpcount), 1, 1);
1620                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1621                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpmax), 1, 1);
1622                tmpstr = ostrcat(tmpstr, _(" New: "), 1, 0);
1623                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpnew), 1, 1);
1624                tmpstr = ostrcat(tmpstr, _(" Del: "), 1, 0);
1625                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpdel), 1, 1);
1626                changetext(tpcount, tmpstr);
1627                free(tmpstr); tmpstr = NULL;
1628
1629                //tvcount
1630                tmpstr = ostrcat(tmpstr, _("TV: "), 1, 0);
1631                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newtvcount), 1, 1);
1632                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1633                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tvcount), 1, 1);
1634                changetext(foundtv, tmpstr);
1635                free(tmpstr); tmpstr = NULL;
1636
1637                //radiocount
1638                tmpstr = ostrcat(tmpstr, _("Radio: "), 1, 0);
1639                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newradiocount), 1, 1);
1640                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1641                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.radiocount), 1, 1);
1642                changetext(foundradio, tmpstr);
1643                free(tmpstr); tmpstr = NULL;
1644
1645                //datacount
1646                tmpstr = ostrcat(tmpstr, _("Data: "), 1, 0);
1647                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newdatacount), 1, 1);
1648                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1649                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.datacount), 1, 1);
1650                changetext(founddata, tmpstr);
1651                free(tmpstr); tmpstr = NULL;
1652
1653                //blindcount
1654                tmpstr = ostrcat(tmpstr, _("Blindscan: "), 1, 0);
1655                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newblindcount), 1, 1);
1656                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1657                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.blindcount), 1, 1);
1658                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1659                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.blindmax), 1, 1);
1660                changetext(foundblind, tmpstr);
1661                free(tmpstr); tmpstr = NULL;
1662
1663                if(scaninfo.tpmax == 0)
1664                        progress->progresssize = 100;
1665                else
1666                        progress->progresssize = (100 / (float)scaninfo.tpmax) * scaninfo.tpcount;
1667
1668                drawscreen(scan, 0, 0);
1669                rcret = waitrc(scan, 1000, 0);
1670
1671                if(scantype != 3 && scaninfo.threadend == 1 && endmsgshow == 0)
1672                {
1673                        if(scaninfo.tvcount + scaninfo.radiocount + scaninfo.datacount == 0)
1674                                textbox(_("Message"), _("Channel scan ended.\nNothing found."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
1675                        else
1676                                textbox(_("Message"), _("Channel scan ended."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
1677                        endmsgshow = 1;
1678                }
1679
1680                if(scantype != 3 && rcret == getrcconfigint("rcred", NULL))
1681                        scanaddchannel(listbox->select, scantype, tpnode, ichangename);
1682
1683                if((scantype != 3 && rcret == getrcconfigint("rcgreen", NULL)) || (scantype == 3 && scaninfo.threadend == 1 && alladded < 2))
1684                {
1685                        struct skin* lnode = listbox;
1686
1687                        long deaktivcol = convertcol("deaktivcol");
1688                        if(scantype == 3 && alladded == 0)
1689                        {
1690                                alladded = 1;
1691                                continue;
1692                        }
1693                        alladded = 2;
1694
1695                        drawscreen(load, 0, 0);
1696                        while(lnode != NULL)
1697                        {
1698                                if(lnode->fontcol != deaktivcol && lnode->del == 1)
1699                                        scanaddchannel(lnode, scantype, tpnode, ichangename);
1700                                lnode = lnode->next;
1701                        }
1702                        clearscreen(load);
1703                        if(scaninfo.tvcount + scaninfo.radiocount + scaninfo.datacount == 0)
1704                                textbox(_("Message"), _("Channel scan ended.\nNothing found."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
1705                        else
1706                                textbox(_("Message"), _("Scan completed, changes have been saved."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
1707                }
1708
1709                if(rcret == getrcconfigint("rcexit", NULL))
1710                {
1711                        if(timernode != NULL && scaninfo.threadend == 0)
1712                        {
1713                                timernode->aktion = STOP;
1714                                while(i < 4 && scaninfo.threadend == 0)
1715                                {
1716                                        textbox(_("Message"), _("Wait for channel scan end"), NULL, 0, NULL, 0, NULL, 0, NULL, 0, 800, 200, 3, 0);
1717                                        i++;
1718                                }
1719                        }
1720                        break;
1721                }
1722        }
1723
1724        if(scantype == 0) deltransponderbyid(99);
1725        if(clear == 1)
1726        {
1727                // favtype 0 = unchanged
1728                // favtype 1 = create new
1729                // favtype 2 = delete
1730
1731                if(favtype == 1)
1732                {
1733                        freemainbouquet(1);
1734                        struct provider *pnode = provider;
1735
1736                        while(pnode != NULL)
1737                        {
1738                                provider2bouquet(pnode->providerid, 1);
1739                                pnode = pnode->next;
1740                        }
1741                }
1742                else if(favtype == 2)
1743                        freemainbouquet(1);
1744
1745                if(emptybouquet == 1)
1746                        delemptymainbouquet(1);
1747
1748                if(unusedbouquetchannels == 1)
1749                        delunusedbouquetchannels(0);
1750                else
1751                        delunusedbouquetchannels(1);
1752
1753                if(cleartransponder == 1 && unusedsatprovider == 1)
1754                        deltransponderbyid(0);
1755        }
1756        delmarkedscreennodes(scan, 1);
1757        delownerrc(scan);
1758        clearscreen(scan);
1759        resetsatscan();
1760        drawscreen(load, 0, 0);
1761        sortchannel();
1762        sortprovider();
1763        clearscreen(load);
1764}
1765
1766void changescantype(char* scantype, struct skin* scan, struct skin* listbox, struct skin* tuner, struct skin* satellite, struct skin* id, struct skin* system, struct skin* frequency, struct skin* inversion, struct skin* symbolrate, struct skin* polarization, struct skin* fec, struct skin* modulation, struct skin* rolloff, struct skin* pilot, struct skin* hp, struct skin* lp, struct skin* bandwidth, struct skin* transmission, struct skin* guardinterval, struct skin* hierarchy, struct skin* b4, struct skin* b5, int flag)
1767{
1768        struct sat* satnode = sat;
1769        struct skin* tmp = NULL;
1770        char* tmpstr = NULL, *tmpstr1 = NULL, *tmpnr = NULL;
1771        char* feshortname = NULL;
1772        int i, orbitalpos = 0;
1773
1774        if(tuner != NULL) feshortname = tuner->ret;
1775
1776        tuner->hidden = NO;
1777        id->hidden = NO;
1778        system->hidden = NO;
1779        frequency->hidden = NO;
1780        inversion->hidden = NO;
1781        symbolrate->hidden = NO;
1782        polarization->hidden = NO;
1783        fec->hidden = NO;
1784        modulation->hidden = NO;
1785        rolloff->hidden = NO;
1786        pilot->hidden = NO;
1787        hp->hidden = NO;
1788        lp->hidden = NO;
1789        bandwidth->hidden = NO;
1790        transmission->hidden = NO;
1791        guardinterval->hidden = NO;
1792        hierarchy->hidden = NO;
1793        satellite->hidden = NO;
1794        b4->hidden = NO;
1795        b5->hidden = NO;
1796        delmarkedscreennodes(scan, 1);
1797
1798        if(flag == 0 && ostrcmp(scantype, "0") == 0 && ostrcmp(system->ret, "0") == 0)
1799        {
1800                modulation->hidden = YES;
1801                rolloff->hidden = YES;
1802                pilot->hidden = YES;
1803        }
1804
1805        if(ostrcmp(scantype, "1") == 0 || ostrcmp(scantype, "2") == 0 || ostrcmp(scantype, "3") == 0)
1806        {
1807                id->hidden = YES;
1808                system->hidden = YES;
1809                frequency->hidden = YES;
1810                inversion->hidden = YES;
1811                symbolrate->hidden = YES;
1812                polarization->hidden = YES;
1813                fec->hidden = YES;
1814                modulation->hidden = YES;
1815                rolloff->hidden = YES;
1816                pilot->hidden = YES;
1817                hp->hidden = YES;
1818                lp->hidden = YES;
1819                bandwidth->hidden = YES;
1820                transmission->hidden = YES;
1821                guardinterval->hidden = YES;
1822                hierarchy->hidden = YES;
1823                b4->hidden = YES;
1824                b5->hidden = YES;
1825        }
1826        if(ostrcmp(scantype, "2") == 0 && feshortname != NULL)
1827        {
1828                satellite->hidden = YES;
1829
1830                tmpstr = ostrcat(feshortname, "_sat", 0, 0);
1831                for(i = 1; i <= getmaxsat(feshortname); i++)
1832                {
1833                        tmpnr = oitoa(i);
1834                        orbitalpos = getconfigint(tmpstr, tmpnr);
1835                        free(tmpnr); tmpnr = NULL;
1836
1837                        satnode = getsatbyorbitalpos(orbitalpos);
1838                        if(satnode != NULL && satnode->fetype == FE_QPSK)
1839                        {
1840                                tmp = addlistbox(scan, listbox, tmp, 1);
1841                                if(tmp != NULL)
1842                                {
1843                                        tmpstr1 = oitoa(satnode->orbitalpos);
1844                                        changename(tmp, tmpstr1);
1845                                        free(tmpstr1); tmpstr1 = NULL;
1846                                        changetext(tmp, satnode->name);
1847                                        tmp->type = CHOICEBOX;
1848                                        addchoicebox(tmp, "0", _("no"));
1849                                        addchoicebox(tmp, "1", _("yes"));
1850                                }
1851                        }
1852                }
1853                free(tmpstr); tmpstr = NULL;
1854        }
1855        if(ostrcmp(scantype, "3") == 0)
1856        {
1857                tuner->hidden = YES;
1858                satellite->hidden = YES;
1859        }
1860
1861        if(flag == 2)
1862        {
1863                system->hidden = YES;
1864                inversion->hidden = YES;
1865                polarization->hidden = YES;
1866                rolloff->hidden = YES;
1867                pilot->hidden = YES;
1868                satellite->hidden = YES;
1869        }
1870
1871        if(flag == 3)
1872        {
1873                system->hidden = YES;
1874                polarization->hidden = YES;
1875                rolloff->hidden = YES;
1876                pilot->hidden = YES;
1877                satellite->hidden = YES;
1878                symbolrate->hidden = YES;
1879                fec->hidden = YES;
1880        }
1881        else
1882        {
1883                hp->hidden = YES;
1884                lp->hidden = YES;
1885                bandwidth->hidden = YES;
1886                transmission->hidden = YES;
1887                guardinterval->hidden = YES;
1888                hierarchy->hidden = YES;
1889        }
1890}
1891
1892void scanchangesat(struct skin* sat, struct transponder* tpnode, char* feshortname)
1893{
1894        char* tmpstr = NULL;
1895
1896        changeinput(sat, NULL);
1897        changechoiceboxvalue(sat, NULL);
1898        tmpstr = getsatstring(feshortname, FE_QPSK);
1899        changeinput(sat, tmpstr);
1900        free(tmpstr); tmpstr = NULL;
1901        tmpstr = getorbitalposstring(feshortname, FE_QPSK);
1902        changechoiceboxvalue(sat, tmpstr);
1903        free(tmpstr); tmpstr = NULL;
1904        if(tpnode != NULL)
1905        {
1906                tmpstr = oitoa(tpnode->orbitalpos);
1907                setchoiceboxselection(sat, tmpstr);
1908                free(tmpstr); tmpstr = NULL;
1909        }
1910}
1911
1912//flag 0: manual scan (DVB-S)
1913//flag 1: auto scan (all)
1914//flag 2: manual scan (DVB-C)
1915//flag 3: manual scan (DVB-T)
1916void screenscanconfig(int flag)
1917{
1918        int rcret = 0, fetype = -1;
1919        unsigned int ifrequency = -1, isymbolrate = -1;
1920        int iscantype = -1, isat = -1;
1921        int iinversion = -1, ipolarization = -1;
1922        int ifec = -1, imodulation = -1, irolloff = -1, ipilot = -1, isystem = -1;
1923        int inetworkscan = -1, ionlyfree = -1, iclear = -1, iblindscan = -1, ichangename = -1;
1924        int ifavtype = -1, iemptybouquet = -1, iunusedbouquetchannels = -1;
1925        int iunusedsatprovider = -1, icleartransponder = -1;
1926
1927        int i = 0, treffer = 0, tunercount = 0;
1928
1929        struct skin* scan = NULL;
1930        if(flag == 1)
1931                scan = getscreen("scanadjustauto");
1932        else
1933                scan = getscreen("scanadjustmanual");
1934
1935        struct skin* listbox = getscreennode(scan, "listbox");
1936        struct skin* tuner = getscreennode(scan, "tuner");
1937        struct skin* scantype = getscreennode(scan, "scantype");
1938        struct skin* sat = getscreennode(scan, "sat");
1939        struct skin* id = getscreennode(scan, "id");
1940        struct skin* system = getscreennode(scan, "system");
1941        struct skin* frequency = getscreennode(scan, "frequency");
1942        struct skin* inversion = getscreennode(scan, "inversion");
1943        struct skin* symbolrate = getscreennode(scan, "symbolrate");
1944        struct skin* polarization = getscreennode(scan, "polarization");
1945        struct skin* fec = getscreennode(scan, "fec");
1946        struct skin* modulation = getscreennode(scan, "modulation");
1947        struct skin* rolloff = getscreennode(scan, "rolloff");
1948        struct skin* pilot = getscreennode(scan, "pilot");
1949        struct skin* hp = getscreennode(scan, "hp");
1950        struct skin* lp = getscreennode(scan, "lp");
1951        struct skin* bandwidth = getscreennode(scan, "bandwidth");
1952        struct skin* transmission = getscreennode(scan, "transmission");
1953        struct skin* guardinterval = getscreennode(scan, "guardinterval");
1954        struct skin* hierarchy = getscreennode(scan, "hierarchy");
1955        struct skin* networkscan = getscreennode(scan, "networkscan");
1956        struct skin* clear = getscreennode(scan, "clear");
1957        struct skin* onlyfree = getscreennode(scan, "onlyfree");
1958        struct skin* blindscan = getscreennode(scan, "blindscan");
1959        struct skin* changename = getscreennode(scan, "changename");
1960        struct skin* favtype = getscreennode(scan, "favtype");
1961        struct skin* emptybouquet = getscreennode(scan, "emptybouquet");
1962        struct skin* unusedsatprovider = getscreennode(scan, "unusedsatprovider");
1963        struct skin* cleartransponder = getscreennode(scan, "cleartransponder");
1964        struct skin* unusedbouquetchannels = getscreennode(scan, "unusedbouquetchannels");
1965
1966        struct skin* b4 = getscreennode(scan, "b4");
1967        struct skin* b5 = getscreennode(scan, "b5");
1968        struct skin* tmp = NULL;
1969        char* tmpstr = NULL, *tmpnr = NULL, *feshortname = NULL;
1970        struct transponder* tpnode = NULL;
1971        struct dvbdev* dvbnode = dvbdev;
1972
1973        listbox->aktline = 1;
1974        listbox->aktpage = -1;
1975
1976        if(status.recording > 0 || status.streaming > 0)
1977        {
1978                textbox(_("Message"), _("Scan is not allowed if record or stream is running !"), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
1979                return;
1980        }
1981
1982        //del old values
1983        changeinput(tuner, NULL);
1984        changechoiceboxvalue(tuner, NULL);
1985        changeinput(scantype, NULL);
1986        changechoiceboxvalue(scantype, NULL);
1987        changeinput(sat, NULL);
1988        changechoiceboxvalue(sat, NULL);
1989        changeinput(system, NULL);
1990        changechoiceboxvalue(system, NULL);
1991        changeinput(inversion, NULL);
1992        changechoiceboxvalue(inversion, NULL);
1993        changeinput(polarization, NULL);
1994        changechoiceboxvalue(polarization, NULL);
1995        changeinput(fec, NULL);
1996        changechoiceboxvalue(fec, NULL);
1997        changeinput(modulation, NULL);
1998        changechoiceboxvalue(modulation, NULL);
1999        changeinput(rolloff, NULL);
2000        changechoiceboxvalue(rolloff, NULL);
2001        changeinput(pilot, NULL);
2002        changechoiceboxvalue(pilot, NULL);
2003        changeinput(hp, NULL);
2004        changeinput(lp, NULL);
2005        changeinput(bandwidth, NULL);
2006        changeinput(transmission, NULL);
2007        changeinput(guardinterval, NULL);
2008        changeinput(hierarchy, NULL);
2009        changechoiceboxvalue(hp, NULL);
2010        changechoiceboxvalue(lp, NULL);
2011        changechoiceboxvalue(bandwidth, NULL);
2012        changechoiceboxvalue(transmission, NULL);
2013        changechoiceboxvalue(guardinterval, NULL);
2014        changechoiceboxvalue(hierarchy, NULL);
2015
2016        frequency->aktpage = 0;
2017        symbolrate->aktpage = 0;
2018
2019        if(flag == 0) fetype = FE_QPSK;
2020        if(flag == 2) fetype = FE_QAM;
2021        if(flag == 3) fetype = FE_OFDM;
2022
2023        //tuner
2024        while(dvbnode != NULL)
2025        {
2026                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL && dvbnode->felock < 1 && dvbnode->deactive == 0 && (flag == 1 || dvbnode->feinfo->type == fetype))
2027                {
2028                        treffer = 0;
2029                        if(dvbnode->feshortname != NULL)
2030                        {
2031                                tmpstr = ostrcat(dvbnode->feshortname, "_sat", 0, 0);
2032                                for(i = 1; i <= getmaxsat(dvbnode->feshortname); i++)
2033                                {
2034                                        tmpnr = oitoa(i);
2035                                        if(getconfigint(tmpstr, tmpnr) != 0)
2036                                        {
2037                                                treffer = 1;
2038                                                break;
2039                                        }
2040                                        free(tmpnr); tmpnr = NULL;
2041                                }
2042                                free(tmpnr); tmpnr = NULL;
2043                                free(tmpstr); tmpstr = NULL;
2044                        }
2045
2046                        if(treffer == 0)
2047                        {
2048                                dvbnode = dvbnode->next;
2049                                continue;
2050                        }
2051
2052                        tunercount++;
2053                        if(feshortname == NULL) feshortname = dvbnode->feshortname;
2054
2055                        tmpstr = ostrcat(tmpstr, dvbnode->feinfo->name, 1, 0);
2056                        tmpstr = ostrcat(tmpstr, " (", 1, 0);
2057                        tmpstr = ostrcat(tmpstr, oitoa(dvbnode->adapter), 1, 1);
2058                        tmpstr = ostrcat(tmpstr, "/", 1, 0);
2059                        tmpstr = ostrcat(tmpstr, oitoa(dvbnode->devnr), 1, 1);
2060                        tmpstr = ostrcat(tmpstr, ")", 1, 0);
2061                        addchoicebox(tuner, dvbnode->feshortname, tmpstr);
2062                        free(tmpstr); tmpstr = NULL;
2063                }
2064                dvbnode = dvbnode->next;
2065        }
2066
2067        if(tunercount < 1)
2068        {
2069                textbox(_("Message"), _("No Tuner configured"), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
2070                return;
2071        }
2072
2073        rcret = servicestop(status.aktservice, 1, 1);
2074        if(rcret == 1) return;
2075
2076        if(status.aktservice->channel != NULL)
2077                tpnode = status.aktservice->channel->transponder;
2078
2079        //clear akt and last channel, so all channel can delete
2080        freechannelhistory();
2081        status.lastservice->channel = NULL;
2082        status.aktservice->channel = NULL;
2083
2084start:
2085
2086        if(flag == 0)
2087        {
2088                addchoicebox(scantype, "0", _("Single Transponder"));
2089                addchoicebox(scantype, "1", _("Single Sat"));
2090                addchoicebox(scantype, "2", _("Multi Sat"));
2091                setchoiceboxselection(scantype, "0");
2092        }
2093        else if(flag == 2 || flag == 3)
2094        {
2095                addchoicebox(scantype, "0", _("Single Transponder"));
2096                addchoicebox(scantype, "1", _("Single Provider"));
2097                setchoiceboxselection(scantype, "0");
2098        }
2099        else
2100        {
2101                addchoicebox(scantype, "3", _("Auto Scan"));
2102                setchoiceboxselection(scantype, "3");
2103        }
2104
2105        //sat
2106        scanchangesat(sat, tpnode, feshortname);
2107
2108        //id
2109        if(tpnode != NULL)
2110                tmpstr = ollutoa(tpnode->id);
2111        changeinput(id, tmpstr);
2112        free(tmpstr); tmpstr = NULL;
2113
2114        //system
2115        tmpstr = transpondergetsystemstr(tpnode, 1);
2116        changeinput(system, tmpstr);
2117        free(tmpstr); tmpstr = NULL;
2118        tmpstr = transpondergetsystemstr(tpnode, 2);
2119        changechoiceboxvalue(system, tmpstr);
2120        free(tmpstr); tmpstr = NULL;
2121        if(tpnode != NULL)
2122        {
2123                tmpstr = oitoa(tpnode->system);
2124                setchoiceboxselection(system, tmpstr);
2125                free(tmpstr); tmpstr = NULL;
2126        }
2127
2128        //frequency
2129        if(tpnode != NULL)
2130                tmpstr = oitoa(tpnode->frequency / 1000);
2131        else
2132        {
2133                if(flag == 3)
2134                        tmpstr = ostrcat(tmpstr, "000000", 1, 0);
2135                else
2136                        tmpstr = ostrcat(tmpstr, "00000", 1, 0);
2137        }
2138        if(flag == 2 || flag == 3)
2139        {
2140                changemask(frequency, "000000");
2141                changeinput(frequency, tmpstr);
2142                frequency->input = mask(frequency->input, 6, "0");
2143        }
2144        else
2145        {
2146                changemask(frequency, "00000");
2147                changeinput(frequency, tmpstr);
2148                frequency->input = mask(frequency->input, 5, "0");
2149        }
2150        free(tmpstr); tmpstr = NULL;
2151
2152        //inversion
2153        tmpstr = transpondergetinversionstr(tpnode, 1);
2154        changeinput(inversion, tmpstr);
2155        free(tmpstr); tmpstr = NULL;
2156        tmpstr = transpondergetinversionstr(tpnode, 2);
2157        changechoiceboxvalue(inversion, tmpstr);
2158        free(tmpstr); tmpstr = NULL;
2159        if(tpnode != NULL)
2160        {
2161                tmpstr = oitoa(tpnode->inversion);
2162                setchoiceboxselection(inversion, tmpstr);
2163                free(tmpstr); tmpstr = NULL;
2164        }
2165
2166        //symbolrate
2167        if(tpnode != NULL)
2168                tmpstr = oitoa(tpnode->symbolrate / 1000);
2169        else
2170                tmpstr = ostrcat(tmpstr, "00000", 1, 0);
2171        changemask(symbolrate, "00000");
2172        changeinput(symbolrate, tmpstr);
2173        symbolrate->input = mask(symbolrate->input, 5, "0");
2174        free(tmpstr); tmpstr = NULL;
2175
2176        //polarization
2177        tmpstr = transpondergetpolarizationstr(tpnode, 1);
2178        changeinput(polarization, tmpstr);
2179        free(tmpstr); tmpstr = NULL;
2180        tmpstr = transpondergetpolarizationstr(tpnode, 2);
2181        changechoiceboxvalue(polarization, tmpstr);
2182        free(tmpstr); tmpstr = NULL;
2183        if(tpnode != NULL)
2184        {
2185                tmpstr = oitoa(tpnode->polarization);
2186                setchoiceboxselection(polarization, tmpstr);
2187                free(tmpstr); tmpstr = NULL;
2188        }
2189
2190        //fec
2191        tmpstr = transpondergetfecstr(tpnode, fetype, 1);
2192        changeinput(fec, tmpstr);
2193        free(tmpstr); tmpstr = NULL;
2194        tmpstr = transpondergetfecstr(tpnode, fetype, 2);
2195        changechoiceboxvalue(fec, tmpstr);
2196        free(tmpstr); tmpstr = NULL;
2197        if(tpnode != NULL)
2198        {
2199                tmpstr = oitoa(tpnode->fec);
2200                setchoiceboxselection(fec, tmpstr);
2201                free(tmpstr); tmpstr = NULL;
2202        }
2203
2204        //modulation
2205        tmpstr = transpondergetmodulationstr(tpnode, fetype, 1);
2206        changeinput(modulation, tmpstr);
2207        free(tmpstr); tmpstr = NULL;
2208        tmpstr = transpondergetmodulationstr(tpnode, fetype, 2);
2209        changechoiceboxvalue(modulation, tmpstr);
2210        free(tmpstr); tmpstr = NULL;
2211        if(tpnode != NULL)
2212        {
2213                tmpstr = oitoa(tpnode->modulation);
2214                setchoiceboxselection(modulation, tmpstr);
2215                free(tmpstr); tmpstr = NULL;
2216        }
2217
2218        //rolloff
2219        tmpstr = transpondergetrolloffstr(tpnode, 1);
2220        changeinput(rolloff, tmpstr);
2221        free(tmpstr); tmpstr = NULL;
2222        tmpstr = transpondergetrolloffstr(tpnode, 2);
2223        changechoiceboxvalue(rolloff, tmpstr);
2224        free(tmpstr); tmpstr = NULL;
2225        if(tpnode != NULL)
2226        {
2227                tmpstr = oitoa(tpnode->rolloff);
2228                setchoiceboxselection(rolloff, tmpstr);
2229                free(tmpstr); tmpstr = NULL;
2230        }
2231
2232        //pilot
2233        tmpstr = transpondergetpilotstr(tpnode, 1);
2234        changeinput(pilot, tmpstr);
2235        free(tmpstr); tmpstr = NULL;
2236        tmpstr = transpondergetpilotstr(tpnode, 2);
2237        changechoiceboxvalue(pilot, tmpstr);
2238        free(tmpstr); tmpstr = NULL;
2239        if(tpnode != NULL)
2240        {
2241                tmpstr = oitoa(tpnode->pilot);
2242                setchoiceboxselection(pilot, tmpstr);
2243                free(tmpstr); tmpstr = NULL;
2244        }
2245
2246        //hp
2247        tmpstr = transpondergetfecstr(tpnode, fetype, 1);
2248        changeinput(hp, tmpstr);
2249        free(tmpstr); tmpstr = NULL;
2250        tmpstr = transpondergetfecstr(tpnode, fetype, 2);
2251        changechoiceboxvalue(hp, tmpstr);
2252        free(tmpstr); tmpstr = NULL;
2253        if(tpnode != NULL)
2254        {
2255                tmpstr = oitoa(tpnode->fec);
2256                setchoiceboxselection(hp, tmpstr);
2257                free(tmpstr); tmpstr = NULL;
2258        }
2259
2260        //lp
2261        tmpstr = transpondergetfecstr(tpnode, fetype, 1);
2262        changeinput(lp, tmpstr);
2263        free(tmpstr); tmpstr = NULL;
2264        tmpstr = transpondergetfecstr(tpnode, fetype, 2);
2265        changechoiceboxvalue(lp, tmpstr);
2266        free(tmpstr); tmpstr = NULL;
2267        if(tpnode != NULL)
2268        {
2269                tmpstr = oitoa(tpnode->polarization);
2270                setchoiceboxselection(lp, tmpstr);
2271                free(tmpstr); tmpstr = NULL;
2272        }
2273
2274        //bandwidth
2275        tmpstr = transpondergetbandwidthstr(tpnode, 1);
2276        changeinput(bandwidth, tmpstr);
2277        free(tmpstr); tmpstr = NULL;
2278        tmpstr = transpondergetbandwidthstr(tpnode, 2);
2279        changechoiceboxvalue(bandwidth, tmpstr);
2280        free(tmpstr); tmpstr = NULL;
2281        if(tpnode != NULL)
2282        {
2283                tmpstr = oitoa(tpnode->symbolrate);
2284                setchoiceboxselection(bandwidth, tmpstr);
2285                free(tmpstr); tmpstr = NULL;
2286        }
2287
2288        //guardinterval
2289        tmpstr = transpondergetguardintervalstr(tpnode, 1);
2290        changeinput(guardinterval, tmpstr);
2291        free(tmpstr); tmpstr = NULL;
2292        tmpstr = transpondergetguardintervalstr(tpnode, 2);
2293        changechoiceboxvalue(guardinterval, tmpstr);
2294        free(tmpstr); tmpstr = NULL;
2295        if(tpnode != NULL)
2296        {
2297                tmpstr = oitoa(tpnode->rolloff);
2298                setchoiceboxselection(guardinterval, tmpstr);
2299                free(tmpstr); tmpstr = NULL;
2300        }
2301
2302        //transmission
2303        tmpstr = transpondergettransmissionstr(tpnode, 1);
2304        changeinput(transmission, tmpstr);
2305        free(tmpstr); tmpstr = NULL;
2306        tmpstr = transpondergettransmissionstr(tpnode, 2);
2307        changechoiceboxvalue(transmission, tmpstr);
2308        free(tmpstr); tmpstr = NULL;
2309        if(tpnode != NULL)
2310        {
2311                tmpstr = oitoa(tpnode->pilot);
2312                setchoiceboxselection(transmission, tmpstr);
2313                free(tmpstr); tmpstr = NULL;
2314        }
2315
2316        //hierarchy
2317        tmpstr = transpondergethierarchystr(tpnode, 1);
2318        changeinput(hierarchy, tmpstr);
2319        free(tmpstr); tmpstr = NULL;
2320        tmpstr = transpondergethierarchystr(tpnode, 2);
2321        changechoiceboxvalue(hierarchy, tmpstr);
2322        free(tmpstr); tmpstr = NULL;
2323        if(tpnode != NULL)
2324        {
2325                tmpstr = oitoa(tpnode->system);
2326                setchoiceboxselection(hierarchy, tmpstr);
2327                free(tmpstr); tmpstr = NULL;
2328        }
2329
2330        //networkscan
2331        addchoicebox(networkscan, "0", _("no"));
2332        addchoicebox(networkscan, "1", _("yes"));
2333
2334        //clear
2335        addchoicebox(clear, "0", _("no"));
2336        addchoicebox(clear, "1", _("yes"));
2337
2338        //only free
2339        addchoicebox(onlyfree, "0", _("no"));
2340        addchoicebox(onlyfree, "1", _("yes"));
2341
2342        //blindscan
2343        addchoicebox(blindscan, "0", _("no"));
2344        addchoicebox(blindscan, "1", _("yes"));
2345
2346        //changename
2347        addchoicebox(changename, "1", _("yes"));
2348        addchoicebox(changename, "0", _("no"));
2349
2350        //favtype
2351        addchoicebox(favtype, "0", _("Unchanged"));
2352        addchoicebox(favtype, "1", _("Create new"));
2353        addchoicebox(favtype, "2", _("Delete All"));
2354
2355        //emptybouquet
2356        addchoicebox(emptybouquet, "0", _("no"));
2357        addchoicebox(emptybouquet, "1", _("yes"));
2358
2359        //unusedbouquetchannels
2360        addchoicebox(unusedbouquetchannels, "0", _("no"));
2361        addchoicebox(unusedbouquetchannels, "1", _("yes"));
2362
2363        //unusedsatprovider
2364        addchoicebox(unusedsatprovider, "0", _("no"));
2365        addchoicebox(unusedsatprovider, "1", _("yes"));
2366
2367        //cleartransponder
2368        addchoicebox(cleartransponder, "0", _("no"));
2369        addchoicebox(cleartransponder, "1", _("yes"));
2370
2371        drawscreen(scan, 2, 0);
2372        changescantype(scantype->ret, scan, listbox, tuner, sat, id, system, frequency, inversion, symbolrate, polarization, fec, modulation, rolloff, pilot, hp, lp, bandwidth, transmission, guardinterval, hierarchy, b4, b5, flag);
2373        drawscreen(scan, 0, 0);
2374        addscreenrc(scan, listbox);
2375
2376        tmp = listbox->select;
2377        while(1)
2378        {
2379                addscreenrc(scan, tmp);
2380
2381                if(clear->ret != NULL && ostrcmp(clear->ret, "1") == 0)
2382                {
2383                        emptybouquet->hidden = NO;
2384                        unusedbouquetchannels->hidden = NO;
2385                        unusedsatprovider->hidden = NO;
2386                        cleartransponder->hidden = NO;
2387                }
2388                else
2389                {
2390                        emptybouquet->hidden = YES;
2391                        unusedbouquetchannels->hidden = YES;
2392                        unusedsatprovider->hidden = YES;
2393                        cleartransponder->hidden = YES;
2394                }
2395                drawscreen(scan, 0, 0);
2396
2397                rcret = waitrc(scan, 0, 0);
2398                tmp = listbox->select;
2399
2400                if(scantype->ret != NULL) iscantype = atoi(scantype->ret);
2401                if(sat->ret != NULL) isat = atoi(sat->ret);
2402                if(system->ret != NULL) isystem = atoi(system->ret);
2403                if(frequency->ret != NULL) ifrequency = atoi(frequency->ret) * 1000;
2404                if(inversion->ret != NULL) iinversion = atoi(inversion->ret);
2405                if(symbolrate->ret != NULL) isymbolrate = atoi(symbolrate->ret) * 1000;
2406                if(polarization->ret != NULL) ipolarization = atoi(polarization->ret);
2407                if(fec->ret != NULL) ifec = atoi(fec->ret);
2408                if(modulation->ret != NULL) imodulation = atoi(modulation->ret);
2409                if(rolloff->ret != NULL) irolloff = atoi(rolloff->ret);
2410                if(pilot->ret != NULL) ipilot = atoi(pilot->ret);
2411
2412                if(flag == 3)
2413                {
2414                        if(hp->ret != NULL) ifec = atoi(hp->ret);
2415                        if(lp->ret != NULL) ipolarization = atoi(lp->ret);
2416                        if(bandwidth->ret != NULL) isymbolrate = atoi(bandwidth->ret);
2417                        if(transmission->ret != NULL) ipilot = atoi(transmission->ret);
2418                        if(guardinterval->ret != NULL) irolloff = atoi(guardinterval->ret);
2419                        if(hierarchy->ret != NULL) isystem = atoi(hierarchy->ret);
2420                }
2421
2422                if(networkscan->ret != NULL) inetworkscan = atoi(networkscan->ret);
2423                if(onlyfree->ret != NULL) ionlyfree = atoi(onlyfree->ret);
2424                if(clear->ret != NULL) iclear = atoi(clear->ret);
2425                if(blindscan->ret != NULL) iblindscan = atoi(blindscan->ret);
2426                if(changename->ret != NULL) ichangename = atoi(changename->ret);
2427                if(favtype->ret != NULL) ifavtype = atoi(favtype->ret);
2428                if(emptybouquet->ret != NULL) iemptybouquet = atoi(emptybouquet->ret);
2429                if(unusedbouquetchannels->ret != NULL) iunusedbouquetchannels = atoi(unusedbouquetchannels->ret);
2430                if(unusedsatprovider->ret != NULL) iunusedsatprovider = atoi(unusedsatprovider->ret);
2431                if(cleartransponder->ret != NULL) icleartransponder = atoi(cleartransponder->ret);
2432
2433                if(rcret == getrcconfigint("rcexit", NULL)) break;
2434                if(rcret == getrcconfigint("rcok", NULL)) break;
2435                if(listbox->select != NULL && ostrcmp(listbox->select->name, "tuner") == 0)
2436                {
2437                        scanchangesat(sat, tpnode, listbox->select->ret);
2438                        changescantype(scantype->ret, scan, listbox, tuner, sat, id, system, frequency, inversion, symbolrate, polarization, fec, modulation, rolloff, pilot, hp, lp, bandwidth, transmission, guardinterval, hierarchy, b4, b5, flag);
2439                        drawscreen(scan, 0, 0);
2440                }
2441                if(listbox->select != NULL && ostrcmp(listbox->select->name, "scantype") == 0)
2442                {
2443                        changescantype(scantype->ret, scan, listbox, tuner, sat, id, system, frequency, inversion, symbolrate, polarization, fec, modulation, rolloff, pilot, hp, lp, bandwidth, transmission, guardinterval, hierarchy, b4, b5, flag);
2444                        drawscreen(scan, 0, 0);
2445                }
2446                if(listbox->select != NULL && ostrcmp(listbox->select->name, "system") == 0)
2447                {
2448                        changescantype(scantype->ret, scan, listbox, tuner, sat, id, system, frequency, inversion, symbolrate, polarization, fec, modulation, rolloff, pilot, hp, lp, bandwidth, transmission, guardinterval, hierarchy, b4, b5, flag);
2449                        drawscreen(scan, 0, 0);
2450                }
2451                if(rcret == getrcconfigint("rcred", NULL))
2452                {
2453                        clearscreen(scan);
2454                        screenscan(tpnode, scan->child, tuner->ret, iscantype, isat, ifrequency, iinversion, isymbolrate, ipolarization, ifec, imodulation, irolloff, ipilot, inetworkscan, ionlyfree, iclear, iblindscan, ichangename, isystem, ifavtype, iemptybouquet, iunusedbouquetchannels, iunusedsatprovider, icleartransponder, 5000000, flag);
2455                        drawscreen(scan, 0, 0);
2456                }
2457                if(rcret == getrcconfigint("rcgreen", NULL) && tpnode != NULL && iscantype == 0)
2458                {
2459                        struct transponder* tp1 = createtransponder(99, tpnode->fetype, isat, ifrequency, iinversion, isymbolrate, ipolarization, ifec, imodulation, irolloff, ipilot, isystem);
2460                        copytransponder(tp1, tpnode, 99);
2461                        deltransponderbyid(99);
2462                        textbox(_("Message"), _("Transponder changed"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0);
2463                        drawscreen(scan, 0, 0);
2464                }
2465                if(rcret == getrcconfigint("rcyellow", NULL) && iscantype == 0)
2466                {
2467                        struct transponder* tp = tpchoicescreen(isat, flag);
2468                        if(tp != NULL)
2469                        {
2470                                tpnode = tp;
2471                                goto start;
2472                        }
2473                        else
2474                                drawscreen(scan, 0, 0);
2475                }
2476                else if(rcret == getrcconfigint("rcok", NULL))
2477                        break;
2478        }
2479
2480        delmarkedscreennodes(scan, 1);
2481        delownerrc(scan);
2482        clearscreen(scan);
2483        resetsatscan();
2484
2485        if(status.lastservice->channel == NULL)
2486        {
2487                if(getchannel(getconfigint("serviceid", NULL), getconfigllu("transponderid", NULL)) != NULL)
2488                {
2489                        if(status.servicetype == 0)
2490                                servicecheckret(servicestart(getchannel(getconfigint("serviceid", NULL), getconfigllu("transponderid", NULL)), getconfig("channellist", NULL), NULL, 0), 0);
2491                        else
2492                                servicecheckret(servicestart(getchannel(getconfigint("rserviceid", NULL), getconfigllu("rtransponderid", NULL)), getconfig("rchannellist", NULL),  NULL, 0), 0);
2493                }
2494        }
2495        else
2496        {
2497                tmpstr = ostrcat(status.lastservice->channellist, NULL, 0, 0);
2498                servicecheckret(servicestart(status.lastservice->channel, tmpstr, NULL, 0), 0);
2499                free(tmpstr); tmpstr = NULL;
2500        }
2501
2502        //recalc channels
2503        struct channel* chnode = channel;
2504        while(chnode != NULL)
2505        {
2506                if(chnode->servicetype != 99)
2507                {
2508                        chnode->transponder = gettransponder(chnode->transponderid);
2509                        chnode->provider = getprovider(chnode->providerid);
2510                }
2511                chnode = chnode->next;
2512        }
2513
2514        writeallconfig(1);
2515}
2516
2517#endif
Note: See TracBrowser for help on using the repository browser.