From acf66542ee8a6a4437e8ecc3247e167b1f66799c Mon Sep 17 00:00:00 2001 From: Terje Io Date: Sat, 4 Dec 2021 12:12:28 +0100 Subject: [PATCH] Added flags for WebUI reconnect handling and core support for enabling debug stream. --- changelog.md | 20 ++++++++++++++++++++ config.h | 2 +- grbl.h | 2 +- grbllib.c | 14 ++++---------- protocol.c | 4 +++- stream.c | 36 +++++++++++++++++++++++++++++++----- stream.h | 13 +++++++++++-- system.h | 8 +++++--- 8 files changed, 76 insertions(+), 23 deletions(-) diff --git a/changelog.md b/changelog.md index 176d99c..6809006 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,25 @@ ## grblHAL changelog +Build 20211203: + +Core: + +* Added flags for WebUI reconnect handling. +* For developers: Changed debug stream initialization to claim specific stream instance and moved init call to core. +Enabling the debug stream is done in [grbl/config.h](https://github.com/grblHAL/core/blob/master/config.h). + +Drivers: + +* All: updated for core changes \(new flags\). +* iMRXRT driver: fixed regression causing UART mode to fail, driver issue [#28](https://github.com/grblHAL/iMXRT1062/issues/28). + +Plugins: + +* SD card plugin: Fixed issue that crashes the controller if a client disconnects/reconnects while a job is running. +Added support for WebUI disconnect/reconnect without terminating a running job. + +--- + Build 20211130: Core: diff --git a/config.h b/config.h index 3f58888..d3a9fff 100644 --- a/config.h +++ b/config.h @@ -114,7 +114,7 @@ __NOTE:__ these definitions are only referenced in this file. Do __NOT__ change! // Enables code for debugging purposes. Not for general use and always in constant flux. // #define DEBUG // Uncomment to enable. Default disabled. -// #define DEBUGOUT // Uncomment to add HAL entry point for debug output. +// #define DEBUGOUT 0 // Uncomment to claim serial port with given instance number and add HAL entry point for debug output. // If spindle RPM is set by high-level commands to a spindle controller (eg. via Modbus) or the driver supports closed loop // spindle RPM control either uncomment the #define SPINDLE_RPM_CONTROLLED below or add SPINDLE_RPM_CONTROLLED as predefined symbol diff --git a/grbl.h b/grbl.h index 91e0e30..0296976 100644 --- a/grbl.h +++ b/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20211128 +#define GRBL_BUILD 20211203 // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/grbllib.c b/grbllib.c index c300b77..4c6f219 100644 --- a/grbllib.c +++ b/grbllib.c @@ -89,13 +89,6 @@ static bool kinematics_segment_line (float *target, plan_line_data_t *pl_data, b #endif -#ifdef DEBUGOUT -static void debug_out (bool on) -{ - // NOOP -} -#endif - void dummy_bool_handler (bool arg) { // NOOP @@ -166,11 +159,12 @@ int grbl_enter (void) kinematics.segment_line = kinematics_segment_line; // default to no segmentation #endif -#ifdef DEBUGOUT - hal.debug_out = debug_out; // must be overridden by driver to have any effect -#endif driver.init = driver_init(); +#ifdef DEBUGOUT + debug_stream_init(); +#endif + #if COMPATIBILITY_LEVEL > 0 hal.stream.suspend_read = NULL; #endif diff --git a/protocol.c b/protocol.c index f616fc0..407a58e 100644 --- a/protocol.c +++ b/protocol.c @@ -508,9 +508,11 @@ bool protocol_exec_rt_system (void) // Tell driver/plugins about reset. hal.driver_reset(); - if(hal.stream.suspend_read && hal.stream.suspend_read(false)) + if(!sys.flags.keep_input && hal.stream.suspend_read && hal.stream.suspend_read(false)) hal.stream.cancel_read_buffer(); // flush pending blocks (after M6) + sys.flags.keep_input = Off; + gc_init(); plan_reset(); /* if(sys.alarm_pending == Alarm_ProbeProtect) { diff --git a/stream.c b/stream.c index e18be29..ef043a7 100644 --- a/stream.c +++ b/stream.c @@ -172,6 +172,11 @@ ISR_CODE bool stream_enable_mpg (const io_stream_t *mpg_stream, bool mpg_mode) static stream_write_ptr dbg_write = NULL; +static void debug_stream_warning (uint_fast16_t state) +{ + report_message("Failed to initialize debug stream!", Message_Warning); +} + void debug_write (const char *s) { if(dbg_write) { @@ -180,13 +185,34 @@ void debug_write (const char *s) } } -void debug_stream_init (io_stream_t *stream) +static bool debug_claim_stream (io_stream_properties_t const *stream) { - memcpy(&hal.debug, stream, sizeof(io_stream_t)); - dbg_write = hal.debug.write; - hal.debug.write = debug_write; + io_stream_t const *claimed = NULL; - hal.debug.write(ASCII_EOL "UART debug active:" ASCII_EOL); + if(stream->type == StreamType_Serial && stream->flags.claimable && !stream->flags.claimed) { + + if(stream->instance == DEBUGOUT && (claimed = stream->claim(115200))) { + + memcpy(&hal.debug, claimed, sizeof(io_stream_t)); + dbg_write = hal.debug.write; + hal.debug.write = debug_write; + + if(hal.periph_port.set_pin_description) + hal.periph_port.set_pin_description(Output_TX, hal.debug.instance == 0 ? PinGroup_UART : PinGroup_UART2, "Debug out"); + } + } + + return claimed != NULL; +} + +bool debug_stream_init (void) +{ + if(stream_enumerate_streams(debug_claim_stream)) + hal.debug.write(ASCII_EOL "UART debug active:" ASCII_EOL); + else + protocol_enqueue_rt_command(debug_stream_warning); + + return hal.debug.write == debug_write; } #endif diff --git a/stream.h b/stream.h index 29e33ec..ba3f577 100644 --- a/stream.h +++ b/stream.h @@ -206,11 +206,20 @@ typedef union { }; } io_stream_flags_t; +typedef union { + uint8_t value; + struct { + uint8_t connected :1, + webui_connected :1, + unused :6; + }; +} io_stream_state_t; + //! Properties and handlers for stream I/O typedef struct { stream_type_t type; //!< Type of stream. uint8_t instance; //!< Instance of stream type, starts from 0. - bool connected; //!< Set to true by the driver if stream is connected. _Optional._ Under consideration. + io_stream_state_t state; //!< Optional status flags such as connected status. get_stream_buffer_count_ptr get_rx_buffer_free; //!< Handler for getting number of free characters in the input buffer. stream_write_ptr write; //!< Handler for writing string to current output stream only. stream_write_ptr write_all; //!< Handler for writing string to all active output streams. @@ -317,7 +326,7 @@ bool stream_enumerate_streams (stream_enumerate_callback_ptr callback); #ifdef DEBUGOUT void debug_write (const char *s); -void debug_stream_init (io_stream_t *stream); +bool debug_stream_init (void); #endif #ifdef __cplusplus diff --git a/system.h b/system.h index a23e4fb..01d7cff 100644 --- a/system.h +++ b/system.h @@ -194,15 +194,17 @@ typedef struct { typedef union { uint16_t value; struct { - uint16_t mpg_mode :1, //!< MPG mode flag. Set when switched to secondary input stream. (unused for now) + uint16_t mpg_mode :1, //!< MPG mode flag. Set when switched to secondary input stream. (unused for now). probe_succeeded :1, //!< Tracks if last probing cycle was successful. soft_limit :1, //!< Tracks soft limit errors for the state machine. exit :1, //!< System exit flag. Used in combination with abort to terminate main loop. - block_delete_enabled :1, //!< Set to true to enable block delete + block_delete_enabled :1, //!< Set to true to enable block delete. feed_hold_pending :1, delay_overrides :1, optional_stop_disable :1, - single_block :1; //!< Set to true to disable M1 (optional stop), via realtime command + single_block :1, //!< Set to true to disable M1 (optional stop), via realtime command. + keep_input :1, //!< Set to true to not flush stream input buffer on executing STOP. + unused :6; }; } system_flags_t;