Skip to content

Commit

Permalink
fmu-v5测试:测试一个workq的执行
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHAHA committed Aug 20, 2024
1 parent 0296060 commit 170365b
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions apps/utest/test_workq/workq_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ 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 {
/**
* @brief
*
* ModuleCommand<SimRateControl, 6>: 最多创建6个实例
*/
class SimRateControl : public ModuleCommand<SimRateControl, 6>, public nextpilot::WorkItemScheduled {
public:
SimRateControl() :
SimRateControl(int idx) :
WorkItemScheduled(MODULE_NAME, sim_rate_ctrl) {
_idx = idx;
}

~SimRateControl() {
}

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

Expand All @@ -41,15 +48,35 @@ class SimRateControl : public ModuleCommand<SimRateControl>, public nextpilot::W
static uint32_t cnt = 0;
if (should_exit()) {
}
rt_thread_mdelay(1000);
rt_kprintf("======%ld, %d\n", rt_tick_get(), cnt++);
// rt_thread_mdelay(1000);
rt_tick_t start = rt_tick_get();
while (rt_tick_get() - start <= 2) {
}
// static double total = 0.0f;
// // 执行一些很耗时的操作
// for (uint32_t sleep = 0; sleep < 500000; ++sleep) {
// total += 1.0 / sleep;
// }
// if (_idx == 0) {
// rt_kprintf("======idx=%d, %ld, %d\n", _idx, rt_tick_get(), cnt++);
// }
}

int _idx;
};

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


// const char *argv1[] = {"sim_rate_control1", "start", "1"};
// int argc1 = sizeof(argv1) / sizeof(argv1[0]);
// ret = SimRateControl::main(argc1, (char **)argv1);

return ret;
}

INIT_APP_EXPORT(sim_rate_ctrl_start);

0 comments on commit 170365b

Please sign in to comment.