#include #include #include #include #include #include #include "include/serial.h" #undef max using namespace std::literals::chrono_literals; using namespace serial; namespace ranges = std::ranges; namespace views = std::views; void PrintLog(const std::string &msg) { std::cout << msg << std::endl; } int main(int argc, char **const argv) { Serial serial; auto ports = serial::GetUsbPorts(); ranges::for_each(ports, [](const auto &port) { std::cout << port << std::endl; }); std::string portName; std::string command; std::cin >> portName; std::cin.ignore(std::numeric_limits::max(), '\n'); serial.OpenDevice(portName); serial.SetLogCallBack(PrintLog); while (true) { command.clear(); std::getline(std::cin, command); system("cls"); auto startTime = std::chrono::system_clock::now(); if (command.find(":") != std::string::npos) { command.erase(std::remove_if(command.begin(), command.end(), [](char c) { return c == ':'; }), command.end()); auto reallyCommand = command.substr(0, command.find_first_of(' ')); auto expect = command.substr(command.find_first_of(' ') + 1, command.length()); auto res = serial.GetAtUntil(reallyCommand, expect, 2000); auto endTime = std::chrono::system_clock::now(); std::cout << "dura: " << std::chrono::duration_cast( endTime - startTime) .count() << std::endl; } else { auto resp = serial.GetAtResponse(command); auto endTime = std::chrono::system_clock::now(); std::cout << "dura: " << std::chrono::duration_cast( endTime - startTime) .count() << std::endl; std::cout << resp.value_or("Send Command Fail") << std::endl; } } return 0; }