Commit b50efff339e55b44a1d967b38b3ca96633060f9f
1 parent
5317bfff
Started refactoring/improving code. Added config files for Visual Studio Code. R…
…emoved unused files. Added 'mn' namespace.
Showing
5 changed files
with
106 additions
and
69 deletions
.vscode/c_cpp_properties.json
0 → 100644
| 1 | +{ | ||
| 2 | + "configurations": [ | ||
| 3 | + { | ||
| 4 | + "name": "Mac", | ||
| 5 | + "includePath": [ | ||
| 6 | + "/usr/include", | ||
| 7 | + "/usr/local/include", | ||
| 8 | + "${workspaceRoot}" | ||
| 9 | + ], | ||
| 10 | + "defines": [], | ||
| 11 | + "intelliSenseMode": "clang-x64", | ||
| 12 | + "browse": { | ||
| 13 | + "path": [ | ||
| 14 | + "/usr/include", | ||
| 15 | + "/usr/local/include", | ||
| 16 | + "${workspaceRoot}" | ||
| 17 | + ], | ||
| 18 | + "limitSymbolsToIncludedHeaders": true, | ||
| 19 | + "databaseFilename": "" | ||
| 20 | + }, | ||
| 21 | + "macFrameworkPath": [ | ||
| 22 | + "/System/Library/Frameworks", | ||
| 23 | + "/Library/Frameworks" | ||
| 24 | + ] | ||
| 25 | + }, | ||
| 26 | + { | ||
| 27 | + "name": "Linux", | ||
| 28 | + "includePath": [ | ||
| 29 | + "/usr/include/c++/6", | ||
| 30 | + "/usr/include/x86_64-linux-gnu/c++/6", | ||
| 31 | + "/usr/include/c++/6/backward", | ||
| 32 | + "/usr/lib/gcc/x86_64-linux-gnu/6/include", | ||
| 33 | + "/usr/local/include", | ||
| 34 | + "/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed", | ||
| 35 | + "/usr/include/x86_64-linux-gnu", | ||
| 36 | + "/usr/include", | ||
| 37 | + "${workspaceRoot}", | ||
| 38 | + "${workspaceRoot}/include" | ||
| 39 | + ], | ||
| 40 | + "defines": [], | ||
| 41 | + "intelliSenseMode": "clang-x64", | ||
| 42 | + "browse": { | ||
| 43 | + "path": [ | ||
| 44 | + "/usr/include/c++/6", | ||
| 45 | + "/usr/include/x86_64-linux-gnu/c++/6", | ||
| 46 | + "/usr/include/c++/6/backward", | ||
| 47 | + "/usr/lib/gcc/x86_64-linux-gnu/6/include", | ||
| 48 | + "/usr/local/include", | ||
| 49 | + "/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed", | ||
| 50 | + "/usr/include/x86_64-linux-gnu", | ||
| 51 | + "/usr/include", | ||
| 52 | + "${workspaceRoot}", | ||
| 53 | + "${workspaceRoot}/include" | ||
| 54 | + ], | ||
| 55 | + "limitSymbolsToIncludedHeaders": true, | ||
| 56 | + "databaseFilename": "" | ||
| 57 | + } | ||
| 58 | + }, | ||
| 59 | + { | ||
| 60 | + "name": "Win32", | ||
| 61 | + "includePath": [ | ||
| 62 | + "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include", | ||
| 63 | + "${workspaceRoot}" | ||
| 64 | + ], | ||
| 65 | + "defines": [ | ||
| 66 | + "_DEBUG", | ||
| 67 | + "UNICODE" | ||
| 68 | + ], | ||
| 69 | + "intelliSenseMode": "msvc-x64", | ||
| 70 | + "browse": { | ||
| 71 | + "path": [ | ||
| 72 | + "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*", | ||
| 73 | + "${workspaceRoot}" | ||
| 74 | + ], | ||
| 75 | + "limitSymbolsToIncludedHeaders": true, | ||
| 76 | + "databaseFilename": "" | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + ], | ||
| 80 | + "version": 3 | ||
| 81 | +} | ||
| 0 | \ No newline at end of file | 82 | \ No newline at end of file |
README.rst
| 1 | -============================================================== | ||
| 2 | -serial-port-cpp | ||
| 3 | -============================================================== | 1 | +============== |
| 2 | +CppLinuxSerial | ||
| 3 | +============== | ||
| 4 | 4 | ||
| 5 | ---------------------------------- | 5 | ---------------------------------- |
| 6 | Serial port library written in C++ | 6 | Serial port library written in C++ |
| @@ -9,20 +9,6 @@ Serial port library written in C++ | @@ -9,20 +9,6 @@ Serial port library written in C++ | ||
| 9 | .. image:: https://api.travis-ci.org/gbmhunter/serial-port-cpp.png?branch=master | 9 | .. image:: https://api.travis-ci.org/gbmhunter/serial-port-cpp.png?branch=master |
| 10 | :target: https://travis-ci.org/gbmhunter/serial-port-cpp | 10 | :target: https://travis-ci.org/gbmhunter/serial-port-cpp |
| 11 | 11 | ||
| 12 | -- Author: gbmhunter <gbmhunter@gmail.com> (http://www.cladlab.com) | ||
| 13 | -- Created: 2014/01/07 | ||
| 14 | -- Last Modified: 2014/05/21 | ||
| 15 | -- Version: v1.0.1.0 | ||
| 16 | -- Company: CladLabs | ||
| 17 | -- Project: Free Code Libraries | ||
| 18 | -- Language: C++ | ||
| 19 | -- Compiler: GCC | ||
| 20 | -- uC Model: n/a | ||
| 21 | -- Computer Architecture: n/a | ||
| 22 | -- Operating System: n/a | ||
| 23 | -- Documentation Format: Doxygen | ||
| 24 | -- License: GPLv3 | ||
| 25 | - | ||
| 26 | .. role:: bash(code) | 12 | .. role:: bash(code) |
| 27 | :language: bash | 13 | :language: bash |
| 28 | 14 |
include/Config.hpp deleted
| 1 | -//! | ||
| 2 | -//! @file Config.hpp | ||
| 3 | -//! @author Geoffrey Hunter <gbmhunter@gmail.com> () | ||
| 4 | -//! @created 2014/01/07 | ||
| 5 | -//! @last-modified 2014/01/07 | ||
| 6 | -//! @brief Config file for the ComPort library. | ||
| 7 | -//! @details | ||
| 8 | -//! See README.rst in repo root dir for more info. | ||
| 9 | - | ||
| 10 | - | ||
| 11 | -namespace SerialPort | ||
| 12 | -{ | ||
| 13 | - | ||
| 14 | - | ||
| 15 | -} |
include/SerialPort.hpp renamed to include/SerialPort/SerialPort.hpp
| 1 | -//! | ||
| 2 | -//! @file SerialPort.hpp | ||
| 3 | -//! @author Geoffrey Hunter <gbmhunter@gmail.com> () | ||
| 4 | -//! @created 2014/01/07 | ||
| 5 | -//! @last-modified 2014/05/21 | ||
| 6 | -//! @brief The main serial port class. | ||
| 7 | -//! @details | ||
| 8 | -//! See README.rst in repo root dir for more info. | 1 | +/// |
| 2 | +/// \file SerialPort.hpp | ||
| 3 | +/// \author Geoffrey Hunter <gbmhunter@gmail.com> () | ||
| 4 | +/// \created 2014-01-07 | ||
| 5 | +/// \last-modified 2017-11-23 | ||
| 6 | +/// \brief The main serial port class. | ||
| 7 | +/// \details | ||
| 8 | +/// See README.rst in repo root dir for more info. | ||
| 9 | 9 | ||
| 10 | // Header guard | 10 | // Header guard |
| 11 | #ifndef SERIAL_PORT_SERIAL_PORT_H | 11 | #ifndef SERIAL_PORT_SERIAL_PORT_H |
| @@ -17,14 +17,13 @@ | @@ -17,14 +17,13 @@ | ||
| 17 | #include <termios.h> // POSIX terminal control definitions (struct termios) | 17 | #include <termios.h> // POSIX terminal control definitions (struct termios) |
| 18 | 18 | ||
| 19 | // User headers | 19 | // User headers |
| 20 | -#include "lib/SmartPrint/include/Sp.hpp" | ||
| 21 | 20 | ||
| 21 | +namespace mn { | ||
| 22 | namespace SerialPort | 22 | namespace SerialPort |
| 23 | { | 23 | { |
| 24 | 24 | ||
| 25 | - //! @brief Strongly-typed enumeration of baud rates for use with the SerialPort class | ||
| 26 | - enum class BaudRates | ||
| 27 | - { | 25 | + /// \brief Strongly-typed enumeration of baud rates for use with the SerialPort class |
| 26 | + enum class BaudRates { | ||
| 28 | none, | 27 | none, |
| 29 | b9600, | 28 | b9600, |
| 30 | b57600 | 29 | b57600 |
| @@ -88,9 +87,6 @@ namespace SerialPort | @@ -88,9 +87,6 @@ namespace SerialPort | ||
| 88 | //! @brief The file descriptor for the open file. This gets written to when Open() is called. | 87 | //! @brief The file descriptor for the open file. This gets written to when Open() is called. |
| 89 | int fileDesc; | 88 | int fileDesc; |
| 90 | 89 | ||
| 91 | - //! @brief Object for printing debug and error messages with | ||
| 92 | - SmartPrint::Sp* sp; | ||
| 93 | - | ||
| 94 | //! @brief Returns a populated termios structure for the passed in file descriptor. | 90 | //! @brief Returns a populated termios structure for the passed in file descriptor. |
| 95 | termios GetTermios(); | 91 | termios GetTermios(); |
| 96 | 92 | ||
| @@ -99,5 +95,6 @@ namespace SerialPort | @@ -99,5 +95,6 @@ namespace SerialPort | ||
| 99 | }; | 95 | }; |
| 100 | 96 | ||
| 101 | } // namespace SerialPort | 97 | } // namespace SerialPort |
| 98 | +} // namespace mn | ||
| 102 | 99 | ||
| 103 | #endif // #ifndef SERIAL_PORT_SERIAL_PORT_H | 100 | #endif // #ifndef SERIAL_PORT_SERIAL_PORT_H |
src/SerialPort.cpp
| 1 | //! | 1 | //! |
| 2 | //! @file SerialPort.cpp | 2 | //! @file SerialPort.cpp |
| 3 | //! @author Geoffrey Hunter <gbmhunter@gmail.com> () | 3 | //! @author Geoffrey Hunter <gbmhunter@gmail.com> () |
| 4 | -//! @created 2014/01/07 | ||
| 5 | -//! @last-modified 2014/05/21 | 4 | +//! @created 2014-01-07 |
| 5 | +//! @last-modified 2017-11-23 | ||
| 6 | //! @brief The main serial port class. | 6 | //! @brief The main serial port class. |
| 7 | //! @details | 7 | //! @details |
| 8 | //! See README.rst in repo root dir for more info. | 8 | //! See README.rst in repo root dir for more info. |
| @@ -17,9 +17,7 @@ | @@ -17,9 +17,7 @@ | ||
| 17 | #include <termios.h> // POSIX terminal control definitions (struct termios) | 17 | #include <termios.h> // POSIX terminal control definitions (struct termios) |
| 18 | #include <system_error> // For throwing std::system_error | 18 | #include <system_error> // For throwing std::system_error |
| 19 | 19 | ||
| 20 | -#include "../include/Config.hpp" | ||
| 21 | -#include "../include/SerialPort.hpp" | ||
| 22 | -#include "lib/SmartPrint/api/SmartPrint.hpp" | 20 | +#include "SerialPort/SerialPort.hpp" |
| 23 | 21 | ||
| 24 | namespace SerialPort | 22 | namespace SerialPort |
| 25 | { | 23 | { |
| @@ -27,16 +25,7 @@ namespace SerialPort | @@ -27,16 +25,7 @@ namespace SerialPort | ||
| 27 | SerialPort::SerialPort() : | 25 | SerialPort::SerialPort() : |
| 28 | filePath(std::string()), | 26 | filePath(std::string()), |
| 29 | baudRate(BaudRates::none), | 27 | baudRate(BaudRates::none), |
| 30 | - fileDesc(0), | ||
| 31 | - sp( | ||
| 32 | - new SmartPrint::Sp( | ||
| 33 | - "Port", | ||
| 34 | - &std::cout, | ||
| 35 | - &SmartPrint::Colours::yellow, | ||
| 36 | - &std::cout, | ||
| 37 | - &SmartPrint::Colours::yellow, | ||
| 38 | - &std::cerr, | ||
| 39 | - &SmartPrint::Colours::red)) | 28 | + fileDesc(0) |
| 40 | { | 29 | { |
| 41 | // Everything setup in initialiser list | 30 | // Everything setup in initialiser list |
| 42 | } | 31 | } |
| @@ -85,10 +74,9 @@ namespace SerialPort | @@ -85,10 +74,9 @@ namespace SerialPort | ||
| 85 | void SerialPort::Open() | 74 | void SerialPort::Open() |
| 86 | { | 75 | { |
| 87 | 76 | ||
| 88 | - this->sp->PrintDebug(SmartPrint::Ss() << "Attempting to open COM port \"" << this->filePath << "\"."); | 77 | + std::cout << "Attempting to open COM port \"" << this->filePath << "\"." << std::endl; |
| 89 | 78 | ||
| 90 | - if(this->filePath.size() == 0) | ||
| 91 | - { | 79 | + if(this->filePath.size() == 0) { |
| 92 | //this->sp->PrintError(SmartPrint::Ss() << "Attempted to open file when file path has not been assigned to."); | 80 | //this->sp->PrintError(SmartPrint::Ss() << "Attempted to open file when file path has not been assigned to."); |
| 93 | //return false; | 81 | //return false; |
| 94 | 82 | ||
| @@ -112,7 +100,7 @@ namespace SerialPort | @@ -112,7 +100,7 @@ namespace SerialPort | ||
| 112 | throw std::system_error(EFAULT, std::system_category()); | 100 | throw std::system_error(EFAULT, std::system_category()); |
| 113 | } | 101 | } |
| 114 | 102 | ||
| 115 | - this->sp->PrintDebug(SmartPrint::Ss() << "COM port opened successfully."); | 103 | + std::cout << "COM port opened successfully." << std::endl; |
| 116 | 104 | ||
| 117 | // If code reaches here, open and config must of been successful | 105 | // If code reaches here, open and config must of been successful |
| 118 | 106 | ||
| @@ -130,7 +118,7 @@ namespace SerialPort | @@ -130,7 +118,7 @@ namespace SerialPort | ||
| 130 | 118 | ||
| 131 | void SerialPort::SetEverythingToCommonDefaults() | 119 | void SerialPort::SetEverythingToCommonDefaults() |
| 132 | { | 120 | { |
| 133 | - this->sp->PrintDebug(SmartPrint::Ss() << "Configuring COM port \"" << this->filePath << "\"."); | 121 | + std::cout << "Configuring COM port \"" << this->filePath << "\"." << std::endl; |
| 134 | 122 | ||
| 135 | //================== CONFIGURE ==================// | 123 | //================== CONFIGURE ==================// |
| 136 | 124 | ||
| @@ -313,7 +301,7 @@ namespace SerialPort | @@ -313,7 +301,7 @@ namespace SerialPort | ||
| 313 | if(tcgetattr(this->fileDesc, &tty) != 0) | 301 | if(tcgetattr(this->fileDesc, &tty) != 0) |
| 314 | { | 302 | { |
| 315 | // Error occurred | 303 | // Error occurred |
| 316 | - this->sp->PrintError(SmartPrint::Ss() << "Could not get terminal attributes for \"" << this->filePath << "\" - " << strerror(errno)); | 304 | + std::cout << "Could not get terminal attributes for \"" << this->filePath << "\" - " << strerror(errno) << std::endl; |
| 317 | throw std::system_error(EFAULT, std::system_category()); | 305 | throw std::system_error(EFAULT, std::system_category()); |
| 318 | //return false; | 306 | //return false; |
| 319 | } | 307 | } |
| @@ -329,7 +317,7 @@ namespace SerialPort | @@ -329,7 +317,7 @@ namespace SerialPort | ||
| 329 | if(tcsetattr(this->fileDesc, TCSANOW, &myTermios) != 0) | 317 | if(tcsetattr(this->fileDesc, TCSANOW, &myTermios) != 0) |
| 330 | { | 318 | { |
| 331 | // Error occurred | 319 | // Error occurred |
| 332 | - this->sp->PrintError(SmartPrint::Ss() << "Could not apply terminal attributes for \"" << this->filePath << "\" - " << strerror(errno)); | 320 | + std::cout << "Could not apply terminal attributes for \"" << this->filePath << "\" - " << strerror(errno) << std::endl; |
| 333 | throw std::system_error(EFAULT, std::system_category()); | 321 | throw std::system_error(EFAULT, std::system_category()); |
| 334 | 322 | ||
| 335 | } | 323 | } |