Skip to content

Commit

Permalink
Merge pull request IntelRealSense#1101 from icarpis/rs-term
Browse files Browse the repository at this point in the history
Fixing rs-terminal device_id parameter.
Fix handling of empty frames in v4l backend
  • Loading branch information
ev-mp authored Jan 31, 2018
2 parents 1e66580 + fa244f7 commit 2e9295e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
29 changes: 13 additions & 16 deletions src/linux/backend-v4l2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ namespace librealsense
PROT_READ | PROT_WRITE, MAP_SHARED,
fd, buf.m.offset));
if(_start == MAP_FAILED)
linux_backend_exception("mmap failed");
throw linux_backend_exception("mmap failed");
}
else
{
Expand Down Expand Up @@ -781,7 +781,7 @@ namespace librealsense

_error_handler(n);
}
else
else if (buf.bytesused > 0)
{
void* md_start = nullptr;
uint8_t md_size = 0;
Expand All @@ -794,20 +794,17 @@ namespace librealsense
frame_object fo{ buffer->get_length_frame_only(), md_size,
buffer->get_frame_start(), md_start };

if (buf.bytesused > 0)
{
buffer->attach_buffer(buf);
moved_qbuff = true;
auto fd = _fd;
_callback(_profile, fo,
[fd, buffer]() mutable {
buffer->request_next_frame(fd);
});
}
else
{
LOG_WARNING("Empty frame has arrived.");
}
buffer->attach_buffer(buf);
moved_qbuff = true;
auto fd = _fd;
_callback(_profile, fo,
[fd, buffer]() mutable {
buffer->request_next_frame(fd);
});
}
else
{
LOG_WARNING("Empty frame has arrived.");
}
}

Expand Down
36 changes: 32 additions & 4 deletions tools/terminal/rs-terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,16 @@ void read_script_file(const string& full_file_path, vector<string>& hex_lines)
throw runtime_error("Script file not found!");
}

rs2::device wait_for_device(const rs2::device_hub& hub)
rs2::device wait_for_device(const rs2::device_hub& hub, bool print_info = true)
{
cout << "\nWaiting for RealSense device to connect...\n";
if (print_info)
cout << "\nWaiting for RealSense device to connect...\n";

auto dev = hub.wait_for_device();
cout << "RealSense device has connected...\n";

if (print_info)
cout << "RealSense device has connected...\n";

return dev;
}

Expand Down Expand Up @@ -196,9 +201,32 @@ int main(int argc, char** argv)
}
auto auto_comp = get_auto_complete_obj(is_application_in_hex_mode, cmd_xml.commands);

rs2::device dev;
while (true)
{
auto dev = wait_for_device(hub);
if (device_id_arg.isSet())
{
auto dev_id = device_id_arg.getValue();
auto num_of_devices = ctx.query_devices().size();
if (num_of_devices < (dev_id + 1))
{
std::cout << "\nGiven device_id doesn't exist! device_id=" <<
dev_id << " ; connected devices=" << num_of_devices << std::endl;
return EXIT_FAILURE;
}

for (int i = 0; i < (num_of_devices - 1); ++i)
{
wait_for_device(hub, false);
}
dev = wait_for_device(hub, false);
std::cout << "\nDevice ID " << dev_id << " has loaded.\n";
}
else
{
dev = wait_for_device(hub);
}

fflush(nullptr);

if (hex_cmd_arg.isSet())
Expand Down

0 comments on commit 2e9295e

Please sign in to comment.