DUDS
Distributed Update of Data from Something
DevSmbus.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
11 #include <string>
12 
13 #ifdef linux
14 // !@?!#?!#?
15 #undef linux
16 #endif
17 
18 // defined in linux/i2c-dev.h
19 struct i2c_smbus_ioctl_data;
20 
21 namespace duds { namespace hardware { namespace interface { namespace linux {
22 
44  std::string dev;
48  int fd;
52  int addr;
57  void io(i2c_smbus_ioctl_data &sdat);
58 public:
74  DevSmbus(const std::string &devname, int devaddr, bool pec = true);
88  DevSmbus(const std::string &devname, int devaddr, UsePec) :
89  DevSmbus(devname, devaddr, true) { }
102  DevSmbus(const std::string &devname, int devaddr, NoPec) :
103  DevSmbus(devname, devaddr, false) { }
107  ~DevSmbus();
108  // documentation for the functions below is in
109  // duds/hardware/interface/Smbus.hpp
110  virtual std::uint8_t receiveByte();
111  virtual std::uint8_t receiveByte(std::uint8_t cmd);
112  virtual std::uint16_t receiveWord(std::uint8_t cmd);
113  virtual int receive(
114  std::uint8_t cmd,
115  std::uint8_t *in,
116  const int maxlen
117  );
118  virtual void receive(std::uint8_t cmd, std::vector<std::uint8_t> &in);
119  virtual void transmitBool(bool out);
120  virtual void transmitByte(std::uint8_t byte);
121  virtual void transmitByte(std::uint8_t cmd, std::uint8_t byte);
122  virtual void transmitWord(std::uint8_t cmd, std::uint16_t word);
123  virtual void transmit(
124  std::uint8_t cmd,
125  const std::uint8_t *out,
126  const int len
127  );
128  virtual std::uint16_t call(std::uint8_t cmd, std::uint16_t word);
129  virtual void call(
130  std::uint8_t cmd,
131  const std::vector<std::uint8_t> &out,
132  std::vector<std::uint8_t> &in
133  );
134  virtual int address() const;
135 };
136 
137 } } } }
DevSmbus(const std::string &devname, int devaddr, bool pec=true)
Opens the device file for the bus.
Definition: DevSmbus.cpp:24
virtual void transmitByte(std::uint8_t byte)
Sends a single byte to the device.
Definition: DevSmbus.cpp:134
virtual int receive(std::uint8_t cmd, std::uint8_t *in, const int maxlen)
Sends a command byte, then reads a block of data from the device.
Definition: DevSmbus.cpp:194
Use with constructors to specify that Packet Error Checking (PEC) will not be used.
Definition: Smbus.hpp:70
Implementation of the Smbus interface using the Linux kernel&#39;s user-space support.
Definition: DevSmbus.hpp:40
~DevSmbus()
Closes the device file.
Definition: DevSmbus.cpp:53
virtual int address() const
Returns the address of the device that this object will attempt to communicate with.
Definition: DevSmbus.cpp:285
DevSmbus(const std::string &devname, int devaddr, NoPec)
Opens the device file for the bus and specifies that Packet Error Checking (PEC) will not be used...
Definition: DevSmbus.hpp:102
An interface for communication with a SMBus device.
Definition: Smbus.hpp:56
virtual void transmit(std::uint8_t cmd, const std::uint8_t *out, const int len)
Sends a command byte and a block of data to the device.
Definition: DevSmbus.cpp:226
virtual std::uint8_t receiveByte()
Read a single byte from the device without sending a command/register byte first. ...
Definition: DevSmbus.cpp:122
int addr
The device (slave) address; used for error reporting.
Definition: DevSmbus.hpp:52
Use with constructors to explicitly specify that Packet Error Checking (PEC) be used.
Definition: Smbus.hpp:64
int fd
The file descriptor for the open device.
Definition: DevSmbus.hpp:48
void io(i2c_smbus_ioctl_data &sdat)
Sends I/O requests to the kernel, then checks for an error and if found throws the appropriate except...
Definition: DevSmbus.cpp:57
std::string dev
Stores the device file name for later error reporting.
Definition: DevSmbus.hpp:44
virtual std::uint16_t receiveWord(std::uint8_t cmd)
Sends a command byte, then reads a word, two bytes, from the device.
Definition: DevSmbus.cpp:170
virtual void transmitWord(std::uint8_t cmd, std::uint16_t word)
Sends a command byte and a data word to the device.
Definition: DevSmbus.cpp:182
virtual std::uint16_t call(std::uint8_t cmd, std::uint16_t word)
Does a process call operation.
Definition: DevSmbus.cpp:248
DevSmbus(const std::string &devname, int devaddr, UsePec)
Opens the device file for the bus and specifies that Packet Error Checking (PEC) will be used...
Definition: DevSmbus.hpp:88
virtual void transmitBool(bool out)
Sends a single bit to the device.
Definition: DevSmbus.cpp:112