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

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

sources reformatted with flair-format-dir script

File size: 1.5 KB
RevLine 
[2]1// %flair:license{
[15]2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
[2]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>
[15]20#include <fcntl.h> /* File control definitions */
[2]21#include <unistd.h>
22#include <sys/ioctl.h>
23#include <linux/i2c-dev.h>
24
25using std::string;
26
[15]27namespace flair {
28namespace core {
[2]29
[15]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 }
[2]37}
38
[15]39Unix_I2cPort::~Unix_I2cPort() { close(fd); }
[2]40
[15]41void Unix_I2cPort::SetRxTimeout(core::Time timeout_ns) {
42 Warn("not implemented\n");
[2]43}
44
[15]45void Unix_I2cPort::SetTxTimeout(core::Time timeout_ns) {
46 Warn("not implemented\n");
[2]47}
48
[15]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 }
[2]54
[15]55 return err;
[2]56}
57
[15]58ssize_t Unix_I2cPort::Write(const void *buf, size_t nbyte) {
59 return write(fd, buf, nbyte);
[2]60}
61
[15]62ssize_t Unix_I2cPort::Read(void *buf, size_t nbyte) {
63 return read(fd, buf, nbyte);
[2]64}
65
66} // end namespace core
67} // end namespace flair
Note: See TracBrowser for help on using the repository browser.