64 lines
1.3 KiB
C++
64 lines
1.3 KiB
C++
|
#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);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|