source: svn/newcon3bcm2_21bu/dst/app/src/Function/App_Fnc_EA.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 31.4 KB
Line 
1/****************************************************************************
2* NAME: App_Fnc_EA.c
3*----------------------------------------------------------------------------
4* Copyright (c) DIGITAL STREAM Technology Inc.
5*----------------------------------------------------------------------------
6* CREATED_BY: Do Gon Lee
7* CREATION_DATE: 2009/08/25
8* $Author: foxhunt $
9* $Revision: 1.0 $
10* $Date: 2009/08/25 16:20:41 $
11*----------------------------------------------------------------------------
12* PURPOSE:
13* -
14*****************************************************************************/
15
16/*_____ I N C L U D E __________________________________________*/
17
18#define INCLUDE_EA_DDI
19
20#include "App_Main.h"
21
22#if SUPPORT_EA
23
24#include "App_Fnc_Common.h"
25
26#include "DHL_Bitbuffer.h"
27#include "DHL_PsiAPI.h"
28
29#include "DMW_Status.h"
30
31#include "App_Fnc_ChTune.h"
32#include "App_Fnc_EA.h"
33
34
35
36
37
38/*_____ D E F I N I T I O N ____________________________________*/
39
40#if COMMENT
41____DbgPrint____(){}
42#endif
43
44DHL_MODULE("@f_ea", 0);
45
46
47
48
49
50#if COMMENT
51____Config____(){}
52#endif
53
54#define EA_DELAYED_MONITOR 1
55        /* ch tuning ÈÄ ¹Ù·Î monitoringÀ» ÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó, Á» ½¬¾ú´Ù ÇÔ.
56                 ¾ø¾îÁ®µµ µÉ µí Çϳª, ±âÁ¸ ±¸Çö ¹æ½Ä´ë·Î Çϱâ·Î ÇÔ. */
57
58#define EA_CHECK_STORED_EA_EVENT 1
59        /* Å×½ºÆ®¸¦ À§Çؼ­´Â 0À¸·Î ¼³Á¤ÇÏ´Â °ÍÀÌ ÁÁÀ½. */
60       
61#define EA_TEST_DENY_SEQ_CHECK 0
62        /* Å×½ºÆ® ¿ëµµ·Î sequeuce number check¸¦ ¹«½ÃÇÔ */
63
64#define EA_TEST_DENY_PRIO 0
65        /* Å×½ºÆ®¸¦ À§ÇÑ ¿ëµµ·Î PRIO¿¡ »ó°ü¾øÀÌ ¹«Á¶°Ç ó¸® */
66       
67#define EA_SCROLL_SPEED_PRIOR 0
68  /* scroll speed ¿ì¼± 0À̸é scroll ¼Óµµ´Â ´À·Áµµ ¾ÈÁ¤¼º ¿ì¼±ÇÔ. */
69
70
71#define TASK_EA_PRIORITY TASK_PRI_EA
72#define EA_TASK_STK_SIZE 16384
73#define MAX_EA_MSGQ 32
74
75#define SCROLL_SLICE 8                                  /* ÇÑ ¹ø updateµÉ ¶§¸¶´Ù À̵¿ÇÏ´Â pixel Å©±â */
76#define SCROLL_UPDATE_DELAY 80  /* ms´ÜÀ§       */
77#define CHTUNE_CHECK_DELAY 1000 /* 1ÃÊ ´ÜÀ§ */
78
79#define MAX_STORED_EVENT 10
80
81#define INDEF_DURATION 1                                /* 1ºÐ. durationÀÌ 0À¸·Î ¼³Á¤µÇ¾îÀÖÀ» ¶§ default */
82#define INDEF_TIME_REMAIN 10            /* 10ÃÊ. time remainingÀÌ 0À¸·Î ¼³Á¤µÇ¾îÀÖÀ» ¶§ default */
83
84
85/* graphic.. 960,540 planeÀ» ±âÁØÀ¸·Î ÇÔ. */
86#define EA_MAIN_X 0
87#if APP_PORTING
88#define EA_MAIN_Y 380
89#define EA_MAIN_W 960
90#else // trinity´Â 720x480 À̹ǷÎ
91#define EA_MAIN_Y 320
92#define EA_MAIN_W 720
93#endif // #if APP_PORTING
94#define EA_MAIN_H 60
95
96/* MAIN ±âÁØ ÁÂÇ¥ÀÓ */
97#define SCROLL_R_X 60
98#define SCROLL_R_Y 10
99#define SCROLL_R_W 840
100#define SCROLL_R_H 40
101
102#define EA_BG_COLOR 9
103#define EA_TEXT_COLOR 7
104
105
106#define EA_FONT_SIZE_240 13
107#define EA_FONT_SIZE_480 26
108
109#define TICK_CUR OS_GetTickCount()
110#define TICK_PASS(st) (TICK_CUR-st)
111#define TICK_1SEC OS_GetTicksPerSecond()
112
113#define INFO(i) p_ea_info.i
114#define EVENT(i) p_ea_info.p_cur_event->i
115#define STORED(i) p_ea_info.stored_event_list[i]
116
117#define EA_NOW_WORKING (INFO(b_now_scrolling) || INFO(b_now_ch_tuning))
118
119
120
121
122
123#if COMMENT
124____Types____(){}
125#endif
126
127typedef struct {
128        UINT8 state;
129        UINT8 countrySub;
130        UINT16 countryCode;
131} LocCode;
132
133typedef struct {
134        BOOL bInband;
135        UINT16 attr1;   /* bInband¿¡ µû¶ó major/reserved */
136        UINT16 attr2;   /* bInband¿¡ µû¶ó minor/exception OOB */
137} ExceptionInfo;
138
139typedef struct {
140        UINT16 eventId;
141        char pOrigCode[3];
142        UINT8 eventCodeLen;
143        char *pEventCode;
144        UINT8 natureActivTextLen;
145        char *pNatureActivText;
146        UINT8 timeRemaining;
147        UINT32 startTime;
148        UINT16 duration;
149        UINT8 priority;
150        UINT16 detailSrcId;
151        UINT16 detailMajor;
152        UINT16 detailMinor;
153        UINT16 audioSrcId;
154        UINT16 alertTextLen;
155        char *pAlertText;
156        UINT8 locCodeCnt;
157        LocCode *pLocCode;
158        UINT8 exceptionCnt;
159        ExceptionInfo *pException;
160        UINT8 descLen;
161        char *pDescriptors;
162} EA_EVENT;
163
164typedef struct {
165        UINT32  eaEventId;
166        UINT32  endTime;
167        UINT16  alertTextLen;
168        UINT8   priority;
169} EA_StoredEvent;
170
171
172typedef struct {
173        UINT8 cmd;
174        UINT8 opt;
175        UINT32 param1;
176        UINT32 param2;
177} EA_CMD;
178
179
180static struct {
181        UINT8 osd_resolution;
182       
183        BOOL b_medium_on;
184        BOOL b_low_on;
185       
186        BOOL b_now_monitoring;          /* ea monitoring */
187       
188        BOOL b_now_scrolling;
189        BOOL b_now_ch_tuning;
190        BOOL b_scroll_pause;                    /* scrollingÀÇ Áß´Ü ¿©ºÎ.        */
191       
192        UINT32 event_start_tick;
193        UINT32 scroll_prev_tick;        /* ÀÌ Àü ½ÇÇà tick */
194       
195        UINT16 ch_b_major;
196        UINT16 ch_b_minor;
197       
198        EA_EVENT *p_cur_event;
199        EA_StoredEvent stored_event_list[MAX_STORED_EVENT];
200       
201} p_ea_info;
202
203/* define nvparam strunct */
204struct nvparam_ea nvp_ea;
205
206
207
208
209
210#if COMMENT
211____Variables____(){}
212#endif
213
214static struct {
215        UINT8 prio;
216} p_ea_nvm_param;
217
218
219
220static PSIControl *p_psi_ctrl;
221static DHL_OS_MSGQ_ID p_ea_msgq;
222
223static void p_send_msg(UINT8 cmd, UINT8 opt, UINT32 param1, UINT32 param2);
224
225
226
227
228
229/*_____ F U N C T I O N ________________________________________*/
230
231#if 0
232__MONITORING_PARSING__(){}
233#endif
234
235/******************************************************************************************
236FUNCTION:
237  - p_ea_print_info
238
239Purpose:
240  - EA information print function
241******************************************************************************************/
242static void p_ea_print_info(EA_EVENT *event)
243{
244        UINT16 *pAlertText, alertTextLen;
245       
246        if(!event) return;
247        dprint(1, "EA Section Info..cur time(%d)\n", OS_GetTickCount()/OS_GetTicksPerSecond());
248        dprint(1, "==========================================\n");
249        dprint(1, "  event id %d\n", event->eventId);
250        dprint(1, "  time remaining %d\n", event->timeRemaining);
251        dprint(1, "  start time %d\n", event->startTime);
252        dprint(1, "  duration %d\n", event->duration);
253        dprint(1, "  priority %d\n", event->priority);
254        dprint(1, "  detail src id %d\n", event->detailSrcId);
255        dprint(1, "  detail major %d\n", event->detailMajor);
256        dprint(1, "  detail minor %d\n", event->detailMinor);
257        dprint(1, "  audio src %d\n", event->audioSrcId);
258        dprint(1, "  alert text len %d\n", event->alertTextLen);
259       
260        if (event->alertTextLen> 6) {
261                pAlertText=(UINT16 *)OS_Malloc((event->alertTextLen+1)*sizeof(UINT16));
262                alertTextLen=DLIB_PSI_DecodeMultipleStringStructure(event->alertTextLen,
263                                                                                                                        (UINT8 *)event->pAlertText, "eng", 
264                                                                                                                        event->alertTextLen, 
265                                                                                                                        pAlertText);
266                pAlertText[alertTextLen]=0;
267       
268                dprint(1, "  alert text         : [%s]\n", DMW_Unicode2Ks(pAlertText, -1, NULL));
269                OS_Free(&pAlertText);
270        }
271        dprint(1, "==========================================\n");
272}
273
274
275/******************************************************************************************
276FUNCTION:
277  - p_release_ea_event
278
279Purpose:
280  -
281******************************************************************************************/
282static void p_release_ea_event(EA_EVENT **ppevent)
283{
284        if(!ppevent)
285                return;
286
287        if((*ppevent)->pEventCode)
288                OS_Free((void **)&(*ppevent)->pEventCode);
289        if((*ppevent)->pNatureActivText)
290                OS_Free((void **)&(*ppevent)->pNatureActivText);
291        if((*ppevent)->pAlertText)
292                OS_Free((void **)&(*ppevent)->pAlertText);
293        if((*ppevent)->pException)
294                OS_Free((void **)&(*ppevent)->pException);
295        if((*ppevent)->pDescriptors)
296                OS_Free((void **)&(*ppevent)->pDescriptors);
297
298        OS_Free((void **)ppevent);
299}
300
301
302/******************************************************************************************
303FUNCTION:
304  - p_parse_ea_event
305
306Purpose:
307  -
308******************************************************************************************/
309static ErrCode p_parse_ea_event(UINT8 *psect_data, EA_EVENT **ppevent)
310{
311        bitBufferPtr_t bits = NULL;
312        ErrCode err = noError;
313        UINT16 sect_len;
314        EA_EVENT *pevent=NULL;
315        UINT32 temp;
316        int i;
317        static int prev_seq_num=-1;
318
319        if (get_section_syntax_indicator(psect_data) == 0) {
320                dprint(1, "[MW CEA] section_syntax_indicator not set\n");
321        }
322       
323        if((sect_len=get_section_length(psect_data)) > 4093) {
324                dprint(1, "[MW CEA] section_length=%d\n", (int)sect_len);
325                err=DHL_FAIL_BAD_FORMAT;
326                goto ParseExit;
327        }
328       
329        if ((err = bitBufferCreate(&bits,psect_data+3,sect_len))) {
330                err=DHL_FAIL_BAD_FORMAT;        /* ÀÏ´Ü general warning ó¸®ÇÔ. */
331                goto ParseExit;
332        }
333
334        pevent = (EA_EVENT *)(OS_Calloc(sizeof(EA_EVENT), 1));
335       
336        /* table_id_extension */
337        if (bitBufferGetBits(bits,16) != 0x0000) {
338                dprint(1, "[MW CEA] table_id_extension != 0x0000\n");
339        }
340       
341        bitBufferGetBits(bits,2);
342
343
344        if((temp=bitBufferGetBits(bits,5))==prev_seq_num) {     /* sequence numÀÌ °°¾ÒÀ¸¹Ç·Î Ãë¼Ò */
345#if !EA_TEST_DENY_SEQ_CHECK
346                dprint(1, "[MW CEA] EA Msg Incoming, BUT CANCELED because Seq # is equal to prev seq #\n");
347                err=DHL_FAIL;   /* ÀÏ´Ü general warning ó¸®ÇÔ. */
348                goto ParseExit;
349#endif
350        }
351       
352        /* current next indicator : Ç×»ó 1 */
353        if (bitBufferGetBits(bits,1) != 1) { 
354                dprint(1, "[MW CEA] current_next_indicator != 1\n");
355        }
356       
357        /* section number : Ç×»ó 0x00 */
358        if (bitBufferGetBits(bits,8) != 0x00) {
359                dprint(1, "[MW CEA] section_number != 0x00\n");
360        }
361       
362        /* last section number : Ç×»ó 0x00 */
363        if (bitBufferGetBits(bits,8) != 0x00) {
364                dprint(1, "[MW CEA] section_number != 0x00\n");
365        }
366       
367        /* protocol version ¹Ýµå½Ã 0À̾î¾ß ÇÔ. */
368        if(bitBufferGetBits(bits,8) != 0x00) {
369                err=DHL_FAIL;
370                goto ParseExit;
371        }
372       
373        prev_seq_num=temp;
374       
375        /*
376                event id´Â 1)ÇöÀç ÁøÇàÁßÀÎ EAÀÇ event ID¿Í °°´Ù¸é, remaining time Á¶Àý ¸ñÀû
377                2) ÁøÇàÀÌ ³¡³µ°í, start, duration time¾È¿¡ ÀÖ´Ù¸é ¹«½ÃÇÑ´Ù.
378                1), 2)ÀÇ »óȲÀ» MW°¡ ¾Ë ¼ö ¾ø±â ¶§¹®¿¡ App¿¡¼­ ó¸®ÇÑ´Ù.
379        */
380        pevent->eventId=bitBufferGetBits(bits,16);
381        pevent->pOrigCode[0] = bitBufferGetBits(bits,8);
382        pevent->pOrigCode[1] = bitBufferGetBits(bits,8);
383        pevent->pOrigCode[2] = bitBufferGetBits(bits,8);
384       
385        pevent->eventCodeLen=bitBufferGetBits(bits,8);
386        if(pevent->eventCodeLen != 0) {
387
388                pevent->pEventCode
389                        =(char *)OS_Malloc((pevent->eventCodeLen+1)*sizeof(char));
390               
391                for( i = 0 ; i < pevent->eventCodeLen ; i++ ) { /*EAS_event_code*/
392                        pevent->pEventCode[i] = bitBufferGetBits(bits,8);
393                }
394        }
395       
396        pevent->natureActivTextLen=bitBufferGetBits(bits,8);
397        if(pevent->natureActivTextLen != 0) {
398
399                pevent->pNatureActivText
400                        =(char *)OS_Malloc((pevent->natureActivTextLen+1)*sizeof(char));
401               
402                for( i = 0 ; i < pevent->natureActivTextLen ; i++ ) {   /*EAS_event_code*/
403                        pevent->pNatureActivText[i] = bitBufferGetBits(bits,8);
404                }
405        }       
406       
407        pevent->timeRemaining = bitBufferGetBits(bits,8);
408       
409        pevent->startTime=bitBufferGetBits(bits, 32);
410        pevent->duration=bitBufferGetBits(bits, 16);
411       
412        bitBufferGetBits(bits,12);
413       
414        pevent->priority=bitBufferGetBits(bits, 4);
415       
416        pevent->detailSrcId=bitBufferGetBits(bits, 16);
417        bitBufferGetBits(bits,6);
418        pevent->detailMajor=bitBufferGetBits(bits, 10);
419        bitBufferGetBits(bits,6);
420        pevent->detailMinor=bitBufferGetBits(bits, 10);
421        pevent->audioSrcId=bitBufferGetBits(bits, 16);
422       
423        pevent->alertTextLen=bitBufferGetBits(bits,16);
424        if(pevent->alertTextLen != 0) {
425
426                pevent->pAlertText
427                        =(char *)OS_Malloc((pevent->alertTextLen+1)*sizeof(char));
428               
429                for( i = 0 ; i < pevent->alertTextLen ; i++ ) {/*EAS_event_code*/
430                        pevent->pAlertText[i] = bitBufferGetBits(bits,8);
431                }
432        }
433       
434        pevent->locCodeCnt=bitBufferGetBits(bits,8);
435        if(pevent->locCodeCnt != 0) {
436
437                pevent->pLocCode
438                        =(LocCode *)OS_Malloc(pevent->locCodeCnt*sizeof(LocCode));
439               
440                for( i = 0 ; i < pevent->locCodeCnt ; i++ ) {
441                        pevent->pLocCode[i].state=bitBufferGetBits(bits,8);
442                        pevent->pLocCode[i].countrySub=bitBufferGetBits(bits,4);
443                        bitBufferGetBits(bits,2);
444                        pevent->pLocCode[i].countryCode=bitBufferGetBits(bits,10);
445
446                }
447        }
448       
449        pevent->exceptionCnt=bitBufferGetBits(bits,8);
450        if(pevent->exceptionCnt != 0) {
451
452                pevent->pException
453                        =(ExceptionInfo *)OS_Malloc(pevent->exceptionCnt*sizeof(ExceptionInfo));
454       
455                for( i = 0 ; i < pevent->exceptionCnt ; i++ ) {
456                        pevent->pException[i].bInband=bitBufferGetBits(bits, 1);
457                        bitBufferGetBits(bits, 7);
458                        if(pevent->pException[i].bInband) {
459                                bitBufferGetBits(bits, 6);
460                                pevent->pException[i].attr1=bitBufferGetBits(bits,10);
461                                bitBufferGetBits(bits, 6);
462                                pevent->pException[i].attr2=bitBufferGetBits(bits,10);
463                        }
464                        else {
465                                bitBufferGetBits(bits, 16);
466                                pevent->pException[i].attr1=0;
467                                pevent->pException[i].attr2=bitBufferGetBits(bits, 16);
468                        }
469                }
470        }
471       
472        bitBufferGetBits(bits, 6);
473        pevent->descLen=bitBufferGetBits(bits, 10);
474       
475        if(pevent->descLen != 0) {
476
477                pevent->pDescriptors
478                        =(char *)OS_Malloc((pevent->descLen+1)*sizeof(char));
479               
480                for( i = 0 ; i < pevent->descLen ; i++ ) {
481                        pevent->pDescriptors[i]=bitBufferGetBits(bits, 8);
482                }
483        }
484       
485ParseExit :
486        if (bits) {
487                /* clean up the bitBuffer */
488                bitBufferDestroy(bits);
489        }
490       
491        *ppevent=pevent;
492       
493        return err;
494}
495
496
497/******************************************************************************************
498FUNCTION:
499  - p_ea_event_proc
500
501Purpose:
502  -
503******************************************************************************************/
504static void p_ea_event_proc(PSIEvent event, PSIControl *psiCtl, UINT32 userParam)
505{
506        PSIDataArray *pDesc;
507        ErrCode err;
508        EA_EVENT *pea_event;
509
510        /* dprint(1, "in the easSyncEventProc....\n"); */
511        switch (event) {
512                case psiDataReceived:
513                        err = ReadPSIData(p_psi_ctrl, &pDesc);  /*desc¸¦ »ç¿ëÇϰí ÇØÁ¦ÇؾßÇÔ. */
514                        if(!err) {
515                                /* desc¸¦ parsingÇϰí, queue¿¡ Áý¾î³Ö´Â ÄÚµå... */
516                                err=p_parse_ea_event(pDesc->sectPtr[0], &pea_event);
517                                if(!err) p_send_msg(EACMD_RECEIVE, 0, (UINT32)pea_event, 0);
518                        }
519                        if(pDesc)
520                                FreePSIData(pDesc);
521                        break;
522                       
523                case psiScrambledErr:
524                        break;
525                       
526                default:
527                        break;
528        }
529}
530
531
532
533
534
535#if 0
536__CH_TUNING_FUNC__()
537#endif
538
539/******************************************************************************************
540FUNCTION:
541  - p_ea_restore_ch
542
543Purpose:
544  -
545******************************************************************************************/
546static void p_ea_restore_ch()
547{
548        if(INFO(ch_b_major)==0 && INFO(ch_b_minor)==0) return;
549               
550        EADDI_ChTune(INFO(ch_b_major), INFO(ch_b_minor));
551        INFO(ch_b_major)=0;
552        INFO(ch_b_minor)=0;
553}
554
555
556
557
558
559#if 0
560__SCROLLING_FUNC__()
561#endif
562
563
564
565#define TEXT_WIDTH 26 /* Á¡°Ë ÇÊ¿ä */
566#define TEXT_NUM_IN_LINE 34
567
568static UINT16 p_scroll_text[1024];
569static int p_scroll_idx;
570static int p_scroll_len;
571
572
573static UINT16 p_resolution_table[EA_R_NUM][2]=
574{
575        {960,540}, {720, 480}, {1280, 720}, {1920, 1280}, {360, 240}
576};
577
578#define RESZX(x) (x)*p_resolution_table[INFO(osd_resolution)][0]/p_resolution_table[0][0]
579#define RESZY(y) (y)*p_resolution_table[INFO(osd_resolution)][1]/p_resolution_table[0][1]
580
581
582static void p_ea_draw_main()
583{
584        dprint(1, "p_ea_draw_main [%d,%d,%d,%d]\n", 
585                RESZX(EA_MAIN_X), RESZY(EA_MAIN_Y), RESZX(EA_MAIN_W), RESZY(EA_MAIN_H), EA_BG_COLOR);
586        EADDI_FillRect(RESZX(EA_MAIN_X), RESZY(EA_MAIN_Y), RESZX(EA_MAIN_W), RESZY(EA_MAIN_H), EA_BG_COLOR);
587        EADDI_Refresh();
588}
589
590
591static void p_ea_erase_main()
592{
593        EADDI_FillRect(RESZX(EA_MAIN_X), RESZY(EA_MAIN_Y), RESZX(EA_MAIN_W), RESZY(EA_MAIN_H), 0);
594        EADDI_Refresh();
595}
596
597
598/******************************************************************************************
599FUNCTION:
600  - p_ea_scroll_start
601
602Purpose:
603  -
604******************************************************************************************/
605
606
607
608static void p_ea_scroll_start()
609{
610        p_ea_draw_main();
611       
612        p_scroll_len=DMW_Decode_MultipleStringStructure(EVENT(alertTextLen)
613                ,(UINT8 *)EVENT(pAlertText), "eng", EVENT(alertTextLen), p_scroll_text);
614        p_scroll_text[p_scroll_len]=0;
615       
616        p_scroll_idx=0;
617}
618
619
620/******************************************************************************************
621FUNCTION:
622  - p_ea_scroll_stop
623
624Purpose:
625  -
626******************************************************************************************/
627static void p_ea_scroll_stop()
628{
629
630}
631
632static void p_ea_scroll_pause()
633{
634        p_ea_erase_main();
635}
636
637
638/******************************************************************************************
639FUNCTION:
640  - p_ea_scroll_update
641
642Purpose:
643  -
644******************************************************************************************/
645static void p_ea_scroll_update()
646{
647        UINT16 temp[TEXT_NUM_IN_LINE+1];
648        int i;
649       
650        for(i=0; i<TEXT_NUM_IN_LINE; i++) {
651               
652                if(p_scroll_idx+i+TEXT_NUM_IN_LINE>=p_scroll_len) break;
653                       
654                temp[i]=p_scroll_text[p_scroll_idx+i];
655        }
656        temp[TEXT_NUM_IN_LINE]=0;
657       
658       
659        switch(INFO(osd_resolution)) {
660                case EA_R_240 :
661                        EADDI_SetFontSize(EA_FONT_SIZE_240);
662                        break;
663               
664                case EA_R_480 :
665                        EADDI_SetFontSize(EA_FONT_SIZE_480);
666                        break;
667                       
668                default :
669                        EADDI_SetFontSize(EA_FONT_SIZE_480);
670        }
671       
672       
673        EADDI_UPrint(RESZX(EA_MAIN_X)+RESZX(SCROLL_R_X), RESZY(EA_MAIN_Y)+RESZY(SCROLL_R_Y), 
674                temp, EA_TEXT_COLOR);
675       
676        EADDI_Refresh();
677}
678
679
680static BOOL p_ea_scroll_remaining()
681{
682        return (p_scroll_idx+i+TEXT_NUM_IN_LINE<p_scroll_len);
683}
684
685
686
687
688
689#if 0
690__EA_EVENT__()
691#endif
692
693/******************************************************************************************
694FUNCTION:
695  - p_ea_check_event
696
697Purpose:
698  -
699******************************************************************************************/
700static BOOL p_ea_check_event(EA_EVENT *event)
701{
702        int i;
703        int ch_mj=0, ch_mn=0, ch_rf=0;
704        UINT32 cur_time=EADDI_GetCurTime();
705       
706        p_ea_print_info(event);
707       
708        /* expiredµÈ event°¡ ÀÖ´Ù¸é Áö¿î´Ù. */
709        for(i=0; i<MAX_STORED_EVENT; i++) {
710                if(STORED(i).eaEventId != 255) {
711                        if(STORED(i).endTime < cur_time) {
712                                STORED(i).eaEventId=255;
713                        }
714                }
715        }
716
717#if EA_CHECK_STORED_EA_EVENT    /* Å×½ºÆ® Áß ¸·¾Æ³õÀ½. */
718        /* 1. regd eventÁß °°Àº event id°¡ ÀÖ´ÂÁö È®ÀÎÇÑ´Ù.
719                 event ID¿Í  */
720        for(i=0; i<MAX_STORED_EVENT; i++) {
721                if((STORED(i).eaEventId == event->eventId) &&
722                        STORED(i).alertTextLen == event->alertTextLen && 
723                        STORED(i).priority == event->priority) { /* ½ÇÆÐ.. */
724                        dprint(1, "same event id is detected..\n");
725                        goto EaEventDeny;
726                }
727        }
728#endif
729
730        /* exception list¿¡ ÇöÀç ä³ÎÀÌ ÀÖ´ÂÁö ¾ø´ÂÁö¸¦ ÆÇ´ÜÇÑ´Ù. */
731        EADDI_GetCh(&ch_mj, &ch_mn, &ch_rf);
732       
733        for(i=0; i < event->exceptionCnt ; i++) {
734                if(event->pException[i].bInband) {
735                       
736                       
737                        UINT32 major=event->pException[i].attr1;
738                        UINT32 minor=event->pException[i].attr2;
739                       
740                        if(IsOnePartChannelNumber(major)) {
741                                major = ConvertToOnePartChannelNumber(major, minor);
742                                minor = ONE_PART_CHANNEL_INDICATOR;
743                        }
744                       
745                        dprint(1, "EA_MAJOR(%d), major(%d),,,EA_MINOR(%d), minor(%d)\n", 
746                                ch_mj, major, ch_mn, minor);
747                       
748                        if(ch_mj == major && ch_mn == minor) {  /* ÇöÀç ä³ÎÀÌ exception ä³ÎÀÎ °æ¿ì */
749                                dprint(1, "EA Event Check Fails..Exception Channel\n");
750                                goto EaEventDeny;
751                        }
752                       
753                        /* ¾Æ·¡ ÄÚµå´Â ¹¹·¡? Àß ¸ð¸£°ÚÀ½. */
754                        if (ch_mj == 0 && major == ch_rf && minor == ch_mn) {
755                                dprint(1, "EA Event Check Fails..Exception Channel\n");
756                                goto EaEventDeny;
757                        }
758                }
759                else { 
760                        /* TODO : oob¿¡ ´ëÇØ¼­´Â...³ªÁß¿¡ ±¸ÇöÇÑ´Ù. */
761                }
762        }
763
764
765#if !EA_TEST_DENY_PRIO 
766        /* ALERT PRIORITY üũ */
767        if(event->priority == 0) {      /* ´Ü¼ø Å×½ºÆ®¿ë */
768                goto EaEventDeny;
769        }
770        else if(event->priority <= 3) { /* Low Priority */
771                if(!INFO(b_low_on)) goto EaEventDeny;
772        }
773        else if(event->priority <= 7) { /* Medium Priority */
774                if(!INFO(b_medium_on)) goto EaEventDeny;
775        }       
776#endif
777
778        /* modify¸¦ ÇØ ÁÖÀÚ.. */
779        if(event->timeRemaining==0)     /* Á¤Çϱ⠳ª¸§.. */
780                event->timeRemaining=INDEF_TIME_REMAIN;
781       
782        if(event->duration==0)
783                event->duration=INDEF_DURATION*60;
784               
785        if(EA_NOW_WORKING) {
786                /* Comment : Event°¡ °ãÄ¥ °æ¿ì, ´Ù¸¥ Á¾·ùÀÇ EventÀÏ ¼ö ÀÖ´Ù.
787                         ex) Force Tuning & Scroll
788                         a. time remainingÀ» ¿¬Àå
789                         b. & ´Ù¸¥ Á¾·ùÀÇ EventÀÏ °æ¿ì, Á¤º¸¸¦ Ãß°¡ÇÑ´Ù. */
790               
791                if(event->priority > EVENT(priority)) {
792                       
793                        /* p_send_msg(EACMD_STOP, 0, 0, 0); */
794                        if(INFO(b_now_ch_tuning)) {
795                                p_ea_restore_ch();
796                                INFO(b_now_ch_tuning)=FALSE;
797                        }
798                        if(INFO(b_now_scrolling)) {
799                                p_ea_scroll_stop();
800                                INFO(b_now_scrolling)=FALSE;
801#if APP_PORTING
802                                EADDI_ReleaseOSDToken();
803#endif  /* #if APP_PORTING */
804                        }
805                        INFO(b_scroll_pause)=FALSE;
806                       
807                        if(INFO(p_cur_event)) p_release_ea_event(&INFO(p_cur_event));
808                       
809                }
810                else if(EVENT(eventId) == event->eventId) {
811                       
812                        dprint(1, "[EA] Event check..same event id\n");
813                       
814                        EVENT(timeRemaining)+=event->timeRemaining;
815                       
816                        if(event->alertTextLen > 6) {
817                               
818                        }
819                        else {
820                                goto EaEventDeny;
821                        }
822                }
823                else {
824                        goto EaEventDeny;
825                }
826        }
827       
828        if(INFO(p_cur_event)) p_release_ea_event(&INFO(p_cur_event));
829        INFO(p_cur_event)=event;
830        return TRUE;
831                       
832EaEventDeny :
833        p_release_ea_event(&event);
834        return FALSE;
835       
836}
837
838
839/******************************************************************************************
840FUNCTION:
841  - p_ea_adjust_ch_info
842
843Purpose:
844  -
845******************************************************************************************/
846static void p_ea_adjust_ch_info(EA_EVENT *event)
847{
848        if(event->priority < 12) {      /* ÀÌ °æ¿ì Æ©´×Àº ÀϾÁö ¾ÊÀ½. */
849                event->detailMajor=0;
850                event->detailMinor=0;
851                event->detailSrcId=0;
852        }
853       
854        if(event->detailSrcId) {
855                int major, minor;
856               
857                EADDI_GetChBySrcId(event->detailSrcId, &major, &minor);
858                event->detailMajor=major;
859                event->detailMinor=minor;
860        }
861       
862        if(event->audioSrcId) { /* audio src id°¡ detail src idº¸´Ù ´õ priority°¡ ³ôÀº°¡? */
863                int major, minor;
864               
865                EADDI_GetChBySrcId(event->detailSrcId, &major, &minor);
866                event->detailMajor=major;
867                event->detailMinor=minor;
868        }
869}
870
871
872
873
874
875#if 0
876__Task__()
877#endif
878
879/******************************************************************************************
880FUNCTION:
881  - p_send_msg
882
883Purpose:
884  -
885******************************************************************************************/
886static void p_send_msg(UINT8 cmd, UINT8 opt, UINT32 param1, UINT32 param2)
887{
888        EA_CMD msg;
889       
890        msg.cmd=cmd;
891        msg.opt=opt;
892        msg.param1=param1;
893        msg.param2=param2;
894       
895        if(p_ea_msgq)
896                DHL_OS_SendMessage(p_ea_msgq, &msg, sizeof(msg));
897}
898
899
900/******************************************************************************************
901FUNCTION:
902  - p_set_msg_sync
903
904Purpose:
905  -
906******************************************************************************************/
907static void p_set_msg_sync()
908{
909        static DHL_OS_SEMA_ID ea_sync_sem=(DHL_OS_SEMA_ID)0;
910        static DHL_OS_SEMA_ID ea_mtx=(DHL_OS_SEMA_ID)0;
911        /* Ȥ½Ã ¿©·¯ task¿¡¼­ ÀÌ ÇÔ¼ö¸¦ È£ÃâÇÒ ¼öµµ ÀÖÀ» µí.. */
912       
913        if(!ea_mtx)
914                ea_mtx=DHL_OS_CreateMutexSemaphore("ea mtx");
915       
916        DHL_OS_TakeSemaphore(ea_mtx, DHL_TIMEOUT_FOREVER);
917       
918        if(ea_sync_sem)
919                OS_FlushSemaphore(ea_sync_sem);
920        else
921                ea_sync_sem=DHL_OS_CreateCountingSemaphore("ea sync", OS_SEM_PRIO, 0);
922       
923        p_send_msg(EACMD_SYNC, 0, (UINT32)ea_sync_sem, 0);
924        DHL_OS_TakeSemaphore(ea_sync_sem, DHL_TIMEOUT_FOREVER);
925       
926        DHL_OS_GiveSemaphore(ea_mtx);
927}
928
929
930
931static void p_format_ea_param()
932{
933        p_ea_nvm_param.prio=TRUE;
934       
935        App_NVM_SaveModuleParam(eAPP_NVR_EA, &p_ea_nvm_param);
936}
937
938
939/******************************************************************************************
940FUNCTION:
941  - p_ea_task
942
943Purpose:
944  -
945******************************************************************************************/
946static void p_ea_task(UINT32 param)
947{
948        int err;
949        EA_CMD rcv_msg;
950        int rcv_len;
951        UINT32 defered_mon_start_tick=0;
952        UINT32 defered_mon_duration=0;  /* ms ´ÜÀ§ */
953        DST_CURCHANNEL ChannelInfo;
954       
955        while(1) {
956               
957                err=DHL_OS_ReceiveMessage(p_ea_msgq, &rcv_msg, sizeof(rcv_msg), &rcv_len, TICK_1SEC/100);
958               
959                if(err) {       /* msg°¡ ¾øÀ¸¸é..½Ã°£Ã¼Å©¸¦ ÇØ¼­ scrollÀ̳ª ch tuneÀÌ µÇµµ·Ï ÇÔ. */
960                       
961                        /* defered mon start */
962                        if(defered_mon_duration>0 && TICK_PASS(defered_mon_start_tick)>defered_mon_duration*TICK_1SEC/1000) {
963                                defered_mon_duration=0;
964                                p_send_msg(EACMD_MON_START, 0, 0, 0);
965                        }
966                       
967                        if(INFO(b_now_ch_tuning) || INFO(b_now_scrolling)) {
968                                if(TICK_PASS(INFO(event_start_tick)) >= EVENT(timeRemaining)*TICK_1SEC) {
969                                        /* scrollÀÌ Á¾·áµÇ¾î¾ß ÇÔ. */
970                                        if(INFO(b_now_ch_tuning)) {
971                                                p_ea_restore_ch();
972                                                INFO(b_now_ch_tuning)=FALSE;
973                                        }
974                                        if(INFO(b_now_scrolling) && !p_ea_scroll_remaining()) {
975                                                p_ea_scroll_stop();
976                                                INFO(b_now_scrolling)=FALSE;
977#if APP_PORTING
978                                                EADDI_ReleaseOSDToken();
979#endif  /* #if APP_PORTING */
980                                                continue;
981                                        }
982                                }
983                               
984                                if(INFO(b_now_scrolling) && !INFO(b_scroll_pause) && TICK_PASS(INFO(scroll_prev_tick)) >= SCROLL_UPDATE_DELAY*TICK_1SEC/1000) {
985                                        dprint(1, "[EA] scroll updating....\n");
986                                        p_ea_scroll_update();
987                                        INFO(scroll_prev_tick)=TICK_CUR;
988                                }
989                               
990                        }
991                        else
992                                OS_Delay(TICK_1SEC/10);
993                               
994                        continue;
995                }
996               
997                dprint(1, "********************************************************\n");
998                dprint(1, "[EA cmd %s is received\n", EACMD_NAME(rcv_msg.cmd));
999                dprint(1, "********************************************************\n");
1000               
1001                switch(rcv_msg.cmd) {
1002                       
1003                        case EACMD_INIT :
1004                                INFO(osd_resolution)=rcv_msg.param1;
1005                                break;
1006                       
1007                        case EACMD_MON_START :
1008                                if(!INFO(b_now_monitoring)) {
1009                                        TSD *tsd = DHL_DMX_GetTsd();
1010                                       
1011                                        MonitorEAS(tsd, psiCRCChange, p_ea_event_proc, 0, &p_psi_ctrl);
1012                                        INFO(b_now_monitoring)=TRUE;
1013                                }
1014                                break;
1015                       
1016                        case EACMD_DEFER_MON_START :
1017                               
1018                                defered_mon_start_tick=TICK_CUR;
1019                                defered_mon_duration=rcv_msg.param1;
1020                               
1021                                break;
1022                               
1023                        case EACMD_MON_STOP :
1024                               
1025                                if(defered_mon_duration>0) defered_mon_duration=0;
1026                               
1027                                if(INFO(b_now_monitoring)) {
1028                                        CancelPSIPidMonitor(p_psi_ctrl);
1029                                        INFO(b_now_monitoring)=FALSE;
1030                                }
1031                                break;
1032                       
1033                        case EACMD_STOP :
1034                                /* scrolling ch tuning ÁßÁö. */
1035                                if(INFO(b_now_ch_tuning)) {
1036                                        p_ea_restore_ch();
1037                                        INFO(b_now_ch_tuning)=FALSE;
1038                                }
1039                                if(INFO(b_now_scrolling)) {
1040                                       
1041                                        if(!INFO(b_scroll_pause))
1042                                                p_ea_scroll_stop();
1043                                        else
1044                                                p_scroll_idx=0;
1045                                               
1046                                        INFO(b_now_scrolling)=FALSE;
1047#if APP_PORTING
1048                                        EADDI_ReleaseOSDToken();
1049#endif  /* #if APP_PORTING */
1050                                }
1051                                INFO(b_scroll_pause)=FALSE;
1052                               
1053                                if(INFO(p_cur_event)) p_release_ea_event(&INFO(p_cur_event));
1054                                break;
1055                       
1056                        case EACMD_PAUSE :
1057                                /* scroll pause */
1058                                INFO(b_scroll_pause)=TRUE;
1059                               
1060                                if(INFO(b_now_scrolling)) {
1061                                        p_ea_scroll_pause();
1062                                }
1063                                break;
1064                       
1065                        case EACMD_RESUME :
1066                                INFO(b_scroll_pause)=FALSE;
1067                                /* scroll resume */
1068                                if(INFO(b_now_scrolling)) {
1069#if 0
1070                                        p_ea_draw_main();
1071#else           /* ´Ù¸¥ OSD¿¡¼­ temp planeÀ» »ç¿ëÇÒ ¼ö Àֱ⠶§¹®¿¡, ´Ù½Ã scrollÀ» ±×·ÁÁà¾ß ÇÔ. */
1072                                        p_ea_scroll_start();
1073#endif
1074                                }
1075                                break;
1076                       
1077                        case EACMD_RECEIVE :
1078                        /* EA MESSAGE ¼ö½ÅÇÔ. */
1079                       
1080                                /* ea event À¯È¿¼º °Ë»ç */
1081                                if(!p_ea_check_event((EA_EVENT *)rcv_msg.param1)) {
1082                                        dprint(1, "[EA] EA event check failed..\n");
1083                                        break;
1084                                }
1085                               
1086                                /* ea event °ª Á¶Àý */
1087                                p_ea_adjust_ch_info((EA_EVENT *)rcv_msg.param1);
1088                               
1089                                /* ch tuning Á¶°Ç °Ë»ö */
1090                                {
1091                                        int uid=-1, flag;
1092                                       
1093                                        flag = CSF_ATSC_Only | CSF_Include_PSI | CSF_Include_Skipped | CSF_Include_Hidden;
1094                                        DMW_MSC_FindChannelMajorMinor(EVENT(detailMajor), EVENT(detailMinor), flag, 1, &uid);
1095
1096                                        App_Ucm_GetCurChInfo(&ChannelInfo);
1097
1098                                        if(EVENT(detailMajor) && (uid != ChannelInfo.nUid)) {                                           
1099                                                dprint(1, "[EA] Ch Tune start(M:%d,m:%d\n", EVENT(detailMajor), EVENT(detailMinor));
1100                                               
1101                                                /* ch tuningÀÌ µÇ°í ÀÖÀ¸¸é °­Á¦·Î eascrollÀ» Áö¿î´Ù. */
1102                                                if(INFO(b_now_scrolling)) {
1103                                                        if(!INFO(b_scroll_pause)) {     /* pause°¡ ¾ÈµÈ »óŶó¸é */
1104                                                                /* scroll Áö¿ì±â */
1105                                                                p_ea_erase_main();
1106                                                        }
1107                                                       
1108                                                        INFO(b_now_scrolling)=FALSE;
1109                                                }
1110                                       
1111                                                INFO(ch_b_major)=ChannelInfo.nMajor;
1112                                                INFO(ch_b_minor)=ChannelInfo.nMinor;
1113                                               
1114                                                if(EADDI_ChTune(EVENT(detailMajor), EVENT(detailMinor))) {
1115
1116                                                }
1117                                               
1118                                                INFO(b_now_ch_tuning)=TRUE;
1119                                        }
1120                                       
1121                                }
1122                               
1123                                /* scrolling Á¶°Ç. */
1124                                if(EVENT(alertTextLen)>6) {
1125                                       
1126                                        dprint(1, "[EA] scroll Start(len:%d)\n", EVENT(alertTextLen));
1127                                       
1128#if APP_PORTING
1129                                        /* 1. osd tokenÀ» ¾ò´Â °ÍÀÌ °¡´ÉÇÑÁö È®ÀÎ. */
1130                                        if(!EADDI_GetOSDToken()) {
1131                                                /* ¸Þ´º°¡ ¶° ÀÖÀ» ‹š ea scrollingÀ» ¹«½ÃÇØ¼­´Â ¾È µÉ µí ÇÏÁö¸¸, ±¸ÇöµÈ´ë·Î ÇÔ. */
1132                                                dprint(1, "[EA] EADDI_CanDraw --> FALSE\n");
1133                                                break;
1134                                        }
1135#endif  /* #if APP_PORTING */
1136
1137                                        if(INFO(b_now_scrolling)) {     /* ÀÌ¹Ì scrollingÀÌ µÇ°í ÀÖ¾ú´Ù¸é ? */
1138                                                p_ea_scroll_stop();
1139                                        }
1140
1141                                        p_ea_scroll_start();
1142                                       
1143                                        INFO(b_now_scrolling)=TRUE;
1144                                }
1145                               
1146                                INFO(scroll_prev_tick)=TICK_CUR;
1147                                INFO(event_start_tick)=TICK_CUR;
1148                               
1149                                break;
1150                       
1151                        case EACMD_SET_RESOLUTION :
1152                               
1153                                if(INFO(osd_resolution)!=rcv_msg.param1) {
1154                                        INFO(osd_resolution)=rcv_msg.param1;
1155                                }                       
1156                               
1157                                break;
1158                       
1159                        case EACMD_SYNC :
1160                                DHL_OS_GiveSemaphore((DHL_OS_SEMA_ID)rcv_msg.param1);
1161                                break;
1162                }
1163        }
1164       
1165}
1166
1167
1168
1169
1170
1171#if 0
1172__APIs__()
1173#endif
1174
1175/******************************************************************************************
1176FUNCTION:
1177  - App_EAInit
1178
1179Purpose:
1180  - EA initialize function
1181******************************************************************************************/
1182void App_EAInit()
1183{
1184        App_NVM_GetLoadedAppModuleParam(eApp_ea, &nvp_ea, sizeof(nvp_ea));
1185       
1186        p_ea_msgq=DHL_OS_CreateMessageQueue("EAMsgQ", OS_MSGQ_FIFO, MAX_EA_MSGQ, sizeof(EA_CMD));
1187       
1188        OS_SpawnTask((DHL_OS_TASKFUNCTION)p_ea_task, "EATask", TASK_EA_PRIORITY, EA_TASK_STK_SIZE, 0);
1189        p_send_msg(EACMD_INIT, 0, EA_R_480, 0);
1190}
1191
1192
1193
1194
1195void App_EAParamInit(void)
1196{
1197        App_NVM_RegisterModule(eAPP_NVR_EA, sizeof(p_ea_nvm_param), p_format_ea_param);
1198}
1199
1200/******************************************************************************************
1201FUNCTION:
1202  - App_EAMonStart/Stop
1203
1204Purpose:
1205  - EA monitoring Start/Stop function
1206******************************************************************************************/
1207void App_EAMonStart()
1208{
1209#if EA_DELAYED_MONITOR
1210        /* 5ÃÊ ÈÄ¿¡ ½ÃÀÛÇÔ. */
1211        p_send_msg(EACMD_DEFER_MON_START, 0, 5000, 0);
1212#else
1213        p_send_msg(EACMD_MON_START, 0, 0, 0);
1214#endif
1215}
1216
1217void App_EAMonStop()
1218{
1219        p_send_msg(EACMD_MON_STOP, 0, 0, 0);
1220}
1221
1222
1223/******************************************************************************************
1224FUNCTION:
1225  - App_EAPause/Resume/Exit
1226
1227Purpose:
1228  - EA Pause/Resume/Exit function
1229******************************************************************************************/
1230void App_EAPause()
1231{
1232        p_send_msg(EACMD_PAUSE, 0, 0, 0);
1233        p_set_msg_sync();
1234}
1235
1236void App_EAResume()
1237{
1238        p_send_msg(EACMD_RESUME, 0, 0, 0);
1239}
1240
1241void App_EAExit()
1242{
1243        p_send_msg(EACMD_STOP, 0, 0, 0);
1244}
1245
1246
1247/******************************************************************************************
1248FUNCTION:
1249  - App_EASetLow/Meduim
1250
1251Purpose:
1252  - EA Set Low/Meduim function
1253******************************************************************************************/
1254void App_EASetLow(BOOL bon)
1255{
1256        INFO(b_low_on)=bon;
1257}
1258
1259void App_EASetMedium(BOOL bon)
1260{
1261        INFO(b_medium_on)=bon;
1262}
1263
1264
1265/******************************************************************************************
1266FUNCTION:
1267  - App_EAIsLow/App_EAIsMedium
1268
1269Purpose:
1270  -
1271******************************************************************************************/
1272BOOL App_EAIsLow()
1273{
1274        return INFO(b_low_on);
1275}
1276
1277BOOL App_EAIsMedium()
1278{
1279        return INFO(b_medium_on);
1280}
1281
1282void App_EAInitPriority()
1283{
1284        App_EASetMedium(TRUE);
1285        App_EASetLow(TRUE);
1286        App_EASavePriority();
1287}
1288
1289
1290/******************************************************************************************
1291FUNCTION:
1292  - App_EASavePriority/App_EALoadPriority
1293
1294Purpose:
1295  -
1296******************************************************************************************/
1297void App_EASavePriority()
1298{
1299        nvp_ea.prio = INFO(b_medium_on)<<1 | INFO(b_low_on);
1300        App_NVM_SaveAppModuleParam(eApp_ea, &nvp_ea, sizeof(nvp_ea));
1301}
1302
1303void App_EALoadPriority()
1304{
1305        App_NVM_GetLoadedAppModuleParam(eApp_ea, &nvp_ea, sizeof(nvp_ea));
1306       
1307        App_EASetMedium(nvp_ea.prio>>1);
1308        App_EASetLow(nvp_ea.prio&0x1);
1309}
1310
1311
1312
1313
1314
1315#endif /* SUPPORT_EA */
1316
1317
1318/* end of file */
Note: See TracBrowser for help on using the repository browser.