device.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Intel Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <cassert>
18 #include <string>
19 
20 #include <ros/console.h>
21 
25 
26 namespace movidius_ncs_lib
27 {
28 Device::Device(int index, LogLevel log_level)
29  : index_(index), handle_(nullptr)
30 {
31  assert(index_ >= 0);
32  setLogLevel(log_level);
33  find();
34  open();
35 }
36 
38 {
39  try
40  {
41  close();
42  }
43  catch (MvncException& e)
44  {
45  ROS_ERROR_STREAM("Exception caught on device[" << index_ << "], " << e.what());
46  }
47 }
48 
49 std::string Device::getName() const
50 {
51  assert(handle_ != nullptr);
52  return name_;
53 }
54 
56 {
57  ROS_INFO_STREAM("opening device #" << index_ << " name=" << name_);
58  int ret = mvncOpenDevice(name_.c_str(), &handle_);
60 }
61 
63 {
64  if (handle_ == nullptr)
65  {
66  return;
67  }
68 
69  ROS_INFO_STREAM("close device #" << index_ << " name=" << name_);
70  int ret = mvncCloseDevice(handle_);
72 }
73 
75 {
77 
78  if (level == High)
79  {
80  throw MvncHighThermal();
81  }
82 
83  if (level == Aggressive)
84  {
85  throw MvncAggressiveThermal();
86  }
87 }
88 
90 {
91  int level = log_level;
92  int ret = mvncSetGlobalOption(MVNC_LOG_LEVEL,
93  static_cast<void*>(&level),
94  sizeof(level));
96 }
97 
99 {
100  int level;
101  unsigned int size_of_level = sizeof(level);
102  int ret = mvncGetGlobalOption(MVNC_LOG_LEVEL,
103  reinterpret_cast<void**>(&level),
104  &size_of_level);
106  return static_cast<LogLevel>(level);
107 }
108 
110 {
111  assert(handle_ != nullptr);
112  int throttling;
113  unsigned int size_of_throttling = sizeof(throttling);
114  int ret = mvncGetDeviceOption(handle_,
115  MVNC_THERMAL_THROTTLING_LEVEL,
116  reinterpret_cast<void**>(&throttling),
117  &size_of_throttling);
119  return static_cast<ThermalThrottlingLevel>(throttling);
120 }
121 
123 {
124  assert(handle_ != nullptr);
125  return handle_;
126 }
127 
129 {
130  assert(handle_ == nullptr);
131  char name[MVNC_MAX_NAME_SIZE];
132  int ret = mvncGetDeviceName(index_, name, sizeof(name));
134  name_ = name;
135 }
136 } // namespace movidius_ncs_lib
137 
void monitorThermal() const
Definition: device.cpp:74
void setLogLevel(LogLevel level)
Definition: device.cpp:89
static void tryToThrowMvncException(int code)
const char * what() const noexcept
Definition: exception.h:34
std::string getName() const
Definition: device.cpp:49
LogLevel getLogLevel()
Definition: device.cpp:98
ThermalThrottlingLevel getThermalThrottlingLevel() const
Definition: device.cpp:109
#define ROS_INFO_STREAM(args)
std::string name_
Definition: device.h:63
#define ROS_ERROR_STREAM(args)
Device(int index, LogLevel log_level)
Definition: device.cpp:28


movidius_ncs_lib
Author(s): Xiaojun Huang
autogenerated on Mon Jun 10 2019 14:11:23