diff --git a/.gitmodules b/.gitmodules index 06b2e16..97aa8bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "rxi/log/3rdparty/log.c"] path = rxi/log/3rdparty/log.c url = https://github.com/rxi/log.c.git +[submodule "communication/cpp_linux_serial/3rdparty/CppLinuxSerial"] + path = communication/cpp_linux_serial/3rdparty/CppLinuxSerial + url = https://github.com/gbmhunter/CppLinuxSerial.git diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md index e69de29..ed6d433 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,4 @@ +# Примеры кода, алгоритмов и библиотек на Си (C++) + +- [rxi/log](rxi/log) — ... +- [CppLinuxSerial](communication/cpp_linux_serial) — Библиотека для работы с Serial в связке с Arduino diff --git a/communication/cpp_linux_serial/.gitignore b/communication/cpp_linux_serial/.gitignore new file mode 100644 index 0000000..5654e6a --- /dev/null +++ b/communication/cpp_linux_serial/.gitignore @@ -0,0 +1,2 @@ +serial_test +SerialPort.o diff --git a/communication/cpp_linux_serial/3rdparty/CppLinuxSerial b/communication/cpp_linux_serial/3rdparty/CppLinuxSerial new file mode 160000 index 0000000..7401bd7 --- /dev/null +++ b/communication/cpp_linux_serial/3rdparty/CppLinuxSerial @@ -0,0 +1 @@ +Subproject commit 7401bd7b064fe0ed1e777364da651c28349c4086 diff --git a/communication/cpp_linux_serial/Makefile b/communication/cpp_linux_serial/Makefile new file mode 100644 index 0000000..4c54732 --- /dev/null +++ b/communication/cpp_linux_serial/Makefile @@ -0,0 +1,10 @@ +PROGRAM = serial_test +CC = g++ -O2 +HEADER = -I./3rdparty/CppLinuxSerial/include + +all: $(PROGRAM) + +$(PROGRAM): + cc $(HEADER) main.cpp SerialPort.o -o $@ -lstdc++ + +.PHONY: $(PROGRAM) diff --git a/communication/cpp_linux_serial/main.cpp b/communication/cpp_linux_serial/main.cpp new file mode 100644 index 0000000..4c729b5 --- /dev/null +++ b/communication/cpp_linux_serial/main.cpp @@ -0,0 +1,32 @@ +#include +#include +#include + +using namespace mn::CppLinuxSerial; + +#define PORT "/dev/ttyACM0" +#define WAIT_SEC 3 + +int main(int argc, char const *argv[]) { + SerialPort serialPort(PORT, BaudRate::B_9600, NumDataBits::EIGHT, + Parity::NONE, NumStopBits::ONE); + serialPort.SetTimeout(100); + std::cout << "Opening " PORT "... " << std::flush; + serialPort.Open(); + std::cout << "OK" << std::endl; + + std::cout << "Waiting Arduino restart... " << std::flush; + std::this_thread::sleep_for(std::chrono::seconds(WAIT_SEC)); + std::cout << "OK" << std::endl; + + std::cout << "Sending string data... " << std::flush; + std::string txDataString = "d"; + serialPort.Write(txDataString); + std::cout << "OK" << std::endl; + + std::cout << "Clossing port... " << std::flush; + serialPort.Close(); + std::cout << "OK" << std::endl; + + return 0; +}