One Framework 0.1.0
RoboMaster嵌入式框架“一键”解决方案,为你的“创意”服务。
载入中...
搜索中...
未找到
Node.hpp
浏览该文件的文档.
1#ifndef OF_LIB_NODE_HPP
2#define OF_LIB_NODE_HPP
3
4#include <concepts>
5
6#include <zephyr/logging/log.h>
7
8#include "Macro.hpp"
9
10namespace OF
11{
12
13 template <typename T>
14 concept NodeConcept = requires
15 {
16 { T::Meta::stack_size } -> std::convertible_to<size_t>;
17 { T::Meta::priority } -> std::convertible_to<int>;
18 { T::Meta::name } -> std::convertible_to<const char*>;
19 { std::declval<T>().init() } -> std::same_as<bool>;
20 { std::declval<T>().run() } -> std::same_as<void>;
21 { std::declval<T>().cleanup() } -> std::same_as<void>;
22 };
23
24 template <typename Derived>
25 class Node
26 {
27 public:
28 static void zephyr_entry_point(void* p1, void*, void*)
29 {
30 LOG_MODULE_DECLARE(NodeSystem, CONFIG_NODE_LOG_LEVEL);
31 auto* node = static_cast<Derived*>(p1);
32
33 if (!node->init())
34 {
35 LOG_ERR("Node %s failed to init", Derived::Meta::name);
36 return;
37 }
38
39 node->run();
40
41 node->cleanup();
42 }
43
44 static void start_impl(k_thread* thread_data, k_thread_stack_t* stack_area)
45 {
46 k_tid_t tid = k_thread_create(thread_data, stack_area, Derived::Meta::stack_size, zephyr_entry_point,
47 &instance(), nullptr,
48 nullptr, Derived::Meta::priority, 0, K_NO_WAIT);
49 k_thread_name_set(tid, Derived::Meta::name);
50 Derived::tid_storage = tid;
51 }
52
53 template <typename ConfigType>
54 static void bind(const ConfigType& cfg)
55 {
56 Derived::config = cfg;
57 }
58
59 static Derived& instance()
60 {
61 static Derived instance;
62 return instance;
63 }
64
65 inline static k_tid_t tid_storage = nullptr;
66 };
67}
68
69#endif //OF_LIB_NODE_HPP
定义 Node.hpp:26
static void zephyr_entry_point(void *p1, void *, void *)
定义 Node.hpp:28
static k_tid_t tid_storage
定义 Node.hpp:65
static void bind(const ConfigType &cfg)
定义 Node.hpp:54
static void start_impl(k_thread *thread_data, k_thread_stack_t *stack_area)
定义 Node.hpp:44
static Derived & instance()
定义 Node.hpp:59
定义 Node.hpp:14
定义 Mecanum.hpp:6