55 lines
1.7 KiB
C++
55 lines
1.7 KiB
C++
#include "BoostLog.h"
|
|
#include <boost/asio.hpp>
|
|
#include <boost/json.hpp>
|
|
#include <chrono>
|
|
#include <iostream>
|
|
#include <thread>
|
|
|
|
using boost::asio::ip::udp;
|
|
|
|
int main(int argc, char const *argv[]) {
|
|
boost::log::initialize("/data/sdcard/logs/GatePass", "/data/sdcard/logs");
|
|
LOG(info) << "app start...";
|
|
std::cout << "hello word." << std::endl;
|
|
|
|
constexpr auto txt = R"({"cmd":"gate_status","status":1,"personIn":11638,"personOut":5123,"runCount":115370})";
|
|
|
|
constexpr auto txt1 = R"({"cmd":"gate_status","status":2,"personIn":-12345,"personOut":-12345,"runCount":115370})";
|
|
|
|
constexpr auto error = R"({"cmd":"fault_and_alarm","code":91})";
|
|
|
|
constexpr auto error1 = R"({"cmd":"fault_and_alarm","code":96})";
|
|
|
|
try {
|
|
// if (argc != 2) {
|
|
// std::cerr << "Usage: client <host>" << std::endl;
|
|
// return 1;
|
|
// }
|
|
|
|
udp::endpoint point(udp::v4(), 6787);
|
|
|
|
boost::asio::io_context io_context;
|
|
|
|
udp::socket socket(io_context);
|
|
socket.open(udp::v4());
|
|
|
|
socket.send_to(boost::asio::buffer(std::string(txt)), point);
|
|
LOG(info) << "udp send: " << txt;
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(150));
|
|
socket.send_to(boost::asio::buffer(std::string(error)), point);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(150));
|
|
socket.send_to(boost::asio::buffer(std::string(error1)), point);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(150));
|
|
socket.send_to(boost::asio::buffer(std::string(txt1)), point);
|
|
|
|
} catch (std::exception &e) {
|
|
std::cerr << e.what() << std::endl;
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
}
|