forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

wujiazhi
2024-06-13 72def895431ad7a08e635b11f3da738e2b2c4618
Soft/sundry.c
New file
@@ -0,0 +1,530 @@
#include "main.h"
#include "sundry.h"
#include "time.h"
#include "string.h"
#include "administrator.h"
#include "key.h"
#define SYS_RESTART_DELAY_TIME 180
// Ä¬ÈÏÉϵçGET_FLOW_DATA_PERIOD_TIME²É¼¯Ò»´ÎÊý¾Ý£¬¼¤»îʱ¼äΪSYS_WAKE_UP_TIME
SYS_DELAY_SEC_PARA_T sys_delay_sec_para_g = {{RESET}, {RESET}, {RESET, GET_FLOW_DATA_PERIOD_TIME},
                                                                     {RESET, SYS_WAKE_UP_TIME}, {RESET}, {RESET,SYS_RESTART_DELAY_TIME}};
PERIOD_PARA_T  period_para_g  = {{SET, 0}, {SET, 0}, {SET, 0}, {SET, 0}};
typedef union
{
  float flo;
  uint8_t data[4];
} FLOAT_U8;
typedef union
{
   double dou;
   uint8_t data[8];
}DOUBLE_U8;
/*4×Ö½ÚתFloat*/
float Byte4_To_Float(uint8_t *pData)
{
  FLOAT_U8 f_conv;
  for (uint8_t i = 0; i < 4; i++)
    f_conv.data[i] = pData[i];
  return f_conv.flo;
}
/*Floatת4×Ö½Ú*/
void Float_To_Byte4(float flo, uint8_t *pData)
{
  FLOAT_U8 f_conv;
  f_conv.flo = flo;
  for (uint8_t i = 0; i < 4; i++)
    pData[i] = f_conv.data[i];
}
float BLEndianFloat(float fValue)
{
   FLOAT_U8 d1, d2;
   d1.flo = fValue;
   d2.data[0] = d1.data[3];
   d2.data[1] = d1.data[2];
   d2.data[2] = d1.data[1];
   d2.data[3] = d1.data[0];
   return d2.flo;
}
double BLEndianDouble(double ffValue)
{
   DOUBLE_U8 d1, d2;
   d1.dou = ffValue;
   d2.data[0] = d1.data[7];
   d2.data[1] = d1.data[6];
   d2.data[2] = d1.data[5];
   d2.data[3] = d1.data[4];
   d2.data[4] = d1.data[3];
   d2.data[5] = d1.data[2];
   d2.data[6] = d1.data[1];
   d2.data[7] = d1.data[0];
   return d2.dou;
}
uint8_t Bcd_2_Hex(uint8_t bcd_data) // BCD_TO_HEX
{
  /*£¨ÏÞÖÆ·¶Î§0~99£©*/
  uint8_t temp;
  temp = ((bcd_data / 16) * 10 + bcd_data % 16);
  return temp;
}
uint8_t Hex_2_Bcd(uint8_t hex_data) // HEX_TO_BCD
{
  /*£¨ÏÞÖÆ·¶Î§0~99£©*/
  uint8_t temp;
  temp = ((hex_data / 10) * 16 + hex_data % 10);
  return temp;
}
void Hex_2_Ascii(uint8_t *Hex, uint8_t *Ascii, int Len) //   HEX_TO_ASCII
{
  uint8_t Nibble[2];
  uint8_t i, j;
  for (i = 0; i < Len; i++)
  {
    Nibble[0] = (Hex[i] & 0xF0) >> 4;
    Nibble[1] = (Hex[i] & 0x0F);
    for (j = 0; j < 2; j++)
    {
      if (Nibble[j] < 10)
      {
        Nibble[j] += 0x30;
      }
      else
      {
        if (Nibble[j] < 16)
          Nibble[j] = Nibble[j] - 10 + 'A';
      }
      *Ascii++ = Nibble[j];
    }
  }
}
void Ascii_2_Hex(uint8_t *Ascii, uint8_t *Hex, int Len) //   ASCII_TO_HEX
{
  if (Len & 1) // µÈ¼ÛÓÚLen % 2£¬µ«³ÌÐòÔËÐÐËٶȸü¿ì
    return;
  int nHexLen = Len >> 1; // µÈ¼ÛÓÚLen / 2£¬µ«³ÌÐòÔËÐÐËٶȸü¿ì
  int i, j;
  for (i = 0; i < nHexLen; i++)
  {
    uint8_t Nibble[2];
    Nibble[0] = *Ascii++;
    Nibble[1] = *Ascii++;
    for (j = 0; j < 2; j++)
    {
      if (Nibble[j] <= 'F' && Nibble[j] >= 'A')
      {
        Nibble[j] = Nibble[j] - 'A' + 10;
      }
      else if (Nibble[j] <= 'f' && Nibble[j] >= 'a')
      {
        Nibble[j] = Nibble[j] - 'a' + 10;
      }
      else if (Nibble[j] >= '0' && Nibble[j] <= '9')
      {
        Nibble[j] = Nibble[j] - '0';
      }
      else
      {
        return;
      }
    }
    Hex[i] = Nibble[0] << 4;
    Hex[i] |= Nibble[1];
  }
}
uint8_t restart_alarm_flag = 0;
/*ϵͳѭ»·µÄÑÓ³Ùʱ¼ä*/
void Sys_Delay_Sec(SYS_DELAY_SEC_PARA_T *sys_delay_sec_para_p)
{
  // ÅжÏϵͳ¼¤»îʱ¼äÊÇ·ñ½áÊø
  if (sys_delay_sec_para_p->sys_active_time.delay_time)
  {
    if (!(--sys_delay_sec_para_p->sys_active_time.delay_time))
      {
         sys_delay_sec_para_p->sys_active_time.delay_flag = SET;
         GPIO_EXTI_EXTIISR_ClrEx(KEYA_S1_PORT, KEYA_S1_PIN);
      }
  }
  // ÅжÏGPRSÑÓ³Ùʱ¼äÊÇ·ñ´ïµ½
  if (sys_delay_sec_para_p->gprs_delay_para.delay_time)
  {
    if (!(--sys_delay_sec_para_p->gprs_delay_para.delay_time))
      sys_delay_sec_para_p->gprs_delay_para.delay_flag = SET;
  }
  // ÅжÏGPRS³¬Ê±Ê±¼ä
  if (sys_delay_sec_para_p->gprs_timeout_para.delay_time)
  {
    if (!(--sys_delay_sec_para_p->gprs_timeout_para.delay_time))
      sys_delay_sec_para_p->gprs_timeout_para.delay_flag = SET;
  }
  // ÅжÏÁ÷Á¿Êý¾Ý»ñÈ¡ÖÜÆÚʱ¼äÊÇ·ñ´ïµ½
  if (sys_delay_sec_para_p->flow_data_period_para.delay_time)
  {
    if (!(--sys_delay_sec_para_p->flow_data_period_para.delay_time))
    {
      sys_delay_sec_para_p->flow_data_period_para.delay_flag = SET;
    }
  }
   // ÅжÏÇл»Ä£Ê½±ê־λ³ÖÐøÊ±¼ä
  if (sys_delay_sec_para_p->mode_flag_active_time.delay_time)
  {
    if (!(--sys_delay_sec_para_p->mode_flag_active_time.delay_time))
      sys_delay_sec_para_p->mode_flag_active_time.delay_flag = SET;
  }
   // ÖØÆôµÄÑÓ³Ùʱ¼ä
  if (sys_delay_sec_para_p->sys_restart_delay_time.delay_time)
  {
    if (!(--sys_delay_sec_para_p->sys_restart_delay_time.delay_time))
      {
         __SYS_ALARM_BYTES_SET(restart, SET);// ¸´Î»±¨¾¯
         restart_alarm_flag = 1;
      }
  }
}
/******************************************
 * func:    Func_PeriodStartHandler
 * desc:    ÖÜÆÚÆô¶¯¹¦ÄÜ´¦Àí
 * input:   ref_time_m : »ù׼ʱ¼ä£¨·ÖÖÓ£©
            period_min_set £ºÉèÖõÄÖÜÆÚʱ¼ä£¨·ÖÖÓ£©
            pPeriod_flag : Ê×´ÎÅжϱê־λ
            pLast_time_m £ºÉÏÒ»´ÎµÄʱ¼ä£¨·ÖÖÓ£©
            calendar_p £ºÉ豸¶Ëʱ¼ä
 * output:  none
 * return: ÊÇ·ñ³É¹¦£¨SET/RESET£©
 * ×¢Ò⣺ÓÉÓÚÊÇÒÔ·ÖÖÓΪÅжÏ×îСֵ£¬Ã¿ÌìÓÐ1440·ÖÖÓ£¬ÔÚ0µãÇåÁ㣬ËùÒÔ¼ä¸ô×î´óֵΪ1440
 *          ÎªÁ˼õÉÙ²»±ØÒªµÄ³ÌÐòÁ÷³Ì£¬Ã¿·ÖÖÓÖ»ÅжÏÒ»´Î¼´¿É
 *****************************************/
FlagStatus Func_PeriodStartHandler(uint16_t ref_time_m, uint16_t period_min_set,
                                   uint16_t *pPeriod_flag, __IO uint16_t *pLast_time_m, __IO RTC_TimeDateTypeDef *calendar_p)
{
  FlagStatus flag = RESET;
  uint16_t i = 0;
  int16_t temp_min = 0; // ¼ÆËãʱÓпÉÄÜΪ¸ºÊý£¬ËùÒÔ²»ÄÜÓÃÎÞ·ûºÅ
  uint16_t now_time_m = Bcd_2_Hex(calendar_p->Hour) * 60 + Bcd_2_Hex(calendar_p->Minute);
  if (ref_time_m >= 1440)
    ref_time_m = 0;
  if (period_min_set > 1440)
    period_min_set = 1440;
  /*Ê×´ÎÅжÏÉÏ´ÎµÄÆô¶¯Ê±¼ä£¬µ±Ç°Ê±¼ä>=»ù׼ʱ¼ä*/
  if (*pPeriod_flag == 1)
  {
    *pPeriod_flag = 0;
    if (now_time_m >= ref_time_m)
    {
      temp_min = ref_time_m;
      while (now_time_m >= temp_min)
      {
        temp_min += period_min_set;
        if (++i > 289) // 1440 / 5 + 1
          break;
      }
      *pLast_time_m = temp_min - period_min_set;
    }
    else if (now_time_m < ref_time_m) // ÕâÖÖÇé¿öÊÇ£¬µ±Ç°Ê±¼ä<»ù׼ʱ¼ä
    {
      temp_min = ref_time_m - period_min_set;
      while (now_time_m <= temp_min)
      {
        temp_min -= period_min_set;
        if (++i > 289)
          break;
      }
      if (temp_min >= 0)
        *pLast_time_m = temp_min;
      else
        *pLast_time_m = temp_min + 1440;
    }
  }
  /*¿çÌìÇé¿ö*/
  if ((now_time_m <= *pLast_time_m) && ((now_time_m + 1440 - *pLast_time_m) % period_min_set == 0))
  {
    *pLast_time_m = now_time_m;
    flag = SET;
  }
  else if ((now_time_m - *pLast_time_m) % period_min_set == 0) // µ±Ç°Ê±¼ä´óÓÚÉÏÒ»´Îʱ¼äÇé¿ö
  {
    *pLast_time_m = now_time_m;
    flag = SET;
  }
  return flag;
}
/*²é±í·¨£¬Êý¾ÝÖÐbitΪ1µÄ¸öÊý*/
static const uint8_t numbits_lookup_table[256] = {
    0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2,
    3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3,
    3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3,
    4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4,
    3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5,
    6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4,
    4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5,
    6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5,
    3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3,
    4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6,
    6, 7, 6, 7, 7, 8};
uint16_t get_one_in_data_3(uint16_t data)
{
  uint16_t n = 0;
  n = numbits_lookup_table[data & 0x00ff];
  n += numbits_lookup_table[data >> 8 & 0x00ff];
  return n;
}
/******************************************
 * 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_HEX_U8(pDate1[0]);
  temp_year[1] = 2000 + BCD_2_HEX_U8(pDate2[0]);
  /*ʱ¼ä½á¹¹Ì帳ֵ*/
  date_tm1.tm_year = temp_year[0] - 1900;
  date_tm1.tm_mon = BCD_2_HEX_U8(pDate1[1]) - 1;
  date_tm1.tm_mday = BCD_2_HEX_U8(pDate1[2]);
  date_tm1.tm_hour = BCD_2_HEX_U8(pDate1[3]);
  date_tm1.tm_min = BCD_2_HEX_U8(pDate1[4]);
  date_tm1.tm_sec = BCD_2_HEX_U8(pDate1[5]);
  date_tm2.tm_year = temp_year[1] - 1900;
  date_tm2.tm_mon = BCD_2_HEX_U8(pDate2[1]) - 1;
  date_tm2.tm_mday = BCD_2_HEX_U8(pDate2[2]);
  date_tm2.tm_hour = BCD_2_HEX_U8(pDate2[3]);
  date_tm2.tm_min = BCD_2_HEX_U8(pDate2[4]);
  date_tm2.tm_sec = BCD_2_HEX_U8(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);
}
/*¼ÆËãijÄê¹ýÁ˶àÉÙÌì*/
uint16_t CalculateDays_of_the_year(uint8_t year_bcd, uint8_t month_bcd, uint8_t day_bcd)
{
  uint16_t sum = 0, year_h = BCD_2_HEX_U8(year_bcd) + 2000;
  uint8_t month_h = BCD_2_HEX_U8(month_bcd), day_h = BCD_2_HEX_U8(day_bcd);
  uint8_t months[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  for (uint8_t i = 0; i < month_h; i++)
    sum += months[i];
  sum += day_h;
  if (((year_h % 4 == 0 && year_h % 100 != 0) || year_h % 400 == 0) && month_h >= 3)
    sum += 1;
  return sum;
}
/*¼ÆËãÁ½ÈÕÆÚµÄÌìÊý²î*/
int16_t Date_DaysDifference(uint8_t yearst_bcd, uint8_t monthst_bcd, uint8_t dayst_bcd,
                            uint8_t yearend_bcd, uint8_t monthend_bcd, uint8_t dayend_bcd)
{
  int16_t total = 0, yearst_h = BCD_2_HEX_U8(yearst_bcd) + 2000, yearend_h = BCD_2_HEX_U8(yearend_bcd) + 2000;
  total = (yearend_h - yearst_h) * 365;                                      // Ïà²îÁ½ÈÕÆÚÄê·ÝµÄ×ÜÌìÊý
  total -= CalculateDays_of_the_year(yearst_bcd, monthst_bcd, dayst_bcd);    // ¼õÈ¥¿ªÊ¼ÈÕÆÚµÄÌìÊý
  total += CalculateDays_of_the_year(yearend_bcd, monthend_bcd, dayend_bcd); // ¼ÓÉÏÒѹýÈÕÆÚµÄÌìÊý
  while (yearst_h != yearend_h)                                              // ÅжÏÊÇ·ñÈòÄê
  {
    if (total > 0) // ¿ªÊ¼ÄêÔÂÈÕ > ½áÊøÄêÔÂÈÕ
    {
      if ((yearst_h % 4 == 0 && yearst_h % 100 != 0) || yearst_h % 400 == 0)
        total += 1;
      yearst_h++;
    }
    else // ¿ªÊ¼ÄêÔÂÈÕ < ½áÊøÄêÔÂÈÕ
    {
      if ((yearst_h % 4 == 0 && yearst_h % 100 != 0) || yearst_h % 400 == 0)
        total -= 1;
      yearend_h++;
    }
  }
  return total;
}
/*¼ÆËãÁ½ÈÕÆÚµÄÔ·ݲî*/
int16_t Data_MonthsDifference(uint8_t yearst_bcd, uint8_t monthst_bcd,
                              uint8_t yearend_bcd, uint8_t monthend_bcd)
{
  int16_t total = 0, yearst_h = BCD_2_HEX_U8(yearst_bcd) + 2000, yearend_h = BCD_2_HEX_U8(yearend_bcd) + 2000;
  total = (yearend_h - yearst_h) * 12;
  total -= BCD_2_HEX_U8(monthst_bcd);
  total += BCD_2_HEX_U8(monthend_bcd);
  return total;
}
/*Ç󯽾ùÖµ*/
float flow_ring_buffer[FLOW_RING_BUFFER_SIZE] = {0};
float temp_ring_buffer[TEMP_RING_BUFFER_SIZE] = {0};
float press_ring_buffer[PRESS_RING_BUFFER_SIZE] = {0};
ANALOGOUS_RING_BUFFER_T __attribute__ ((aligned (4))) flow_ring = {flow_ring_buffer, 0, 0};
ANALOGOUS_RING_BUFFER_T __attribute__ ((aligned (4))) temp_ring = {temp_ring_buffer, 0, 0};
ANALOGOUS_RING_BUFFER_T __attribute__ ((aligned (4))) press_ring = {press_ring_buffer, 0, 0};
/*ÿÃëµÄ˲ʱ¹¤¿ö*/
float instant_wc_ring_queue_buffer[INSTANT_WC_RING_BUFFER_SIZE] = {0};
ANALOGOUS_RING_BUFFER_T __attribute__ ((aligned (4))) instant_wc_ring = {instant_wc_ring_queue_buffer, 0, 0};
/*»·ÐÎÊý×éÊÇ·ñ´æÂú*/
uint8_t isFull(ANALOGOUS_RING_BUFFER_T *ring_buffer_p, uint8_t buffer_len_max)
{
  return (ring_buffer_p->rear_index + 1) % buffer_len_max == ring_buffer_p->front_index;
}
/*»·ÐÎÊý×éÊÇ·ñΪ¿Õ*/
uint8_t isEmpty(ANALOGOUS_RING_BUFFER_T *ring_buffer_p)
{
  return (ring_buffer_p->rear_index == ring_buffer_p->front_index);
}
/*»·Ð´µ¥×éÊý¾Ý
 * ×¢Ò⣺float * ²ÎÊý²»¿ÉÒÔ¸ÄΪ float ²ÎÊý£¬·ñÔò³ÌÐò»áÅÜ·É£¨Ôݲ»Ã÷°×Ϊʲô£©
 */
uint8_t ring_write_1_data(ANALOGOUS_RING_BUFFER_T *ring_buffer_p, const float *pData, uint8_t buffer_len_max)
{
  uint8_t full_flag = 0, modulo = 0;
  modulo = (ring_buffer_p->rear_index + 1) % buffer_len_max;
  if (modulo == ring_buffer_p->front_index) // ÀûÓá°È¡Ä£¡±µÄ·½Ê½£¬ÅжÏÊÇ·ñ´æÂú
  {
    ring_buffer_p->front_index = (ring_buffer_p->front_index + 1) % buffer_len_max; // ´æÂú¶ÓÁÐÍ·Ò²Òª¸ú×ű仯
    full_flag = 1;
  }
  ring_buffer_p->pRing_buffer[ring_buffer_p->rear_index] = *pData;
  ring_buffer_p->rear_index = modulo;
  return full_flag;
}
/*»·Ð´¶à×éÊý¾Ý*/
uint8_t ring_write_array(ANALOGOUS_RING_BUFFER_T *ring_buffer_p, const float *pData, uint8_t write_cnt, uint8_t buffer_len_max)
{
  uint8_t full_flag = 0;
  for (uint8_t i = 0; i < write_cnt; i++)
    full_flag = ring_write_1_data(ring_buffer_p, &pData[i], buffer_len_max);
  return full_flag;
}
/*»·¶Áµ¥×éÊý¾Ý*/
uint8_t ring_read_1_data(ANALOGOUS_RING_BUFFER_T *ring_buffer_p, float *pData, uint8_t buffer_len_max)
{
  if (ring_buffer_p->rear_index == ring_buffer_p->front_index)
    return 0;
  *pData = ring_buffer_p->pRing_buffer[ring_buffer_p->front_index];
  ring_buffer_p->front_index = (ring_buffer_p->front_index + 1) % buffer_len_max;
  return 1;
}
/******************************************
 * func:    LowPassFilter_Ring_Average
 * desc:   ÀûÓû·ÐÎÊý×鸲¸ÇµÄÐÎʽ£¬Æ½¾ùÖµ
 * input:   ring_buffer_p : »·ÐζÓÁнṹÌåÖ¸Õë
            *pData £ºÐ´ÈëµÄÊý¾ÝµØÖ·
            write_cnt : Ò»´ÎдÈëµÄÊý¾Ý¸öÊý
            buffer_len_max £ºÇ󯽾ùÖµµÄ×î´ó¸öÊý
 * output:  none
 * return:  Æ½¾ùÖµ
 *****************************************/
float LowPassFilter_Ring_Average(ANALOGOUS_RING_BUFFER_T *ring_buffer_p, const float *pData, uint8_t write_cnt, uint8_t buffer_len_max)
{
  float result = 0, add = 0;
  if (ring_write_array(ring_buffer_p, pData, write_cnt, buffer_len_max))
  {
    for (uint8_t i = 0; i < buffer_len_max; i++)
      add += ring_buffer_p->pRing_buffer[i];
    result = add / buffer_len_max;
  }
  return result;
}
/*ðÅÝÅÅÐò*/
void My_BubbleSort(float * pNum,int len)
{
   int i,j;
   float temp;
   for(i = 0;i < len - 1;i++)
   {
      for(j = 0;j < len - 1- i;j++)
      {
         if(pNum[j] > pNum[j + 1])
         {
            temp = pNum[j];
            pNum[j] = pNum[j+1];
            pNum[j+1] = temp;
         }
      }
   }
}
/*È¥³ý×î´óÖµºÍ×îСֵ£¬Çó»·ÐÎÊý×éµÄƽ¾ùÖµ*/
float LowPassFilter_MaxMin_Ring_Average(ANALOGOUS_RING_BUFFER_T *ring_buffer_p, const float *pData, uint8_t write_cnt, uint8_t buffer_len_max)
{
  float result = 0, add = 0;
  if (ring_write_array(ring_buffer_p, pData, write_cnt, buffer_len_max))
  {
      My_BubbleSort(ring_buffer_p->pRing_buffer,buffer_len_max);
    for (uint8_t i = 1; i < buffer_len_max - 1; i++)
      add += ring_buffer_p->pRing_buffer[i];
    result = add / (buffer_len_max - 2);
  }
  return result;
}
/********************************************************************
 * name         : CalcCheckSum
 * description  : ¼ÆËãУÑéºÍ
 * Input        :   *pData£ºÊäÈëÊý¾ÝÖ¸Õë Len£ºÊý¾Ý³¤¶È
 * Output       : none
 * Return       : Sum:УÑéºÍ
 ********************************************************************/
uint8_t CalcCheckSum(const uint8_t *pData, uint16_t Len)
{
  uint32_t Sum = 0;
  for (uint16_t i = 0; i < Len; i++)
    Sum += pData[i];
  return (Sum & 0xFF);
}
/*
¹¤¿öת±ê¿ö
return £º±ê¿öÊý¾Ý
*/
float Wc_2_Sc(float wc_flow, float real_press, float real_temp)
{
  float temp_factor = 0;
  uint8_t standard_compressibility_factor = 1; // ±ê׼ѹËõÒò×Ó
  uint8_t real_compressibility_factor = 1;     // ÊµÊ±Ñ¹ËõÒò×Ó
  if (wc_flow != 0)
    temp_factor = ((STANDARD_TEMPERATURE / STANDARD_PRESSURE) * real_press / (real_temp + 273.15f)) *
              (standard_compressibility_factor / real_compressibility_factor);
  return (temp_factor * wc_flow);
}
/*ÀàËÆmemcmp¿âº¯Êý£¬µ«ÊÇpData_2²»½øÐеØÖ·Æ«ÒÆ*/
int8_t my_memcmp(const void * pData_1,const void * pData_2,size_t n)
{
   if(!n)
      return 0;
   while(--n && *(int8_t *)pData_1 == *(int8_t *)pData_2)
      pData_1++;
   return (*(uint8_t *)pData_1 - *(uint8_t *)pData_2);
}