diff options
author | Serhii Kostiuk <serhii.o.kostiuk@globallogic.com> | 2020-06-30 12:49:56 +0300 |
---|---|---|
committer | Serhii Kostiuk <serhii.o.kostiuk@globallogic.com> | 2020-06-30 12:49:56 +0300 |
commit | 24ed390ceb584fadfd428a6e9019371550931094 (patch) | |
tree | bf9d7b72303a8cd9026e625a4cd2812cab708d5c | |
parent | 6e9ce61addd97809d5ea7b912332dd11a4bf7cee (diff) | |
parent | adaca6b0fc6430f38ae3f0551f9a248563ad53b5 (diff) | |
download | libmts-io-24ed390ceb584fadfd428a6e9019371550931094.tar.gz libmts-io-24ed390ceb584fadfd428a6e9019371550931094.tar.bz2 libmts-io-24ed390ceb584fadfd428a6e9019371550931094.zip |
Merge remote-tracking branch 'origin/master' into sk/quectel-delta-fwu
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | include/mts/MTS_IO_CellularRadioFactory.h | 1 | ||||
-rw-r--r-- | include/mts/MTS_IO_EG25Radio.h | 48 | ||||
-rw-r--r-- | include/mts/MTS_IO_EG95Radio.h | 2 | ||||
-rw-r--r-- | include/mts/MTS_IO_LockFile.h | 6 | ||||
-rw-r--r-- | include/mts/MTS_IO_QuectelRadio.h | 2 | ||||
-rw-r--r-- | include/mts/MTS_IO_SerialConnection.h | 2 | ||||
-rw-r--r-- | src/MTS_IO_CellularRadioFactory.cpp | 9 | ||||
-rw-r--r-- | src/MTS_IO_EG25Radio.cpp | 52 | ||||
-rw-r--r-- | src/MTS_IO_EG95Radio.cpp | 40 | ||||
-rw-r--r-- | src/MTS_IO_ICellularRadio.cpp | 23 | ||||
-rw-r--r-- | src/MTS_IO_LockFile.cpp | 94 | ||||
-rw-r--r-- | src/MTS_IO_QuectelRadio.cpp | 34 | ||||
-rw-r--r-- | src/MTS_IO_SerialConnection.cpp | 85 |
14 files changed, 281 insertions, 118 deletions
@@ -6,6 +6,7 @@ libdir ?= /usr/lib OBJS += \ src/MTS_IO_TelitRadio.o \ + src/MTS_IO_EG25Radio.o \ src/MTS_IO_EG95Radio.o \ src/MTS_IO_QuectelRadio.o \ src/MTS_IO_CdmaRadio.o \ diff --git a/include/mts/MTS_IO_CellularRadioFactory.h b/include/mts/MTS_IO_CellularRadioFactory.h index e57ca5e..13f3993 100644 --- a/include/mts/MTS_IO_CellularRadioFactory.h +++ b/include/mts/MTS_IO_CellularRadioFactory.h @@ -55,6 +55,7 @@ namespace MTS { ICellularRadio* createCE910(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; ICellularRadio* createLE866A1JS(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; ICellularRadio* createEG95Radio(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; + ICellularRadio* createEG25Radio(const std::string& sPort = ICellularRadio::DEFAULT_RADIO_PORT) const; protected: typedef MTS::IO::ICellularRadio* (CellularRadioFactory::*CREATEFUNCPTR)(const std::string& sPort) const; diff --git a/include/mts/MTS_IO_EG25Radio.h b/include/mts/MTS_IO_EG25Radio.h new file mode 100644 index 0000000..46bff20 --- /dev/null +++ b/include/mts/MTS_IO_EG25Radio.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2019 by Multi-Tech Systems + * + * This file is part of libmts-io. + * + * libmts-io is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts-io is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts-io. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +#ifndef MTS_IO_EG25RADIO_H_ +#define MTS_IO_EG25RADIO_H_ + +#include "mts/MTS_IO_QuectelRadio.h" + +namespace MTS { + namespace IO { + + class EG25Radio : public QuectelRadio { + + public: + static const std::string MODEL_NAME; + + EG25Radio(const std::string& sPort); + virtual ~EG25Radio(); + CODE setRxDiversity(const Json::Value& jArgs) override; + + protected: + + private: + CODE getSupportedCellularModes(CELLULAR_MODES &networks) override; + + }; + } +} + +#endif /* MTS_IO_EG25RADIO_H_ */ diff --git a/include/mts/MTS_IO_EG95Radio.h b/include/mts/MTS_IO_EG95Radio.h index 5296e16..17c413e 100644 --- a/include/mts/MTS_IO_EG95Radio.h +++ b/include/mts/MTS_IO_EG95Radio.h @@ -40,7 +40,7 @@ namespace MTS { private: CODE getSupportedCellularModes(CELLULAR_MODES &networks) override; - CODE setCellularMode(CELLULAR_MODES networks) override; + }; } } diff --git a/include/mts/MTS_IO_LockFile.h b/include/mts/MTS_IO_LockFile.h index 730cf3c..22e641b 100644 --- a/include/mts/MTS_IO_LockFile.h +++ b/include/mts/MTS_IO_LockFile.h @@ -34,11 +34,8 @@ namespace MTS { namespace IO { - class LockFile : MTS::NonCopyable { - public: - LockFile(const std::string& sFilePath); virtual ~LockFile(); @@ -46,11 +43,10 @@ namespace MTS { void unlock(); bool isLocked(); - protected: - private: std::string m_sFile; int m_iLockFd; + int m_iLockErr; }; } diff --git a/include/mts/MTS_IO_QuectelRadio.h b/include/mts/MTS_IO_QuectelRadio.h index 9ccf50a..c55b224 100644 --- a/include/mts/MTS_IO_QuectelRadio.h +++ b/include/mts/MTS_IO_QuectelRadio.h @@ -42,6 +42,8 @@ namespace MTS { CODE setMdn(const Json::Value& jArgs) override; + CODE setCellularMode(CELLULAR_MODES networks) override; + CODE uploadDeltaFirmwareFile(int fd, UpdateCb& stepCb) override; CODE removeDeltaFirmwareFile() override; CODE applyDeltaFirmwareFile(UpdateCb& stepCb) override; diff --git a/include/mts/MTS_IO_SerialConnection.h b/include/mts/MTS_IO_SerialConnection.h index a4ca011..b0ce663 100644 --- a/include/mts/MTS_IO_SerialConnection.h +++ b/include/mts/MTS_IO_SerialConnection.h @@ -173,6 +173,8 @@ namespace MTS { virtual int doWrite(const char* pBuffer, const uint32_t& iSize, int32_t& timeoutMillis); void cleanup(); + void printPortSetting(const termios *options); + const char* humanSpeed(speed_t speed); }; } } diff --git a/src/MTS_IO_CellularRadioFactory.cpp b/src/MTS_IO_CellularRadioFactory.cpp index 08c6315..1a2cee2 100644 --- a/src/MTS_IO_CellularRadioFactory.cpp +++ b/src/MTS_IO_CellularRadioFactory.cpp @@ -37,6 +37,7 @@ #include <mts/MTS_IO_CE910Radio.h> #include <mts/MTS_IO_DE910Radio.h> #include "mts/MTS_IO_EG95Radio.h" +#include "mts/MTS_IO_EG25Radio.h" #include <mts/MTS_Logger.h> using namespace MTS::IO; @@ -60,6 +61,7 @@ CellularRadioFactory::CellularRadioFactory() { m_mCreationMap[CE910Radio::MODEL_NAME] = &CellularRadioFactory::createCE910; m_mCreationMap[LE866A1JSRadio::MODEL_NAME] = &CellularRadioFactory::createLE866A1JS; m_mCreationMap[EG95Radio::MODEL_NAME] = &CellularRadioFactory::createEG95Radio; + m_mCreationMap[EG25Radio::MODEL_NAME] = &CellularRadioFactory::createEG25Radio; } ICellularRadio* CellularRadioFactory::create(const std::string& sModel, const std::string& sPort) { @@ -191,7 +193,10 @@ ICellularRadio* CellularRadioFactory::createLE866A1JS(const std::string &sPort) return new LE866A1JSRadio(sPort); } -ICellularRadio* CellularRadioFactory::createEG95Radio(const std::string& sPort) const -{ +ICellularRadio* CellularRadioFactory::createEG95Radio(const std::string& sPort) const { return new EG95Radio(sPort); } + +ICellularRadio* CellularRadioFactory::createEG25Radio(const std::string& sPort) const { + return new EG25Radio(sPort); +} diff --git a/src/MTS_IO_EG25Radio.cpp b/src/MTS_IO_EG25Radio.cpp new file mode 100644 index 0000000..aa5d453 --- /dev/null +++ b/src/MTS_IO_EG25Radio.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2019 by Multi-Tech Systems + * + * This file is part of libmts-io. + * + * libmts-io is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * libmts-io is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libmts-io. If not, see <http://www.gnu.org/licenses/>. + * + */ + + +#include <mts/MTS_IO_EG25Radio.h> + +using namespace MTS::IO; + +const std::string EG25Radio::MODEL_NAME("EG25"); + +EG25Radio::EG25Radio(const std::string& sPort) +: QuectelRadio(MODEL_NAME, sPort) +{ + +} + +EG25Radio::~EG25Radio() { + +} + +ICellularRadio::CODE EG25Radio::setRxDiversity(const Json::Value& jArgs) { + /* Command string for EG25 radios: AT+QCFG="diversity",(0-1) */ + if (jArgs["enabled"].asString() != "1" && jArgs["enabled"].asString() != "0") { + return FAILURE; + } + std::string sCmd = "AT+QCFG=\"diversity\","; + sCmd += jArgs["enabled"].asString(); + + return sendBasicCommand(sCmd); +} + +ICellularRadio::CODE EG25Radio::getSupportedCellularModes(CELLULAR_MODES &networks) { + networks = static_cast<CELLULAR_MODES>(CELLULAR_MODE_2G | CELLULAR_MODE_3G | CELLULAR_MODE_4G); + return SUCCESS; +}
\ No newline at end of file diff --git a/src/MTS_IO_EG95Radio.cpp b/src/MTS_IO_EG95Radio.cpp index f1c040a..296f183 100644 --- a/src/MTS_IO_EG95Radio.cpp +++ b/src/MTS_IO_EG95Radio.cpp @@ -18,14 +18,8 @@ * */ - #include <mts/MTS_IO_EG95Radio.h> -#include <climits> - -#include <mts/MTS_Logger.h> -#include <mts/MTS_Text.h> - using namespace MTS::IO; const std::string EG95Radio::MODEL_NAME("EG95"); @@ -54,36 +48,4 @@ ICellularRadio::CODE EG95Radio::setRxDiversity(const Json::Value& jArgs) { ICellularRadio::CODE EG95Radio::getSupportedCellularModes(CELLULAR_MODES &networks) { networks = static_cast<CELLULAR_MODES>(CELLULAR_MODE_2G | CELLULAR_MODE_3G | CELLULAR_MODE_4G); return SUCCESS; -} - -ICellularRadio::CODE EG95Radio::setCellularMode(CELLULAR_MODES networks) { - std::string prefNet; - unsigned int prefOnly = 0, prefCount = 0; - for (int i = sizeof(networks)*CHAR_BIT-1; i>=0; --i){ - switch (1<<i & networks) { - case ICellularRadio::CELLULAR_MODE_2G: prefNet += "01" ; prefOnly = 1; prefCount++; break; - case ICellularRadio::CELLULAR_MODE_3G: prefNet += "0302"; prefOnly = 2; prefCount++; break; - case ICellularRadio::CELLULAR_MODE_4G: prefNet += "04" ; prefOnly = 3; prefCount++; break; - } - } - - std::string sCmd; - if (prefCount == 1) { // *g-only - sCmd = "AT+QCFG=\"nwscanmode\"," + std::to_string(prefOnly); - } else { // preferred - sCmd = "AT+QCFG=\"nwscanmode\",0"; - } - std::string cmdResult = sendCommand(sCmd); - if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { - printError("%s| AT+QCFG=\"nwscanmode\" returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); - return FAILURE; - } - - sCmd = "AT+QCFG=\"nwscanseq\"," + prefNet; - cmdResult = sendCommand(sCmd); - if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { - printError("%s| AT+QCFG=\"nwscanseq\" returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); - return FAILURE; - } - return SUCCESS; -} +}
\ No newline at end of file diff --git a/src/MTS_IO_ICellularRadio.cpp b/src/MTS_IO_ICellularRadio.cpp index 2de52bb..b84fa3f 100644 --- a/src/MTS_IO_ICellularRadio.cpp +++ b/src/MTS_IO_ICellularRadio.cpp @@ -207,6 +207,24 @@ MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertModelToMtsShortCod eCode = ERROR; } } + } else if (sModel.find("EG25") == 0) { + if (NULL == radioObject) { + sCode = VALUE_NOT_SUPPORTED; + eCode = ERROR; + } else { + std::string sValue; + eCode = radioObject->getFirmware(sValue); + if (eCode != SUCCESS) { + sCode = VALUE_NOT_SUPPORTED; + eCode = ERROR; + } else if (sValue.find("EG25G") != std::string::npos) { + sCode = "L4G1"; + eCode = SUCCESS; + } else { + sCode = VALUE_NOT_SUPPORTED; + eCode = ERROR; + } + } } else { sCode = VALUE_NOT_SUPPORTED; printError("RADIO| Could not identify MTS short code from model. [%s]", sModel.c_str()); @@ -300,6 +318,9 @@ MTS::IO::ICellularRadio::CODE MTS::IO::ICellularRadio::convertModelToType(const } else if (sModel.find("EG95") == 0) { sType = VALUE_TYPE_LTE; eCode = SUCCESS; + } else if (sModel.find("EG25") == 0) { + sType = VALUE_TYPE_LTE; + eCode = SUCCESS; } else { sType = VALUE_TYPE_GSM; eCode = ERROR; @@ -445,6 +466,8 @@ std::string MTS::IO::ICellularRadio::extractModelFromResult(const std::string& s sModel = "CE910"; } else if(sResult.find("EG95") != std::string::npos) { sModel = "EG95"; + } else if(sResult.find("EG25") != std::string::npos) { + sModel = "EG25"; } return sModel; } diff --git a/src/MTS_IO_LockFile.cpp b/src/MTS_IO_LockFile.cpp index b74ba73..7f84f42 100644 --- a/src/MTS_IO_LockFile.cpp +++ b/src/MTS_IO_LockFile.cpp @@ -18,9 +18,9 @@ * */ -/*! +/*! \file MTS_IO_LockFile.cpp - \brief A brief description + \brief A brief description \date Oct 8, 2014 \author sgodinez @@ -29,13 +29,7 @@ #include <mts/MTS_IO_LockFile.h> #include <mts/MTS_Timer.h> -#include <mts/MTS_Logger.h> -#include <mts/MTS_System.h> -#include <mts/MTS_Text.h> #include <sys/file.h> -#include <sys/stat.h> -#include <errno.h> -#include <string.h> #include <unistd.h> using namespace MTS::IO; @@ -43,79 +37,49 @@ using namespace MTS::IO; LockFile::LockFile(const std::string& sFile) : m_sFile(sFile) , m_iLockFd(-1) +, m_iLockErr(-1) { - } -LockFile::~LockFile() { +LockFile::~LockFile() +{ unlock(); } -bool LockFile::lock(uint32_t attemptMillis) { - if(isLocked()) { +bool LockFile::lock(uint32_t attemptMillis) +{ + if (isLocked()) { return true; } - MTS::Timer timer; - - timer.start(); - while(timer.getMillis() < attemptMillis) { - m_iLockFd =::open(m_sFile.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_EXCL, 0644); - if (m_iLockFd < 0) { - // device already locked -> bail out - printWarning("LockFile| Failed to Lock [%s] [%d][%s]", m_sFile.c_str(), errno, strerror(errno)); - - //Check if lock file's process still exists - std::string sResult; - if(MTS::System::readFile(m_sFile, sResult) == 0 && sResult.size() > 0) { - struct stat sts; - std::string sProc = "/proc/" + MTS::Text::trim(sResult); - if (stat(sProc.c_str(), &sts) == -1 && errno == ENOENT) { - printWarning("LockFile| Current Lock's Process [%s] does not exist. Removing lock.", sResult.c_str()); - // process doesn't exist -> remove file - ::unlink(m_sFile.c_str()); - } - } - - } else { - //TODO: Investigate using flock in addition to minicom-style lock : flock(m_iLockFd, LOCK_EX | LOCK_NB); - - // %4d to make concurrent mgetty (if any) happy. - // Mgetty treats 4-bytes lock files as binary, - // not text, PID. Making 5+ char file. Brrr... - char buf[256] = {0}; - size_t written = 0; - - sprintf(buf, "%4d\n", getpid()); - size_t wsize = strlen(buf); - - written = write(m_iLockFd, buf, wsize); - - if (wsize != written) { - printError("LockFile| Error writing to lock file [%s] [%d][%s]", m_sFile.c_str(), errno, strerror(errno)); - close(m_iLockFd); - return false; - } - else { - close(m_iLockFd); + m_iLockFd = ::open(m_sFile.c_str(), O_CREAT | O_RDWR, 0644); + if (m_iLockFd >= 0) { + MTS::Timer timer; + timer.start(); + while (timer.getMillis() < attemptMillis) { + m_iLockErr = ::flock(m_iLockFd, LOCK_EX | LOCK_NB); + if (m_iLockErr == 0) { return true; + } else if (errno != EWOULDBLOCK) { + break; } + ::usleep(((rand() % 10) + 1) * 100000); //Sleep from 100ms to 1 Second } - uint32_t randomSleepTime = ((rand() % 10) + 1) * 100000; //Sleep from 100ms to 1 Second - ::usleep(randomSleepTime); + ::close(m_iLockFd); } + m_iLockFd = -1; return false; } -void LockFile::unlock() { - if(isLocked()) { - ::unlink(m_sFile.c_str()); - //TODO: flock cleanup : flock(m_iLockFd, LOCK_UN); - m_iLockFd = -1; - } +void LockFile::unlock() +{ + ::flock(m_iLockFd, LOCK_UN); + ::close(m_iLockFd); + m_iLockFd = -1; + m_iLockErr = -1; } -bool LockFile::isLocked() { - return m_iLockFd >= 0; +bool LockFile::isLocked() +{ + return m_iLockErr == 0; } - diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 8cd7194..a8986f4 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -20,6 +20,8 @@ #include "mts/MTS_IO_QuectelRadio.h" +#include <climits> + #include <mts/MTS_Logger.h> #include <mts/MTS_Thread.h> #include <mts/MTS_Text.h> @@ -618,6 +620,38 @@ ICellularRadio::CODE QuectelRadio::convertToActiveBand(const std::string& sQuect return SUCCESS; } +ICellularRadio::CODE QuectelRadio::setCellularMode(CELLULAR_MODES networks) { + std::string prefNet; + unsigned int prefOnly = 0, prefCount = 0; + for (int i = sizeof(networks)*CHAR_BIT-1; i>=0; --i){ + switch (1<<i & networks) { + case ICellularRadio::CELLULAR_MODE_2G: prefNet += "01" ; prefOnly = 1; prefCount++; break; + case ICellularRadio::CELLULAR_MODE_3G: prefNet += "0302"; prefOnly = 2; prefCount++; break; + case ICellularRadio::CELLULAR_MODE_4G: prefNet += "04" ; prefOnly = 3; prefCount++; break; + } + } + + std::string sCmd; + if (prefCount == 1) { // *g-only + sCmd = "AT+QCFG=\"nwscanmode\"," + std::to_string(prefOnly); + } else { // preferred + sCmd = "AT+QCFG=\"nwscanmode\",0"; + } + std::string cmdResult = sendCommand(sCmd); + if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { + printError("%s| AT+QCFG=\"nwscanmode\" returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); + return FAILURE; + } + + sCmd = "AT+QCFG=\"nwscanseq\"," + prefNet; + cmdResult = sendCommand(sCmd); + if (cmdResult.find(ICellularRadio::RSP_OK) == std::string::npos) { + printError("%s| AT+QCFG=\"nwscanseq\" returned unexpected response: [%s][%s]", getName().c_str(), sCmd.c_str(), cmdResult.c_str()); + return FAILURE; + } + return SUCCESS; +} + ICellularRadio::CODE QuectelRadio::uploadFile(int fd, const std::string& sTargetFilename, ICellularRadio::UpdateCb& stepCb) { size_t dPayloadLenght; size_t nChunks; diff --git a/src/MTS_IO_SerialConnection.cpp b/src/MTS_IO_SerialConnection.cpp index a9f3d6e..936d28d 100644 --- a/src/MTS_IO_SerialConnection.cpp +++ b/src/MTS_IO_SerialConnection.cpp @@ -50,6 +50,7 @@ SerialConnection::Builder::Builder(const std::string& sPortName) , m_eParity(OFF) , m_eDataBits(B8) , m_eStopBits(B1) +, m_eFlowControl(NONE) , m_bBuilt(false) { @@ -254,6 +255,77 @@ int SerialConnection::getFileDescriptor() { return h; } +const char* SerialConnection::humanSpeed(speed_t speed) { + const char *hspeed; + switch (speed) { + case B0: hspeed = "B0"; + break; + case B50: hspeed = "B50"; + break; + case B75: hspeed = "B75"; + break; + case B110: hspeed = "B110"; + break; + case B134: hspeed = "B134"; + break; + case B150: hspeed = "B150"; + break; + case B200: hspeed = "B200"; + break; + case B300: hspeed = "B300"; + break; + case B600: hspeed = "B600"; + break; + case B1200: hspeed = "B1200"; + break; + case B1800: hspeed = "B1800"; + break; + case B2400: hspeed = "B2400"; + break; + case B4800: hspeed = "B4800"; + break; + case B9600: hspeed = "B9600"; + break; + case B19200: hspeed = "B19200"; + break; + case B57600: hspeed = "B57600"; + break; + case B115200: hspeed = "B115200"; + break; + default: hspeed = "unknown"; + } + return hspeed; +} + +void SerialConnection::printPortSetting(const termios *options){ + printDebug("SERIAL| port settings:"); + printDebug("SERIAL| in speed:%s out speed:%s", + humanSpeed(cfgetispeed(options)), + humanSpeed(cfgetospeed(options))); + int data_length=0; + if ((options->c_cflag&CSIZE) == CS5) { + data_length = 5; + } + if ((options->c_cflag&CSIZE) == CS6) { + data_length = 6; + } + if ((options->c_cflag&CSIZE) == CS7) { + data_length = 7; + } + if ((options->c_cflag&CSIZE) == CS8) { + data_length = 8; + } + printDebug("SERIAL| data:%d stop bits:%d", data_length,options->c_cflag&CSTOPB?2:1); + if (!(options->c_cflag&PARENB)) { + printDebug("SERIAL| parity: NONE"); + } else if (options->c_cflag&PARODD) { + printDebug("SERIAL| parity: ODD"); + } else { + printDebug("SERIAL| parity: EVEN"); + } + printDebug("SERIAL| CRTSCTS:%d", options->c_cflag&CRTSCTS?1:0); +} + bool SerialConnection::doOpen(const int32_t& timeoutMillis) { m_apHandleLock->lock(); @@ -353,6 +425,7 @@ bool SerialConnection::doOpen(const int32_t& timeoutMillis) { } //Set Parity, Stop Bits, and Data Length + options.c_cflag &= ~(PARODD | PARENB); switch(m_eParity) { case ODD: options.c_cflag |= ( PARODD | PARENB ); @@ -364,7 +437,6 @@ bool SerialConnection::doOpen(const int32_t& timeoutMillis) { case OFF: default: - options.c_cflag &= ~PARENB; break; } @@ -390,7 +462,7 @@ bool SerialConnection::doOpen(const int32_t& timeoutMillis) { switch(m_eStopBits) { case B2: - options.c_cflag &= CSTOPB; + options.c_cflag |= CSTOPB; break; case B1: @@ -401,19 +473,20 @@ bool SerialConnection::doOpen(const int32_t& timeoutMillis) { switch (m_eFlowControl) { case RTS_CTS: - options.c_cflag &= CRTSCTS; + options.c_cflag |= CRTSCTS; break; case NONE: default: - options.c_cflag &= ~(IXON | IXOFF | IXANY); - break; + options.c_cflag &= ~CRTSCTS; + break; } //Set Control Modes options.c_cc[VMIN] = 0; options.c_cc[VTIME] = 2; // tenths of seconds - + printPortSetting(&options); result = tcsetattr(m_iHandle, TCSANOW, &options); + if (result == -1) { printWarning("SERIAL| Failed to set configurations on port [%s] [%d]%s", m_sPortName.c_str(), errno, errno == 13 ? " (Permission Denied)" : ""); |