欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

基于C语言的NMEA-0183解析程序(四)

程序员文章站 2022-07-12 21:56:40
...

实现条件筛选容错输入

#ifndef _CONDITION_H_
#define _CONDITION_H_

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>

/******************************************************************************
 *  Function    -  Location state condition fault tolerant input
 *
 *  Purpose     -  定位状态筛选条件容错输入
 *
 *  Description -  定位是否有效
 *
 * modification history
 * ----------------------------------------
 * v1.0  , 2018-12-27,  zhanglixv  written
 * ----------------------------------------
 ******************************************************************************/
char Condition_Locate(void)
{
	char avhemi_;
	printf("是否有效定位(A/V/C):");
	while (1)
	{
		scanf("%c", &avhemi_);
		if (!isalpha(avhemi_))
		/*if (!scanf("%c", &avhemi_))*/
		{
			printf("The condition data you input is illegal.Please input a alphabet:");
			while (getchar() != '\n');
		}
		else if (!isupper(avhemi_))/*islower(avhemi_)*/
		{
			printf("The alphabet you input is lower case.Please input a upper case:");
			while (getchar() != '\n');
		}
		else if ((avhemi_ != 'A') && (avhemi_ != 'V') && (avhemi_ != 'C'))
		{
			printf("The condition data you input is illegal.Please input again:");
			while (getchar() != '\n');
		}
		else
		{
			setbuf(stdin, NULL);
			break;
		}
	}
	return avhemi_;
}

/******************************************************************************
 *  Function    -  Speed threshold condition fault tolerant input
 *
 *  Purpose     -  速度阈值筛选条件容错输入
 *
 *  Description -  +/-:大于/小于
 *
 * modification history
 * ----------------------------------------
 * v1.0  , 2018-12-26,  zhanglixv  written
 * ----------------------------------------
 ******************************************************************************/
float Condition_Speed(void)
{
	float speed_;
	printf("定位物体速度阈值(+/-):");
	while (1)
	{
		if (!scanf("%f", &speed_))/*字母开头,返回0,非0为1*/
		{
			printf("The condition data you input is illegal.Please input again:");
			while (getchar() != '\n');/*等待回车结束输入*/
		}
		else if (getchar() != '\n')/*数字开头后面没接回车//继续输入字符变量*/
		{
			printf("The condition data you input is illegal.Please input again:");
			while (getchar() != '\n');
		}
		else if (speed_ < 0)/*数字开头后接回车//负数*/
			printf("The condition data you input is illegal.Please input again:");
		else
		{
			setbuf(stdin, NULL);/*使stdin输入流由默认缓冲区转为无缓冲区*/
			break; /*数字开头后接回车(正数)*/
		}
	}
	return speed_;
}

/******************************************************************************
 *  Function    -  Positioning satellite number condition fault tolerant input
 *
 *  Purpose     -  定位卫星颗数筛选条件容错输入
 *
 *  Description -  +/-:大于/小于
 *
 * modification history
 * ----------------------------------------
 * v1.0  , 2018-12-26,  zhanglixv  written
 * ----------------------------------------
 ******************************************************************************/
int Condition_Svnum(void)
{
	int svnum_;
	printf("参与定位卫星颗数(+/-):");
	while (1)
	{
		if (!scanf("%d", &svnum_))
		{
			printf("The condition data you input is illegal.Please input again:");
			while (getchar() != '\n');
		}
		else if (getchar() != '\n')
		{
			printf("The condition data you input is illegal.Please input again:");
			while (getchar() != '\n');
		}
		else if (svnum_ < 0)
			printf("The condition data you input is illegal.Please input again:");
		else
		{
			setbuf(stdin, NULL);
			break;
		}
	}
	return svnum_;
}

/******************************************************************************
 *  Function    -  Satellite signal to noise ratio condition fault tolerant input
 *
 *  Purpose     -  卫星信号强度筛选条件容错输入
 *
 *  Description -  +/-:大于/小于(dB)
 *
 * modification history
 * ----------------------------------------
 * v1.0  , 2018-12-26,  zhanglixv  written
 * ----------------------------------------
 ******************************************************************************/
int Condition_Sn(void)
{
	int sn_;
	printf("卫星信号强度阈值(+/-):");
	while (1)
	{
		if (!scanf("%d", &sn_))
		{
			printf("The condition data you input is illegal.Please input again:");
			while (getchar() != '\n');
		}
		else if (getchar() != '\n')
		{
			printf("The condition data you input is illegal.Please input again:");
			while (getchar() != '\n');
		}
		else if (sn_ < 0)
			printf("The condition data you input is illegal.Please input again:");
		else
		{
			setbuf(stdin, NULL);
			break;
		}
	}
	return sn_;
}

#endif // _CONDITION_H_

 

相关标签: C GPS NMEA-0183