|
|
@@ -5,10 +5,29 @@
|
|
|
#include "appcontext.h"
|
|
|
#include "version.h"
|
|
|
#include "utils.h"
|
|
|
+#include "netparseprocess.h"
|
|
|
+#include "calprocess.h"
|
|
|
+#include "defs.h"
|
|
|
+
|
|
|
+#include <getopt.h>
|
|
|
|
|
|
#define SCREEN_WIDTH 1280
|
|
|
#define SCREEN_HEIGHT 720
|
|
|
|
|
|
+app_param_st g_appParam;
|
|
|
+
|
|
|
+void print_help(const char *prog)
|
|
|
+{
|
|
|
+ std::cout <<
|
|
|
+ "Usage: " << prog << " [OPTIONS]\n\n"
|
|
|
+ "Options:\n"
|
|
|
+ " -i, --iface <name> Network interface name (required)\n"
|
|
|
+ " --broadcast <port> Broadcast port number (1-65535)\n"
|
|
|
+ " -h, --help Show this help message\n\n"
|
|
|
+ "Examples:\n"
|
|
|
+ " " << prog << " -i eth0 --broadcast 8888\n";
|
|
|
+}
|
|
|
+
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
|
|
@@ -16,6 +35,51 @@ int main(int argc, char *argv[])
|
|
|
#endif
|
|
|
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
|
QApplication app(argc, argv);
|
|
|
+ /* parse argv */
|
|
|
+ static struct option long_options[] = {
|
|
|
+ {"iface", required_argument, 0, 'i'},
|
|
|
+ {"broadcast", required_argument, 0, OPT_BROADCAST},
|
|
|
+ {"help", no_argument, 0, 'h'},
|
|
|
+ {0, 0, 0, 0}
|
|
|
+ };
|
|
|
+ int opt;
|
|
|
+ while ((opt = getopt_long(argc, argv, "i:h", long_options, nullptr)) != -1) {
|
|
|
+ switch (opt) {
|
|
|
+ case 'i':
|
|
|
+ g_appParam.iface = optarg;
|
|
|
+ break;
|
|
|
+
|
|
|
+ case OPT_BROADCAST:
|
|
|
+ g_appParam.broadcast_port = std::atoi(optarg);
|
|
|
+ if (g_appParam.broadcast_port <= 0 || g_appParam.broadcast_port > 65535) {
|
|
|
+ std::cerr << "error: invalid broadcast port: " << optarg << "\n";
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case 'h':
|
|
|
+ print_help(argv[0]);
|
|
|
+ return EXIT_SUCCESS;
|
|
|
+
|
|
|
+ default:
|
|
|
+ std::cerr << "unknown option";
|
|
|
+ std::cerr << "try '" << argv[0] << " --help' for more information.\n";
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* 必选参数检查 */
|
|
|
+ if (!g_appParam.iface) {
|
|
|
+ std::cerr << "Error: --iface is required\n";
|
|
|
+ std::cerr << "Try '" << argv[0] << " --help' for more information.\n";
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (g_appParam.broadcast_port == -1) {
|
|
|
+ std::cerr << "Error: --broadcast is required\n";
|
|
|
+ std::cerr << "Try '" << argv[0] << " --help' for more information.\n";
|
|
|
+ return EXIT_FAILURE;
|
|
|
+ }
|
|
|
|
|
|
#ifdef NDEBUG
|
|
|
Logger::setup(Logger::INFO, "storage/logs/log.txt");
|
|
|
@@ -24,10 +88,12 @@ int main(int argc, char *argv[])
|
|
|
#endif
|
|
|
|
|
|
CRITICAL_LOG(spdlog::level::info, "app start...");
|
|
|
+ CRITICAL_LOG(spdlog::level::info, "iface: {}", g_appParam.iface);
|
|
|
+ CRITICAL_LOG(spdlog::level::info, "broadcast port: {}", g_appParam.broadcast_port);
|
|
|
|
|
|
char *ip = NULL;
|
|
|
char *mask = NULL;
|
|
|
- bool result = Utils::ipv4("eth0", &ip, &mask);
|
|
|
+ bool result = Utils::ipv4(g_appParam.iface, &ip, &mask);
|
|
|
|
|
|
CRITICAL_LOG(spdlog::level::info, "PROJECT_NAME: {}", PROJECT_NAME);
|
|
|
CRITICAL_LOG(spdlog::level::info, "PROJECT_VERSION: {}", PROJECT_VERSION);
|
|
|
@@ -53,11 +119,12 @@ int main(int argc, char *argv[])
|
|
|
int frequency = QString(argv[1]).toInt();
|
|
|
#endif
|
|
|
|
|
|
- AppContext &appCtx = AppContext::instance();
|
|
|
MainWindow w;
|
|
|
w.resize(SCREEN_WIDTH, SCREEN_HEIGHT);
|
|
|
w.showFullScreen();
|
|
|
|
|
|
+ AppContext &appCtx = AppContext::instance();
|
|
|
+
|
|
|
int ret = app.exec();
|
|
|
return ret;
|
|
|
}
|