/* * Copyright (C) 2026 Frederic BORRY - ADRASEC 31 * * This file is part of PortaPack. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ #ifndef __RESOUCES_H__ #define __RESOUCES_H__ #include #include #include "file_reader.hpp" #include "file_path.hpp" namespace ui::external_app::epirb_rx { #define UNKNOWN_LABEL "Unk." extern std::vector beacon_res; extern std::vector freq; /** * This class is used to load string resources from SD card. * This is done mostly to reduce application size and keep it under the 32kb limit. * It's also used to load frequency values, allowing users to customize frequency list by editing FREQ.TXT file on SD card. */ class ResourceManager { public: // Singleton getter static ResourceManager* getInstance(); // Singleton instance static ResourceManager* current; // Used from standalone app, to prevent memleak static void destroy(); // Get a string from BEACON.RES file static const char* get_beacon_resource(uint8_t line) { ResourceManager* rm = getInstance(); if (rm->beacon_res.empty()) { load_file((epirb_dir / u"RES/BEACON.RES"), rm->beacon_res); } if (line < rm->beacon_res.size()) { return rm->beacon_res[line].c_str(); } return UNKNOWN_LABEL; } // Get frequency values static const std::vector& get_frequencies() { ResourceManager* rm = getInstance(); if (rm->freq.empty()) { load_file((epirb_dir / u"FREQ.TXT"), rm->freq); } return rm->freq; } private: // BEACON.RES content std::vector beacon_res{}; // FREQ.TXT content std::vector freq{}; static void load_file(const std::filesystem::path& path, std::vector& vect) { FIL file; if (f_open(&file, path.tchar(), FA_READ) == FR_OK) { TCHAR line_buffer[32]; // Read the file line by line while (f_gets(line_buffer, sizeof(line_buffer) / sizeof(TCHAR), &file)) { std::string s; for (int i = 0; line_buffer[i] != '\0' && line_buffer[i] != '\n' && line_buffer[i] != '\r'; i++) { // Convert each TCHAR in char s += (char)line_buffer[i]; } vect.push_back(std::move(s)); } f_close(&file); } if (vect.empty()) vect.push_back(UNKNOWN_LABEL); } }; } // namespace ui::external_app::epirb_rx #endif // __RESOUCES_H__