Skip to content

Commit

Permalink
re-enable Mac build (#657)
Browse files Browse the repository at this point in the history
* enable mac build, enable basic OS commands as on linux

* back to intact linux stuff

* fix timing for alive status for air, ground, rs, fc and wifi card systems

* show all local IP addresses

* remove unclear define

---------

Co-authored-by: Oleg <[email protected]>
  • Loading branch information
sound-eng and sound-eng authored Feb 1, 2024
1 parent d673fdb commit d3d34e1
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 16 deletions.
1 change: 1 addition & 0 deletions QOpenHD.pro
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ iOSBuild {
}

MacBuild {
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.15
QMAKE_INFO_PLIST = mac/Info.plist
ICON = $${BASEDIR}/icons/macos.icns
DISTFILES += mac/Info.plist
Expand Down
14 changes: 7 additions & 7 deletions app/common/openhd-util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include <sstream>
#include <memory>

#ifdef __linux__
#if defined(__linux__) || defined(__macos__)
#include <arpa/inet.h>
#include <netinet/in.h>
#endif // __linux__
#endif // __linux__ || __macos__


namespace OHDUtil {
Expand All @@ -27,7 +27,7 @@ namespace OHDUtil {
* NOTE: Used to use boost, there were issues with that, I changed it to use c standard library.
*/
static bool run_command(const std::string &command, const std::vector<std::string> &args,bool print_debug=true) {
#ifdef __linux__
#if defined(__linux__) || defined(__macos__)
std::stringstream ss;
ss << command;
for (const auto &arg: args) {
Expand All @@ -51,7 +51,7 @@ static bool run_command(const std::string &command, const std::vector<std::strin
}
return ret;
#else
std::cerr<<"run_command only supported on linux\n";
std::cerr<<"run_command only supported on linux and macos\n";
return false;
#endif
}
Expand All @@ -67,7 +67,7 @@ static bool run_command(const std::string &command, const std::vector<std::strin
*/

static std::optional<std::string> run_command_out(const char* command){
#ifdef __linux__
#if defined(__linux__) || defined(__macos__)
std::string raw_value;
std::array<char, 512> buffer{};
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command, "r"), pclose);
Expand All @@ -83,7 +83,7 @@ static std::optional<std::string> run_command_out(const char* command){
}
return raw_value;
#else
std::cerr<<"run_command only supported on linux\n";
std::cerr<<"run_command only supported on linux and macos\n";
return std::nullopt;
#endif
}
Expand All @@ -93,7 +93,7 @@ static std::string yes_or_no(bool yes){
}

static bool is_valid_ip(const std::string& ip) {
#ifdef __linux__
#if defined(__linux__) || defined(__macos__)
unsigned char buf[sizeof(struct in6_addr)];
auto result = inet_pton(AF_INET, ip.c_str(), buf);
return result == 1;
Expand Down
4 changes: 2 additions & 2 deletions app/telemetry/models/aohdsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ void AOHDSystem::update_alive()
// come through, not only a heartbeat
// AIR: Quite lossy, and r.n we send about 2 to 3 telemetry packets per second
// GROUND: OpenHD (can) send a lot of data to QOpenHD, since there are no bw constraints
const int tmp=m_last_message_ms;
if(tmp<=-1){
const int64_t tmp=m_last_message_ms;
if(tmp<=-1) {
update_alive_status_with_hud_message(false);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions app/telemetry/models/aohdsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class AOHDSystem : public QObject
void process_sys_status1(const mavlink_openhd_sys_status1_t& msg);
void process_op_mode(const mavlink_openhd_wifbroadcast_gnd_operating_mode_t& msg);
private:
std::atomic<int32_t> m_last_heartbeat_ms = -1;
std::atomic<int32_t> m_last_message_ms= -1;
std::atomic<int64_t> m_last_heartbeat_ms = -1;
std::atomic<int64_t> m_last_message_ms= -1;
//
QString m_curr_incoming_bitrate="Bitrate NA";
QString m_curr_incoming_tele_bitrate="Bitrate NA";
Expand Down
4 changes: 2 additions & 2 deletions app/telemetry/models/fcmavlinksystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ class FCMavlinkSystem : public QObject
std::unique_ptr<QTimer> m_flight_time_timer = nullptr;
//
std::unique_ptr<QTimer> m_alive_timer = nullptr;
std::atomic<int32_t> m_last_heartbeat_ms = -1;
std::atomic<int32_t> m_last_message_ms= -1;
std::atomic<int64_t> m_last_heartbeat_ms = -1;
std::atomic<int64_t> m_last_message_ms= -1;
void update_alive();
std::chrono::steady_clock::time_point m_last_update_update_rate_mavlink_message_attitude=std::chrono::steady_clock::now();
int m_n_messages_update_rate_mavlink_message_attitude=0;
Expand Down
2 changes: 1 addition & 1 deletion app/telemetry/models/rcchannelsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public slots:
QList<int> m_data{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
private:
// We need thread saftey on the alive
std::atomic<int32_t> m_last_update_ms = -1;
std::atomic<int64_t> m_last_update_ms = -1;
std::unique_ptr<QTimer> m_alive_timer;
void update_alive();
};
Expand Down
2 changes: 1 addition & 1 deletion app/telemetry/models/wificard.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class WiFiCard : public QObject
int64_t m_last_packets_in_X_second_value=-1;
// Card alive - ONLY USED FOR GROUND CARD(s)
std::unique_ptr<QTimer> m_alive_timer = nullptr;
std::atomic<int> m_last_mavlink_message=0;
std::atomic<int64_t> m_last_mavlink_message=0;
void update_alive();
};

Expand Down
14 changes: 13 additions & 1 deletion app/util/qopenhd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include<fstream>
#include<string>

#ifdef __linux__
#if defined(__linux__) || defined(__macos__)
#include "common/openhd-util.hpp"
#endif

Expand Down Expand Up @@ -227,6 +227,9 @@ QString QOpenHD::show_local_ip()
#ifdef __linux__
auto res=OHDUtil::run_command_out("hostname -I");
return QString(res->c_str());
#elif defined(__macos__)
auto res=OHDUtil::run_command_out("ifconfig -l | xargs -n1 ipconfig getifaddr");
return QString(res->c_str());
#else
return QString("Only works on linux");
#endif
Expand All @@ -246,6 +249,15 @@ bool QOpenHD::is_linux()
return false;
}

bool QOpenHD::is_mac()
{
#if defined(__macos__)
return true;
#else
return false;
#endif
}

bool QOpenHD::is_android()
{
#if defined(__android__)
Expand Down
1 change: 1 addition & 0 deletions app/util/qopenhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class QOpenHD : public QObject
// some settings an stuff depend on that, called from .qml
// NOTE: android is not linux in this definition !
Q_INVOKABLE bool is_linux();
Q_INVOKABLE bool is_mac();
Q_INVOKABLE bool is_android();
Q_INVOKABLE void android_open_tethering_settings();
// runs systemctl start/stop/enable/disable openhd
Expand Down
5 changes: 5 additions & 0 deletions app/videostreaming/vscommon/rtp/RTP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
#include <sstream>

// This code is written for little endian (aka ARM,x86) byte order
#if defined(__macos__)
static_assert(__BYTE_ORDER__==LITTLE_ENDIAN);
#else
static_assert(__BYTE_ORDER__==__LITTLE_ENDIAN);
#endif

// RTP uses big endian (network) byte order. Therefore, most of the structs here
// are actually declared in 'reverse order' such that the compiler can do the work
// of 'interpreting bits the right way' for us
Expand Down

0 comments on commit d3d34e1

Please sign in to comment.