source: flair-src/branches/mavlink/lib/FlairMeta/src/UavFactory.cpp@ 83

Last change on this file since 83 was 41, checked in by Sanahuja Guillaume, 8 years ago

m

File size: 2.3 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5// created: 2016/02/05
6// filename: UavFactory.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: construct a Uav based on the type name
14//
15//
16/*********************************************************************/
17
18#include "UavFactory.h"
19#include "FrameworkManager.h"
20//#include "ArDrone2.h"
21#include "SimuX4.h"
22#include "SimuX8.h"
23#include "HdsX8.h"
24#include "XAir.h"
25
26using namespace std;
27using namespace flair::core;
28using namespace flair::filter;
29using namespace flair::meta;
30
31namespace { // anonymous
32 vector<flair::meta::Uav* (*)(FrameworkManager*,string,string,UavMultiplex*)> vectoroffunctions;
33}
34
35Uav *CreateUav(FrameworkManager *parent, string uav_name, string uav_type,
36 UavMultiplex *multiplex) {
37
38 Uav *uav;
39 for(int i=0;i<vectoroffunctions.size();i++) {
40 uav=vectoroffunctions.at(i)(parent, uav_name, uav_type,multiplex);
41 if(uav!=NULL) return uav;
42 }
43
44 if (uav_type == "hds_x4") {
45 parent->Err("UAV type %s not yet implemented\n", uav_type.c_str());
46 return NULL;
47 } else if (uav_type == "hds_x8") {
48 return new HdsX8(parent, uav_name, multiplex);
49 } else if (uav_type == "xair") {
50 return new XAir(parent, uav_name, multiplex);
51 } else if (uav_type == "hds_xufo") {
52 parent->Err("UAV type %s not yet implemented\n", uav_type.c_str());
53 return NULL;
54 } else if (uav_type.compare(0, 7, "x4_simu") == 0) {
55 int simu_id = 0;
56 if (uav_type.size() > 7) {
57 simu_id = atoi(uav_type.substr(7, uav_type.size() - 7).c_str());
58 }
59 return new SimuX4(parent, uav_name, simu_id, multiplex);
60 } else if (uav_type.compare(0, 7, "x8_simu") == 0) {
61 int simu_id = 0;
62 if (uav_type.size() > 7) {
63 simu_id = atoi(uav_type.substr(7, uav_type.size() - 7).c_str());
64 }
65 return new SimuX8(parent, uav_name, simu_id, multiplex);
66 } else {
67 parent->Err("UAV type %s unknown\n", uav_type.c_str());
68 return NULL;
69 }
70}
71
72void RegisterUavCreator(flair::meta::Uav*(*func)(FrameworkManager *parent, string uav_name, string uav_type,
73 UavMultiplex *multiplex)) {
74 vectoroffunctions.push_back(func);
75
76}
Note: See TracBrowser for help on using the repository browser.