source: flair-src/trunk/lib/FlairCore/src/Unix_I2cPort.cpp @ 67

Last change on this file since 67 was 15, checked in by Bayard Gildas, 6 years ago

sources reformatted with flair-format-dir script

File size: 1.5 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5//  created:    2014/08/28
6//  filename:   Unix_I2cPort.cpp
7//
8//  author:     Guillaume Sanahuja
9//              Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11//  version:    $Id: $
12//
13//  purpose:    Class for unix i2c port
14//
15//
16/*********************************************************************/
17
18#include "Unix_I2cPort.h"
19#include <errno.h>
20#include <fcntl.h> /* File control definitions */
21#include <unistd.h>
22#include <sys/ioctl.h>
23#include <linux/i2c-dev.h>
24
25using std::string;
26
27namespace flair {
28namespace core {
29
30Unix_I2cPort::Unix_I2cPort(const Object *parent, string name, string device)
31    : I2cPort(parent, name) {
32  // open port
33  fd = open(device.c_str(), O_RDWR);
34  if (fd == -1) {
35    Err("open_port: Unable to open %s\n", device.c_str());
36  }
37}
38
39Unix_I2cPort::~Unix_I2cPort() { close(fd); }
40
41void Unix_I2cPort::SetRxTimeout(core::Time timeout_ns) {
42  Warn("not implemented\n");
43}
44
45void Unix_I2cPort::SetTxTimeout(core::Time timeout_ns) {
46  Warn("not implemented\n");
47}
48
49int Unix_I2cPort::SetSlave(uint16_t address) {
50  int err = ioctl(fd, I2C_SLAVE_FORCE, address);
51  if (err < 0) {
52    Err("Failed to set slave address\n");
53  }
54
55  return err;
56}
57
58ssize_t Unix_I2cPort::Write(const void *buf, size_t nbyte) {
59  return write(fd, buf, nbyte);
60}
61
62ssize_t Unix_I2cPort::Read(void *buf, size_t nbyte) {
63  return read(fd, buf, nbyte);
64}
65
66} // end namespace core
67} // end namespace flair
Note: See TracBrowser for help on using the repository browser.