source: titan/titan/scan.h @ 40808

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

next fix

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