LCOV - code coverage report
Current view: top level - src/drivers/velodyne_nodes/src - velodyne_cloud_node_main.cpp (source / functions) Hit Total Coverage
Test: coverage.filtered Lines: 23 36 63.9 %
Date: 2022-02-08 20:34:35 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 72 30.6 %

           Branch data     Line data    Source code
       1                 :            : // Copyright 2018-2020 the Autoware Foundation, Arm Limited
       2                 :            : //
       3                 :            : // Licensed under the Apache License, Version 2.0 (the "License");
       4                 :            : // you may not use this file except in compliance with the License.
       5                 :            : // You may obtain a copy of the License at
       6                 :            : //
       7                 :            : //     http://www.apache.org/licenses/LICENSE-2.0
       8                 :            : //
       9                 :            : // Unless required by applicable law or agreed to in writing, software
      10                 :            : // distributed under the License is distributed on an "AS IS" BASIS,
      11                 :            : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12                 :            : // See the License for the specific language governing permissions and
      13                 :            : // limitations under the License.
      14                 :            : //
      15                 :            : // Co-developed by Tier IV, Inc. and Apex.AI, Inc.
      16                 :            : 
      17                 :            : #include <velodyne_nodes/velodyne_cloud_node.hpp>
      18                 :            : #include <rcutils/cmdline_parser.h>
      19                 :            : 
      20                 :            : //lint -e537 NOLINT  // cpplint vs pclint
      21                 :            : #include <string>
      22                 :            : //lint -e537 NOLINT  // cpplint vs pclint
      23                 :            : #include <memory>
      24                 :            : #include <vector>
      25                 :            : #include <cstdio>
      26                 :            : #include <algorithm>
      27                 :            : #include "rclcpp/rclcpp.hpp"
      28                 :            : 
      29                 :            : // this file is simply a main file to create a ros1 style standalone node
      30                 :          5 : int32_t main(const int32_t argc, char ** const argv)
      31                 :            : {
      32                 :          5 :   int32_t ret = 0;
      33                 :            : 
      34                 :            :   try {
      35   [ +  -  +  -  :          5 :     rclcpp::init(argc, argv);
                   +  - ]
      36                 :            : 
      37                 :          8 :     const auto run = [](const auto & nd_ptr) {
      38   [ +  -  +  + ]:          8 :         while (rclcpp::ok()) {
      39         [ +  - ]:          4 :           rclcpp::spin(nd_ptr);
      40                 :            :         }
      41   [ +  -  +  - ]:          4 :         rclcpp::shutdown();
      42                 :          4 :       };
      43                 :            : 
      44         [ +  - ]:          5 :     const auto * arg = rcutils_cli_get_option(argv, &argv[argc], "--model");
      45         [ +  - ]:          5 :     if (arg != nullptr) {
      46         [ +  - ]:         10 :       auto model = std::string(arg);
      47                 :            :       std::transform(
      48                 :         25 :         model.begin(), model.end(), model.begin(), [](const auto & c) {
      49                 :         25 :           return std::tolower(c);
      50                 :          5 :         });
      51         [ +  - ]:          5 :       if (model == "vlp16") {
      52         [ +  - ]:          4 :         run(
      53                 :            :           std::make_shared<
      54         [ +  + ]:          9 :             autoware::drivers::velodyne_nodes::VLP16DriverNode>(
      55                 :            :             "vlp16_driver_node",
      56   [ +  -  +  - ]:         11 :             rclcpp::NodeOptions{}));
      57         [ #  # ]:          0 :       } else if (model == "vlp32c") {
      58         [ #  # ]:          0 :         run(
      59                 :            :           std::make_shared<
      60         [ #  # ]:          0 :             autoware::drivers::velodyne_nodes::VLP32CDriverNode>(
      61                 :            :             "vlp32c_driver_node",
      62   [ #  #  #  # ]:          0 :             rclcpp::NodeOptions{}));
      63         [ #  # ]:          0 :       } else if (model == "vls128") {
      64         [ #  # ]:          0 :         run(
      65                 :            :           std::make_shared<
      66         [ #  # ]:          0 :             autoware::drivers::velodyne_nodes::VLS128DriverNode>(
      67                 :            :             "vls128_driver_node",
      68   [ #  #  #  # ]:          0 :             rclcpp::NodeOptions{}));
      69                 :            :       } else {
      70   [ #  #  #  #  :          0 :         throw std::runtime_error("Model " + model + " is not supperted.");
                   #  # ]
      71                 :            :       }
      72                 :            :     } else {
      73         [ #  # ]:          0 :       throw std::runtime_error("Please specify a velodyne model using --model argument");
      74                 :            :     }
      75                 :          1 :   } catch (const std::exception & err) {
      76                 :            :     // RCLCPP logging macros are not used in error handling because they would depend on vptr's
      77                 :            :     // logger. This dependency would result in a crash when vptr is a nullptr
      78   [ +  -  +  - ]:          1 :     std::cerr << err.what() << std::endl;
      79                 :          1 :     ret = 2;
      80                 :          0 :   } catch (...) {
      81   [ -  -  -  - ]:          0 :     std::cerr << "Unknown error encountered, exiting..." << std::endl;
      82                 :          0 :     ret = -1;
      83                 :            :   }
      84   [ +  -  +  - ]:          5 :   rclcpp::shutdown();
      85                 :          5 :   return ret;
      86                 :            : }

Generated by: LCOV version 1.14