【开源】蓝桥杯十二届停车场

 

 功能全部实现

十二届的题目难点在于数据处理

附上关键代码

初始化:

uint8_t buffer[120]={0};
char buff[40]="0";
int len1;
float carmoney;
int carhour;
int carp=1;
int B1=1,B2=1,B3=1,B4=1;
int flag1,flag2,flag3=0,flag4=0,flag5=0;
int CNBRnum=0;
int VNBRnum=0;
float fee1=3.5;
float fee2=2.5;
int IDLE=8;
int pwm1=1;
int location=1;
struct car_date
{char cartype[6];
char carnum[6];
char cartim[12];
};
struct car_time
{
int caryear;
	int carmonth;
	int cardate;
	int carhour;
	int carmin;
	int carsec;


}	;

	struct car_date car_wait[8];
		struct car_date car_in[8];
		struct car_time car_it[8]={0};
		struct car_time car_wt={0};

串口部分:

void uart_clear()
	{ 
		
		
	
		IDLE=8-CNBRnum-VNBRnum;
	if(buffer[0]!=0)
 { 
	if( len1>22||buffer[4]!=':'||buffer[9]!=':')
	{ memset(&car_wt,0,(sizeof(car_wt)));
	 car_wait[1]=car_wait[2];
   flag4=1;
	}
 }
	
if(len1==22&&buffer[4]==':'&&buffer[9]==':')
 {
	for(int i=0;i<4;i++)
		{
			car_wait[1].cartype[i]=buffer[i];
			car_wait[1].carnum[i]=buffer[i+5];
		}
		for(int i=0;i<13;i++)
		{
			car_wait[1].cartim[i]=buffer[i+10]; 
		
		}
		for(int i=0;i<2;i++)
		{
			car_wt.caryear=car_wt.caryear*10+(buffer[i+10]-'0');
		
		}
		for(int i=0;i<2;i++)
		{
			car_wt.carmonth=car_wt.carmonth*10+(buffer[i+12]-'0');
		
		}
		for(int i=0;i<2;i++)
		{
			car_wt.cardate=car_wt.cardate*10+(buffer[i+14]-'0');
		
		}
		for(int i=0;i<2;i++)
		{
			car_wt.carhour=car_wt.carhour*10+(buffer[i+16]-'0');
		
		}
		for(int i=0;i<2;i++)
		{
			car_wt.carmin=car_wt.carmin*10+(buffer[i+18]-'0');
		
		}
		for(int i=0;i<2;i++)
		{
			car_wt.carsec=car_wt.carsec*10+(buffer[i+20]-'0');
		
		}
		if(car_wt.carsec>60|car_wt.carsec<0||car_wt.cardate>31||car_wt.cardate<0||car_wt.carhour>24||car_wt.carhour<0||car_wt.carmin>60||car_wt.carmin<0||car_wt.caryear>99||car_wt.caryear<0||car_wt.carmonth>12||car_wt.carmonth<0)
			flag4=1;
		//uint8_t buffer[100]={0};
		flag1=1;
		len1=0;
		//printf("%s:%s:%d%d%d%d%d%d\r\n",car_wait[1].cartype,car_wait[1].carnum,car_wt.caryear,car_wt.carmonth,car_wt.cardate,car_wt.carhour,car_wt.carmin,car_wt.carsec);
		
  }
 
 
 
 
 location=9-IDLE;
	if(IDLE<8)
	{
		for(int i=1;i<9;i++)//出库检测
		{
		if(strcmp(car_wait[1].cartype,car_in[i].cartype)==0&&strcmp(car_wait[1].carnum,car_in[i].carnum)==0&&strcmp(car_wait[1].cartype,car_wait[2].cartype)!=0)
			{
				flag3=1;
			  location=i;
				break;
			}
    
		
	 }
	}	
	for(int i=1;i<9;i++)//入库检测
{
 if(strcmp(car_wait[1].cartype,"CNBR")!=0&&strcmp(car_wait[1].cartype,"VNBR")!=0&&flag3==0)
		 {location=i;
			 flag2=1;
			 break;
		 }
	 }	
 if(flag1==1&&strcmp(car_wait[1].cartype,"CNBR")==0&&flag3==0&&flag2==1)//入库
	{
		for(int i=0;i<4;i++)
		{
			car_in[location].cartype[i]=car_wait[1].cartype[i];
			car_in[location].carnum[i]=car_wait[1].carnum[i];
		}
		car_it[location].caryear=car_wt.caryear;
		car_it[location].carmonth=car_wt.carmonth;
		car_it[location].cardate=car_wt.cardate;
		car_it[location].carhour=car_wt.carhour;
		car_it[location].carmin=car_wt.carmin;
		car_it[location].carsec=car_wt.carsec;
	
		//printf("%s:%s:%d%d%d%d%d%d\r\n",car_in[1].cartype,car_in[1].carnum,car_it[1].caryear,car_it[1].carmonth,car_it[1].cardate,car_it[1].carhour,car_it[1].carmin,car_it[1].carsec);	
	HAL_Delay(300);
		CNBRnum++;
		car_wait[1]=car_wait[2];
		 
	flag2=0;
   flag1=0;
		memset(&car_wt,0,(sizeof(car_wt)));
	}
	 if(flag1==1&&strcmp(car_wait[1].cartype,"VNBR")==0&&flag3==0&&flag2==1)//入库
	{
		for(int i=0;i<4;i++)
		{
			car_in[location].cartype[i]=car_wait[1].cartype[i];
			car_in[location].carnum[i]=car_wait[1].carnum[i];
		}
		car_it[location].caryear=car_wt.caryear;
		car_it[location].carmonth=car_wt.carmonth;
		car_it[location].cardate=car_wt.cardate;
		car_it[location].carhour=car_wt.carhour;
		car_it[location].carmin=car_wt.carmin;
		car_it[location].carsec=car_wt.carsec;
		HAL_Delay(300);
//	printf("%s:%s:%d%d%d%d%d%d\r\n",car_in[1].cartype,car_in[1].carnum,car_it[1].caryear,car_it[1].carmonth,car_it[1].cardate,car_it[1].carhour,car_it[1].carmin,car_it[1].carsec);	
	 VNBRnum++;
		car_wait[1]=car_wait[2];
		flag2=0;
   flag1=0;
		memset(&car_wt,0,(sizeof(car_wt)));
		
	}


		
		
		
		
		
		
	
		if(strcmp(car_wait[1].cartype,"CNBR")==0&&flag3==1)
		{	
			carmoney=fee1*((-car_it[location].caryear+car_wt.caryear)*365*24+(-car_it[location].carmonth+car_wt.carmonth)*30*24+(car_wt.cardate-car_it[location].cardate)*24+(car_wt.carhour-car_it[location].carhour)+((car_wt.carmin-car_it[location].carmin)*60+(car_wt.carsec-car_it[location].carsec))/3600+1);
		  carhour=carmoney/fee1;
			printf("%s:%s:%d:%.2f",car_wait[1].cartype,car_wait[1].carnum,carhour,carmoney);
			car_wait[1]=car_wait[2];
		car_in[location]=car_wait[2];
				memset(&car_wt,0,(sizeof(car_wt)));
				memset(&car_it[location],0,(sizeof(car_it[location])));
			carmoney=0;
			carhour=0;
			CNBRnum--;
			flag3=0;
		}
		if(strcmp(car_wait[1].cartype,"VNBR")==0&&flag3==1)	
		{
			
			carmoney=fee2*((-car_it[location].caryear+car_wt.caryear)*365*24+(-car_it[location].carmonth+car_wt.carmonth)*30*24+(car_wt.cardate-car_it[location].cardate)*24+(car_wt.carhour-car_it[location].carhour)+((car_wt.carmin-car_it[location].carmin)*60+(car_wt.carsec-car_it[location].carsec))/3600+1);
      carhour=carmoney/fee2;		
			printf("%s:%s:%d:%.2f",car_wait[1].cartype,car_wait[1].carnum,carhour,carmoney);
			car_wait[1]=car_wait[2];
		car_in[location]=car_wait[2];
				memset(&car_wt,0,(sizeof(car_wt)));
			memset(&car_it[location],0,(sizeof(car_it[location])));
				carmoney=0;
			carhour=0;
			CNBRnum--;
			flag3=0;
		}
		if(flag4==1)
		{
		printf("Error");
			flag4=0;
			buffer[0]=0;
		}
}

IDLE中断配置:

void USART1_IRQHandler(void)
{
  /* USER CODE BEGIN USART1_IRQn 0 */
if(__HAL_UART_GET_FLAG(&huart1,UART_FLAG_IDLE)!=RESET)
{
   __HAL_UART_CLEAR_IDLEFLAG(&huart1);
    HAL_UART_DMAStop(&huart1);
uint8_t len=120-__HAL_DMA_GET_COUNTER(huart1.hdmarx);
	//printf("k%d",len);
len1=len;

	HAL_UART_Receive_DMA(&huart1,buffer,120);
}
  /* USER CODE END USART1_IRQn 0 */
  HAL_UART_IRQHandler(&huart1);
  /* USER CODE BEGIN USART1_IRQn 1 */

  /* USER CODE END USART1_IRQn 1 */
}

完整项目已开源至码云:小恐龙/stm - Gitee.com

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值