Skip to content

Commit

Permalink
Merge branch 'main' into add-station
Browse files Browse the repository at this point in the history
  • Loading branch information
neilenns committed Nov 19, 2024
2 parents 693ef26 + 4511442 commit 6248cb2
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
git submodule update --init --remote backend/extern/afv-native
git submodule update --init --remote backend/extern/libuiohook
cd backend/extern/afv-native
git checkout unicom2
git checkout modern-chained-callback
- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
git submodule update --init --remote backend/vcpkg
git submodule update --init --remote backend/extern/afv-native
cd backend/extern/afv-native
git checkout unicom2
git checkout modern-chained-callback
- name: Setup Node.js
uses: actions/setup-node@v4
Expand Down
63 changes: 27 additions & 36 deletions backend/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@ void RequestPttKeyName(const Napi::CallbackInfo& info)
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast,readability-function-cognitive-complexity)
void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* data2)
void HandleAfvEvents(afv_native::ClientEventType eventType, std::optional<std::string> string1,
std::optional<int> int1, std::optional<std::pair<std::string, unsigned int>> stationData,
std::optional<std::map<std::string, unsigned int>> vccsData)
{
if (!NapiHelpers::callbackAvailable) {
return;
Expand All @@ -508,12 +510,11 @@ void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* da
}

if (eventType == afv_native::ClientEventType::StationTransceiversUpdated) {
if (data == nullptr) {
if (!string1) {
return;
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
std::string station = static_cast<const char*>(data);
std::string station = string1.value();
auto transceiverCount = mClient->GetTransceiverCountForStation(station);
auto states = mClient->getRadioState();
for (const auto& state : states) {
Expand All @@ -528,20 +529,18 @@ void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* da
}

if (eventType == afv_native::ClientEventType::StationDataReceived) {
if (data == nullptr || data2 == nullptr) {
if (!stationData || !int1) {
return;
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
bool found = static_cast<bool>(data);
bool found = static_cast<bool>(int1);
if (!found) {
NapiHelpers::sendErrorToElectron("Station not found");
return;
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
auto stationData = *reinterpret_cast<std::pair<std::string, unsigned int>*>(data2);
std::string callsign = stationData.first;
unsigned int frequency = stationData.second;

std::string callsign = stationData->first;
unsigned int frequency = stationData->second;

if (mClient->IsFrequencyActive(frequency)) {
PLOGW << "StationDataReceived: Frequency " << frequency << " already active, skipping";
Expand All @@ -553,13 +552,11 @@ void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* da
}

if (eventType == afv_native::ClientEventType::VccsReceived) {
if (data == nullptr || data2 == nullptr) {
if (!vccsData) {
return;
}

std::map<std::string, unsigned int> stations
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
= *reinterpret_cast<std::map<std::string, unsigned int>*>(data2);
std::map<std::string, unsigned int> stations = vccsData.value();

for (const auto& station : stations) {
const std::string& callsign = station.first;
Expand All @@ -570,19 +567,19 @@ void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* da
continue;
}

NapiHelpers::callElectron("StationDataReceived", callsign, std::to_string(frequency));
MainThreadShared::mApiServer->publishStationAdded(
NapiHelpers::callElectron("StationDataReceived", callsign,
std::to_string(frequency)); MainThreadShared::mApiServer->publishStationAdded(
callsign, static_cast<int>(frequency));
}
}

if (eventType == afv_native::ClientEventType::FrequencyRxBegin) {
if (data == nullptr) {
if (!int1) {
return;
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
int frequency = *reinterpret_cast<int*>(data);
int frequency = int1.value();
if (!mClient->IsFrequencyActive(frequency)) {
PLOGW << "FrequencyRxBegin: Frequency " << frequency << " not active, skipping";
return;
Expand All @@ -594,12 +591,11 @@ void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* da
}

if (eventType == afv_native::ClientEventType::FrequencyRxEnd) {
if (data == nullptr) {
if (!int1) {
return;
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
int frequency = *reinterpret_cast<int*>(data);
int frequency = int1.value();
if (!mClient->IsFrequencyActive(frequency)) {
PLOGW << "FrequencyRxEnd: Frequency " << frequency << " not active, skipping";
return;
Expand All @@ -610,14 +606,14 @@ void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* da
}

if (eventType == afv_native::ClientEventType::StationRxBegin) {
if (data == nullptr || data2 == nullptr) {
if (!int1 || !string1) {
return;
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
int frequency = *reinterpret_cast<int*>(data);
int frequency = int1.value();
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
std::string callsign = static_cast<const char*>(data2);
std::string callsign = string1.value();
if (!mClient->IsFrequencyActive(frequency)) {
PLOGW << "StationRxBegin: Frequency " << frequency << " not active, skipping";
return;
Expand All @@ -632,14 +628,12 @@ void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* da
}

if (eventType == afv_native::ClientEventType::StationRxEnd) {
if (data == nullptr || data2 == nullptr) {
if (!int1 || !string1) {
return;
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
int frequency = *reinterpret_cast<int*>(data);
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
std::string callsign = static_cast<const char*>(data2);;
int frequency = int1.value();
std::string callsign = string1.value();

if (!mClient->IsFrequencyActive(frequency)) {
PLOGW << "StationRxEnd: Frequency " << frequency << " not active, skipping";
Expand Down Expand Up @@ -667,12 +661,11 @@ void HandleAfvEvents(afv_native::ClientEventType eventType, void* data, void* da
}

if (eventType == afv_native::ClientEventType::APIServerError) {
if (data == nullptr) {
if (!int1) {
return;
}

// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
auto err = *reinterpret_cast<afv_native::afv::APISessionError*>(data);
auto err = static_cast<afv_native::afv::APISessionError>(int1.value());

if (err == afv_native::afv::APISessionError::BadPassword
|| err == afv_native::afv::APISessionError::RejectedCredentials) {
Expand Down Expand Up @@ -787,9 +780,7 @@ Napi::Object Bootstrap(const Napi::CallbackInfo& info)
MainThreadShared::mRemoteDataHandler = std::make_unique<RemoteData>();

// Setup afv
mClient->RaiseClientEvent([](afv_native::ClientEventType eventType, void* data1, void* data2) {
HandleAfvEvents(eventType, data1, data2);
});
mClient->RaiseModernClientEvent(std::function(&HandleAfvEvents));

MainThreadShared::mApiServer = std::make_shared<SDK>();

Expand Down
3 changes: 2 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6248cb2

Please sign in to comment.