source: titan/titan/scan.h @ 22550

Last change on this file since 22550 was 22445, checked in by nit, 11 years ago

[titan] add please wait before sort channel

File size: 64.8 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        if(frequency > 1000000) frequency /= 1000;
203
204        frequency = (int)1000 * (int)round((double)frequency / (double)1000);
205
206        id = ((onid << 16) | transportid) & 0xffffffff;
207        id = id | ((uint64_t)1 << 32);
208
209        if(gettransponder(id) == NULL)
210        {
211                tpnode = createtransponder(id, FE_QAM, orbitalpos, frequency, INVERSION_AUTO, symbolrate, 0, fec, modulation, 0, 0, 0);
212                status.writetransponder = 1;
213        }
214
215        debug(500, "nitscan: id=%llu freq=%d sr=%d fec=%d modulation=%d tpnode=%p", id, frequency, symbolrate, fec, modulation, tpnode);
216
217        return tpnode;
218}
219
220struct transponder* terrsystemdesc(unsigned char* buf, uint64_t transportid, unsigned short onid, int orbitalpos)
221{
222        int modulation = 0, hp = 0, lp = 0;
223        int bandwidth = 0, hierarchy = 0, guardinterval = 0;
224        int transmission = 0;
225        unsigned int frequency = 0;
226        uint64_t id = 0;
227        struct transponder *tpnode = NULL;
228
229        if(buf == NULL) return NULL;
230
231        frequency = (buf[2] << 24) | (buf[3] << 16);
232        frequency |= (buf[4] << 8) | buf[5];
233        frequency *= 10;
234
235        bandwidth = BANDWIDTH_8_MHZ + ((buf[6] >> 5) & 0x3);
236        modulation = (buf[7] >> 6) & 0x3;
237        hierarchy = HIERARCHY_NONE + ((buf[7] >> 3) & 0x3);
238
239        hp = (buf[7] & 0x7);
240        switch(hp)
241        {
242                case 0x00:
243                        hp = FEC_1_2;
244                        break;
245                case 0x01:
246                        hp = FEC_2_3;
247                        break;
248                case 0x02:
249                        hp = FEC_3_4;
250                        break;
251                case 0x03:
252                        hp = FEC_5_6;
253                        break;
254                case 0x04:
255                        hp = FEC_7_8;
256                        break;
257                default:
258                        hp = FEC_AUTO;
259                        break;
260        }
261
262        lp = ((buf[8] >> 5) & 0x7);
263        switch(lp)
264        {
265                case 0x00:
266                        lp = FEC_1_2;
267                        break;
268                case 0x01:
269                        lp = FEC_2_3;
270                        break;
271                case 0x02:
272                        lp = FEC_3_4;
273                        break;
274                case 0x03:
275                        lp = FEC_5_6;
276                        break;
277                case 0x04:
278                        lp = FEC_7_8;
279                        break;
280                default:
281                        lp = FEC_AUTO;
282                        break;
283        }
284
285        guardinterval = GUARD_INTERVAL_1_32 + ((buf[8] >> 3) & 0x3);
286
287        transmission = (buf[8] & 0x2);
288        switch(transmission)
289        {
290                case 0x00:
291                        transmission = TRANSMISSION_MODE_2K;
292                        break;
293                case 0x01:
294                        transmission = TRANSMISSION_MODE_8K;
295                        break;
296                case 0x02:
297                        transmission = TRANSMISSION_MODE_AUTO;
298                        break;
299                default:
300                        transmission = TRANSMISSION_MODE_AUTO;
301                        break;
302        }
303
304        //other_frequency_flag = (buf[8] & 0x01);
305
306        id = ((onid << 16) | transportid) & 0xffffffff;
307        id = id | ((uint64_t)2 << 32);
308
309        if(gettransponder(id) == NULL)
310        {
311                tpnode = createtransponder(id, FE_OFDM, orbitalpos, frequency, INVERSION_AUTO, bandwidth, lp, hp, modulation, guardinterval, transmission, hierarchy);
312                status.writetransponder = 1;
313        }
314
315        debug(500, "nitscan: id=%llu freq=%d bandwidth=%d hp=%d lp=%d modulation=%d guard=%d trans=%d hierarchy=%d tpnode=%p", id, frequency, bandwidth, hp, lp, modulation, guardinterval, transmission, hierarchy, tpnode);
316
317        return tpnode;
318}
319
320int parsenit(unsigned char* buf, uint8_t* lastsecnr, int orbitalpos)
321{
322        int ret = 0;
323
324        if(buf == NULL) return ret;
325
326        //unsigned char buf[MINMALLOC];
327
328        // position in buffer
329        unsigned short pos = 0;
330        unsigned short pos2 = 0;
331
332        // network_information_section elements
333        unsigned short seclen = 0;
334        unsigned short desclen = 0;
335        unsigned short tdesclen = 0;
336        unsigned short looplen = 0;
337        uint64_t transponderid = 0;
338        unsigned short onid = 0;
339        unsigned short nid = 0;
340        unsigned char secnr = 0;
341
342        seclen = ((buf[1] & 0x0F) << 8) + buf[2];
343        nid = ((buf[3] << 8)| buf[4]);
344        desclen = ((buf[8] & 0x0F) << 8) | buf[9];
345        secnr = buf[6];
346        *lastsecnr = buf[7];
347        debug(500, "nitscan: section %d last %d nid %d", secnr, *lastsecnr, nid);
348
349        for(pos = 10; pos < desclen + 10; pos += buf[pos + 1] + 2)
350        {
351                switch(buf[pos])
352                {
353                        case 0x0F:
354                                //private_data_indicator_desc(buf + pos);
355                                break;
356                        case 0x40:
357                                //network_name_desc(buf + pos);
358                                break;
359                        case 0x4A:
360                                //linkage_desc(buf + pos);
361                                break;
362                        case 0x5B:
363                                //multilingual_networkname_desc(buf + pos);
364                                break;
365                        case 0x5F:
366                                //private_data_specifier_desc(buf + pos);
367                                break;
368                        case 0x80:
369                                break;
370                        case 0x90:
371                                break;
372                }
373        }
374
375        looplen = ((buf[pos] & 0x0F) << 8) | buf[pos + 1];
376        if (!looplen) return ret;
377
378        for(pos += 2; pos < seclen - 3; pos += tdesclen + 6)
379        {
380                transponderid = (buf[pos] << 8) | buf[pos + 1];
381                onid = (buf[pos + 2] << 8) | buf[pos + 3];
382                tdesclen = ((buf[pos + 4] & 0x0F) << 8) | buf[pos + 5];
383
384                for(pos2 = pos + 6; pos2 < pos + tdesclen + 6; pos2 += buf[pos2 + 1] + 2)
385                {
386                        switch(buf[pos2])
387                        {
388                                case 0x41:
389                                        //servicelistdesc(buf + pos2, transponderid, onid);
390                                        break;
391                                case 0x43:
392                                        if(satsystemdesc(buf + pos2, transponderid, onid, orbitalpos) != NULL)
393                                        {
394                                                scaninfo.tpnew++;
395                                                if(scaninfo.scantype != 0)
396                                                        scaninfo.tpmax++;
397                                        }
398                                        break;
399                                case 0x44:
400                                        if(cablesystemdesc(buf + pos2, transponderid, onid, orbitalpos) != NULL)
401                                        {
402                                                scaninfo.tpnew++;
403                                                if(scaninfo.scantype != 0)
404                                                        scaninfo.tpmax++;
405                                        }
406                                        break;
407                                case 0x5A:
408                                        if(terrsystemdesc(buf + pos2, transponderid, onid, orbitalpos) != NULL)
409                                        {
410                                                scaninfo.tpnew++;
411                                                if(scaninfo.scantype != 0)
412                                                        scaninfo.tpmax++;
413                                        }
414                                        break;
415                                case 0x62:
416                                        //frequencylistdesc(buf + pos2);
417                                        break;
418                        }
419                }
420        }
421
422        return ret;
423}
424
425//flag 0: from scan
426//flag 1: from update channelname
427int findchannel(struct dvbdev* fenode, struct transponder* tpnode, unsigned char *buf, uint8_t* lastsecnr, struct skin* scan, struct skin* listbox, int ichangename, int flag)
428{
429        int ret = -1, changed = 0;
430        uint64_t transponderid = 0;
431        struct skin* node = NULL;
432        struct channel* chnode = NULL;
433
434        // position in buffer
435        unsigned short pos;
436        unsigned short pos2;
437
438        // service_description_section elements
439        unsigned short seclen;
440        uint8_t secnr;
441        unsigned short onid, tid;
442        unsigned short serviceid;
443        unsigned short desclooplen;
444        unsigned short running;
445        int eitscheduleflag;
446        int eitpresentfollowingflag;
447        int camode;
448        uint8_t servicetype = 0;
449        uint8_t providerlen = 0;
450        char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL;
451        uint64_t* tmpuint64 = NULL;
452
453        if(buf == NULL || fenode == NULL || fenode->feinfo == NULL) return ret;
454
455        seclen = ((buf[1] & 0x0F) << 8) | buf[2];
456        secnr = buf[6];
457        *lastsecnr = buf[7];
458        tid = (buf[3] << 8) | buf[4];
459        onid = (buf[8] << 8) | buf[9];
460       
461        transponderid = ((onid << 16) | tid) & 0xffffffff;
462        if(fenode->feinfo->type == FE_QAM)
463                transponderid = transponderid | ((uint64_t)1 << 32);
464        else if(fenode->feinfo->type == FE_OFDM)
465                transponderid = transponderid | ((uint64_t)2 << 32);
466        if(tpnode != NULL && tpnode->id != transponderid && tpnode->id != 99)
467        {
468                changetransponderid(tpnode, transponderid);
469                status.writetransponder = 1;
470        }
471
472        debug(500, "SDT nr: %d, lastnr: %d, len: %d, tid: %d, onid: %d, transponderid: %llu", secnr, *lastsecnr, seclen, tid, onid, transponderid);
473
474        for(pos = 11; pos < seclen - 1; pos += desclooplen + 5)
475        {
476                serviceid = (buf[pos] << 8) | buf[pos + 1];
477                eitscheduleflag = buf[pos + 2] & 0x02;
478                eitpresentfollowingflag = buf[pos + 2] & 0x01;
479                running = buf[pos + 3] & 0xE0;
480                camode = buf[pos + 3] & 0x10;
481                desclooplen = ((buf[pos + 3] & 0x0F) << 8) | buf[pos + 4];
482                if(flag == 0 && scaninfo.onlyfree == 1 && camode > 0) continue;
483
484                for(pos2 = pos + 5; pos2 < pos + desclooplen + 5; pos2 += buf[pos2 + 1] + 2)
485                {
486                        switch(buf[pos2])
487                        {
488                                case 0x48:
489                                        servicetype = buf[pos2 + 2];
490                                        servicetype = changeservicetype(servicetype);
491                                        providerlen = buf[pos2 + 3];
492                                       
493                                        //providername
494                                        tmpstr1 = strndup((char*)&(buf[pos2 + 4]), providerlen);
495                                        //channelname
496                                        tmpstr2 = strndup((char*)&(buf[pos2 + 4 + providerlen + 1]), (2 + buf[pos2 + 1]) - (4 + providerlen + 1));
497
498                                        tmpstr1 = string_strip_whitechars(tmpstr1);
499                                        tmpstr2 = string_strip_whitechars(tmpstr2);
500                                        if(tmpstr1 == NULL || strlen(tmpstr1) == 0) tmpstr1 = ostrcat(tmpstr1, "unknown", 1, 0);
501                                        if(tmpstr2 == NULL || strlen(tmpstr2) == 0) tmpstr2 = ostrcat(tmpstr2, "unknown", 1, 0);
502
503                                        tmpstr1 = strutf8(tpnode, tmpstr1, strlen(tmpstr1), 0, 1, 0);
504                                        tmpstr1 = stringreplacechar(tmpstr1, '#', '_');
505                                        tmpstr2 = strutf8(tpnode, tmpstr2, strlen(tmpstr2), 0, 1, 1);
506                                        tmpstr2 = stringreplacechar(tmpstr2, '#', '_');
507
508                                        //add to listbox
509                                        chnode = getchannel(serviceid, transponderid);
510                                        if(flag == 0) node = addlistbox(scan, listbox, node, 1);
511                                        if(node != NULL)
512                                        {
513                                                switch(servicetype)
514                                                {
515                                                        case 0:
516                                                                scaninfo.tvcount++;
517                                                                if(chnode == NULL) scaninfo.newtvcount++;
518                                                                break;
519                                                        case 1:
520                                                                scaninfo.radiocount++;
521                                                                if(chnode == NULL) scaninfo.newradiocount++;
522                                                                break;
523                                                        default:
524                                                                scaninfo.datacount++;
525                                                                if(chnode == NULL) scaninfo.newdatacount++;
526                                                                break;
527                                                }
528                                                tmpstr = ostrcat(tmpstr2, " (", 0, 0);
529                                                tmpstr = ostrcat(tmpstr, tmpstr1, 1, 0);
530                                                tmpstr = ostrcat(tmpstr, " - ", 1, 0);
531                                                if(servicetype == 0)
532                                                        tmpstr = ostrcat(tmpstr, _("TV"), 1, 0);
533                                                else if(servicetype == 1)
534                                                        tmpstr = ostrcat(tmpstr, _("Radio"), 1, 0);
535                                                else
536                                                        tmpstr = ostrcat(tmpstr, _("Data"), 1, 0);
537
538                                                changed = 0;
539                                                if(chnode != NULL && chnode->name != NULL && strlen(chnode->name) > 0 && ostrcmp(tmpstr2, chnode->name) != 0)
540                                                {
541                                                        tmpstr = ostrcat(tmpstr, " - ", 1, 0);
542                                                        tmpstr = ostrcat(tmpstr, chnode->name, 1, 0);
543                                                        if(ichangename == 1) changed = 1;
544                                                }
545                                                tmpstr = ostrcat(tmpstr, ")", 1, 0);
546                                                changetext(node, tmpstr);
547
548                                                if(chnode != NULL && chnode->transponder != NULL && changed == 0)
549                                                        node->fontcol = convertcol("deaktivcol");
550
551                                                changeparam1(node, tmpstr1);
552                                                changeparam2(node, tmpstr2);
553                                                tmpuint64 = (uint64_t*)calloc(1, sizeof(uint64_t) * 3);
554                                                if(tmpuint64 != NULL)
555                                                {
556                                                        tmpuint64[0] = serviceid;
557                                                        tmpuint64[1] = transponderid;
558                                                        tmpuint64[2] = servicetype;
559                                                }
560                                                free(node->name);
561                                                node->name = (char*)tmpuint64;
562                                        }
563                                       
564                                        if(flag == 1 && chnode != NULL && ostrcmp(chnode->name, tmpstr2) != 0)
565                                        {
566                                                free(chnode->name);
567                                                chnode->name = ostrcat(tmpstr2, NULL, 0, 0);
568                                                status.writechannel = 1;
569                                        }
570                                       
571                                        free(tmpstr); tmpstr = NULL;
572                                        free(tmpstr1); tmpstr1 = NULL;
573                                        free(tmpstr2); tmpstr2 = NULL;
574
575                                        ret = 0;
576                                        break;
577                        }
578                }
579        }
580
581        return ret;
582}
583
584uint64_t findtransponderid(struct dvbdev* fenode, unsigned char *buf)
585{
586        uint64_t transponderid = 0;
587        unsigned short onid, tid;
588
589        if(buf == NULL || fenode == NULL || fenode->feinfo == NULL) return 0;
590
591        tid = (buf[3] << 8) | buf[4];
592        onid = (buf[8] << 8) | buf[9];
593       
594        transponderid = ((onid << 16) | tid) & 0xffffffff;
595
596        if(fenode->feinfo->type == FE_QAM)
597                transponderid = transponderid | ((uint64_t)1 << 32);
598        else if(fenode->feinfo->type == FE_OFDM)
599                transponderid = transponderid | ((uint64_t)2 << 32);
600
601        debug(500, "found SDT transponderid: %llu", transponderid);
602
603        return transponderid;
604}
605
606unsigned int satblindscan(struct stimerthread* timernode, int onlycalc)
607{
608        int festatus = 0;
609        uint64_t transponderid = 0;
610        unsigned char* buf = NULL;
611        struct dvbdev* fenode = NULL;
612        struct transponder* tpnode = NULL;
613
614        unsigned int frequency = 0, symbolrate = 0;
615        int polarization = 0, modulation = 0, system = 0, fec = 0;
616
617        unsigned int minfrequency = getconfigint("blindminfrequency", NULL) * 1000;
618        unsigned int maxfrequency = getconfigint("blindmaxfrequency", NULL) * 1000;
619        unsigned int stepfrequency = getconfigint("blindstepfrequency", NULL) * 1000;
620        unsigned int minsymbolrate = getconfigint("blindminsignalrate", NULL) * 1000;
621        unsigned int maxsymbolrate = getconfigint("blindmaxsignalrate", NULL) * 1000;
622        unsigned int stepsymbolrate = getconfigint("blindstepsignalrate", NULL) * 1000;
623        unsigned int usedefaultsr = getconfigint("blindusedefaultsr", NULL);
624        unsigned int onlydvbs = getconfigint("blindonlydvbs", NULL);
625        unsigned int usedefaultfec = getconfigint("blindusedefaultfec", NULL);
626       
627        int minmodulation = 1, maxmodulation = 2, stepmodulation = 1;
628        int minpolarization = 0, maxpolarization = 1, steppolarization = 1;
629        int minsystem = 0, maxsystem = 1, stepsystem = 1;
630        int minfec = 0, maxfec = 8, stepfec = 1;
631
632        if(onlydvbs == 1)
633        {
634                maxmodulation = 0;
635                maxsystem = 0;
636        }
637
638        if(usedefaultsr == 1)
639        {
640                minsymbolrate = 0;
641                maxsymbolrate = 3;
642                stepsymbolrate = 1;
643        }
644
645        if(usedefaultfec == 1)
646                maxfec = 6;
647
648        int countfrequency = ((maxfrequency + stepfrequency) - minfrequency) / stepfrequency;
649        int countsymbolrate = ((maxsymbolrate + stepsymbolrate) - minsymbolrate) / stepsymbolrate;
650        int countmodulation = ((maxmodulation + stepmodulation) - minmodulation) / stepmodulation;
651        int countpolarization = ((maxpolarization + steppolarization) - minpolarization) / steppolarization;
652        int countfec = ((maxfec + stepfec) - minfec) / stepfec;
653        int systemcount = ((maxsystem + stepsystem) - minsystem) / stepsystem;
654       
655        if(onlycalc == 1) return systemcount * countpolarization * countmodulation * countsymbolrate * countfrequency * countfec;
656
657        if(scaninfo.fenode == NULL || timernode == NULL) return -1;
658        int timeout = scaninfo.timeout / 5;
659        if(timeout < 1000000) timeout = 1000000;
660        scaninfo.blindmax += systemcount * countpolarization * countmodulation * countsymbolrate * countfrequency * countfec;
661
662        for(frequency = minfrequency; frequency <= maxfrequency; frequency += stepfrequency)
663        {
664
665                int csymbolrate = 0;
666                for(csymbolrate = minsymbolrate; csymbolrate <= maxsymbolrate; csymbolrate += stepsymbolrate)
667                {
668                        if(usedefaultsr == 1)
669                        {
670                                switch(csymbolrate)
671                                {
672                                        case 0:
673                                                symbolrate = 22000 * 1000;
674                                                break;
675                                        case 1:
676                                                symbolrate = 27500 * 1000;
677                                                break;
678                                        case 2:
679                                                symbolrate = 30000 * 1000;
680                                                break;
681                                }
682                        }
683                        else
684                                symbolrate = csymbolrate;
685
686                        for(modulation = minmodulation; modulation <= maxmodulation; modulation += stepmodulation)
687                        {
688                               
689                                for(polarization = minpolarization; polarization <= maxpolarization; polarization += steppolarization)
690                                {
691
692                                        for(fec = minfec; fec <= maxfec; fec += stepfec)
693                                        {
694
695                                                for(system = minsystem; system <= maxsystem; system += stepsystem)
696                                                {
697                                                        scaninfo.blindcount++;
698
699                                                        tpnode = createtransponder(99, scaninfo.fenode->feinfo->type, scaninfo.orbitalpos, frequency, INVERSION_AUTO, symbolrate, polarization, fec, modulation, 0, 0, system);
700
701                                                        debug(500, "blindscan: frequ=%d, sr=%d, modulation=%d, fec=%d, system=%d, orbitalpos=%d", frequency, symbolrate, modulation, fec, system, scaninfo.orbitalpos);
702
703                                                        if(tpnode != NULL)
704                                                        {
705
706                                                                fenode = fegetfree(tpnode, 0, scaninfo.fenode);
707                                                                if(fenode == NULL )
708                                                                {
709                                                                        debug(500, "Frontend for scan not free");
710                                                                        deltransponderbyid(99);
711                                                                        continue;
712                                                                }
713
714                                                                //frontend tune
715                                                                if(fenode->feinfo->type == FE_QPSK)
716                                                                {
717                                                                        feset(fenode, tpnode);
718                                                                        fetunedvbs(fenode, tpnode);
719                                                                }
720                                                                else
721                                                                {
722                                                                        debug(500, "Frontend type unknown");
723                                                                        deltransponderbyid(99);
724                                                                        continue;
725                                                                }
726
727                                                                festatus = fewait(fenode);
728                                                                if(debug_level == 200) fereadstatus(fenode);
729                                                                if(festatus != 0)
730                                                                {
731                                                                        debug(500, "tuning failed");
732                                                                        deltransponderbyid(99);
733                                                                        continue;
734                                                                }
735
736                                                                buf = dvbgetsdt(fenode, 0, timeout);
737                                                                transponderid = findtransponderid(fenode, buf);
738                                                                free(buf); buf = NULL;
739
740                                                                if(transponderid == 0 || gettransponder(transponderid) != NULL)
741                                                                {
742                                                                        deltransponderbyid(99);
743                                                                        continue;
744                                                                }
745
746                                                                if(tpnode->id != transponderid)
747                                                                {
748                                                                        scaninfo.newblindcount++;
749                                                                        changetransponderid(tpnode, transponderid);
750                                                                        status.writetransponder = 1;
751                                                                }
752                                                        }
753                                                        deltransponderbyid(99);
754                                                        if(timernode->aktion != START) break;
755                                                }
756                                                if(timernode->aktion != START) break;
757                                        }
758                                        if(timernode->aktion != START) break;
759                                }
760                                if(timernode->aktion != START) break;
761                        }
762                        if(timernode->aktion != START) break;
763                }
764                if(timernode->aktion != START) break;
765        }
766       
767        return 0;
768}
769
770unsigned int cableblindscan(struct stimerthread* timernode, int onlycalc)
771{
772        int festatus = 0;
773        uint64_t transponderid = 0;
774        unsigned char* buf = NULL;
775        struct dvbdev* fenode = NULL;
776        struct transponder* tpnode = NULL;
777
778        unsigned int frequency = 0, symbolrate = 0;
779        int modulation = 0, fec = 0;
780
781        unsigned int minfrequency = getconfigint("cblindminfrequency", NULL) * 1000;
782        unsigned int maxfrequency = getconfigint("cblindmaxfrequency", NULL) * 1000;
783        unsigned int stepfrequency = getconfigint("cblindstepfrequency", NULL) * 1000;
784        unsigned int minsymbolrate = getconfigint("cblindminsignalrate", NULL) * 1000;
785        unsigned int maxsymbolrate = getconfigint("cblindmaxsignalrate", NULL) * 1000;
786        unsigned int stepsymbolrate = getconfigint("cblindstepsignalrate", NULL) * 1000;
787        unsigned int usedefaultsr = getconfigint("cblindusedefaultsr", NULL);
788        unsigned int usedefaultfec = getconfigint("cblindusedefaultfec", NULL);
789       
790        int minmodulation = 0, maxmodulation = 4, stepmodulation = 1;
791        int minfec = 0, maxfec = 8, stepfec = 1;
792
793        if(usedefaultsr == 1)
794        {
795                minsymbolrate = 0;
796                maxsymbolrate = 3;
797                stepsymbolrate = 1;
798        }
799
800        if(usedefaultfec == 1)
801                maxfec = 6;
802
803        int countfrequency = ((maxfrequency + stepfrequency) - minfrequency) / stepfrequency;
804        int countsymbolrate = ((maxsymbolrate + stepsymbolrate) - minsymbolrate) / stepsymbolrate;
805        int countmodulation = ((maxmodulation + stepmodulation) - minmodulation) / stepmodulation;
806        int countfec = ((maxfec + stepfec) - minfec) / stepfec;
807       
808        if(onlycalc == 1) return countmodulation * countsymbolrate * countfrequency * countfec;
809       
810        if(scaninfo.fenode == NULL || timernode == NULL) return -1;
811        int timeout = scaninfo.timeout / 5;
812        if(timeout < 1000000) timeout = 1000000;
813        scaninfo.blindmax += countmodulation * countsymbolrate * countfrequency * countfec;
814
815        for(frequency = minfrequency; frequency <= maxfrequency; frequency += stepfrequency)
816        {
817
818                int csymbolrate = 0;
819                for(csymbolrate = minsymbolrate; csymbolrate <= maxsymbolrate; csymbolrate += stepsymbolrate)
820                {
821                        if(usedefaultsr == 1)
822                        {
823                                switch(csymbolrate)
824                                {
825                                        case 0:
826                                                symbolrate = 22000 * 1000;
827                                                break;
828                                        case 1:
829                                                symbolrate = 27500 * 1000;
830                                                break;
831                                        case 2:
832                                                symbolrate = 30000 * 1000;
833                                                break;
834                                }
835                        }
836                        else
837                                symbolrate = csymbolrate;
838
839                        for(modulation = minmodulation; modulation <= maxmodulation; modulation += stepmodulation)
840                        {
841
842                                for(fec = minfec; fec <= maxfec; fec += stepfec)
843                                {
844                                        scaninfo.blindcount++;
845
846                                        tpnode = createtransponder(99, scaninfo.fenode->feinfo->type, scaninfo.orbitalpos, frequency, INVERSION_AUTO, symbolrate, 0, fec, modulation, 0, 0, 0);
847
848                                        debug(500, "blindscan: frequ=%d, sr=%d, modulation=%d, fec=%d, orbitalpos=%d", frequency, symbolrate, modulation, fec, scaninfo.orbitalpos);
849
850                                        if(tpnode != NULL)
851                                        {
852
853                                                fenode = fegetfree(tpnode, 0, scaninfo.fenode);
854                                                if(fenode == NULL )
855                                                {
856                                                        debug(500, "Frontend for scan not free");
857                                                        deltransponderbyid(99);
858                                                        continue;
859                                                }
860
861                                                //frontend tune
862                                                if(fenode->feinfo->type == FE_QAM)
863                                                        fetunedvbc(fenode, tpnode);
864                                                else
865                                                {
866                                                        debug(500, "Frontend type unknown");
867                                                        deltransponderbyid(99);
868                                                        continue;
869                                                }
870
871                                                festatus = fewait(fenode);
872                                                if(debug_level == 200) fereadstatus(fenode);
873                                                if(festatus != 0)
874                                                {
875                                                        debug(500, "tuning failed");
876                                                        deltransponderbyid(99);
877                                                        continue;
878                                                }
879
880                                                buf = dvbgetsdt(fenode, 0, timeout);
881                                                transponderid = findtransponderid(fenode, buf);
882                                                free(buf); buf = NULL;
883
884                                                if(transponderid == 0 || gettransponder(transponderid) != NULL)
885                                                {
886                                                        deltransponderbyid(99);
887                                                        continue;
888                                                }
889
890                                                if(tpnode->id != transponderid)
891                                                {
892                                                        scaninfo.newblindcount++;
893                                                        changetransponderid(tpnode, transponderid);
894                                                        status.writetransponder = 1;
895                                                }
896                                        }
897                                        deltransponderbyid(99);
898                                        if(timernode->aktion != START) break;
899                                }
900                                if(timernode->aktion != START) break;
901                        }
902                        if(timernode->aktion != START) break;
903                }
904                if(timernode->aktion != START) break;
905        }
906       
907        return 0;
908}
909
910unsigned int terrblindscan(struct stimerthread* timernode, int onlycalc)
911{
912        int festatus = 0;
913        uint64_t transponderid = 0;
914        unsigned char* buf = NULL;
915        struct dvbdev* fenode = NULL;
916        struct transponder* tpnode = NULL;
917
918        unsigned int frequency = 0;
919        int hp = 0, lp = 0, modulation = 0, bandwidth = 0, transmission = 0, guardinterval = 0, hierarchy = 0;
920
921        unsigned int minfrequency = getconfigint("tblindminfrequency", NULL) * 1000;
922        unsigned int maxfrequency = getconfigint("tblindmaxfrequency", NULL) * 1000;
923        unsigned int stepfrequency = getconfigint("tblindstepfrequency", NULL) * 1000;
924       
925        int minhp = 0, maxhp = 3, stephp = 1;
926        int minlp = 0, maxlp = 3, steplp = 1;
927        int minmodulation = 0, maxmodulation = 2, stepmodulation = 1;
928        int minbandwidth = 0, maxbandwidth = 2, stepbandwidth = 1;
929        int mintransmission = 0, maxtransmission = 1, steptransmission = 1;
930        int minguardinterval = 0, maxguardinterval = 3, stepguardinterval = 1;
931        int minhierarchy = 0, maxhierarchy = 3, stephierarchy = 1;
932
933        int countfrequency = ((maxfrequency + stepfrequency) - minfrequency) / stepfrequency;
934        int counthp = ((maxhp + stephp) - minhp) / stephp;
935        int countlp = ((maxlp + steplp) - minlp) / steplp;
936        int countmodulation = ((maxmodulation + stepmodulation) - minmodulation) / stepmodulation;
937        int countbandwidth = ((maxbandwidth + stepbandwidth) - minbandwidth) / stepbandwidth;
938        int counttransmission = ((maxtransmission + steptransmission) - mintransmission) / steptransmission;
939        int countguardinterval = ((maxguardinterval + stepguardinterval) - minguardinterval) / stepguardinterval;
940        int counthierarchy = ((maxhierarchy + stephierarchy) - minhierarchy) / stephierarchy;
941       
942        if(onlycalc == 1) return counthierarchy * countguardinterval * countmodulation * counttransmission * countfrequency * countbandwidth * countlp * counthp;
943       
944        if(scaninfo.fenode == NULL || timernode == NULL) return -1;
945        int timeout = scaninfo.timeout / 5;
946        if(timeout < 1000000) timeout = 1000000;
947        scaninfo.blindmax += counthierarchy * countguardinterval * countmodulation * counttransmission * countfrequency * countbandwidth * countlp * counthp;
948
949        for(frequency = minfrequency; frequency <= maxfrequency; frequency += stepfrequency)
950        {
951
952                for(hp = minhp; hp <= maxhp; hp += stephp)
953                {
954
955                        for(lp = minlp; lp <= maxlp; lp += steplp)
956                        {
957
958                                for(modulation = minmodulation; modulation <= maxmodulation; modulation += stepmodulation)
959                                {
960
961                                        for(bandwidth = minbandwidth; bandwidth <= maxbandwidth; bandwidth += stepbandwidth)
962                                        {
963
964                                                for(transmission = mintransmission; transmission <= maxtransmission; transmission += steptransmission)
965                                                {
966                                               
967                                                        for(guardinterval = minguardinterval; guardinterval <= maxguardinterval; guardinterval += stepguardinterval)
968                                                        {
969                                               
970                                                                for(hierarchy = minhierarchy; hierarchy <= maxhierarchy; hierarchy += stephierarchy)
971                                                                {
972                                                                        scaninfo.blindcount++;
973       
974                                                                        tpnode = createtransponder(99, scaninfo.fenode->feinfo->type, scaninfo.orbitalpos, frequency, INVERSION_AUTO, bandwidth, lp, hp, modulation, guardinterval, transmission, hierarchy);
975       
976                                                                        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);
977       
978                                                                        if(tpnode != NULL)
979                                                                        {
980       
981                                                                                fenode = fegetfree(tpnode, 0, scaninfo.fenode);
982                                                                                if(fenode == NULL )
983                                                                                {
984                                                                                        debug(500, "Frontend for scan not free");
985                                                                                        deltransponderbyid(99);
986                                                                                        continue;
987                                                                                }
988       
989                                                                                //frontend tune
990                                                                                if(fenode->feinfo->type == FE_OFDM)
991                                                                                {
992                                                                                        feset(fenode, tpnode);
993                                                                                        fetunedvbs(fenode, tpnode);
994                                                                                }
995                                                                                else
996                                                                                {
997                                                                                        debug(500, "Frontend type unknown");
998                                                                                        deltransponderbyid(99);
999                                                                                        continue;
1000                                                                                }
1001               
1002                                                                                festatus = fewait(fenode);
1003                                                                                if(debug_level == 200) fereadstatus(fenode);
1004                                                                                if(festatus != 0)
1005                                                                                {
1006                                                                                        debug(500, "tuning failed");
1007                                                                                        deltransponderbyid(99);
1008                                                                                        continue;
1009                                                                                }
1010               
1011                                                                                buf = dvbgetsdt(fenode, 0, timeout);
1012                                                                                transponderid = findtransponderid(fenode, buf);
1013                                                                                free(buf); buf = NULL;
1014               
1015                                                                                if(transponderid == 0 || gettransponder(transponderid) != NULL)
1016                                                                                {
1017                                                                                        deltransponderbyid(99);
1018                                                                                        continue;
1019                                                                                }
1020       
1021                                                                                if(tpnode->id != transponderid)
1022                                                                                {
1023                                                                                        scaninfo.newblindcount++;
1024                                                                                        changetransponderid(tpnode, transponderid);
1025                                                                                        status.writetransponder = 1;
1026                                                                                }
1027                                                                        }
1028                                                                        deltransponderbyid(99);
1029                                                                        if(timernode->aktion != START) break;
1030                                                                }
1031                                                                if(timernode->aktion != START) break;
1032                                                        }
1033                                                        if(timernode->aktion != START) break;
1034                                                }
1035                                                if(timernode->aktion != START) break;
1036                                        }
1037                                        if(timernode->aktion != START) break;
1038                                }
1039                                if(timernode->aktion != START) break;
1040                        }
1041                        if(timernode->aktion != START) break;
1042                }
1043                if(timernode->aktion != START) break;
1044        }
1045       
1046        return 0;
1047}
1048
1049void blindscan(struct stimerthread* timernode)
1050{
1051        if(scaninfo.fenode == NULL) return;
1052       
1053        if(scaninfo.fenode->feinfo->type == FE_QPSK)
1054                satblindscan(timernode, 0);
1055        else if(scaninfo.fenode->feinfo->type == FE_QAM)
1056                cableblindscan(timernode, 0);
1057        else if(scaninfo.fenode->feinfo->type == FE_OFDM)
1058                terrblindscan(timernode, 0);
1059}
1060
1061void doscan(struct stimerthread* timernode)
1062{
1063        int festatus = 0, secnr = 0;
1064        uint8_t lastsecnr = 0xff;
1065        unsigned char* buf = NULL;
1066        struct transponder* tpnode = NULL;
1067        struct dvbdev* fenode = NULL;
1068        //struct channel* chnode = NULL;
1069        struct sat* satnode = sat;
1070        int nitscan = 1;
1071
1072        if(scaninfo.fenode == NULL || scaninfo.tpnode == NULL || timernode == NULL)
1073        {
1074                scaninfo.threadend = 1;
1075                return;
1076        }
1077
1078        debug(500, "channel scan thread start");
1079
1080        //sat loop
1081        satnode = sat;
1082        while(satnode != NULL && timernode->aktion == START)
1083        {
1084                if(satnode->scan == 0)
1085                {
1086                        satnode = satnode->next;
1087                        continue;
1088                }
1089                scaninfo.satname = satnode->name;
1090
1091                if(scaninfo.scantype == 0)
1092                        tpnode = scaninfo.tpnode;
1093                else if(scaninfo.scantype == 1)
1094                        tpnode = transponder;
1095                else if(scaninfo.scantype == 2 || scaninfo.scantype == 3)
1096                {
1097                        tpnode = transponder;
1098                        scaninfo.orbitalpos = satnode->orbitalpos;
1099                }
1100
1101                if(scaninfo.blindscan == 1) blindscan(timernode);
1102               
1103                nitscan = 1;
1104                //transponder loop
1105                while(tpnode != NULL && timernode->aktion == START)
1106                {
1107                        if(scaninfo.orbitalpos != tpnode->orbitalpos)
1108                        {
1109                                tpnode = tpnode->next;
1110                                if(scaninfo.scantype == 0) break;
1111                                continue;
1112                        }
1113       
1114                        fenode = fegetfree(tpnode, 0, scaninfo.fenode);
1115                        if(fenode == NULL || (scaninfo.scantype != 3 && fenode != scaninfo.fenode))
1116                        {
1117                                scaninfo.tpcount++;
1118                                tpnode = tpnode->next;
1119                                debug(500, "Frontend for scan not free");
1120                                if(scaninfo.scantype == 0) break;
1121                                continue;
1122                        }
1123
1124                        //frontend tune
1125                        if(fenode->feinfo->type == FE_QPSK)
1126                        {
1127                                feset(fenode, tpnode);
1128                                fetunedvbs(fenode, tpnode);
1129                        }
1130                        else if(fenode->feinfo->type == FE_QAM)
1131                                fetunedvbc(fenode, tpnode);
1132                        else if(fenode->feinfo->type == FE_OFDM)
1133                                fetunedvbt(fenode, tpnode);
1134                        else
1135                        {
1136                                scaninfo.tpcount++;
1137                                tpnode = tpnode->next;
1138                                debug(500, "Frontend type unknown");
1139                                if(scaninfo.scantype == 0) break;
1140                                continue;
1141                        }
1142
1143                        festatus = fewait(fenode);
1144                        if(debug_level == 200) fereadstatus(fenode);
1145                        if(festatus != 0)
1146                        {
1147                                scaninfo.tpcount++;
1148                                tpnode = tpnode->next;
1149                                debug(500, "tuning failed");
1150                                if(scaninfo.scantype == 0) break;
1151                                continue;
1152                        }
1153
1154                        //del channels from transponder if selected
1155                        //if(scaninfo.scantype != 3 && scaninfo.clear == 1)
1156                        //{
1157                        //      struct channel* tmpchannel = NULL;
1158                        //      chnode = channel;
1159                        //      while(chnode != NULL)
1160                        //      {
1161                        //              tmpchannel = chnode->next;
1162                        //              if(chnode->transponder == tpnode)
1163                        //                      delchannel(chnode->serviceid, chnode->transponderid, 1);
1164                        //              chnode = tmpchannel;
1165                        //      }
1166                        //}
1167
1168                        //get nit
1169                        if(scaninfo.networkscan == 1 && nitscan == 1)
1170                        {
1171                                lastsecnr = 0xff;
1172                                secnr = 0;
1173                                while(secnr <= lastsecnr && secnr <= 256)
1174                                {
1175                                        if(timernode->aktion != START) break;
1176                                        buf = dvbgetnit(fenode, secnr, scaninfo.timeout * 2);
1177                                        if(buf != NULL)
1178                                        {
1179                                                parsenit(buf, &lastsecnr, satnode->orbitalpos);
1180                                                nitscan = 1; //1 = scan all transponder for nit / 0 = scan only first transponder for nit
1181                                        }
1182                                        else
1183                                                break;
1184                                        free(buf); buf = NULL;
1185                                        secnr++;
1186                                }
1187                        }
1188
1189                        lastsecnr = 0xff;
1190                        secnr = 0;
1191                        while(secnr <= lastsecnr && secnr <= 256)
1192                        {
1193                                if(timernode->aktion != START) break;
1194#ifndef SIMULATE
1195                                buf = dvbgetsdt(fenode, secnr, scaninfo.timeout);
1196#endif
1197                                if(buf != NULL)
1198                                        findchannel(fenode, tpnode, buf, &lastsecnr, scaninfo.scanscreen, scaninfo.listbox, scaninfo.changename, 0);
1199                                else
1200                                        break;
1201                                free(buf); buf = NULL;
1202                                secnr++;
1203                        }
1204       
1205                        scaninfo.tpcount++;
1206                        if(scaninfo.scantype == 0) break;
1207                        tpnode = tpnode->next;
1208                }
1209                if(scaninfo.scantype == 0 || scaninfo.scantype == 1) break;
1210                satnode = satnode->next;
1211        }
1212        scaninfo.threadend = 1;
1213        debug(500, "channel scan thread end");
1214}
1215
1216void scanaddchannel(struct skin* node, int scantype, struct transponder* tp1, int ichangename)
1217{
1218        int serviceid = 0;
1219        uint64_t transponderid = 0;
1220        int servicetype = 0;
1221        int providerid = 0;
1222        struct provider* providernode = NULL;
1223        char* tmpstr = NULL;
1224        struct transponder* tp2 = NULL;
1225        struct channel* chnode = NULL;
1226
1227        if(node == NULL || node->name == NULL) return;
1228
1229        serviceid = ((uint64_t*)node->name)[0];
1230        transponderid = ((uint64_t*)node->name)[1];
1231        servicetype = ((uint64_t*)node->name)[2];
1232
1233        chnode = getchannel(serviceid, transponderid);
1234        if(chnode == NULL || (chnode != NULL && chnode->transponder == NULL))
1235        {
1236                //check if provider valid
1237                providernode = getproviderbyname(node->param1);
1238                if(providernode != NULL)
1239                        providerid = providernode->providerid;
1240                else
1241                {
1242                        providerid = getlastproviderid() + 1;
1243                        tmpstr = ostrcat(tmpstr, oitoa(providerid), 1, 1);
1244                        tmpstr = ostrcat(tmpstr, "#", 1, 0);
1245                        tmpstr = ostrcat(tmpstr, node->param1, 1, 0);
1246                        tmpstr = ostrcat(tmpstr, "#0", 1, 0);
1247                        addprovider(tmpstr, 1, NULL);
1248                        free(tmpstr); tmpstr = NULL;
1249                }
1250
1251                //check if transponder valid
1252                if(scantype == 0)
1253                {
1254                        tp2 = gettransponder(transponderid);
1255
1256                        if(tp2 == NULL && tp1 != NULL)
1257                        {
1258                                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);
1259                                if(tp2 != NULL)
1260                                        changetransponderid(tp2, transponderid);
1261                        }
1262
1263                        if(tp2 == NULL) //create new transponder
1264                                copytransponder(tp1, tp2, transponderid);
1265                        else //change transponder
1266                                copytransponder(tp1, tp2, 99);
1267                }
1268
1269                if(servicetype != 0 && servicetype != 1)
1270                        servicetype = 0;
1271
1272                if(chnode == NULL)
1273                {
1274                        if(createchannel(node->param2, transponderid, providerid, serviceid, servicetype, 0, -1, -1, -1, -1, 0) != NULL)
1275                                node->fontcol = convertcol("deaktivcol");
1276                }
1277                else
1278                        node->fontcol = convertcol("deaktivcol");
1279        }
1280        else
1281        {
1282                node->fontcol = convertcol("deaktivcol");
1283                //change channel name if selected
1284                if(ichangename == 1 && node->param2 != NULL && strlen(node->param2) > 0 && ostrcmp(node->param2, chnode->name) != 0)
1285                {
1286                        free(chnode->name);
1287                        chnode->name = ostrcat(node->param2, NULL, 0, 0);
1288                        status.writetransponder = 1;
1289                }
1290        }
1291}
1292
1293void scansetallsat(int fetype)
1294{
1295        int i = 0, orbitalpos = 0;
1296        struct sat* satnode = NULL;
1297        struct dvbdev* dvbnode = dvbdev;
1298        char* tmpstr = NULL, *tmpnr = NULL;
1299
1300        while(dvbnode != NULL)
1301        {
1302                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL && dvbnode->felock < 1 && (fetype == -1 || dvbnode->feinfo->type == fetype))
1303                {
1304
1305                        tmpstr = ostrcat(dvbnode->feshortname, "_sat", 0, 0);
1306                        for(i = 1; i <= getmaxsat(dvbnode->feshortname); i++)
1307                        {
1308                                tmpnr = oitoa(i);
1309                                orbitalpos = getconfigint(tmpstr, tmpnr);
1310                                free(tmpnr); tmpnr = NULL;
1311
1312                                satnode = getsatbyorbitalpos(orbitalpos);
1313                                if(satnode != NULL && (fetype == -1 || satnode->fetype == fetype))
1314                                        satnode->scan = 1;
1315                        }
1316                        free(tmpstr); tmpstr = NULL;
1317                }
1318                dvbnode = dvbnode->next;
1319        }
1320}
1321
1322void scansetmultisat(struct skin* scan)
1323{
1324        struct skin* node = scan;
1325        struct sat* satnode = NULL;
1326
1327        while(node != NULL && node->name != NULL)
1328        {
1329                if(ostrcmp(node->ret, "1") == 0)
1330                {
1331                        satnode = getsatbyorbitalpos(atoi(node->name));
1332                        if(satnode != NULL)
1333                                satnode->scan = 1;
1334                }
1335                node = node->next;
1336        }
1337}
1338
1339void delchannelbysat(int orbitalpos)
1340{
1341        struct transponder* transpondernode = transponder;
1342        struct channel* chnode = NULL;
1343
1344        while(transpondernode != NULL)
1345        {
1346                if(transpondernode->orbitalpos == orbitalpos)
1347                {
1348                        struct channel* tmpchannel = NULL;
1349                        chnode = channel;
1350                        while(chnode != NULL)
1351                        {
1352                                tmpchannel = chnode->next;
1353                                if(chnode->transponder == transpondernode)
1354                                        delchannel(chnode->serviceid, chnode->transponderid, 1);
1355                                chnode = tmpchannel;
1356                        }
1357                }
1358                transpondernode = transpondernode->next;
1359        }
1360}
1361
1362void delchannelbymultisat()
1363{
1364        struct sat* satnode = sat;
1365
1366        while(satnode != NULL)
1367        {
1368                if(satnode->scan == 1)
1369                        delchannelbysat(satnode->orbitalpos);
1370                satnode = satnode->next;
1371        }
1372}
1373
1374void 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 timeout)
1375{
1376        int rcret = 0, tpmax = 0, i = 0, alladded = 0;
1377        struct skin* scan = getscreen("scan");
1378        struct skin* progress = getscreennode(scan, "progress");
1379        struct skin* listbox = getscreennode(scan, "listbox");
1380        struct skin* satname = getscreennode(scan, "satname");
1381        struct skin* tpcount = getscreennode(scan, "tpcount");
1382        struct skin* foundtv = getscreennode(scan, "foundtv");
1383        struct skin* foundradio = getscreennode(scan, "foundradio");
1384        struct skin* founddata = getscreennode(scan, "founddata");
1385        struct skin* foundblind = getscreennode(scan, "foundblind");
1386        struct skin* b2 = getscreennode(scan, "b2");
1387        struct skin* b3 = getscreennode(scan, "b3");
1388        struct skin* load = getscreen("loading");
1389        struct transponder* tpnode = NULL;
1390        struct dvbdev* fenode = NULL, *dvbnode = dvbdev;
1391        struct stimerthread* timernode = NULL;
1392        struct sat* satnode = NULL;
1393        struct channel* chnode = NULL;
1394        char* tmpstr = NULL;
1395
1396        listbox->aktline = 1;
1397        listbox->aktpage = -1;
1398        progress->progresssize = 0;
1399        memset(&scaninfo, 0, sizeof(struct scaninfo));
1400
1401        b2->hidden = NO;
1402        b3->hidden = NO;
1403
1404        addscreenrc(scan, listbox);
1405        if(scantype != 3)
1406        {
1407                while(dvbnode != NULL)
1408                {
1409                        if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL && dvbnode->felock < 1)
1410                        {
1411                                if(ostrcmp(dvbnode->feshortname, tuner) == 0)
1412                                {
1413                                        fenode = dvbnode;
1414                                        break;
1415                                }
1416                        }
1417                        dvbnode = dvbnode->next;
1418                }
1419                if(fenode == NULL) return;
1420        }
1421        else if(scantype == 3)
1422                fenode = dvbdev;
1423
1424        if(scantype == 0) //single transponder
1425        {
1426                if(fenode != NULL && fenode->feinfo != NULL)
1427                {
1428                        //del channels from transponder if selected
1429                        if(clear == 1)
1430                        {
1431                                struct channel* tmpchannel = NULL;
1432                                chnode = channel;
1433                                while(chnode != NULL)
1434                                {
1435                                        tmpchannel = chnode->next;
1436                                        if(chnode->transponder == transpondernode)
1437                                                delchannel(chnode->serviceid, chnode->transponderid, 1);
1438                                        chnode = tmpchannel;
1439                                }
1440                        }
1441
1442                        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);
1443                        tpnode = createtransponder(99, fenode->feinfo->type, orbitalpos, frequency, inversion, symbolrate, polarization, fec, modulation, rolloff, pilot, system);
1444                }
1445                if(tpnode != NULL)
1446                {
1447                        tpmax = 1;
1448                        satnode = getsatbyorbitalpos(tpnode->orbitalpos);
1449                        if(satnode != NULL) satnode->scan = 1;
1450                }
1451        }
1452        else if(scantype == 1) //single sat
1453        {
1454                if(clear == 1) delchannelbysat(orbitalpos);
1455                tpnode = transponder;
1456                while(tpnode != NULL)
1457                {
1458                        if(tpnode->orbitalpos == orbitalpos)
1459                                tpmax++;
1460                        tpnode = tpnode->next;
1461                }
1462                tpnode = transponder;
1463                satnode = getsatbyorbitalpos(orbitalpos);
1464                if(satnode != NULL) satnode->scan = 1;
1465        }
1466        else if(scantype == 2 || scantype == 3) //2: multi sat, 3: all
1467        {
1468                if(scantype == 2)
1469                {
1470                        scansetmultisat(mscan);
1471                        if(clear == 1) delchannelbymultisat();
1472                }
1473                if(scantype == 3)
1474                {
1475                        scansetallsat(-1);
1476                        b2->hidden = YES;
1477                        b3->hidden = YES;
1478                        //del all channel for auto. search
1479                        if(clear == 1) freechannel(1);
1480                }
1481                satnode = sat;
1482                while(satnode != NULL)
1483                {
1484                        if(satnode->scan != 0)
1485                        {
1486                                tpnode = transponder;
1487                                while(tpnode != NULL)
1488                                {
1489                                        if(tpnode->orbitalpos == satnode->orbitalpos)
1490                                                tpmax++;
1491                                        tpnode = tpnode->next;
1492                                }
1493                        }
1494                        satnode = satnode->next;
1495                }
1496                tpnode = transponder;
1497        }
1498
1499        scaninfo.fenode = fenode;
1500        scaninfo.tpnode = tpnode;
1501        scaninfo.scanscreen = scan;
1502        scaninfo.listbox = listbox;
1503        scaninfo.timeout = timeout;
1504        scaninfo.scantype = scantype;
1505        scaninfo.orbitalpos = orbitalpos;
1506        scaninfo.onlyfree = onlyfree;
1507        scaninfo.networkscan = networkscan;
1508        scaninfo.blindscan = blindscan;
1509        scaninfo.changename = ichangename;
1510        scaninfo.clear = clear;
1511        scaninfo.tpmax = tpmax;
1512        timernode = addtimer(&doscan, START, 1000, 1, NULL, NULL, NULL);
1513
1514        while(1)
1515        {
1516                //satname
1517                tmpstr = ostrcat(tmpstr, _("Sat/Provider: "), 1, 0);
1518                tmpstr = ostrcat(tmpstr, scaninfo.satname, 1, 0);
1519                changetext(satname, tmpstr);
1520                free(tmpstr); tmpstr = NULL;
1521
1522                //transpondercount
1523                tmpstr = ostrcat(tmpstr, _("Transponder: "), 1, 0);
1524                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpcount), 1, 1);
1525                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1526                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpmax), 1, 1);
1527                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1528                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tpnew), 1, 1);
1529                changetext(tpcount, tmpstr);
1530                free(tmpstr); tmpstr = NULL;
1531
1532                //tvcount
1533                tmpstr = ostrcat(tmpstr, _("TV: "), 1, 0);
1534                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newtvcount), 1, 1);
1535                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1536                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.tvcount), 1, 1);
1537                changetext(foundtv, tmpstr);
1538                free(tmpstr); tmpstr = NULL;
1539
1540                //radiocount
1541                tmpstr = ostrcat(tmpstr, _("Radio: "), 1, 0);
1542                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newradiocount), 1, 1);
1543                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1544                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.radiocount), 1, 1);
1545                changetext(foundradio, tmpstr);
1546                free(tmpstr); tmpstr = NULL;
1547
1548                //datacount
1549                tmpstr = ostrcat(tmpstr, _("Data: "), 1, 0);
1550                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newdatacount), 1, 1);
1551                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1552                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.datacount), 1, 1);
1553                changetext(founddata, tmpstr);
1554                free(tmpstr); tmpstr = NULL;
1555
1556                //blindcount
1557                tmpstr = ostrcat(tmpstr, _("Blindscan: "), 1, 0);
1558                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.newblindcount), 1, 1);
1559                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1560                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.blindcount), 1, 1);
1561                tmpstr = ostrcat(tmpstr, " / ", 1, 0);
1562                tmpstr = ostrcat(tmpstr, oitoa(scaninfo.blindmax), 1, 1);
1563                changetext(foundblind, tmpstr);
1564                free(tmpstr); tmpstr = NULL;
1565
1566                if(scaninfo.tpmax == 0)
1567                        progress->progresssize = 100;
1568                else
1569                        progress->progresssize = (100 / (float)scaninfo.tpmax) * scaninfo.tpcount;
1570
1571                drawscreen(scan, 0, 0);
1572                rcret = waitrc(scan, 1000, 0);
1573
1574                if(scantype != 3 && rcret == getrcconfigint("rcred", NULL))
1575                        scanaddchannel(listbox->select, scantype, tpnode, ichangename);
1576
1577                if((scantype != 3 && rcret == getrcconfigint("rcgreen", NULL)) || (scantype == 3 && scaninfo.threadend == 1 && alladded < 2))
1578                {
1579                        struct skin* lnode = listbox;
1580
1581                        long deaktivcol = convertcol("deaktivcol");
1582                        if(scantype == 3 && alladded == 0)
1583                        {
1584                                alladded = 1;
1585                                continue;
1586                        }
1587                        alladded = 2;
1588
1589                        drawscreen(load, 0, 0);
1590                        while(lnode != NULL)
1591                        {
1592                                if(lnode->fontcol != deaktivcol && lnode->del == 1)
1593                                        scanaddchannel(lnode, scantype, tpnode, ichangename);
1594                                lnode = lnode->next;
1595                        }
1596                        clearscreen(load);
1597                        textbox(_("Message"), _("All new channel added!"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
1598                }
1599
1600                if(rcret == getrcconfigint("rcexit", NULL))
1601                {
1602                        if(timernode != NULL && scaninfo.threadend == 0)
1603                        {
1604                                timernode->aktion = STOP;
1605                                while(i < 4 && scaninfo.threadend == 0)
1606                                {
1607                                        textbox(_("Message"), _("Wait for channel scan end"), NULL, 0, NULL, 0, NULL, 0, NULL, 0, 600, 200, 3, 0);
1608                                        i++;
1609                                }
1610                        }
1611                        break;
1612                }
1613        }
1614
1615        if(scantype == 0) deltransponderbyid(99);
1616        if(clear == 1)
1617        {
1618                if(textbox(_("Message"), _("Does you want delete all unused Bouquetentrys?"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0) == 1)
1619                        delunusedbouquetchannels(0);
1620                else
1621                        delunusedbouquetchannels(1);
1622        }
1623        delmarkedscreennodes(scan, 1);
1624        delownerrc(scan);
1625        clearscreen(scan);
1626        resetsatscan();
1627        drawscreen(load, 0, 0);
1628  sortchannel();
1629  clearscreen(load);
1630}
1631
1632void 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)
1633{
1634        struct sat* satnode = sat;
1635        struct skin* tmp = NULL;
1636        char* tmpstr = NULL, *tmpstr1 = NULL, *tmpnr = NULL;
1637        char* feshortname = NULL;
1638        int i, orbitalpos = 0;
1639
1640        if(tuner != NULL) feshortname = tuner->ret;
1641
1642        tuner->hidden = NO;
1643        id->hidden = NO;
1644        system->hidden = NO;
1645        frequency->hidden = NO;
1646        inversion->hidden = NO;
1647        symbolrate->hidden = NO;
1648        polarization->hidden = NO;
1649        fec->hidden = NO;
1650        modulation->hidden = NO;
1651        rolloff->hidden = NO;
1652        pilot->hidden = NO;
1653        hp->hidden = NO;
1654        lp->hidden = NO;
1655        bandwidth->hidden = NO;
1656        transmission->hidden = NO;
1657        guardinterval->hidden = NO;
1658        hierarchy->hidden = NO;
1659        satellite->hidden = NO;
1660        b4->hidden = NO;
1661        b5->hidden = NO;
1662        delmarkedscreennodes(scan, 1);
1663
1664        if(flag == 0 && ostrcmp(scantype, "0") == 0 && ostrcmp(system->ret, "0") == 0)
1665        {
1666                modulation->hidden = YES;
1667                rolloff->hidden = YES;
1668                pilot->hidden = YES;
1669        }
1670
1671        if(ostrcmp(scantype, "1") == 0 || ostrcmp(scantype, "2") == 0 || ostrcmp(scantype, "3") == 0)
1672        {
1673                id->hidden = YES;
1674                system->hidden = YES;
1675                frequency->hidden = YES;
1676                inversion->hidden = YES;
1677                symbolrate->hidden = YES;
1678                polarization->hidden = YES;
1679                fec->hidden = YES;
1680                modulation->hidden = YES;
1681                rolloff->hidden = YES;
1682                pilot->hidden = YES;
1683                hp->hidden = YES;
1684                lp->hidden = YES;
1685                bandwidth->hidden = YES;
1686                transmission->hidden = YES;
1687                guardinterval->hidden = YES;
1688                hierarchy->hidden = YES;
1689                b4->hidden = YES;
1690                b5->hidden = YES;
1691        }
1692        if(ostrcmp(scantype, "2") == 0 && feshortname != NULL)
1693        {
1694                satellite->hidden = YES;
1695
1696                tmpstr = ostrcat(feshortname, "_sat", 0, 0);
1697                for(i = 1; i <= getmaxsat(feshortname); i++)
1698                {
1699                        tmpnr = oitoa(i);
1700                        orbitalpos = getconfigint(tmpstr, tmpnr);
1701                        free(tmpnr); tmpnr = NULL;
1702
1703                        satnode = getsatbyorbitalpos(orbitalpos);
1704                        if(satnode != NULL && satnode->fetype == FE_QPSK)
1705                        {
1706                                tmp = addlistbox(scan, listbox, tmp, 1);
1707                                if(tmp != NULL)
1708                                {
1709                                        tmpstr1 = oitoa(satnode->orbitalpos);
1710                                        changename(tmp, tmpstr1);
1711                                        free(tmpstr1); tmpstr1 = NULL;
1712                                        changetext(tmp, satnode->name);
1713                                        tmp->type = CHOICEBOX;
1714                                        addchoicebox(tmp, "0", _("no"));
1715                                        addchoicebox(tmp, "1", _("yes"));
1716                                }
1717                        }
1718                }
1719                free(tmpstr); tmpstr = NULL;
1720        }
1721        if(ostrcmp(scantype, "3") == 0)
1722        {
1723                tuner->hidden = YES;
1724                satellite->hidden = YES;
1725        }
1726
1727        if(flag == 2)
1728        {
1729                system->hidden = YES;
1730                inversion->hidden = YES;
1731                polarization->hidden = YES;
1732                rolloff->hidden = YES;
1733                pilot->hidden = YES;
1734                satellite->hidden = YES;
1735        }
1736
1737        if(flag == 3)
1738        {
1739                system->hidden = YES;
1740                polarization->hidden = YES;
1741                rolloff->hidden = YES;
1742                pilot->hidden = YES;
1743                satellite->hidden = YES;
1744                symbolrate->hidden = YES;
1745                fec->hidden = YES;
1746        }
1747        else
1748        {
1749                hp->hidden = YES;
1750                lp->hidden = YES;
1751                bandwidth->hidden = YES;
1752                transmission->hidden = YES;
1753                guardinterval->hidden = YES;
1754                hierarchy->hidden = YES;
1755        }
1756}
1757
1758void scanchangesat(struct skin* sat, struct transponder* tpnode, char* feshortname)
1759{
1760        char* tmpstr = NULL;
1761
1762        changeinput(sat, NULL);
1763        changechoiceboxvalue(sat, NULL);
1764        tmpstr = getsatstring(feshortname, FE_QPSK);
1765        changeinput(sat, tmpstr);
1766        free(tmpstr); tmpstr = NULL;
1767        tmpstr = getorbitalposstring(feshortname, FE_QPSK);
1768        changechoiceboxvalue(sat, tmpstr);
1769        free(tmpstr); tmpstr = NULL;
1770        if(tpnode != NULL)
1771        {
1772                tmpstr = oitoa(tpnode->orbitalpos);
1773                setchoiceboxselection(sat, tmpstr);
1774                free(tmpstr); tmpstr = NULL;
1775        }
1776}
1777
1778//flag 0: manual scan (DVB-S)
1779//flag 1: auto scan (all)
1780//flag 2: manual scan (DVB-C)
1781//flag 3: manual scan (DVB-T)
1782void screenscanconfig(int flag)
1783{
1784        int rcret = 0, fetype = -1;
1785        unsigned int ifrequency = -1, isymbolrate = -1;
1786        int iscantype = -1, isat = -1;
1787        int iinversion = -1, ipolarization = -1;
1788        int ifec = -1, imodulation = -1, irolloff = -1, ipilot = -1, isystem = -1;
1789        int inetworkscan = -1, ionlyfree = -1, iclear = -1, iblindscan = -1, ichangename = -1;
1790        int i = 0, treffer = 0, tunercount = 0;
1791        struct skin* scan = getscreen("manualscan");
1792        struct skin* listbox = getscreennode(scan, "listbox");
1793        struct skin* tuner = getscreennode(scan, "tuner");
1794        struct skin* scantype = getscreennode(scan, "scantype");
1795        struct skin* sat = getscreennode(scan, "sat");
1796        struct skin* id = getscreennode(scan, "id");
1797        struct skin* system = getscreennode(scan, "system");
1798        struct skin* frequency = getscreennode(scan, "frequency");
1799        struct skin* inversion = getscreennode(scan, "inversion");
1800        struct skin* symbolrate = getscreennode(scan, "symbolrate");
1801        struct skin* polarization = getscreennode(scan, "polarization");
1802        struct skin* fec = getscreennode(scan, "fec");
1803        struct skin* modulation = getscreennode(scan, "modulation");
1804        struct skin* rolloff = getscreennode(scan, "rolloff");
1805        struct skin* pilot = getscreennode(scan, "pilot");
1806        struct skin* hp = getscreennode(scan, "hp");
1807        struct skin* lp = getscreennode(scan, "lp");
1808        struct skin* bandwidth = getscreennode(scan, "bandwidth");
1809        struct skin* transmission = getscreennode(scan, "transmission");
1810        struct skin* guardinterval = getscreennode(scan, "guardinterval");
1811        struct skin* hierarchy = getscreennode(scan, "hierarchy");
1812        struct skin* networkscan = getscreennode(scan, "networkscan");
1813        struct skin* clear = getscreennode(scan, "clear");
1814        struct skin* onlyfree = getscreennode(scan, "onlyfree");
1815        struct skin* blindscan = getscreennode(scan, "blindscan");
1816        struct skin* changename = getscreennode(scan, "changename");
1817        struct skin* b4 = getscreennode(scan, "b4");
1818        struct skin* b5 = getscreennode(scan, "b5");
1819        struct skin* tmp = NULL;
1820        char* tmpstr = NULL, *tmpnr = NULL, *feshortname = NULL;
1821        struct transponder* tpnode = NULL;
1822        struct dvbdev* dvbnode = dvbdev;
1823       
1824        listbox->aktline = 1;
1825        listbox->aktpage = -1;
1826
1827        if(status.recording > 0 || status.streaming > 0)
1828        {
1829                textbox(_("Message"), _("Scan is not allowed if record\nor stream is running !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
1830                return;
1831        }
1832
1833        //del old values
1834        changeinput(tuner, NULL);
1835        changechoiceboxvalue(tuner, NULL);
1836        changeinput(scantype, NULL);
1837        changechoiceboxvalue(scantype, NULL);
1838        changeinput(sat, NULL);
1839        changechoiceboxvalue(sat, NULL);
1840        changeinput(system, NULL);
1841        changechoiceboxvalue(system, NULL);
1842        changeinput(inversion, NULL);
1843        changechoiceboxvalue(inversion, NULL);
1844        changeinput(polarization, NULL);
1845        changechoiceboxvalue(polarization, NULL);
1846        changeinput(fec, NULL);
1847        changechoiceboxvalue(fec, NULL);
1848        changeinput(modulation, NULL);
1849        changechoiceboxvalue(modulation, NULL);
1850        changeinput(rolloff, NULL);
1851        changechoiceboxvalue(rolloff, NULL);
1852        changeinput(pilot, NULL);
1853        changechoiceboxvalue(pilot, NULL);
1854        changeinput(hp, NULL);
1855        changeinput(lp, NULL);
1856        changeinput(bandwidth, NULL);
1857        changeinput(transmission, NULL);
1858        changeinput(guardinterval, NULL);
1859        changeinput(hierarchy, NULL);
1860        changechoiceboxvalue(hp, NULL);
1861        changechoiceboxvalue(lp, NULL);
1862        changechoiceboxvalue(bandwidth, NULL);
1863        changechoiceboxvalue(transmission, NULL);
1864        changechoiceboxvalue(guardinterval, NULL);
1865        changechoiceboxvalue(hierarchy, NULL);
1866
1867        frequency->aktpage = 0;
1868        symbolrate->aktpage = 0;
1869
1870        if(flag == 0) fetype = FE_QPSK;
1871        if(flag == 2) fetype = FE_QAM;
1872        if(flag == 3) fetype = FE_OFDM;
1873
1874        //tuner
1875        while(dvbnode != NULL)
1876        {
1877                if(dvbnode->type == FRONTENDDEV && dvbnode->feinfo != NULL && dvbnode->felock < 1 && (flag == 1 || dvbnode->feinfo->type == fetype))
1878                {
1879                        treffer = 0;
1880                        if(dvbnode->feshortname != NULL)
1881                        {
1882                                tmpstr = ostrcat(dvbnode->feshortname, "_sat", 0, 0);
1883                                for(i = 1; i <= getmaxsat(dvbnode->feshortname); i++)
1884                                {
1885                                        tmpnr = oitoa(i);
1886                                        if(getconfigint(tmpstr, tmpnr) != 0)
1887                                        {
1888                                                treffer = 1;
1889                                                break;
1890                                        }
1891                                        free(tmpnr); tmpnr = NULL;
1892                                }
1893                                free(tmpnr); tmpnr = NULL;
1894                                free(tmpstr); tmpstr = NULL;
1895                        }
1896
1897                        if(treffer == 0)
1898                        {
1899                                dvbnode = dvbnode->next;
1900                                continue;
1901                        }
1902
1903                        tunercount++;
1904                        if(feshortname == NULL) feshortname = dvbnode->feshortname;
1905
1906                        tmpstr = ostrcat(tmpstr, dvbnode->feinfo->name, 1, 0);
1907                        tmpstr = ostrcat(tmpstr, " (", 1, 0);
1908                        tmpstr = ostrcat(tmpstr, oitoa(dvbnode->adapter), 1, 1);
1909                        tmpstr = ostrcat(tmpstr, "/", 1, 0);
1910                        tmpstr = ostrcat(tmpstr, oitoa(dvbnode->devnr), 1, 1);
1911                        tmpstr = ostrcat(tmpstr, ")", 1, 0);
1912                        addchoicebox(tuner, dvbnode->feshortname, tmpstr);
1913                        free(tmpstr); tmpstr = NULL;
1914                }
1915                dvbnode = dvbnode->next;
1916        }
1917
1918        if(tunercount < 1)
1919        {
1920                textbox(_("Message"), _("No Tuner configured"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 0, 0);
1921                return;
1922        }
1923
1924        rcret = servicestop(status.aktservice, 1, 1);
1925        if(rcret == 1) return;
1926
1927        if(status.aktservice->channel != NULL)
1928                tpnode = status.aktservice->channel->transponder;
1929
1930start:
1931
1932        if(flag == 0)
1933        {
1934                addchoicebox(scantype, "0", _("Single Transponder"));
1935                addchoicebox(scantype, "1", _("Single Sat"));
1936                addchoicebox(scantype, "2", _("Multi Sat"));
1937                setchoiceboxselection(scantype, "0");
1938        }
1939        else if(flag == 2 || flag == 3)
1940        {
1941                addchoicebox(scantype, "0", _("Single Transponder"));
1942                addchoicebox(scantype, "1", _("Single Provider"));
1943                setchoiceboxselection(scantype, "0");
1944        }
1945        else
1946        {
1947                addchoicebox(scantype, "3", _("Auto Scan"));
1948                setchoiceboxselection(scantype, "3");
1949        }
1950
1951        //sat
1952        scanchangesat(sat, tpnode, feshortname);
1953
1954        //id
1955        if(tpnode != NULL)
1956                tmpstr = ollutoa(tpnode->id);
1957        changeinput(id, tmpstr);
1958        free(tmpstr); tmpstr = NULL;
1959
1960        //system
1961        tmpstr = transpondergetsystemstr(tpnode, 1);
1962        changeinput(system, tmpstr);
1963        free(tmpstr); tmpstr = NULL;
1964        tmpstr = transpondergetsystemstr(tpnode, 2);
1965        changechoiceboxvalue(system, tmpstr);
1966        free(tmpstr); tmpstr = NULL;
1967        if(tpnode != NULL)
1968        {
1969                tmpstr = oitoa(tpnode->system);
1970                setchoiceboxselection(system, tmpstr);
1971                free(tmpstr); tmpstr = NULL;
1972        }
1973
1974        //frequency
1975        if(tpnode != NULL)
1976                tmpstr = oitoa(tpnode->frequency / 1000);
1977        else
1978        {
1979                if(flag == 3)
1980                        tmpstr = ostrcat(tmpstr, "000000", 1, 0);
1981                else
1982                        tmpstr = ostrcat(tmpstr, "00000", 1, 0);
1983        }
1984        if(flag == 2 || flag == 3)
1985        {
1986                changemask(frequency, "000000");
1987                changeinput(frequency, tmpstr);
1988                frequency->input = mask(frequency->input, 6, "0");
1989        }
1990        else
1991        {
1992                changemask(frequency, "00000");
1993                changeinput(frequency, tmpstr);
1994                frequency->input = mask(frequency->input, 5, "0");
1995        }
1996        free(tmpstr); tmpstr = NULL;
1997
1998        //inversion
1999        tmpstr = transpondergetinversionstr(tpnode, 1);
2000        changeinput(inversion, tmpstr);
2001        free(tmpstr); tmpstr = NULL;
2002        tmpstr = transpondergetinversionstr(tpnode, 2);
2003        changechoiceboxvalue(inversion, tmpstr);
2004        free(tmpstr); tmpstr = NULL;
2005        if(tpnode != NULL)
2006        {
2007                tmpstr = oitoa(tpnode->inversion);
2008                setchoiceboxselection(inversion, tmpstr);
2009                free(tmpstr); tmpstr = NULL;
2010        }
2011
2012        //symbolrate
2013        if(tpnode != NULL)
2014                tmpstr = oitoa(tpnode->symbolrate / 1000);
2015        else
2016                tmpstr = ostrcat(tmpstr, "00000", 1, 0);
2017        changemask(symbolrate, "00000");
2018        changeinput(symbolrate, tmpstr);
2019        symbolrate->input = mask(symbolrate->input, 5, "0");
2020        free(tmpstr); tmpstr = NULL;
2021
2022        //polarization
2023        tmpstr = transpondergetpolarizationstr(tpnode, 1);
2024        changeinput(polarization, tmpstr);
2025        free(tmpstr); tmpstr = NULL;
2026        tmpstr = transpondergetpolarizationstr(tpnode, 2);
2027        changechoiceboxvalue(polarization, tmpstr);
2028        free(tmpstr); tmpstr = NULL;
2029        if(tpnode != NULL)
2030        {
2031                tmpstr = oitoa(tpnode->polarization);
2032                setchoiceboxselection(polarization, tmpstr);
2033                free(tmpstr); tmpstr = NULL;
2034        }
2035
2036        //fec
2037        tmpstr = transpondergetfecstr(tpnode, fetype, 1);
2038        changeinput(fec, tmpstr);
2039        free(tmpstr); tmpstr = NULL;
2040        tmpstr = transpondergetfecstr(tpnode, fetype, 2);
2041        changechoiceboxvalue(fec, tmpstr);
2042        free(tmpstr); tmpstr = NULL;
2043        if(tpnode != NULL)
2044        {
2045                tmpstr = oitoa(tpnode->fec);
2046                setchoiceboxselection(fec, tmpstr);
2047                free(tmpstr); tmpstr = NULL;
2048        }
2049
2050        //modulation
2051        tmpstr = transpondergetmodulationstr(tpnode, fetype, 1);
2052        changeinput(modulation, tmpstr);
2053        free(tmpstr); tmpstr = NULL;
2054        tmpstr = transpondergetmodulationstr(tpnode, fetype, 2);
2055        changechoiceboxvalue(modulation, tmpstr);
2056        free(tmpstr); tmpstr = NULL;
2057        if(tpnode != NULL)
2058        {
2059                tmpstr = oitoa(tpnode->modulation);
2060                setchoiceboxselection(modulation, tmpstr);
2061                free(tmpstr); tmpstr = NULL;
2062        }
2063
2064        //rolloff
2065        tmpstr = transpondergetrolloffstr(tpnode, 1);
2066        changeinput(rolloff, tmpstr);
2067        free(tmpstr); tmpstr = NULL;
2068        tmpstr = transpondergetrolloffstr(tpnode, 2);
2069        changechoiceboxvalue(rolloff, tmpstr);
2070        free(tmpstr); tmpstr = NULL;
2071        if(tpnode != NULL)
2072        {
2073                tmpstr = oitoa(tpnode->rolloff);
2074                setchoiceboxselection(rolloff, tmpstr);
2075                free(tmpstr); tmpstr = NULL;
2076        }
2077
2078        //pilot
2079        tmpstr = transpondergetpilotstr(tpnode, 1);
2080        changeinput(pilot, tmpstr);
2081        free(tmpstr); tmpstr = NULL;
2082        tmpstr = transpondergetpilotstr(tpnode, 2);
2083        changechoiceboxvalue(pilot, tmpstr);
2084        free(tmpstr); tmpstr = NULL;
2085        if(tpnode != NULL)
2086        {
2087                tmpstr = oitoa(tpnode->pilot);
2088                setchoiceboxselection(pilot, tmpstr);
2089                free(tmpstr); tmpstr = NULL;
2090        }
2091
2092        //hp
2093        tmpstr = transpondergetfecstr(tpnode, fetype, 1);
2094        changeinput(hp, tmpstr);
2095        free(tmpstr); tmpstr = NULL;
2096        tmpstr = transpondergetfecstr(tpnode, fetype, 2);
2097        changechoiceboxvalue(hp, tmpstr);
2098        free(tmpstr); tmpstr = NULL;
2099        if(tpnode != NULL)
2100        {
2101                tmpstr = oitoa(tpnode->fec);
2102                setchoiceboxselection(hp, tmpstr);
2103                free(tmpstr); tmpstr = NULL;
2104        }
2105
2106        //lp
2107        tmpstr = transpondergetfecstr(tpnode, fetype, 1);
2108        changeinput(lp, tmpstr);
2109        free(tmpstr); tmpstr = NULL;
2110        tmpstr = transpondergetfecstr(tpnode, fetype, 2);
2111        changechoiceboxvalue(lp, tmpstr);
2112        free(tmpstr); tmpstr = NULL;
2113        if(tpnode != NULL)
2114        {
2115                tmpstr = oitoa(tpnode->polarization);
2116                setchoiceboxselection(lp, tmpstr);
2117                free(tmpstr); tmpstr = NULL;
2118        }
2119
2120        //bandwidth
2121        tmpstr = transpondergetbandwidthstr(tpnode, 1);
2122        changeinput(bandwidth, tmpstr);
2123        free(tmpstr); tmpstr = NULL;
2124        tmpstr = transpondergetbandwidthstr(tpnode, 2);
2125        changechoiceboxvalue(bandwidth, tmpstr);
2126        free(tmpstr); tmpstr = NULL;
2127        if(tpnode != NULL)
2128        {
2129                tmpstr = oitoa(tpnode->symbolrate);
2130                setchoiceboxselection(bandwidth, tmpstr);
2131                free(tmpstr); tmpstr = NULL;
2132        }
2133
2134        //guardinterval
2135        tmpstr = transpondergetguardintervalstr(tpnode, 1);
2136        changeinput(guardinterval, tmpstr);
2137        free(tmpstr); tmpstr = NULL;
2138        tmpstr = transpondergetguardintervalstr(tpnode, 2);
2139        changechoiceboxvalue(guardinterval, tmpstr);
2140        free(tmpstr); tmpstr = NULL;
2141        if(tpnode != NULL)
2142        {
2143                tmpstr = oitoa(tpnode->rolloff);
2144                setchoiceboxselection(guardinterval, tmpstr);
2145                free(tmpstr); tmpstr = NULL;
2146        }
2147
2148        //transmission
2149        tmpstr = transpondergettransmissionstr(tpnode, 1);
2150        changeinput(transmission, tmpstr);
2151        free(tmpstr); tmpstr = NULL;
2152        tmpstr = transpondergettransmissionstr(tpnode, 2);
2153        changechoiceboxvalue(transmission, tmpstr);
2154        free(tmpstr); tmpstr = NULL;
2155        if(tpnode != NULL)
2156        {
2157                tmpstr = oitoa(tpnode->pilot);
2158                setchoiceboxselection(transmission, tmpstr);
2159                free(tmpstr); tmpstr = NULL;
2160        }
2161
2162        //hierarchy
2163        tmpstr = transpondergethierarchystr(tpnode, 1);
2164        changeinput(hierarchy, tmpstr);
2165        free(tmpstr); tmpstr = NULL;
2166        tmpstr = transpondergethierarchystr(tpnode, 2);
2167        changechoiceboxvalue(hierarchy, tmpstr);
2168        free(tmpstr); tmpstr = NULL;
2169        if(tpnode != NULL)
2170        {
2171                tmpstr = oitoa(tpnode->system);
2172                setchoiceboxselection(hierarchy, tmpstr);
2173                free(tmpstr); tmpstr = NULL;
2174        }
2175
2176        //networkscan
2177        addchoicebox(networkscan, "0", _("no"));
2178        addchoicebox(networkscan, "1", _("yes"));
2179
2180        //clear
2181        addchoicebox(clear, "0", _("no"));
2182        addchoicebox(clear, "1", _("yes"));
2183
2184        //only free
2185        addchoicebox(onlyfree, "0", _("no"));
2186        addchoicebox(onlyfree, "1", _("yes"));
2187
2188        //blindscan
2189        addchoicebox(blindscan, "0", _("no"));
2190        addchoicebox(blindscan, "1", _("yes"));
2191
2192        //changename
2193        addchoicebox(changename, "0", _("no"));
2194        addchoicebox(changename, "1", _("yes"));
2195
2196        drawscreen(scan, 2, 0);
2197        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);
2198        drawscreen(scan, 0, 0);
2199        addscreenrc(scan, listbox);
2200
2201        tmp = listbox->select;
2202        while(1)
2203        {
2204                addscreenrc(scan, tmp);
2205                rcret = waitrc(scan, 0, 0);
2206                tmp = listbox->select;
2207
2208                if(scantype->ret != NULL) iscantype = atoi(scantype->ret);
2209                if(sat->ret != NULL) isat = atoi(sat->ret);
2210                if(system->ret != NULL) isystem = atoi(system->ret);
2211                if(frequency->ret != NULL) ifrequency = atoi(frequency->ret) * 1000;
2212                if(inversion->ret != NULL) iinversion = atoi(inversion->ret);
2213                if(symbolrate->ret != NULL) isymbolrate = atoi(symbolrate->ret) * 1000;
2214                if(polarization->ret != NULL) ipolarization = atoi(polarization->ret);
2215                if(fec->ret != NULL) ifec = atoi(fec->ret);
2216                if(modulation->ret != NULL) imodulation = atoi(modulation->ret);
2217                if(rolloff->ret != NULL) irolloff = atoi(rolloff->ret);
2218                if(pilot->ret != NULL) ipilot = atoi(pilot->ret);
2219
2220                if(flag == 3)
2221                {
2222                        if(hp->ret != NULL) ifec = atoi(hp->ret);
2223                        if(lp->ret != NULL) ipolarization = atoi(lp->ret);
2224                        if(bandwidth->ret != NULL) isymbolrate = atoi(bandwidth->ret);
2225                        if(transmission->ret != NULL) ipilot = atoi(transmission->ret);
2226                        if(guardinterval->ret != NULL) irolloff = atoi(guardinterval->ret);
2227                        if(hierarchy->ret != NULL) isystem = atoi(hierarchy->ret);
2228                }
2229
2230                if(networkscan->ret != NULL) inetworkscan = atoi(networkscan->ret);
2231                if(onlyfree->ret != NULL) ionlyfree = atoi(onlyfree->ret);
2232                if(clear->ret != NULL) iclear = atoi(clear->ret);
2233                if(blindscan->ret != NULL) iblindscan = atoi(blindscan->ret);
2234                if(changename->ret != NULL) ichangename = atoi(changename->ret);
2235
2236                if(rcret == getrcconfigint("rcexit", NULL)) break;
2237                if(rcret == getrcconfigint("rcok", NULL)) break;
2238                if(listbox->select != NULL && ostrcmp(listbox->select->name, "tuner") == 0)
2239                {
2240                        scanchangesat(sat, tpnode, listbox->select->ret);
2241                        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);
2242                        drawscreen(scan, 0, 0);
2243                }
2244                if(listbox->select != NULL && ostrcmp(listbox->select->name, "scantype") == 0)
2245                {
2246                        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);
2247                        drawscreen(scan, 0, 0);
2248                }
2249                if(listbox->select != NULL && ostrcmp(listbox->select->name, "system") == 0)
2250                {
2251                        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);
2252                        drawscreen(scan, 0, 0);
2253                }
2254                if(rcret == getrcconfigint("rcred", NULL))
2255                {
2256                        clearscreen(scan);
2257                        screenscan(tpnode, scan->child, tuner->ret, iscantype, isat, ifrequency, iinversion, isymbolrate, ipolarization, ifec, imodulation, irolloff, ipilot, inetworkscan, ionlyfree, iclear, iblindscan, ichangename, isystem, 5000000);
2258                        drawscreen(scan, 0, 0);
2259                }
2260                if(rcret == getrcconfigint("rcgreen", NULL) && tpnode != NULL && iscantype == 0)
2261                {
2262                        struct transponder* tp1 = createtransponder(99, tpnode->fetype, isat, ifrequency, iinversion, isymbolrate, ipolarization, ifec, imodulation, irolloff, ipilot, isystem);
2263                        copytransponder(tp1, tpnode, 99);
2264                        deltransponderbyid(99);
2265                        textbox(_("Message"), _("Transponder changed"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0);
2266                        drawscreen(scan, 0, 0);
2267                }
2268                if(rcret == getrcconfigint("rcyellow", NULL) && iscantype == 0)
2269                {
2270                        struct transponder* tp = tpchoicescreen(isat, flag);
2271                        if(tp != NULL)
2272                        {
2273                                tpnode = tp;
2274                                goto start;
2275                        }
2276                        else
2277                                drawscreen(scan, 0, 0);
2278                }
2279                else if(rcret == getrcconfigint("rcok", NULL))
2280                        break;
2281        }
2282
2283        delmarkedscreennodes(scan, 1);
2284        delownerrc(scan);
2285        clearscreen(scan);
2286        resetsatscan();
2287
2288        if(status.lastservice->channel == NULL)
2289        {
2290                if(status.servicetype == 0)
2291                        servicecheckret(servicestart(getchannel(getconfigint("serviceid", NULL), getconfigllu("transponderid", NULL)), getconfig("channellist", NULL), NULL, 0), 0);
2292                else
2293                        servicecheckret(servicestart(getchannel(getconfigint("rserviceid", NULL), getconfigllu("rtransponderid", NULL)), getconfig("rchannellist", NULL),  NULL, 0), 0);
2294        }
2295        else
2296        {
2297                tmpstr = ostrcat(status.lastservice->channellist, NULL, 0, 0);
2298                servicecheckret(servicestart(status.lastservice->channel, tmpstr, NULL, 0), 0);
2299                free(tmpstr); tmpstr = NULL;
2300        }
2301
2302        //recalc channels
2303        struct channel* chnode = channel;
2304        while(chnode != NULL)
2305        {
2306                if(chnode->servicetype != 99)
2307                {
2308                        chnode->transponder = gettransponder(chnode->transponderid);
2309                        chnode->provider = getprovider(chnode->providerid);
2310                }
2311                chnode = chnode->next;
2312        }
2313       
2314        writeallconfig(1);
2315}
2316
2317#endif
Note: See TracBrowser for help on using the repository browser.