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

Added Command Checksum + code optimization + cleanup #2889

Merged
merged 6 commits into from
Feb 19, 2024

Conversation

digant73
Copy link
Contributor

@digant73 digant73 commented Feb 13, 2024

With other two pending PRs #2886 and #2852, this PR implements the last remaining (useful) FR #2839 requesting the command checksum feature. I needed that feature to troubleshot #2870. Once created, I'm simply sharing it with other code optimization/improvements compliant to other FRs.

IMPROVEMENTS:

  • Added line number and checksum feature based on [FR] Support for gcode sending with line numbers and checksums to improve communicaton reliability #2839: The TFT enriches each G-code to be sent to the mainboard adding a leading sequential line number and a trailing checksum appended after an * character used as separator. The checksum is based on algorithm CheckSum8 Xor and it is calculated on the G-code with the applied line number. E.g. G28 is firstly enriched with a line number (e.g. N1 G28) and finally a checksum calculated on that enriched G-code is appended (e.g. N1 G28*18). A data integrity check (sequential line number check and checksum check) will be performed on the mainboard. In case of data mismatch (e.g. data corruption due to EMI on communication serial line) the TFT will resend the requested G-code for a maximum of 3 attempts.
    New setting command_checksum added on config.ini file. The feature is also selectable at runtime from the Feature menu.

    NOTE: Disable it in case:

    • printing is controlled by a remote host (e.g. ESP3D, OctoPrint etc.) and a COMMAND_CHECKSUM
      feature is enabled and managed by the remote host. Otherwise (COMMAND_CHECKSUM feature also
      enabled in TFT), the TFT's COMMAND_CHECKSUM feature will always replace the one provided by
      the remote host causing conflicts in case data mismatch will be notified by the mainboard.
    • ADVANCED_OK feature is enabled in TFT. Otherwise, any out of synch command already sent to
      the mainboard will be discarded by the mainboard and not resent by the TFT due the current
      implementation of COMMAND_CHECKSUM feature on the TFT buffers only the last sent command
      and not all the pending commands.
  • Code optimization and reduction based on [FR] General TFT Speed Improvements #2836 and [BUG] Buggy time handling code (doesn't consider timer rollover) #2832: Functions looping on query updates (based on periodic update time) or HW events (e.g. a touch on screen etc.) invoked in the main loopBackEnd() and loopFrontEnd() functions optimized to provide better performance on both idle and printing states.

  • Improved TFT stability in case of ACK timeout: In case of no OK ACK message is received by the TFT (e.g. ACK corrupted) within a timeout period of 15 seconds for a pending gcode, the pending gcode is released allowing the TFT to not freeze.

  • Improved TFT stability for all the queries sent by the TFT based on a state variable (e.g. not sent again until the query gcode is dequeued and sent to the mainboard). In case the query is lost without resetting its status (e.g. speed, fan, coordinate query gcode removed from command queue), the status is reset allowing the TFT to reschedule the periodic transmission of the gcode.

  • Renamed API: APIs parseACK and interfaceCmd renamed to Mainboard_AckHandler and Mainboard_CmdHandler respectively.

  • Cleanup: Created APIs Mainboard_CmdControl and Mainboard_FlowControl with functions and/or control functions shared between Mainboard_AckHandler and Mainboard_CmdHandler.

resolves #2878 (answer provided)
resolves #2864 (answer provided)
resolves #2839
resolves #2836
resolves #2832

PR STATE: Ready for merge

@bigtreetech bigtreetech merged commit 4f722c3 into bigtreetech:master Feb 19, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment