pile_com_stm32/main/stm32/utils.c

61 lines
1.6 KiB
C
Raw Normal View History

2023-07-20 10:17:11 +08:00
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "utils.h"
#include <stdio.h>
#include <string.h>
int GetCompileDateTime(uint16_t *DateTime)
{
const int MONTH_PER_YEAR=13;
static char szEnglishMonth[][4] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
char szTmpDate[40]= {0};
char szTmpTime[20]= {0};
char szMonth[4]= {0};
int iYear,iMonth,iDay,iHour,iMin,iSec;//,,
int i;
//获取编译日期、时间
sprintf(szTmpDate,"%s",__DATE__); //"Sep 18 2010"
sprintf(szTmpTime,"%s",__TIME__); //"10:59:19"
sscanf(szTmpDate,"%s %d %d",szMonth,&iDay,&iYear);
sscanf(szTmpTime,"%d:%d:%d",&iHour,&iMin,&iSec);
for(i=0; MONTH_PER_YEAR; i++)
{
if(strncmp(szMonth,szEnglishMonth[i],3)==0)
{
iMonth=i+1;
break;
}
}
//printf("%d,%d,%d,%d,%d,%d\n",iYear,iMonth,iDay,iHour,iMin,iSec);
//sprintf(szDateTime,"%04d-%02d-%02d %02d:%02d:%02d",iYear,iMonth,iDay,iHour,iMin,iSec);
DateTime[0] = iYear;
DateTime[1] = iMonth*100;
DateTime[1] += iDay;
DateTime[2] = iHour*100;
DateTime[2] += iMin;
return 0;
}
unsigned int TickDiff(unsigned int comptime)
{
unsigned int nowtime = xTaskGetTickCount();
if(nowtime >= comptime)
return (nowtime - comptime);
else
return (0 - (comptime - nowtime));
}
int scale(int raw, int raw_min, int raw_max,int eng_min, int eng_max)
{
int result = 0;
if(raw_max != raw_min)
{
result = (raw - raw_min) * (eng_max - eng_min) / (raw_max - raw_min) + eng_min;
}
return result;
}