CP控制V1.0
This commit is contained in:
63
ComCtrl/ComCtrl.cpp
Normal file
63
ComCtrl/ComCtrl.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
#include "ComCtrl.h"
|
||||
|
||||
void SendCmd(const vector<string> &args, const string &type) {
|
||||
string tmpCmd = type + args[1] + "," + args[2] + "\r\n";
|
||||
myDateTime tmp;
|
||||
string log = tmp.toDateTime() + " Send: " + tmpCmd;
|
||||
cout << log;
|
||||
historyList.push_back(log);
|
||||
string tmpCmdList = args[0] + " " + args[1] + " " + args[2];
|
||||
if (cmdList.empty()) {
|
||||
cmdList.push_back(tmpCmdList);
|
||||
}
|
||||
else {
|
||||
if (cmdList.back() != tmpCmdList) {
|
||||
cmdList.push_back(tmpCmdList);
|
||||
}
|
||||
}
|
||||
if (Sender.sendto(tmpCmd) < 0) {
|
||||
cerr << "send error" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void setantCommand(const vector<string> &args) {
|
||||
if (args.size() != 3) {
|
||||
cout << "Usage: setant <key> <value>" << endl;
|
||||
return;
|
||||
}
|
||||
SendCmd(args, "AT+SetAnt=");
|
||||
}
|
||||
|
||||
void setephCommand(const vector<string> &args) {
|
||||
if (args.size() != 3) {
|
||||
cout << "Usage: seteph <key> <value>" << endl;
|
||||
return;
|
||||
}
|
||||
SendCmd(args, "AT+SetEph=");
|
||||
}
|
||||
|
||||
// 查询键值
|
||||
void queryCommand(const vector<string> &args) {
|
||||
if (args.size() != 3) {
|
||||
cout << "Usage: query <type> <key>" << endl;
|
||||
return;
|
||||
}
|
||||
SendCmd(args, "AT+Query=");
|
||||
}
|
||||
|
||||
void listCommand() {
|
||||
for (const auto &i: historyList) {
|
||||
cout << i << flush;
|
||||
}
|
||||
string tmpCmdList = "list";
|
||||
if (cmdList.empty()) {
|
||||
cmdList.push_back(tmpCmdList);
|
||||
}
|
||||
else {
|
||||
if (cmdList.back() != tmpCmdList) {
|
||||
cmdList.push_back(tmpCmdList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
21
ComCtrl/ComCtrl.h
Normal file
21
ComCtrl/ComCtrl.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef CPCTRL_COMCTRL_H
|
||||
#define CPCTRL_COMCTRL_H
|
||||
|
||||
#include "GlobalDefs.h"
|
||||
#include "Noncanonical.h"
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// 设置
|
||||
void setantCommand(const vector<string>& args);
|
||||
void setephCommand(const vector<string>& args);
|
||||
|
||||
// 查询
|
||||
void queryCommand(const vector<string>& args);
|
||||
|
||||
//历史
|
||||
void listCommand();
|
||||
|
||||
|
||||
#endif //CPCTRL_COMCTRL_H
|
Reference in New Issue
Block a user