From 5b21c715ff2dcdc589fb1e6f468d87588c28d361 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Tue, 9 Mar 2021 22:19:27 +0100 Subject: [PATCH] Initialize default device info --- src/dev/posix/hasp_posix.cpp | 27 +++++++++++++++++++++++++-- src/dev/posix/hasp_posix.h | 10 ++++------ src/main_sdl2.cpp | 26 ++------------------------ 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index 1e5b086e..1515b315 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -15,11 +15,34 @@ namespace dev { +PosixDevice::PosixDevice() { + struct utsname uts; + + if (uname(&uts) < 0) { + LOG_ERROR(0,"uname() error"); + _hostname = "localhost"; + _core_version = "unknown"; + } else { + // LOG_VERBOSE(0,"Sysname: %s", uts.sysname); + // LOG_VERBOSE(0,"Nodename: %s", uts.nodename); + // LOG_VERBOSE(0,"Release: %s", uts.release); + // LOG_VERBOSE(0,"Version: %s", uts.version); + // LOG_VERBOSE(0,"Machine: %s", uts.machine); + + char version[128]; + snprintf(version, sizeof(version), "%s %s", uts.sysname, uts.release); + _core_version = version; + _hostname = uts.nodename; + } + + _backlight_power = 1; + _backlight_level = 100; + } + void PosixDevice::reboot() {} void PosixDevice::show_info() { - struct utsname uts; if (uname(&uts) < 0) { @@ -49,7 +72,7 @@ void PosixDevice::set_hostname(const char* hostname) } const char* PosixDevice::get_core_version() { - return "posix"; + return _core_version.c_str(); } const char* PosixDevice::get_display_driver() { diff --git a/src/dev/posix/hasp_posix.h b/src/dev/posix/hasp_posix.h index eebcfd7c..687aa8ea 100644 --- a/src/dev/posix/hasp_posix.h +++ b/src/dev/posix/hasp_posix.h @@ -6,11 +6,13 @@ #include #include + extern "C" { #include #include #include +#include } #include "hasp_conf.h" @@ -28,12 +30,7 @@ namespace dev { class PosixDevice : public BaseDevice { public: - PosixDevice() - { - _hostname = "localhost"; - _backlight_power = 1; - _backlight_level = 100; - } + PosixDevice(); void reboot() override; void show_info() override; @@ -58,6 +55,7 @@ class PosixDevice : public BaseDevice { private: std::string _hostname; + std::string _core_version; uint8_t _backlight_pin; uint8_t _backlight_level; diff --git a/src/main_sdl2.cpp b/src/main_sdl2.cpp index 80ef08a9..096906fb 100644 --- a/src/main_sdl2.cpp +++ b/src/main_sdl2.cpp @@ -112,7 +112,8 @@ void setup() lv_log_register_print_cb(debugLvglLogEvent); lv_init(); - haspDevice.init(); // hardware setup + haspDevice.init(); // hardware setup + haspDevice.show_info(); // debug info // hal_setup(); guiSetup(); @@ -204,29 +205,6 @@ int main(int argc, char* argv[]) InitializeConsoleOutput(); #endif - haspDevice.show_info(); - - char hostbuffer[256]; - char* IPbuffer; - struct hostent* host_entry; - int hostname; - - // To retrieve hostname - hostname = gethostname(hostbuffer, sizeof(hostbuffer)); - // checkHostName(hostname); - - // To retrieve host information - host_entry = gethostbyname(hostbuffer); - // checkHostEntry(host_entry); - haspDevice.set_hostname(hostbuffer); - - // To convert an Internet network - // address into ASCII string - // IPbuffer = inet_ntoa(*((struct in_addr*)host_entry->h_addr_list[0])); - - printf("Hostname: %s", hostbuffer); - // printf("Host IP: %s", IPbuffer); - // Display each command-line argument. std::cout << "\nCommand-line arguments:\n"; for(count = 0; count < argc; count++)