Skip to content

Commit 70f2c3d

Browse files
committed
Format code.
1 parent ced6fdf commit 70f2c3d

File tree

1 file changed

+28
-41
lines changed

1 file changed

+28
-41
lines changed

SharedTopic.hpp

Lines changed: 28 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@ required_hardware: uart_name, ramfs
2727
#include "thread.hpp"
2828
#include "uart.hpp"
2929

30-
class SharedTopic : public LibXR::Application
31-
{
30+
class SharedTopic : public LibXR::Application {
3231
public:
3332
SharedTopic(LibXR::HardwareContainer &hw, LibXR::ApplicationManager &app,
34-
const char *uart_name, uint32_t task_stack_depth, uint32_t buffer_size,
33+
const char *uart_name, uint32_t task_stack_depth,
34+
uint32_t buffer_size,
3535
std::initializer_list<const char *> topic_names)
3636
: uart_(hw.template Find<LibXR::UART>(uart_name)),
3737
server_(buffer_size),
3838
rx_buffer_(new uint8_t[buffer_size], buffer_size),
39-
cmd_file_(LibXR::RamFS::CreateFile("shared_topic", CommandFunc, this))
40-
{
41-
for (const char *name : topic_names)
42-
{
39+
cmd_file_(LibXR::RamFS::CreateFile("shared_topic", CommandFunc, this)) {
40+
for (const char *name : topic_names) {
4341
auto topic = LibXR::Topic::Find(name);
44-
if (topic == nullptr)
45-
{
42+
if (topic == nullptr) {
4643
XR_LOG_ERROR("Topic not found: %s", name);
4744
ASSERT(false);
4845
}
@@ -51,27 +48,24 @@ class SharedTopic : public LibXR::Application
5148

5249
hw.template FindOrExit<LibXR::RamFS>({"ramfs"})->Add(cmd_file_);
5350

54-
rx_thread_.Create(this, RxThreadFun, "SharedTopic::RxThread", task_stack_depth,
55-
LibXR::Thread::Priority::REALTIME);
51+
rx_thread_.Create(this, RxThreadFun, "SharedTopic::RxThread",
52+
task_stack_depth, LibXR::Thread::Priority::REALTIME);
5653

5754
app.Register(*this);
5855
}
5956

60-
static void RxThreadFun(SharedTopic *self)
61-
{
57+
static void RxThreadFun(SharedTopic *self) {
6258
LibXR::Semaphore sem;
6359
LibXR::ReadOperation op(sem);
64-
while (true)
65-
{
66-
auto size =
67-
LibXR::max(sizeof(LibXR::Topic::PackedDataHeader),
68-
LibXR::min(self->uart_->read_port_.Size(), self->rx_buffer_.size_));
69-
auto ans =
70-
self->uart_->read_port_(LibXR::RawData{self->rx_buffer_.addr_, size}, op);
71-
72-
if (ans == ErrorCode::OK)
73-
{
74-
auto ans = self->server_.ParseData(LibXR::RawData{self->rx_buffer_.addr_, size});
60+
while (true) {
61+
auto size = LibXR::max(
62+
sizeof(LibXR::Topic::PackedDataHeader),
63+
LibXR::min(self->uart_->read_port_.Size(), self->rx_buffer_.size_));
64+
auto ans = self->uart_->read_port_(
65+
LibXR::RawData{self->rx_buffer_.addr_, size}, op);
66+
67+
if (ans == ErrorCode::OK) {
68+
self->server_.ParseData(LibXR::RawData{self->rx_buffer_.addr_, size});
7569
}
7670

7771
self->rx_count_ += size;
@@ -80,34 +74,27 @@ class SharedTopic : public LibXR::Application
8074

8175
void OnMonitor() override {}
8276

83-
static int CommandFunc(SharedTopic *self, int argc, char **argv)
84-
{
85-
if (argc == 1)
86-
{
77+
static int CommandFunc(SharedTopic *self, int argc, char **argv) {
78+
if (argc == 1) {
8779
LibXR::STDIO::Printf("Usage:\r\n");
88-
LibXR::STDIO::Printf(" monitor [time_ms] [interval_ms] - test received speed\r\n");
80+
LibXR::STDIO::Printf(
81+
" monitor [time_ms] [interval_ms] - test received speed\r\n");
8982
return 0;
90-
}
91-
else if (argc == 4)
92-
{
93-
if (strcmp(argv[1], "monitor") == 0)
94-
{
83+
} else if (argc == 4) {
84+
if (strcmp(argv[1], "monitor") == 0) {
9585
int time = atoi(argv[2]);
9686
int delay = atoi(argv[3]);
9787
auto start = self->rx_count_;
98-
while (time > 0)
99-
{
88+
while (time > 0) {
10089
LibXR::Thread::Sleep(delay);
10190
LibXR::STDIO::Printf(
102-
"%f Mbps\r\n", static_cast<float>(self->rx_count_ - start) * 8.0 / 1024.0 /
103-
1024.0 / delay * 1000.0);
91+
"%f Mbps\r\n", static_cast<float>(self->rx_count_ - start) * 8.0 /
92+
1024.0 / 1024.0 / delay * 1000.0);
10493
time -= delay;
10594
start = self->rx_count_;
10695
}
10796
}
108-
}
109-
else
110-
{
97+
} else {
11198
LibXR::STDIO::Printf("Error: Invalid arguments.\r\n");
11299
return -1;
113100
}

0 commit comments

Comments
 (0)