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

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

flaircore

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