NASA Astrobee Robot Software  0.19.1
Flight software for the Astrobee robots operating inside the International Space Station.
i2c.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, United States Government, as represented by the
2  * Administrator of the National Aeronautics and Space Administration.
3  *
4  * All rights reserved.
5  *
6  * The Astrobee platform is licensed under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations
16  * under the License.
17  */
18 
19 #ifndef I2C_I2C_H_
20 #define I2C_I2C_H_
21 
22 #include <map>
23 #include <string>
24 #include <mutex>
25 
26 namespace I2c {
27 class I2c {
28  public:
29  static bool Open(std::string const& device);
30  static bool Close(std::string const& device);
31  static int16_t WriteI2c(std::string const& device, const uint8_t addr,
32  const uint8_t& data);
33  static int16_t WriteI2c(std::string const& device, const uint8_t addr,
34  uint8_t* data, const size_t len);
35  static int16_t ReadI2c(std::string const& device, const uint8_t addr,
36  uint8_t *buf, const int size);
37  static int16_t WriteSmb(std::string const& device, const uint8_t addr,
38  const uint8_t cmd, const uint8_t& data);
39  static int16_t WriteSmb(std::string const& device, const uint8_t addr,
40  const uint8_t cmd, const uint16_t& data);
41  static ssize_t WriteSmb(std::string const& device, const uint8_t addr,
42  const uint8_t cmd, const size_t len, const uint8_t* data);
43  static int16_t ReadSmb(std::string const& device, const uint8_t addr,
44  const uint8_t cmd, uint8_t* data);
45  static int16_t ReadSmb(std::string const& device, const uint8_t addr,
46  const uint8_t cmd, uint16_t* data);
47  static int16_t ReadSmb(std::string const& device, const uint8_t addr,
48  const uint8_t cmd, const size_t len,
49  uint8_t* data);
50 
51  private:
52  static I2c& Instance();
53  static I2c* instance_;
54  I2c();
55  ~I2c();
56  I2c(const I2c&) = delete;
57  I2c & operator=(const I2c&) = delete;
58  static std::map<std::string, std::mutex> mtx_map_;
59  static std::map<std::string, int> fd_map_;
60 };
61 } // end namespace I2c
62 #endif // I2C_I2C_H_
i2c::Open
Bus::Ptr Open(std::string const &dev, Error *err)
Definition: i2c_new.cc:46
I2c
Definition: i2c.h:26