source: titan/titan/scan.h @ 40798

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

[titan] add new dvb-t2 test

File size: 76.6 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 = 1; //DVB-T2
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                                        debug(500, "scan done system:%d", tpnode->system);
1343                                        if(tpnode->system == 0 || tpnode->system == 3 )
1344                                        {
1345                                                tpnode->system = 1;
1346                                                debug(500, "tune DVB-T2 after DVB-T id=%llu freq=%d orbitalpos=%d tpnode=%p", tpnode->id, tpnode->frequency, tpnode->orbitalpos, tpnode);
1347                                                if(fetunedvbt(fenode, tpnode) == 0)
1348                                                        tout = 0;
1349                                        }
1350                                }
1351                                if(tout == 1)                   
1352                                {       
1353                                        scaninfo.tpcount++;
1354                                        if(scaninfo.cleartransponder == 1)
1355                                        {
1356                                                debug(500, "delete tuning failed id=%llu freq=%d orbitalpos=%d tpnode=%p", tpnode->id, tpnode->frequency, tpnode->orbitalpos, tpnode);
1357                                                deltransponderonscan(tpnode->id, tpnode->frequency, tpnode->orbitalpos);
1358                                        }
1359                                        tpnode = tpnode->next;
1360                                        debug(500, "tuning failed");
1361                                        if(scaninfo.scantype == 0) break;
1362                                        continue;
1363                                }
1364                        }
1365                        else
1366                        {
1367                                scaninfo.tpcount++;
1368                                tpnode = tpnode->next;
1369                                debug(500, "Frontend type unknown");
1370                                if(scaninfo.scantype == 0) break;
1371                                continue;
1372                        }
1373
1374                        festatus = fewait(fenode);
1375                        if(debug_level == 200) fereadstatus(fenode);
1376                        if(festatus != 0)
1377                        {
1378                                scaninfo.tpcount++;
1379                                if(scaninfo.cleartransponder == 1)
1380                                {
1381                                        debug(500, "delete tuning failed id=%llu freq=%d orbitalpos=%d tpnode=%p", tpnode->id, tpnode->frequency, tpnode->orbitalpos, tpnode);
1382                                        deltransponderonscan(tpnode->id, tpnode->frequency, tpnode->orbitalpos);
1383                                }
1384                                tpnode = tpnode->next;
1385                                debug(500, "tuning failed last");
1386                                if(scaninfo.scantype == 0) break;
1387                                continue;
1388                        }
1389
1390                        //del channels from transponder if selected
1391                        //if(scaninfo.scantype != 3 && scaninfo.clear == 1)
1392                        //{
1393                        //      struct channel* tmpchannel = NULL;
1394                        //      chnode = channel;
1395                        //      while(chnode != NULL)
1396                        //      {
1397                        //              tmpchannel = chnode->next;
1398                        //              if(chnode->transponder == tpnode)
1399                        //                      delchannel(chnode->serviceid, chnode->transponderid, 1);
1400                        //              chnode = tmpchannel;
1401                        //      }
1402                        //}
1403
1404                        //get nit
1405                        if(scaninfo.networkscan == 1 && nitscan == 1)
1406                        {
1407                                lastsecnr = 0xff;
1408                                secnr = 0;
1409                                while(secnr <= lastsecnr && secnr <= 256)
1410                                {
1411                                        if(timernode->aktion != START) break;
1412                                        buf = dvbgetnit(fenode, secnr, scaninfo.timeout * 2);
1413                                        if(buf != NULL)
1414                                        {
1415                                                parsenit(buf, &lastsecnr, satnode->orbitalpos);
1416                                                nitscan = 1; //1 = scan all transponder for nit / 0 = scan only first transponder for nit
1417                                        }
1418                                        else
1419                                                break;
1420                                        free(buf); buf = NULL;
1421                                        secnr++;
1422                                }
1423                        }
1424
1425                        lastsecnr = 0xff;
1426                        secnr = 0;
1427                        while(secnr <= lastsecnr && secnr <= 256)
1428                        {
1429                                if(timernode->aktion != START) break;
1430#ifndef SIMULATE
1431                                buf = dvbgetsdt(fenode, secnr, scaninfo.timeout);
1432#endif
1433                                if(buf != NULL)
1434                                        findchannel(fenode, tpnode, buf, &lastsecnr, scaninfo.scanscreen, scaninfo.listbox, scaninfo.changename, 0);
1435                                else
1436                                        break;
1437                                free(buf); buf = NULL;
1438                                secnr++;
1439                        }
1440
1441                        scaninfo.tpcount++;
1442                        if(scaninfo.scantype == 0) break;
1443                        tpnode = tpnode->next;
1444                }
1445                if(scaninfo.scantype == 0 || scaninfo.scantype == 1) break;
1446                satnode = satnode->next;
1447        }
1448        scaninfo.threadend = 1;
1449        debug(500, "channel scan thread end");
1450}
1451
1452void scanaddchannel(struct skin* node, int scantype, struct transponder* tp1, int ichangename)
1453{
1454        int serviceid = 0;
1455        uint64_t transponderid = 0;
1456        int servicetype = 0;
1457        int providerid = 0;
1458        struct provider* providernode = NULL;
1459        char* tmpstr = NULL;
1460        struct transponder* tp2 = NULL;
1461        struct channel* chnode = NULL;
1462
1463        if(node == NULL || node->name == NULL) return;
1464
1465        serviceid = ((uint64_t*)node->name)[0];
1466        transponderid = ((uint64_t*)node->name)[1];
1467        servicetype = ((uint64_t*)node->name)[2];
1468
1469        chnode = getchannel(serviceid, transponderid);
1470        if(chnode == NULL || (chnode != NULL && chnode->transponder == NULL))
1471        {
1472                //check if provider valid
1473                providernode = getproviderbyname(node->param1);
1474                if(providernode != NULL)
1475                        providerid = providernode->providerid;
1476                else
1477                {
1478                        providerid = getlastproviderid() + 1;
1479                        tmpstr = ostrcat(tmpstr, oitoa(providerid), 1, 1);
1480                        tmpstr = ostrcat(tmpstr, "#", 1, 0);
1481                        tmpstr = ostrcat(tmpstr, node->param1, 1, 0);
1482                        tmpstr = ostrcat(tmpstr, "#0", 1, 0);
1483                        addprovider(tmpstr, 1, NULL);
1484                        free(tmpstr); tmpstr = NULL;
1485                }
1486
1487                //check if transponder valid
1488                if(scantype == 0)
1489                {
1490                        tp2 = gettransponder(transponderid);
1491
1492                        if(tp2 == NULL && tp1 != NULL)
1493                        {
1494                                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);
1495                                if(tp2 != NULL)
1496                                        changetransponderid(tp2, transponderid);
1497                        }
1498
1499                        if(tp2 == NULL) //create new transponder
1500                                copytransponder(tp1, tp2, transponderid);
1501                        else //change transponder
1502                                copytransponder(tp1, tp2, 99);
1503                }
1504
1505                if(servicetype != 0 && servicetype != 1)
1506                        servicetype = 0;
1507
1508                if(chnode == NULL)
1509                {
1510                        if(createchannel(node->param2, transponderid, providerid, serviceid, servicetype, 0, -1, -1, -1, -1, 0, -1) != NULL)
1511                                node->fontcol = convertcol("deaktivcol");
1512                }
1513                else
1514                        node->fontcol = convertcol("deaktivcol");
1515        }
1516        else
1517        {
1518                node->fontcol = convertcol("deaktivcol");
1519                //change channel name if selected
1520                if(ichangename == 1 && node->param2 != NULL && strlen(node->param2) > 0 && ostrcmp(node->param2, chnode->name) != 0)
1521                {
1522                        free(chnode->name);
1523                        chnode->name = ostrcat(node->param2, NULL, 0, 0);
1524                        status.writetransponder = 1;
1525                }
1526        }
1527}
1528
1529void scansetallsat(int fetype)
1530{
1531        int i = 0, orbitalpos = 0;
1532        struct sat* satnode = NULL;
1533        struct dvbdev* dvbnode = dvbdev;
1534        char* tmpstr = NULL, *tmpnr = NULL;
1535
1536        while(dvbnode != NULL)
1537        {
1538                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL && dvbnode->felock < 1 && dvbnode->deactive == 0 && (fetype == -1 || dvbnode->feinfo->type == fetype))
1539                {
1540
1541                        tmpstr = ostrcat(dvbnode->feshortname, "_sat", 0, 0);
1542                        for(i = 1; i <= getmaxsat(dvbnode->feshortname); i++)
1543                        {
1544                                tmpnr = oitoa(i);
1545                                orbitalpos = getconfigint(tmpstr, tmpnr);
1546                                free(tmpnr); tmpnr = NULL;
1547
1548                                satnode = getsatbyorbitalpos(orbitalpos);
1549                                if(satnode != NULL && (fetype == -1 || satnode->fetype == fetype))
1550                                        satnode->scan = 1;
1551                        }
1552                        free(tmpstr); tmpstr = NULL;
1553                }
1554                dvbnode = dvbnode->next;
1555        }
1556}
1557
1558void scansetmultisat(struct skin* scan)
1559{
1560        struct skin* node = scan;
1561        struct sat* satnode = NULL;
1562
1563        while(node != NULL && node->name != NULL)
1564        {
1565                if(ostrcmp(node->ret, "1") == 0)
1566                {
1567                        satnode = getsatbyorbitalpos(atoi(node->name));
1568                        if(satnode != NULL)
1569                                satnode->scan = 1;
1570                }
1571                node = node->next;
1572        }
1573}
1574
1575void delchannelbysat(int orbitalpos)
1576{
1577        struct transponder* transpondernode = transponder;
1578        struct channel* chnode = NULL;
1579
1580        while(transpondernode != NULL)
1581        {
1582                if(transpondernode->orbitalpos == orbitalpos)
1583                {
1584                        struct channel* tmpchannel = NULL;
1585                        chnode = channel;
1586                        while(chnode != NULL)
1587                        {
1588                                tmpchannel = chnode->next;
1589                                if(chnode->transponder == transpondernode)
1590                                        delchannel(chnode->serviceid, chnode->transponderid, 1);
1591                                chnode = tmpchannel;
1592                        }
1593                }
1594                transpondernode = transpondernode->next;
1595        }
1596}
1597
1598void delchannelbymultisat()
1599{
1600        struct sat* satnode = sat;
1601
1602        while(satnode != NULL)
1603        {
1604                if(satnode->scan == 1)
1605                        delchannelbysat(satnode->orbitalpos);
1606                satnode = satnode->next;
1607        }
1608}
1609
1610void 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)
1611{
1612        int rcret = 0, tpmax = 0, i = 0, alladded = 0, endmsgshow = 0, tpdel = 0;
1613
1614        struct skin* scan = NULL;
1615        if(flag == 1)
1616                scan = getscreen("scanauto");
1617        else
1618                scan = getscreen("scanmanual");
1619
1620        struct skin* progress = getscreennode(scan, "progress");
1621        struct skin* listbox = getscreennode(scan, "listbox");
1622        struct skin* satname = getscreennode(scan, "satname");
1623        struct skin* tpcount = getscreennode(scan, "tpcount");
1624        struct skin* foundtv = getscreennode(scan, "foundtv");
1625        struct skin* foundradio = getscreennode(scan, "foundradio");
1626        struct skin* founddata = getscreennode(scan, "founddata");
1627        struct skin* foundblind = getscreennode(scan, "foundblind");
1628        struct skin* b2 = getscreennode(scan, "b2");
1629        struct skin* b3 = getscreennode(scan, "b3");
1630        struct skin* load = getscreen("loading");
1631        struct transponder* tpnode = NULL;
1632        struct dvbdev* fenode = NULL, *dvbnode = dvbdev;
1633        struct stimerthread* timernode = NULL;
1634        struct sat* satnode = NULL;
1635        struct channel* chnode = NULL;
1636        char* tmpstr = NULL;
1637
1638        listbox->aktline = 1;
1639        listbox->aktpage = -1;
1640        progress->progresssize = 0;
1641        memset(&scaninfo, 0, sizeof(struct scaninfo));
1642
1643        b2->hidden = NO;
1644        b3->hidden = NO;
1645
1646        addscreenrc(scan, listbox);
1647        if(scantype != 3)
1648        {
1649                while(dvbnode != NULL)
1650                {
1651                        if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL && dvbnode->felock < 1)
1652                        {
1653                                if(ostrcmp(dvbnode->feshortname, tuner) == 0)
1654                                {
1655                                        fenode = dvbnode;
1656                                        break;
1657                                }
1658                        }
1659                        dvbnode = dvbnode->next;
1660                }
1661                if(fenode == NULL) return;
1662        }
1663        else if(scantype == 3)
1664                fenode = dvbdev;
1665
1666        if(scantype == 0) //single transponder
1667        {
1668                if(fenode != NULL && fenode->feinfo != NULL)
1669                {
1670                        //del channels from transponder if selected
1671                        if(clear == 1)
1672                        {
1673                                struct channel* tmpchannel = NULL;
1674                                chnode = channel;
1675                                while(chnode != NULL)
1676                                {
1677                                        tmpchannel = chnode->next;
1678                                        if(chnode->transponder == transpondernode)
1679                                                delchannel(chnode->serviceid, chnode->transponderid, 1);
1680                                        chnode = tmpchannel;
1681                                }
1682                        }
1683
1684                        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);
1685                        tpnode = createtransponder(99, fenode->feinfo->type, orbitalpos, frequency, inversion, symbolrate, polarization, fec, modulation, rolloff, pilot, system);
1686                }
1687                if(tpnode != NULL)
1688                {
1689                        tpmax = 1;
1690                        satnode = getsatbyorbitalpos(tpnode->orbitalpos);
1691                        if(satnode != NULL) satnode->scan = 1;
1692                }
1693        }
1694        else if(scantype == 1) //single sat
1695        {
1696                if(clear == 1) delchannelbysat(orbitalpos);
1697                tpnode = transponder;
1698                while(tpnode != NULL)
1699                {
1700                        if(tpnode->orbitalpos == orbitalpos)
1701                                tpmax++;
1702                        tpnode = tpnode->next;
1703                }
1704                tpnode = transponder;
1705                satnode = getsatbyorbitalpos(orbitalpos);
1706                if(satnode != NULL) satnode->scan = 1;
1707        }
1708        else if(scantype == 2 || scantype == 3) //2: multi sat, 3: all
1709        {
1710                if(scantype == 2)
1711                {
1712                        scansetmultisat(mscan);
1713                        if(clear == 1) delchannelbymultisat();
1714                }
1715                if(scantype == 3)
1716                {
1717                        scansetallsat(-1);
1718                        b2->hidden = YES;
1719                        b3->hidden = YES;
1720                        //del all channel for auto. search
1721                        if(clear == 1)
1722                        {
1723                                freechannel(1);
1724                                if(unusedsatprovider == 1)
1725                                {
1726                                        delunusedsat();
1727                                        delunusedtransponder();
1728                                        delunusedchannel();
1729                                        //delunusedepgchannel();
1730                                        delunusedprovider();
1731                                }
1732                        }
1733                }
1734
1735                satnode = sat;
1736                while(satnode != NULL)
1737                {
1738                        if(satnode->scan != 0)
1739                        {
1740                                tpnode = transponder;
1741                                while(tpnode != NULL)
1742                                {
1743                                        if(tpnode->orbitalpos == satnode->orbitalpos)
1744                                                tpmax++;
1745                                        tpnode = tpnode->next;
1746                                }
1747                        }
1748                        satnode = satnode->next;
1749                }
1750                tpnode = transponder;
1751        }
1752
1753        scaninfo.fenode = fenode;
1754        scaninfo.tpnode = tpnode;
1755        scaninfo.scanscreen = scan;
1756        scaninfo.listbox = listbox;
1757        scaninfo.timeout = timeout;
1758        scaninfo.scantype = scantype;
1759        scaninfo.orbitalpos = orbitalpos;
1760        scaninfo.onlyfree = onlyfree;
1761        scaninfo.networkscan = networkscan;
1762        scaninfo.blindscan = blindscan;
1763        scaninfo.changename = ichangename;
1764        scaninfo.clear = clear;
1765        scaninfo.tpmax = tpmax;
1766        scaninfo.tpdel = tpdel;
1767        scaninfo.cleartransponder = cleartransponder;
1768        timernode = addtimer(&doscan, START, 1000, 1, NULL, NULL, NULL);
1769
1770        while(1)
1771        {
1772                //satname
1773                tmpstr = ostrcat(tmpstr, _("Sat/Provider: "), 1, 0);
1774                tmpstr = ostrcat(tmpstr, scaninfo.satname, 1, 0);
1775                changetext(satname, tmpstr);
1776                free(tmpstr); tmpstr = NULL;
1777
1778                //transpondercount
1779                tmpstr = ostrcat(tmpstr, _("Transponder: "), 1, 0);
1780                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpcount), 1, 1);
1781                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1782                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpmax), 1, 1);
1783                tmpstr = ostrcat(tmpstr, _(" New: "), 1, 0);
1784                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpnew), 1, 1);
1785                tmpstr = ostrcat(tmpstr, _(" Del: "), 1, 0);
1786                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpdel), 1, 1);
1787                changetext(tpcount, tmpstr);
1788                free(tmpstr); tmpstr = NULL;
1789
1790                //tvcount
1791                tmpstr = ostrcat(tmpstr, _("TV: "), 1, 0);
1792                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newtvcount), 1, 1);
1793                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1794                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tvcount), 1, 1);
1795                changetext(foundtv, tmpstr);
1796                free(tmpstr); tmpstr = NULL;
1797
1798                //radiocount
1799                tmpstr = ostrcat(tmpstr, _("Radio: "), 1, 0);
1800                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newradiocount), 1, 1);
1801                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1802                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.radiocount), 1, 1);
1803                changetext(foundradio, tmpstr);
1804                free(tmpstr); tmpstr = NULL;
1805
1806                //datacount
1807                tmpstr = ostrcat(tmpstr, _("Data: "), 1, 0);
1808                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newdatacount), 1, 1);
1809                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1810                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.datacount), 1, 1);
1811                changetext(founddata, tmpstr);
1812                free(tmpstr); tmpstr = NULL;
1813
1814                //blindcount
1815                tmpstr = ostrcat(tmpstr, _("Blindscan: "), 1, 0);
1816                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newblindcount), 1, 1);
1817                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1818                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.blindcount), 1, 1);
1819                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1820                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.blindmax), 1, 1);
1821                changetext(foundblind, tmpstr);
1822                free(tmpstr); tmpstr = NULL;
1823
1824                if(scaninfo.tpmax == 0)
1825                        progress->progresssize = 100;
1826                else
1827                        progress->progresssize = (100 / (float)scaninfo.tpmax) * scaninfo.tpcount;
1828
1829                drawscreen(scan, 0, 0);
1830                rcret = waitrc(scan, 1000, 0);
1831
1832                if(scantype != 3 && scaninfo.threadend == 1 && endmsgshow == 0)
1833                {
1834                        if(scaninfo.tvcount + scaninfo.radiocount + scaninfo.datacount == 0)
1835                                textbox(_("Message"), _("Channel scan ended.\nNothing found."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
1836                        else
1837                                textbox(_("Message"), _("Channel scan ended."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
1838                        endmsgshow = 1;
1839                }
1840
1841                if(scantype != 3 && rcret == getrcconfigint("rcred", NULL))
1842                        scanaddchannel(listbox->select, scantype, tpnode, ichangename);
1843
1844                if((scantype != 3 && rcret == getrcconfigint("rcgreen", NULL)) || (scantype == 3 && scaninfo.threadend == 1 && alladded < 2))
1845                {
1846                        struct skin* lnode = listbox;
1847
1848                        long deaktivcol = convertcol("deaktivcol");
1849                        if(scantype == 3 && alladded == 0)
1850                        {
1851                                alladded = 1;
1852                                continue;
1853                        }
1854                        alladded = 2;
1855
1856                        drawscreen(load, 0, 0);
1857                        while(lnode != NULL)
1858                        {
1859                                if(lnode->fontcol != deaktivcol && lnode->del == 1)
1860                                        scanaddchannel(lnode, scantype, tpnode, ichangename);
1861                                lnode = lnode->next;
1862                        }
1863                        clearscreen(load);
1864                        if(scaninfo.tvcount + scaninfo.radiocount + scaninfo.datacount == 0)
1865                                textbox(_("Message"), _("Channel scan ended.\nNothing found."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
1866                        else
1867                                textbox(_("Message"), _("Scan completed, changes have been saved."), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 600, 200, 0, 0);
1868                }
1869
1870                if(rcret == getrcconfigint("rcexit", NULL))
1871                {
1872                        if(timernode != NULL && scaninfo.threadend == 0)
1873                        {
1874                                timernode->aktion = STOP;
1875                                while(i < 4 && scaninfo.threadend == 0)
1876                                {
1877                                        textbox(_("Message"), _("Wait for channel scan end"), NULL, 0, NULL, 0, NULL, 0, NULL, 0, 800, 200, 3, 0);
1878                                        i++;
1879                                }
1880                        }
1881                        break;
1882                }
1883        }
1884
1885        if(scantype == 0) deltransponderbyid(99);
1886        if(clear == 1)
1887        {
1888                // favtype 0 = unchanged
1889                // favtype 1 = create new
1890                // favtype 2 = delete
1891
1892                if(favtype == 1)
1893                {
1894                        freemainbouquet(1);
1895                        struct provider *pnode = provider;
1896
1897                        while(pnode != NULL)
1898                        {
1899                                provider2bouquet(pnode->providerid, 1);
1900                                pnode = pnode->next;
1901                        }
1902                }
1903                else if(favtype == 2)
1904                        freemainbouquet(1);
1905
1906                if(emptybouquet == 1)
1907                        delemptymainbouquet(1);
1908
1909                if(unusedbouquetchannels == 1)
1910                        delunusedbouquetchannels(0);
1911                else
1912                        delunusedbouquetchannels(1);
1913
1914                if(cleartransponder == 1 && unusedsatprovider == 1)
1915                        deltransponderbyid(0);
1916        }
1917        delmarkedscreennodes(scan, 1);
1918        delownerrc(scan);
1919        clearscreen(scan);
1920        resetsatscan();
1921        drawscreen(load, 0, 0);
1922        sortchannel();
1923        sortprovider();
1924        clearscreen(load);
1925}
1926
1927void 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)
1928{
1929        struct sat* satnode = sat;
1930        struct skin* tmp = NULL;
1931        char* tmpstr = NULL, *tmpstr1 = NULL, *tmpnr = NULL;
1932        char* feshortname = NULL;
1933        int i, orbitalpos = 0;
1934
1935        if(tuner != NULL) feshortname = tuner->ret;
1936
1937        tuner->hidden = NO;
1938        id->hidden = NO;
1939        system->hidden = NO;
1940        frequency->hidden = NO;
1941        inversion->hidden = NO;
1942        symbolrate->hidden = NO;
1943        polarization->hidden = NO;
1944        fec->hidden = NO;
1945        modulation->hidden = NO;
1946        rolloff->hidden = NO;
1947        pilot->hidden = NO;
1948        hp->hidden = NO;
1949        lp->hidden = NO;
1950        bandwidth->hidden = NO;
1951        transmission->hidden = NO;
1952        guardinterval->hidden = NO;
1953        hierarchy->hidden = NO;
1954        satellite->hidden = NO;
1955        b4->hidden = NO;
1956        b5->hidden = NO;
1957        delmarkedscreennodes(scan, 1);
1958
1959        if(flag == 0 && ostrcmp(scantype, "0") == 0 && ostrcmp(system->ret, "0") == 0)
1960        {
1961                modulation->hidden = YES;
1962                rolloff->hidden = YES;
1963                pilot->hidden = YES;
1964        }
1965
1966        if(ostrcmp(scantype, "1") == 0 || ostrcmp(scantype, "2") == 0 || ostrcmp(scantype, "3") == 0)
1967        {
1968                id->hidden = YES;
1969                system->hidden = YES;
1970                frequency->hidden = YES;
1971                inversion->hidden = YES;
1972                symbolrate->hidden = YES;
1973                polarization->hidden = YES;
1974                fec->hidden = YES;
1975                modulation->hidden = YES;
1976                rolloff->hidden = YES;
1977                pilot->hidden = YES;
1978                hp->hidden = YES;
1979                lp->hidden = YES;
1980                bandwidth->hidden = YES;
1981                transmission->hidden = YES;
1982                guardinterval->hidden = YES;
1983                hierarchy->hidden = YES;
1984                b4->hidden = YES;
1985                b5->hidden = YES;
1986        }
1987        if(ostrcmp(scantype, "2") == 0 && feshortname != NULL)
1988        {
1989                satellite->hidden = YES;
1990
1991                tmpstr = ostrcat(feshortname, "_sat", 0, 0);
1992                for(i = 1; i <= getmaxsat(feshortname); i++)
1993                {
1994                        tmpnr = oitoa(i);
1995                        orbitalpos = getconfigint(tmpstr, tmpnr);
1996                        free(tmpnr); tmpnr = NULL;
1997
1998                        satnode = getsatbyorbitalpos(orbitalpos);
1999                        if(satnode != NULL && satnode->fetype == FE_QPSK)
2000                        {
2001                                tmp = addlistbox(scan, listbox, tmp, 1);
2002                                if(tmp != NULL)
2003                                {
2004                                        tmpstr1 = oitoa(satnode->orbitalpos);
2005                                        changename(tmp, tmpstr1);
2006                                        free(tmpstr1); tmpstr1 = NULL;
2007                                        changetext(tmp, satnode->name);
2008                                        tmp->type = CHOICEBOX;
2009                                        addchoicebox(tmp, "0", _("no"));
2010                                        addchoicebox(tmp, "1", _("yes"));
2011                                }
2012                        }
2013                }
2014                free(tmpstr); tmpstr = NULL;
2015        }
2016        if(ostrcmp(scantype, "3") == 0)
2017        {
2018                tuner->hidden = YES;
2019                satellite->hidden = YES;
2020        }
2021
2022        if(flag == 2)
2023        {
2024                system->hidden = YES;
2025                inversion->hidden = YES;
2026                polarization->hidden = YES;
2027                rolloff->hidden = YES;
2028                pilot->hidden = YES;
2029                satellite->hidden = YES;
2030        }
2031
2032        if(flag == 3)
2033        {
2034                system->hidden = YES;
2035                polarization->hidden = YES;
2036                rolloff->hidden = YES;
2037                pilot->hidden = YES;
2038                satellite->hidden = YES;
2039                symbolrate->hidden = YES;
2040                fec->hidden = YES;
2041        }
2042        else
2043        {
2044                hp->hidden = YES;
2045                lp->hidden = YES;
2046                bandwidth->hidden = YES;
2047                transmission->hidden = YES;
2048                guardinterval->hidden = YES;
2049                hierarchy->hidden = YES;
2050        }
2051}
2052
2053void scanchangesat(struct skin* sat, struct transponder* tpnode, char* feshortname)
2054{
2055        char* tmpstr = NULL;
2056
2057        changeinput(sat, NULL);
2058        changechoiceboxvalue(sat, NULL);
2059        tmpstr = getsatstring(feshortname, FE_QPSK);
2060        changeinput(sat, tmpstr);
2061        free(tmpstr); tmpstr = NULL;
2062        tmpstr = getorbitalposstring(feshortname, FE_QPSK);
2063        changechoiceboxvalue(sat, tmpstr);
2064        free(tmpstr); tmpstr = NULL;
2065        if(tpnode != NULL)
2066        {
2067                tmpstr = oitoa(tpnode->orbitalpos);
2068                setchoiceboxselection(sat, tmpstr);
2069                free(tmpstr); tmpstr = NULL;
2070        }
2071}
2072
2073//flag 0: manual scan (DVB-S)
2074//flag 1: auto scan (all)
2075//flag 2: manual scan (DVB-C)
2076//flag 3: manual scan (DVB-T)
2077void screenscanconfig(int flag)
2078{
2079        int rcret = 0, fetype = -1;
2080        unsigned int ifrequency = -1, isymbolrate = -1;
2081        int iscantype = -1, isat = -1;
2082        int iinversion = -1, ipolarization = -1;
2083        int ifec = -1, imodulation = -1, irolloff = -1, ipilot = -1, isystem = -1;
2084        int inetworkscan = -1, ionlyfree = -1, iclear = -1, iblindscan = -1, ichangename = -1;
2085        int ifavtype = -1, iemptybouquet = -1, iunusedbouquetchannels = -1;
2086        int iunusedsatprovider = -1, icleartransponder = -1;
2087
2088        int i = 0, treffer = 0, tunercount = 0;
2089
2090        struct skin* scan = NULL;
2091        if(flag == 1)
2092                scan = getscreen("scanadjustauto");
2093        else
2094                scan = getscreen("scanadjustmanual");
2095
2096        struct skin* listbox = getscreennode(scan, "listbox");
2097        struct skin* tuner = getscreennode(scan, "tuner");
2098        struct skin* scantype = getscreennode(scan, "scantype");
2099        struct skin* sat = getscreennode(scan, "sat");
2100        struct skin* id = getscreennode(scan, "id");
2101        struct skin* system = getscreennode(scan, "system");
2102        struct skin* frequency = getscreennode(scan, "frequency");
2103        struct skin* inversion = getscreennode(scan, "inversion");
2104        struct skin* symbolrate = getscreennode(scan, "symbolrate");
2105        struct skin* polarization = getscreennode(scan, "polarization");
2106        struct skin* fec = getscreennode(scan, "fec");
2107        struct skin* modulation = getscreennode(scan, "modulation");
2108        struct skin* rolloff = getscreennode(scan, "rolloff");
2109        struct skin* pilot = getscreennode(scan, "pilot");
2110        struct skin* hp = getscreennode(scan, "hp");
2111        struct skin* lp = getscreennode(scan, "lp");
2112        struct skin* bandwidth = getscreennode(scan, "bandwidth");
2113        struct skin* transmission = getscreennode(scan, "transmission");
2114        struct skin* guardinterval = getscreennode(scan, "guardinterval");
2115        struct skin* hierarchy = getscreennode(scan, "hierarchy");
2116        struct skin* networkscan = getscreennode(scan, "networkscan");
2117        struct skin* clear = getscreennode(scan, "clear");
2118        struct skin* onlyfree = getscreennode(scan, "onlyfree");
2119        struct skin* blindscan = getscreennode(scan, "blindscan");
2120        struct skin* changename = getscreennode(scan, "changename");
2121        struct skin* favtype = getscreennode(scan, "favtype");
2122        struct skin* emptybouquet = getscreennode(scan, "emptybouquet");
2123        struct skin* unusedsatprovider = getscreennode(scan, "unusedsatprovider");
2124        struct skin* cleartransponder = getscreennode(scan, "cleartransponder");
2125        struct skin* unusedbouquetchannels = getscreennode(scan, "unusedbouquetchannels");
2126
2127        struct skin* b4 = getscreennode(scan, "b4");
2128        struct skin* b5 = getscreennode(scan, "b5");
2129        struct skin* tmp = NULL;
2130        char* tmpstr = NULL, *tmpnr = NULL, *feshortname = NULL;
2131        struct transponder* tpnode = NULL;
2132        struct dvbdev* dvbnode = dvbdev;
2133
2134        listbox->aktline = 1;
2135        listbox->aktpage = -1;
2136
2137        if(status.recording > 0 || status.streaming > 0)
2138        {
2139                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);
2140                return;
2141        }
2142
2143        //del old values
2144        changeinput(tuner, NULL);
2145        changechoiceboxvalue(tuner, NULL);
2146        changeinput(scantype, NULL);
2147        changechoiceboxvalue(scantype, NULL);
2148        changeinput(sat, NULL);
2149        changechoiceboxvalue(sat, NULL);
2150        changeinput(system, NULL);
2151        changechoiceboxvalue(system, NULL);
2152        changeinput(inversion, NULL);
2153        changechoiceboxvalue(inversion, NULL);
2154        changeinput(polarization, NULL);
2155        changechoiceboxvalue(polarization, NULL);
2156        changeinput(fec, NULL);
2157        changechoiceboxvalue(fec, NULL);
2158        changeinput(modulation, NULL);
2159        changechoiceboxvalue(modulation, NULL);
2160        changeinput(rolloff, NULL);
2161        changechoiceboxvalue(rolloff, NULL);
2162        changeinput(pilot, NULL);
2163        changechoiceboxvalue(pilot, NULL);
2164        changeinput(hp, NULL);
2165        changeinput(lp, NULL);
2166        changeinput(bandwidth, NULL);
2167        changeinput(transmission, NULL);
2168        changeinput(guardinterval, NULL);
2169        changeinput(hierarchy, NULL);
2170        changechoiceboxvalue(hp, NULL);
2171        changechoiceboxvalue(lp, NULL);
2172        changechoiceboxvalue(bandwidth, NULL);
2173        changechoiceboxvalue(transmission, NULL);
2174        changechoiceboxvalue(guardinterval, NULL);
2175        changechoiceboxvalue(hierarchy, NULL);
2176
2177        frequency->aktpage = 0;
2178        symbolrate->aktpage = 0;
2179
2180        if(flag == 0) fetype = FE_QPSK;
2181        if(flag == 2) fetype = FE_QAM;
2182        if(flag == 3) fetype = FE_OFDM;
2183
2184        //tuner
2185        while(dvbnode != NULL)
2186        {
2187                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL && dvbnode->felock < 1 && dvbnode->deactive == 0 && (flag == 1 || dvbnode->feinfo->type == fetype))
2188                {
2189                        treffer = 0;
2190                        if(dvbnode->feshortname != NULL)
2191                        {
2192                                tmpstr = ostrcat(dvbnode->feshortname, "_sat", 0, 0);
2193                                for(i = 1; i <= getmaxsat(dvbnode->feshortname); i++)
2194                                {
2195                                        tmpnr = oitoa(i);
2196                                        if(getconfigint(tmpstr, tmpnr) != 0)
2197                                        {
2198                                                treffer = 1;
2199                                                break;
2200                                        }
2201                                        free(tmpnr); tmpnr = NULL;
2202                                }
2203                                free(tmpnr); tmpnr = NULL;
2204                                free(tmpstr); tmpstr = NULL;
2205                        }
2206
2207                        if(treffer == 0)
2208                        {
2209                                dvbnode = dvbnode->next;
2210                                continue;
2211                        }
2212
2213                        tunercount++;
2214                        if(feshortname == NULL) feshortname = dvbnode->feshortname;
2215
2216                        tmpstr = ostrcat(tmpstr, dvbnode->feinfo->name, 1, 0);
2217                        tmpstr = ostrcat(tmpstr, " (", 1, 0);
2218                        tmpstr = ostrcat(tmpstr, oitoa(dvbnode->adapter), 1, 1);
2219                        tmpstr = ostrcat(tmpstr, "/", 1, 0);
2220                        tmpstr = ostrcat(tmpstr, oitoa(dvbnode->devnr), 1, 1);
2221                        tmpstr = ostrcat(tmpstr, ")", 1, 0);
2222                        addchoicebox(tuner, dvbnode->feshortname, tmpstr);
2223                        free(tmpstr); tmpstr = NULL;
2224                }
2225                dvbnode = dvbnode->next;
2226        }
2227
2228        if(tunercount < 1)
2229        {
2230                textbox(_("Message"), _("No Tuner configured"), _("OK"), getrcconfigint("rcok", NULL), NULL, 0, NULL, 0, NULL, 0, 800, 200, 0, 0);
2231                return;
2232        }
2233
2234        rcret = servicestop(status.aktservice, 1, 1);
2235        if(rcret == 1) return;
2236
2237        if(status.aktservice->channel != NULL)
2238                tpnode = status.aktservice->channel->transponder;
2239
2240        //clear akt and last channel, so all channel can delete
2241        freechannelhistory();
2242        status.lastservice->channel = NULL;
2243        status.aktservice->channel = NULL;
2244
2245start:
2246
2247        if(flag == 0)
2248        {
2249                addchoicebox(scantype, "0", _("Single Transponder"));
2250                addchoicebox(scantype, "1", _("Single Sat"));
2251                addchoicebox(scantype, "2", _("Multi Sat"));
2252                setchoiceboxselection(scantype, "0");
2253        }
2254        else if(flag == 2 || flag == 3)
2255        {
2256                addchoicebox(scantype, "0", _("Single Transponder"));
2257                addchoicebox(scantype, "1", _("Single Provider"));
2258                setchoiceboxselection(scantype, "0");
2259        }
2260        else
2261        {
2262                addchoicebox(scantype, "3", _("Auto Scan"));
2263                setchoiceboxselection(scantype, "3");
2264        }
2265
2266        //sat
2267        scanchangesat(sat, tpnode, feshortname);
2268
2269        //id
2270        if(tpnode != NULL)
2271                tmpstr = ollutoa(tpnode->id);
2272        changeinput(id, tmpstr);
2273        free(tmpstr); tmpstr = NULL;
2274
2275        //system
2276        tmpstr = transpondergetsystemstr(tpnode, 1);
2277        changeinput(system, tmpstr);
2278        free(tmpstr); tmpstr = NULL;
2279        tmpstr = transpondergetsystemstr(tpnode, 2);
2280        changechoiceboxvalue(system, tmpstr);
2281        free(tmpstr); tmpstr = NULL;
2282        if(tpnode != NULL)
2283        {
2284                tmpstr = oitoa(tpnode->system);
2285                setchoiceboxselection(system, tmpstr);
2286                free(tmpstr); tmpstr = NULL;
2287        }
2288
2289        //frequency
2290        if(tpnode != NULL)
2291                tmpstr = oitoa(tpnode->frequency / 1000);
2292        else
2293        {
2294                if(flag == 3)
2295                        tmpstr = ostrcat(tmpstr, "000000", 1, 0);
2296                else
2297                        tmpstr = ostrcat(tmpstr, "00000", 1, 0);
2298        }
2299        if(flag == 2 || flag == 3)
2300        {
2301                changemask(frequency, "000000");
2302                changeinput(frequency, tmpstr);
2303                frequency->input = mask(frequency->input, 6, "0");
2304        }
2305        else
2306        {
2307                changemask(frequency, "00000");
2308                changeinput(frequency, tmpstr);
2309                frequency->input = mask(frequency->input, 5, "0");
2310        }
2311        free(tmpstr); tmpstr = NULL;
2312
2313        //inversion
2314        tmpstr = transpondergetinversionstr(tpnode, 1);
2315        changeinput(inversion, tmpstr);
2316        free(tmpstr); tmpstr = NULL;
2317        tmpstr = transpondergetinversionstr(tpnode, 2);
2318        changechoiceboxvalue(inversion, tmpstr);
2319        free(tmpstr); tmpstr = NULL;
2320        if(tpnode != NULL)
2321        {
2322                tmpstr = oitoa(tpnode->inversion);
2323                setchoiceboxselection(inversion, tmpstr);
2324                free(tmpstr); tmpstr = NULL;
2325        }
2326
2327        //symbolrate
2328        if(tpnode != NULL)
2329                tmpstr = oitoa(tpnode->symbolrate / 1000);
2330        else
2331                tmpstr = ostrcat(tmpstr, "00000", 1, 0);
2332        changemask(symbolrate, "00000");
2333        changeinput(symbolrate, tmpstr);
2334        symbolrate->input = mask(symbolrate->input, 5, "0");
2335        free(tmpstr); tmpstr = NULL;
2336
2337        //polarization
2338        tmpstr = transpondergetpolarizationstr(tpnode, 1);
2339        changeinput(polarization, tmpstr);
2340        free(tmpstr); tmpstr = NULL;
2341        tmpstr = transpondergetpolarizationstr(tpnode, 2);
2342        changechoiceboxvalue(polarization, tmpstr);
2343        free(tmpstr); tmpstr = NULL;
2344        if(tpnode != NULL)
2345        {
2346                tmpstr = oitoa(tpnode->polarization);
2347                setchoiceboxselection(polarization, tmpstr);
2348                free(tmpstr); tmpstr = NULL;
2349        }
2350
2351        //fec
2352        tmpstr = transpondergetfecstr(tpnode, fetype, 1);
2353        changeinput(fec, tmpstr);
2354        free(tmpstr); tmpstr = NULL;
2355        tmpstr = transpondergetfecstr(tpnode, fetype, 2);
2356        changechoiceboxvalue(fec, tmpstr);
2357        free(tmpstr); tmpstr = NULL;
2358        if(tpnode != NULL)
2359        {
2360                tmpstr = oitoa(tpnode->fec);
2361                setchoiceboxselection(fec, tmpstr);
2362                free(tmpstr); tmpstr = NULL;
2363        }
2364
2365        //modulation
2366        tmpstr = transpondergetmodulationstr(tpnode, fetype, 1);
2367        changeinput(modulation, tmpstr);
2368        free(tmpstr); tmpstr = NULL;
2369        tmpstr = transpondergetmodulationstr(tpnode, fetype, 2);
2370        changechoiceboxvalue(modulation, tmpstr);
2371        free(tmpstr); tmpstr = NULL;
2372        if(tpnode != NULL)
2373        {
2374                tmpstr = oitoa(tpnode->modulation);
2375                setchoiceboxselection(modulation, tmpstr);
2376                free(tmpstr); tmpstr = NULL;
2377        }
2378
2379        //rolloff
2380        tmpstr = transpondergetrolloffstr(tpnode, 1);
2381        changeinput(rolloff, tmpstr);
2382        free(tmpstr); tmpstr = NULL;
2383        tmpstr = transpondergetrolloffstr(tpnode, 2);
2384        changechoiceboxvalue(rolloff, tmpstr);
2385        free(tmpstr); tmpstr = NULL;
2386        if(tpnode != NULL)
2387        {
2388                tmpstr = oitoa(tpnode->rolloff);
2389                setchoiceboxselection(rolloff, tmpstr);
2390                free(tmpstr); tmpstr = NULL;
2391        }
2392
2393        //pilot
2394        tmpstr = transpondergetpilotstr(tpnode, 1);
2395        changeinput(pilot, tmpstr);
2396        free(tmpstr); tmpstr = NULL;
2397        tmpstr = transpondergetpilotstr(tpnode, 2);
2398        changechoiceboxvalue(pilot, tmpstr);
2399        free(tmpstr); tmpstr = NULL;
2400        if(tpnode != NULL)
2401        {
2402                tmpstr = oitoa(tpnode->pilot);
2403                setchoiceboxselection(pilot, tmpstr);
2404                free(tmpstr); tmpstr = NULL;
2405        }
2406
2407        //hp
2408        tmpstr = transpondergetfecstr(tpnode, fetype, 1);
2409        changeinput(hp, tmpstr);
2410        free(tmpstr); tmpstr = NULL;
2411        tmpstr = transpondergetfecstr(tpnode, fetype, 2);
2412        changechoiceboxvalue(hp, tmpstr);
2413        free(tmpstr); tmpstr = NULL;
2414        if(tpnode != NULL)
2415        {
2416                tmpstr = oitoa(tpnode->fec);
2417                setchoiceboxselection(hp, tmpstr);
2418                free(tmpstr); tmpstr = NULL;
2419        }
2420
2421        //lp
2422        tmpstr = transpondergetfecstr(tpnode, fetype, 1);
2423        changeinput(lp, tmpstr);
2424        free(tmpstr); tmpstr = NULL;
2425        tmpstr = transpondergetfecstr(tpnode, fetype, 2);
2426        changechoiceboxvalue(lp, tmpstr);
2427        free(tmpstr); tmpstr = NULL;
2428        if(tpnode != NULL)
2429        {
2430                tmpstr = oitoa(tpnode->polarization);
2431                setchoiceboxselection(lp, tmpstr);
2432                free(tmpstr); tmpstr = NULL;
2433        }
2434
2435        //bandwidth
2436        tmpstr = transpondergetbandwidthstr(tpnode, 1);
2437        changeinput(bandwidth, tmpstr);
2438        free(tmpstr); tmpstr = NULL;
2439        tmpstr = transpondergetbandwidthstr(tpnode, 2);
2440        changechoiceboxvalue(bandwidth, tmpstr);
2441        free(tmpstr); tmpstr = NULL;
2442        if(tpnode != NULL)
2443        {
2444                tmpstr = oitoa(tpnode->symbolrate);
2445                setchoiceboxselection(bandwidth, tmpstr);
2446                free(tmpstr); tmpstr = NULL;
2447        }
2448
2449        //guardinterval
2450        tmpstr = transpondergetguardintervalstr(tpnode, 1);
2451        changeinput(guardinterval, tmpstr);
2452        free(tmpstr); tmpstr = NULL;
2453        tmpstr = transpondergetguardintervalstr(tpnode, 2);
2454        changechoiceboxvalue(guardinterval, tmpstr);
2455        free(tmpstr); tmpstr = NULL;
2456        if(tpnode != NULL)
2457        {
2458                tmpstr = oitoa(tpnode->rolloff);
2459                setchoiceboxselection(guardinterval, tmpstr);
2460                free(tmpstr); tmpstr = NULL;
2461        }
2462
2463        //transmission
2464        tmpstr = transpondergettransmissionstr(tpnode, 1);
2465        changeinput(transmission, tmpstr);
2466        free(tmpstr); tmpstr = NULL;
2467        tmpstr = transpondergettransmissionstr(tpnode, 2);
2468        changechoiceboxvalue(transmission, tmpstr);
2469        free(tmpstr); tmpstr = NULL;
2470        if(tpnode != NULL)
2471        {
2472                tmpstr = oitoa(tpnode->pilot);
2473                setchoiceboxselection(transmission, tmpstr);
2474                free(tmpstr); tmpstr = NULL;
2475        }
2476
2477        //hierarchy
2478        tmpstr = transpondergethierarchystr(tpnode, 1);
2479        changeinput(hierarchy, tmpstr);
2480        free(tmpstr); tmpstr = NULL;
2481        tmpstr = transpondergethierarchystr(tpnode, 2);
2482        changechoiceboxvalue(hierarchy, tmpstr);
2483        free(tmpstr); tmpstr = NULL;
2484        if(tpnode != NULL)
2485        {
2486                tmpstr = oitoa(tpnode->system);
2487                setchoiceboxselection(hierarchy, tmpstr);
2488                free(tmpstr); tmpstr = NULL;
2489        }
2490
2491        //networkscan
2492        addchoicebox(networkscan, "0", _("no"));
2493        addchoicebox(networkscan, "1", _("yes"));
2494
2495        //clear
2496        addchoicebox(clear, "0", _("no"));
2497        addchoicebox(clear, "1", _("yes"));
2498
2499        //only free
2500        addchoicebox(onlyfree, "0", _("no"));
2501        addchoicebox(onlyfree, "1", _("yes"));
2502
2503        //blindscan
2504        addchoicebox(blindscan, "0", _("no"));
2505        addchoicebox(blindscan, "1", _("yes"));
2506
2507        //changename
2508        addchoicebox(changename, "1", _("yes"));
2509        addchoicebox(changename, "0", _("no"));
2510
2511        //favtype
2512        addchoicebox(favtype, "0", _("Unchanged"));
2513        addchoicebox(favtype, "1", _("Create new"));
2514        addchoicebox(favtype, "2", _("Delete All"));
2515
2516        //emptybouquet
2517        addchoicebox(emptybouquet, "0", _("no"));
2518        addchoicebox(emptybouquet, "1", _("yes"));
2519
2520        //unusedbouquetchannels
2521        addchoicebox(unusedbouquetchannels, "0", _("no"));
2522        addchoicebox(unusedbouquetchannels, "1", _("yes"));
2523
2524        //unusedsatprovider
2525        addchoicebox(unusedsatprovider, "0", _("no"));
2526        addchoicebox(unusedsatprovider, "1", _("yes"));
2527
2528        //cleartransponder
2529        addchoicebox(cleartransponder, "0", _("no"));
2530        addchoicebox(cleartransponder, "1", _("yes"));
2531
2532        drawscreen(scan, 2, 0);
2533        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);
2534        drawscreen(scan, 0, 0);
2535        addscreenrc(scan, listbox);
2536
2537        tmp = listbox->select;
2538        while(1)
2539        {
2540                addscreenrc(scan, tmp);
2541
2542                if(clear->ret != NULL && ostrcmp(clear->ret, "1") == 0)
2543                {
2544                        emptybouquet->hidden = NO;
2545                        unusedbouquetchannels->hidden = NO;
2546                        unusedsatprovider->hidden = NO;
2547                        cleartransponder->hidden = NO;
2548                }
2549                else
2550                {
2551                        emptybouquet->hidden = YES;
2552                        unusedbouquetchannels->hidden = YES;
2553                        unusedsatprovider->hidden = YES;
2554                        cleartransponder->hidden = YES;
2555                }
2556                drawscreen(scan, 0, 0);
2557
2558                rcret = waitrc(scan, 0, 0);
2559                tmp = listbox->select;
2560
2561                if(scantype->ret != NULL) iscantype = atoi(scantype->ret);
2562                if(sat->ret != NULL) isat = atoi(sat->ret);
2563                if(system->ret != NULL) isystem = atoi(system->ret);
2564                if(frequency->ret != NULL) ifrequency = atoi(frequency->ret) * 1000;
2565                if(inversion->ret != NULL) iinversion = atoi(inversion->ret);
2566                if(symbolrate->ret != NULL) isymbolrate = atoi(symbolrate->ret) * 1000;
2567                if(polarization->ret != NULL) ipolarization = atoi(polarization->ret);
2568                if(fec->ret != NULL) ifec = atoi(fec->ret);
2569                if(modulation->ret != NULL) imodulation = atoi(modulation->ret);
2570                if(rolloff->ret != NULL) irolloff = atoi(rolloff->ret);
2571                if(pilot->ret != NULL) ipilot = atoi(pilot->ret);
2572
2573                if(flag == 3)
2574                {
2575                        if(hp->ret != NULL) ifec = atoi(hp->ret);
2576                        if(lp->ret != NULL) ipolarization = atoi(lp->ret);
2577                        if(bandwidth->ret != NULL) isymbolrate = atoi(bandwidth->ret);
2578                        if(transmission->ret != NULL) ipilot = atoi(transmission->ret);
2579                        if(guardinterval->ret != NULL) irolloff = atoi(guardinterval->ret);
2580                        if(hierarchy->ret != NULL) isystem = atoi(hierarchy->ret);
2581                }
2582
2583                if(networkscan->ret != NULL) inetworkscan = atoi(networkscan->ret);
2584                if(onlyfree->ret != NULL) ionlyfree = atoi(onlyfree->ret);
2585                if(clear->ret != NULL) iclear = atoi(clear->ret);
2586                if(blindscan->ret != NULL) iblindscan = atoi(blindscan->ret);
2587                if(changename->ret != NULL) ichangename = atoi(changename->ret);
2588                if(favtype->ret != NULL) ifavtype = atoi(favtype->ret);
2589                if(emptybouquet->ret != NULL) iemptybouquet = atoi(emptybouquet->ret);
2590                if(unusedbouquetchannels->ret != NULL) iunusedbouquetchannels = atoi(unusedbouquetchannels->ret);
2591                if(unusedsatprovider->ret != NULL) iunusedsatprovider = atoi(unusedsatprovider->ret);
2592                if(cleartransponder->ret != NULL) icleartransponder = atoi(cleartransponder->ret);
2593
2594                if(rcret == getrcconfigint("rcexit", NULL)) break;
2595                if(rcret == getrcconfigint("rcok", NULL)) break;
2596                if(listbox->select != NULL && ostrcmp(listbox->select->name, "tuner") == 0)
2597                {
2598                        scanchangesat(sat, tpnode, listbox->select->ret);
2599                        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);
2600                        drawscreen(scan, 0, 0);
2601                }
2602                if(listbox->select != NULL && ostrcmp(listbox->select->name, "scantype") == 0)
2603                {
2604                        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);
2605                        drawscreen(scan, 0, 0);
2606                }
2607                if(listbox->select != NULL && ostrcmp(listbox->select->name, "system") == 0)
2608                {
2609                        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);
2610                        drawscreen(scan, 0, 0);
2611                }
2612                if(rcret == getrcconfigint("rcred", NULL))
2613                {
2614                        clearscreen(scan);
2615                        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);
2616                        drawscreen(scan, 0, 0);
2617                }
2618                if(rcret == getrcconfigint("rcgreen", NULL) && tpnode != NULL && iscantype == 0)
2619                {
2620                        struct transponder* tp1 = createtransponder(99, tpnode->fetype, isat, ifrequency, iinversion, isymbolrate, ipolarization, ifec, imodulation, irolloff, ipilot, isystem);
2621                        copytransponder(tp1, tpnode, 99);
2622                        deltransponderbyid(99);
2623                        textbox(_("Message"), _("Transponder changed"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0);
2624                        drawscreen(scan, 0, 0);
2625                }
2626                if(rcret == getrcconfigint("rcyellow", NULL) && iscantype == 0)
2627                {
2628                        struct transponder* tp = tpchoicescreen(isat, flag);
2629                        if(tp != NULL)
2630                        {
2631                                tpnode = tp;
2632                                goto start;
2633                        }
2634                        else
2635                                drawscreen(scan, 0, 0);
2636                }
2637                else if(rcret == getrcconfigint("rcok", NULL))
2638                        break;
2639        }
2640
2641        delmarkedscreennodes(scan, 1);
2642        delownerrc(scan);
2643        clearscreen(scan);
2644        resetsatscan();
2645
2646        if(status.lastservice->channel == NULL)
2647        {
2648                if(getchannel(getconfigint("serviceid", NULL), getconfigllu("transponderid", NULL)) != NULL)
2649                {
2650                        if(status.servicetype == 0)
2651                                servicecheckret(servicestart(getchannel(getconfigint("serviceid", NULL), getconfigllu("transponderid", NULL)), getconfig("channellist", NULL), NULL, 0), 0);
2652                        else
2653                                servicecheckret(servicestart(getchannel(getconfigint("rserviceid", NULL), getconfigllu("rtransponderid", NULL)), getconfig("rchannellist", NULL),  NULL, 0), 0);
2654                }
2655        }
2656        else
2657        {
2658                tmpstr = ostrcat(status.lastservice->channellist, NULL, 0, 0);
2659                servicecheckret(servicestart(status.lastservice->channel, tmpstr, NULL, 0), 0);
2660                free(tmpstr); tmpstr = NULL;
2661        }
2662
2663        //recalc channels
2664        struct channel* chnode = channel;
2665        while(chnode != NULL)
2666        {
2667                if(chnode->servicetype != 99)
2668                {
2669                        chnode->transponder = gettransponder(chnode->transponderid);
2670                        chnode->provider = getprovider(chnode->providerid);
2671                }
2672                chnode = chnode->next;
2673        }
2674
2675        writeallconfig(1);
2676}
2677
2678#endif
Note: See TracBrowser for help on using the repository browser.