| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of the Falcon Player (FPP) and is Copyright (C) | ||
| 3 | * 2013-2022 by the Falcon Player Developers. | ||
| 4 | * | ||
| 5 | * The Falcon Player (FPP) is free software, and is covered under | ||
| 6 | * multiple Open Source licenses. Please see the included 'LICENSES' | ||
| 7 | * file for descriptions of what files are covered by each license. | ||
| 8 | * | ||
| 9 | * This source file is covered under the LGPL v2.1 as described in the | ||
| 10 | * included LICENSE.LGPL file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include "fpp-pch.h" | ||
| 14 | |||
| 15 | #include "fpp-json.h" | ||
| 16 | |||
| 17 | #ifdef PLATFORM_OSX | ||
| 18 | #include <netinet/udp.h> | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #include <arpa/inet.h> | ||
| 22 | #include <net/if.h> | ||
| 23 | #include <netinet/in.h> | ||
| 24 | #include <sys/socket.h> | ||
| 25 | #include <sys/uio.h> | ||
| 26 | #include <algorithm> | ||
| 27 | #include <atomic> | ||
| 28 | #include <cstdlib> | ||
| 29 | #include <errno.h> | ||
| 30 | #include <ifaddrs.h> | ||
| 31 | #include <inttypes.h> | ||
| 32 | #include <map> | ||
| 33 | #include <memory> | ||
| 34 | #include <set> | ||
| 35 | #include <stdio.h> | ||
| 36 | #include <string.h> | ||
| 37 | #include <string> | ||
| 38 | #include <unistd.h> | ||
| 39 | #include <utility> | ||
| 40 | #include <vector> | ||
| 41 | |||
| 42 | #include "EPollManager.h" | ||
| 43 | #include "FileMonitor.h" | ||
| 44 | #include "Sequence.h" | ||
| 45 | #include "Timers.h" | ||
| 46 | #include "Warnings.h" | ||
| 47 | #include "common.h" | ||
| 48 | #include "e131defs.h" | ||
| 49 | #include "fppversion.h" | ||
| 50 | #include "log.h" | ||
| 51 | #include "settings.h" | ||
| 52 | #include "channeloutput/ChannelOutputSetup.h" | ||
| 53 | #include "channeloutput/DDP.h" | ||
| 54 | #include "channeloutput/Universe.h" | ||
| 55 | #include "channeloutput/channeloutputthread.h" | ||
| 56 | #include "commands/Commands.h" | ||
| 57 | |||
| 58 | #include "channeloutput/serialutil.h" | ||
| 59 | #include "util/GPIOUtils.h" | ||
| 60 | |||
| 61 | #include "e131bridge.h" | ||
| 62 | #include "SysSocket.h" | ||
| 63 | |||
| 64 | #define BRIDGE_INVALID_UNIVERSE_INDEX 0xFFFFFF | ||
| 65 | // Cached "looked it up, not configured" marker, distinct from the | ||
| 66 | // "never looked up" state above. Internal to the universe caches. | ||
| 67 | #define BRIDGE_UNIVERSE_NOT_FOUND 0xFFFFFE | ||
| 68 | |||
| 69 | static int bridgeSock = -1; | ||
| 70 | static int ddpSock = -1; | ||
| 71 | static std::atomic<int> artnetSock = -1; | ||
| 72 | static volatile bool artnetSocketAsInput = false; | ||
| 73 | |||
| 74 | static long long last_packet_time = GetTimeMS(); | ||
| 75 | static long long expireOffSet = 1000; // expire after 1 second | ||
| 76 | |||
| 77 | // When true, the bridge tracks the active source per universe and prefers | ||
| 78 | // the highest-priority sender. For E1.31 the priority comes from the packet | ||
| 79 | // header; for ArtNet (which has no priority field) all senders share the | ||
| 80 | // same priority so it reduces to first-source-wins with timeout failover. | ||
| 81 | // A lower-priority source only takes over if the current source stops | ||
| 82 | // sending for longer than expireOffSet. | ||
| 83 | static std::atomic<bool> sourcePriorityEnabled{false}; | ||
| 84 | |||
| 85 | // Source address and received length of the ArtNet packet currently being | ||
| 86 | // handled. Set by Bridge_ReceiveArtNetData before each handler callback so | ||
| 87 | // handlers can use them without changing the public AddArtNetOpcodeHandler | ||
| 88 | // signature. | ||
| 89 | static in_addr_t currentArtNetSourceIP = 0; | ||
| 90 | static int currentArtNetPacketLen = 0; | ||
| 91 | |||
| 92 | // The per-universe counters are bumped by the packet path, and read and reset | ||
| 93 | // from the HTTP threads, so every access is a relaxed atomic one: a reset | ||
| 94 | // racing an increment was a data race, as was the stats read itself. | ||
| 95 | // UniverseEntry keeps plain fields (its layout is shared), hence the builtins. | ||
| 96 | 144970 | static inline void StatAdd(uint32_t& c, uint32_t n) { | |
| 97 | 144970 | __atomic_fetch_add(&c, n, __ATOMIC_RELAXED); | |
| 98 | 144970 | } | |
| 99 | 349030 | static inline uint32_t StatLoad(const uint32_t& c) { | |
| 100 | 349030 | return __atomic_load_n(&c, __ATOMIC_RELAXED); | |
| 101 | } | ||
| 102 | 192317 | static inline void StatStore(uint32_t& c, uint32_t v) { | |
| 103 | 192317 | __atomic_store_n(&c, v, __ATOMIC_RELAXED); | |
| 104 | 192317 | } | |
| 105 | |||
| 106 | // Evaluate whether to accept a packet from the given source for this | ||
| 107 | // universe under the priority-aware policy. Updates the entry's active | ||
| 108 | // source state as a side effect. Returns true if the packet should be | ||
| 109 | // applied; false if it should be suppressed. sourceJustSwitched is set to | ||
| 110 | // true when the caller should skip sequence-number error counting for this | ||
| 111 | // packet because the active source identifier just changed. | ||
| 112 | 256 | static inline bool EvaluateSource(UniverseEntry& entry, | |
| 113 | const uint8_t* sourceId, | ||
| 114 | uint8_t priority, | ||
| 115 | bool& sourceJustSwitched) { | ||
| 116 | 256 | sourceJustSwitched = false; | |
| 117 | // The active source's age is on the monotonic clock. It was the packets' | ||
| 118 | // wall-clock time: a step back kept a stopped source "active" for the size | ||
| 119 | // of the step, so the backup source stayed suppressed and the output froze | ||
| 120 | // on the last frame of the one that stopped. | ||
| 121 | 256 | long long packetTime = GetMonotonicTimeMS(); | |
| 122 |
2/2✓ Branch 0 taken 254 times.
✓ Branch 1 taken 2 times.
|
510 | bool idMatches = entry.activeSourceValid && |
| 123 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 124 times.
|
254 | memcmp(entry.activeSourceId, sourceId, 16) == 0; |
| 124 |
2/2✓ Branch 0 taken 254 times.
✓ Branch 1 taken 2 times.
|
510 | bool expired = entry.activeSourceValid && |
| 125 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 252 times.
|
254 | (packetTime - entry.activeSourceLastTime) > expireOffSet; |
| 126 | |||
| 127 |
6/6✓ Branch 0 taken 254 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 252 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 250 times.
|
256 | if (!entry.activeSourceValid || expired || priority > entry.activeSourcePriority) { |
| 128 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
6 | if (entry.activeSourceValid && !idMatches) { |
| 129 | 4 | sourceJustSwitched = true; | |
| 130 | } | ||
| 131 | 6 | memcpy(entry.activeSourceId, sourceId, 16); | |
| 132 | 6 | entry.activeSourcePriority = priority; | |
| 133 | 6 | entry.activeSourceLastTime = packetTime; | |
| 134 | 6 | entry.activeSourceValid = true; | |
| 135 | 6 | return true; | |
| 136 | } | ||
| 137 |
2/2✓ Branch 0 taken 130 times.
✓ Branch 1 taken 120 times.
|
250 | if (idMatches) { |
| 138 | 130 | entry.activeSourcePriority = priority; | |
| 139 | 130 | entry.activeSourceLastTime = packetTime; | |
| 140 | 130 | return true; | |
| 141 | } | ||
| 142 | // Lower-or-equal priority from a different source while the current | ||
| 143 | // source is still active; suppress it. | ||
| 144 | 120 | StatAdd(entry.suppressedPackets, 1); | |
| 145 | 120 | return false; | |
| 146 | } | ||
| 147 | |||
| 148 | #define MAX_MSG 64 | ||
| 149 | // Batches of MAX_MSG read per wakeup. The sockets are level-triggered, so | ||
| 150 | // what is left is read on the next pass; draining until empty let a sender | ||
| 151 | // faster than fppd keep the main loop in here for good. | ||
| 152 | static constexpr int MAX_BATCHES_PER_WAKEUP = 64; | ||
| 153 | #define BUFSIZE 1500 | ||
| 154 | static struct mmsghdr msgs[MAX_MSG]; | ||
| 155 | static struct iovec iovecs[MAX_MSG]; | ||
| 156 | static uint8_t buffers[MAX_MSG][BUFSIZE + 1]; | ||
| 157 | static struct sockaddr_in inAddress[MAX_MSG]; | ||
| 158 | |||
| 159 | // One lookup cache per protocol: E1.31 and ArtNet number their universes | ||
| 160 | // independently, so ArtNet universe N and E1.31 universe N are different | ||
| 161 | // inputs and a packet must only ever land on an entry of its own protocol. | ||
| 162 | // ArtNet's Port-Address is 15 bits. | ||
| 163 | static unsigned int E131UniverseCache[65536]; | ||
| 164 | static unsigned int ArtNetUniverseCache[32768]; | ||
| 165 | |||
| 166 | static std::vector<UniverseEntry> InputUniverses; | ||
| 167 | static int InputUniverseCount; | ||
| 168 | |||
| 169 | // DMX serial inputs live apart from the UDP universe list. The UDP reload | ||
| 170 | // path rebuilds InputUniverses from scratch, so anything else stored in that | ||
| 171 | // vector is destroyed (and any index captured by an epoll callback goes | ||
| 172 | // stale) on every ci-universes.json change. shared_ptr gives each DMX entry | ||
| 173 | // an identity that survives both reload paths. | ||
| 174 | static std::vector<std::shared_ptr<UniverseEntry>> DMXInputs; | ||
| 175 | |||
| 176 | // Guards the STRUCTURE of InputUniverses/DMXInputs. Reloads (main loop) swap | ||
| 177 | // the containers while GetE131UniverseBytesReceived/ResetBytesReceived run on | ||
| 178 | // the HTTP server's worker threads; without this a stats poll during a config | ||
| 179 | // reload reads a vector mid-rebuild. The packet path runs on the same | ||
| 180 | // main-loop thread as every mutation, so it deliberately does NOT take this - | ||
| 181 | // a freed vector is the danger, not a counter being bumped meanwhile. | ||
| 182 | static std::mutex universesStructureLock; | ||
| 183 | |||
| 184 | static std::atomic<uint64_t> ddpBytesReceived{0}; | ||
| 185 | static std::atomic<uint32_t> ddpPacketsReceived{0}; | ||
| 186 | static std::atomic<uint32_t> ddpErrors{0}; | ||
| 187 | |||
| 188 | static uint32_t ddpLastSequence = 0; | ||
| 189 | static uint32_t ddpLastChannel = 0; | ||
| 190 | // The channel range DDP has covered. Written only by the main loop's packet | ||
| 191 | // handler, read by the stats endpoint from the HTTP threads. | ||
| 192 | static std::atomic<uint32_t> ddpMinChannel{0xFFFFFFF}; | ||
| 193 | static std::atomic<uint32_t> ddpMaxChannel{0}; | ||
| 194 | |||
| 195 | static std::atomic<uint32_t> e131Errors{0}; | ||
| 196 | static std::atomic<uint32_t> e131SyncPackets{0}; | ||
| 197 | static UniverseEntry unknownUniverse; | ||
| 198 | |||
| 199 | // Sync universes we've auto-joined the multicast group for, based on the | ||
| 200 | // sync-address field advertised in received data packets. Lets sync packets | ||
| 201 | // reach the bridge even when the sync universe isn't a configured input. | ||
| 202 | // Capped: every new one costs a getifaddrs() and a join per interface on the | ||
| 203 | // main loop, and the field comes from whoever sends a packet, so a stream | ||
| 204 | // with a different sync address in each packet would otherwise join groups | ||
| 205 | // (and stall the loop) without limit. A real show uses one or two. | ||
| 206 | static std::set<int> joinedSyncUniverses; | ||
| 207 | static constexpr size_t MAX_JOINED_SYNC_UNIVERSES = 16; | ||
| 208 | static bool syncUniverseCapLogged = false; | ||
| 209 | |||
| 210 | // Set by the receive path, read by status and the main loop. | ||
| 211 | static std::atomic<bool> bridgeDataReceived{ false }; | ||
| 212 | |||
| 213 | static std::map<int, std::function<bool(uint8_t* data, long long packetTime)>> ArtNetOpcodeHandlers; | ||
| 214 | |||
| 215 | // The ArtNet socket is shared by everything that speaks ArtNet: the protocol | ||
| 216 | // fixes the port, so the bridge and any plugin extending ArtNet necessarily | ||
| 217 | // receive on one descriptor. Its epoll registration therefore belongs HERE and | ||
| 218 | // nowhere else, driven by whether any opcode handler currently wants packets. | ||
| 219 | // | ||
| 220 | // It used to be registered by each interested party instead, which does not | ||
| 221 | // work for a shared descriptor. EPollManager holds one callback per fd, so the | ||
| 222 | // second registration silently replaced the first, and the first removal took | ||
| 223 | // the descriptor out of the epoll set for everyone - unloading a plugin that | ||
| 224 | // had registered it stopped the bridge receiving ArtNet entirely. Keeping it | ||
| 225 | // here also means the callback is always FPP's own, never a plugin's, so an | ||
| 226 | // unloaded plugin can never leave the loop dispatching into an unmapped | ||
| 227 | // library. | ||
| 228 | // | ||
| 229 | // While a handler is waiting for a socket that could not be opened (another | ||
| 230 | // program holds 6454), a main-loop timer keeps calling back in here. The | ||
| 231 | // socket can appear without this function running at all -- the ArtNet | ||
| 232 | // output asks for it from the output thread on every frame -- and nothing | ||
| 233 | // else would put it in the epoll set: ArtNet input stayed dead after the | ||
| 234 | // port came free, with the warning that said so already taken down. The | ||
| 235 | // timer also retries the port itself when nothing else asks for it. | ||
| 236 | static constexpr const char* ARTNET_INPUT_RETRY_TIMER = "ArtNetInputRetry"; | ||
| 237 | static bool artnetInputRetryRunning = false; | ||
| 238 | |||
| 239 | 8012 | static void UpdateArtNetInputRegistration() { | |
| 240 | 8012 | bool wanted = !ArtNetOpcodeHandlers.empty(); | |
| 241 |
6/6✓ Branch 0 taken 109 times.
✓ Branch 1 taken 7903 times.
✓ Branch 2 taken 13 times.
✓ Branch 3 taken 96 times.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 7999 times.
|
8012 | if (wanted && artnetSock < 0) { |
| 242 | // A handler wants ArtNet packets on a player that has no ArtNet input | ||
| 243 | // of its own, so there is no socket yet. Create it - this is what the | ||
| 244 | // callers who used to register the descriptor themselves were doing by | ||
| 245 | // calling CreateArtNetSocket(), and without it a plugin's triggers | ||
| 246 | // would silently stop working wherever the bridge has no ArtNet. | ||
| 247 | // After a failure this returns at once until its retry interval is up. | ||
| 248 | 13 | CreateArtNetSocket(); | |
| 249 | } | ||
| 250 |
4/4✓ Branch 0 taken 109 times.
✓ Branch 1 taken 7903 times.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 99 times.
|
8012 | bool waiting = wanted && artnetSock < 0; |
| 251 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 8010 times.
|
8012 | if (waiting != artnetInputRetryRunning) { |
| 252 | 2 | artnetInputRetryRunning = waiting; | |
| 253 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (waiting) { |
| 254 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
3 | Timers::INSTANCE.addPeriodicTimer(ARTNET_INPUT_RETRY_TIMER, 1000, []() { |
| 255 | 10 | UpdateArtNetInputRegistration(); | |
| 256 | 10 | }); | |
| 257 | } else { | ||
| 258 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | Timers::INSTANCE.stopPeriodicTimer(ARTNET_INPUT_RETRY_TIMER); |
| 259 | } | ||
| 260 | } | ||
| 261 |
2/2✓ Branch 0 taken 7801 times.
✓ Branch 1 taken 211 times.
|
8012 | if (artnetSock < 0) { |
| 262 | 7801 | return; | |
| 263 | } | ||
| 264 |
6/6✓ Branch 0 taken 99 times.
✓ Branch 1 taken 112 times.
✓ Branch 2 taken 91 times.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 91 times.
✓ Branch 5 taken 120 times.
|
211 | if (wanted && !artnetSocketAsInput) { |
| 265 | 34408 | std::function<bool(int)> f = [](int i) { | |
| 266 | 34317 | return Bridge_ReceiveArtNetData(); | |
| 267 | 91 | }; | |
| 268 |
1/2✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
|
91 | EPollManager::INSTANCE.addFileDescriptor(artnetSock, f); |
| 269 | 91 | artnetSocketAsInput = true; | |
| 270 |
6/6✓ Branch 0 taken 112 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 88 times.
✓ Branch 3 taken 24 times.
✓ Branch 4 taken 88 times.
✓ Branch 5 taken 32 times.
|
211 | } else if (!wanted && artnetSocketAsInput) { |
| 271 | 88 | EPollManager::INSTANCE.removeFileDescriptor(artnetSock); | |
| 272 | 88 | artnetSocketAsInput = false; | |
| 273 | } | ||
| 274 | } | ||
| 275 | |||
| 276 | 2 | void AddArtNetOpcodeHandler(int opCode, std::function<bool(uint8_t* data, long long packetTime)> handler) { | |
| 277 | 2 | ArtNetOpcodeHandlers[opCode] = handler; | |
| 278 | 2 | UpdateArtNetInputRegistration(); | |
| 279 | 2 | } | |
| 280 | 2 | void RemoveArtNetOpcodeHandler(int opCode) { | |
| 281 | 2 | ArtNetOpcodeHandlers.erase(opCode); | |
| 282 | 2 | UpdateArtNetInputRegistration(); | |
| 283 | 2 | } | |
| 284 | |||
| 285 | // Changed by input config reloads, read by the output thread. | ||
| 286 | static std::atomic<bool> hasUDP{ false }; | ||
| 287 | static std::atomic<bool> hasDMX{ false }; | ||
| 288 | 35629 | bool InputsEnabled() { | |
| 289 |
4/4✓ Branch 0 taken 35561 times.
✓ Branch 1 taken 68 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 35560 times.
|
35629 | return hasUDP || hasDMX; |
| 290 | } | ||
| 291 | |||
| 292 | // prototypes for functions below | ||
| 293 | bool Bridge_StoreData(uint8_t* bridgeBuffer, long long packetTime, int msgLen); | ||
| 294 | bool Bridge_StoreDDPData(uint8_t* bridgeBuffer, long long packetTime, int msgLen); | ||
| 295 | void BridgeShutdownUDP(bool reloading); | ||
| 296 | int Bridge_GetIndexFromUniverseNumber(int universe, bool artnet); | ||
| 297 | void InputUniversesPrint(); | ||
| 298 | inline void SetBridgeData(uint8_t* data, int startChannel, int len, long long packetTime); | ||
| 299 | inline void CommitBridgeData(); | ||
| 300 | |||
| 301 | // Size the receive buffer on a bridge input socket. A show pushing several | ||
| 302 | // hundred universes delivers a full frame as one back-to-back burst (hundreds | ||
| 303 | // of packets), and the main loop can stall for a frame or two doing output | ||
| 304 | // processing before it drains the socket. If the receive buffer is too small | ||
| 305 | // the kernel tail-drops that burst. A plain SO_RCVBUF request is silently | ||
| 306 | // clamped to net.core.rmem_max, so scale the request to the packets in a frame | ||
| 307 | // and try SO_RCVBUFFORCE first (fppd runs as root, so CAP_NET_ADMIN lets it | ||
| 308 | // bypass rmem_max); fall back to the clamped SO_RCVBUF otherwise. | ||
| 309 | 3437 | static void SetBridgeReceiveBufferSize(int sock, long packetsPerFrame) { | |
| 310 | // ~4KB/packet leaves several frames of burst headroom even after the | ||
| 311 | // kernel's per-packet accounting overhead; clamp to a floor and ceiling. | ||
| 312 | 3437 | long desired = packetsPerFrame * 4096; | |
| 313 |
2/2✓ Branch 0 taken 3429 times.
✓ Branch 1 taken 8 times.
|
3437 | if (desired < 512 * 1024) { |
| 314 | 3429 | desired = 512 * 1024; | |
| 315 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
|
8 | } else if (desired > 16 * 1024 * 1024) { |
| 316 | 1 | desired = 16 * 1024 * 1024; | |
| 317 | } | ||
| 318 | 3437 | int bufSize = (int)desired; | |
| 319 | 3437 | bool forced = false; | |
| 320 | #ifdef SO_RCVBUFFORCE | ||
| 321 | 3437 | forced = setsockopt(sock, SOL_SOCKET, SO_RCVBUFFORCE, &bufSize, sizeof(bufSize)) == 0; | |
| 322 | #endif | ||
| 323 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3437 times.
|
3437 | if (!forced) { |
| 324 | // Not privileged (or unsupported): plain request, clamped to rmem_max. | ||
| 325 | ✗ | setsockopt(sock, SOL_SOCKET, SO_RCVBUF, &bufSize, sizeof(bufSize)); | |
| 326 | } | ||
| 327 | 3437 | int actual = 0; | |
| 328 | 3437 | socklen_t len = sizeof(actual); | |
| 329 |
1/2✓ Branch 0 taken 3437 times.
✗ Branch 1 not taken.
|
3437 | if (getsockopt(sock, SOL_SOCKET, SO_RCVBUF, &actual, &len) == 0) { |
| 330 |
1/2✓ Branch 0 taken 3437 times.
✗ Branch 1 not taken.
|
3437 | LogDebug(VB_E131BRIDGE, "Bridge socket %d recv buffer: requested %d, granted %d\n", |
| 331 | sock, bufSize, actual); | ||
| 332 | } | ||
| 333 | 3437 | } | |
| 334 | |||
| 335 | // E1.31 and ArtNet send a packet per configured input universe. DDP input | ||
| 336 | // is not configured by universe -- it lands anywhere in the channel buffer -- | ||
| 337 | // so a box fed only DDP counted no universes and got the floor, about 450 | ||
| 338 | // full packets: two frames of a few hundred thousand channels. A sender | ||
| 339 | // sends the channels the outputs here use, up to 1440 to a packet, so count | ||
| 340 | // the packets that cover each output range. | ||
| 341 | 1739 | static long DDPPacketsPerFrame() { | |
| 342 | 1739 | long packets = 0; | |
| 343 |
1/2✓ Branch 0 taken 1739 times.
✗ Branch 1 not taken.
|
1739 | auto ranges = GetOutputRangesSnapshot(); |
| 344 |
2/2✓ Branch 0 taken 1739 times.
✓ Branch 1 taken 1739 times.
|
3478 | for (const auto& r : *ranges) { |
| 345 | 1739 | packets += ((long)r.second + 1439) / 1440; | |
| 346 | } | ||
| 347 | 1739 | return packets; | |
| 348 | 1739 | } | |
| 349 | |||
| 350 | 2950 | void Bridge_OutputRangesChanged() { | |
| 351 |
2/2✓ Branch 0 taken 103 times.
✓ Branch 1 taken 2847 times.
|
2950 | if (ddpSock >= 0) { |
| 352 | 103 | SetBridgeReceiveBufferSize(ddpSock, DDPPacketsPerFrame()); | |
| 353 | } | ||
| 354 | 2950 | } | |
| 355 | |||
| 356 | // Why ArtNet is off (or is sending from another port), as shown in the | ||
| 357 | // warning banner; empty while the socket is fine. The ArtNet port is fixed | ||
| 358 | // by the protocol, so another program holding it (a second player, xLights, | ||
| 359 | // a plugin) is an ordinary condition, not a fault. | ||
| 360 | static constexpr int WARNING_ID_ARTNET_PORT = 54; | ||
| 361 | static std::string artnetPortWarning; | ||
| 362 | // When the last attempt to open the socket failed (GetMonotonicTimeMS()), 0 | ||
| 363 | // if it didn't. An ArtNet output asks for the socket on every frame while it | ||
| 364 | // has none, and every attempt used to log an error: 20-40 lines a second to | ||
| 365 | // the log for as long as the port stayed taken. Attempts from there are made | ||
| 366 | // at most every ARTNET_RETRY_MS. | ||
| 367 | static long long artnetFailedAt = 0; | ||
| 368 | static constexpr long long ARTNET_RETRY_MS = 10000; | ||
| 369 | static std::mutex artnetSocketMutex; | ||
| 370 | |||
| 371 | // Caller holds artnetSocketMutex. | ||
| 372 | 3689 | static void SetArtNetPortWarning(const std::string& msg) { | |
| 373 |
2/2✓ Branch 0 taken 3683 times.
✓ Branch 1 taken 6 times.
|
3689 | if (msg == artnetPortWarning) { |
| 374 | 3683 | return; | |
| 375 | } | ||
| 376 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
|
6 | if (!artnetPortWarning.empty()) { |
| 377 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | WarningHolder::RemoveWarning(WARNING_ID_ARTNET_PORT, artnetPortWarning); |
| 378 | } | ||
| 379 | 6 | artnetPortWarning = msg; | |
| 380 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
|
6 | if (!msg.empty()) { |
| 381 | 4 | LogWarn(VB_E131BRIDGE, "%s\n", msg.c_str()); | |
| 382 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | WarningHolder::AddWarning(WARNING_ID_ARTNET_PORT, msg); |
| 383 | } | ||
| 384 | } | ||
| 385 | |||
| 386 | 1041 | int CreateArtNetSocket(uint32_t sourceAddr, bool allowPortChange) { | |
| 387 |
1/2✓ Branch 0 taken 1041 times.
✗ Branch 1 not taken.
|
1041 | std::lock_guard<std::mutex> lock(artnetSocketMutex); |
| 388 |
2/2✓ Branch 0 taken 49 times.
✓ Branch 1 taken 992 times.
|
1041 | if (artnetSock >= 0) { |
| 389 | 49 | return artnetSock; | |
| 390 | } | ||
| 391 | // Callers that can fall back to another port (output setup, a network | ||
| 392 | // change) always try: they are rare, and the fallback is what lets ArtNet | ||
| 393 | // output run at all while the port is taken. | ||
| 394 |
1/2✓ Branch 0 taken 992 times.
✗ Branch 1 not taken.
|
992 | long long now = GetMonotonicTimeMS(); |
| 395 |
6/6✓ Branch 0 taken 985 times.
✓ Branch 1 taken 7 times.
✓ Branch 2 taken 926 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 924 times.
✓ Branch 5 taken 2 times.
|
992 | if (!allowPortChange && artnetFailedAt && now - artnetFailedAt < ARTNET_RETRY_MS) { |
| 396 | 924 | return -1; | |
| 397 | } | ||
| 398 | 3 | auto failed = [now](const std::string& msg) { | |
| 399 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | artnetFailedAt = now ? now : 1; |
| 400 | // Logged once, when it changes; the warning says it from then on. | ||
| 401 | 3 | SetArtNetPortWarning(msg); | |
| 402 | 3 | return -1; | |
| 403 | 68 | }; | |
| 404 | |||
| 405 | 68 | int artnetSockT = OpenSocket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0); | |
| 406 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
|
68 | if (artnetSockT < 0) { |
| 407 | // As for a failed bind below: run without ArtNet, don't exit(). | ||
| 408 | ✗ | return failed(std::string("ArtNet is off: could not create its socket (") + FPPstrerror(errno) + ")"); | |
| 409 | } | ||
| 410 | 68 | int enable = 1; | |
| 411 | // need to be able to send broadcast for ArtPollReply | ||
| 412 | 68 | setsockopt(artnetSockT, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable)); | |
| 413 | 68 | enable = 1; | |
| 414 | #ifdef PLATFORM_OSX | ||
| 415 | setsockopt(artnetSockT, IPPROTO_UDP, UDP_NOCKSUM, (void*)&enable, sizeof enable); | ||
| 416 | #else | ||
| 417 | 68 | setsockopt(artnetSockT, SOL_SOCKET, SO_NO_CHECK, (void*)&enable, sizeof enable); | |
| 418 | #endif | ||
| 419 |
1/2✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
|
68 | SetBridgeReceiveBufferSize(artnetSockT, InputUniverseCount); |
| 420 | 68 | int bufSize = 512 * 1024; | |
| 421 | 68 | setsockopt(artnetSockT, SOL_SOCKET, SO_SNDBUF, &bufSize, sizeof(bufSize)); | |
| 422 | |||
| 423 | // A local: CreateArtNetSocket runs on the output thread as well as the | ||
| 424 | // main loop, and a bind address shared with OpenBridgeSocket could be | ||
| 425 | // rewritten between filling it in and bind(). | ||
| 426 | struct sockaddr_in addr; | ||
| 427 | 68 | memset((char*)&addr, 0, sizeof(addr)); | |
| 428 | 68 | addr.sin_family = AF_INET; | |
| 429 |
2/2✓ Branch 0 taken 61 times.
✓ Branch 1 taken 7 times.
|
68 | addr.sin_addr.s_addr = sourceAddr == 0 ? htonl(INADDR_ANY) : (in_addr_t)sourceAddr; |
| 430 | 68 | addr.sin_port = htons(0x1936); // artnet port | |
| 431 | 68 | std::string warning; | |
| 432 | // Bind the socket to address/port | ||
| 433 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 64 times.
|
68 | if (bind(artnetSockT, (struct sockaddr*)&addr, sizeof(addr)) < 0) { |
| 434 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | std::string why = FPPstrerror(errno); |
| 435 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | if (!allowPortChange) { |
| 436 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | close(artnetSockT); |
| 437 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
3 | return failed("ArtNet is off: could not open UDP port 6454 (" + why + ")"); |
| 438 | } | ||
| 439 | 1 | addr.sin_port = htons(0); // let OS pick port | |
| 440 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (bind(artnetSockT, (struct sockaddr*)&addr, sizeof(addr)) < 0) { |
| 441 | ✗ | std::string why2 = FPPstrerror(errno); | |
| 442 | ✗ | close(artnetSockT); | |
| 443 | ✗ | return failed("ArtNet is off: could not open UDP port 6454 (" + why + ") or any other port (" + why2 + ")"); | |
| 444 | ✗ | } | |
| 445 | // Output still works from here, but nothing reaches ArtNet input or | ||
| 446 | // ArtPoll on 6454 until the socket is opened again. | ||
| 447 | // Nothing retries 6454 once a socket is open on another port, so this | ||
| 448 | // stays up until FPPD restarts (or the output interface changes) -- | ||
| 449 | // and says so. | ||
| 450 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
2 | warning = "ArtNet input is off and ArtNet output is sent from another port: could not open UDP port 6454 (" + why + |
| 451 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | "). Restart FPPD once the port is free."; |
| 452 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
|
4 | } |
| 453 | 65 | artnetFailedAt = 0; | |
| 454 |
1/2✓ Branch 0 taken 65 times.
✗ Branch 1 not taken.
|
65 | SetArtNetPortWarning(warning); |
| 455 |
2/2✓ Branch 0 taken 64 times.
✓ Branch 1 taken 1 times.
|
65 | if (warning.empty()) { |
| 456 |
1/2✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
|
64 | LogDebug(VB_E131BRIDGE, "ArtNet socket open on UDP port 6454\n"); |
| 457 | } | ||
| 458 | 65 | artnetSock = artnetSockT; | |
| 459 | 65 | return artnetSock; | |
| 460 | 1041 | } | |
| 461 | |||
| 462 | 3668 | void ResetArtNetSocketFailure() { | |
| 463 | // A config reload may have removed whatever wanted ArtNet, and then | ||
| 464 | // nothing would ever retry and take the warning down. Forget the failure | ||
| 465 | // instead: anything that still needs the socket asks again straight away | ||
| 466 | // and raises the warning again if the port is still taken. | ||
| 467 |
1/2✓ Branch 0 taken 3668 times.
✗ Branch 1 not taken.
|
3668 | std::lock_guard<std::mutex> lock(artnetSocketMutex); |
| 468 |
2/2✓ Branch 0 taken 3621 times.
✓ Branch 1 taken 47 times.
|
3668 | if (artnetSock < 0) { |
| 469 | 3621 | artnetFailedAt = 0; | |
| 470 |
2/4✓ Branch 0 taken 3621 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3621 times.
✗ Branch 3 not taken.
|
7242 | SetArtNetPortWarning(""); |
| 471 | } | ||
| 472 | 3668 | } | |
| 473 | |||
| 474 | // Network/DMX input problems. Shares its id with the ArtNet port warning | ||
| 475 | // above; each message is stored where it is raised and retracted by the next | ||
| 476 | // reload of the config that produced it. | ||
| 477 | static constexpr int WARNING_ID_INPUT = 54; | ||
| 478 | |||
| 479 | // Total universe entries across every row of ci-universes.json. Each row is | ||
| 480 | // already held to 65536 (a universe number is 16 bits), but a hundred such | ||
| 481 | // rows built millions of entries -- hundreds of MB on a device with 512MB. | ||
| 482 | // 65536 is more than any real input config: every E1.31 universe. | ||
| 483 | static constexpr size_t MAX_INPUT_UNIVERSES = 65536; | ||
| 484 | static std::string universeCapWarning; | ||
| 485 | |||
| 486 | /* | ||
| 487 | * | ||
| 488 | */ | ||
| 489 | 2689 | bool LoadInputUniversesFromFile(void) { | |
| 490 | // The previous load's cap warning; raised again below if still true. | ||
| 491 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2689 times.
|
2689 | if (!universeCapWarning.empty()) { |
| 492 | ✗ | WarningHolder::RemoveWarning(WARNING_ID_INPUT, universeCapWarning); | |
| 493 | ✗ | universeCapWarning.clear(); | |
| 494 | } | ||
| 495 | // Built locally and swapped in under universesStructureLock at the end so | ||
| 496 | // an HTTP-thread stats reader never sees the vector mid-rebuild. | ||
| 497 | 2689 | std::vector<UniverseEntry> newUniverses; | |
| 498 | 2689 | bool truncated = false; | |
| 499 |
3/6✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2689 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2689 times.
✗ Branch 5 not taken.
|
2689 | std::string filename = FPP_DIR_CONFIG("/ci-universes.json"); |
| 500 | |||
| 501 |
1/2✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
|
2689 | LogDebug(VB_E131BRIDGE, "Opening File Now %s\n", filename.c_str()); |
| 502 | |||
| 503 |
3/4✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2584 times.
✓ Branch 3 taken 105 times.
|
2689 | if (!FileExists(filename)) { |
| 504 | // Normal on any player with no bridge input configured, which is most of | ||
| 505 | // them -- not an error. (ci-dmx.json below already treats its own | ||
| 506 | // absence this way.) | ||
| 507 |
1/2✓ Branch 0 taken 2584 times.
✗ Branch 1 not taken.
|
2584 | LogDebug(VB_E131BRIDGE, "Universe file %s does not exist\n", |
| 508 | filename.c_str()); | ||
| 509 | 2584 | return false; | |
| 510 | } | ||
| 511 | |||
| 512 |
1/2✓ Branch 0 taken 105 times.
✗ Branch 1 not taken.
|
105 | Json::Value root; |
| 513 |
3/4✓ Branch 0 taken 105 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 104 times.
|
105 | if (!LoadJsonFromFile(filename, root, JsonRoot::Object)) { |
| 514 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogErr(VB_E131BRIDGE, "Error parsing %s\n", filename.c_str()); |
| 515 | 1 | return false; | |
| 516 | } | ||
| 517 | |||
| 518 |
2/4✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 104 times.
✗ Branch 3 not taken.
|
104 | Json::Value outputs = root["channelInputs"]; |
| 519 | |||
| 520 | 104 | std::string type; | |
| 521 | 104 | int start = 0; | |
| 522 | 104 | int count = 0; | |
| 523 | |||
| 524 | 104 | bool enabled = false; | |
| 525 | // Every value comes out of a file a user or an API may have written with | ||
| 526 | // the wrong JSON type, and jsoncpp throws on those: an entry or a universe | ||
| 527 | // that can't be read is skipped (with a warning) instead of the exception | ||
| 528 | // reaching std::terminate during startup. | ||
| 529 |
3/4✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 103 times.
|
104 | if (!outputs.isArray()) { |
| 530 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | if (!outputs.isNull()) { |
| 531 |
3/6✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
4 | WarningHolder::InvalidConfigEntry("ci-universes.json", "channelInputs is not a list"); |
| 532 | } | ||
| 533 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | outputs = Json::Value(Json::arrayValue); |
| 534 | } | ||
| 535 |
3/4✓ Branch 0 taken 206 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 102 times.
✓ Branch 3 taken 104 times.
|
206 | for (int c = 0; c < outputs.size(); c++) { |
| 536 | try { | ||
| 537 |
1/2✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
|
102 | const Json::Value& o = outputs[c]; |
| 538 |
5/8✓ Branch 0 taken 101 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 101 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 101 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 101 times.
|
102 | if (o["type"].asString() != "universes") |
| 539 | ✗ | continue; | |
| 540 | |||
| 541 |
4/6✓ Branch 0 taken 101 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 100 times.
|
101 | if (o["enabled"].asInt() == 0) |
| 542 | ✗ | continue; | |
| 543 | |||
| 544 |
3/4✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 97 times.
|
100 | if (o.isMember("timeout")) { |
| 545 |
4/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 1 times.
|
3 | if (!o["timeout"].isNull()) { |
| 546 |
3/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | expireOffSet = o["timeout"].asInt(); |
| 547 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (expireOffSet < 10) { |
| 548 | ✗ | expireOffSet = 10; | |
| 549 | } | ||
| 550 | } | ||
| 551 | } | ||
| 552 | |||
| 553 |
2/4✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 99 times.
✗ Branch 3 not taken.
|
99 | Json::Value univs = o["universes"]; |
| 554 |
2/4✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 99 times.
|
99 | if (!univs.isArray()) { |
| 555 | ✗ | univs = Json::Value(Json::arrayValue); | |
| 556 | } | ||
| 557 | 99 | enabled = true; | |
| 558 |
3/4✓ Branch 0 taken 288 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✓ Branch 3 taken 99 times.
|
288 | for (int i = 0; i < univs.size(); i++) { |
| 559 | try { | ||
| 560 |
1/2✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
|
189 | const Json::Value& u = univs[i]; |
| 561 |
2/4✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
|
189 | int active = u["active"].asInt(); |
| 562 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 189 times.
|
189 | if (!active) { |
| 563 | ✗ | continue; | |
| 564 | } | ||
| 565 | // read everything before adding anything, so a bad field | ||
| 566 | // can't leave half a universe range behind | ||
| 567 |
2/4✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
|
189 | int universe = u["id"].asInt(); |
| 568 |
3/6✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 189 times.
✗ Branch 5 not taken.
|
189 | int count = u.get("universeCount", Json::Value(1)).asInt(); |
| 569 |
2/4✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
|
189 | int startChannel = u["startChannel"].asInt(); |
| 570 |
2/4✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
|
189 | int channelCount = u["channelCount"].asInt(); |
| 571 |
2/4✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
|
189 | int type = u["type"].asInt(); |
| 572 |
4/6✓ Branch 0 taken 98 times.
✓ Branch 1 taken 91 times.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 98 times.
✗ Branch 5 not taken.
|
189 | std::string address = type == 1 ? u["address"].asString() : std::string(); |
| 573 |
2/4✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 189 times.
✗ Branch 3 not taken.
|
189 | int priority = u["priority"].asInt(); |
| 574 | // universe numbers are 16 bits: a bigger count only built | ||
| 575 | // entries nothing can address (and a huge one, millions) | ||
| 576 |
1/2✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
|
189 | count = std::clamp(count, 0, 65536); |
| 577 |
2/4✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 189 times.
|
189 | if (type < 0 || type > 3) { |
| 578 | ✗ | continue; | |
| 579 | } | ||
| 580 |
2/2✓ Branch 0 taken 66807 times.
✓ Branch 1 taken 187 times.
|
66994 | for (int x = 0; x < count; ++x) { |
| 581 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 66805 times.
|
66807 | if (newUniverses.size() >= MAX_INPUT_UNIVERSES) { |
| 582 | 2 | truncated = true; | |
| 583 | 2 | break; | |
| 584 | } | ||
| 585 | 66805 | UniverseEntry entry; | |
| 586 | 66805 | entry.active = active; | |
| 587 | 66805 | entry.universe = universe + x; | |
| 588 | 66805 | entry.startAddress = startChannel; | |
| 589 | 66805 | entry.size = channelCount; | |
| 590 | 66805 | entry.type = type; | |
| 591 |
2/2✓ Branch 0 taken 66714 times.
✓ Branch 1 taken 91 times.
|
66805 | if (type == 1) { // UnicastAddress |
| 592 | 66714 | snprintf(entry.unicastAddress, sizeof(entry.unicastAddress), "%s", address.c_str()); | |
| 593 | } else { // Multicast, ArtNet | ||
| 594 | 91 | entry.unicastAddress[0] = 0; | |
| 595 | } | ||
| 596 | 66805 | entry.priority = priority; | |
| 597 | 66805 | startChannel += channelCount; | |
| 598 |
1/2✓ Branch 0 taken 66805 times.
✗ Branch 1 not taken.
|
66805 | newUniverses.push_back(entry); |
| 599 | 66805 | } | |
| 600 |
1/4✓ Branch 0 taken 189 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
189 | } catch (const std::exception& e) { |
| 601 | ✗ | WarningHolder::InvalidConfigEntry("ci-universes.json", e.what()); | |
| 602 | ✗ | } | |
| 603 | } | ||
| 604 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
102 | } catch (const std::exception& e) { |
| 605 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
9 | WarningHolder::InvalidConfigEntry("ci-universes.json", e.what()); |
| 606 | 3 | } | |
| 607 | } | ||
| 608 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 103 times.
|
104 | if (truncated) { |
| 609 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | universeCapWarning = "Channel Inputs: only the first " + std::to_string(MAX_INPUT_UNIVERSES) + |
| 610 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | " input universes are used; the rest of ci-universes.json is ignored"; |
| 611 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogWarn(VB_E131BRIDGE, "%s\n", universeCapWarning.c_str()); |
| 612 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | WarningHolder::AddWarning(WARNING_ID_INPUT, universeCapWarning); |
| 613 | } | ||
| 614 | |||
| 615 |
1/2✓ Branch 0 taken 104 times.
✗ Branch 1 not taken.
|
104 | std::lock_guard<std::mutex> lg(universesStructureLock); |
| 616 | 104 | InputUniverses = std::move(newUniverses); | |
| 617 | 104 | InputUniverseCount = InputUniverses.size(); | |
| 618 | 104 | return enabled; | |
| 619 | 2689 | } | |
| 620 | |||
| 621 | // Ranges written since the last CommitBridgeData(). A receive callback | ||
| 622 | // drains a burst of packets in one go; deferring the range bookkeeping to a | ||
| 623 | // single commit takes the sequence's range lock once per burst instead of | ||
| 624 | // once per packet. Every path that calls SetBridgeData must commit before | ||
| 625 | // returning to the epoll loop. | ||
| 626 | static std::vector<std::pair<uint32_t, uint32_t>> pendingBridgeRanges; | ||
| 627 | |||
| 628 | 68628 | inline void SetBridgeData(uint8_t* data, int startChannel, int len, long long packetTime) { | |
| 629 | 68628 | last_packet_time = packetTime; | |
| 630 | // Every received packet. Only status reads it ("bridging"), and nothing | ||
| 631 | // is published through it, so it needs no barriers. | ||
| 632 | 68628 | bridgeDataReceived.store(true, std::memory_order_relaxed); | |
| 633 |
2/2✓ Branch 0 taken 51440 times.
✓ Branch 1 taken 17188 times.
|
68628 | if (sequence->WriteBridgeData(data, startChannel, len)) { |
| 634 | 51440 | pendingBridgeRanges.emplace_back(startChannel, len); | |
| 635 | } | ||
| 636 | 68628 | } | |
| 637 | 52261 | inline void CommitBridgeData() { | |
| 638 |
2/2✓ Branch 0 taken 18912 times.
✓ Branch 1 taken 33349 times.
|
52261 | if (!pendingBridgeRanges.empty()) { |
| 639 | // Expiry is on the monotonic clock (as Sequence compares it). It was | ||
| 640 | // the packets' wall-clock time, so a clock stepping back kept stale | ||
| 641 | // bridge pixels over the sequence for as long as the step; and the | ||
| 642 | // serial-input path, whose time already included the timeout, got it | ||
| 643 | // added twice. | ||
| 644 | 18912 | sequence->CommitBridgeRanges(pendingBridgeRanges, GetMonotonicTimeMS() + expireOffSet); | |
| 645 | 18912 | pendingBridgeRanges.clear(); | |
| 646 | } | ||
| 647 | 52261 | } | |
| 648 | |||
| 649 | // Add or drop multicast-group membership for the 239.255.x.y address | ||
| 650 | // associated with an E1.31 universe across every non-loopback IPv4 | ||
| 651 | // interface. Op is IP_ADD_MEMBERSHIP or IP_DROP_MEMBERSHIP. | ||
| 652 | 2 | static void ChangeE131MulticastMembership(int universe, int op) { | |
| 653 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
|
2 | if (bridgeSock < 0 || universe <= 0) { |
| 654 | ✗ | return; | |
| 655 | } | ||
| 656 | struct ip_mreq mreq; | ||
| 657 | char strMulticastGroup[16]; | ||
| 658 | 2 | snprintf(strMulticastGroup, sizeof(strMulticastGroup), "239.255.%d.%d", | |
| 659 | universe / 256, universe % 256); | ||
| 660 | 2 | mreq.imr_multiaddr.s_addr = inet_addr(strMulticastGroup); | |
| 661 | |||
| 662 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | const char* action = (op == IP_ADD_MEMBERSHIP) ? "Adding" : "Removing"; |
| 663 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | LogInfo(VB_E131BRIDGE, "%s group %s\n", action, strMulticastGroup); |
| 664 | |||
| 665 | struct ifaddrs* interfaces; | ||
| 666 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (getifaddrs(&interfaces) < 0) { |
| 667 | ✗ | return; | |
| 668 | } | ||
| 669 | char address[16]; | ||
| 670 | 2 | address[0] = 0; | |
| 671 | 2 | int multicastJoined = 0; | |
| 672 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
|
12 | for (struct ifaddrs* tmp = interfaces; tmp; tmp = tmp->ifa_next) { |
| 673 |
3/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 6 times.
|
10 | if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET) { |
| 674 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | GetInterfaceAddress(tmp->ifa_name, address, NULL, NULL); |
| 675 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
|
4 | if (strcmp(address, "127.0.0.1")) { |
| 676 | 2 | mreq.imr_interface.s_addr = inet_addr(address); | |
| 677 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | if (setsockopt(bridgeSock, IPPROTO_IP, op, &mreq, sizeof(mreq)) < 0) { |
| 678 | ✗ | LogWarn(VB_E131BRIDGE, " %s multicast group %s failed on interface %s: %s\n", | |
| 679 | action, strMulticastGroup, tmp->ifa_name, FPPstrerror(errno)); | ||
| 680 | } | ||
| 681 | 2 | multicastJoined = 1; | |
| 682 | } | ||
| 683 | } | ||
| 684 | } | ||
| 685 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
2 | if (!multicastJoined && op == IP_ADD_MEMBERSHIP) { |
| 686 | ✗ | mreq.imr_interface.s_addr = htonl(INADDR_ANY); | |
| 687 | ✗ | if (setsockopt(bridgeSock, IPPROTO_IP, op, &mreq, sizeof(mreq)) < 0) { | |
| 688 | ✗ | LogWarn(VB_E131BRIDGE, " Could not setup Multicast Group %s on default interface\n", | |
| 689 | strMulticastGroup); | ||
| 690 | } | ||
| 691 | } | ||
| 692 | 2 | freeifaddrs(interfaces); | |
| 693 | } | ||
| 694 | |||
| 695 | /* | ||
| 696 | * Read data waiting for us | ||
| 697 | */ | ||
| 698 | 13811 | bool Bridge_ReceiveE131Data(void) { | |
| 699 | // LogExcess(VB_E131BRIDGE, "Bridge_ReceiveData()\n"); | ||
| 700 | 13811 | bool sync = false; | |
| 701 | 13811 | long long packetTime = GetTimeMS(); | |
| 702 | 13811 | int msgcnt = recvmmsg(bridgeSock, msgs, MAX_MSG, MSG_DONTWAIT, nullptr); | |
| 703 | 13811 | int batches = 1; | |
| 704 |
2/2✓ Branch 0 taken 14209 times.
✓ Branch 1 taken 13811 times.
|
28020 | while (msgcnt > 0) { |
| 705 |
2/2✓ Branch 0 taken 44831 times.
✓ Branch 1 taken 14209 times.
|
59040 | for (int x = 0; x < msgcnt; x++) { |
| 706 | 44831 | sync |= Bridge_StoreData((uint8_t*)buffers[x], packetTime, msgs[x].msg_len); | |
| 707 | } | ||
| 708 |
2/2✓ Branch 0 taken 14205 times.
✓ Branch 1 taken 4 times.
|
14209 | msgcnt = ++batches > MAX_BATCHES_PER_WAKEUP ? 0 : recvmmsg(bridgeSock, msgs, MAX_MSG, MSG_DONTWAIT, nullptr); |
| 709 | } | ||
| 710 | 13811 | CommitBridgeData(); | |
| 711 | 13811 | return sync; | |
| 712 | } | ||
| 713 | 4049 | bool Bridge_ReceiveDDPData(void) { | |
| 714 | // LogExcess(VB_E131BRIDGE, "Bridge_ReceiveData()\n"); | ||
| 715 | 4049 | int msgcnt = recvmmsg(ddpSock, msgs, MAX_MSG, MSG_DONTWAIT, nullptr); | |
| 716 | 4049 | int batches = 1; | |
| 717 | 4049 | bool sync = false; | |
| 718 | 4049 | long long packetTime = GetTimeMS(); | |
| 719 |
2/2✓ Branch 0 taken 4186 times.
✓ Branch 1 taken 4049 times.
|
8235 | while (msgcnt > 0) { |
| 720 |
2/2✓ Branch 0 taken 9791 times.
✓ Branch 1 taken 4186 times.
|
13977 | for (int x = 0; x < msgcnt; x++) { |
| 721 | 9791 | sync |= Bridge_StoreDDPData((uint8_t*)buffers[x], packetTime, msgs[x].msg_len); | |
| 722 | } | ||
| 723 |
1/2✓ Branch 0 taken 4186 times.
✗ Branch 1 not taken.
|
4186 | msgcnt = ++batches > MAX_BATCHES_PER_WAKEUP ? 0 : recvmmsg(ddpSock, msgs, MAX_MSG, MSG_DONTWAIT, nullptr); |
| 724 | } | ||
| 725 | 4049 | CommitBridgeData(); | |
| 726 | 4049 | return sync; | |
| 727 | } | ||
| 728 | 34317 | bool Bridge_ReceiveArtNetData(void) { | |
| 729 | 34317 | int msgcnt = recvmmsg(artnetSock, msgs, MAX_MSG, MSG_DONTWAIT, nullptr); | |
| 730 | 34317 | int batches = 1; | |
| 731 | 34317 | bool sync = false; | |
| 732 | 34317 | long long packetTime = GetTimeMS(); | |
| 733 |
2/2✓ Branch 0 taken 34412 times.
✓ Branch 1 taken 34317 times.
|
68729 | while (msgcnt > 0) { |
| 734 |
2/2✓ Branch 0 taken 35312 times.
✓ Branch 1 taken 34412 times.
|
69724 | for (int x = 0; x < msgcnt; x++) { |
| 735 | 35312 | uint8_t* bridgeBuffer = (uint8_t*)buffers[x]; | |
| 736 | // The buffers are reused, so bytes past msg_len are stale data | ||
| 737 | // from an earlier packet; too-short packets must not reach the | ||
| 738 | // signature/opcode checks at all. | ||
| 739 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35312 times.
|
35312 | if (msgs[x].msg_len < 12) { |
| 740 | 4 | continue; | |
| 741 | } | ||
| 742 |
10/18✓ Branch 0 taken 35312 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35312 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 35312 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 35312 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 35312 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 35312 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 35312 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 35312 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 4 times.
✓ Branch 17 taken 35308 times.
|
35312 | if (bridgeBuffer[0] != 'A' || bridgeBuffer[1] != 'r' || bridgeBuffer[2] != 't' || bridgeBuffer[3] != '-' || bridgeBuffer[4] != 'N' || bridgeBuffer[5] != 'e' || bridgeBuffer[6] != 't' || bridgeBuffer[7] != 0 || bridgeBuffer[11] != 0xE) { // version must be 14 |
| 743 | 4 | continue; | |
| 744 | } | ||
| 745 | 35308 | int opCode = (bridgeBuffer[9] << 8) | bridgeBuffer[8]; | |
| 746 |
1/2✓ Branch 0 taken 35308 times.
✗ Branch 1 not taken.
|
35308 | auto cb = ArtNetOpcodeHandlers.find(opCode); |
| 747 |
1/2✓ Branch 0 taken 35308 times.
✗ Branch 1 not taken.
|
35308 | if (cb != ArtNetOpcodeHandlers.end()) { |
| 748 | 35308 | currentArtNetSourceIP = inAddress[x].sin_addr.s_addr; | |
| 749 | 35308 | currentArtNetPacketLen = msgs[x].msg_len; | |
| 750 |
1/2✓ Branch 0 taken 35308 times.
✗ Branch 1 not taken.
|
35308 | sync |= cb->second(bridgeBuffer, packetTime); |
| 751 | } | ||
| 752 | } | ||
| 753 |
2/2✓ Branch 0 taken 34411 times.
✓ Branch 1 taken 1 times.
|
34412 | msgcnt = ++batches > MAX_BATCHES_PER_WAKEUP ? 0 : recvmmsg(artnetSock, msgs, MAX_MSG, MSG_DONTWAIT, nullptr); |
| 754 | } | ||
| 755 | 34317 | CommitBridgeData(); | |
| 756 | 34317 | return sync; | |
| 757 | } | ||
| 758 | |||
| 759 | // A bridge input port that can't be opened (another program already has it) | ||
| 760 | // leaves that input off with a warning; fppd used to exit(1) here, which on a | ||
| 761 | // reload of the input config took a running show down from the main loop, and | ||
| 762 | // systemd's restart then failed the same way. Each (re)initialization retracts | ||
| 763 | // what the last one raised, so the banner clears once the port is free and the | ||
| 764 | // input config is saved again or fppd restarts. | ||
| 765 | static constexpr int WARNING_ID_BRIDGE_PORT = 72; | ||
| 766 | static std::vector<std::string> bridgePortWarnings; | ||
| 767 | |||
| 768 | 3269 | static int OpenBridgeSocket(const char* what, int port, long packetsPerFrame) { | |
| 769 | 3269 | int sock = OpenSocket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0); | |
| 770 | 3269 | const char* step = "socket"; | |
| 771 |
1/2✓ Branch 0 taken 3269 times.
✗ Branch 1 not taken.
|
3269 | if (sock >= 0) { |
| 772 | struct sockaddr_in addr; | ||
| 773 | 3269 | memset((char*)&addr, 0, sizeof(addr)); | |
| 774 | 3269 | addr.sin_family = AF_INET; | |
| 775 | 3269 | addr.sin_addr.s_addr = htonl(INADDR_ANY); | |
| 776 | 3269 | addr.sin_port = htons(port); | |
| 777 |
2/2✓ Branch 0 taken 3266 times.
✓ Branch 1 taken 3 times.
|
3269 | if (bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == 0) { |
| 778 |
1/2✓ Branch 0 taken 3266 times.
✗ Branch 1 not taken.
|
3266 | SetBridgeReceiveBufferSize(sock, packetsPerFrame); |
| 779 | 3266 | return sock; | |
| 780 | } | ||
| 781 | 3 | step = "bind"; | |
| 782 | } | ||
| 783 | 3 | int err = errno; | |
| 784 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | LogErr(VB_E131BRIDGE, "e131bridge %s %s failed on UDP port %d: %s\n", what, step, port, FPPstrerror(err)); |
| 785 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | if (sock >= 0) { |
| 786 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | close(sock); |
| 787 | } | ||
| 788 |
3/6✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
|
9 | std::string msg = std::string(what) + " input is off: could not open UDP port " + std::to_string(port) + |
| 789 |
4/8✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
|
6 | " (" + FPPstrerror(err) + ")"; |
| 790 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | WarningHolder::AddWarning(WARNING_ID_BRIDGE_PORT, msg); |
| 791 |
1/2✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
|
3 | bridgePortWarnings.push_back(msg); |
| 792 | 3 | return -1; | |
| 793 | 3 | } | |
| 794 | |||
| 795 | 2689 | bool Bridge_Initialize_Internal(bool& hasArtNet) { | |
| 796 | 2689 | LogExcess(VB_E131BRIDGE, "Bridge_Initialize()\n"); | |
| 797 | |||
| 798 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2689 times.
|
2691 | for (const auto& w : bridgePortWarnings) { |
| 799 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | WarningHolder::RemoveWarning(WARNING_ID_BRIDGE_PORT, w); |
| 800 | } | ||
| 801 | 2689 | bridgePortWarnings.clear(); | |
| 802 | |||
| 803 | // prepare the msg receive buffers | ||
| 804 | 2689 | memset(msgs, 0, sizeof(msgs)); | |
| 805 |
2/2✓ Branch 0 taken 172096 times.
✓ Branch 1 taken 2689 times.
|
174785 | for (int i = 0; i < MAX_MSG; i++) { |
| 806 | 172096 | iovecs[i].iov_base = buffers[i]; | |
| 807 | 172096 | iovecs[i].iov_len = BUFSIZE; | |
| 808 | 172096 | msgs[i].msg_hdr.msg_iov = &iovecs[i]; | |
| 809 | 172096 | msgs[i].msg_hdr.msg_iovlen = 1; | |
| 810 | 172096 | msgs[i].msg_hdr.msg_namelen = sizeof(struct sockaddr_in); | |
| 811 | 172096 | msgs[i].msg_hdr.msg_name = &inAddress[i]; | |
| 812 | } | ||
| 813 | |||
| 814 | /* Initialize our Universe Index lookup caches */ | ||
| 815 |
2/2✓ Branch 0 taken 176226304 times.
✓ Branch 1 taken 2689 times.
|
176228993 | for (auto& c : E131UniverseCache) { |
| 816 | 176226304 | c = BRIDGE_INVALID_UNIVERSE_INDEX; | |
| 817 | } | ||
| 818 |
2/2✓ Branch 0 taken 88113152 times.
✓ Branch 1 taken 2689 times.
|
88115841 | for (auto& c : ArtNetUniverseCache) { |
| 819 | 88113152 | c = BRIDGE_INVALID_UNIVERSE_INDEX; | |
| 820 | } | ||
| 821 | |||
| 822 | 2689 | bool enabled = LoadInputUniversesFromFile(); | |
| 823 | 2689 | hasUDP = enabled; | |
| 824 | 2689 | bool disableFakeBridges = getSettingInt("DisableFakeNetworkBridges"); | |
| 825 | |||
| 826 | 2689 | LogInfo(VB_E131BRIDGE, "Universe Count = %d\n", InputUniverseCount); | |
| 827 | 2689 | InputUniversesPrint(); | |
| 828 | |||
| 829 |
4/4✓ Branch 0 taken 2590 times.
✓ Branch 1 taken 99 times.
✓ Branch 2 taken 1537 times.
✓ Branch 3 taken 1053 times.
|
2689 | if (enabled || !disableFakeBridges) { |
| 830 | 1636 | ddpSock = OpenBridgeSocket("DDP", DDP_PORT, DDPPacketsPerFrame()); | |
| 831 | } | ||
| 832 | |||
| 833 | 2689 | hasArtNet = false; | |
| 834 | 2689 | bool hase131 = false; | |
| 835 |
2/2✓ Branch 0 taken 99 times.
✓ Branch 1 taken 2590 times.
|
2689 | if (enabled) { |
| 836 |
2/2✓ Branch 0 taken 66805 times.
✓ Branch 1 taken 99 times.
|
66904 | for (int i = 0; i < InputUniverseCount; i++) { |
| 837 |
5/6✓ Branch 0 taken 66805 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 66714 times.
✓ Branch 3 taken 91 times.
✓ Branch 4 taken 66714 times.
✓ Branch 5 taken 91 times.
|
66805 | if (InputUniverses[i].type == E131_TYPE_MULTICAST || InputUniverses[i].type == E131_TYPE_UNICAST) { |
| 838 | 66714 | hase131 = true; | |
| 839 |
3/6✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 91 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 91 times.
✗ Branch 5 not taken.
|
91 | } else if (InputUniverses[i].type == ARTNET_TYPE_BROADCAST || InputUniverses[i].type == ARTNET_TYPE_UNICAST) { |
| 840 | 91 | hasArtNet = true; | |
| 841 | } | ||
| 842 | } | ||
| 843 | } | ||
| 844 | |||
| 845 |
4/4✓ Branch 0 taken 2593 times.
✓ Branch 1 taken 96 times.
✓ Branch 2 taken 1537 times.
✓ Branch 3 taken 1056 times.
|
2689 | if (hase131 || !disableFakeBridges) { |
| 846 | int UniverseOctet[2]; | ||
| 847 | struct ip_mreq mreq; | ||
| 848 | char strMulticastGroup[16]; | ||
| 849 |
1/2✓ Branch 0 taken 1633 times.
✗ Branch 1 not taken.
|
1633 | bridgeSock = OpenBridgeSocket("E1.31", E131_DEST_PORT, InputUniverseCount); |
| 850 | |||
| 851 | // get all the addresses | ||
| 852 | struct ifaddrs *interfaces, *tmp; | ||
| 853 | 1633 | getifaddrs(&interfaces); | |
| 854 | |||
| 855 | char address[16]; | ||
| 856 | 1633 | address[0] = 0; | |
| 857 | // Join the multicast groups (none without a socket to join them on) | ||
| 858 |
4/4✓ Branch 0 taken 68431 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 66800 times.
✓ Branch 3 taken 1631 times.
|
68433 | for (int i = 0; bridgeSock >= 0 && i < InputUniverseCount; i++) { |
| 859 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66800 times.
|
66800 | if (InputUniverses[i].type == E131_TYPE_MULTICAST) { |
| 860 | ✗ | UniverseOctet[0] = InputUniverses[i].universe / 256; | |
| 861 | ✗ | UniverseOctet[1] = InputUniverses[i].universe % 256; | |
| 862 | ✗ | snprintf(strMulticastGroup, sizeof(strMulticastGroup), "239.255.%d.%d", UniverseOctet[0], UniverseOctet[1]); | |
| 863 | ✗ | mreq.imr_multiaddr.s_addr = inet_addr(strMulticastGroup); | |
| 864 | |||
| 865 | ✗ | LogInfo(VB_E131BRIDGE, "Adding group %s\n", strMulticastGroup); | |
| 866 | |||
| 867 | // add group to groups to listen for on eth0 and wlan0 if it exists | ||
| 868 | ✗ | int multicastJoined = 0; | |
| 869 | ✗ | tmp = interfaces; | |
| 870 | // loop through all the interfaces and subscribe to the group | ||
| 871 | ✗ | while (tmp) { | |
| 872 | // struct sockaddr_in *sin = (struct sockaddr_in *)tmp->ifa_addr; | ||
| 873 | // strcpy(address, inet_ntoa(sin->sin_addr)); | ||
| 874 | ✗ | if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET) { | |
| 875 | ✗ | GetInterfaceAddress(tmp->ifa_name, address, NULL, NULL); | |
| 876 | ✗ | if (strcmp(address, "127.0.0.1")) { | |
| 877 | ✗ | LogDebug(VB_E131BRIDGE, " Adding interface %s - %s\n", tmp->ifa_name, address); | |
| 878 | ✗ | mreq.imr_interface.s_addr = inet_addr(address); | |
| 879 | ✗ | if (setsockopt(bridgeSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { | |
| 880 | ✗ | LogWarn(VB_E131BRIDGE, " Could not setup Multicast Group for interface %s\n", tmp->ifa_name); | |
| 881 | } | ||
| 882 | ✗ | multicastJoined = 1; | |
| 883 | } | ||
| 884 | ✗ | } else if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET6) { | |
| 885 | // FIXME for ipv6 multicast | ||
| 886 | // LogDebug(VB_E131BRIDGE, " Inet6 interface %s\n", tmp->ifa_name); | ||
| 887 | } | ||
| 888 | ✗ | tmp = tmp->ifa_next; | |
| 889 | } | ||
| 890 | |||
| 891 | ✗ | if (!multicastJoined) { | |
| 892 | ✗ | LogDebug(VB_E131BRIDGE, " Binding to default interface\n"); | |
| 893 | ✗ | mreq.imr_interface.s_addr = htonl(INADDR_ANY); | |
| 894 | ✗ | if (setsockopt(bridgeSock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) { | |
| 895 | ✗ | LogWarn(VB_E131BRIDGE, " Could not setup Multicast Group\n"); | |
| 896 | } | ||
| 897 | } | ||
| 898 | } | ||
| 899 | } | ||
| 900 | 1633 | freeifaddrs(interfaces); | |
| 901 | } | ||
| 902 | |||
| 903 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 2599 times.
|
2689 | if (hasArtNet) { |
| 904 | 90 | CreateArtNetSocket(); | |
| 905 | } | ||
| 906 | |||
| 907 | 2689 | return enabled; | |
| 908 | } | ||
| 909 | |||
| 910 | 5309 | static void removeMulticastGroups() { | |
| 911 |
2/2✓ Branch 0 taken 66802 times.
✓ Branch 1 taken 5309 times.
|
72111 | for (int i = 0; i < InputUniverseCount; i++) { |
| 912 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66802 times.
|
66802 | if (InputUniverses[i].type == E131_TYPE_MULTICAST) { |
| 913 | ✗ | ChangeE131MulticastMembership(InputUniverses[i].universe, IP_DROP_MEMBERSHIP); | |
| 914 | } | ||
| 915 | } | ||
| 916 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5309 times.
|
5310 | for (int u : joinedSyncUniverses) { |
| 917 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ChangeE131MulticastMembership(u, IP_DROP_MEMBERSHIP); |
| 918 | } | ||
| 919 | 5309 | joinedSyncUniverses.clear(); | |
| 920 | 5309 | syncUniverseCapLogged = false; | |
| 921 | 5309 | } | |
| 922 | |||
| 923 | 44831 | bool Bridge_StoreData(uint8_t* bridgeBuffer, long long packetTime, int msgLen) { | |
| 924 | // The receive buffers are reused across packets, so anything beyond | ||
| 925 | // msgLen is stale data from an earlier packet. Never interpret it. | ||
| 926 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 44831 times.
|
44831 | if (msgLen <= E131_VECTOR_INDEX) { |
| 927 | ✗ | e131Errors++; | |
| 928 | ✗ | return false; | |
| 929 | } | ||
| 930 |
4/4✓ Branch 0 taken 44830 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 44230 times.
✓ Branch 3 taken 600 times.
|
44831 | if ((bridgeBuffer[E131_VECTOR_INDEX] == VECTOR_ROOT_E131_DATA) && |
| 931 | 44230 | (msgLen >= E131_HEADER_LENGTH) && | |
| 932 |
1/2✓ Branch 0 taken 44230 times.
✗ Branch 1 not taken.
|
44230 | (bridgeBuffer[E131_START_CODE] == 0x00)) { |
| 933 | 44230 | uint32_t universe = ((int)bridgeBuffer[E131_UNIVERSE_INDEX] << 8) + bridgeBuffer[E131_UNIVERSE_INDEX + 1]; | |
| 934 | |||
| 935 | // If the sender advertises a sync universe, make sure we're subscribed | ||
| 936 | // to its multicast group so the sync packets reach us. Data is still | ||
| 937 | // applied immediately; this only ensures the sync counter updates and | ||
| 938 | // sets the stage for any future buffered-until-sync handling. | ||
| 939 | 44230 | int syncUniverse = ((int)bridgeBuffer[E131_SYNC_ADDRESS_INDEX] << 8) + | |
| 940 | 44230 | bridgeBuffer[E131_SYNC_ADDRESS_INDEX + 1]; | |
| 941 | 88462 | if (syncUniverse > 0 && | |
| 942 |
6/8✓ Branch 0 taken 2 times.
✓ Branch 1 taken 44228 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 44229 times.
|
44232 | Bridge_GetIndexFromUniverseNumber(syncUniverse, false) == BRIDGE_INVALID_UNIVERSE_INDEX && |
| 943 |
3/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | !joinedSyncUniverses.contains(syncUniverse)) { |
| 944 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (joinedSyncUniverses.size() < MAX_JOINED_SYNC_UNIVERSES) { |
| 945 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | joinedSyncUniverses.insert(syncUniverse); |
| 946 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ChangeE131MulticastMembership(syncUniverse, IP_ADD_MEMBERSHIP); |
| 947 | ✗ | } else if (!syncUniverseCapLogged) { | |
| 948 | ✗ | syncUniverseCapLogged = true; | |
| 949 | ✗ | LogWarn(VB_E131BRIDGE, "Not joining E1.31 sync universe %d: already joined %d sync universes\n", | |
| 950 | syncUniverse, (int)MAX_JOINED_SYNC_UNIVERSES); | ||
| 951 | } | ||
| 952 | } | ||
| 953 | |||
| 954 |
1/2✓ Branch 0 taken 44230 times.
✗ Branch 1 not taken.
|
44230 | uint32_t universeIndex = Bridge_GetIndexFromUniverseNumber(universe, false); |
| 955 |
2/2✓ Branch 0 taken 42559 times.
✓ Branch 1 taken 1671 times.
|
44230 | if (universeIndex != BRIDGE_INVALID_UNIVERSE_INDEX) { |
| 956 | 42559 | bool sourceJustSwitched = false; | |
| 957 |
2/2✓ Branch 0 taken 256 times.
✓ Branch 1 taken 42303 times.
|
42559 | if (sourcePriorityEnabled.load(std::memory_order_relaxed)) { |
| 958 | uint8_t sourceId[16]; | ||
| 959 | 256 | memcpy(sourceId, &bridgeBuffer[E131_CID_INDEX], E131_CID_LENGTH); | |
| 960 |
3/4✓ Branch 0 taken 256 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 120 times.
✓ Branch 3 taken 136 times.
|
256 | if (!EvaluateSource(InputUniverses[universeIndex], sourceId, |
| 961 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
256 | bridgeBuffer[E131_PRIORITY_INDEX], |
| 962 | sourceJustSwitched)) { | ||
| 963 | 120 | return false; | |
| 964 | } | ||
| 965 | } | ||
| 966 | |||
| 967 | 42439 | uint32_t sn = bridgeBuffer[E131_SEQUENCE_INDEX]; | |
| 968 |
6/6✓ Branch 0 taken 42435 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 37299 times.
✓ Branch 3 taken 5136 times.
✓ Branch 4 taken 37299 times.
✓ Branch 5 taken 5140 times.
|
42439 | if (!sourceJustSwitched && StatLoad(InputUniverses[universeIndex].packetsReceived) != 0) { |
| 969 |
2/2✓ Branch 0 taken 67 times.
✓ Branch 1 taken 37232 times.
|
37299 | if (StatLoad(InputUniverses[universeIndex].lastSequenceNumber) == 255) { |
| 970 | // some wrap from 255 -> 1 and some from 255 -> 0, spec doesn't say which | ||
| 971 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 67 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
67 | if (sn != 0 && sn != 1) { |
| 972 | ✗ | StatAdd(InputUniverses[universeIndex].errorPackets, 1); | |
| 973 | } | ||
| 974 |
2/2✓ Branch 0 taken 18094 times.
✓ Branch 1 taken 19138 times.
|
37232 | } else if ((StatLoad(InputUniverses[universeIndex].lastSequenceNumber) + 1) != sn) { |
| 975 | 18094 | StatAdd(InputUniverses[universeIndex].errorPackets, 1); | |
| 976 | } | ||
| 977 | } | ||
| 978 | 42439 | StatStore(InputUniverses[universeIndex].lastSequenceNumber, sn); | |
| 979 | |||
| 980 | // Only store what the packet actually carries: the smaller of the | ||
| 981 | // configured universe size, the bytes physically received, and the | ||
| 982 | // DMP property count (which includes the start code). Copying the | ||
| 983 | // configured size regardless (as this used to) put stale bytes | ||
| 984 | // from a previous packet on the wire whenever a packet was short. | ||
| 985 | 42439 | uint32_t dataLen = InputUniverses[universeIndex].size; | |
| 986 | 42439 | dataLen = std::min(dataLen, (uint32_t)(msgLen - E131_HEADER_LENGTH)); | |
| 987 | 42439 | uint32_t propCount = ((uint32_t)bridgeBuffer[E131_COUNT_INDEX] << 8) | bridgeBuffer[E131_COUNT_INDEX + 1]; | |
| 988 |
2/2✓ Branch 0 taken 42139 times.
✓ Branch 1 taken 300 times.
|
42439 | if (propCount > 0) { |
| 989 | 42139 | dataLen = std::min(dataLen, propCount - 1); | |
| 990 | } | ||
| 991 | 84878 | SetBridgeData(&bridgeBuffer[E131_HEADER_LENGTH], | |
| 992 |
1/2✓ Branch 0 taken 42439 times.
✗ Branch 1 not taken.
|
42439 | InputUniverses[universeIndex].startAddress - 1, |
| 993 | dataLen, | ||
| 994 | packetTime); | ||
| 995 | 42439 | StatAdd(InputUniverses[universeIndex].bytesReceived, dataLen); | |
| 996 | 42439 | StatAdd(InputUniverses[universeIndex].packetsReceived, 1); | |
| 997 | } else { | ||
| 998 | 1671 | StatAdd(unknownUniverse.packetsReceived, 1); | |
| 999 | 1671 | uint32_t len = bridgeBuffer[16] & 0xF; | |
| 1000 | 1671 | len <<= 8; | |
| 1001 | 1671 | len += bridgeBuffer[17]; | |
| 1002 | 1671 | StatAdd(unknownUniverse.bytesReceived, len); | |
| 1003 | // Per packet; unknownUniverse already counts these. | ||
| 1004 |
1/2✓ Branch 0 taken 1671 times.
✗ Branch 1 not taken.
|
1671 | LogExcess(VB_E131BRIDGE, "Received e1.31 data packet for unconfigured universe %d\n", universe); |
| 1005 | } | ||
| 1006 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 600 times.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
44711 | } else if (bridgeBuffer[E131_VECTOR_INDEX] == VECTOR_ROOT_E131_EXTENDED && |
| 1007 | msgLen > E131_EXTENDED_PACKET_TYPE_INDEX) { | ||
| 1008 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (bridgeBuffer[E131_EXTENDED_PACKET_TYPE_INDEX] == VECTOR_E131_EXTENDED_SYNCHRONIZATION) { |
| 1009 | 1 | e131SyncPackets++; | |
| 1010 | 1 | return true; | |
| 1011 | } | ||
| 1012 | ✗ | e131Errors++; | |
| 1013 | ✗ | LogDebug(VB_E131BRIDGE, "Unknown e1.31 extended packet type %d\n", (int)bridgeBuffer[E131_EXTENDED_PACKET_TYPE_INDEX]); | |
| 1014 | } else { | ||
| 1015 | 600 | e131Errors++; | |
| 1016 | 600 | LogDebug(VB_E131BRIDGE, "Unknown e1.31 packet type %d, start code %d\n", (int)bridgeBuffer[E131_VECTOR_INDEX], (int)bridgeBuffer[E131_START_CODE]); | |
| 1017 | } | ||
| 1018 | 44710 | return false; | |
| 1019 | } | ||
| 1020 | |||
| 1021 | 15964 | bool Bridge_HandleArtNetSync(uint8_t* bridgeBuffer, long long packetTime) { | |
| 1022 | // sync packet | ||
| 1023 | 15964 | return true; | |
| 1024 | } | ||
| 1025 | 19334 | bool Bridge_StoreArtNetData(uint8_t* bridgeBuffer, long long packetTime) { | |
| 1026 |
2/4✓ Branch 0 taken 19334 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19334 times.
✗ Branch 3 not taken.
|
19334 | if (bridgeBuffer[9] == 0x50 && bridgeBuffer[8] == 0x00) { |
| 1027 | // data packet; 18 byte ArtDMX header, then the channel data | ||
| 1028 |
2/2✓ Branch 0 taken 300 times.
✓ Branch 1 taken 19034 times.
|
19334 | if (currentArtNetPacketLen < 18) { |
| 1029 | 300 | return false; | |
| 1030 | } | ||
| 1031 | 19034 | uint32_t sn = bridgeBuffer[12]; | |
| 1032 | |||
| 1033 | 19034 | uint32_t univ = bridgeBuffer[15]; | |
| 1034 | 19034 | univ <<= 8; | |
| 1035 | 19034 | univ &= 0x7F00; | |
| 1036 | 19034 | univ |= bridgeBuffer[14]; | |
| 1037 | |||
| 1038 | 19034 | uint32_t len = bridgeBuffer[16]; | |
| 1039 | 19034 | len <<= 8; | |
| 1040 | 19034 | len &= 0x7F00; | |
| 1041 | 19034 | len += bridgeBuffer[17]; | |
| 1042 | // never trust the header's length beyond what actually arrived | ||
| 1043 | 19034 | len = std::min(len, (uint32_t)(currentArtNetPacketLen - 18)); | |
| 1044 |
1/2✓ Branch 0 taken 19034 times.
✗ Branch 1 not taken.
|
19034 | uint32_t universeIndex = Bridge_GetIndexFromUniverseNumber(univ, true); |
| 1045 |
2/2✓ Branch 0 taken 18436 times.
✓ Branch 1 taken 598 times.
|
19034 | if (universeIndex != BRIDGE_INVALID_UNIVERSE_INDEX) { |
| 1046 | 18436 | bool sourceJustSwitched = false; | |
| 1047 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18436 times.
|
18436 | if (sourcePriorityEnabled.load(std::memory_order_relaxed)) { |
| 1048 | // ArtNet has no priority field in ArtDMX; key on source IP | ||
| 1049 | // and use a constant priority so all sources tie. The helper | ||
| 1050 | // then reduces to first-source-wins with timeout failover. | ||
| 1051 | ✗ | uint8_t sourceId[16] = {}; | |
| 1052 | ✗ | memcpy(sourceId, ¤tArtNetSourceIP, sizeof(currentArtNetSourceIP)); | |
| 1053 | ✗ | if (!EvaluateSource(InputUniverses[universeIndex], sourceId, | |
| 1054 | 100, sourceJustSwitched)) { | ||
| 1055 | ✗ | return false; | |
| 1056 | } | ||
| 1057 | } | ||
| 1058 | |||
| 1059 |
5/6✓ Branch 0 taken 18436 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16398 times.
✓ Branch 3 taken 2038 times.
✓ Branch 4 taken 16398 times.
✓ Branch 5 taken 2038 times.
|
18436 | if (!sourceJustSwitched && StatLoad(InputUniverses[universeIndex].packetsReceived) != 0) { |
| 1060 |
2/2✓ Branch 0 taken 63 times.
✓ Branch 1 taken 16335 times.
|
16398 | if (StatLoad(InputUniverses[universeIndex].lastSequenceNumber) == 255) { |
| 1061 | // some wrap from 255 -> 1 and some from 255 -> 0 | ||
| 1062 |
3/4✓ Branch 0 taken 62 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
|
63 | if (sn != 0 && sn != 1) { |
| 1063 | ✗ | StatAdd(InputUniverses[universeIndex].errorPackets, 1); | |
| 1064 | } | ||
| 1065 |
2/2✓ Branch 0 taken 300 times.
✓ Branch 1 taken 16035 times.
|
16335 | } else if ((StatLoad(InputUniverses[universeIndex].lastSequenceNumber) + 1) != sn) { |
| 1066 | 300 | StatAdd(InputUniverses[universeIndex].errorPackets, 1); | |
| 1067 | } | ||
| 1068 | } | ||
| 1069 | 18436 | StatStore(InputUniverses[universeIndex].lastSequenceNumber, sn); | |
| 1070 | 18436 | StatAdd(InputUniverses[universeIndex].bytesReceived, std::min(InputUniverses[universeIndex].size, len)); | |
| 1071 | 18436 | StatAdd(InputUniverses[universeIndex].packetsReceived, 1); | |
| 1072 | |||
| 1073 | 36872 | SetBridgeData(&bridgeBuffer[18], | |
| 1074 |
1/2✓ Branch 0 taken 18436 times.
✗ Branch 1 not taken.
|
18436 | InputUniverses[universeIndex].startAddress - 1, |
| 1075 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
18436 | std::min(InputUniverses[universeIndex].size, len), |
| 1076 | packetTime); | ||
| 1077 | |||
| 1078 | } else { | ||
| 1079 | 598 | StatAdd(unknownUniverse.packetsReceived, 1); | |
| 1080 | // len already holds the ArtDMX data length (15-bit field), clamped | ||
| 1081 | // to what was actually received. | ||
| 1082 | 598 | StatAdd(unknownUniverse.bytesReceived, len); | |
| 1083 | // Per packet; unknownUniverse already counts these. | ||
| 1084 |
1/2✓ Branch 0 taken 598 times.
✗ Branch 1 not taken.
|
598 | LogExcess(VB_E131BRIDGE, "Received ArtNet data packet for unconfigured universe %d\n", univ); |
| 1085 | } | ||
| 1086 | } | ||
| 1087 | 19034 | return false; | |
| 1088 | } | ||
| 1089 | 4 | bool Bridge_HandleArtNetPoll(uint8_t* bridgeBuffer, long long packetTime) { | |
| 1090 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | if (bridgeBuffer[9] == 0x20 && bridgeBuffer[8] == 0x00) { |
| 1091 | // ArtNet Poll, need to send a reply | ||
| 1092 | char buf[512]; | ||
| 1093 | 4 | memset(buf, 0, sizeof(buf)); | |
| 1094 | 4 | strcpy(buf, "Art-Net"); | |
| 1095 | 4 | buf[9] = 0x21; // PollReply | |
| 1096 | 4 | buf[10] = 0; // IP | |
| 1097 | 4 | buf[11] = 0; | |
| 1098 | 4 | buf[12] = 0; | |
| 1099 | 4 | buf[13] = 0; | |
| 1100 | 4 | buf[14] = 0x36; // port | |
| 1101 | 4 | buf[15] = 0x19; | |
| 1102 | |||
| 1103 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | buf[16] = std::atoi(getFPPMajorVersion()); |
| 1104 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | buf[17] = std::atoi(getFPPMinorVersion()); |
| 1105 | |||
| 1106 | 4 | buf[18] = 0; // universes? | |
| 1107 | 4 | buf[19] = 0; | |
| 1108 | |||
| 1109 | 4 | buf[20] = 0; // OEM value? | |
| 1110 | 4 | buf[21] = 0; | |
| 1111 | |||
| 1112 | 4 | buf[23] = 0; // status1 | |
| 1113 | |||
| 1114 | 4 | buf[24] = 0; // ESTA | |
| 1115 | 4 | buf[25] = 0; | |
| 1116 | |||
| 1117 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | std::string hostname = getSetting("HostName"); |
| 1118 | |||
| 1119 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4 | if (hostname == "") { |
| 1120 | ✗ | hostname = "FPP"; | |
| 1121 | } | ||
| 1122 | // Zero the fields first so snprintf's truncation doesn't leave stale bytes | ||
| 1123 | // from a previous packet, then bounded-copy. | ||
| 1124 | 4 | memset(&buf[26], 0, 18); | |
| 1125 | 4 | memset(&buf[44], 0, 64); | |
| 1126 | 4 | memset(&buf[108], 0, 64); | |
| 1127 | // Bounded copy — HostName is user-controlled via /api/settings and could be up to 255 chars. | ||
| 1128 | // Original strcpy could overflow buf[512] (18 bytes at 26, 64 bytes at 44). snprintf truncates safely. | ||
| 1129 | 4 | snprintf(&buf[26], 18, "%s", hostname.c_str()); // HOSTNAME (18 bytes) | |
| 1130 | 4 | snprintf(&buf[44], 64, "%s", hostname.c_str()); // Description (64 bytes) | |
| 1131 | // buf[108] Status stays empty — memset already zeroed it, no snprintf needed | ||
| 1132 | |||
| 1133 | // ArtPollReply: advertise the ArtNet input universes actually configured. | ||
| 1134 | // Previously this was hardcoded to 4 ports on universe 0 (all SwIn 0), | ||
| 1135 | // so a controller polling FPP always saw universe 0 regardless of | ||
| 1136 | // Settings > Channel Inputs (issue #2927). Populate from InputUniverses | ||
| 1137 | // where type is ArtNet. Non-breaking: packet stays 240 bytes, IP/port/ | ||
| 1138 | // version/hostname unchanged — only the 16 universe-advertising bytes | ||
| 1139 | // (172-193) now reflect configuration. Capped at 4 ports per spec. | ||
| 1140 | 4 | std::vector<uint32_t> artNetUniverses; | |
| 1141 | { | ||
| 1142 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | std::lock_guard<std::mutex> lg(universesStructureLock); |
| 1143 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | for (auto &ue : InputUniverses) { |
| 1144 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | if (ue.type == ARTNET_TYPE_BROADCAST || ue.type == ARTNET_TYPE_UNICAST) { |
| 1145 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | artNetUniverses.push_back(ue.universe); |
| 1146 | } | ||
| 1147 | } | ||
| 1148 | 4 | } | |
| 1149 | 4 | int numPorts = std::min<int>((int)artNetUniverses.size(), 4); | |
| 1150 | // Preserve historical big-endian NumPorts encoding (0,4 = 4 ports). | ||
| 1151 | 4 | buf[172] = 0; | |
| 1152 | 4 | buf[173] = (char)numPorts; | |
| 1153 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
|
20 | for (int i = 0; i < 4; ++i) { |
| 1154 | 16 | bool active = (i < numPorts); | |
| 1155 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 11 times.
|
16 | buf[174 + i] = active ? (char)0xc0 : 0; // PortTypes: DMX512 |
| 1156 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 11 times.
|
16 | buf[178 + i] = active ? (char)0x08 : 0; // GoodInput: port enabled |
| 1157 | 16 | buf[182 + i] = 0; // GoodOutput: no ArtNet outputs | |
| 1158 | // SwIn: low 8 bits of PortAddress (exact for 0-255, best-effort >255, | ||
| 1159 | // far better than always-0). SwOut unused (bridge is input-only). | ||
| 1160 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 11 times.
|
16 | buf[186 + i] = active ? (char)(artNetUniverses[i] & 0xFF) : 0; |
| 1161 | 16 | buf[190 + i] = 0; | |
| 1162 | } | ||
| 1163 | |||
| 1164 | char addressBuf[128]; | ||
| 1165 | // get all the addresses | ||
| 1166 | struct ifaddrs *interfaces, *tmp; | ||
| 1167 | 4 | getifaddrs(&interfaces); | |
| 1168 | 4 | tmp = interfaces; | |
| 1169 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 4 times.
|
28 | while (tmp) { |
| 1170 |
3/4✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 14 times.
|
24 | if (tmp->ifa_addr && tmp->ifa_addr->sa_family == AF_INET) { |
| 1171 | // Check if interface is UP and RUNNING before sending ArtNet poll response | ||
| 1172 |
4/6✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
|
10 | if (strncmp("usb", tmp->ifa_name, 3) != 0 && strncmp("lo", tmp->ifa_name, 2) != 0 && tmp->ifa_addr && |
| 1173 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
6 | (tmp->ifa_flags & IFF_UP) && (tmp->ifa_flags & IFF_RUNNING)) { |
| 1174 | 4 | struct sockaddr_in* sain = (struct sockaddr_in*)tmp->ifa_addr; | |
| 1175 | 4 | unsigned long s_addr = sain->sin_addr.s_addr; | |
| 1176 | 4 | buf[13] = s_addr >> 24; // IP | |
| 1177 | 4 | buf[12] = s_addr >> 16; | |
| 1178 | 4 | buf[11] = s_addr >> 8; | |
| 1179 | 4 | buf[10] = s_addr & 0xFF; | |
| 1180 | |||
| 1181 | struct sockaddr_in s; | ||
| 1182 | 4 | memset(&s, '\0', sizeof(struct sockaddr_in)); | |
| 1183 | 4 | s.sin_family = AF_INET; | |
| 1184 | 4 | s.sin_port = (in_port_t)htons(0x1936); | |
| 1185 | 4 | s.sin_addr.s_addr = htonl(INADDR_BROADCAST); | |
| 1186 |
1/2✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
|
4 | sendto(artnetSock, buf, 240, 0, (struct sockaddr*)&s, sizeof(struct sockaddr_in)); |
| 1187 | } | ||
| 1188 | } | ||
| 1189 | 24 | tmp = tmp->ifa_next; | |
| 1190 | } | ||
| 1191 | 4 | freeifaddrs(interfaces); | |
| 1192 | 4 | } | |
| 1193 | 4 | return false; | |
| 1194 | } | ||
| 1195 | 9791 | bool Bridge_StoreDDPData(uint8_t* bridgeBuffer, long long packetTime, int msgLen) { | |
| 1196 | 9791 | bool push = false; | |
| 1197 | // The receive buffers are reused, so bytes past msgLen are stale data | ||
| 1198 | // from an earlier packet. A malformed packet must not force an output | ||
| 1199 | // cycle either, so error paths return false rather than a push flag | ||
| 1200 | // read from garbage. | ||
| 1201 |
2/2✓ Branch 0 taken 300 times.
✓ Branch 1 taken 9491 times.
|
9791 | if (msgLen < 4) { |
| 1202 | 300 | ddpErrors++; | |
| 1203 | 300 | return false; | |
| 1204 | } | ||
| 1205 |
2/2✓ Branch 0 taken 9191 times.
✓ Branch 1 taken 300 times.
|
9491 | if (bridgeBuffer[3] == 1) { |
| 1206 | 9191 | ddpPacketsReceived++; | |
| 1207 | 9191 | bool tc = bridgeBuffer[0] & DDP_TIMECODE_FLAG; | |
| 1208 | 9191 | push = bridgeBuffer[0] & DDP_PUSH_FLAG; | |
| 1209 | |||
| 1210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9191 times.
|
9191 | int ddpOffset = tc ? 14 : 10; |
| 1211 |
2/2✓ Branch 0 taken 300 times.
✓ Branch 1 taken 8891 times.
|
9191 | if (msgLen < ddpOffset) { |
| 1212 | 300 | ddpErrors++; | |
| 1213 | 300 | return false; | |
| 1214 | } | ||
| 1215 | |||
| 1216 | 8891 | uint32_t chan = bridgeBuffer[4]; | |
| 1217 | 8891 | chan <<= 8; | |
| 1218 | 8891 | chan += bridgeBuffer[5]; | |
| 1219 | 8891 | chan <<= 8; | |
| 1220 | 8891 | chan += bridgeBuffer[6]; | |
| 1221 | 8891 | chan <<= 8; | |
| 1222 | 8891 | chan += bridgeBuffer[7]; | |
| 1223 | |||
| 1224 | 8891 | uint32_t len = bridgeBuffer[8] << 8; | |
| 1225 | 8891 | len += bridgeBuffer[9]; | |
| 1226 | |||
| 1227 | // Drop the packet if the length or channel map is out of bounds. Reading | ||
| 1228 | // `len` bytes from the receive buffer (beyond what was actually received), | ||
| 1229 | // or writing beyond the bridge buffer (FPPD_MAX_CHANNEL_NUM), would leak | ||
| 1230 | // stale data or corrupt memory. 64-bit arithmetic avoids uint32 overflow | ||
| 1231 | // of the channel+length sum. | ||
| 1232 |
2/2✓ Branch 0 taken 8591 times.
✓ Branch 1 taken 300 times.
|
8891 | if ((uint64_t)len > (uint64_t)(msgLen - ddpOffset) || |
| 1233 |
2/2✓ Branch 0 taken 922 times.
✓ Branch 1 taken 7669 times.
|
8591 | (uint64_t)chan + (uint64_t)len > (uint64_t)FPPD_MAX_CHANNELS) { // not into the reserved OFF/WHITE channels |
| 1234 | 1222 | ddpErrors++; | |
| 1235 | 1222 | return false; | |
| 1236 | } | ||
| 1237 | |||
| 1238 | 7669 | uint32_t sn = bridgeBuffer[1] & 0xF; | |
| 1239 |
1/2✓ Branch 0 taken 7669 times.
✗ Branch 1 not taken.
|
7669 | if (sn) { |
| 1240 | 7669 | bool isErr = false; | |
| 1241 |
2/2✓ Branch 0 taken 7657 times.
✓ Branch 1 taken 12 times.
|
7669 | if (ddpLastSequence) { |
| 1242 |
2/2✓ Branch 0 taken 2239 times.
✓ Branch 1 taken 5418 times.
|
7657 | if (sn == 1) { |
| 1243 |
2/2✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 235 times.
|
2239 | if (ddpLastSequence != 15) { |
| 1244 | 2004 | isErr = true; | |
| 1245 | } | ||
| 1246 |
2/2✓ Branch 0 taken 2087 times.
✓ Branch 1 taken 3331 times.
|
5418 | } else if ((sn - 1) != ddpLastSequence) { |
| 1247 | 2087 | isErr = true; | |
| 1248 | } | ||
| 1249 | } | ||
| 1250 |
2/2✓ Branch 0 taken 4091 times.
✓ Branch 1 taken 3578 times.
|
7669 | if (isErr) { |
| 1251 | 4091 | ddpErrors++; | |
| 1252 | // printf("%d %d %d %d\n", sn, ddpLastSequence, chan, ddpLastChannel); | ||
| 1253 | } | ||
| 1254 | 7669 | ddpLastSequence = sn; | |
| 1255 | 7669 | ddpLastChannel = chan + len; | |
| 1256 | } | ||
| 1257 | |||
| 1258 | 15338 | ddpMinChannel.store(std::min(ddpMinChannel.load(std::memory_order_relaxed), chan + 1), | |
| 1259 | std::memory_order_relaxed); | ||
| 1260 | 15116 | ddpMaxChannel.store(std::max(ddpMaxChannel.load(std::memory_order_relaxed), chan + len), | |
| 1261 | std::memory_order_relaxed); | ||
| 1262 | |||
| 1263 | 7669 | SetBridgeData(&bridgeBuffer[ddpOffset], | |
| 1264 | chan, | ||
| 1265 | len, | ||
| 1266 | packetTime); | ||
| 1267 | 7669 | ddpBytesReceived += len; | |
| 1268 |
4/4✓ Branch 0 taken 200 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✓ Branch 3 taken 100 times.
|
300 | } else if (bridgeBuffer[0] & 0x02 && bridgeBuffer[3] == 250) { |
| 1269 | // Queries and other non-data packets are ordinary DDP traffic FPP | ||
| 1270 | // doesn't answer; printed one per packet, they filled the journal. | ||
| 1271 | 100 | LogExcess(VB_E131BRIDGE, "DDP query config packet: %d\n", (int)bridgeBuffer[3]); | |
| 1272 |
3/4✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
|
200 | } else if (bridgeBuffer[0] & 0x02 && bridgeBuffer[3] == 251) { |
| 1273 | 100 | LogExcess(VB_E131BRIDGE, "DDP query status packet: %d\n", (int)bridgeBuffer[3]); | |
| 1274 | } else { | ||
| 1275 | 100 | LogExcess(VB_E131BRIDGE, "DDP packet for id %d ignored\n", (int)bridgeBuffer[3]); | |
| 1276 | } | ||
| 1277 | 7969 | return push; | |
| 1278 | } | ||
| 1279 | |||
| 1280 | 1085 | static inline bool IsArtNetInputType(int type) { | |
| 1281 |
3/4✓ Branch 0 taken 1085 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 1077 times.
|
1085 | return type == ARTNET_TYPE_BROADCAST || type == ARTNET_TYPE_UNICAST; |
| 1282 | } | ||
| 1283 | |||
| 1284 | // universe is a received packet's universe number (16 bits for E1.31, 15 for | ||
| 1285 | // ArtNet), so it is always inside its protocol's cache. | ||
| 1286 | 63266 | inline int Bridge_GetIndexFromUniverseNumber(int universe, bool artnet) { | |
| 1287 |
2/2✓ Branch 0 taken 19034 times.
✓ Branch 1 taken 44232 times.
|
63266 | unsigned int* cache = artnet ? ArtNetUniverseCache : E131UniverseCache; |
| 1288 | 63266 | unsigned int cached = cache[universe]; | |
| 1289 |
2/2✓ Branch 0 taken 2233 times.
✓ Branch 1 taken 61033 times.
|
63266 | if (cached == BRIDGE_UNIVERSE_NOT_FOUND) |
| 1290 | 2233 | return BRIDGE_INVALID_UNIVERSE_INDEX; | |
| 1291 |
2/2✓ Branch 0 taken 59911 times.
✓ Branch 1 taken 1122 times.
|
61033 | if (cached != BRIDGE_INVALID_UNIVERSE_INDEX) |
| 1292 | 59911 | return cached; | |
| 1293 | |||
| 1294 |
2/2✓ Branch 0 taken 500716 times.
✓ Branch 1 taken 38 times.
|
500754 | for (int index = 0; index < InputUniverseCount; index++) { |
| 1295 |
6/6✓ Branch 0 taken 1085 times.
✓ Branch 1 taken 499631 times.
✓ Branch 2 taken 1084 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1084 times.
✓ Branch 5 taken 499632 times.
|
501801 | if (universe == InputUniverses[index].universe && |
| 1296 | 1085 | IsArtNetInputType(InputUniverses[index].type) == artnet) { | |
| 1297 | 1084 | cache[universe] = index; | |
| 1298 | 1084 | return index; | |
| 1299 | } | ||
| 1300 | } | ||
| 1301 | // Cache the miss too. The sync-address check runs this for every data | ||
| 1302 | // packet, and the advertised sync universe is normally not a configured | ||
| 1303 | // input, so an uncached miss meant a full scan of the universe list per | ||
| 1304 | // packet. The cache is rebuilt from scratch on every UDP reload. | ||
| 1305 | 38 | cache[universe] = BRIDGE_UNIVERSE_NOT_FOUND; | |
| 1306 | 38 | return BRIDGE_INVALID_UNIVERSE_INDEX; | |
| 1307 | } | ||
| 1308 | |||
| 1309 | 7746 | void ResetBytesReceived() { | |
| 1310 | // Callable from the HTTP server's worker threads. | ||
| 1311 |
1/2✓ Branch 0 taken 7746 times.
✗ Branch 1 not taken.
|
7746 | std::lock_guard<std::mutex> lg(universesStructureLock); |
| 1312 |
2/2✓ Branch 0 taken 23190 times.
✓ Branch 1 taken 7746 times.
|
30936 | for (int i = 0; i < InputUniverseCount; i++) { |
| 1313 | 23190 | StatStore(InputUniverses[i].bytesReceived, 0); | |
| 1314 | 23190 | StatStore(InputUniverses[i].packetsReceived, 0); | |
| 1315 | 23190 | StatStore(InputUniverses[i].errorPackets, 0); | |
| 1316 | 23190 | StatStore(InputUniverses[i].lastSequenceNumber, 0); | |
| 1317 | 23190 | StatStore(InputUniverses[i].suppressedPackets, 0); | |
| 1318 | } | ||
| 1319 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7746 times.
|
7746 | for (auto& entry : DMXInputs) { |
| 1320 | ✗ | StatStore(entry->bytesReceived, 0); | |
| 1321 | ✗ | StatStore(entry->packetsReceived, 0); | |
| 1322 | ✗ | StatStore(entry->errorPackets, 0); | |
| 1323 | ✗ | StatStore(entry->lastSequenceNumber, 0); | |
| 1324 | } | ||
| 1325 | 7746 | ddpBytesReceived = 0; | |
| 1326 | 7746 | ddpPacketsReceived = 0; | |
| 1327 | 7746 | ddpErrors = 0; | |
| 1328 | 7746 | e131Errors = 0; | |
| 1329 | 7746 | StatStore(unknownUniverse.bytesReceived, 0); | |
| 1330 | 7746 | StatStore(unknownUniverse.packetsReceived, 0); | |
| 1331 | 7746 | e131SyncPackets = 0; | |
| 1332 | 7746 | } | |
| 1333 | |||
| 1334 | 13922 | Json::Value GetE131UniverseBytesReceived() { | |
| 1335 | // Callable from the HTTP server's worker threads; the lock keeps a config | ||
| 1336 | // reload from rebuilding the universe lists under this iteration. The | ||
| 1337 | // counters themselves are read atomically (StatLoad). | ||
| 1338 |
1/2✓ Branch 0 taken 13922 times.
✗ Branch 1 not taken.
|
13922 | std::lock_guard<std::mutex> lg(universesStructureLock); |
| 1339 |
1/2✓ Branch 0 taken 13922 times.
✗ Branch 1 not taken.
|
13922 | Json::Value result; |
| 1340 |
1/2✓ Branch 0 taken 13922 times.
✗ Branch 1 not taken.
|
13922 | Json::Value universes(Json::arrayValue); |
| 1341 | |||
| 1342 | int i; | ||
| 1343 | |||
| 1344 |
2/2✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 11983 times.
|
13922 | if (ddpBytesReceived) { |
| 1345 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | Json::Value ddpUniverse; |
| 1346 |
2/4✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1939 times.
✗ Branch 3 not taken.
|
1939 | ddpUniverse["id"] = "DDP"; |
| 1347 | |||
| 1348 | 1939 | uint32_t minChannel = ddpMinChannel.load(std::memory_order_relaxed); | |
| 1349 | 1939 | uint32_t maxChannel = ddpMaxChannel.load(std::memory_order_relaxed); | |
| 1350 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | if (maxChannel > minChannel) { |
| 1351 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | std::stringstream ss; |
| 1352 |
3/6✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1939 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1939 times.
✗ Branch 5 not taken.
|
1939 | ss << minChannel << "-" << maxChannel; |
| 1353 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | std::string chanRange = ss.str(); |
| 1354 |
2/4✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1939 times.
✗ Branch 3 not taken.
|
1939 | ddpUniverse["startChannel"] = chanRange; |
| 1355 | 1939 | } else { | |
| 1356 | ✗ | ddpUniverse["startChannel"] = "-"; | |
| 1357 | } | ||
| 1358 | |||
| 1359 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | std::stringstream ss; |
| 1360 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | ss << ddpBytesReceived; |
| 1361 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | std::string bytesReceived = ss.str(); |
| 1362 |
2/4✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1939 times.
✗ Branch 3 not taken.
|
1939 | ddpUniverse["bytesReceived"] = bytesReceived; |
| 1363 | |||
| 1364 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | std::stringstream pr; |
| 1365 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | pr << ddpPacketsReceived; |
| 1366 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | std::string packetsReceived = pr.str(); |
| 1367 |
2/4✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1939 times.
✗ Branch 3 not taken.
|
1939 | ddpUniverse["packetsReceived"] = packetsReceived; |
| 1368 | |||
| 1369 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | std::stringstream er; |
| 1370 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | er << ddpErrors; |
| 1371 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | std::string errors = er.str(); |
| 1372 |
2/4✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1939 times.
✗ Branch 3 not taken.
|
1939 | ddpUniverse["errors"] = errors; |
| 1373 |
2/4✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1939 times.
✗ Branch 3 not taken.
|
1939 | ddpUniverse["suppressedPackets"] = "-"; |
| 1374 |
1/2✓ Branch 0 taken 1939 times.
✗ Branch 1 not taken.
|
1939 | universes.append(ddpUniverse); |
| 1375 | 1939 | } | |
| 1376 | |||
| 1377 |
2/2✓ Branch 0 taken 41742 times.
✓ Branch 1 taken 13922 times.
|
55664 | for (i = 0; i < InputUniverseCount; i++) { |
| 1378 |
1/2✓ Branch 0 taken 41742 times.
✗ Branch 1 not taken.
|
41742 | Json::Value universe; |
| 1379 | |||
| 1380 |
2/4✓ Branch 0 taken 41742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41742 times.
✗ Branch 3 not taken.
|
41742 | universe["id"] = InputUniverses[i].universe; |
| 1381 |
2/4✓ Branch 0 taken 41742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41742 times.
✗ Branch 3 not taken.
|
41742 | universe["startChannel"] = InputUniverses[i].startAddress; |
| 1382 | |||
| 1383 |
2/4✓ Branch 0 taken 41742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41742 times.
✗ Branch 3 not taken.
|
41742 | universe["bytesReceived"] = std::to_string(StatLoad(InputUniverses[i].bytesReceived)); |
| 1384 |
2/4✓ Branch 0 taken 41742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41742 times.
✗ Branch 3 not taken.
|
41742 | universe["packetsReceived"] = std::to_string(StatLoad(InputUniverses[i].packetsReceived)); |
| 1385 |
2/4✓ Branch 0 taken 41742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41742 times.
✗ Branch 3 not taken.
|
41742 | universe["errors"] = std::to_string(StatLoad(InputUniverses[i].errorPackets)); |
| 1386 |
2/4✓ Branch 0 taken 41742 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 41742 times.
✗ Branch 3 not taken.
|
41742 | universe["suppressedPackets"] = std::to_string(StatLoad(InputUniverses[i].suppressedPackets)); |
| 1387 | |||
| 1388 |
1/2✓ Branch 0 taken 41742 times.
✗ Branch 1 not taken.
|
41742 | universes.append(universe); |
| 1389 | 41742 | } | |
| 1390 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13922 times.
|
13923 | for (auto& entry : DMXInputs) { |
| 1391 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | Json::Value universe; |
| 1392 | |||
| 1393 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["id"] = entry->dmxDevice; |
| 1394 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["startChannel"] = entry->startAddress; |
| 1395 | |||
| 1396 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["bytesReceived"] = std::to_string(StatLoad(entry->bytesReceived)); |
| 1397 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["packetsReceived"] = std::to_string(StatLoad(entry->packetsReceived)); |
| 1398 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["errors"] = std::to_string(StatLoad(entry->errorPackets)); |
| 1399 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["suppressedPackets"] = "-"; |
| 1400 | |||
| 1401 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | universes.append(universe); |
| 1402 | 1 | } | |
| 1403 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13922 times.
|
13922 | if (e131Errors) { |
| 1404 | ✗ | Json::Value universe; | |
| 1405 | |||
| 1406 | ✗ | universe["id"] = "E1.31 Errors"; | |
| 1407 | ✗ | universe["startChannel"] = "-"; | |
| 1408 | ✗ | universe["bytesReceived"] = "-"; | |
| 1409 | ✗ | universe["packetsReceived"] = "-"; | |
| 1410 | |||
| 1411 | ✗ | std::stringstream er; | |
| 1412 | ✗ | er << e131Errors; | |
| 1413 | ✗ | std::string errors = er.str(); | |
| 1414 | ✗ | universe["errors"] = errors; | |
| 1415 | ✗ | universe["suppressedPackets"] = "-"; | |
| 1416 | |||
| 1417 | ✗ | universes.append(universe); | |
| 1418 | ✗ | } | |
| 1419 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13921 times.
|
13922 | if (StatLoad(unknownUniverse.packetsReceived)) { |
| 1420 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | Json::Value universe; |
| 1421 | |||
| 1422 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["id"] = "Ignored"; |
| 1423 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["startChannel"] = "-"; |
| 1424 | |||
| 1425 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::stringstream er; |
| 1426 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | er << e131Errors; |
| 1427 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::string errors = er.str(); |
| 1428 | |||
| 1429 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::stringstream ss; |
| 1430 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | ss << StatLoad(unknownUniverse.bytesReceived); |
| 1431 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::string bytesReceived = ss.str(); |
| 1432 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["bytesReceived"] = bytesReceived; |
| 1433 | |||
| 1434 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::stringstream pr; |
| 1435 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | pr << StatLoad(unknownUniverse.packetsReceived); |
| 1436 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::string packetsReceived = pr.str(); |
| 1437 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["packetsReceived"] = packetsReceived; |
| 1438 | |||
| 1439 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["errors"] = "-"; |
| 1440 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | universe["suppressedPackets"] = "-"; |
| 1441 | |||
| 1442 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | universes.append(universe); |
| 1443 | 1 | } | |
| 1444 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 13920 times.
|
13922 | if (e131SyncPackets) { |
| 1445 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | Json::Value universe; |
| 1446 | |||
| 1447 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | universe["id"] = "E1.31 Sync"; |
| 1448 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | universe["startChannel"] = "-"; |
| 1449 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | universe["bytesReceived"] = "-"; |
| 1450 | |||
| 1451 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::stringstream er; |
| 1452 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | er << e131SyncPackets; |
| 1453 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::string sync = er.str(); |
| 1454 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | universe["packetsReceived"] = sync; |
| 1455 | |||
| 1456 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | universe["errors"] = "-"; |
| 1457 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | universe["suppressedPackets"] = "-"; |
| 1458 | |||
| 1459 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | universes.append(universe); |
| 1460 | 2 | } | |
| 1461 | |||
| 1462 |
2/4✓ Branch 0 taken 13922 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13922 times.
✗ Branch 3 not taken.
|
13922 | result["universes"] = universes; |
| 1463 | |||
| 1464 | 13922 | return result; | |
| 1465 | 13922 | } | |
| 1466 | |||
| 1467 | 2689 | void InputUniversesPrint() { | |
| 1468 |
2/2✓ Branch 0 taken 66805 times.
✓ Branch 1 taken 2689 times.
|
69494 | for (int i = 0; i < InputUniverseCount; i++) { |
| 1469 |
2/2✓ Branch 0 taken 66714 times.
✓ Branch 1 taken 91 times.
|
66805 | if (InputUniverses[i].type < 2) { |
| 1470 | 66714 | LogDebug(VB_E131BRIDGE, "E1.31 Universe: %d:%d:%d:%d:%d %s\n", | |
| 1471 | InputUniverses[i].active, | ||
| 1472 | InputUniverses[i].universe, | ||
| 1473 | InputUniverses[i].startAddress, | ||
| 1474 | InputUniverses[i].size, | ||
| 1475 | InputUniverses[i].type, | ||
| 1476 | InputUniverses[i].unicastAddress); | ||
| 1477 | } else { | ||
| 1478 | 91 | LogDebug(VB_E131BRIDGE, "ArtNet Universe: %d:%d:%d:%d:%d %s\n", | |
| 1479 | InputUniverses[i].active, | ||
| 1480 | InputUniverses[i].universe, | ||
| 1481 | InputUniverses[i].startAddress, | ||
| 1482 | InputUniverses[i].size, | ||
| 1483 | InputUniverses[i].type, | ||
| 1484 | InputUniverses[i].unicastAddress); | ||
| 1485 | } | ||
| 1486 | } | ||
| 1487 | 2689 | } | |
| 1488 | |||
| 1489 | // "Received <protocol> data from <ip>" warnings for data arriving with no | ||
| 1490 | // input configured. Each source's warning times out 10s after it was last | ||
| 1491 | // raised, so it is re-raised at most every 5s while the source keeps sending, | ||
| 1492 | // rather than on every wakeup; and only the first few sources get their own | ||
| 1493 | // warning -- the source address is whatever the packet says, so a flood with | ||
| 1494 | // a new one per packet grew the warning list (walked on every add) without | ||
| 1495 | // limit. The rest share one warning. Main loop only. | ||
| 1496 | static constexpr int FAKE_BRIDGE_WARNING_SECONDS = 10; | ||
| 1497 | static constexpr long long FAKE_BRIDGE_RERAISE_MS = 5000; | ||
| 1498 | static constexpr size_t MAX_FAKE_BRIDGE_SOURCES = 8; | ||
| 1499 | struct FakeBridgeSources { | ||
| 1500 | std::map<in_addr_t, long long> raisedAt; // GetMonotonicTimeMS() | ||
| 1501 | long long othersRaisedAt = 0; | ||
| 1502 | }; | ||
| 1503 | static std::map<std::string, FakeBridgeSources> fakeBridgeSources; | ||
| 1504 | |||
| 1505 | 4 | bool AddWarningForProtocol(int sock, const std::string& protocol) { | |
| 1506 | 4 | FakeBridgeSources& seen = fakeBridgeSources[protocol]; | |
| 1507 | 4 | long long now = GetMonotonicTimeMS(); | |
| 1508 | // A source whose warning has timed out no longer holds a slot. | ||
| 1509 | 4 | std::erase_if(seen.raisedAt, [now](const auto& e) { | |
| 1510 | ✗ | return now - e.second > FAKE_BRIDGE_WARNING_SECONDS * 1000; | |
| 1511 | }); | ||
| 1512 | 4 | int msgcnt = recvmmsg(sock, msgs, MAX_MSG, MSG_DONTWAIT, nullptr); | |
| 1513 | 4 | int batches = 1; | |
| 1514 |
2/2✓ Branch 0 taken 5 times.
✓ Branch 1 taken 4 times.
|
9 | while (msgcnt > 0) { |
| 1515 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 5 times.
|
56 | for (int x = 0; x < msgcnt; x++) { |
| 1516 | 51 | struct in_addr i = inAddress[x].sin_addr; | |
| 1517 | 51 | in_addr_t at = i.s_addr; | |
| 1518 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
|
51 | if (msgs[x].msg_len < 4) { |
| 1519 | 41 | continue; | |
| 1520 | } | ||
| 1521 |
7/8✓ Branch 0 taken 51 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✓ Branch 3 taken 41 times.
✓ Branch 4 taken 9 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 9 times.
✓ Branch 7 taken 42 times.
|
51 | if (protocol == "DDP" && buffers[x][3] != 1) { |
| 1522 | // non pixel DDP data, possibly a broadcast discovery packet or sync packet or similar | ||
| 1523 | 9 | continue; | |
| 1524 | } | ||
| 1525 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | auto it = seen.raisedAt.find(at); |
| 1526 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | if (it != seen.raisedAt.end()) { |
| 1527 | ✗ | if (now - it->second < FAKE_BRIDGE_RERAISE_MS) { | |
| 1528 | ✗ | continue; | |
| 1529 | } | ||
| 1530 | ✗ | it->second = now; | |
| 1531 |
2/2✓ Branch 0 taken 10 times.
✓ Branch 1 taken 32 times.
|
42 | } else if (seen.raisedAt.size() < MAX_FAKE_BRIDGE_SOURCES) { |
| 1532 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | seen.raisedAt[at] = now; |
| 1533 | } else { | ||
| 1534 |
3/4✓ Branch 0 taken 31 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 31 times.
✗ Branch 3 not taken.
|
32 | if (seen.othersRaisedAt && now - seen.othersRaisedAt < FAKE_BRIDGE_RERAISE_MS) { |
| 1535 | 31 | continue; | |
| 1536 | } | ||
| 1537 | 1 | seen.othersRaisedAt = now; | |
| 1538 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | std::string ne = "Received " + protocol + " data from other sources as well"; |
| 1539 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | LogDebug(VB_E131BRIDGE, "%s\n", ne.c_str()); |
| 1540 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | WarningHolder::AddWarningTimeout(ne, FAKE_BRIDGE_WARNING_SECONDS); |
| 1541 | 1 | continue; | |
| 1542 | 1 | } | |
| 1543 | 10 | char abuf[INET_ADDRSTRLEN] = {0}; | |
| 1544 | 10 | inet_ntop(AF_INET, &inAddress[x].sin_addr, abuf, sizeof(abuf)); | |
| 1545 |
3/6✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
|
10 | std::string ne = "Received " + protocol + " data from " + abuf; |
| 1546 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | LogDebug(VB_E131BRIDGE, "%s\n", ne.c_str()); |
| 1547 |
1/2✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
|
10 | WarningHolder::AddWarningTimeout(ne, FAKE_BRIDGE_WARNING_SECONDS); |
| 1548 | 10 | } | |
| 1549 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | msgcnt = ++batches > MAX_BATCHES_PER_WAKEUP ? 0 : recvmmsg(sock, msgs, MAX_MSG, MSG_DONTWAIT, nullptr); |
| 1550 | } | ||
| 1551 | 4 | return false; | |
| 1552 | } | ||
| 1553 | |||
| 1554 | // The "could not open" warnings the last DMX reload raised, retracted by the | ||
| 1555 | // next one: saving the DMX input config again is how a user retries after | ||
| 1556 | // plugging the adapter in or fixing the device name. | ||
| 1557 | static std::vector<std::string> dmxInputWarnings; | ||
| 1558 | |||
| 1559 | 2651 | static void BridgeReloadDMXInputs() { | |
| 1560 | 2651 | hasDMX = false; | |
| 1561 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2651 times.
|
2652 | for (const auto& w : dmxInputWarnings) { |
| 1562 |
2/4✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | WarningHolder::RemoveWarning(WARNING_ID_INPUT, w); |
| 1563 | } | ||
| 1564 | 2651 | dmxInputWarnings.clear(); | |
| 1565 | // remove any existing DMX inputs | ||
| 1566 | 2651 | std::vector<std::shared_ptr<UniverseEntry>> oldDMX; | |
| 1567 | { | ||
| 1568 |
1/2✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
|
2651 | std::lock_guard<std::mutex> lg(universesStructureLock); |
| 1569 | 2651 | oldDMX.swap(DMXInputs); | |
| 1570 | 2651 | } | |
| 1571 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2651 times.
|
2651 | for (auto& entry : oldDMX) { |
| 1572 | // close the serial port | ||
| 1573 | ✗ | EPollManager::INSTANCE.removeFileDescriptor(entry->inFile); | |
| 1574 | ✗ | SerialClose(entry->inFile); | |
| 1575 | } | ||
| 1576 | 2651 | oldDMX.clear(); | |
| 1577 | |||
| 1578 | // load the DMX inputs from the config file | ||
| 1579 |
3/6✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2651 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2651 times.
✗ Branch 5 not taken.
|
2651 | std::string filename = FPP_DIR_CONFIG("/ci-dmx.json"); |
| 1580 |
3/4✓ Branch 0 taken 2651 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 2646 times.
|
2651 | if (FileExists(filename)) { |
| 1581 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | Json::Value root; |
| 1582 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | if (LoadJsonFromFile(filename, root, JsonRoot::Object)) { |
| 1583 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | Json::Value outputs = root["channelInputs"]; |
| 1584 |
2/4✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
|
5 | if (!outputs.isArray()) { |
| 1585 | ✗ | outputs = Json::Value(Json::arrayValue); | |
| 1586 | } | ||
| 1587 |
3/4✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 5 times.
|
10 | for (int c = 0; c < outputs.size(); c++) { |
| 1588 | // Read the entry inside a try: a value of the wrong JSON type | ||
| 1589 | // threw out of this file-monitor callback, at startup, to | ||
| 1590 | // std::terminate. Such an entry is skipped. | ||
| 1591 | 5 | std::string type; | |
| 1592 | 5 | int start = 0; | |
| 1593 | 5 | int count = 0; | |
| 1594 | 5 | bool denabled = false; | |
| 1595 | 5 | std::string device; | |
| 1596 | try { | ||
| 1597 |
1/2✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
|
5 | const Json::Value& o = outputs[c]; |
| 1598 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
5 | type = o["type"].asString(); |
| 1599 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
|
4 | if (type == "dmx") { |
| 1600 |
3/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
|
4 | start = o["startAddress"].asInt(); |
| 1601 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | count = o["channelCount"].asInt(); |
| 1602 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | denabled = o["enabled"].asBool(); |
| 1603 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | device = o["device"].asString(); |
| 1604 | } | ||
| 1605 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | } catch (const std::exception& e) { |
| 1606 |
3/6✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
6 | WarningHolder::InvalidConfigEntry("ci-dmx.json", e.what()); |
| 1607 | 2 | continue; | |
| 1608 | 2 | } | |
| 1609 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | if (type == "dmx") { |
| 1610 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (denabled) { |
| 1611 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | std::string devPath = "/dev/" + device; |
| 1612 |
5/10✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
|
10 | PinCapabilities::getPinByUART(device + "-rx").configPin("uart"); |
| 1613 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | int dmxIn = SerialOpen(devPath.c_str(), 250000, "N82", false); |
| 1614 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (dmxIn > 0) { |
| 1615 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | auto entry = std::make_shared<UniverseEntry>(); |
| 1616 | 1 | entry->active = 1; | |
| 1617 | 1 | entry->universe = 0; | |
| 1618 | 1 | entry->startAddress = start - 1; | |
| 1619 | 1 | entry->size = count; | |
| 1620 | 1 | entry->type = DMX_TYPE; | |
| 1621 | 1 | entry->inFile = dmxIn; | |
| 1622 | 1 | entry->unicastAddress[0] = 0; | |
| 1623 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | entry->dmxDevice = device; |
| 1624 | 1 | entry->lastTimestamp = 0; | |
| 1625 | 1 | entry->priority = 0; | |
| 1626 | { | ||
| 1627 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::lock_guard<std::mutex> lg(universesStructureLock); |
| 1628 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | DMXInputs.push_back(entry); |
| 1629 | 1 | } | |
| 1630 |
0/2✗ Branch 0 not taken.
✗ Branch 1 not taken.
|
2 | std::function<bool(int)> f = [entry, count](int i) { |
| 1631 | 170 | uint8_t buffer[513] = { 0, 0, 0, 0 }; | |
| 1632 |
1/2✓ Branch 0 taken 170 times.
✗ Branch 1 not taken.
|
170 | int sz = read(i, buffer, sizeof(buffer)); |
| 1633 | 170 | long long commitTime = 0; | |
| 1634 |
2/2✓ Branch 0 taken 84 times.
✓ Branch 1 taken 170 times.
|
254 | while (sz > 0) { |
| 1635 |
1/2✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
|
84 | uint64_t ts = GetMonotonicTimeMicros(); // DMX break detection: an interval |
| 1636 | 84 | uint64_t diff = ts - entry->lastTimestamp; | |
| 1637 | 84 | entry->lastTimestamp = ts; | |
| 1638 | |||
| 1639 |
3/6✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 84 times.
✗ Branch 5 not taken.
|
84 | if (sz > 0 && buffer[0] == 0 && diff > 3000) { |
| 1640 | // it's a reset... | ||
| 1641 | 84 | commitTime = (ts / 1000) + expireOffSet; | |
| 1642 |
1/2✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
|
84 | SetBridgeData(&buffer[1], entry->startAddress, std::min(sz - 1, count), commitTime); |
| 1643 | 84 | entry->lastIndex = sz - 1; | |
| 1644 | 84 | StatAdd(entry->packetsReceived, 1); | |
| 1645 | 84 | sz -= 1; | |
| 1646 | ✗ | } else if (diff < 3000) { | |
| 1647 | ✗ | int num = sz; | |
| 1648 | ✗ | if (count < entry->lastIndex) { | |
| 1649 | ✗ | num = 0; | |
| 1650 | ✗ | } else if (count < entry->lastIndex + sz) { | |
| 1651 | ✗ | num = count - entry->lastIndex; | |
| 1652 | } | ||
| 1653 | ✗ | if (num) { | |
| 1654 | ✗ | commitTime = (ts / 1000) + expireOffSet; | |
| 1655 | ✗ | SetBridgeData(buffer, entry->startAddress + entry->lastIndex, num, commitTime); | |
| 1656 | } | ||
| 1657 | ✗ | entry->lastIndex += sz; | |
| 1658 | } else { | ||
| 1659 | ✗ | sz = 0; | |
| 1660 | ✗ | StatAdd(entry->errorPackets, 1); | |
| 1661 | } | ||
| 1662 | 84 | StatAdd(entry->bytesReceived, sz); | |
| 1663 |
1/2✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
|
84 | sz = read(i, buffer, sizeof(buffer)); |
| 1664 | } | ||
| 1665 |
2/2✓ Branch 0 taken 84 times.
✓ Branch 1 taken 86 times.
|
170 | if (commitTime) { |
| 1666 |
1/2✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
|
84 | CommitBridgeData(); |
| 1667 | } | ||
| 1668 | 170 | return 0; | |
| 1669 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | }; |
| 1670 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | EPollManager::INSTANCE.addFileDescriptor(dmxIn, f); |
| 1671 | 1 | hasDMX = true; | |
| 1672 | 1 | } else { | |
| 1673 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | std::string msg = "Could not open DMX input device " + device; |
| 1674 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | WarningHolder::AddWarning(WARNING_ID_INPUT, msg); |
| 1675 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | dmxInputWarnings.push_back(msg); |
| 1676 | 1 | } | |
| 1677 | 2 | } | |
| 1678 | } | ||
| 1679 |
4/4✓ Branch 0 taken 3 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 2 times.
|
7 | } |
| 1680 | 5 | } | |
| 1681 | 5 | } | |
| 1682 | 2651 | } | |
| 1683 | |||
| 1684 | 2689 | void BridgeReloadUDP() { | |
| 1685 |
1/2✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
|
2689 | ResetArtNetSocketFailure(); |
| 1686 | // close the existing sockets | ||
| 1687 |
1/2✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
|
2689 | BridgeShutdownUDP(true); |
| 1688 | |||
| 1689 | 2689 | bridgeDataReceived = false; | |
| 1690 | 2689 | hasUDP = false; | |
| 1691 | 2689 | bool hasArtNet = false; | |
| 1692 |
1/2✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
|
2689 | bool enabled = Bridge_Initialize_Internal(hasArtNet); |
| 1693 |
1/2✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
|
2689 | bool disableFakeBridges = getSettingInt("DisableFakeNetworkBridges"); |
| 1694 |
2/2✓ Branch 0 taken 1631 times.
✓ Branch 1 taken 1058 times.
|
2689 | if (bridgeSock > 0) { |
| 1695 |
2/2✓ Branch 0 taken 95 times.
✓ Branch 1 taken 1536 times.
|
1631 | if (enabled) { |
| 1696 | 13906 | std::function<bool(int)> f = [](int i) { | |
| 1697 | 13811 | return Bridge_ReceiveE131Data(); | |
| 1698 | 95 | }; | |
| 1699 |
1/2✓ Branch 0 taken 95 times.
✗ Branch 1 not taken.
|
95 | EPollManager::INSTANCE.addFileDescriptor(bridgeSock, f); |
| 1700 |
1/2✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
|
1631 | } else if (!disableFakeBridges) { |
| 1701 | 2 | std::function<bool(int)> f = [](int i) { | |
| 1702 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | return AddWarningForProtocol(i, "E1.31"); |
| 1703 | 1536 | }; | |
| 1704 |
1/2✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
|
1536 | EPollManager::INSTANCE.addFileDescriptor(bridgeSock, f); |
| 1705 | 1536 | } | |
| 1706 | } | ||
| 1707 |
2/2✓ Branch 0 taken 1635 times.
✓ Branch 1 taken 1054 times.
|
2689 | if (ddpSock > 0) { |
| 1708 |
2/2✓ Branch 0 taken 99 times.
✓ Branch 1 taken 1536 times.
|
1635 | if (enabled) { |
| 1709 | 4148 | std::function<bool(int)> f = [](int i) { | |
| 1710 | 4049 | return Bridge_ReceiveDDPData(); | |
| 1711 | 99 | }; | |
| 1712 |
1/2✓ Branch 0 taken 99 times.
✗ Branch 1 not taken.
|
99 | EPollManager::INSTANCE.addFileDescriptor(ddpSock, f); |
| 1713 |
1/2✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
|
1635 | } else if (!disableFakeBridges) { |
| 1714 | 2 | std::function<bool(int)> f = [](int i) { | |
| 1715 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
4 | return AddWarningForProtocol(i, "DDP"); |
| 1716 | 1536 | }; | |
| 1717 |
1/2✓ Branch 0 taken 1536 times.
✗ Branch 1 not taken.
|
1536 | EPollManager::INSTANCE.addFileDescriptor(ddpSock, f); |
| 1718 | 1536 | } | |
| 1719 | } | ||
| 1720 |
4/4✓ Branch 0 taken 99 times.
✓ Branch 1 taken 2590 times.
✓ Branch 2 taken 90 times.
✓ Branch 3 taken 9 times.
|
2689 | if (enabled && hasArtNet) { |
| 1721 | // Registering the handlers is what puts the socket in the epoll set - | ||
| 1722 | // see UpdateArtNetInputRegistration(). Registered even when the | ||
| 1723 | // socket couldn't be opened just now: that function keeps retrying, | ||
| 1724 | // and picks the socket up if the output thread opens it first. | ||
| 1725 |
1/2✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
|
90 | ArtNetOpcodeHandlers[0x5000] = Bridge_StoreArtNetData; // ArtOutput |
| 1726 |
1/2✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
|
90 | ArtNetOpcodeHandlers[0x5200] = Bridge_HandleArtNetSync; // ArtSync |
| 1727 |
1/2✓ Branch 0 taken 90 times.
✗ Branch 1 not taken.
|
90 | ArtNetOpcodeHandlers[0x2000] = Bridge_HandleArtNetPoll; // ArtPoll |
| 1728 | } | ||
| 1729 |
1/2✓ Branch 0 taken 2689 times.
✗ Branch 1 not taken.
|
2689 | UpdateArtNetInputRegistration(); |
| 1730 | 2689 | } | |
| 1731 | 5309 | void BridgeShutdownUDP(bool reloading) { | |
| 1732 | 5309 | removeMulticastGroups(); | |
| 1733 | { | ||
| 1734 | // DMX inputs live in DMXInputs, so the whole vector is UDP entries. | ||
| 1735 |
1/2✓ Branch 0 taken 5309 times.
✗ Branch 1 not taken.
|
5309 | std::lock_guard<std::mutex> lg(universesStructureLock); |
| 1736 | 5309 | InputUniverses.clear(); | |
| 1737 | 5309 | InputUniverseCount = 0; | |
| 1738 | 5309 | } | |
| 1739 | |||
| 1740 | // close the existing sockets | ||
| 1741 |
2/2✓ Branch 0 taken 1601 times.
✓ Branch 1 taken 3708 times.
|
5309 | if (bridgeSock >= 0) { |
| 1742 | 1601 | EPollManager::INSTANCE.removeFileDescriptor(bridgeSock); | |
| 1743 | 1601 | close(bridgeSock); | |
| 1744 | 1601 | bridgeSock = -1; | |
| 1745 | } | ||
| 1746 |
2/2✓ Branch 0 taken 1605 times.
✓ Branch 1 taken 3704 times.
|
5309 | if (ddpSock >= 0) { |
| 1747 | 1605 | EPollManager::INSTANCE.removeFileDescriptor(ddpSock); | |
| 1748 | 1605 | close(ddpSock); | |
| 1749 | 1605 | ddpSock = -1; | |
| 1750 | } | ||
| 1751 | // Give back the bridge's own handlers and let the shared registration | ||
| 1752 | // re-evaluate, rather than pulling the descriptor out from under | ||
| 1753 | // everyone: a plugin may still want ArtNet delivered across a reload. | ||
| 1754 | // Done whether or not there is a socket: the handlers are registered | ||
| 1755 | // while one is still being waited for. All three go before the one | ||
| 1756 | // re-evaluation, which would otherwise try to open the port for the | ||
| 1757 | // bridge handlers still left. | ||
| 1758 |
1/2✓ Branch 0 taken 5309 times.
✗ Branch 1 not taken.
|
5309 | ArtNetOpcodeHandlers.erase(0x5000); |
| 1759 |
1/2✓ Branch 0 taken 5309 times.
✗ Branch 1 not taken.
|
5309 | ArtNetOpcodeHandlers.erase(0x5200); |
| 1760 |
1/2✓ Branch 0 taken 5309 times.
✗ Branch 1 not taken.
|
5309 | ArtNetOpcodeHandlers.erase(0x2000); |
| 1761 | 5309 | UpdateArtNetInputRegistration(); | |
| 1762 |
6/6✓ Branch 0 taken 2620 times.
✓ Branch 1 taken 2689 times.
✓ Branch 2 taken 64 times.
✓ Branch 3 taken 2556 times.
✓ Branch 4 taken 64 times.
✓ Branch 5 taken 5245 times.
|
5309 | if (!reloading && artnetSock >= 0) { |
| 1763 | // don't close the artNet socket if we are reloading | ||
| 1764 | // as outputs or inputs may still be using it | ||
| 1765 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 62 times.
|
64 | if (artnetSocketAsInput) { |
| 1766 | 2 | EPollManager::INSTANCE.removeFileDescriptor(artnetSock); | |
| 1767 | 2 | artnetSocketAsInput = false; | |
| 1768 | } | ||
| 1769 | 64 | close(artnetSock); | |
| 1770 | 64 | artnetSock = -1; | |
| 1771 | } | ||
| 1772 | 5309 | } | |
| 1773 | 2620 | void Bridge_Shutdown(void) { | |
| 1774 | 2620 | std::vector<std::shared_ptr<UniverseEntry>> oldDMX; | |
| 1775 | { | ||
| 1776 |
1/2✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
|
2620 | std::lock_guard<std::mutex> lg(universesStructureLock); |
| 1777 | 2620 | oldDMX.swap(DMXInputs); | |
| 1778 | 2620 | } | |
| 1779 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2620 times.
|
2621 | for (auto& entry : oldDMX) { |
| 1780 | // close the serial port | ||
| 1781 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | EPollManager::INSTANCE.removeFileDescriptor(entry->inFile); |
| 1782 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | SerialClose(entry->inFile); |
| 1783 | } | ||
| 1784 | 2620 | oldDMX.clear(); | |
| 1785 | 2620 | hasDMX = false; | |
| 1786 |
1/2✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
|
2620 | BridgeShutdownUDP(false); |
| 1787 |
3/6✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2620 times.
✗ Branch 5 not taken.
|
10480 | unregisterSettingsListener("DisableFakeNetworkBridges", "DisableFakeNetworkBridges"); |
| 1788 |
3/6✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2620 times.
✗ Branch 5 not taken.
|
10480 | unregisterSettingsListener("BridgeSourcePriority", "BridgeSourcePriority"); |
| 1789 |
3/6✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2620 times.
✗ Branch 5 not taken.
|
5240 | std::string udpInFile = FPP_DIR_CONFIG("/ci-universes.json"); |
| 1790 |
2/4✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
|
5240 | FileMonitor::INSTANCE.RemoveFile("ci-universes.json", udpInFile); |
| 1791 |
3/6✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2620 times.
✗ Branch 5 not taken.
|
5240 | std::string dmxInFile = FPP_DIR_CONFIG("/ci-dmx.json"); |
| 1792 |
2/4✓ Branch 0 taken 2620 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2620 times.
✗ Branch 3 not taken.
|
2620 | FileMonitor::INSTANCE.RemoveFile("ci-dmx.json", dmxInFile); |
| 1793 | |||
| 1794 | 2620 | ArtNetOpcodeHandlers.clear(); | |
| 1795 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2620 times.
|
2620 | if (artnetInputRetryRunning) { |
| 1796 | ✗ | artnetInputRetryRunning = false; | |
| 1797 | ✗ | Timers::INSTANCE.stopPeriodicTimer(ARTNET_INPUT_RETRY_TIMER); | |
| 1798 | } | ||
| 1799 | 2620 | } | |
| 1800 | |||
| 1801 | 2650 | void Bridge_Initialize(std::map<int, std::function<bool(int)>>& callbacks) { | |
| 1802 |
3/6✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2650 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2650 times.
✗ Branch 5 not taken.
|
12660 | registerSettingsListener("DisableFakeNetworkBridges", "DisableFakeNetworkBridges", [](const std::string& s) { |
| 1803 | // reload the bridges when the setting changes | ||
| 1804 | 1 | BridgeReloadUDP(); | |
| 1805 | 1 | }); | |
| 1806 |
1/2✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
|
2650 | sourcePriorityEnabled.store(getSettingInt("BridgeSourcePriority") != 0, |
| 1807 | std::memory_order_relaxed); | ||
| 1808 |
3/6✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2650 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2650 times.
✗ Branch 5 not taken.
|
12955 | registerSettingsListener("BridgeSourcePriority", "BridgeSourcePriority", [](const std::string& s) { |
| 1809 | ✗ | bool enabled = !s.empty() && s != "0"; | |
| 1810 | ✗ | sourcePriorityEnabled.store(enabled, std::memory_order_relaxed); | |
| 1811 | // Clear per-universe source state so the next packet establishes a | ||
| 1812 | // fresh active source under the new setting. | ||
| 1813 | ✗ | for (int i = 0; i < InputUniverseCount; i++) { | |
| 1814 | ✗ | InputUniverses[i].activeSourceValid = false; | |
| 1815 | ✗ | InputUniverses[i].activeSourcePriority = 0; | |
| 1816 | ✗ | InputUniverses[i].activeSourceLastTime = 0; | |
| 1817 | } | ||
| 1818 | ✗ | }); | |
| 1819 | |||
| 1820 |
3/6✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2650 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2650 times.
✗ Branch 5 not taken.
|
2945 | std::string udpInFile = FPP_DIR_CONFIG("/ci-universes.json"); |
| 1821 |
2/4✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2650 times.
✗ Branch 3 not taken.
|
7655 | FileMonitor::INSTANCE.AddFile("ci-universes.json", udpInFile, |
| 1822 | 2650 | []() { | |
| 1823 | 2688 | BridgeReloadUDP(); | |
| 1824 | 2688 | }) | |
| 1825 |
2/4✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2650 times.
✗ Branch 3 not taken.
|
5300 | .TriggerFileChanged("ci-universes.json", udpInFile); |
| 1826 | |||
| 1827 |
3/6✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2650 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2650 times.
✗ Branch 5 not taken.
|
2945 | std::string dmxInFile = FPP_DIR_CONFIG("/ci-dmx.json"); |
| 1828 |
2/4✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2650 times.
✗ Branch 3 not taken.
|
7360 | FileMonitor::INSTANCE.AddFile("ci-dmx.json", dmxInFile, |
| 1829 | 295 | []() { | |
| 1830 | 2651 | BridgeReloadDMXInputs(); | |
| 1831 | 2651 | }) | |
| 1832 |
2/4✓ Branch 0 taken 2650 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2650 times.
✗ Branch 3 not taken.
|
5300 | .TriggerFileChanged("ci-dmx.json", dmxInFile); |
| 1833 | 2650 | } | |
| 1834 | |||
| 1835 | 136669 | bool HasBridgeData() { | |
| 1836 | 136669 | return bridgeDataReceived.load(std::memory_order_relaxed); | |
| 1837 | } | ||
| 1838 |