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

Last change on this file since 317 was 216, checked in by Sanahuja Guillaume, 6 years ago

maj

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