DUDS
Distributed Update of Data from Something
Smbus.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  */
10 #ifndef SMBUS_HPP
11 #define SMBUS_HPP
12 
13 #include <cstdint>
14 #include <vector>
15 #include <boost/noncopyable.hpp>
16 
17 namespace duds { namespace hardware { namespace interface {
18 
56 class Smbus : boost::noncopyable {
57 public:
58  virtual ~Smbus() = 0;
59  // PEC
64  struct UsePec { };
70  struct NoPec { };
71  // some flag for big-endian data; standard is little
89  virtual std::uint8_t receiveByte() = 0;
107  virtual std::uint8_t receiveByte(std::uint8_t cmd) = 0;
125  virtual std::uint16_t receiveWord(std::uint8_t cmd) = 0;
146  std::uint16_t receiveWordBe(std::uint8_t cmd) {
147  std::uint16_t result = receiveWord(cmd);
148  return (result << 8) | (result >> 8);
149  }
171  virtual int receive(std::uint8_t cmd, std::uint8_t *in,
172  const int maxlen) = 0;
191  virtual void receive(std::uint8_t cmd, std::vector<std::uint8_t> &in) = 0;
207  virtual void transmitBool(bool out) = 0;
224  virtual void transmitByte(std::uint8_t byte) = 0;
242  virtual void transmitByte(std::uint8_t cmd, std::uint8_t byte) = 0;
260  virtual void transmitWord(std::uint8_t cmd, std::uint16_t word) = 0;
281  void transmitWordBe(std::uint8_t cmd, std::uint16_t word) {
282  transmitWord(cmd, (word << 8) | (word >> 8));
283  }
305  virtual void transmit(
306  std::uint8_t cmd,
307  const std::uint8_t *out,
308  const int len
309  ) = 0;
330  void transmit(std::uint8_t cmd, const std::vector<std::uint8_t> &out) {
331  transmit(cmd, &(out[0]), out.size());
332  }
352  virtual std::uint16_t call(std::uint8_t cmd, std::uint16_t word) = 0;
374  virtual void call(
375  std::uint8_t cmd,
376  const std::vector<std::uint8_t> &out,
377  std::vector<std::uint8_t> &in
378  ) = 0;
383  virtual int address() const = 0;
384 };
385 
386 } } }
387 
388 #endif // #ifndef SMBUS_HPP
virtual std::uint16_t call(std::uint8_t cmd, std::uint16_t word)=0
Does a process call operation.
virtual void transmitWord(std::uint8_t cmd, std::uint16_t word)=0
Sends a command byte and a data word to the device.
virtual void transmitByte(std::uint8_t byte)=0
Sends a single byte to the device.
void transmitWordBe(std::uint8_t cmd, std::uint16_t word)
Sends a command byte and a big-endian data word to the device.
Definition: Smbus.hpp:281
virtual int address() const =0
Returns the address of the device that this object will attempt to communicate with.
Use with constructors to specify that Packet Error Checking (PEC) will not be used.
Definition: Smbus.hpp:70
virtual std::uint16_t receiveWord(std::uint8_t cmd)=0
Sends a command byte, then reads a word, two bytes, from the device.
std::uint16_t receiveWordBe(std::uint8_t cmd)
Sends a command byte, then reads a big-endian word from the device.
Definition: Smbus.hpp:146
An interface for communication with a SMBus device.
Definition: Smbus.hpp:56
Use with constructors to explicitly specify that Packet Error Checking (PEC) be used.
Definition: Smbus.hpp:64
virtual int receive(std::uint8_t cmd, std::uint8_t *in, const int maxlen)=0
Sends a command byte, then reads a block of data from the device.
virtual std::uint8_t receiveByte()=0
Read a single byte from the device without sending a command/register byte first. ...
void transmit(std::uint8_t cmd, const std::vector< std::uint8_t > &out)
Sends a command byte and a block of data to the device.
Definition: Smbus.hpp:330
virtual void transmitBool(bool out)=0
Sends a single bit to the device.
virtual void transmit(std::uint8_t cmd, const std::uint8_t *out, const int len)=0
Sends a command byte and a block of data to the device.