Fix device page and camera streaming over LAN connections - #39
Open
sudharsan-gandhi wants to merge 1 commit into
Open
Fix device page and camera streaming over LAN connections#39sudharsan-gandhi wants to merge 1 commit into
sudharsan-gandhi wants to merge 1 commit into
Conversation
Three related defects leave the device page degraded and the camera dark on any locally connected printer. Present on main, develop, release_0715 and beta_hunse. 1. ComGetDevProductDetail reported the whole command unsupported on LAN. The network library does expose LAN equivalents, already used individually by ComGetDevProduct and ComGetDevDetail a few lines above, so devProduct and devDetail stayed null on every LAN connection and each capability the device page reads from them was silently absent: camera, lightCtrlState, internalFanCtrlState. Now fetches both via getLanDevProduct and getLanDevDetail, freeing the product if the detail call fails. 2. ComCameraStreamCtrl also returned COM_UNSUPPORTED on LAN, and here there is genuinely no ctrlLanDev* counterpart to fnet_camera_stream_ctrl_t. But SingleDeviceState issues the "open" command precisely when connectMode is LAN, and the camera only serves frames once explicitly opened, so the stream could never start. Implemented the LAN path as a POST to the printer's local /control endpoint: the same request the library performs for lightControl_cmd via fnet_ctrlLanDevLight, using the ip, port, serialNumber and checkCode already carried in com_command_exec_data_t. 3. SingleDeviceState::fillValue dereferenced data.devDetail unconditionally, including on the WAN path where status is read from wanDevInfo instead. devDetail can legitimately be null when the fetch has not run or failed, so this was a live null dereference; it now returns early. fillValue also did nothing when the printer reported no stream URL, which happens on LAN, and now falls back to the local MJPEG endpoint. Light control is unaffected: ComLightCtrl already had a working LAN branch, which is why lights respond locally while the camera does not.
Author
|
Additional build verification, since I could only cite macOS when opening this:
Zero compile errors on any of the three compilers, and none of the three changed files appear in any diagnostic. Two unrelated failures in those same runs, both pre-existing on a clean checkout and neither touched by this PR — noting them only so they aren't mistaken for fallout:
Happy to send either as its own small PR if useful — I kept them out of this one to keep the diff focused on the LAN defects. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three related defects leave the device page degraded and the camera dark on any locally connected printer. Present on
main,develop,release_0715andbeta_hunse— verified individually on each.This is not model-specific; it affects every FlashForge printer connected over LAN rather than the cloud. It's most visible on the Creator 5 / 5 Pro, where the device page shows no video at all.
Light control is unaffected, and that turned out to be the clue:
ComLightCtrlalready has a working LAN branch viafnet_ctrlLanDevLight, which is exactly why lights respond locally while the camera does not.1.
ComGetDevProductDetailgives up on LANThe network library does expose LAN equivalents —
getLanDevProductandgetLanDevDetail— and they're already used individually byComGetDevProductandComGetDevDetaila few lines above in the same header.Because this returned
COM_UNSUPPORTED,devProductanddevDetailstayed null on every LAN connection, so each capability the device page reads from them was silently absent:camera,lightCtrlState,internalFanCtrlState.Now fetches both, freeing the product if the detail call fails so a partial success doesn't leak.
2.
ComCameraStreamCtrlhas no LAN pathAlso returned
COM_UNSUPPORTEDon LAN. Here there genuinely is noctrlLanDev*counterpart tofnet_camera_stream_ctrl_tin the library.But
SingleDeviceState::fillValueissues the"open"command precisely whenconnectModeis LAN, and the camera only serves frames once explicitly opened. So the stream could never start — a dead end by construction.Implemented the LAN path as a POST to the printer's local
/controlendpoint. This is the same request the library already performs forlightControl_cmdviafnet_ctrlLanDevLight, using theip,port,serialNumberandcheckCodealready carried incom_command_exec_data_t:{ "serialNumber": "...", "checkCode": "...", "payload": { "cmd": "streamCtrl_cmd", "args": { "action": "open" } } }A non-2xx reply, or a JSON body with a non-zero
code, is treated as failure. An unparsable body on a 2xx is accepted, since the command was acknowledged.If you'd prefer this went through the network library instead, that works too — it would need a
fnet_ctrlLanDevCameraStreamcounterpart exposed, and I'd happily rework the patch against it.3. Null dereference plus a missing stream-URL fallback in
fillValuedevDetailis dereferenced unconditionally, including on the WAN path where status comes fromwanDevInfo. Since it can legitimately be null when the fetch hasn't run or has failed, this was a live null dereference. Now returns early.Separately, when the printer reported no stream URL — which happens on LAN — the function did nothing at all. It now falls back to the standard local MJPEG endpoint so the panel has something to load, and assigns the resolved URL rather than re-reading the empty field.
Verification
Build slicer macgreen on both). The build I ran was thebeta_hunse-based variant of this patch; themain-adapted version differs only in the camera block, which followsmain's existing structure sincemainhas noisSupportCameragate.GhostTypes/ff-5mp-api-pyand its Home Assistant integrationGhostTypes/ff-5mp-hass. Both use the same/controlenvelope and the same MJPEG endpoint, and their printer-ID table matchesFFUtils::printer_preset_mapexactly (AD5X0x26, C50x28, C5P0x29).Scope
Three files, +119/−4. No behaviour change on WAN connections. No new dependencies —
Httpandnlohmann/jsonare both already used in this directory.