forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

jinlicong
2024-05-23 e5ec6ffc2fa0c07785c9d797c3fd74fd3031059f
Soft/system_general_para.c
@@ -1,6 +1,7 @@
#include "system_general_para.h"
#include "main.h"
#include "extern_rtc.h"
#include "time.h"
//uint8_t read_data_buf_A_l[200] ={0};
//uint8_t read_data_buf_B_l[200] ={0};
@@ -165,3 +166,58 @@
   }
   
}
/******************************************
 * func: Time_Compare
 * desc: Á½ÈÕÆÚ±È½Ï£¨²îÖµ£©
 * input:
          pDate1  Ê±¼ä1 BCD
          pDate2  Ê±¼ä2 BCD
 * output: none
 * return: Á½Ê±¼ä²îÖµ Ê±¼ä1´óÓÚʱ¼ä2£¬·µ»ØÕýÊý£¬ÏàµÈ·µ»Ø0£¬Ð¡·µ»Ø¸ºÊý
 *****************************************/
int Datecmp(const uint8_t *pDate1, const uint8_t *pDate2)
{
  uint16_t temp_year[2];
  time_t date_time1, date_time2;
  struct tm date_tm1 = {0}, date_tm2 = {0};
  /*°ÑÄê·Ý²¹ÍêÕû Hex*/
  temp_year[0] = 2000 + BCD_2_DECIMAL(pDate1[0]);
  temp_year[1] = 2000 + BCD_2_DECIMAL(pDate2[0]);
  /*ʱ¼ä½á¹¹Ì帳ֵ*/
  date_tm1.tm_year = temp_year[0] - 1900;
  date_tm1.tm_mon = BCD_2_DECIMAL(pDate1[1]) - 1;
  date_tm1.tm_mday = BCD_2_DECIMAL(pDate1[2]);
  date_tm1.tm_hour = BCD_2_DECIMAL(pDate1[3]);
  date_tm1.tm_min = BCD_2_DECIMAL(pDate1[4]);
  date_tm1.tm_sec = BCD_2_DECIMAL(pDate1[5]);
  date_tm2.tm_year = temp_year[1] - 1900;
  date_tm2.tm_mon = BCD_2_DECIMAL(pDate2[1]) - 1;
  date_tm2.tm_mday = BCD_2_DECIMAL(pDate2[2]);
  date_tm2.tm_hour = BCD_2_DECIMAL(pDate2[3]);
  date_tm2.tm_min = BCD_2_DECIMAL(pDate2[4]);
  date_tm2.tm_sec = BCD_2_DECIMAL(pDate2[5]);
  /*»ñµÃ´Ó1900Äê1ÔÂ1ÈÕ0ʱ0·Ö0ÃëÖÁ½ñµÄÃëÊý*/
  date_time1 = mktime(&date_tm1);
  date_time2 = mktime(&date_tm2);
  // if (date_time1 > date_time2)
  // {
  //   *diff_value = date_time1 - date_time2;
  //   return 1;
  // }
  // else if (date_time1 < date_time2)
  // {
  //   *diff_value = date_time2 - date_time1;
  //   return -1;
  // }
  return (int)(date_time1 - date_time2);
}