void Analyzer_Position_Estimate_Divergence::evaluate_estimate(
    const std::string name,
    AnalyzerVehicle::Position position,
    AnalyzerVehicle::Position estimate)
{
    if (estimate.lat_modtime() == 0) {
        // No estimate for this  yet
        return;
    }
    double delta = estimate.horizontal_distance_to(position);

    bool failing = (delta > delta_warn());
    // ::fprintf(stderr, "%s: delta=%f delta_warn=%f: %s\n", name.c_str(), delta, delta_warn(), failing ? "FAILING" : "");

    if (_result.count(name) == 0 ||
        _result[name] == NULL) {
        // no current problem
        if (failing) {
            open_result(name, delta);
        }
    } else {
        // problem currently underway
        if (failing) {
            update_result(name, delta);
        } else {
            close_result(name);
        }
    }
}
Ejemplo n.º 2
0
bool sql_connecter::exe_query(const string &sql)
{
	if(mysql_query(_mysql_conn, sql.c_str()) != 0){
		cout<<mysql_error(_mysql_conn)<<endl;
		return false;
	}
	//从MYSQL句柄中提取出查询结果

	_res = mysql_store_result(_mysql_conn);
	int row_num = mysql_num_rows(_res);//查询结果集行数
	cout<<"共查询到:"<<row_num<<"行。"<<endl;
	int field_num = mysql_num_fields(_res);//查询结果集列数
	cout<<"共有:"<<field_num<<"列。"<<endl;
	
	MYSQL_FIELD *fd = NULL;//打印列名
	for(; fd=mysql_fetch_field(_res);){
		cout<<fd->name<<"\t";
	}
	cout<<endl;

	for(int index=0; index < row_num; ++index){//外层控制打印多少行的信息
		MYSQL_ROW _row = mysql_fetch_row(_res);//获取结果集的一行信息
		if(_row){//如果获取的信息不为空
			int start = 0;
			for(; start < field_num; ++start){
				cout<<_row[start]<<'\t';//依次打印一行中的每一列的信息
			}
			cout<<endl;
		}
	}
	cout<<endl;
	close_result();
	return true;
}
void Analyzer_Sensor_Health::end_of_log(uint32_t packet_count UNUSED)
{
    std::map<const std::string, bool> sensors_health = _vehicle->sensors_health();

    bool have = false;
    for (std::map<const std::string, bool>::const_iterator it = sensors_health.begin();
         it != sensors_health.end();
         ++it) {
        // ::fprintf(stderr, "would evaluate (%s)\n", (*it).first.c_str());
        std::string name = (*it).first;
        if (_results[name] != NULL) {
            close_result(name);
        }
        have = true;
    }

    if (!have) {
        Analyzer_Result_Summary *summary = new Analyzer_Result_Summary();
        summary->set_status(analyzer_status_warn);
        summary->set_reason("Sensor health never updated");
        summary->add_source(_data_sources.get("SENSORS_HEALTH"));
        add_result(summary);
    }

}
void Analyzer_Attitude_Estimate_Divergence::evaluate_estimate(
    std::string name,
    AnalyzerVehicle::Attitude attitude,
    AnalyzerVehicle::Attitude estimate)
{
    if (estimate.roll_modtime() == 0) {
        // No estimate for this  yet
        return;
    }

    double delta_roll = fabs(angle_delta(estimate.roll(), attitude.roll()));
    double delta_pitch = fabs(angle_delta(estimate.pitch(), attitude.pitch()));
    // double delta_yaw = estimate.yaw() - attitude.yaw();

    double delta = delta_roll > delta_pitch ? delta_roll : delta_pitch;

    bool failing = (delta >= delta_warn());
    if (_result[name] == NULL) {
        if (failing) {
            open_result(name, delta);
        }
    } else {
        if (failing) {
            update_result(name, delta);
        } else {
            close_result(name);
        }
    }
}
Ejemplo n.º 5
0
sql_connecter::~sql_connecter()
{
	if(this->_mysql_conn != NULL){//只有连接成功才进行关闭操作
		close_connect();
	}
	//结果集使用完毕必须free负责会造成内存泄露
	close_result();
}
Ejemplo n.º 6
0
void lily_pg_result_close(lily_vm_state *vm, uint16_t argc, uint16_t *code)
{
    lily_value *to_close_reg = vm->vm_regs[code[1]];
    lily_pg_result *to_close = (lily_pg_result *)to_close_reg->value.generic;

    close_result(to_close_reg);
    to_close->row_count = 0;
}
void Analyzer_Estimate_Divergence::end_of_log(const uint32_t packet_count UNUSED)
{
    auto next = _result.begin();
    while (next != _result.end()) {
        auto current = next;
        next++;
        if ((*current).second != NULL) {
            close_result((*current).first);
        }
    }
}
void Analyzer_Sensor_Health::evaluate()
{
    std::map<const std::string, bool> sensors_health = _vehicle->sensors_health();

    for (std::map<const std::string, bool>::const_iterator it = sensors_health.begin();
         it != sensors_health.end();
         ++it) {
        std::string name = (*it).first;
        // ::fprintf(stderr, "would evaluate (%s)\n", name.c_str());
        if ((*it).second) {
            if (_results[name] != NULL) {
                close_result(name);
            }
        } else {
            if (_results[name] == NULL) {
                open_result(name);
            }
        }
    }
}
Ejemplo n.º 9
0
int sql_connecter::exe_update(const string &sql)
{
	int eft_num = -1;
	_res = mysql_store_result(_mysql_conn);
	close_result();

	if( (eft_num = mysql_query(_mysql_conn, sql.c_str())) != 0){
	//	cout<<"update error!\n"<<endl;
		cout<<"<p> database error:"<<mysql_error(_mysql_conn)<<"</p>"<<endl;
		return eft_num;
	}

	_res = mysql_store_result(_mysql_conn);
	eft_num = mysql_affected_rows(_mysql_conn);//get affected rows

	if(_res != NULL){//if null, not query sql
		mysql_free_result(_res);
	}
	//cout<<"update success affected "<<eft_num<<" rows.\n"<<endl;

	return eft_num;
}
void Analyzer_Velocity_Estimate_Divergence::evaluate_estimate(
    const std::string name,
    AnalyzerVehicle::Velocity &velocity,
    AnalyzerVehicle::Velocity &estimate)
{
    if (estimate.velocity_modtime() == 0) {
        // No estimate for this  yet
        return;
    }

    // make sure we're comparing apples with apples:
    double velocity_size;
    if (estimate.is_2d()) {
        velocity_size = velocity.size_2d();
    } else {
        velocity_size = velocity.size();
    }
    double delta = estimate.size() - velocity_size;
    // ::fprintf(stderr, "delta: %f\n", delta);

    bool failing = (delta > delta_warn());
    // ::fprintf(stderr, "%s: delta=%f delta_warn=%f: %s\n", name.c_str(), delta, delta_warn(), failing ? "FAILING" : "");

    if (_result.count(name) == 0 ||
        _result[name] == NULL) {
        // no current problem
        if (failing) {
            open_result(name, delta);
        }
    } else {
        // problem currently underway
        if (failing) {
            update_result(name, delta);
        } else {
            close_result(name);
        }
    }
}
Ejemplo n.º 11
0
void destroy_result(lily_value *v)
{
    close_result(v);
    lily_free(v->value.generic);
}