优化约束
This commit is contained in:
48
main.cc
48
main.cc
@@ -1,19 +1,40 @@
|
||||
#include "include/serial.h"
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <ranges>
|
||||
#include <limits>
|
||||
#include <ranges>
|
||||
#include <string_view>
|
||||
|
||||
#include "include/serial.h"
|
||||
#undef max
|
||||
using namespace std::literals::chrono_literals;
|
||||
using namespace std::literals::string_view_literals;
|
||||
using namespace std::literals::string_literals;
|
||||
using namespace serial;
|
||||
namespace ranges = std::ranges;
|
||||
namespace views = std::views;
|
||||
|
||||
void PrintLog(const std::string &msg) { std::cout << msg << std::endl; }
|
||||
|
||||
template <typename T>
|
||||
requires std::is_same_v<T, std::string> ||
|
||||
std::is_same_v<T, std::string_view>
|
||||
std::vector<T> split(T str, T d) {
|
||||
auto v = views::split(str, d) | views::transform([](auto word) {
|
||||
return T(word.begin(), word.end());
|
||||
});
|
||||
return std::vector<T>(v.begin(), v.end());
|
||||
}
|
||||
|
||||
int main() {
|
||||
Serial ser;
|
||||
ser.OpenDevice("COM11", 115200);
|
||||
ser.SetLogCallBack(PrintLog);
|
||||
ser.GetAtUntilRepeat<5>("AT", "OK");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
int main(int argc, char **const argv) {
|
||||
Serial serial;
|
||||
auto ports = serial::GetUsbPorts();
|
||||
@@ -30,20 +51,20 @@ int main(int argc, char **const argv) {
|
||||
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);
|
||||
if (command.at(0) == ':') {
|
||||
command = command.substr(1, command.length() - 1);
|
||||
auto sp = split(command, " "s);
|
||||
auto reallyCommand = sp[0];
|
||||
auto expect = sp[1];
|
||||
auto res = serial.GetAtUntil(reallyCommand, 2000, expect);
|
||||
auto endTime = std::chrono::system_clock::now();
|
||||
std::cout << "dura: "
|
||||
res ? std::cout
|
||||
<< "dura: "
|
||||
<< std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
endTime - startTime)
|
||||
.count()
|
||||
<< std::endl;
|
||||
<< std::endl
|
||||
: std::cout << "Recive Error";
|
||||
} else {
|
||||
auto resp = serial.GetAtResponse(command);
|
||||
auto endTime = std::chrono::system_clock::now();
|
||||
@@ -57,3 +78,4 @@ int main(int argc, char **const argv) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user