source: titan/titan/scan.h @ 40800

Last change on this file since 40800 was 40800, checked in by gost, 7 years ago

[titan] next test DVB-t2

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