source: titan/titan/scan.h @ 42867

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

[titan] last fix DVB-t2 nit scan

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