当前位置: 首页>>代码示例>>C++>>正文


C++ Actuator::sanity方法代码示例

本文整理汇总了C++中Actuator::sanity方法的典型用法代码示例。如果您正苦于以下问题:C++ Actuator::sanity方法的具体用法?C++ Actuator::sanity怎么用?C++ Actuator::sanity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Actuator的用法示例。


在下文中一共展示了Actuator::sanity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Actuator_Handler

/**
 * Handle a request for an Actuator
 * @param context - FCGI context
 * @param params - Parameters passed
 */
void Actuator_Handler(FCGIContext * context, char * params)
{
	struct timespec now;
	clock_gettime(CLOCK_MONOTONIC, &now);
	double current_time = TIMEVAL_DIFF(now, *Control_GetStartTime());
	int id = 0;
	char * name = "";
	char * set = "";
	double start_time = 0;
	double end_time = current_time;
	char * fmt_str;

	// key/value pairs
	FCGIValue values[] = {
		{"id", &id, FCGI_INT_T},
		{"name", &name, FCGI_STRING_T}, 
		{"set", &set, FCGI_STRING_T},
		{"start_time", &start_time, FCGI_DOUBLE_T},
		{"end_time", &end_time, FCGI_DOUBLE_T},
		{"format", &fmt_str, FCGI_STRING_T}
	};

	// enum to avoid the use of magic numbers
	typedef enum {
		ID,
		NAME,
		SET,
		START_TIME,
		END_TIME,
		FORMAT
	} ActuatorParams;
	
	// Fill values appropriately
	if (!FCGI_ParseRequest(context, params, values, sizeof(values)/sizeof(FCGIValue)))
	{
		// Error occured; FCGI_RejectJSON already called
		return;
	}	

	// Get the Actuator identified
	Actuator * a = NULL;

	if (FCGI_RECEIVED(values[NAME].flags))
	{
		if (FCGI_RECEIVED(values[ID].flags))
		{
			FCGI_RejectJSON(context, "Can't supply both id and name");
			return;
		}
		a = Actuator_Identify(name);
		if (a == NULL)
		{
			FCGI_RejectJSON(context, "Unknown actuator name");
			return;
		}
		
	}
	else if (!FCGI_RECEIVED(values[ID].flags))
	{
		FCGI_RejectJSON(context, "No id or name supplied");
		return;
	}
	else if (id < 0 || id >= g_num_actuators)
	{
		FCGI_RejectJSON(context, "Invalid Actuator id");
		return;
	}
	else
	{
		a = &(g_actuators[id]);
	}
	

	DataFormat format = Data_GetFormat(&(values[FORMAT]));




	if (FCGI_RECEIVED(values[SET].flags))
	{
		
	
		ActuatorControl c = {0.0, 0.0, 0.0, 0}; // Need to set default values (since we don't require them all)
		// sscanf returns the number of fields successfully read...
		int n = sscanf(set, "%lf,%lf,%lf,%d", &(c.start), &(c.stepwait), &(c.stepsize), &(c.steps)); // Set provided values in order
		if (n != 4)
		{
			//	If the user doesn't provide all 4 values, the Actuator will get set *once* using the first of the provided values
			//	(see Actuator_Loop)
			//  Not really a problem if n = 1, but maybe generate a warning for 2 <= n < 4 ?
			Log(LOGDEBUG, "Only provided %d values (expect %d) for Actuator setting", n, 4);
		}
		// SANITY CHECKS
		if (c.stepwait < 0 || c.steps < 0 || (a->sanity != NULL && !a->sanity(a->user_id, c.start)))
		{
//.........这里部分代码省略.........
开发者ID:firefields,项目名称:MCTX3420,代码行数:101,代码来源:actuator.c


注:本文中的Actuator::sanity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。