Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Improve MSP handling #3415

Merged
merged 9 commits into from May 6, 2023
Merged

Conversation

haslinghuis
Copy link
Member

@haslinghuis haslinghuis commented Apr 10, 2023

  • Give FC time to react to new settings
  • Reduce MSP.timeout from 250 to 50ms
  • Reduce timeout from 250 to 200ms
  • Add new mspHelper for EEPROM write

@github-actions

This comment has been minimized.

@blckmn
Copy link
Member

blckmn commented Apr 10, 2023

AUTOMERGE: (FAIL)

  • github identifies PR as mergeable -> PASS
  • assigned to a milestone -> PASS
  • cooling off period lapsed -> PASS
  • commit count less or equal to three -> FAIL
  • Don't merge label NOT found -> PASS
  • at least one RN: label found -> PASS
  • Tested label found -> FAIL
  • assigned to an approver -> PASS
  • approver count at least three -> FAIL

@HThuren
Copy link
Member

HThuren commented Apr 10, 2023

remove when already are ind queue.... but don't you risk, this case: have a long transaktion, put short status request, another long transaktion, you now want same short status since you still have the answer from first - this are with this PR skipped, and you only get an (old) answer to the short status request.
Better if you refresh the first request, ie, delete and place last in queue, but not if it is a write action ....
Job queues handling are complex to handle...

@haslinghuis
Copy link
Member Author

Sure this needs a lot of testing. But see here how it was before: e87c0ca

@McGiverGim
Copy link
Member

This code sends the callback? Now we have a MSP request and we inform when finished to the caller. With this PR is discarded, do we inform the caller too?

@HThuren
Copy link
Member

HThuren commented Apr 10, 2023

This code sends the callback? Now we have a MSP request and we inform when finished to the caller. With this PR is discarded, do we inform the caller too?

PR !, you mean request ? or ...

@haslinghuis
Copy link
Member Author

haslinghuis commented Apr 10, 2023

@McGiverGim good call, this was not handled in original code either. Added callbacks

@github-actions

This comment has been minimized.

src/js/msp.js Outdated
Comment on lines 334 to 342
if (callback_msp) {
callback_msp();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure if this can have some unexpected result. Some pages call the MSP commands at certain order, for example I think remember the VTX tab. With this, if I'm not wrong, it can call the callback way before if it is at the queue. But I suppose this is very similar to the code actual, is that true? I think this works because at the end, only events executed in a timer manner are affected by this.
Another question, this takes into account the parameters to the MSP command? If the same command is called twice with different parameters the second one is ignored?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are valid concerns.

I think for read kind of operations this wouldn't matter that much, because it was read and put into FC or whatever is needed. Though some things require arguments as you mentioned so if reading mutliple things with same command but different request then it would have stale data.

Another thing is putting the data into FC, not 100% of the flow, but would this change mean that if there are 2 MSP commands sending data to FC, only the first one would get executed? So there would be weird state where you'd click something it wouldn't work, then click again for it to be saved?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is reverting an experimental fix from @cTn-dev as the concerns are valid but it's how it was e87c0ca

// utilizing callback/timeout system for all commands
// dev version 0.57 code below got recently changed due to the fact that queueing same MSP codes was unsupported
// and was causing trouble while backup/restoring configurations
// watch out if the recent change create any inconsistencies and then adjust accordingly

It's blazing fast - but need to log and test real situations.

🤔 As alternative for dropping last command - if it exists already - we could replace the existing with the new one. For the aux tab had to introduce a timer to stop the objects interval allowing ongoing execution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly how MSP2_SET_TEXT works, every command has to be accounted for based on it's payload so we can't discard any of the messages. I know this might be an exception, but if future apis are built in similar way then it might be hard to maintain.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the code to apply for MSP V1 requests only.

@github-actions

This comment has been minimized.

@haslinghuis haslinghuis changed the title Remove duplicate MSP requests Remove duplicate MSP V1 requests Apr 12, 2023
@github-actions

This comment has been minimized.

@haslinghuis haslinghuis force-pushed the bad-cable-detection branch 5 times, most recently from 25e7ccc to 9e26559 Compare April 12, 2023 21:36
@github-actions

This comment has been minimized.

@McGiverGim
Copy link
Member

Only as suggestion, now that you are looking at how to accelerate MSP commands, we have a MULTIPLE_MSP command, more info here: #1605
That can be used to send various commands at once. It is not being used because maybe it can produce some problems with very old FCs if the message is too big, but now that we have abandoned "some" of the backward compatibility, maybe we can try to test it.
Of course, for other PR, not here ;)

Copy link
Member

@McGiverGim McGiverGim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved, but the MSP_MULTIPLE command that I've mentioned, maybe must be an exception too? It can be used to send different commands to the FC, so it must not be "removed" if there are others in the queue.

@nerdCopter
Copy link
Member

  • 9e265595
  • successfully flashed 2 FC's, both 4.4.1-release and 4.5-zulu
  • successfully configured 2 FC's (un-soldered)
  • will revisit when @McGiverGim 's concern is resolved.

@haslinghuis
Copy link
Member Author

haslinghuis commented Apr 13, 2023

Firmware buffer size overflow is solved by adding multiple MSP_MULTIPLE_MSP requests so this should certainly not be replaced if not processed before the new request.

MSP_MULTIPLE_MSP (would call it MSP_BATCH) has yet no examples for implementation. #1605

🤔 But as the code already allows an ongoing process to continue adding the second command should already work.
🤔 we should try parallel execution as MSP request should be independent on each other by design.

#2356 (comment)

image

image

@McGiverGim
Copy link
Member

MSP_MULTIPLE_MSP (would call it MSP_BATCH) has yet no examples for implementation. #1605

There is one example in the text of the PR. I don't know if it's this what you want.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@haslinghuis haslinghuis force-pushed the bad-cable-detection branch 2 times, most recently from dfd787e to 3e5d644 Compare May 2, 2023 00:59
@haslinghuis haslinghuis changed the title Remove duplicate MSP V1 requests Improve MSP handling May 2, 2023
@github-actions

This comment has been minimized.

@haslinghuis
Copy link
Member Author

Needed to refactor ports tab not using async as settings were not applied.

@McGiverGim @nerdCopter not so sure about replacing duplicate MSP requests so dropped that for the moment as clicking other tabs sometimes hung up loading sequence without notice - using a timeout was working but don't want to add another timer as this would still allow duplicates to run.

Speeding up communication works good by improving timing.

@nerdCopter
Copy link
Member

nerdCopter commented May 2, 2023

i have it installed as my daily-driver, will keep an eye on it. (3e5d6442)

Copy link
Member

@nerdCopter nerdCopter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • approving. no known problems.
  • MSP timeouts, but as expected.

EDIT: dismissed

@nerdCopter nerdCopter self-requested a review May 6, 2023 15:33
@nerdCopter nerdCopter marked this pull request as draft May 6, 2023 15:35
@nerdCopter
Copy link
Member

nerdCopter commented May 6, 2023

SORRY, converted PR to draft to prevent merging. setting DSHOTXXX does not save to FC.
(3e5d6442)

https://youtu.be/nMeiG66xaPE

@sonarcloud
Copy link

sonarcloud bot commented May 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@github-actions
Copy link
Contributor

github-actions bot commented May 6, 2023

Do you want to test this code? Here you have an automated build:
Betaflight-Configurator-Android
Betaflight-Configurator-Linux
Betaflight-Configurator-macOS
Betaflight-Configurator-Windows
WARNING: It may be unstable and result in corrupted configurations or data loss. Use only for testing!

Copy link
Member

@nerdCopter nerdCopter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • re-approving
  • c1b1e1a9 fixes last concern.

@nerdCopter nerdCopter marked this pull request as ready for review May 6, 2023 16:47
@haslinghuis haslinghuis merged commit 07a352a into betaflight:master May 6, 2023
9 checks passed
@haslinghuis haslinghuis deleted the bad-cable-detection branch May 6, 2023 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: COMPLETED
Development

Successfully merging this pull request may close these issues.

None yet

6 participants