source: titan/titan/scan.h @ 40810

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

[titan] add new DVB-T variables

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