source: svn/branches/kctv/zasc/app/DST_WinAutoSearch.cpp

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
File size: 10.9 KB
Line 
1#include "DST_WinManager.h"
2#include "DST_ChannelTune.h"
3#include "DST_SignalMonitor.h"
4
5#include "DST_DataStrings.h"
6#include "DST_OSDImage.h"
7#include "DST_UserInterface.h"
8
9#include "DST_ISDBT_ChannelTask.h"
10#include "DST_ChannelTune.h"
11#include "DST_DB.h"
12#include "DST_DB_Engine.h"
13
14#define AS_RF_W                 77
15#define AS_CH_NO_W              111
16#define AS_CH_NAME_W    364
17
18#define PROGRESS_BAR_X  33
19#define PROGRESS_BAR_Y  266
20#define PROGRESS_BAR_W  333
21
22
23class CAutoSearchWin : public CWindow
24{
25private:
26        int m_nState;
27        int m_nRF; // ½ºÄµ À§Ä¡
28        CHANNEL_DISPLAY ch[4];
29        DS_U8 nAutoSearchMode;
30        int nChCount[255];
31        bool bTimeOut;
32        bool bReceivePSIP; 
33        bool bReceivePMT;
34        bool bCanceled; 
35        DS_U16 g_nPos;
36        DS_U16 g_nTop;
37        DS_U16 mainSelect;
38        DS_U16 mainListNum;
39        DS_U16 mainItemNum;
40public:
41        CAutoSearchWin(SWinEventMsg event):CWindow(event)
42        {
43                bCanceled = false;
44                bTimeOut = false; 
45                bReceivePSIP = false;
46                bReceivePMT = false;
47               
48                nAutoSearchMode = 1; // 0 ¾÷µ¥ÀÌÆ® 1 ¸®½ºÄµ
49                InitValues();
50               
51//              DST_Printf("nAutoSearchMode = %d\n", nAutoSearchMode);
52                rect.w = DST_GetImageWidth(newcon2_gui_autoscan_back);
53                rect.h = DST_GetImageHeight(newcon2_gui_autoscan_back);
54                rect.x = (DST_GetScreenWidth() - rect.w) / 2;
55                rect.y = (DST_GetScreenHeight()- rect.h) / 2;
56               
57                RegisterAllKey();
58                RegisterKey(VK_PWR, false);
59               
60                memset(DST_g_SignalStrength, 0, sizeof(DST_g_SignalStrength));// ½ºÄµÀü¿¡ ÃʱâÈ­
61                SetTimeOut(0);
62                m_nState = 0; // ½ºÄµ Àü
63                m_nRF = DST_MinRF();
64                memset(ch, 0, sizeof(ch));
65                memset(nChCount, 0, sizeof(nChCount));
66
67                /*if(DST_DB_GetChannelCount() == 0)*/ KeyInput(VK_OK, false);
68        }
69
70        virtual ~CAutoSearchWin()
71        {
72                T();
73                T();
74                T();
75                T();
76                T();
77        }
78       
79        void InitValues(void)
80        {
81                mainItemNum = 2;
82                g_nTop = 0;
83                g_nPos = 0;
84                mainSelect = nAutoSearchMode;
85               
86                mainListNum = 2;
87                if (mainItemNum < mainListNum) mainListNum = mainItemNum;
88               
89                InitItemValues(mainListNum, mainSelect, &g_nTop, &g_nPos);
90        }
91       
92        void AddChList(int rf, int major, int minor, char* name)
93        {
94                int nPos = 4;
95                for (int i = 0; i < 4; i++)
96                {
97                        if (strlen(ch[i].num) != 0) continue;
98                        nPos = i;
99                        break;
100                }
101                if (nPos > 3) 
102                {
103                        nPos = 3;
104                        memcpy(&ch[0], &ch[1], sizeof(CHANNEL_DISPLAY)* 3);
105                }
106                if (minor == 0)
107                {
108                        sprintf(ch[nPos].num, "%d(%d)", major, DST_GetFrequencyNumberbyIndex(rf));
109                }
110                else
111                {
112                        sprintf(ch[nPos].num, "%d-%d(%d)", major, minor, DST_GetFrequencyNumberbyIndex(rf));
113                }
114                strcpy((char*)ch[nPos].name, (char*)name);
115        }
116        void AddChList(int RF)
117        {
118                CDB db;
119                db.GetTable("select major, minor, name from channel_db where rf =%d order by major,minor", RF);
120                if (db.GetRow() < 1) return;
121                nChCount[RF] = db.GetRow();
122                for (int i = 0; i < db.GetRow(); i++)
123                {
124                        AddChList(RF, 
125                                atoi(db.GetResult((i+1)*db.GetCol()+0)), 
126                                atoi(db.GetResult((i+1)*db.GetCol()+1)), 
127                                db.GetResult((i+1)*db.GetCol()+2));
128                }
129        }
130       
131        void Scan(int nRF)
132        {
133                if (bCanceled) return;
134                JST_Scan(nRF);
135                m_nState = 1; //½ºÄµÁß
136                m_nRF = nRF;
137                T();
138        }
139
140        void ScanComplete()
141        {
142                DST_DB_TuneFirstChannel();
143                m_nState = 2;   // ½ºÄµ Á¾·á
144                Draw(m_nState, m_nRF);
145                SetTimeOut(5);
146        }       
147
148        virtual void OnMessage(SWinEventMsg event)
149        {
150                switch (event.cmd)
151                {
152                        case WM_POWER_OFF:
153                                Close();
154                                break;
155                               
156                        case WM_CT_MSG:
157                                switch (event.data32[0])
158                                {
159                                        case CT_STOPPED:
160                                                m_nState = 2;
161                                                Draw(m_nState, m_nRF);
162                                                ScanComplete();
163                                                break;
164                                               
165                                        case CT_SCAN_START:
166                                                T();
167                                                Draw(m_nState, event.data32[1]);
168                                                bTimeOut = false; // LOCKÀÌ ¾ÈµÇ°Å³ª PSIPÀ» ¸ø¹Þ¾Æ¼­ ŸÀӾƿôÀÌ ³­ °æ¿ì
169                                                bReceivePSIP = false; // PSIPÀ» ¹Þ¾Ò´Ù.
170                                                bReceivePMT = false; //PMT¸¦ ¹Þ¾Ò´Ù. VCT°¡ ¾ø¾îµµ ä³ÎÀÌ ÀÖÀ»¼ö ÀÖ´Ù
171                                                break;
172                                       
173                                        case CT_SCAN_PSIP_WAIT:
174                                                DST_Printf("CT_SCAN_PSIP_WAIT %d %d %d\n", (int)event.data32[1], (int)event.data32[2], (int)event.data32[3]);
175                                                if (bReceivePSIP == true) break;
176                                                if (bTimeOut == true) break;
177                                                if ((int)event.data32[1] != m_nRF) break;
178                                                if (event.data32[2] < 7000) break;
179                                                DST_Printf("CT_SCAN_PSIP_WAIT timeout\n");
180                                                bTimeOut = true;
181                                               
182                                                // ÀÌÀü ä³ÎÀ» Áö¿î´Ù.
183                                                if (bReceivePMT == false && nAutoSearchMode == 1) // 0 ¾÷µ¥ÀÌÆ® 1 ¸®½ºÄµ
184                                                {
185                                                        JST_DB_Del(m_nRF);
186                                                }
187                                                 if (bReceivePMT == true) // PSIP ä³ÎÀϼöµµ ÀÖ´Ù.
188                                                 {
189                                                        AddChList(event.data32[1]);
190                                                }
191                                                if (event.data32[1] >= DST_MaxRF())
192                                                {
193                                                        ScanComplete();
194                                                }
195                                                else
196                                                {
197                                                        Scan(event.data32[1]+1);
198                                                } 
199                                                break;
200                                                       
201                                        case CT_SCAN_LOCK_WAIT:
202                                                DST_Printf("CT_SCAN_LOCK_WAIT %d %d %d\n", (int)event.data32[1], (int)event.data32[2], (int)event.data32[3]);
203                                                if (bReceivePSIP == true) break;
204                                                if (bTimeOut == true) break;
205                                                if ((int)event.data32[1] != m_nRF) break;
206                                                if (event.data32[2] < 700) break; // 700ms À̳»´Â ¹«½Ã
207                                                if (event.data32[3] > 0) break; // lockÀÌ µÇ¾î ÀÖ´Ù¸é ¹«½Ã
208                                                DST_Printf("CT_SCAN_LOCK_WAIT timeout\n");
209                                                bTimeOut = true;
210                                               
211                                                // ÀÌÀü ä³ÎÀ» Áö¿î´Ù.
212                                                if (bReceivePMT == false && nAutoSearchMode == 1) // 0 ¾÷µ¥ÀÌÆ® 1 ¸®½ºÄµ 2:±âÁö±¹ ¼­Ä¡
213                                                {
214                                                        JST_DB_Del(m_nRF);
215                                                }
216                                                  if (bReceivePMT == true) // PSIP ä³ÎÀϼöµµ ÀÖ´Ù.
217                                                 {
218                                                        AddChList(event.data32[1]);
219                                                }
220                                                if (event.data32[1] >= DST_MaxRF())
221                                                {
222                                                        ScanComplete();
223                                                }
224                                                else
225                                                {
226                                                        Scan(event.data32[1]+1);
227                                                } 
228                                                break;
229                                       
230                                        case CT_SCAN_RECEIVE_TVCT:
231                                        case CT_SCAN_RECEIVE_CVCT:
232                                                DST_Printf("CT_SCAN_RECEIVE_TVCT\n");
233                                                if (bReceivePSIP == true) break;
234                                                if (bTimeOut == true) break;
235                                                bReceivePSIP = true;
236                                                AddChList(event.data32[1]);
237                                                if (event.data32[1] >= DST_MaxRF())
238                                                {
239                                                        ScanComplete();
240                                                }
241                                                else
242                                                {
243                                                        Scan(event.data32[1]+1);
244                                                } 
245                                                break;
246                                               
247                                        case CT_SCAN_RECEIVE_PMT:
248                                                DST_Printf("CT_SCAN_RECEIVE_PMT %d %d %d\n", (int)event.data32[1], (int)event.data32[2], (int)event.data32[3]);
249                                                bReceivePMT = true;
250                                                break;
251                                        case CT_SCAN_RECEIVE_PAT:
252                                                DST_Printf("CT_SCAN_RECEIVE_PAT\n");
253                                                break;
254                                }
255                                break;
256                }
257        }
258       
259        virtual void Show(void)
260        {
261                Draw(m_nState, m_nRF);
262        }
263       
264        DS_U16* GetString(int index)
265        {
266                switch(index)
267                {
268                        case 0: return pz_Scan_Update[OSD_Lang];
269                        case 1: return pz_Scan_Rescan[OSD_Lang];
270                        default: break;
271                }
272                return 0;
273        }       
274       
275        // nState == 0; // ½ÃÀÛÀü  ¹öư ¾øÀ½
276        // nState == 1; // ÁøÇàÁß  Ãë¼Ò ¹öư
277        // nState == 2; // Á¾·á Àç½ÃÀÛ ´ë±â ½ÃÀÛ ¹öư
278        void Draw(int nState, int nRF)
279        {
280                // ¹è°æ
281                DrawImage(0, 0, newcon2_gui_autoscan_back);
282                // ŸÀÌÆ²
283                setFontStyle(20,0xC8C8C8,ALIGN_MIDDLE,ALIGN_CENTER);
284                // Ç׸ñ À̸§  ä³Î¹øÈ£ RF ä³ÎÀ̸§
285#if DESIGN_TYPE == 1
286                DrawTextUni( 27, 10,  118, 29, pz_Scan_NoRF[OSD_Lang], &font);
287                DrawTextUni(174, 10, 176, 29, pz_chName[OSD_Lang], &font);
288#else
289                DrawTextUni( 10, 10,  171, 29, pz_Scan_NoRF[OSD_Lang], &font);
290                DrawTextUni(184, 10, 169, 29, pz_chName[OSD_Lang], &font);
291#endif
292
293
294                // ¹öư ±×¸®±â
295               
296                setFontStyle(19,0xC8C8C8,ALIGN_MIDDLE,ALIGN_CENTER);
297                DrawImage(390, 12, newcon2_gui_depth3_button_small_selected,true);
298                //DrawImage(390, 61, newcon2_gui_depth3_button_small_selected,true);
299                DrawTextUni(390, 12, DST_GetImageWidth(newcon2_gui_depth3_button_small_selected), 38, pz_Scan_Update[OSD_Lang], &font);
300                //DrawTextUni(390, 61, DST_GetImageWidth(newcon2_gui_depth3_button_small_selected), 38, pz_Scan_Rescan[OSD_Lang], &font);
301#if DESIGN_TYPE == 1
302#else
303                                setFontStyle(19,0x000000,ALIGN_MIDDLE,ALIGN_CENTER);
304#endif
305
306                //if(mainSelect == 0)
307                //{
308                        DrawImage(390, 12, newcon2_gui_depth3_button_small_cursor,true);
309                        DrawTextUni(390, 12, DST_GetImageWidth(newcon2_gui_depth3_button_small_selected),  DST_GetImageHeight(newcon2_gui_depth3_button_small_selected), (nState==1)?pz_Stop[OSD_Lang]:GetString(mainSelect), &font);
310                //}
311                //else
312                //{
313                        //DrawImage(390, 61, newcon2_gui_depth3_button_small_cursor,true);
314                        //DrawTextUni(390, 61, DST_GetImageWidth(newcon2_gui_depth3_button_small_selected),  DST_GetImageHeight(newcon2_gui_depth3_button_small_selected), (nState==1)?pz_Stop[OSD_Lang]:GetString(mainSelect), &font);
315                //}
316               
317                setFontStyle(20,0xC8C8C8,ALIGN_MIDDLE,ALIGN_CENTER);
318                // Ç׸ñ Ç¥½Ã
319                for (int i=0; i < 4; i++)
320                {
321                        if (strlen(ch[i].num) == 0) continue;
322                        DS_U32* strText32 = DST_UTF82Uni((DS_U8*)ch[i].name); // È£ÃâÇÑ ÂÊ¿¡¼­ ¸Þ¸ð¸® ÇØÁ¦
323                        // ä³Î ¹øÈ£ , RF
324#if DESIGN_TYPE == 1
325                        // RF
326                        //sprintf(strText, "(%d) %02d", ch[i].rf, ch[i].num);
327                        DrawText( 27, 10+(i+1)*36,      118, 29,  ch[i].num, &font);
328                        // ä³Î À̸§
329                        DrawText32(174, 10+(i+1)*36, 174, 29, strText32, &font);
330#else
331                        // RF
332                        //sprintf(strText, "(%d) %02d", ch[i].rf, ch[i].num);
333                        DrawText( 10, 10+(i+1)*36,      171, 29,  ch[i].num, &font);
334                        // ä³Î À̸§
335                        DrawText32(184, 10+(i+1)*36, 169, 29, strText32, &font);
336#endif
337//                      DST_OS_Free(&strText32);
338
339                }
340                // ÁøÇà¹Ù
341                int nProg = 0;
342                switch (nState)
343                {
344                        case 0: nProg = 0; break;
345                        case 1: nProg = nRF - DST_MinRF() + 1; break;
346                        case 2: nProg = DST_MaxRF() - DST_MinRF()+1; break;
347                }
348                DST_Printf("nProg = %d\n", nProg);
349               
350#if DESIGN_TYPE == 1
351                DrawProgressBar(36, 211, 291,  DST_MaxRF() - DST_MinRF() +1, nProg);
352#else
353                DrawProgressBar(13, 210, 338,  DST_MaxRF() - DST_MinRF() +1, nProg);
354#endif
355               
356
357                               
358                // ÁøÇà»óȲ ¹®±¸
359                // 5 channels found. searching...
360               
361                int nTotalCount = 0;
362                for (int i = 0; i <= nRF; i++) nTotalCount+=nChCount[i];
363
364                if( m_nState == 0 ) 
365                {
366                        UpdateScreen();
367                        return;
368                }
369               
370                if(nTotalCount == 0 && m_nState == 1)
371                {
372                        //DrawTextUni(366, 166, 148, 29, pz_Searching[OSD_Lang], &font);
373                }
374                else
375                {
376                        if (nTotalCount)
377                        {
378                                char strTextNum[20];
379                                sprintf(strTextNum, " %d", nTotalCount);
380                                DS_U16 strText16[64];
381                                str2uni(strText16, strTextNum);
382                                strcat16(strText16, pz_Scan_ChannelFound[OSD_Lang]);
383                                DrawTextUni(366-15, 166, 148+30, 29, strText16, &font);
384                        }
385                }
386
387                       
388               
389                UpdateScreen();
390               
391        }
392
393        void DrawProgressBar(int x, int y, int w, int range, int pos)
394        {
395                DST_Printf("range = %d pos = %d\n", range, pos);
396                int position = (w*pos)/(range);
397
398                for (int i = x; i < x+position; i++)
399                {
400                        DrawImage(i, y, newcon2_gui_progress_yellow,true);
401                }
402        }
403
404        virtual void KeyInput(unsigned char key, bool /*bRepeat*/)
405        {
406                switch(key)
407                {
408//                      case VK_UP:
409//                      case VK_DN:
410//                              if(m_nState==1) break;
411//                              if(key == VK_UP)
412//                                      ItemIncrease(mainItemNum, 2, &g_nTop, &mainSelect, &g_nPos);
413//                              else
414//                                      ItemDecrease(mainItemNum, 2, &g_nTop, &mainSelect, &g_nPos);
415//                              Draw(m_nState, m_nRF);
416//                              break;
417                        case VK_OK: 
418                                if(nAutoSearchMode == mainSelect && m_nState == 1)
419                                {
420                                        bCanceled = true;
421                                        JST_Stop();
422                                        ScanComplete();                 
423                                }
424                                else
425                                {
426                                        SetTimeOut(0);
427                                        bCanceled = false;
428                                        m_nRF = DST_MinRF();
429                                        memset(ch, 0, sizeof(ch));
430                                        memset(nChCount, 0, sizeof(nChCount));
431                                        // nAutoSearchMode=mainSelect; Ç×»ó Ãʱ⠽ºÄµÀÌ´Ù.
432                                        Scan(m_nRF);
433                                        Draw(m_nState, m_nRF);
434                                }
435                                break;
436                        case VK_CANCEL:
437                        case VK_MENU:
438                                m_nState = 0;
439                                bCanceled = true;
440                                JST_Stop();
441                                ScanComplete();
442                                Close();
443                                break;
444                }
445        }
446};
447
448void DST_CreateAutoSearchWin(SWinEventMsg event)
449{
450        DST_AddWin((WinID)(event.data[0]), new CAutoSearchWin(event));
451}
Note: See TracBrowser for help on using the repository browser.