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

Last change on this file since 148 was 133, checked in by Sanahuja Guillaume, 7 years ago

modif sterror

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 <fcntl.h> /* File control definitions */
20#include <unistd.h>
21#include <sys/ioctl.h>
22#include <linux/i2c-dev.h>
23
24using std::string;
25
26namespace flair {
27namespace core {
28
29Unix_I2cPort::Unix_I2cPort(const Object *parent, string name, string device)
30 : I2cPort(parent, name) {
31 // open port
32 fd = open(device.c_str(), O_RDWR);
33 if (fd == -1) {
34 Err("open_port: Unable to open %s\n", device.c_str());
35 }
36}
37
38Unix_I2cPort::~Unix_I2cPort() { close(fd); }
39
40void Unix_I2cPort::SetRxTimeout(core::Time timeout_ns) {
41 Warn("not implemented\n");
42}
43
44void Unix_I2cPort::SetTxTimeout(core::Time timeout_ns) {
45 Warn("not implemented\n");
46}
47
48int Unix_I2cPort::SetSlave(uint16_t address) {
49 int err = ioctl(fd, I2C_SLAVE_FORCE, address);
50 if (err < 0) {
51 Err("Failed to set slave address\n");
52 }
53
54 return err;
55}
56
57ssize_t Unix_I2cPort::Write(const void *buf, size_t nbyte) {
58 return write(fd, buf, nbyte);
59}
60
61ssize_t Unix_I2cPort::Read(void *buf, size_t nbyte) {
62 return read(fd, buf, nbyte);
63}
64
65} // end namespace core
66} // end namespace flair
Note: See TracBrowser for help on using the repository browser.