#include #include #include #include #include #include #include #include #include #include "SpiPort.h" SpiPort::SpiPort(const std::string& path) : m_path(path), m_fd(0) { } SpiPort::~SpiPort() { if (m_fd > 0) { close(m_fd); } } bool SpiPort::Open() { if(m_fd <= 0) m_fd = open(m_path.c_str(), O_RDWR/*|O_NDELAY|O_NOCTTY*/); if(m_fd <= 0 ) { int err = errno; m_log = "open spi Error errno=" + std::to_string(err); __android_log_print(ANDROID_LOG_INFO, "SPi", "open spi Error errno=%d", err); return false; } else __android_log_print(ANDROID_LOG_INFO, "SPi", "open spi Success m_fd=%d",m_fd); return true; } // write int SpiPort::Write(unsigned char *buf, int len) { return write(m_fd, buf, len); } // read int SpiPort::Read(unsigned char *buf, int len) { return read(m_fd, buf, len); } //close bool SpiPort::Close() { if(m_fd > 0) { close(m_fd); m_fd = 0; } return true; }