libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR Namespace Reference

LibXR Color Control Library / LibXR终端颜色控制库 More...

Data Structures

class  ADC
 模拟数字转换器(ADC)基类 More...
 
class  Application
 应用模块抽象类,需实现 OnMonitor 方法 More...
 
class  ApplicationManager
 应用模块管理器 More...
 
class  Assert
 运行时错误检查的断言工具类。 Provides assertion mechanisms for runtime error checking. More...
 
class  ASync
 异步任务处理类。 Asynchronous task processing class. More...
 
class  Axis
 三维坐标轴类,继承自 Eigen::Matrix<Scalar, 3, 1>。 A 3D axis class, inheriting from Eigen::Matrix<Scalar, 3, 1>. More...
 
class  BaseQueue
 基础队列类,提供固定大小的循环缓冲区 (Base queue class providing a fixed-size circular buffer). More...
 
class  Callback
 提供一个通用的回调包装,支持动态参数传递。 Provides a generic callback wrapper, supporting dynamic argument passing. More...
 
class  CallbackBlock
 提供一个回调函数的封装,实现参数绑定和回调执行。 Provides a wrapper for callback functions, enabling argument binding and invocation. More...
 
class  CAN
 CAN通信接口,定义标准CAN通信结构,支持不同类型的消息 (CAN communication interface that defines a standard CAN structure supporting different message types). More...
 
class  CenterOfMass
 质心信息表示类。Represents the center of mass information. More...
 
class  ChunkQueue
 块队列(ChunkQueue)用于存储和管理数据块 ChunkQueue is used to store and manage chunks of data More...
 
struct  condition_var_handle
 条件变量结构体定义,包含互斥锁和条件变量 Condition variable structure definition including a mutex and a condition variable More...
 
class  ConditionVar
 条件变量封装类 / Condition variable wrapper class More...
 
class  ConstRawData
 常量原始数据封装类。 A class for encapsulating constant raw data. More...
 
class  CRC16
 16 位循环冗余校验(CRC-16)计算类 / CRC-16 checksum computation class More...
 
class  CRC32
 32 位循环冗余校验(CRC-32)计算类 / CRC-32 checksum computation class More...
 
class  CRC8
 8 位循环冗余校验(CRC-8)计算类 / CRC-8 checksum computation class More...
 
class  CycleValue
 角度循环处理类,用于处理周期性角度计算。 A cyclic angle handling class for periodic angle calculations. More...
 
class  Database
 数据库接口,提供键值存储和管理功能 (Database interface providing key-value storage and management). More...
 
class  DatabaseRaw
 适用于最小写入单元受限的 Flash 存储的数据库实现 (Database implementation for Flash storage with minimum write unit restrictions). More...
 
class  DatabaseRawSequential
 适用于不支持逆序写入的 Flash 存储的数据库实现 (Database implementation for Flash storage that does not support reverse writing). More...
 
struct  Entry
 
class  EulerAngle
 表示欧拉角的类,用于描述3D旋转。Class representing Euler angles for 3D rotation. More...
 
class  Event
 事件管理系统,允许基于事件 ID 注册和触发回调函数。 Event management system that allows registration and triggering of callbacks based on event IDs. More...
 
class  FDCAN
 FDCAN 通信接口,扩展 CAN 功能,支持灵活数据速率(FD)CAN 消息 (FDCAN communication interface that extends CAN functionality by supporting Flexible Data-Rate (FD) CAN messages). More...
 
class  Flash
 Abstract base class representing a flash memory interface. 抽象基类,表示闪存接口。 More...
 
struct  FlashSector
 STM32Flash 通用类,构造时传入扇区列表,自动判断编程粒度。 More...
 
class  FloatEncoder
 浮点数编码器,将浮点值映射到定长无符号整数。 A generic float encoder mapping a float value to N-bit unsigned integer. More...
 
class  GPIO
 通用输入输出(GPIO)接口类。General Purpose Input/Output (GPIO) interface class. More...
 
class  HardwareContainer
 
struct  HasFlashBank
 
struct  HasFlashBank< T, std::void_t< decltype(std::declval< T >().Banks)> >
 
struct  HasFlashPage
 
struct  HasFlashPage< T, std::void_t< decltype(std::declval< T >().Page)> >
 
class  I2C
 I2C(Inter-Integrated Circuit)接口类。 I2C (Inter-Integrated Circuit) interface class. More...
 
class  Inertia
 表示刚体的惯性张量和质量信息的类。Provides a class to represent the inertia tensor and mass of a rigid body. More...
 
class  LinuxBinaryFileFlash
 LinuxBinaryFileFlash 类,用于从二进制文件加载闪存数据 LinuxBinaryFileFlash class for loading flash data from a binary file. More...
 
class  LinuxTimebase
 LinuxTimebase 类,用于获取 Linux 系统的时间基准。Provides a timebase for Linux systems. More...
 
class  LinuxUART
 
class  List
 链表实现,用于存储和管理数据节点。 A linked list implementation for storing and managing data nodes. More...
 
class  LockFreeQueue
 无锁队列实现 / Lock-free queue implementation More...
 
class  LockQueue
 线程安全的队列实现,基于 FreeRTOS 消息队列 Thread-safe queue implementation based on FreeRTOS message queue More...
 
struct  LogData
 日志数据结构体 / Log data structure More...
 
class  Logger
 LibXR 日志管理器 / LibXR Logger Manager. More...
 
class  Mutex
 互斥锁类,提供线程同步机制 (Mutex class providing thread synchronization mechanisms). More...
 
class  Operation
 Defines an operation with different execution modes. More...
 
class  PID
 通用 PID 控制器类。 Generic PID controller. More...
 
class  Position
 三维空间中的位置向量 / 3D position vector More...
 
class  PowerManager
 电源管理器基类 / Abstract base class for Power Manager More...
 
class  PWM
 Abstract base class for PWM (Pulse Width Modulation) control. PWM(脉冲宽度调制)控制的抽象基类。 More...
 
class  Quaternion
 四元数表示与运算,继承自 Eigen::Quaternion / Quaternion representation and operations, inheriting from Eigen::Quaternion More...
 
class  Queue
 基于 BaseQueue 的泛型队列模板类 (Generic queue template class based on BaseQueue). More...
 
class  RamFS
 轻量级的内存文件系统,实现基本的文件、目录和设备管理 A lightweight in-memory file system implementing basic file, directory, and device management More...
 
class  RawData
 原始数据封装类。 A class for encapsulating raw data. More...
 
class  RBTree
 红黑树实现,支持泛型键和值,并提供线程安全操作 (Red-Black Tree implementation supporting generic keys and values with thread-safe operations). More...
 
class  ReadInfoBlock
 Read information block structure. More...
 
class  ReadPort
 ReadPort class for handling read operations. More...
 
class  RotationMatrix
 旋转矩阵类,继承自 Eigen::Matrix<Scalar, 3, 3>。 Rotation matrix class, inheriting from Eigen::Matrix<Scalar, 3, 3>. More...
 
class  Semaphore
 信号量类,实现线程同步机制 Semaphore class implementing thread synchronization More...
 
class  Signal
 信号处理类,用于线程间的信号传递和同步。 Signal handling class for inter-thread signaling and synchronization. More...
 
class  SPI
 串行外设接口(SPI)抽象类。Abstract class for Serial Peripheral Interface (SPI). More...
 
class  SpinLock
 轻量级自旋锁实现 / Lightweight spinlock implementation More...
 
class  Stack
 线程安全的栈数据结构 / Thread-safe stack data structure More...
 
class  STDIO
 STDIO interface for read/write ports. More...
 
class  STM32ADC
 STM32ADC 类,用于处理 STM32 系统的 ADC 通道。 Provides handling for STM32 ADC channels. More...
 
class  STM32CAN
 STM32CAN 类,用于处理 STM32 系统的 CAN 通道。 Provides handling for STM32 CAN channels. More...
 
class  STM32CANFD
 STM32CANFD 类,用于处理 STM32 系统的 CANFD 通道。 Provides handling for STM32 CANFD. More...
 
class  STM32Flash
 STM32Flash 通用类,构造时传入扇区列表,自动判断编程粒度。 More...
 
class  STM32GPIO
 
class  STM32I2C
 
class  STM32PowerManager
 
class  STM32PWM
 
class  STM32SPI
 
class  STM32Timebase
 获取基于STM32 SysTick计数器的时间基准(微秒与毫秒) / Provides a timebase using STM32 SysTick timer (microseconds and milliseconds) More...
 
class  STM32TimerTimebase
 基于硬件定时器的时间基准类 / Provides a timebase using hardware timer (TIM) More...
 
class  STM32UART
 
class  STM32VirtualUART
 
class  String
 A fixed-length string class with safe operations. More...
 
class  Terminal
 终端类,实现一个基于 RamFS 的基本命令行接口 Terminal class implementing a basic command-line interface based on RamFS More...
 
class  Thread
 线程管理类,封装 FreeRTOS 任务创建和调度 Thread management class encapsulating FreeRTOS task creation and scheduling More...
 
class  Timebase
 时间基类,用于提供高精度时间戳。 Timebase class for providing high-precision timestamps. More...
 
class  Timer
 定时器类,实现周期性任务调度 Timer class for scheduling periodic tasks More...
 
class  TimestampMS
 表示毫秒级时间戳的类。Class representing a timestamp in milliseconds. More...
 
class  TimestampUS
 表示微秒级时间戳的类。Class representing a timestamp in microseconds. More...
 
class  Topic
 主题(Topic)管理类 / Topic management class More...
 
class  Transform
 表示三维空间中的刚体变换,包括旋转和位移。Represents rigid body transformations in 3D space, including rotation and translation. More...
 
class  UART
 通用异步收发传输(UART)基类 / Abstract base class for Universal Asynchronous Receiver-Transmitter (UART) More...
 
class  WritePort
 WritePort class for handling write operations. More...
 

Typedefs

typedef SemaphoreHandle_t libxr_mutex_handle
 互斥锁句柄类型定义 Mutex handle type definition
 
typedef SemaphoreHandle_t libxr_semaphore_handle
 信号量句柄类型定义 Semaphore handle type definition
 
typedef TaskHandle_t libxr_thread_handle
 线程句柄类型定义 Thread handle type definition
 
typedef SemaphoreHandle_t condition_var_handle
 
typedef Operation< ErrorCode > ReadOperation
 Read operation type.
 
typedef Operation< ErrorCode > WriteOperation
 Write operation type.
 
typedef ErrorCode(* WriteFun) (WritePort &port)
 Function pointer type for write operations.
 
typedef ErrorCode(* ReadFun) (ReadPort &port)
 Function pointer type for read operations.
 
using DefaultScalar = LIBXR_DEFAULT_SCALAR
 

Enumerations

enum class  Format : uint8_t {
  NONE = 0 , RESET , BOLD , DARK ,
  UNDERLINE , BLINK , REVERSE , CONCEALED ,
  CLEAR_LINE , COUNT
}
 Terminal text format (Format) / 终端文本格式 (Format) More...
 
enum class  Font : uint8_t {
  NONE = 0 , BLACK , RED , GREEN ,
  YELLOW , BLUE , MAGENTA , CYAN ,
  WHITE , COUNT
}
 Terminal font color (Font) / 终端字体颜色 (Font) More...
 
enum class  Background : uint8_t {
  NONE = 0 , BLACK , RED , GREEN ,
  YELLOW , BLUE , MAGENTA , CYAN ,
  WHITE , COUNT
}
 Terminal background color (Background) / 终端背景颜色 (Background) More...
 
enum class  Bold : uint8_t {
  NONE = 0 , YELLOW , RED , ON_RED ,
  COUNT
}
 Terminal bold style (Bold) / 终端粗体样式 (Bold) More...
 
enum class  LogLevel : uint8_t {
  XR_LOG_LEVEL_DEBUG = 0 , XR_LOG_LEVEL_INFO , XR_LOG_LEVEL_PASS , XR_LOG_LEVEL_WARN ,
  XR_LOG_LEVEL_ERROR
}
 日志级别枚举 / Log level enumeration More...
 

Functions

template<typename T >
std::enable_if<!HasFlashPage< T >::value >::type SetNbPages (T &init, uint32_t addr, uint32_t page)
 
template<typename T >
std::enable_if< HasFlashPage< T >::value >::type SetNbPages (T &init, uint32_t addr, uint32_t page)
 
template<typename T >
std::enable_if<!HasFlashBank< T >::value >::type SetBanks (T &init)
 
template<typename T >
std::enable_if< HasFlashBank< T >::value >::type SetBanks (T &init)
 
void PlatformInit (uint32_t timer_pri=2, uint32_t timer_stack_depth=512)
 平台初始化函数 Platform initialization function
 
void PlatformInit ()
 平台初始化函数 Platform initialization function
 
void PlatformInit (webots::Robot *robot)
 Webots 平台初始化函数 Webots platform initialization function.
 
template<typename T1 , typename T2 >
constexpr auto max (T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
 计算两个数的最大值
 
template<typename T1 , typename T2 >
constexpr auto min (T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
 计算两个数的最小值
 

Variables

constexpr const charLIBXR_FORMAT_STR []
 ANSI escape sequences for text format / ANSI转义序列 - 文本格式
 
constexpr const charLIBXR_FONT_STR []
 ANSI escape sequences for font color / ANSI转义序列 - 字体颜色
 
constexpr const charLIBXR_BACKGROUND_STR []
 ANSI escape sequences for background color / ANSI转义序列 - 背景颜色
 
constexpr const charLIBXR_BOLD_STR []
 ANSI escape sequences for bold styles / ANSI转义序列 - 粗体样式
 
static constexpr uint16_t LIBXR_DATABASE_VERSION = 1
 
constexpr DefaultScalar PID_SIGMA = 1e-6f
 

Detailed Description

LibXR Color Control Library / LibXR终端颜色控制库

Provides ANSI escape sequences for setting terminal text styles and colors. 提供基于ANSI转义序列的终端文本样式和颜色设置。

Typedef Documentation

◆ condition_var_handle

◆ DefaultScalar

typedef LIBXR_DEFAULT_SCALAR LibXR::DefaultScalar

Definition at line 10 of file cycle_value.hpp.

◆ libxr_mutex_handle

互斥锁句柄类型定义 Mutex handle type definition

Definition at line 9 of file libxr_system.hpp.

◆ libxr_semaphore_handle

信号量句柄类型定义 Semaphore handle type definition

Definition at line 10 of file libxr_system.hpp.

◆ libxr_thread_handle

线程句柄类型定义 Thread handle type definition

Definition at line 11 of file libxr_system.hpp.

◆ ReadFun

typedef ErrorCode(* LibXR::ReadFun) (ReadPort &port)

Function pointer type for read operations.

读取操作的函数指针类型。

Definition at line 279 of file libxr_rw.hpp.

◆ ReadOperation

Read operation type.

读取操作类型。

Definition at line 267 of file libxr_rw.hpp.

◆ WriteFun

typedef ErrorCode(* LibXR::WriteFun) (WritePort &port)

Function pointer type for write operations.

写入操作的函数指针类型。

Definition at line 275 of file libxr_rw.hpp.

◆ WriteOperation

Write operation type.

写入操作类型。

Definition at line 271 of file libxr_rw.hpp.

Enumeration Type Documentation

◆ Background

Terminal background color (Background) / 终端背景颜色 (Background)

Definition at line 53 of file libxr_color.hpp.

54{
55 NONE = 0,
56 BLACK,
57 RED,
58 GREEN,
59 YELLOW,
60 BLUE,
61 MAGENTA,
62 CYAN,
63 WHITE,
64 COUNT
65};

◆ Bold

Terminal bold style (Bold) / 终端粗体样式 (Bold)

Optional bold styles like yellow bold, red bold, red background bold. 可选粗体样式,包括黄色粗体、红色粗体、红色背景粗体等。

Definition at line 72 of file libxr_color.hpp.

73{
74 NONE = 0,
75 YELLOW,
76 RED,
77 ON_RED,
78 COUNT
79};

◆ Font

Terminal font color (Font) / 终端字体颜色 (Font)

Definition at line 36 of file libxr_color.hpp.

37{
38 NONE = 0,
39 BLACK,
40 RED,
41 GREEN,
42 YELLOW,
43 BLUE,
44 MAGENTA,
45 CYAN,
46 WHITE,
47 COUNT
48};

◆ Format

Terminal text format (Format) / 终端文本格式 (Format)

Defines text styles like NONE, RESET, BOLD, DARK, UNDERLINE, etc. 定义文本样式,如NONE(无格式)、RESET(重置)、BOLD(加粗)、DARK(暗色)、UNDERLINE(下划线)等。

Definition at line 19 of file libxr_color.hpp.

20{
21 NONE = 0,
22 RESET,
23 BOLD,
24 DARK,
25 UNDERLINE,
26 BLINK,
27 REVERSE,
28 CONCEALED,
29 CLEAR_LINE,
30 COUNT
31};

◆ LogLevel

日志级别枚举 / Log level enumeration

Enumerator
XR_LOG_LEVEL_DEBUG 

调试信息 / Debug message

XR_LOG_LEVEL_INFO 

一般信息 / Informational message

XR_LOG_LEVEL_PASS 

通过信息 / Pass message

XR_LOG_LEVEL_WARN 

警告信息 / Warning message

XR_LOG_LEVEL_ERROR 

错误信息 / Error message

Definition at line 18 of file logger.hpp.

19{
25};
@ XR_LOG_LEVEL_INFO
一般信息 / Informational message
@ XR_LOG_LEVEL_DEBUG
调试信息 / Debug message
@ XR_LOG_LEVEL_WARN
警告信息 / Warning message
@ XR_LOG_LEVEL_ERROR
错误信息 / Error message
@ XR_LOG_LEVEL_PASS
通过信息 / Pass message

Function Documentation

◆ max()

template<typename T1 , typename T2 >
constexpr auto LibXR::max ( T1  a,
T2  b 
) -> typename std::common_type<T1, T2>::type
constexpr

计算两个数的最大值

Computes the maximum of two numbers

Template Parameters
T1第一个数的类型 | Type of the first number
T2第二个数的类型 | Type of the second number
Parameters
a第一个数 | First number
b第二个数 | Second number
Returns
两数中的较大值 | The larger of the two numbers

Definition at line 146 of file libxr_def.hpp.

147{
148 return (a > b) ? a : b;
149}

◆ min()

template<typename T1 , typename T2 >
constexpr auto LibXR::min ( T1  a,
T2  b 
) -> typename std::common_type<T1, T2>::type
constexpr

计算两个数的最小值

Computes the minimum of two numbers

Template Parameters
T1第一个数的类型 | Type of the first number
T2第二个数的类型 | Type of the second number
Parameters
a第一个数 | First number
b第二个数 | Second number
Returns
两数中的较小值 | The smaller of the two numbers

Definition at line 161 of file libxr_def.hpp.

162{
163 return (a < b) ? a : b;
164}

◆ PlatformInit() [1/3]

void LibXR::PlatformInit ( )

平台初始化函数 Platform initialization function

平台初始化函数,执行必要的系统初始化 Platform initialization function for necessary system setup

该函数用于初始化 POSIX 线程相关的资源,例如互斥锁、信号量和条件变量。 在使用 LibXR 线程库之前,应调用该函数进行必要的系统初始化。

This function initializes POSIX thread-related resources such as mutexes, semaphores, and condition variables. It should be called before using the LibXR threading library for proper system setup.

此函数用于初始化底层平台的线程管理、同步机制(如互斥锁、信号量)以及其他系统资源, 需要在使用 LibXR 相关功能之前调用,以确保所有系统组件正确初始化。

This function initializes the underlying platform's thread management, synchronization mechanisms (such as mutexes and semaphores), and other system resources. It should be called before using any LibXR functionalities to ensure proper setup.

Definition at line 23 of file libxr_system.cpp.

24{
25 auto write_fun = [](WritePort &port)
26 {
27 static uint8_t write_buff[1024];
29 while (true)
30 {
31 if (port.queue_info_->Pop(info) != ErrorCode::OK)
32 {
33 return ErrorCode::OK;
34 }
35
36 port.queue_data_->PopBatch(write_buff, info.size);
37 auto ans = fwrite(write_buff, 1, info.size, stdout);
38 UNUSED(ans);
39 port.queue_info_->Pop(info);
40
41 port.UpdateStatus(false, ErrorCode::OK, info.op, info.size);
42 }
43
44 return ErrorCode::OK;
45 };
46
48 new LibXR::WritePort(32, static_cast<size_t>(4 * LIBXR_PRINTF_BUFFER_SIZE));
49
50 *LibXR::STDIO::write_ = write_fun;
51
52 auto read_fun = [](ReadPort &port)
53 {
54 ReadInfoBlock info;
55 port.queue_block_->Pop(info);
56
57 auto need_read = info.data_.size_;
58
59 port.read_size_ = fread(info.data_.addr_, sizeof(char), need_read, stdin);
60 port.UpdateStatus(false, ErrorCode::OK, info, need_read);
61 return ErrorCode::OK;
62 };
63
65 new LibXR::ReadPort(32, static_cast<size_t>(4 * LIBXR_PRINTF_BUFFER_SIZE));
66
67 *LibXR::STDIO::read_ = read_fun;
68
69 gettimeofday(&libxr_linux_start_time, nullptr);
70 UNUSED(clock_gettime(CLOCK_REALTIME, &libxr_linux_start_time_spec));
71
72 struct termios tty;
73 tcgetattr(STDIN_FILENO, &tty); // 获取当前终端属性
74 tty.c_lflag &= ~(ICANON | ECHO); // 禁用规范模式和回显
75 tcsetattr(STDIN_FILENO, TCSANOW, &tty); // 立即生效
76}
ReadPort class for handling read operations.
Definition libxr_rw.hpp:309
static ReadPort * read_
Read port instance. 读取端口。
Definition libxr_rw.hpp:693
static WritePort * write_
Write port instance. 写入端口。
Definition libxr_rw.hpp:694
WritePort class for handling write operations.
Definition libxr_rw.hpp:503

◆ PlatformInit() [2/3]

void LibXR::PlatformInit ( uint32_t  timer_pri = 2,
uint32_t  timer_stack_depth = 512 
)

平台初始化函数 Platform initialization function

Parameters
timer_pri定时器任务的优先级(默认值 2) Timer task priority (default: 2)
timer_stack_depth定时器任务的栈深度(默认值 512) Timer task stack depth (default: 512)

该函数用于初始化 FreeRTOS 相关资源,如定时器任务。 它设置定时器任务的优先级 timer_pri 和栈深度 timer_stack_depth

This function initializes FreeRTOS-related resources, such as the timer task. It sets the timer task priority (timer_pri) and stack depth (timer_stack_depth).

Definition at line 12 of file libxr_system.cpp.

13{
14 if (Timebase::timebase == nullptr)
15 {
16 /* You should initialize Timebase first */
17 ASSERT(false);
18 }
19
20 LibXR::Timer::priority_ = static_cast<LibXR::Thread::Priority>(timer_pri);
21 LibXR::Timer::stack_depth_ = timer_stack_depth;
22
23 uint32_t time_need_to_catch_up = Timebase::GetMilliseconds() - xTaskGetTickCount();
24
25 if (time_need_to_catch_up > 0)
26 {
27 xTaskCatchUpTicks(time_need_to_catch_up);
28 }
29}
Priority
线程优先级枚举 Enumeration for thread priorities
Definition thread.hpp:22
static uint32_t stack_depth_
线程栈深度 Thread stack depth
Definition timer.hpp:243
static LibXR::Thread::Priority priority_
线程优先级 Thread priority
Definition timer.hpp:242

◆ PlatformInit() [3/3]

void LibXR::PlatformInit ( webots::Robot *  robot = nullptr)

Webots 平台初始化函数 Webots platform initialization function.

Parameters
robotWebots 机器人对象指针 Webots robot object pointer

此函数用于初始化 Webots 仿真环境,设置 _libxr_webots_robot_handle 变量, 并对仿真时间计数变量 _libxr_webots_time_count 进行初始化。

This function initializes the Webots simulation environment by setting the _libxr_webots_robot_handle variable and initializing the simulation time counter _libxr_webots_time_count.

Definition at line 27 of file libxr_system.cpp.

28{ // NOLINT
29 auto write_fun = [](WritePort &port)
30 {
31 static uint8_t write_buff[1024];
33 while (true)
34 {
35 if (port.queue_info_->Pop(info) != ErrorCode::OK)
36 {
37 return ErrorCode::OK;
38 }
39
40 port.queue_data_->PopBatch(write_buff, info.size);
41 auto ans = fwrite(write_buff, 1, info.size, stdout);
42 UNUSED(ans);
43 port.queue_info_->Pop(info);
44
45 port.UpdateStatus(false, ErrorCode::OK, info.op, info.size);
46 }
47
48 return ErrorCode::OK;
49 };
50
51 LibXR::STDIO::write_ = new LibXR::WritePort(32, 32 * LIBXR_PRINTF_BUFFER_SIZE);
52
53 *LibXR::STDIO::write_ = write_fun;
54
55 auto read_fun = [](ReadPort &port)
56 {
57 ReadInfoBlock info;
58 port.queue_block_->Pop(info);
59
60 auto need_read = info.data_.size_;
61
62 port.read_size_ = fread(info.data_.addr_, sizeof(char), need_read, stdin);
63 port.UpdateStatus(false, ErrorCode::OK, info, need_read);
64 return ErrorCode::OK;
65 };
66
67 LibXR::STDIO::read_ = new LibXR::ReadPort(32, 32 * LIBXR_PRINTF_BUFFER_SIZE);
68
69 *LibXR::STDIO::read_ = read_fun;
70
71 struct termios tty;
72 tcgetattr(STDIN_FILENO, &tty); // 获取当前终端属性
73 tty.c_lflag &= ~(ICANON | ECHO); // 禁用规范模式和回显
74 tcsetattr(STDIN_FILENO, TCSANOW, &tty); // 立即生效
75
76 if (robot == nullptr)
77 {
78 _libxr_webots_robot_handle = new webots::Robot();
79 }
80 else
81 {
82 _libxr_webots_robot_handle = robot;
83 }
84
85 time_step = _libxr_webots_robot_handle->getBasicTimeStep();
86
87 if (_libxr_webots_robot_handle == nullptr)
88 {
89 printf("webots robot handle is null.\n");
90 exit(-1);
91 }
92
93 _libxr_webots_time_notify = new LibXR::ConditionVar();
94
95 auto webots_timebase_thread_fun = [](void *)
96 {
97 poll(nullptr, 0, 100);
98
99 while (true)
100 {
101 poll(nullptr, 0, 1);
102 _libxr_webots_robot_handle->step(time_step);
103 _libxr_webots_time_count++;
104 _libxr_webots_time_notify->Broadcast();
105 }
106 };
107
108 LibXR::Thread webots_timebase_thread;
109 webots_timebase_thread.Create<void *>(
110 reinterpret_cast<void *>(0), webots_timebase_thread_fun, "webots_timebase_thread",
111 1024, Thread::Priority::REALTIME);
112}
条件变量封装类 / Condition variable wrapper class
void Broadcast()
广播信号唤醒所有等待线程 / Broadcasts a signal to wake up all waiting threads
线程管理类,封装 FreeRTOS 任务创建和调度 Thread management class encapsulating FreeRTOS task creation and scheduling
Definition thread.hpp:15
void Create(ArgType arg, void(*function)(ArgType arg), const char *name, size_t stack_depth, Thread::Priority priority)
创建新线程 Creates a new thread
Definition thread.hpp:64

◆ SetBanks() [1/2]

template<typename T >
std::enable_if<!HasFlashBank< T >::value >::type LibXR::SetBanks ( T init)

Definition at line 65 of file stm32_flash.hpp.

66{
67 UNUSED(init);
68}

◆ SetBanks() [2/2]

template<typename T >
std::enable_if< HasFlashBank< T >::value >::type LibXR::SetBanks ( T init)

Definition at line 72 of file stm32_flash.hpp.

73{
74 init.Banks = 1;
75}

◆ SetNbPages() [1/2]

template<typename T >
std::enable_if<!HasFlashPage< T >::value >::type LibXR::SetNbPages ( T init,
uint32_t  addr,
uint32_t  page 
)

Definition at line 47 of file stm32_flash.hpp.

49{
50 UNUSED(page);
51 init.PageAddress = addr;
52}

◆ SetNbPages() [2/2]

template<typename T >
std::enable_if< HasFlashPage< T >::value >::type LibXR::SetNbPages ( T init,
uint32_t  addr,
uint32_t  page 
)

Definition at line 56 of file stm32_flash.hpp.

58{
59 UNUSED(addr);
60 init.Page = page;
61}

Variable Documentation

◆ LIBXR_BACKGROUND_STR

constexpr const char* LibXR::LIBXR_BACKGROUND_STR[]
inlineconstexpr
Initial value:
= {
"", "\033[40m", "\033[41m", "\033[42m", "\033[43m",
"\033[44m", "\033[45m", "\033[46m", "\033[47m"}

ANSI escape sequences for background color / ANSI转义序列 - 背景颜色

Definition at line 98 of file libxr_color.hpp.

98 {
99 "", "\033[40m", "\033[41m", "\033[42m", "\033[43m",
100 "\033[44m", "\033[45m", "\033[46m", "\033[47m"};

◆ LIBXR_BOLD_STR

constexpr const char* LibXR::LIBXR_BOLD_STR[]
inlineconstexpr
Initial value:
= {"", "\033[33m\033[1m", "\033[31m\033[1m",
"\033[1m\033[41m"}

ANSI escape sequences for bold styles / ANSI转义序列 - 粗体样式

Definition at line 105 of file libxr_color.hpp.

105 {"", "\033[33m\033[1m", "\033[31m\033[1m",
106 "\033[1m\033[41m"};

◆ LIBXR_DATABASE_VERSION

constexpr uint16_t LibXR::LIBXR_DATABASE_VERSION = 1
staticconstexpr

Definition at line 14 of file database.hpp.

◆ LIBXR_FONT_STR

constexpr const char* LibXR::LIBXR_FONT_STR[]
inlineconstexpr
Initial value:
= {"", "\033[30m", "\033[31m",
"\033[32m", "\033[33m", "\033[34m",
"\033[35m", "\033[36m", "\033[37m"}

ANSI escape sequences for font color / ANSI转义序列 - 字体颜色

Definition at line 91 of file libxr_color.hpp.

91 {"", "\033[30m", "\033[31m",
92 "\033[32m", "\033[33m", "\033[34m",
93 "\033[35m", "\033[36m", "\033[37m"};

◆ LIBXR_FORMAT_STR

constexpr const char* LibXR::LIBXR_FORMAT_STR[]
inlineconstexpr
Initial value:
= {"", "\033[m", "\033[1m",
"\033[2m", "\033[4m", "\033[5m",
"\033[7m", "\033[8m", "\033[K"}

ANSI escape sequences for text format / ANSI转义序列 - 文本格式

Definition at line 84 of file libxr_color.hpp.

84 {"", "\033[m", "\033[1m",
85 "\033[2m", "\033[4m", "\033[5m",
86 "\033[7m", "\033[8m", "\033[K"};

◆ PID_SIGMA

constexpr DefaultScalar LibXR::PID_SIGMA = 1e-6f
constexpr

Definition at line 13 of file pid.hpp.