mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-16 04:07:35 +08:00
micrortps_client: more cleanup
This commit is contained in:
@@ -94,8 +94,8 @@ void* send(void* /*unused*/)
|
||||
|
||||
// ucdrBuffer to serialize using the user defined buffer
|
||||
ucdrBuffer writer;
|
||||
header_length=transport_node->get_header_length();
|
||||
ucdr_init_buffer(&writer, (uint8_t*)&data_buffer[header_length], BUFFER_SIZE - header_length);
|
||||
header_length = transport_node->get_header_length();
|
||||
ucdr_init_buffer(&writer, reinterpret_cast<uint8_t*>(&data_buffer[header_length]), BUFFER_SIZE - header_length);
|
||||
|
||||
struct timespec begin;
|
||||
px4_clock_gettime(CLOCK_REALTIME, &begin);
|
||||
@@ -105,27 +105,24 @@ void* send(void* /*unused*/)
|
||||
@[for idx, topic in enumerate(send_topics)]@
|
||||
@(send_base_types[idx])_s @(topic)_data;
|
||||
if (@(topic)_sub.update(&@(topic)_data)) {
|
||||
// copy raw data into local buffer
|
||||
// payload is shifted by header length to make room for header
|
||||
// copy raw data into local buffer. Payload is shifted by header length to make room for header
|
||||
serialize_@(send_base_types[idx])(&writer, &@(topic)_data, &data_buffer[header_length], &length);
|
||||
|
||||
if (0 < (read = transport_node->write((char)@(rtps_message_id(ids, topic)), data_buffer, length)))
|
||||
if (0 < (read = transport_node->write(static_cast<char>(@(rtps_message_id(ids, topic))), data_buffer, length)))
|
||||
{
|
||||
total_sent += read;
|
||||
++sent;
|
||||
}
|
||||
}
|
||||
@[end for]@
|
||||
|
||||
px4_usleep(_options.sleep_ms*1000);
|
||||
px4_usleep(_options.sleep_ms * 1e3);
|
||||
++loop;
|
||||
}
|
||||
|
||||
struct timespec end;
|
||||
px4_clock_gettime(CLOCK_REALTIME, &end);
|
||||
double elapsed_secs = double(end.tv_sec - begin.tv_sec) + double(end.tv_nsec - begin.tv_nsec)/double(1000000000);
|
||||
double elapsed_secs = static_cast<double>(end.tv_sec - begin.tv_sec + (end.tv_nsec - begin.tv_nsec) / 1e9);
|
||||
PX4_INFO("SENT: %" PRIu64 " messages in %d LOOPS, %" PRIu64 " bytes in %.03f seconds - %.02fKB/s",
|
||||
sent, loop, total_sent, elapsed_secs, (double)total_sent/(1000*elapsed_secs));
|
||||
sent, loop, total_sent, elapsed_secs, static_cast<double>(total_sent / (1e3 * elapsed_secs)));
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -146,7 +143,7 @@ static int launch_send_thread(pthread_t &sender_thread)
|
||||
}
|
||||
@[end if]@
|
||||
|
||||
void micrortps_start_topics(struct timespec &begin, int &total_read, uint32_t &received, int &loop)
|
||||
void micrortps_start_topics(struct timespec &begin, uint64_t &total_read, uint64_t &received, int &loop)
|
||||
{
|
||||
@[if recv_topics]@
|
||||
|
||||
@@ -162,7 +159,7 @@ void micrortps_start_topics(struct timespec &begin, int &total_read, uint32_t &r
|
||||
|
||||
// ucdrBuffer to deserialize using the user defined buffer
|
||||
ucdrBuffer reader;
|
||||
ucdr_init_buffer(&reader, (uint8_t*)data_buffer, BUFFER_SIZE);
|
||||
ucdr_init_buffer(&reader, reinterpret_cast<uint8_t*>(data_buffer), BUFFER_SIZE);
|
||||
@[end if]@
|
||||
|
||||
px4_clock_gettime(CLOCK_REALTIME, &begin);
|
||||
@@ -201,7 +198,7 @@ void micrortps_start_topics(struct timespec &begin, int &total_read, uint32_t &r
|
||||
// loop forever if informed loop number is negative
|
||||
if (_options.loops >= 0 && loop >= _options.loops) break;
|
||||
|
||||
px4_usleep(_options.sleep_ms*1000);
|
||||
px4_usleep(_options.sleep_ms * 1e3);
|
||||
++loop;
|
||||
}
|
||||
@[if send_topics]@
|
||||
|
||||
Reference in New Issue
Block a user