Motorcortex Core  version: 2.7.6
ps_link.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2021 VECTIONEER.
4  */
5 
6 #ifndef MOTORCORTEX_CORE_PS_LINK_H
7 #define MOTORCORTEX_CORE_PS_LINK_H
8 
9 #include "cmdline_field.h"
10 #include "cmdline_systemmode.h"
11 #include "nlohmann/json.hpp"
12 #include "ps_paramtype.h"
13 #include "ps_setparam.h"
14 #include <future>
15 #include <vector>
16 
17 namespace mcx::parameter_server {
18 
19 class Parameter;
20 
21 struct Link {
22  ParameterPath source;
23  ParameterPath destination;
24  double gain{1.0};
25  double offset{0.0};
26  bool inv_bool{false};
27  bool enable{true};
28 };
29 
30 struct LinkGroup {
31  std::string name;
32  mcx::cmd_line::SystemMode system_mode{mcx::cmd_line::SystemMode::ALL_MODES};
33  bool enable{true};
34  std::vector<Link> links;
35  std::vector<SetParam> set_params;
36 };
37 
38 using LinkGroups = typename std::vector<LinkGroup>;
39 
40 class Linking {
41 public:
42  LinkGroups load(const std::string& file_name);
43  static bool link(const LinkGroups& links, Parameter* root, cmd_line::SystemMode system_mode);
44  static bool setParameters(const LinkGroups& linking_groups, Parameter* root, cmd_line::SystemMode system_mode);
45 
46 private:
47  static const std::map<std::string, mcx::cmd_line::FieldDesc>& getFields();
48  static std::string buildPathAndCheck(const std::string& path, size_t index, Parameter* root);
49  static bool linkDestWithWildcard(const Link& l, Parameter* root);
50  static bool linkSrcWithWildcard(const Link& l, Parameter* root);
51  static bool linkBothWithWildcard(const Link& l, Parameter* root);
52  static bool performLinking(const LinkGroup& links, Parameter* root);
53  LinkGroups loadGroups(const nlohmann::json& root) const;
54  LinkGroup loadGroup(const nlohmann::json& group) const;
55  Link loadLink(const nlohmann::json& link) const;
56  SetParam loadSetParam(const nlohmann::json& set_param) const;
57  ParameterPath loadParameterPath(const nlohmann::json& param_path) const;
58  std::string path_;
59 };
60 
61 bool link(const std::string& file_name, Parameter* root, cmd_line::SystemMode system_mode);
62 
63 } // namespace mcx::parameter_server
64 
65 #endif // MOTORCORTEX_CORE_PS_LINK_H
mcx::parameter_server::ParameterPath
Definition: ps_paramtype.h:17
mcx::parameter_server::Parameter
Definition: ps_parameter.h:45
mcx::parameter_server::SetParam
Definition: ps_setparam.h:16
mcx::parameter_server::Linking
Definition: ps_link.h:40
mcx::parameter_server::LinkGroup
Definition: ps_link.h:30