Browse Source

update

master
zhaohe 2 years ago
parent
commit
ce869ecfb3
  1. 25
      src/main_control_service.cpp

25
src/main_control_service.cpp

@ -62,11 +62,28 @@ void MainControlService::initialize() {
m_iflytopwsService->onMessage.connect([this](weak_ptr<WebSocket> webSocket, json& cmd, json& receipt) { processFrontEndMessage(webSocket, cmd, receipt); });
m_iflytopwsService->onUdpCmdMessage.connect([this](struct sockaddr_in* from, char* data, size_t len) {
//
string retmsg;
bool suc = m_zcanhost->execcmd(string(data, len), retmsg);
string retmsgstr = fmt::format("{},{}", suc ? "suc" : "fail", retmsg);
m_iflytopwsService->sendToUDP(from, retmsgstr.c_str(), retmsgstr.size());
for (size_t i = 0; i < len; i++) {
if (data[i] == '\r' || data[i] == '\n') {
data[i] = '\0';
}
}
bool execsuc = false;
for (size_t i = 0; i < len; i++) {
if (data[i] != '\0') {
int inext = strlen(&data[i]) + i;
{
string retmsg;
execsuc = m_zcanhost->execcmd(string(&data[i]), retmsg);
string retmsgstr = fmt::format("{},{}", execsuc ? "suc" : "fail", retmsg);
m_iflytopwsService->sendToUDP(from, retmsgstr.c_str(), retmsgstr.size());
}
i = inext;
if (!execsuc) {
break;
}
}
}
});
m_iflytopwsService->startListen();

Loading…
Cancel
Save