source: titan/titan/scan.h @ 43326

Last change on this file since 43326 was 43102, checked in by gost, 5 years ago

fix

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