Skip to content

Commit

Permalink
fmu-v5硬件测试:增加utest-workq
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHAHA committed Aug 20, 2024
1 parent 36275b2 commit 0296060
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/utest/test_workq/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
menuconfig TEST_WORK_QUEUE
bool "test work queue"
default n

if TEST_WORK_QUEUE
endif
22 changes: 22 additions & 0 deletions apps/utest/test_workq/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import os
import rtconfig
from building import *

cwd = GetCurrentDir()
group = []


# 添加当前文件夹下的代码
src = Glob("*.c") + Glob("*.cpp")
inc = [cwd]

group += DefineGroup("utest", src, depend = [''], CPPPATH = inc)

for d in os.listdir(cwd):
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, "SConscript")):
# print(os.path.join(d, 'SConscript'))
group += SConscript(os.path.join(d, "SConscript"))

Return("group")
55 changes: 55 additions & 0 deletions apps/utest/test_workq/workq_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <nextpilot.h>
#include <workq/WorkItemScheduled.hpp>

using namespace time_literals;
using namespace nextpilot;

static wq_config_t sim_rate_ctrl{"wq:sim_rate_ctrl", 4096 * 10, 0};

class SimRateControl : public ModuleCommand<SimRateControl>, public nextpilot::WorkItemScheduled {
public:
SimRateControl() :
WorkItemScheduled(MODULE_NAME, sim_rate_ctrl) {
}

~SimRateControl() {
}

/** @see ModuleCommand */
static SimRateControl *instantiate(int argc, char *argv[]) {
SimRateControl *instance = new SimRateControl();
return instance;
}

/** @see ModuleCommand */
static int custom_command(int argc, char *argv[]) {
return 0;
}

/** @see ModuleCommand */
static int print_usage(const char *reason = nullptr) {
return 0;
}

int init() override {
ScheduleOnInterval(100_ms); // 8 Hz
return 0;
}

private:
void Run() override {
static uint32_t cnt = 0;
if (should_exit()) {
}
rt_thread_mdelay(1000);
rt_kprintf("======%ld, %d\n", rt_tick_get(), cnt++);
}
};

int sim_rate_ctrl_start() {
const char *argv[] = {"sim_rate_control", "start"};
int argc = sizeof(argv) / sizeof(argv[0]);
return SimRateControl::main(argc, (char **)argv);
}

INIT_APP_EXPORT(sim_rate_ctrl_start);

0 comments on commit 0296060

Please sign in to comment.