timeclk.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:5k
源码类别:

DVD

开发平台:

C/C++

  1. #include "timeclk.h"
  2. #include "sipsi.h"
  3. #include "osd.h"
  4. #include "avplay.h"
  5. #include "db.h"
  6. #include <string.h>
  7. #include "db.h"
  8. #include "osp.h"
  9. #include "dmd.h"
  10. #include "flash.h"
  11. #include "appltype.h"
  12. #include "timer.h"
  13. #define INVALID_OFFSET -13
  14. #define MAX_TMS 128
  15. typedef struct {
  16. UINT32 freq;
  17. UINT32 symbol;
  18. UINT8  qam;
  19. time_t tm;
  20. INT8   offset;
  21. BOOL   tm_valid;
  22. BOOL   offset_valid;
  23. BOOL   used;
  24. } TM_OFFSET;
  25. static TM_OFFSET tm_offset[MAX_TMS];
  26. KB_SIBatStruct   recBat;
  27. static KB_TimeVariables g_stTimeVars;
  28. static UINT32 current_freq;
  29. static UINT32 current_symbol;
  30. static UINT32 current_qam;
  31. static KB_TimeClkCallbackFunc gptTimeClkCallbackFunction = NULL;
  32. static void KD_AppTimer(void);
  33. int  KB_TimeInit(void)
  34. {
  35. static UINT32 hClockTimer;
  36. current_freq = 0;
  37. current_symbol = 0;
  38. current_qam = 0;
  39. memset(tm_offset, 0, sizeof(tm_offset));
  40. g_stTimeVars.cTimeMsgEnable = 0;
  41. g_stTimeVars.cTimeValidity  = 0;
  42. g_stTimeVars.dwCurrentTime  = 0;
  43. g_stTimeVars.offset  = INVALID_OFFSET;
  44. hClockTimer = KB_TimerCreate(KB_TIMER_REPEAT, (KB_TIMER_FUNC_POINTER)KD_AppTimer,NULL);
  45.     KB_TimerEnable(hClockTimer, 1000);
  46.     
  47. return KB_DB_DTV_SUCCESS;
  48. }
  49. void KB_TimeSetCurTime(time_t  lTime)
  50. {
  51. if(g_stTimeVars.offset == INVALID_OFFSET)
  52. {
  53. g_stTimeVars.dwCurrentTime  = lTime;
  54. }
  55. g_stTimeVars.cTimeValidity  = 1; 
  56. }
  57. void KB_TimeSetCurOffSet(INT8 offset)
  58. {
  59. if(g_stTimeVars.offset == INVALID_OFFSET)
  60. {
  61. g_stTimeVars.offset  = offset;
  62. }
  63. }
  64. INT8 KB_TimeGetCurOffSet(void)
  65. {
  66. return g_stTimeVars.offset  ;
  67. }
  68. time_t KB_TimeGetCurGMTTime(void)
  69. {
  70. return g_stTimeVars.dwCurrentTime;
  71. }
  72. int KB_TimeGetCurTime(time_t  *plTime)
  73. {
  74. //printf("KB_TimeGetCurTime:g_stTimeVars.offset = %d",g_stTimeVars.offset);
  75.     if (g_stTimeVars.cTimeValidity == 0)
  76.     {
  77.         return KB_DB_DTV_FAILURE;
  78.     }
  79.     
  80. if(g_stTimeVars.offset != INVALID_OFFSET)
  81. {
  82. *plTime = g_stTimeVars.dwCurrentTime + g_stTimeVars.offset * 3600;
  83. }
  84. else
  85. {
  86. unsigned char res;
  87. signed char zone;
  88. res = KB_DBGetZone(&zone);
  89. //printf("KB_TimeGetCurTime:g_stTimeVars.zone = %d",zone);
  90. if (res == KB_DB_DTV_SUCCESS)
  91. {
  92. *plTime = (time_t)(g_stTimeVars.dwCurrentTime + zone * 3600);
  93. }
  94. else
  95. {
  96. *plTime = g_stTimeVars.dwCurrentTime;
  97. //Print("[TIMECLK.C KB_TimeGetCurTime] Get time zone error.n");
  98. }
  99. }
  100. return KB_DB_DTV_SUCCESS;
  101. }
  102. //*****************************************************************************
  103. //名称:Time_2_Local_Tiem
  104. //
  105. //功能:将系统中的时间转换成当地时间
  106. //
  107. //输入:当前的格林威治时间
  108. //
  109. //返回:返回的时间是当前时区的当地时间
  110. //
  111. //*****************************************************************************
  112. time_t Time_2_Local_Tiem(time_t timeStamp)
  113. {
  114. //首先要根据系统设置页面中的设置来获得时区
  115. //这里假设时区是8,如果有更改的话,请重新获得
  116. INT8 offset = INVALID_OFFSET;
  117. KB_DBGetZone(&offset);
  118. if (offset != INVALID_OFFSET)
  119. {
  120. timeStamp = (time_t)(timeStamp + offset * 3600);
  121. }
  122. return timeStamp;
  123. }
  124. time_t KB_TimeGMTTime(time_t tt)
  125. {
  126. if (tt != 0)
  127. {
  128. INT8 offset;
  129. offset = KB_TimeGetCurOffSet();
  130. if (offset == INVALID_OFFSET)
  131. {
  132. if (KB_DBGetZone(&offset) != KB_DB_DTV_SUCCESS)
  133. {
  134. offset = 0;
  135. Print("[TIMECLK.C KB_TimeGMTTime] Get time zone error.n");
  136. }
  137. }
  138. tt += (time_t)(offset * 3600);
  139. }
  140. return tt;
  141. }
  142. void  KB_TimeEnableTimer(void)
  143. {
  144. g_stTimeVars.cTimeMsgEnable = 1;
  145. }
  146. void  KB_TimeDisableTimer(void)
  147. {
  148. g_stTimeVars.cTimeMsgEnable = 0;
  149. }
  150. static void KD_AppTimer(void)
  151. {
  152. KB_OSPMsgNode  timeMsg;
  153. int i;
  154. int ret;
  155. g_stTimeVars.dwCurrentTime ++;
  156. for(i=0; i<MAX_TMS; i++)
  157. {
  158. if(tm_offset[i].used && tm_offset[i].tm_valid)
  159. {
  160. tm_offset[i].tm++;
  161. }
  162. }
  163.     if(g_stTimeVars.cTimeMsgEnable == 1)
  164.     {
  165.         timeMsg.Word1 = J_TIME_MODULE;
  166.         if (gptTimeClkCallbackFunction != NULL) 
  167.         {
  168.             gptTimeClkCallbackFunction(&timeMsg);
  169.         }
  170.     }
  171. }
  172. BOOL KB_TimeSetPrgOffset(INT8 offset, UINT32 freq, UINT32 symbol, UINT8 qam)
  173. {
  174. int i;
  175. int index = -1;
  176. for(i=0; i<MAX_TMS; i++)
  177. {
  178. if( (tm_offset[i].used) && 
  179. (tm_offset[i].freq == freq) && 
  180. (tm_offset[i].symbol == symbol) &&
  181. (tm_offset[i].qam == qam))
  182. {
  183. tm_offset[i].offset_valid = TRUE;
  184. tm_offset[i].offset = offset;
  185. return TRUE;
  186. }
  187. if((!tm_offset[i].used) && (index == -1))
  188. {
  189. index = i;
  190. }
  191. }
  192. if(index == -1)
  193. {
  194. KB_TimeResetPrgTimes();
  195. index = 0;
  196. }
  197. tm_offset[index].used = TRUE;
  198. tm_offset[index].freq = freq;
  199. tm_offset[index].symbol = symbol;
  200. tm_offset[index].qam = qam;
  201. tm_offset[index].offset = offset;
  202. tm_offset[index].offset_valid = FALSE;
  203. return TRUE;
  204. }
  205. void KB_TimeResetPrgTimes(void)
  206. {
  207. memset(tm_offset, 0, sizeof(tm_offset));
  208. g_stTimeVars.cTimeMsgEnable = 0;
  209. g_stTimeVars.cTimeValidity  = 0;
  210. g_stTimeVars.dwCurrentTime  = 0;
  211. g_stTimeVars.offset  = INVALID_OFFSET;
  212. current_freq = 0;
  213. current_symbol = 0;
  214. current_qam = 0;
  215. }
  216. KB_TimeClkCallbackFunc KB_TimerCallBack(KB_TimeClkCallbackFunc callback)
  217. {
  218.     KB_TimeClkCallbackFunc ptPrvCallback;
  219.     ptPrvCallback = gptTimeClkCallbackFunction;
  220. gptTimeClkCallbackFunction = callback;
  221.     return ptPrvCallback;
  222. }