mirror of
				https://github.com/AlexandreRouma/SDRPlusPlus.git
				synced 2025-10-31 08:58:13 +01:00 
			
		
		
		
	Merge pull request #1302 from AlexandreRouma/master
keep new_rds branch updated
This commit is contained in:
		| @@ -88,7 +88,7 @@ int CommandArgsParser::parse(int argc, char* argv[]) { | ||||
|             try { | ||||
|                 carg.ival = std::stoi(arg); | ||||
|             } | ||||
|             catch (std::exception e) { | ||||
|             catch (const std::exception& e) { | ||||
|                 printf("Invalid argument, failed to parse integer\n"); | ||||
|                 showHelp(); | ||||
|                 return -1; | ||||
| @@ -98,7 +98,7 @@ int CommandArgsParser::parse(int argc, char* argv[]) { | ||||
|             try { | ||||
|                 carg.fval = std::stod(arg); | ||||
|             } | ||||
|             catch (std::exception e) { | ||||
|             catch (const std::exception& e) { | ||||
|                 printf("Invalid argument, failed to parse float\n"); | ||||
|                 showHelp(); | ||||
|                 return -1; | ||||
|   | ||||
| @@ -36,8 +36,8 @@ void ConfigManager::load(json def, bool lock) { | ||||
|         file >> conf; | ||||
|         file.close(); | ||||
|     } | ||||
|     catch (std::exception e) { | ||||
|         flog::error("Config file '{0}' is corrupted, resetting it", path); | ||||
|     catch (const std::exception& e) { | ||||
|         flog::error("Config file '{}' is corrupted, resetting it: {}", path, e.what()); | ||||
|         conf = def; | ||||
|         save(false); | ||||
|     } | ||||
|   | ||||
| @@ -93,7 +93,7 @@ namespace dsp { | ||||
|         void disableBlock(Processor<T, T>* block, Func onOutputChange) { | ||||
|             // Check that the block is part of the chain | ||||
|             if (!blockExists(block)) { | ||||
|                 throw std::runtime_error("[chain] Tried to enable a block that isn't part of the chain"); | ||||
|                 throw std::runtime_error("[chain] Tried to disable a block that isn't part of the chain"); | ||||
|             } | ||||
|              | ||||
|             // If already disabled, don't do anything | ||||
| @@ -163,10 +163,12 @@ namespace dsp { | ||||
|  | ||||
|     private: | ||||
|         Processor<T, T>* blockBefore(Processor<T, T>* block) { | ||||
|             // TODO: This is wrong and must be fixed when I get more time | ||||
|             for (auto& ln : links) { | ||||
|                 if (ln == block) { return NULL; } | ||||
|                 if (states[ln]) { return ln; } | ||||
|             } | ||||
|             return NULL; | ||||
|         } | ||||
|  | ||||
|         Processor<T, T>* blockAfter(Processor<T, T>* block) { | ||||
|   | ||||
| @@ -110,7 +110,7 @@ namespace dsp::demod { | ||||
|             else if (_mode == Mode::LSB) { | ||||
|                 return -_bandwidth / 2.0; | ||||
|             } | ||||
|             else if (_mode == Mode::DSB) { | ||||
|             else { | ||||
|                 return 0.0; | ||||
|             } | ||||
|         } | ||||
|   | ||||
| @@ -62,6 +62,33 @@ inline void printAndScale(double freq, char* buf) { | ||||
|     } | ||||
| } | ||||
|  | ||||
| inline void doZoom(int offset, int width, int inSize, int outSize, float* in, float* out) { | ||||
|     // NOTE: REMOVE THAT SHIT, IT'S JUST A HACKY FIX | ||||
|     if (offset < 0) { | ||||
|         offset = 0; | ||||
|     } | ||||
|     if (width > 524288) { | ||||
|         width = 524288; | ||||
|     } | ||||
|  | ||||
|     float factor = (float)width / (float)outSize; | ||||
|     float sFactor = ceilf(factor); | ||||
|     float uFactor; | ||||
|     float id = offset; | ||||
|     float maxVal; | ||||
|     int sId; | ||||
|     for (int i = 0; i < outSize; i++) { | ||||
|         maxVal = -INFINITY; | ||||
|         sId = (int)id; | ||||
|         uFactor = (sId + sFactor > inSize) ? sFactor - ((sId + sFactor) - inSize) : sFactor; | ||||
|         for (int j = 0; j < uFactor; j++) { | ||||
|             if (in[sId + j] > maxVal) { maxVal = in[sId + j]; } | ||||
|         } | ||||
|         out[i] = maxVal; | ||||
|         id += factor; | ||||
|     } | ||||
| } | ||||
|  | ||||
| namespace ImGui { | ||||
|     WaterFall::WaterFall() { | ||||
|         fftMin = -70.0; | ||||
| @@ -586,7 +613,7 @@ namespace ImGui { | ||||
|             for (int i = 0; i < count; i++) { | ||||
|                 drawDataSize = (viewBandwidth / wholeBandwidth) * rawFFTSize; | ||||
|                 drawDataStart = (((double)rawFFTSize / 2.0) * (offsetRatio + 1)) - (drawDataSize / 2); | ||||
|                 doZoom(drawDataStart, drawDataSize, dataWidth, &rawFFTs[((i + currentFFTLine) % waterfallHeight) * rawFFTSize], tempData); | ||||
|                 doZoom(drawDataStart, drawDataSize, rawFFTSize, dataWidth, &rawFFTs[((i + currentFFTLine) % waterfallHeight) * rawFFTSize], tempData); | ||||
|                 for (int j = 0; j < dataWidth; j++) { | ||||
|                     pixel = (std::clamp<float>(tempData[j], waterfallMin, waterfallMax) - waterfallMin) / dataRange; | ||||
|                     waterfallFb[(i * dataWidth) + j] = waterfallPallet[(int)(pixel * (WATERFALL_RESOLUTION - 1))]; | ||||
| @@ -867,7 +894,7 @@ namespace ImGui { | ||||
|         int drawDataStart = (((double)rawFFTSize / 2.0) * (offsetRatio + 1)) - (drawDataSize / 2); | ||||
|  | ||||
|         if (waterfallVisible) { | ||||
|             doZoom(drawDataStart, drawDataSize, dataWidth, &rawFFTs[currentFFTLine * rawFFTSize], latestFFT); | ||||
|             doZoom(drawDataStart, drawDataSize, rawFFTSize, dataWidth, &rawFFTs[currentFFTLine * rawFFTSize], latestFFT); | ||||
|             memmove(&waterfallFb[dataWidth], waterfallFb, dataWidth * (waterfallHeight - 1) * sizeof(uint32_t)); | ||||
|             float pixel; | ||||
|             float dataRange = waterfallMax - waterfallMin; | ||||
| @@ -879,7 +906,7 @@ namespace ImGui { | ||||
|             waterfallUpdate = true; | ||||
|         } | ||||
|         else { | ||||
|             doZoom(drawDataStart, drawDataSize, dataWidth, rawFFTs, latestFFT); | ||||
|             doZoom(drawDataStart, drawDataSize, rawFFTSize, dataWidth, rawFFTs, latestFFT); | ||||
|             fftLines = 1; | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -90,33 +90,6 @@ namespace ImGui { | ||||
|         float* getFFTBuffer(); | ||||
|         void pushFFT(); | ||||
|  | ||||
|         inline void doZoom(int offset, int width, int outWidth, float* data, float* out) { | ||||
|             // NOTE: REMOVE THAT SHIT, IT'S JUST A HACKY FIX | ||||
|             if (offset < 0) { | ||||
|                 offset = 0; | ||||
|             } | ||||
|             if (width > 524288) { | ||||
|                 width = 524288; | ||||
|             } | ||||
|  | ||||
|             float factor = (float)width / (float)outWidth; | ||||
|             float sFactor = ceilf(factor); | ||||
|             float uFactor; | ||||
|             float id = offset; | ||||
|             float maxVal; | ||||
|             int sId; | ||||
|             for (int i = 0; i < outWidth; i++) { | ||||
|                 maxVal = -INFINITY; | ||||
|                 sId = (int)id; | ||||
|                 uFactor = (sId + sFactor > rawFFTSize) ? sFactor - ((sId + sFactor) - rawFFTSize) : sFactor; | ||||
|                 for (int j = 0; j < uFactor; j++) { | ||||
|                     if (data[sId + j] > maxVal) { maxVal = data[sId + j]; } | ||||
|                 } | ||||
|                 out[i] = maxVal; | ||||
|                 id += factor; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         void updatePallette(float colors[][3], int colorCount); | ||||
|         void updatePalletteFromArray(float* colors, int colorCount); | ||||
|  | ||||
|   | ||||
| @@ -86,14 +86,14 @@ namespace net { | ||||
|         addr.sin_port = htons(port); | ||||
|     } | ||||
|  | ||||
|     std::string Address::getIPStr() { | ||||
|     std::string Address::getIPStr() const { | ||||
|         char buf[128]; | ||||
|         IP_t ip = getIP(); | ||||
|         sprintf(buf, "%d.%d.%d.%d", (ip >> 24) & 0xFF, (ip >> 16) & 0xFF, (ip >> 8) & 0xFF, ip & 0xFF); | ||||
|         return buf; | ||||
|     } | ||||
|  | ||||
|     IP_t Address::getIP() { | ||||
|     IP_t Address::getIP() const { | ||||
|         return htonl(addr.sin_addr.s_addr); | ||||
|     } | ||||
|  | ||||
| @@ -101,7 +101,7 @@ namespace net { | ||||
|         addr.sin_addr.s_addr = htonl(ip); | ||||
|     } | ||||
|  | ||||
|     int Address::getPort() { | ||||
|     int Address::getPort() const { | ||||
|         return htons(addr.sin_port); | ||||
|     } | ||||
|  | ||||
| @@ -160,8 +160,8 @@ namespace net { | ||||
|  | ||||
|                 // Set timeout | ||||
|                 timeval tv; | ||||
|                 tv.tv_sec = 0; | ||||
|                 tv.tv_usec = timeout * 1000; | ||||
|                 tv.tv_sec = timeout / 1000; | ||||
|                 tv.tv_usec = (timeout - tv.tv_sec*1000) * 1000; | ||||
|  | ||||
|                 // Wait for data | ||||
|                 int err = select(sock+1, &set, NULL, &set, (timeout > 0) ? &tv : NULL); | ||||
| @@ -225,8 +225,8 @@ namespace net { | ||||
|  | ||||
|         // Define timeout | ||||
|         timeval tv; | ||||
|         tv.tv_sec = 0; | ||||
|         tv.tv_usec = timeout * 1000; | ||||
|         tv.tv_sec = timeout / 1000; | ||||
|         tv.tv_usec = (timeout - tv.tv_sec*1000) * 1000; | ||||
|  | ||||
|         // Wait for data or error | ||||
|         if (timeout != NONBLOCKING) { | ||||
| @@ -375,13 +375,25 @@ namespace net { | ||||
|         return connect(Address(host, port)); | ||||
|     } | ||||
|  | ||||
|     std::shared_ptr<Socket> openudp(const Address& raddr, const Address& laddr) { | ||||
|     std::shared_ptr<Socket> openudp(const Address& raddr, const Address& laddr, bool allowBroadcast) { | ||||
|         // Init library if needed | ||||
|         init(); | ||||
|  | ||||
|         // Create socket | ||||
|         SockHandle_t s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); | ||||
|  | ||||
|         // If the remote address is multicast, allow multicast connections | ||||
|         #ifdef _WIN32 | ||||
|                 const char enable = allowBroadcast; | ||||
|         #else | ||||
|                 int enable = allowBroadcast; | ||||
|         #endif | ||||
|         if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(int)) < 0) { | ||||
|             closeSocket(s); | ||||
|             throw std::runtime_error("Could not enable broadcast on socket"); | ||||
|             return NULL; | ||||
|         } | ||||
|  | ||||
|         // Bind socket to local port | ||||
|         if (bind(s, (sockaddr*)&laddr.addr, sizeof(sockaddr_in))) { | ||||
|             closeSocket(s); | ||||
| @@ -393,15 +405,15 @@ namespace net { | ||||
|         return std::make_shared<Socket>(s, &raddr); | ||||
|     } | ||||
|  | ||||
|     std::shared_ptr<Socket> openudp(std::string rhost, int rport, const Address& laddr) { | ||||
|         return openudp(Address(rhost, rport), laddr); | ||||
|     std::shared_ptr<Socket> openudp(std::string rhost, int rport, const Address& laddr, bool allowBroadcast) { | ||||
|         return openudp(Address(rhost, rport), laddr, allowBroadcast); | ||||
|     } | ||||
|  | ||||
|     std::shared_ptr<Socket> openudp(const Address& raddr, std::string lhost, int lport) { | ||||
|         return openudp(raddr, Address(lhost, lport)); | ||||
|     std::shared_ptr<Socket> openudp(const Address& raddr, std::string lhost, int lport, bool allowBroadcast) { | ||||
|         return openudp(raddr, Address(lhost, lport), allowBroadcast); | ||||
|     } | ||||
|  | ||||
|     std::shared_ptr<Socket> openudp(std::string rhost, int rport, std::string lhost, int lport) { | ||||
|         return openudp(Address(rhost, rport), Address(lhost, lport)); | ||||
|     std::shared_ptr<Socket> openudp(std::string rhost, int rport, std::string lhost, int lport, bool allowBroadcast) { | ||||
|         return openudp(Address(rhost, rport), Address(lhost, lport), allowBroadcast); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -67,13 +67,13 @@ namespace net { | ||||
|          * Get the IP address. | ||||
|          * @return IP address in standard string format. | ||||
|          */ | ||||
|         std::string getIPStr(); | ||||
|         std::string getIPStr() const; | ||||
|  | ||||
|         /** | ||||
|          * Get the IP address. | ||||
|          * @return IP address in host byte order. | ||||
|          */ | ||||
|         IP_t getIP(); | ||||
|         IP_t getIP() const; | ||||
|  | ||||
|         /** | ||||
|          * Set the IP address. | ||||
| @@ -85,7 +85,7 @@ namespace net { | ||||
|          * Get the TCP/UDP port. | ||||
|          * @return TCP/UDP port number. | ||||
|          */ | ||||
|         int getPort(); | ||||
|         int getPort() const; | ||||
|  | ||||
|         /** | ||||
|          * Set the TCP/UDP port. | ||||
| @@ -246,37 +246,37 @@ namespace net { | ||||
|  | ||||
|     /** | ||||
|      * Create UDP socket. | ||||
|      * @param raddr Remote address. | ||||
|      * @param raddr Remote address. Set to a multicast address to allow multicast. | ||||
|      * @param laddr Local address to bind the socket to. | ||||
|      * @return Socket instance on success, Throws runtime_error otherwise. | ||||
|      */ | ||||
|     std::shared_ptr<Socket> openudp(const Address& raddr, const Address& laddr); | ||||
|     std::shared_ptr<Socket> openudp(const Address& raddr, const Address& laddr, bool allowBroadcast = false); | ||||
|  | ||||
|     /** | ||||
|      * Create UDP socket. | ||||
|      * @param rhost Remote hostname or IP address. | ||||
|      * @param rhost Remote hostname or IP address. Set to a multicast address to allow multicast. | ||||
|      * @param rport Remote port. | ||||
|      * @param laddr Local address to bind the socket to. | ||||
|      * @return Socket instance on success, Throws runtime_error otherwise. | ||||
|      */ | ||||
|     std::shared_ptr<Socket> openudp(std::string rhost, int rport, const Address& laddr); | ||||
|     std::shared_ptr<Socket> openudp(std::string rhost, int rport, const Address& laddr, bool allowBroadcast = false); | ||||
|  | ||||
|     /** | ||||
|      * Create UDP socket. | ||||
|      * @param raddr Remote address. | ||||
|      * @param raddr Remote address. Set to a multicast or broadcast address to allow multicast. | ||||
|      * @param lhost Local hostname or IP used to bind the socket (optional, "0.0.0.0" for Any). | ||||
|      * @param lpost Local port used to bind the socket to (optional, 0 to allocate automatically). | ||||
|      * @return Socket instance on success, Throws runtime_error otherwise. | ||||
|      */ | ||||
|     std::shared_ptr<Socket> openudp(const Address& raddr, std::string lhost = "0.0.0.0", int lport = 0); | ||||
|     std::shared_ptr<Socket> openudp(const Address& raddr, std::string lhost = "0.0.0.0", int lport = 0, bool allowBroadcast = false); | ||||
|  | ||||
|     /** | ||||
|      * Create UDP socket. | ||||
|      * @param rhost Remote hostname or IP address. | ||||
|      * @param rhost Remote hostname or IP address. Set to a multicast or broadcast address to allow multicast. | ||||
|      * @param rport Remote port. | ||||
|      * @param lhost Local hostname or IP used to bind the socket (optional, "0.0.0.0" for Any). | ||||
|      * @param lpost Local port used to bind the socket to (optional, 0 to allocate automatically). | ||||
|      * @return Socket instance on success, Throws runtime_error otherwise. | ||||
|      */ | ||||
|     std::shared_ptr<Socket> openudp(std::string rhost, int rport, std::string lhost = "0.0.0.0", int lport = 0);   | ||||
|     std::shared_ptr<Socket> openudp(std::string rhost, int rport, std::string lhost = "0.0.0.0", int lport = 0, bool allowBroadcast = false);   | ||||
| } | ||||
| @@ -320,7 +320,7 @@ namespace net { | ||||
|                 } | ||||
|                 entry.handler(std::move(client), entry.ctx); | ||||
|             } | ||||
|             catch (std::exception e) { | ||||
|             catch (const std::exception& e) { | ||||
|                 listening = false; | ||||
|                 return; | ||||
|             } | ||||
|   | ||||
| @@ -257,6 +257,7 @@ namespace net::http { | ||||
|  | ||||
|         // Deserialize | ||||
|         req.deserialize(respData); | ||||
|         return 0; // Might wanna return size instead | ||||
|     } | ||||
|  | ||||
|     int Client::sendResponseHeader(ResponseHeader& resp) { | ||||
| @@ -274,6 +275,7 @@ namespace net::http { | ||||
|  | ||||
|         // Deserialize | ||||
|         resp.deserialize(respData); | ||||
|         return 0; // Might wanna return size instead | ||||
|     } | ||||
|  | ||||
|     int Client::sendChunkHeader(ChunkHeader& chdr) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user