11 #ifndef _UGCS_VSM_VEHICLE_H_
12 #define _UGCS_VSM_VEHICLE_H_
18 #include <ugcs/vsm/device.h>
19 #include <ugcs/vsm/crc32.h>
23 #include <unordered_map>
31 static constexpr
int DEFAULT_COMMAND_TRY_COUNT = 3;
32 static constexpr std::chrono::milliseconds DEFAULT_COMMAND_TIMEOUT(1000);
55 proto::Device_type type = proto::DEVICE_TYPE_VEHICLE,
108 Get_vehicle_type()
const;
112 Set_vehicle_type(proto::Vehicle_type);
115 Is_vehicle_type(proto::Vehicle_type type);
119 return vehicle_type == proto::VEHICLE_TYPE_HELICOPTER || vehicle_type == proto::VEHICLE_TYPE_MULTICOPTER;
130 return hasher(ptr.get());
134 static std::hash<Vehicle*> hasher;
138 Optional<proto::Flight_mode> current_flight_mode;
237 int command_try_count = DEFAULT_COMMAND_TRY_COUNT;
238 std::chrono::milliseconds command_timeout = DEFAULT_COMMAND_TIMEOUT;
263 Set_rc_loss_actions(std::initializer_list<proto::Failsafe_action> actions);
267 Set_gps_loss_actions(std::initializer_list<proto::Failsafe_action> actions);
271 Set_low_battery_actions(std::initializer_list<proto::Failsafe_action> actions);
275 Set_rth_actions(std::initializer_list<proto::Rth_action> actions);
310 const std::string& status_text,
316 const std::string& status_text,
317 proto::Status_code code = proto::STATUS_FAILED);
342 Is_flight_mode(proto::Flight_mode);
346 Is_control_mode(proto::Control_mode m);
375 Set_current_command(
int mission_command_id);
381 Add_command_mapping(
int vehicle_specific_id);
394 Accumulate_route_id(uint32_t hash);
403 Set_secondary_id(uint32_t);
407 Fill_command_mapping_response(Proto_msg_ptr response);
411 int current_mission_command = -1;
413 std::unordered_map<int, int> mission_command_map;
415 uint32_t secondary_id = 0;
423 Set_autopilot_type(
const std::string&);
426 Set_autopilot_serial(
const std::string&);
433 template<
class Request_ptr>
435 Submit_vehicle_request(Request_ptr vehicle_request)
437 using Request =
typename Request_ptr::element_type;
438 using Handle =
typename Request::Handle;
439 typedef void (
Vehicle::*Handler)(Handle);
444 Handle(vehicle_request));
445 vehicle_request->request->Set_processing_handler(proc_handler);
446 processor->Submit_request(vehicle_request->request);
450 Optional<float> current_altitude_origin;
455 friend class Ucs_vehicle_ctx;
456 friend class Ucs_transaction;
457 friend class Ucs_mission_clear_all_transaction;
458 friend class Ucs_task_upload_transaction;
459 friend class Ucs_vehicle_command_transaction;
463 proto::Vehicle_type vehicle_type = proto::VEHICLE_TYPE_MULTICOPTER;
466 std::string serial_number;
469 std::string model_name;
472 std::string port_name;
475 std::string frame_type;
479 std::string vehicle_serial_prefix;
484 #define VEHICLE_LOG(level_, vehicle_, fmt_, ...) \
485 _LOG_WRITE_MSG(level_, "[%s:%s] " fmt_, \
486 (vehicle_).Get_model_name().c_str(), \
487 (vehicle_).Get_serial_number().c_str(), ## __VA_ARGS__)
492 #define VEHICLE_LOG_DBG(vehicle_, fmt_, ...) \
493 VEHICLE_LOG(::ugcs::vsm::Log::Level::DEBUGGING, vehicle_, fmt_, ## __VA_ARGS__)
495 #define VEHICLE_LOG_INF(vehicle_, fmt_, ...) \
496 VEHICLE_LOG(::ugcs::vsm::Log::Level::INFO, vehicle_, fmt_, ## __VA_ARGS__)
498 #define VEHICLE_LOG_WRN(vehicle_, fmt_, ...) \
499 VEHICLE_LOG(::ugcs::vsm::Log::Level::WARNING, vehicle_, fmt_, ## __VA_ARGS__)
501 #define VEHICLE_LOG_ERR(vehicle_, fmt_, ...) \
502 VEHICLE_LOG(::ugcs::vsm::Log::Level::ERROR, vehicle_, fmt_, ## __VA_ARGS__)
Generic request for implementing inter-threads communications and asynchronous operations.
Definition: request_container.h:37
MAVLink protocol messages.
std::shared_ptr< Property > Ptr
Pointer type.
Definition: property.h:18
void Set_frame_type(const std::string &)
Set frame type of the vehicle.
virtual void On_disable()
Vehicle disable event handler.
Definition: vehicle.h:258
Definition: vehicle.h:363
Hasher for Vehicle shared pointer.
Definition: vehicle.h:125
void Set_port_name(const std::string &)
Set port name.
size_t operator()(const Vehicle::Ptr &ptr) const
Get hash value.
Definition: vehicle.h:129
virtual void On_enable()
Vehicle enable event handler.
Definition: vehicle.h:251
const std::string & Get_model_name() const
Get model name of the vehicle.
void Set_altitude_origin(float altitude_amsl)
Tell server that Vehicle knows its altitude_origin.
Request execution context.
Definition: request_context.h:24
void Set_model_name(const std::string &)
Set model name of the vehicle.
const std::string & Get_port_name() const
Get port name the vehicle is connected to.
Result
Request completion result.
Definition: vehicle_request.h:26
std::shared_ptr< Vehicle > Ptr
Pointer type.
Definition: vehicle.h:40
Callback< Callable, void, Args...>::Ptr Make_callback(Callable &&callable, Args &&...args)
Create a callback.
Definition: callback.h:391
Vehicle(proto::Device_type type=proto::DEVICE_TYPE_VEHICLE, Request_processor::Ptr processor=nullptr, Request_completion_context::Ptr completion_ctx=nullptr)
Constructor for a base class.
Handle of a specific vehicle request.
Definition: vehicle_request.h:156
Handles interactions with CUCS.
Definition: cucs_processor.h:34
std::shared_ptr< Vsm_command > Ptr
Pointer type.
Definition: subsystem.h:24
virtual void Handle_ucs_command(Ucs_request::Ptr ucs_request)
Message from ucs arrived.
std::shared_ptr< Device > Ptr
Pointer type.
Definition: device.h:56
const std::string & Get_serial_number() const
Get serial number of the vehicle.
void Process_requests()
Process requests assigned to vehicle in user thread, i.e.
virtual void Handle_vehicle_request(Vehicle_task_request::Handle request)
Task has arrived from UCS and should be uploaded to the vehicle.
std::shared_ptr< Subsystem > Ptr
Pointer type.
Definition: subsystem.h:88
#define DEFINE_COMMON_CLASS(__class_name,...)
Use this macro to define some common attributes for a class.
Definition: utils.h:25
void Reset_altitude_origin()
Tell server that current altitude origin must be dropped.
Convenience types for all specific vehicle requests.
void Set_serial_number(const std::string &)
Set serial number.
std::shared_ptr< Ucs_request > Ptr
Pointer type.
Definition: device.h:24
const std::string & Get_frame_type() const
Get frame type of the vehicle.
Base class for user-defined vehicles.
Definition: vehicle.h:39