source: svn/trunk/zasc/app/DST_ChannelTune.cpp

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

1.phkim

  1. revision copy newcon3sk r27
File size: 31.6 KB
RevLine 
[2]1#include "DST_ChannelTune.h"
2#include "DST_HostInterface.h"
3#include "DST_GlobalVariables.h"
4#include "DST_WindowEvent.h"
5#include "DST_WindowType.h"
6#include "DST_WinManagerTask.h" //ui
7#include "DST_DataStrings.h"
8#include "DST_SignalMonitor.h"
9#include "DST_UserInterface.h"
10#include "DST_FontEngine.h"
11#include "DST_CCTask.h"
12#include "DST_WinManager.h"
13#include "DST_ISDBT_ChannelTask.h"
14#include "dst_eroum_interface.h"
15#include "DST_DB_Engine.h"
16#include "DST_DB.h"
17#include "DST_EEPROM.h"
18#include "DST_GlobalVariables.h"
19#include "DST_Updates.h"
20
21void DST_USBUpdateInit(void);
22
23void DST_DB_Del();
24char *DST_GetModelName(void);
25
26static void DST_CT_CallBack(DS_U8 Cmd, DS_U32 p1, DS_U32 p2, DS_U32 p3, DS_U32 p4, DS_U32 p5, DS_U32 p6);
27
28// °øÀå ÃʱâÈ­ ÈÄ ÀçÆÃ ÈÄ Ã¹¹øÂ°·Î ºÒ¸®´Â ÇÔ¼ö
29// EEPROM°ú ä³Î¸ÊÀ» ¸ðµÎ Áö¿î´Ù.
30void DST_Factory_Reset()
31{
32        DST_DB_Del();
33        DST_EEPROM_FactoryInit();
34}
35
36void DST_Tune(DS_U8 RF, DS_U16 program_number)
37{
38        if (program_number == 0)
39        {
40//              CDB db;
41//              db.Query("update signal set signal_strength=99 where signal_strength=100");
42//              db.Query("delete from signal where rf=%d", RF);
43//              db.Query("insert into signal values(%d, %d, %d, %d, %d)", RF, 100, 0, 0, 1);
44                //Minor = 1;
45        }
46        JST_Open(DST_CT_CallBack);
47        JST_Tune(RF, DHL_MODULATION_8VSB, program_number);
48}
49
50// ä³Î Æ©´×À» ÇÑ´Ù.
51void DST_Scan(DS_U8 RF)
52{
53        JST_Open(DST_CT_CallBack);
54        JST_Scan(RF);
55}
56       
57#if 0
58____AV_STATE___()
59#endif
60static DS_U8  g_AV_RF = 0;
61static DS_U16 g_AV_program_number = 0;
62static DS_U16 g_AV_source_id = 0;
63
64// ÄݹéÀ¸·Î ¿Ã¶ó¿Â AVÀÇ ÁøÇà »óȲ
65void DST_GetAVState(DS_U8 *RF, DS_U16 *program_number, DS_U16 *source_id)
66{
67        if (RF) *RF = g_AV_RF;
68        if (program_number) *program_number = g_AV_program_number;
69        if (source_id) *source_id = g_AV_source_id;
70}
71
72static DS_U32 g_AV_PCR = 0;
73static DS_U32 g_AV_VideoType = 0;
74static DS_U32  g_AV_AudioType = 0;
75static DS_U32 g_AV_VideoPID = 0;
76static DS_U32  g_AV_AudioPID = 0;
77
78void DST_SetAVInfo(DS_U32 PCR, DS_U32 vPid, DS_U32 aPid, DS_U32 vType, DS_U32 aType)
79{
80        g_AV_PCR = PCR;
81        g_AV_VideoPID = vPid;
82        g_AV_AudioPID = aPid;
83        g_AV_VideoType = vType;
84        g_AV_AudioType = aType;
85
86}
87
88// ÄݹéÀ¸·Î ¿Ã¶ó¿Â AVÀÇ ÁøÇà »óȲ
89void DST_GetAVInfo(DS_U32 *PCR, DS_U32 *vPid, DS_U32 *aPid, DS_U32 *vType, DS_U32 *aType)
90{
91        if (PCR) *PCR = g_AV_PCR;
92        if (vType) *vPid = g_AV_VideoPID;
93        if (aType) *aPid = g_AV_AudioPID;
94        if (vType) *vType = g_AV_VideoType;
95        if (aType) *aType = g_AV_AudioType;
96}
97
98
99static DS_U16 DST_g_VideoWidthTV = 0;
100static DS_U16 DST_g_VideoHeightTV = 0;
101static DS_U16 DST_g_RefreshRate = 0;
102static bool DST_g_bInterlace = false;
103static bool DST_g_Wide = false;
104// ºñµð¿À Å©±â¸¦ ¹ÝȯÇÑ´Ù.
105// ¸®ÅϰªÀº interlace À¯¹«´Ù.
106void DST_GetVideoSize(DS_U16* width, DS_U16* height, DS_U16* fps, bool* bInterlace, bool* bWide)
107{
108#if 0
109        *width = DST_g_VideoWidthTV;
110        *height = DST_g_VideoHeightTV;
111        *fps = DST_g_RefreshRate;
112        *bInterlace = DST_g_bInterlace;
113        *bWide = DST_g_Wide;
114#else
115//      //Å×½ºÆ®¿ë:: ºñµð¿À ¼Ò½º°¡ 4:3À϶§
116//      *width = 720;
117//      *height = 480;
118//      *fps = DST_g_RefreshRate;
119//      *bInterlace = DST_g_bInterlace;
120//      *bWide = false;
121        //Å×½ºÆ®¿ë:: ºñµð¿À ¼Ò½º°¡ 16:9À϶§
122        *width = 1920;
123        *height = 1080;
124        *fps = DST_g_RefreshRate;
125        *bInterlace = DST_g_bInterlace;
126        *bWide = true;
127
128#endif
129}
130
131void DST_ResetVideoSize()
132{
133        DST_g_VideoWidthTV = 0;
134        DST_g_VideoHeightTV = 0;
135        DST_g_RefreshRate = 0;
136        DST_g_bInterlace = false;
137        DST_g_Wide = false;
138}
139
140#if 0
141____TIME___()
142#endif
143
144#if 0
145____STT Set___()
146#endif
147static DS_U32 g_systemTime = 0;
148static DS_U8 g_gpsUtcOffset = 0;
149static DS_U32 g_refreshSystemTime = 0;  // system time °»½Å ½Ã°£
150
151void DST_SetTimeBySTT(DS_U32 RF, DS_U32 a_systemTime, DS_U8 a_offset, DS_U32 a_time)
152{
153//      DST_Printf("RF = %d a_systemTime = %d a_offset = %d a_time=%d\n", RF, a_systemTime, a_offset, a_time);
154        g_systemTime = a_systemTime;
155        g_gpsUtcOffset = a_offset;
156        DST_g_TimeOffset[RF]=g_gpsUtcOffset;
157        g_refreshSystemTime = a_time;
158}
159
160DS_U32 DST_GetCurrentUTCTime()
161{
162        DS_U32 systemTime = 0;
163        if(g_systemTime)
164        {
165                if (g_refreshSystemTime > DST_OS_GetTickCount()) g_refreshSystemTime = DST_OS_GetTickCount();
166                systemTime = g_systemTime + (DST_OS_GetTickCount() - g_refreshSystemTime) /  DST_OS_GetTicksPerSecond();
167        }
168        return systemTime;
169}
170
171DS_U32 DST_GetCurrentLocalTime()
172{
173        if(g_systemTime == 0) return 0;
174
175        return DST_GetCurrentUTCTime() + g_gpsUtcOffset + 9 * 3600;
176}
177
178DS_U32 DST_UTCTimeToLocalTime(DS_U32 a_systemTime)
179{
180        if(a_systemTime == 0) return 0;
181
182        DS_U32 localTime = a_systemTime + g_gpsUtcOffset + 9 * 3600;
183        DST_Printf("system time -> local time : %ld -> %ld\n", a_systemTime, localTime);
184       
185        return localTime;
186}
187
188DS_U16* DST_GetTimeString(DS_U32 a_time, TIME_MODE a_mode, bool bApplyTimeZone, int a_offset)
189{
190        DS_U32 year, month, date, day;
191        DS_U32 hour, min, sec;
192        DS_U32 utc = a_time;
193        DS_U32 daytab[2][13] = {
194                {365, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
195                {366, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
196        };
197        int acc_day;
198        int i, leap;
199
200        utc += a_offset;
201        /* timezone ¼³Á¤¿¡ µû¸¥ º¸Á¤À» ÇÑ´Ù. */
202        if(bApplyTimeZone)
203                utc += (9 * 3600);
204       
205        /* 1980/1/1 ºÎÅÍ UTCÀÇ ±âÁØÀÎ 1980/1/6 ±îÁöÀÇ ½Ã°£À» ´õÇÑ ´ÙÀ½
206            1980³â ºÎÅÍ °è»êÇØ ³ª°¡¸é ÆíÇÏ´Ù.
207        */
208        utc += 432000;   /* 5Àϰ£ÀÇ ÃÊ  */
209        acc_day = -5;
210        year = 1980;
211        month = 1;
212        date = 1;
213        day = 2; /* Tuesday: 1980³â 1¿ù 1ÀÏÀº È­¿äÀÏ */
214        hour = 0;
215        min = 0;
216        sec = 0;
217        leap = 1;       /* 1980³âÀº 4ÀÇ ¹è¼öÀ̹ǷΠÀ±³â.. */
218
219        /* year¸¦ °è»ê */
220        while (utc >= (daytab[leap][0]*86400))
221        {
222                utc -= daytab[leap][0]*86400;
223                acc_day += daytab[leap][0];
224                year ++;
225                leap = ((year%4==0)&&(year%100!=0))||(year%400==0);
226        }
227
228        /* month¸¦ °è»ê */
229        i=1;
230        while (utc >= (daytab[leap][i]*86400))
231        {
232                utc -= daytab[leap][i]*86400;
233                acc_day += daytab[leap][i];
234                month ++;
235                i++;
236        }
237
238        date += (utc/86400);
239        acc_day += (utc/86400);
240        utc = utc%86400;
241       
242        day = (acc_day + 7) % 7;
243       
244        hour = (utc/3600);
245        utc = utc%3600;
246       
247        min = (utc/60);         
248        sec = utc%60;
249
250        static DS_U16 timeStr[100];
251        memset(timeStr, 0, 100);
252        char tmpStr[20] = {0, };
253        switch(a_mode)
254        {
255                case DATE_NO_YEAR_TIME_NO_SEC_DETAIL:
256                {
257                        sprintf(tmpStr, "%d", (int)month);
258                        str2uni(timeStr, tmpStr);
259                        strcat16(timeStr, pz_Month[OSD_Lang]);
260                        memset(tmpStr, 0, strlen(tmpStr));
261                        sprintf(tmpStr, " %d", (int)date);
262                        str2uni(&timeStr[strlen16(timeStr)], tmpStr);
263                        strcat16(timeStr, pz_Day[OSD_Lang]);           
264                        strcat16(timeStr, (char*)"(");
265                        DS_U16* dayStr = DST_GetDayOfWeakString(day);
266                        strcat16(timeStr, dayStr);
267                        strcat16(timeStr, (char*)") ");
268                        strcat16(timeStr,  (hour>12)?pz_PM[OSD_Lang]:pz_AM[OSD_Lang]);
269                        sprintf(tmpStr, " %02d:%02d", (hour>12)?(int)hour-12:(int)hour, (int)min);
270                        strcat16(timeStr, tmpStr);
271                        break;
272                }       
273                case DATE_NO_YEAR_TIME_NO_SEC:
274                {
275                        sprintf(tmpStr, "%d/%d(", (int)month, (int)date);
276                        str2uni(timeStr, tmpStr);
277                        DS_U16* dayStr = DST_GetDayOfWeakString(day);
278                        strcat16(timeStr, dayStr);
279                        strcat16(timeStr, (char*)") ");
280                        strcat16(timeStr,  (hour>12)?pz_PM[OSD_Lang]:pz_AM[OSD_Lang]);
281                        sprintf(tmpStr, " %02d:%02d", (hour>12)?(int)hour-12:(int)hour, (int)min);
282
283                        strcat16(timeStr, tmpStr);
284                        break;
285                }
286                case DATE_TIME_NO_SEC:
287                {
288                        sprintf(tmpStr, "%d.%d.%d(", (int)year, (int)month, (int)date);
289                        str2uni(timeStr, tmpStr);
290                        DS_U16* dayStr = DST_GetDayOfWeakString(day);
291                        strcat16(timeStr, dayStr);
292                        strcat16(timeStr, (char*)") ");
293                        strcat16(timeStr,  (hour>12)?pz_PM[OSD_Lang]:pz_AM[OSD_Lang]);
294                        sprintf(tmpStr, " %02d:%02d", (hour>12)?(int)hour-12:(int)hour, (int)min);
295
296                        strcat16(timeStr, tmpStr);
297                        break;
298                }
299                case DATE_TIME:
300                {
301                        sprintf(tmpStr, "%d.%d.%d(", (int)year, (int)month, (int)date);
302                        str2uni(timeStr, tmpStr);
303                        DS_U16* dayStr = DST_GetDayOfWeakString(day);
304                        strcat16(timeStr, dayStr);
305                        strcat16(timeStr, (char*)") ");
306                        sprintf(tmpStr, "%02d:%02d:%02d", (int)hour, (int)min, (int)sec);
307                        strcat16(timeStr, tmpStr);
308                        break;
309                }
310                case DATE_ONLY:
311                {
312                        sprintf(tmpStr, "%d.%d.%d(", (int)year, (int)month, (int)date);
313                        str2uni(timeStr, tmpStr);
314                        DS_U16* dayStr = DST_GetDayOfWeakString(day);
315                        strcat16(timeStr, dayStr);
316                        sprintf(tmpStr, ")");
317                        strcat16(timeStr, tmpStr);
318                        break;
319                }
320                case TIME_NO_SEC:
321                {
322                        strcat16(timeStr,  (hour>12)?pz_PM[OSD_Lang]:pz_AM[OSD_Lang]);
323                        sprintf(tmpStr, "%02d:%02d", (hour>12)?(int)hour-12:(int)hour, (int)min);
324
325                        str2uni(&timeStr[strlen16(timeStr)], tmpStr);
326                        break;
327                }
328                case TIME_NO_SEC_NO_AMPM:
329                {
330                        sprintf(tmpStr, "%02d:%02d", (hour>12)?(int)hour-12:(int)hour, (int)min);
331                        str2uni(timeStr, tmpStr);
332                        break;
333                }
334                case TIME_ONLY:
335                {
336                        sprintf(tmpStr, "%02d:%02d:%02d", (int)hour, (int)min, (int)sec);
337                        str2uni(timeStr, tmpStr);
338                        break;
339                }
340                case AMPM:
341                {                       
342                        strcat16(timeStr,  (hour>12)?pz_PM[OSD_Lang]:pz_AM[OSD_Lang]);
343                        break;
344                }
345        }
346
347        return timeStr;
348}
349
350// ¾Æ·¡ ºê¶óÁúÇà ½Ã°£ °ü·Ã ÇÔ¼ö »èÁ¦ ¿¹Á¤
351struct DATETIME
352{
353        DS_U16 date;
354        DS_U32 time;
355        int offset;
356        DS_U32 tick;
357};
358
359static DATETIME g_time[256];
360
361// MJD½Ã°£ º¯È¯
362static void DST_MJD(int mjd, int *year, int *month, int *day, int *wday)
363{
364        int y = int((mjd-15078.2f)/365.25f);
365        int m = int((mjd-14956.1f - int(y*365.25f)) / 30.6001f);
366        int k = (m==14 || m==15) ? 1 : 0;
367        *day = mjd-14956-int(y*365.25f)-int(m*30.6001f);
368        *year = 1900 + y + k;
369        *month = m - 1 - k * 12;
370        *wday = ((mjd+3) % 7); // ÀÏ¿äÀÏÀÌ 0 ¿ù¿äÀÏÀÌ 1
371}
372
373int DST_GetTimeOffset()
374{
375        DS_U8 RF = 0;
376        DST_GetAVState(&RF);
377        DATETIME time = g_time[0];
378        if (g_time[RF].tick) time = g_time[RF];
379        return time.offset;
380}
381
382// ÇöÀç ½Ã°£À» °¡Á®¿Â´Ù.
383bool DST_GetTime(STime_t *t)
384{
385        DS_U8 RF = 0;
386        DST_GetAVState(&RF);
387        DATETIME time = g_time[0];
388        if (g_time[RF].tick) time = g_time[RF];
389        if (time.date == 0 || time.tick == 0) return false;
390        int sec = time.time + ((DST_OS_GetTickCount() - time.tick) / DST_OS_GetTicksPerSecond()) + time.offset * (60*60);
391        int day = time.date;
392        if (sec >= (24*60*60)) // ƽ Ä«¿îÆ®·Î º¸Á¤ÇÑ °ªÀÌ ¹ã 12½Ã¸¦ ³Ñ¾î°¡¸é º¸Á¤ÇÑ´Ù.
393        {
394                 sec = sec - (24*60*60);
395                 day = day + 1;
396        }
397        if (sec < 0) // OFFSETÀ» Àû¿ëÇϸé À½¼ö°¡ µÉ ¼ö ÀÖ´Ù
398        {
399                 sec = sec + (24*60*60);
400                 day = day - 1;
401        }
402        DST_MJD(day, &t->year, &t->month, &t->day, &t->wday);
403        t->hour = sec / 3600;
404        t->min  = (sec % 3600) / 60;
405        t->sec  = sec % 60;
406        return true;
407}
408
409#if 0
410____NEW_EPG_DB___()
411#endif
412
413EPG_DB* DST_EPG_DB_Get(int *nCount, int limit)
414{
415        //DST_Printf("DST_EPG_DB_Get\n");
416        // ÇöÀç ¹æ¼ÛÁßÀÎ Á¤º¸¸¦ °¡Á®¿Â´Ù
417        int count = 0;
418        DS_U8  RF = 0;
419        DS_U16 sID = 0;
420        DST_GetAVState(&RF, 0, &sID);
421        EPG_DB *epg_db =0;
422        if (RF == 0 || sID == 0) 
423        {
424                *nCount = count;
425                return 0;       
426        }
427
428        DS_U32 curTime = DST_GetCurrentUTCTime();
429        CDB db;
430        db.GetTable("select start_time, length_in_seconds, event_id, title from eit_sub "
431                        "where rf = %d and source_id = %d "
432                        "and start_time <= %d "
433                        "order by start_time DESC", RF,sID, curTime);
434//              DST_Printf("### ROW Count : %d   COL Count : %d\n", db.GetRow(), db.GetCol());
435        if(db.GetRow() < 1)
436        {
437                *nCount = count;
438                return 0;
439        }
440//              DST_Printf("\n\n getRow:%d curTime:%d\n\n",db.GetRow(),curTime);
441//              DS_U16 eventId = 0;
442        DS_U32 eventTime = 0;
443        bool bFound = false;
444        T();
445        for(int i=0 ; i<db.GetRow() ; i++)
446        {
447                DS_U32 startTime = atoi(db.GetResult((i+1)*db.GetCol()));
448                DS_U32 endTime = startTime + atoi(db.GetResult((i+1)*db.GetCol()+1));
449                if(startTime <= curTime && curTime < endTime)
450                {
451//                              eventId = atoi(db.GetResult((i+1)*db.GetCol()+2));
452                        eventTime = atoi(db.GetResult((i+1)*db.GetCol()));
453//                              DST_Printf("\n\n eventTime:%d\n\n",eventTime);
454                        bFound = true;
455                        break;
456                }
457               
458        }
459        int nRealCount = 0;
460        if(bFound)
461        {
462                db.GetTable("select source_id, event_id, title, start_time, length_in_seconds from eit_sub "
463                                "where rf=%d and source_id = %d "
464                                "and start_time >= %d "
465                                "group by event_id order by start_time ASC", RF, sID, eventTime);
466               
467                if(db.GetRow() < 1)
468                {
469                        *nCount = count;
470                        return 0;
471                }
472                nRealCount = db.GetRow() ;
473                epg_db = (EPG_DB*)DST_OS_Calloc(nRealCount, sizeof(EPG_DB));
474                for(int i=0 ; i<nRealCount ; i++)
475                {
476                       
477                        epg_db[count].source_id = atoi(db.GetResult((i+1)*db.GetCol()));
478                        epg_db[count].event_id = atoi(db.GetResult((i+1)*db.GetCol()+1));
479                        strcpy((char*)epg_db[count].title, db.GetResult((i+1)*db.GetCol()+2)); 
480                        epg_db[count].start_time= atoi(db.GetResult((i+1)*db.GetCol()+3));
481                        epg_db[count].duration= atoi(db.GetResult((i+1)*db.GetCol()+4));
482                        CDB db2;
483                        db2.GetTable("select title from ett "
484                                        "where rf=%d and source_id = %d "
485                                        "and event_id = %d ", RF, epg_db[count].source_id, epg_db[count].event_id);
486                       
487                        if(db2.GetRow() < 1)
488                        {
489                                if(epg_db[count].text) DST_OS_Free(&epg_db[count].text);
490                                epg_db[count].text = (char*)DST_OS_Calloc(1, 1);               
491
492                        }               
493                        else
494                        {
495                                epg_db[count].text = (char*)DST_OS_Calloc(strlen(db2.GetResult(db2.GetCol()))+1, 1);
496                                strcpy(epg_db[count].text, (db2.GetResult(db2.GetCol())));     
497                        }
498
499                        count++;
500                }
501
502               
503               
504        }
505        *nCount = nRealCount;
506        return epg_db;
507}
508// EPG µðºñ ¸Þ¸ð¸®¸¦ ÇØÁ¦ÇÑ´Ù.
509void DST_EPG_DB_Free(EPG_DB* db, int nCount)
510{
511        for (int i = 0; i < nCount; i++)
512        {
513                if (db[i].text) DST_OS_Free(&db[i].text);       
514        }
515        DST_OS_Free(&db);
516}
517
518
519#if 0
520____SIGNAL MONITOR___()
521#endif
522
523
524static DHL_AUDIO_MODE g_AudioMode = DHL_AUDIO_UNKNOWN;
525DHL_AUDIO_MODE DST_AUD_GetMode()
526{
527        return g_AudioMode;
528}
529
530int DST_GetSignalStrength()
531{
532        DS_U8 RF = 0;
533        DST_GetAVState(&RF);
534        return DST_g_SignalStrength[RF];
535}
536
537
538static bool g_Lock  = true;
539static bool g_Video = true;
540static bool g_Audio = true;
541
542bool  DST_IsAVBlock()
543{
544        return (g_Lock == false || g_Video == false);
545}
546
547bool DST_IsWeakSignal()
548{
549        return (g_Lock == false);
550}
551
552bool DST_IsAudioOnly()
553{
554        return (g_Lock == true && g_Video == false && g_Audio == true);
555}
556
557bool DST_IsNoProgram()
558{
559        return (g_Lock == true && g_Video == false && g_Audio == false);
560}
561
562static int TUNE_SCAN_STATE = CT_STOPPED;
563bool DST_IsTuneMode()
564{
565        return (TUNE_SCAN_STATE == CT_TUNE_START);
566}
567
568
569
570
571struct DATETIME2
572{
573        DS_U16 date; // day
574        DS_U32 time; // sec
575};
576bool DST_IsBetweenTime(DATETIME2 compare_time, DATETIME2 conrol_start_time, DATETIME2 conrol_end_time)
577{       
578        if(compare_time.date == 0 || conrol_start_time.date == 0 || conrol_end_time.date == 0) return false;
579        if(conrol_start_time.time <= compare_time.time && compare_time.time < conrol_end_time.time)
580        {
581                return true;
582        }
583        else
584        {
585                if(conrol_start_time.date<= compare_time.date && compare_time.date < conrol_end_time.date) return true;
586                else return false;
587        }
588       
589}
590
591
592
593#if 0
594____RF_UPDATE___()
595#endif
596
597
598static char* g_RFUpdate_data = 0;
599static int g_RFUpdate_data_length = 0;
600
601static int DST_CheckCRC(DS_U32 crc_value, char * data, int size)
602{
603        DS_U32 ulCrc = crc32((DS_U8 *)data, size);
604
605        if (ulCrc != crc_value) 
606        {
607                DST_Printf("Total image crc error!!!\n");
608                DST_Printf("\nFilelength:0x%08x \n", size);
609                DST_Printf("Computed crc32:0x%08x, correct crc32:0x%08x\n",(int)ulCrc, (int)crc_value);
610                return CRC_READ_TOTAL_FAIL;
611        }
612
613        DST_Printf("Total image crc ok...\n");
614        return UPDATE_OK;       
615}
616
617int write2Flash(int partition, int partition_size, int data_size, int offset, char * data, int category)
618{
619#ifdef DSTAR
620                char filename[64];
621                sprintf(filename, "%s", partition ? "kernel.bin" : "boot.bin");
622                FILE *fp = fopen(filename,"wb");
623#endif
624
625        int ret = 0;
626        int old_pos = -1;
627
628        SWinEventMsg event;
629        event.cmd = WM_RF_UPDATE;
630       
631        for (int i = 0; i < data_size; i+=4096)
632        {
633                int pos = i * 100 / data_size;
634                int length = (i+4096 > data_size) ? data_size-i : 4096;
635#ifdef DSTAR
636                fwrite(&g_RFUpdate_data[i], 1, length, fp);
637#endif
638
639                if (i < partition_size)
640                {
641                        /*ret = */DHL_Flash_Write(partition+i, length, (DS_U8*)&data[offset+i]);
642                }
643
644                if (ret != 0) return ret;
645                       
646                if (pos != old_pos)
647                {
648                        old_pos = pos;
649                        event.data32[0] = FLASH_WRITING;
650                        event.data32[1] = pos;
651                        event.data32[2] = category;
652                        DST_SendWindowEvent(event);
653                        DST_OS_Delay(DST_OS_GetTicksPerSecond()/100);
654                }
655        }
656#ifdef DSTAR
657        fclose(fp);
658#endif 
659        return ret;
660
661}
662
663void sendFinishMessage(int status1, int status2, int category)
664{
665        SWinEventMsg event;
666        event.cmd = WM_RF_UPDATE;
667        event.data32[0] = status1;
668        event.data32[1] = status2;
669        event.data32[2] = category;
670        DST_SendWindowEvent(event);
671       
672        g_RFUpdate_data_length = 0;
673        DST_CT_CallBack(CT_FLASH_WRITE_COMPLETE,0,0,0,0,0,0);   
674}
675
676static void tFlashWrite()
677{
678        int err_ret = 0;
679        int buf_offset =0;
680        DS_U8 nBank = DHL_INFO_GetBankNumber();
681       
682        // 4KB¾¿ ¾´´Ù.
683       
684        //Çì´õ º¹»ç
685        SystemHeader systemHeader;
686        memset(&systemHeader, 0 , sizeof(SystemHeader));
687        memcpy(&systemHeader, g_RFUpdate_data, sizeof(SystemHeader));
688        DST_Printf("\n");
689        DST_Printf("systemHeader.project_id : %s \n",systemHeader.project_id);
690        DST_Printf("systemHeader.bootloader_length : 0x%08x \n",(unsigned int)systemHeader.bootloader_length);
691        DST_Printf("systemHeader.splash_length : 0x%08x \n",(unsigned int)systemHeader.splash_length);
692        DST_Printf("systemHeader.kernel_length : 0x%08x \n",(unsigned int)systemHeader.kernel_length);
693        DST_Printf("systemHeader.kernel_crc : 0x%08x \n",(unsigned int)systemHeader.kernel_crc);
694        DST_Printf("systemHeader.app_length : 0x%08x \n",(unsigned int)systemHeader.app_length);
695        DST_Printf("systemHeader.app_crc : 0x%08x \n",(unsigned int)systemHeader.app_crc);
696        DST_Printf("systemHeader.model_id : %s\n",systemHeader.model_id);
697        DST_Printf("systemHeader.hw_version_id : %s\n",systemHeader.hw_version_id);
698        DST_Printf("systemHeader.sw_version_id : %s\n",systemHeader.sw_version_id);
699        DST_Printf("systemHeader.force_update : 0x%02x \n",(unsigned int)systemHeader.force_update);
700        DST_Printf("systemHeader.force_reset : 0x%02x \n",(unsigned int)systemHeader.force_reset);
701        DST_Printf("systemHeader.image_crc : 0x%08x \n",(unsigned int)systemHeader.image_crc);         
702
703        //Total CRC check
704        buf_offset += sizeof(SystemHeader);
705        err_ret = DST_CheckCRC(systemHeader.image_crc,&g_RFUpdate_data[buf_offset],g_RFUpdate_data_length-buf_offset);
706        if(err_ret != 0)
707        {
708                sendFinishMessage(FLASH_WRITING_FAIL, CRC_READ_TOTAL_FAIL, UPDATE_BOOTLOADER);
709                return;                 
710        }
711//
712//      //Bootloader CRC check
713//      err_ret = DST_CheckCRC(systemHeader.image_crc,g_RFUpdate_data,g_RFUpdate_data_length-sizeof(SystemHeader));
714//      if(err_ret != 0)
715//      {
716//              finishWriting(FLASH_WRITING_FAIL, CRC_READ_APPLICATION_FAIL, UPDATE_BOOTLOADER);
717//              return;         
718//      }
719
720        //Bootloader Flash Writing
721        err_ret = write2Flash(FLASH_BOOT_POS, FLASH_BOOT_SIZE, systemHeader.bootloader_length, buf_offset, g_RFUpdate_data, UPDATE_BOOTLOADER);
722        if(err_ret != 0)
723        {
724                sendFinishMessage(FLASH_WRITING_FAIL, WRITE_FLASH_FAIL, UPDATE_BOOTLOADER);
725                return;         
726        }       
727       
728        //Application CRC check
729        buf_offset += systemHeader.bootloader_length + systemHeader.splash_length;
730        err_ret = DST_CheckCRC(systemHeader.kernel_crc, &g_RFUpdate_data[buf_offset], systemHeader.kernel_length);
731        if(err_ret != 0)
732        {
733                sendFinishMessage(FLASH_WRITING_FAIL, CRC_READ_APPLICATION_FAIL, nBank ? UPDATE_APPLICATION0 : UPDATE_APPLICATION1);
734                return;         
735        }
736
737
738        //Application Flash Writing
739        DS_U32 nFlashBaseAddress = nBank ? FLASH_BANK0_POS : FLASH_BANK1_POS;
740        err_ret = write2Flash(nFlashBaseAddress, FLASH_BANK_SIZE, systemHeader.kernel_length, buf_offset, g_RFUpdate_data, nBank ? UPDATE_APPLICATION0 : UPDATE_APPLICATION1);
741        if(err_ret != 0)
742        {
743                sendFinishMessage(FLASH_WRITING_FAIL, WRITE_FLASH_FAIL, nBank ? UPDATE_APPLICATION0 : UPDATE_APPLICATION1);
744                return;
745        }       
746
747//TO DO :  Flash writing CRC ºñ±³
748       
749        DHL_INFO_SetBankNumber(nBank ? 0 : 1);
750
751
752        DST_OS_Delay(DST_OS_GetTicksPerSecond()/100);
753        sendFinishMessage(FLASH_WRITING_COMPLETE,UPDATE_FINISHED,UPDATE_OK);
754}
755
756static void DST_RFUpdateWrite(char* p, int length)
757{
758        if (g_RFUpdate_data) return;
759        g_RFUpdate_data = p;
760        g_RFUpdate_data_length = length;
761        /*int taskID = */DST_OS_SpawnTask((void (*)(void *)) tFlashWrite, (char*)"tFlashWrite", APP_TASK_PRIO_RF_UPDATE_WRITE, WIN_MGR_TASK_STACKSIZE, 0);
762}
763
764static DS_U32 DST_g_BER_A = 0;
765static DS_U32 DST_g_BER_B = 0;
766static bool DST_g_vAlive = false;
767static bool DST_g_aAlive = false;
768
769void DST_GetAVAliveInfo(bool *vAlive, bool *aAlive)
770{
771        if(vAlive) *vAlive = DST_g_vAlive;
772        if(aAlive) *aAlive = DST_g_aAlive;
773}
774
775void DST_GetSignalInfo(bool *bLock, int *ss, DS_U32 *ber_a, DS_U32 *ber_b)
776{
777        DS_U8 RF = 0;
778        DST_GetAVState(&RF);
779        if (bLock) *bLock = DST_g_Lock;
780        if (ss) *ss = DST_g_SignalStrength[RF];
781        if (ber_a) *ber_a = DST_g_BER_A;
782        if (ber_b) *ber_b = DST_g_BER_B;
783}
784
785class CMemFile
786{
787private:
788        int m_nTotalSize; // ¸Þ¸ð¸® ÆÄÀÏÀÇ Àüü ±æÀÌ
789        int m_nBlockSize; // ºí·°´ç »çÀÌÁî
790        char* m_data; // ÀúÀåµÇ´Â µ¥ÀÌÅÍ
791        int m_nMaxBlockNumber; // °¡ÀåÅ« ºí·° ¹øÈ£. ºí·°¹øÈ£´Â 0¿¡¼­ ½ÃÀÛÇÑ´Ù.
792        int* m_BlockList; // ÀÌ¹Ì ¹ÞÀº µ¥ÀÌÅÍ´Â ¹ö¸®±âÀ§ÇØ ÀÌÀü¿¡ ¹ÞÀº ºí·° ¹øÈ£¸¦ ÀúÀåÇÑ´Ù.
793        int m_nReceiveCount; // ¹ÞÀº À¯È¿ÇÑ µ¥ÀÌÅÍ °¹¼ö
794public:
795        CMemFile(int nTotalSize, int nBlockSize)
796        {
797                m_nTotalSize = nTotalSize;
798                m_nBlockSize = nBlockSize;
799                m_data = (char*)malloc(nTotalSize);
800                m_nMaxBlockNumber = (nTotalSize-1) / nBlockSize;
801                m_BlockList = (int*)malloc((m_nMaxBlockNumber+1)* sizeof(int));
802                m_nReceiveCount = 0;
803        }
804        void SetBlock(int nBlockNumber, char* data, int nDataLength)
805        {
806                for (int i = 0; i < m_nReceiveCount; i++) if (m_BlockList[i] == nBlockNumber) return; // ÀÌ¹Ì ¹ÞÀº µ¥ÀÌÅÍ¸é ¹«½Ã
807                if (nBlockNumber > m_nMaxBlockNumber) return; // À߸øµÈ ºí·°¹øÈ£´Â ¹ö¸°´Ù.
808                //printf("m_nBlockSize = %d nBlockNumber = %d\n", m_nBlockSize , nBlockNumber);
809                memcpy(m_data + m_nBlockSize * nBlockNumber, data, nDataLength);
810                m_BlockList[m_nReceiveCount++] = nBlockNumber; // ºí·° ¹øÈ£¸¦ ÀúÀåÇÏ¿© ´Ù½Ã ¹Þ´Â°ÍÀ» ¹æÁö
811        }
812        // ¾ó¸¶³ª ¹Þ¾Ò´ÂÁö Ç¥±âÇϱâ À§ÇÑ ¿ëµµ
813        // Áö±Ý±îÁö ¹ÞÀº °¹¼ö / Àüü °¹¼ö 3°³Áß 2°³¸¦ ¹Þ¾Ò´Ù¸é 2/3À» ¹Ýȯ
814        // RecieveCount ¿Í TotalCount °¡ °°´Ù¸é ´Ù ¹ÞÀº°Å´Ù.
815        void GetProgress(int *RecieveCount, int *TotalCount)
816        {
817                *RecieveCount = m_nReceiveCount; 
818                *TotalCount = m_nMaxBlockNumber+1;
819        }
820        // ¼ö½ÅÇÑ µ¥ÀÌÅ͸¦ ¹ÝȯÇÑ´Ù.
821        char* GetData()
822        {
823                return m_data;
824        }
825        int GetLength()
826        {
827                return m_nTotalSize;
828        }
829        ~CMemFile()
830        {
831                free(m_data);
832                free(m_BlockList);
833        }
834};
835
836static void DST_CT_CallBack(DS_U8 Cmd, DS_U32 p1, DS_U32 p2, DS_U32 p3, DS_U32 p4, DS_U32 p5, DS_U32 p6)
837{
838        if (Cmd == CT_RECEIVE_STT)
839        {
840                //DST_SendWindowEventWithOnlyCmd(WM_RECEIVE_STT);
841                DST_SetTimeBySTT(p1, p2, p3, p4);
842        }
843       
844        switch (Cmd)
845        {
846                case CT_SIGNAL:
847                case CT_SIGNAL_INFO:
848                case CT_AV_START:
849                case CT_OTC_RECEIVE_DDB:
850                case CT_RECEIVE_RF_UPDATE:
851                        break;
852                       
853                default:
854                        {
855                                SWinEventMsg event;
856                                event.cmd = WM_CT_MSG;
857                                event.data32[0] = Cmd;
858                                event.data32[1] = p1;
859                                event.data32[2] = p2;
860                                event.data32[3] = p3;
861                                event.data32[4] = p4;   
862                                event.data32[5] = p5;           
863                                event.data32[6] = p6;
864                                DST_SendWindowEvent(event);
865                        }
866                        break;
867        }
868//      if (Cmd != CT_SIGNAL_INFO  && Cmd != CT_AV_START)
869//      {
870////            DST_Printf(">>Cmd = %s(%d) %x %x %x %x\n", CT_GetMsgName(Cmd), Cmd, (int)p1, (int)p2, (int)p3, (int)p4);
871//      }
872        static DS_U32 DST_g_WeakSignalStartTime = 0;
873        SWinEventMsg event;
874        memset(&event, 0, sizeof(SWinEventMsg));
875
876        switch (Cmd)
877        {
878                case CT_AV_INFO:
879                        //(CT_AV_INFO, RF, PcrPid, VideoPid, AudioPid, VideoType, AudioType)
880                        if(g_AV_PCR != p2 || g_AV_VideoPID != p3 || g_AV_AudioPID != p4 || g_AV_VideoType != p5 || g_AV_AudioType != p6)
881                        {
882                                DST_SetAVInfo(p2, p3, p4, p5, p6);
883                                DST_SendWindowEventWithOnlyCmd(WM_SOURCE_FORMAT_DONE);                 
884                        }
885                        break;
886
887                case CT_SIGNAL_INFO:
888                        //(CT_SIGNAL_INFO, RF, bLock, ss, ber_a, ber_b)
889                        DST_g_Lock = p2;
890                        DST_g_SignalStrength[p1] = p3;
891                        DST_g_BER_A = p4;
892                        DST_g_BER_B = p5;
893                        {
894                                bool bWeakSignal = false;
895                                if (DST_g_Lock == false) bWeakSignal = true;
896//                              if (DST_g_Demod != (DHL_MODULATION_MODE)DHL_MODULATION_8VSB && DST_g_SNR <= 25) bWeakSignal = true;
897//                              if (DST_g_Demod == (DHL_MODULATION_MODE)DHL_MODULATION_8VSB && DST_g_SNR <= 14) bWeakSignal = true;
898                                static int old_rf = 0;
899                                if (old_rf != (int)p1) // Á֯ļö°¡ º¯°æµÈ °æ¿ì´Â Weak Signal ¾Æ´Ñ °É·Î °£ÁÖ
900                                {
901                                        bWeakSignal = false;
902                                        old_rf = p1;
903                                }
904                                if (bWeakSignal == true)
905                                {
906                                        if (DST_g_WeakSignalStartTime == 0) DST_g_WeakSignalStartTime = DST_OS_GetTickCount();
907                                }       
908                                else
909                                {
910                                        DST_g_WeakSignalStartTime = 0;
911                                }
912                                if (DST_g_WeakSignalStartTime > DST_OS_GetTickCount()) DST_g_WeakSignalStartTime = DST_OS_GetTickCount();
913//                              CT_WeakSignalMute(bWeakSignal && (DST_OS_GetTickCount() - DST_g_WeakSignalStartTime) > 10*DST_OS_GetTicksPerSecond()); // 10ÃÊÀÌ»ó Weak Signal
914                        }
915
916                        break;
917
918                case  CT_SIGNAL:
919                        {
920                                //(CT_SIGNAL, RF, sourceID, VideoPid ? DHL_VID_Alive() : 0, AudioPid ? DHL_AUD_Alive() : 0)
921                                static DS_U32 nLastSendCommand = 0;
922                                static DS_U32 nLastSendTime = 0;
923                                static DS_U32 LastSourceID = 0;
924                                static DS_U32 LastRF = 0;
925                                static DS_U32 old_nCmd = SM_GOOD_SIGNAL;
926                                DS_U32 nCmd = SM_GOOD_SIGNAL;
927                                if ((nCmd == SM_GOOD_SIGNAL)&& DST_OS_GetTickCount() - DST_g_LastTuneTryTime < WAITING_PERIOD && DST_g_VideoHeightTV == 0)
928                                {
929                                        nCmd = SM_WAIT_SIGNAL;
930                                }                               
931                                if (DST_g_WeakSignalStartTime > DST_OS_GetTickCount()) DST_g_WeakSignalStartTime = DST_OS_GetTickCount();
932                                if (nCmd == SM_GOOD_SIGNAL && DST_g_WeakSignalStartTime > 0 && DST_OS_GetTickCount() - DST_g_WeakSignalStartTime > DST_OS_GetTicksPerSecond())
933                                {
934                                        nCmd = SM_WEAK_SIGNAL;
935                                }
936                                if ((nCmd == SM_GOOD_SIGNAL )&& p3 == 0 && p4 == 0 && DST_OS_GetTickCount() - DST_g_LastTuneTryTime > WAITING_PERIOD)
937                                {
938                                        nCmd = SM_NO_PROGRAM;
939                                }
940                                if (nCmd == SM_GOOD_SIGNAL && p3 == 0 && p4 != 0)
941                                {
942                                        nCmd = SM_AUDIO_ONLY;
943                                }
944                                if (nLastSendTime >  DST_OS_GetTickCount()) nLastSendTime = DST_OS_GetTickCount();
945//                              DST_Printf("LastSourceID:%d, p2:%d++++++++++++++++++++++++++++++++++++++\n",LastSourceID,p2);
946                                if(LastRF != p1 || LastSourceID != p2 ) 
947                                {
948                                        nCmd = SM_WAIT_SIGNAL;
949                                        LastRF = p1;
950                                        LastSourceID = p2;
951                                }
952
953                                if (DST_g_BadSignalStartTime > DST_OS_GetTickCount())   DST_g_BadSignalStartTime = DST_OS_GetTickCount();
954                                if(nCmd == SM_WEAK_SIGNAL || nCmd == SM_NO_PROGRAM)
955                                {
956                                        if(old_nCmd != nCmd)
957                                        {
958                                                if(!(old_nCmd == SM_WEAK_SIGNAL || old_nCmd == SM_NO_PROGRAM))
959                                                {
960                                                        DST_g_BadSignalStartTime = DST_OS_GetTickCount();
961                                                }
962                                                old_nCmd = nCmd;
963                                        }
964                                }
965                                else
966                                {
967                                        DST_g_BadSignalStartTime = 0;
968                                }
969                               
970                                if (nCmd != nLastSendCommand || DST_OS_GetTickCount() - nLastSendTime > DST_OS_GetTicksPerSecond())
971                                {
972                                        DST_g_vAlive = p3?true:false;
973                                        DST_g_aAlive = p4?true:false;
974                                        DST_g_SignalState = nCmd;
975                                        event.cmd = WM_SIGNAL_STATE;
976                                        event.data32[0] = nCmd;
977                                        DST_SendWindowEvent(event);     
978                                        nLastSendCommand = nCmd;
979                                        nLastSendTime = DST_OS_GetTickCount();
980                                       
981//                                      DST_g_OldSignalState = event.data32[0];
982//                                      if (DST_g_SignalState == SM_NO_PROGRAM) DST_g_OldSignalState = SM_NO_PROGRAM;
983//                                      DST_Printf("\n\n\nDST_g_SignalState:%d\n\n\n",DST_g_SignalState);
984                                }
985                        }               
986                        break;
987                case CT_AUDIO_MODE:
988                        g_AudioMode = (DHL_AUDIO_MODE)p1;
989                        break;
990                case CT_VIDEO_RESOLUTION:
991                        //(CT_VIDEO_RESOLUTION: nWidth, nHeight, RefreshRate, bInterlaced, Aspect)
992//                      DST_Printf("\n\nDST_SignalInfoCallBack %d %d %d\n\n", p1, p2, p3);
993                        DST_g_VideoWidthTV = (p1 < 2000 && p1 < 2000) ? p1 : 0;
994                        DST_g_VideoHeightTV = (p2 < 2000 && p2 < 2000) ? p2 : 0;
995                        DST_g_RefreshRate = p3;
996                        DST_g_bInterlace = p4 ? true: false;
997                        switch (p5)
998                        {
999                                case DHL_SOURCE_16x9:
1000                                        DST_g_Wide = true;
1001                                        break;
1002                                case DHL_SOURCE_4x3:
1003                                        DST_g_Wide = false;
1004                                        break;
1005                                default:
1006                                        if (DST_g_VideoWidthTV == 0 || DST_g_VideoHeightTV == 0) break;
1007                                        DST_g_Wide = (((DST_g_VideoWidthTV * 100) / DST_g_VideoHeightTV) > 155) ? true : false;
1008                                        break;
1009                        }
1010                        DST_SendWindowEventWithOnlyCmd(WM_SOURCE_FORMAT_DONE);
1011                        break;
1012
1013                case CT_SCAN_LOCK_WAIT:
1014                        DST_g_SignalStrength[p1] = p3;
1015                        break;
1016                       
1017                case CT_AV_START:
1018//                      if(g_AV_RF != p1 || g_AV_program_number != p2)
1019//                      {
1020//                              DST_ResetVideoSize();
1021//                              DST_CloseWin(WIN_ERROR);
1022//                      }
1023//                      g_AV_RF = p1;
1024//                      g_AV_program_number = p2;
1025//                      g_AV_source_id = p3;
1026                        break;
1027                case CT_SCAN_START:
1028                        TUNE_SCAN_STATE = CT_SCAN_START;
1029                        break;
1030                case CT_TUNE_START:
1031                        TUNE_SCAN_STATE = CT_TUNE_START;
1032                        if(g_AV_RF != p1 || g_AV_program_number != p2)
1033                        {
1034                                DST_ResetVideoSize();
1035                                DST_CloseWin(WIN_ERROR);
1036                        }
1037                        g_AV_RF = p1;
1038                        g_AV_program_number = p2;
1039                        g_AV_source_id = p3;
1040                        DST_Printf("\n\n\n");
1041                        DST_Printf("CT_TUNE_START %d %d %d\n", g_AV_RF, g_AV_program_number, g_AV_source_id);
1042                        DST_Printf("\n\n\n");
1043                        break;
1044                case CT_STOPPED:
1045                        TUNE_SCAN_STATE = CT_STOPPED;
1046                        break;
1047                case CT_OTC_START:
1048                        DST_g_bOTCMode = true;
1049//                      DST_SendWindowProgressEvent(WM_OTC_DOWNLOADING_STARTED);
1050                        break;
1051        }
1052       
1053        // OTC °ü·Ã ó¸®
1054        static CMemFile *mf = 0;
1055        static bool bOTC_Receive_Complete = true;
1056        switch (Cmd)
1057        {
1058                case CT_OTC_RECEIVE_DII:
1059                        if (mf) delete mf;
1060                        mf = new CMemFile(p1, p2);
1061                        bOTC_Receive_Complete = false; 
1062                        break;
1063                       
1064                case CT_OTC_RECEIVE_DDB:
1065                        {
1066                                if (bOTC_Receive_Complete) break;
1067                                mf->SetBlock(p1, (char*)p2, p3);
1068                                int nReceiveCount = 0;
1069                                int nMaxBlockNumber = 0;
1070                                mf->GetProgress(&nReceiveCount, &nMaxBlockNumber);
1071                                SWinEventMsg event;
1072                                memset(&event, 0, sizeof(SWinEventMsg));
1073                                event.cmd = WM_RF_UPDATE;
1074                                if (nReceiveCount == nMaxBlockNumber)
1075                                {
1076                                        bOTC_Receive_Complete = true;
1077                                        event.data32[0] = DATA_RECEIVING_COMPLETE; // ¼ö½Å ¿Ï·á
1078                                        DST_SendWindowEvent(event);
1079                                        JST_Stop();
1080                                        DST_CreateWin(WIN_UPDATE);
1081                                        DST_RFUpdateWrite(mf->GetData(), mf->GetLength());
1082                                }
1083                                else
1084                                {
1085                                        static int old_pos = -1;
1086                                        int pos =  (nReceiveCount - 1) * 100 / nMaxBlockNumber;
1087                                        event.data32[0] = DATA_RECEIVING; // ¼ö½ÅÁß
1088                                        event.data32[1] = pos;
1089                                        if (old_pos != pos) 
1090                                        {
1091                                                DST_SendWindowEvent(event);
1092                                                old_pos = pos;
1093                                        }
1094                                }
1095                        }
1096                        break;
1097                case CT_FLASH_WRITE_COMPLETE:
1098                        if (mf) delete mf;
1099                        mf = 0;
1100                        T();DST_Printf("CT_FLASH_WRITE_COMPLETE\n");
1101                        bOTC_Receive_Complete = true;
1102                        break;
1103
1104                case CT_RF_UPDATE_START:
1105                        bOTC_Receive_Complete = false; 
1106                        break;
1107                       
1108                case CT_RECEIVE_RF_UPDATE:
1109                        {
1110                                if (bOTC_Receive_Complete == true) break;
1111                                char *p = (char*)p2;
1112                                char *strModelName = &p[3]; //Á¦Ç°¸ðµ¨¸í
1113                                char *strVersionName = &p[13]; // S/W ¹öÀü
1114                                char *strFileSize = &p[21]; // Àüü ÆÄÀÏ ±æÀÌ
1115//                              char *strPosition = &p[29]; // µ¥ÀÌÅÍÀÇ ½ÃÀÛ À§Ä¡
1116                                char *strLength = &p[37]; // µ¥ÀÌÅÍÀÇ ±æÀÌ
1117                                char *strMaxBlockNumber = &p[45]; // ¸¶Áö¸· ºí·° ¹øÈ£
1118                                char *strBlockNumber = &p[53]; // ¸î¹øÂ° ºí·°ÀÎÁö 0ºÎÅÍ ½ÃÀÛ
1119                                char *pSrc = &p[61];
1120                               
1121                                int nFileSize = atoi(strFileSize);
1122//                              int nPosition = atoi(strPosition);
1123                                int nLength = atoi(strLength);
1124                                int nMaxBlockNumber = atoi(strMaxBlockNumber);
1125                                int nBlockNumber = atoi(strBlockNumber);
1126                       
1127                                // Å×½ºÆ® ºñ±³ Á¶°ÇÀÓ È®ÀÎ ÈÄ ¼öÁ¤ ÇÊ¿ä
1128                                static char* pData = 0;
1129                                static int*   pLength = 0;
1130                               
1131                                SWinEventMsg event;
1132                                event.cmd = WM_RF_UPDATE;
1133                                memcpy(&event.data32[2], strVersionName, 8);
1134                                       
1135                                if (strcmp(strModelName, DST_GetModelName()) != 0)
1136                                {
1137                                        T();
1138                                        DST_Printf("%s %s\n", strModelName, DST_GetModelName());
1139                                        bOTC_Receive_Complete = true;
1140                                        JST_Stop();
1141                                        if (pData) DST_OS_Free(&pData);
1142                                        if (pLength) DST_OS_Free(&pLength);
1143                                        event.data32[0] = 100; // ´Ù¸¥ ¸ðµ¨ÀÓ
1144                                        DST_SendWindowEvent(event);
1145                                        break;
1146                                }
1147                                if (strcmp(strVersionName, DST_GetAppShortVersion()) == 0)
1148                                {
1149                                        T();
1150                                        bOTC_Receive_Complete = true;
1151                                        JST_Stop();
1152                                        if (pData) DST_OS_Free(&pData);
1153                                        if (pLength) DST_OS_Free(&pLength);
1154                                        event.data32[0] = 101; // °°Àº ¹öÀüÀÓ
1155                                        DST_SendWindowEvent(event);
1156                                        break;
1157                                }
1158                               
1159                                if (mf == 0) // óÀ½ ¹Þ´Â °æ¿ì
1160                                {
1161                                        bOTC_Receive_Complete = false;
1162                                        mf = new CMemFile(nFileSize, nLength);
1163                                }
1164                                mf->SetBlock(nBlockNumber, pSrc, nLength);
1165                               
1166                                int nReceiveCount = 0;
1167                                nMaxBlockNumber = 0;
1168                                mf->GetProgress(&nReceiveCount, &nMaxBlockNumber);
1169                                //SWinEventMsg event;
1170                                memset(&event, 0, sizeof(SWinEventMsg));
1171                                event.cmd = WM_RF_UPDATE;
1172                                if (nReceiveCount == nMaxBlockNumber)
1173                                {
1174                                        bOTC_Receive_Complete = true;
1175                                        event.data32[0] = DATA_RECEIVING_COMPLETE; // ¼ö½Å ¿Ï·á
1176                                        DST_SendWindowEvent(event);
1177                                        JST_Stop();
1178                                        DST_RFUpdateWrite(mf->GetData(), mf->GetLength());
1179                                }
1180                                else
1181                                {
1182                                        static int old_pos = -1;
1183                                        int pos =  (nReceiveCount - 1) * 100 / nMaxBlockNumber;
1184                                        event.data32[0] = DATA_RECEIVING; // ¼ö½ÅÁß
1185                                        event.data32[1] = pos;
1186                                        if (old_pos != pos) 
1187                                        {
1188                                                DST_SendWindowEvent(event);
1189                                                old_pos = pos;
1190                                        }
1191                                }
1192                        }
1193                        break;
1194        }
1195}
Note: See TracBrowser for help on using the repository browser.