Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FPP Rediscover and KeepOpen (plus a few more FPPConnect enhancements) #5094

Merged
merged 5 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions xLights/TabSetup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const long xLightsFrame::ID_NETWORK_ACTIVEXLIGHTS = wxNewId();
const long xLightsFrame::ID_NETWORK_INACTIVE = wxNewId();
const long xLightsFrame::ID_NETWORK_DELETE = wxNewId();
const long xLightsFrame::ID_NETWORK_UNLINKFROMBASE = wxNewId();
const long xLightsFrame::ID_NETWORK_UPLOADOUTPUT = wxNewId();

#pragma region Show Directory
void xLightsFrame::OnMenuMRU(wxCommandEvent& event) {
Expand Down Expand Up @@ -2198,6 +2199,8 @@ void xLightsFrame::OnListControllersItemRClick(wxListEvent& event) {
bool allSelectedControllersFromBase = std::all_of(selectedControllers.begin(), selectedControllers.end(), [](const Controller* controller) { return controller->IsFromBase(); });
bool enableActivateMenuItems = selectedControllers.size() > 0 && !anySelectedControllersFromBase;
bool enableUnlinkFromBaseMenuItem = selectedControllers.size() > 0 && allSelectedControllersFromBase;
bool anySelectedControllersSupportUpload = std::any_of(selectedControllers.begin(), selectedControllers.end(), [](const Controller* controller) { return controller->SupportsUpload(); });
bool enableUploadMenuItem = selectedControllers.size() == 1 && anySelectedControllersSupportUpload;

mnu.Append(ID_NETWORK_ADDETHERNET, ethernet)->Enable(ButtonAddControllerSerial->IsEnabled());
mnu.Append(ID_NETWORK_ADDNULL, "Insert NULL")->Enable(ButtonAddControllerSerial->IsEnabled());
Expand All @@ -2207,6 +2210,7 @@ void xLightsFrame::OnListControllersItemRClick(wxListEvent& event) {
mnu.Append(ID_NETWORK_INACTIVE, "Inactivate")->Enable(ButtonAddControllerSerial->IsEnabled() && enableActivateMenuItems);
mnu.Append(ID_NETWORK_DELETE, "Delete")->Enable(ButtonAddControllerSerial->IsEnabled());
mnu.Append(ID_NETWORK_UNLINKFROMBASE, "Unlink from Base Show Folder")->Enable(ButtonAddControllerSerial->IsEnabled() && enableUnlinkFromBaseMenuItem);
mnu.Append(ID_NETWORK_UPLOADOUTPUT, "Upload Output")->Enable(ButtonAddControllerSerial->IsEnabled() && enableUploadMenuItem);

mnu.Connect(wxEVT_MENU, (wxObjectEventFunction)&xLightsFrame::OnListControllerPopup, nullptr, this);
PopupMenu(&mnu);
Expand Down Expand Up @@ -2274,6 +2278,9 @@ void xLightsFrame::OnListControllerPopup(wxCommandEvent& event) {
_outputModelManager.AddASAPWork(OutputModelManager::WORK_UPDATE_NETWORK_LIST, "OnListControllerPopup:DELETE");
_outputModelManager.AddLayoutTabWork(OutputModelManager::WORK_CALCULATE_START_CHANNELS, "OnListControllerPopup:DELETE");
}
else if (id == ID_NETWORK_UPLOADOUTPUT) {
OnButtonUploadOutputClick(event);
}
}
#pragma endregion

Expand Down
10 changes: 9 additions & 1 deletion xLights/controllers/FPP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,10 @@ bool FPP::uploadFile(const std::string &utfFilename, const std::string &file) {
logger_base.debug("Renaming done.");
}
}
logger_base.debug(utfFilename + " upload complete to " + this->hostName + " (" + this->ipAddress + "). Bytes sent:" + std::to_string(data->totalWritten) + ".");
} else {
messages.push_back("ERROR Uploading file: " + utfFilename + " Response Code: " + std::to_string(response_code));
faileduploads.push_back(filename);
logger_base.warn("Did not get 200 response code: %d", response_code);
}

Expand Down Expand Up @@ -840,7 +842,8 @@ int progress_callback(void *clientp,

void prepareCurlForMulti(V7ProgressStruct *ps) {
static log4cpp::Category& logger_curl = log4cpp::Category::getInstance(std::string("log_curl"));

static log4cpp::Category& logger_base = log4cpp::Category::getInstance(std::string("log_base"));

constexpr uint64_t BLOCK_SIZE = 16*1024*1024;
CurlManager::CurlPrivateData *cpd = nullptr;
CURL *curl = CurlManager::INSTANCE.createCurl(ps->fullUrl, &cpd, true);
Expand Down Expand Up @@ -869,6 +872,7 @@ void prepareCurlForMulti(V7ProgressStruct *ps) {
if (read != remaining) {
logger_curl.info("ERROR Uploading file: " + ps->filename + " Could not read source file.");
ps->instance->messages.push_back("ERROR Uploading file: " + ps->filename + " Could not read source file.");
ps->instance->faileduploads.push_back(ps->filename);
}
std::string contentSizeHeader = "Content-Length: " + std::to_string(remaining);
headers = curl_slist_append(headers, contentSizeHeader.c_str());
Expand Down Expand Up @@ -898,13 +902,15 @@ void prepareCurlForMulti(V7ProgressStruct *ps) {
++ps->errorCount;
} else if (response_code != 200) {
ps->instance->messages.push_back("ERROR Uploading file: " + ps->filename + ". Response code: " + std::to_string(response_code));
ps->instance->faileduploads.push_back(ps->filename);
cancelled = true;
} else {
ps->offset += remaining;
}
uint64_t pct = (ps->offset * 1000) / ps->length;
cancelled |= ps->instance->updateProgress(pct, false);
if (cancelled || ps->offset >= ps->length) {
logger_base.debug(ps->filename + " upload complete to " + ps->instance->hostName + " (" + ps->instance->ipAddress + "). Bytes sent:" + std::to_string(ps->length) + ".");
delete ps;
} else {
prepareCurlForMulti(ps);
Expand Down Expand Up @@ -3845,6 +3851,7 @@ void FPP::MapToFPPInstances(Discovery &discovery, std::list<FPP*> &instances, Ou
FPP *fpp = new FPP(res->ip, res->proxy, res->pixelControllerType);
fpp->ipAddress = res->ip;//not needed, in constructor
fpp->hostName = res->hostname;
fpp->uuid = res->uuid;
fpp->description = res->description;
fpp->platform = res->platform;
fpp->model = res->platformModel;
Expand Down Expand Up @@ -3874,6 +3881,7 @@ void FPP::MapToFPPInstances(Discovery &discovery, std::list<FPP*> &instances, Ou
} else {
setIfEmpty(fpp->proxy, res->proxy);
setIfEmpty(fpp->hostName, res->hostname);
setIfEmpty(fpp->uuid, res->uuid);
setIfEmpty(fpp->description, res->description);
setIfEmpty(fpp->platform, res->platform);
setIfEmpty(fpp->model, res->platformModel);
Expand Down
16 changes: 15 additions & 1 deletion xLights/controllers/FPP.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ class FPP : public BaseController
std::string controllerVendor;
std::string controllerModel;
std::string controllerVariant;
bool upload;

wxWindow *parent = nullptr;
void setProgress(FPPUploadProgressDialog*d, wxGauge *g) { progressDialog = d; progress = g; }
bool updateProgress(int val, bool yield);


std::list<std::string> messages;
std::list<std::string> faileduploads;
int defaultConnectTimeout = 2000;

std::map<int, int> GetExpansionPorts(ControllerCaps* caps) const;
Expand Down Expand Up @@ -232,10 +234,22 @@ static inline int case_insensitive_match(std::string s1, std::string s2)

static inline bool sortByName(const FPP* i, const FPP* j)
{
return i->hostName < j->hostName;
std::string lowerI = i->hostName;
std::string lowerJ = j->hostName;

std::transform(lowerI.begin(), lowerI.end(), lowerI.begin(),
[](unsigned char c) { return std::tolower(c); });
std::transform(lowerJ.begin(), lowerJ.end(), lowerJ.begin(),
[](unsigned char c) { return std::tolower(c); });

return lowerI < lowerJ;
}

static inline bool sortByIP(const FPP* i, const FPP* j)
{
return i->ipAddress < j->ipAddress;
}

static inline bool sortByUpload(const FPP* i, const FPP* j) {
return i->upload > j->upload;
}
Loading