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 | 82 | \ No newline at end of file | ... | ... |
README.rst
| 1 | -============================================================== | |
| 2 | -serial-port-cpp | |
| 3 | -============================================================== | |
| 1 | +============== | |
| 2 | +CppLinuxSerial | |
| 3 | +============== | |
| 4 | 4 | |
| 5 | 5 | ---------------------------------- |
| 6 | 6 | Serial port library written in C++ |
| ... | ... | @@ -9,20 +9,6 @@ Serial port library written in C++ |
| 9 | 9 | .. image:: https://api.travis-ci.org/gbmhunter/serial-port-cpp.png?branch=master |
| 10 | 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 | 12 | .. role:: bash(code) |
| 27 | 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 | 10 | // Header guard |
| 11 | 11 | #ifndef SERIAL_PORT_SERIAL_PORT_H |
| ... | ... | @@ -17,14 +17,13 @@ |
| 17 | 17 | #include <termios.h> // POSIX terminal control definitions (struct termios) |
| 18 | 18 | |
| 19 | 19 | // User headers |
| 20 | -#include "lib/SmartPrint/include/Sp.hpp" | |
| 21 | 20 | |
| 21 | +namespace mn { | |
| 22 | 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 | 27 | none, |
| 29 | 28 | b9600, |
| 30 | 29 | b57600 |
| ... | ... | @@ -88,9 +87,6 @@ namespace SerialPort |
| 88 | 87 | //! @brief The file descriptor for the open file. This gets written to when Open() is called. |
| 89 | 88 | int fileDesc; |
| 90 | 89 | |
| 91 | - //! @brief Object for printing debug and error messages with | |
| 92 | - SmartPrint::Sp* sp; | |
| 93 | - | |
| 94 | 90 | //! @brief Returns a populated termios structure for the passed in file descriptor. |
| 95 | 91 | termios GetTermios(); |
| 96 | 92 | |
| ... | ... | @@ -99,5 +95,6 @@ namespace SerialPort |
| 99 | 95 | }; |
| 100 | 96 | |
| 101 | 97 | } // namespace SerialPort |
| 98 | +} // namespace mn | |
| 102 | 99 | |
| 103 | 100 | #endif // #ifndef SERIAL_PORT_SERIAL_PORT_H | ... | ... |
src/SerialPort.cpp
| 1 | 1 | //! |
| 2 | 2 | //! @file SerialPort.cpp |
| 3 | 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 | 6 | //! @brief The main serial port class. |
| 7 | 7 | //! @details |
| 8 | 8 | //! See README.rst in repo root dir for more info. |
| ... | ... | @@ -17,9 +17,7 @@ |
| 17 | 17 | #include <termios.h> // POSIX terminal control definitions (struct termios) |
| 18 | 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 | 22 | namespace SerialPort |
| 25 | 23 | { |
| ... | ... | @@ -27,16 +25,7 @@ namespace SerialPort |
| 27 | 25 | SerialPort::SerialPort() : |
| 28 | 26 | filePath(std::string()), |
| 29 | 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 | 30 | // Everything setup in initialiser list |
| 42 | 31 | } |
| ... | ... | @@ -85,10 +74,9 @@ namespace SerialPort |
| 85 | 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 | 80 | //this->sp->PrintError(SmartPrint::Ss() << "Attempted to open file when file path has not been assigned to."); |
| 93 | 81 | //return false; |
| 94 | 82 | |
| ... | ... | @@ -112,7 +100,7 @@ namespace SerialPort |
| 112 | 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 | 105 | // If code reaches here, open and config must of been successful |
| 118 | 106 | |
| ... | ... | @@ -130,7 +118,7 @@ namespace SerialPort |
| 130 | 118 | |
| 131 | 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 | 123 | //================== CONFIGURE ==================// |
| 136 | 124 | |
| ... | ... | @@ -313,7 +301,7 @@ namespace SerialPort |
| 313 | 301 | if(tcgetattr(this->fileDesc, &tty) != 0) |
| 314 | 302 | { |
| 315 | 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 | 305 | throw std::system_error(EFAULT, std::system_category()); |
| 318 | 306 | //return false; |
| 319 | 307 | } |
| ... | ... | @@ -329,7 +317,7 @@ namespace SerialPort |
| 329 | 317 | if(tcsetattr(this->fileDesc, TCSANOW, &myTermios) != 0) |
| 330 | 318 | { |
| 331 | 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 | 321 | throw std::system_error(EFAULT, std::system_category()); |
| 334 | 322 | |
| 335 | 323 | } | ... | ... |