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

Multistream communications #529

Merged
merged 28 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
44c1fa4
modify serial to deal with multiple streams
Paciente8159 Oct 8, 2023
72cc38f
modify serial to deal with multiple streams
Paciente8159 Oct 9, 2023
3494d04
Update system_menu.c
Paciente8159 Oct 9, 2023
6fb119b
improved code for simple stream (UNO)
Paciente8159 Oct 10, 2023
44797bd
fixed null char reading from eeprom
Paciente8159 Oct 10, 2023
b509e55
updated ESP32
Paciente8159 Oct 10, 2023
8880a54
Modified ESP8266
Paciente8159 Oct 10, 2023
da6a4ed
Modified LPC176x
Paciente8159 Oct 10, 2023
4fc9373
Modified RP2040
Paciente8159 Oct 10, 2023
bd18c3e
Modified SAMD21
Paciente8159 Oct 10, 2023
a21f983
Modified STM32F1
Paciente8159 Oct 10, 2023
8784242
Modified STM32F4
Paciente8159 Oct 10, 2023
42595a2
Update lpc176x_arduino.cpp
Paciente8159 Oct 10, 2023
98cba31
fixed soft reset
Paciente8159 Oct 10, 2023
dcd0adb
implementing multistream
Paciente8159 Oct 10, 2023
85c4b5d
multistream working
Paciente8159 Oct 11, 2023
0d6a82b
System menu stream integration
Paciente8159 Oct 11, 2023
fc38d2b
added readonly stream function
Paciente8159 Oct 11, 2023
bbba506
multitream fixes
Paciente8159 Oct 12, 2023
ceb6d7a
small fixes to utils and serial
Paciente8159 Oct 12, 2023
d4f363f
Update grbl_interface.h
Paciente8159 Oct 12, 2023
3923f21
recoded string functions to char instead of uint8
Paciente8159 Oct 13, 2023
dbc052e
fixed serial for undef stream output functions
Paciente8159 Oct 13, 2023
fd162ab
PIO environments renaming
Paciente8159 Oct 14, 2023
56575f2
Fixed build option for STM32
Paciente8159 Oct 14, 2023
d0e9f6f
Update esp32.ini
Paciente8159 Oct 14, 2023
584b016
Update platformio.ini
Paciente8159 Oct 14, 2023
3dbcede
Merge branch 'v1.8.x' into 522-fr-communication-revision-multi-contro…
Paciente8159 Oct 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,138 changes: 1,124 additions & 14 deletions makefiles/virtual/uCNC.dev

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[platformio]
include_dir=uCNC
src_dir=uCNC
default_envs = uno, ramps14, rambo, arduinoM0, bluepill_f103c8, blackpill_f401cc, d1, re_arm, d1_r32, rpi_pico_w
default_envs = AVR-UNO, AVR-MEGA2560-RAMPS-V1_4, AVR-RAMBO, SAMD21-Wemos-M0, STM32F1-Bluepill-F103C8, STM32F4-Blackpill-F401CC, ESP8266-Wemos-D1-R2, LPC176X-RE-ARM, ESP32-Wemos-D1-R32, RP2040-PICO-W
extra_configs =
uCNC/src/hal/boards/avr/avr.ini
uCNC/src/hal/boards/samd21/samd21.ini
Expand Down
8 changes: 4 additions & 4 deletions uCNC/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ __NOTE__: Not all event hooks might be listed here. To find all available event
| gcode_before_motion | gcode_exec_args_t* | ENABLE_PARSER_MODULES | Fires before a motion group command is executed (G0, G1, G2, etc...). Arg is a pointer to a gcode_exec_args_t struct |
| gcode_after_motion | gcode_exec_args_t* | ENABLE_PARSER_MODULES | Fires after a motion group command is executed (G0, G1, G2, etc...). Arg is a pointer to a gcode_exec_args_t struct |
| grbl_cmd | grbl_cmd_args_t* | ENABLE_PARSER_MODULES | Fires when a custom/unknown '$' grbl type command is received. Arg is a pointer to a grbl_cmd_args_t struct |
| parse_token | NULL | ENABLE_PARSER_MODULES | Fires when a custom/unknown token/char is received for further processing |
| parse_token | NULL | ENABLE_PARSER_MODULES | Fires when a custom/unknown token/uint8_t is received for further processing |
| parser_get_modes | uint8_t * | ENABLE_PARSER_MODULES | Fires when $G command is issued and the active modal states array is being requested (can be used to modify the active modes with extended gcodes). Arg is a pointer to an uint8_t array with the parser motion groups current values |
| parser_reset | NULL | ENABLE_PARSER_MODULES | Fires on parser reset |
| cnc_reset | NULL | ENABLE_MAIN_LOOP_MODULES | Fires when µCNC resets |
Expand Down Expand Up @@ -88,7 +88,7 @@ gcode_parse_args_t* - Pointer to a struct of type gcode_parse_args_t. The gcode_
```
typedef struct gcode_parse_args_
{
unsigned char word; // This is the GCode word being parsed (usually 'G' or 'M')
uint8_t word; // This is the GCode word being parsed (usually 'G' or 'M')
uint8_t code; // This is the GCode word argument converted to uint8_t format (example 98)
uint8_t error; // The parser current error code (STATUS_GCODE_EXTENDED_UNSUPPORTED)
float value; // This is the actual GCode word argument parsed as float. Useful if code has mantissa or is bigger then 255 (example 98.1)
Expand Down Expand Up @@ -123,9 +123,9 @@ grbl_cmd_args_t* - Pointer to a struct of type grbl_cmd_args_t. The grbl_cmd_arg
typedef struct grbl_cmd_args_
{
uint8_t *error; // current parser error state
unsigned char *cmd; // pointer to the command string
uint8_t *cmd; // pointer to the command string
uint8_t len; // command string length
char next_char; // next char to be read
uint8_t next_char; // next uint8_t to be read
} grbl_cmd_args_t;
```

Expand Down
32 changes: 22 additions & 10 deletions uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void cnc_run(void)
// tries to reset. If fails jumps to error
while (cnc_unlock(false) != UNLOCK_ERROR)
{
serial_select(SERIAL_UART);
// serial_select(SERIAL_UART);
cnc_state.loop_state = LOOP_RUNNING;

do
Expand All @@ -150,7 +150,7 @@ void cnc_run(void)

do
{
if (!serial_rx_is_empty())
if (serial_available())
{
if (serial_getc() == EOL)
{
Expand All @@ -174,15 +174,15 @@ bool cnc_exec_cmd(void)
uint32_t exec_time;
#endif
// process gcode commands
if (!serial_rx_is_empty())
if (serial_available())
{
uint8_t error = 0;
// protocol_echo();
uint8_t c = serial_peek();
switch (c)
{
case OVF:
serial_rx_clear();
serial_clear();
error = STATUS_OVERFLOW;
break;
case EOL: // not necessary but faster to catch empty lines and windows newline (CR+LF)
Expand Down Expand Up @@ -597,7 +597,7 @@ void cnc_reset(void)
cnc_state.alarm = EXEC_ALARM_NOALARM;

// clear all systems
serial_rx_clear();
serial_clear();
itp_clear();
planner_clear();
kinematics_init();
Expand All @@ -610,6 +610,7 @@ void cnc_reset(void)
#ifdef ENABLE_MAIN_LOOP_MODULES
EVENT_INVOKE(cnc_reset, NULL);
#endif
serial_broadcast(true);
protocol_send_string(MSG_STARTUP);
}

Expand Down Expand Up @@ -1029,9 +1030,20 @@ static void cnc_io_dotasks(void)

void cnc_run_startup_blocks(void)
{
serial_select(SERIAL_N0);
cnc_exec_cmd();
serial_select(SERIAL_N1);
cnc_exec_cmd();
serial_select(SERIAL_UART);
serial_broadcast(true);
if (settings_check_startup_gcode(STARTUP_BLOCK0_ADDRESS_OFFSET))
{
serial_stream_eeprom(STARTUP_BLOCK0_ADDRESS_OFFSET);
cnc_exec_cmd();
}

serial_broadcast(true);
if (settings_check_startup_gcode(STARTUP_BLOCK1_ADDRESS_OFFSET))
{
serial_stream_eeprom(STARTUP_BLOCK1_ADDRESS_OFFSET);
cnc_exec_cmd();
}

// reset streams
serial_stream_change(NULL);
}
2 changes: 1 addition & 1 deletion uCNC/src/core/motion_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ uint8_t mc_home_axis(uint8_t axis_mask, uint8_t axis_limit)
motion_data_t block_data = {0};
uint8_t limits_flags;
#ifdef ENABLE_MOTION_CONTROL_MODULES
homing_status_t homing_status __attribute__((__cleanup__(mc_home_axis_finalize))) = {axis, axis_limit, STATUS_OK};
homing_status_t homing_status __attribute__((__cleanup__(mc_home_axis_finalize))) = {axis_mask, axis_limit, STATUS_OK};
#endif

#ifdef ENABLE_G39_H_MAPPING
Expand Down
85 changes: 47 additions & 38 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ static float g92permanentoffset[AXIS_COUNT];
static int32_t rt_probe_step_pos[STEPPER_COUNT];
static float parser_last_pos[AXIS_COUNT];

static unsigned char parser_get_next_preprocessed(bool peek);
FORCEINLINE static void parser_get_comment(unsigned char start_char);
FORCEINLINE static uint8_t parser_get_token(unsigned char *word, float *value);
static uint8_t parser_get_next_preprocessed(bool peek);
FORCEINLINE static void parser_get_comment(uint8_t start_char);
FORCEINLINE static uint8_t parser_get_token(uint8_t *word, float *value);
FORCEINLINE static uint8_t parser_gcode_word(uint8_t code, uint8_t mantissa, parser_state_t *new_state, parser_cmd_explicit_t *cmd);
FORCEINLINE static uint8_t parser_mcode_word(uint8_t code, uint8_t mantissa, parser_state_t *new_state, parser_cmd_explicit_t *cmd);
FORCEINLINE static uint8_t parser_letter_word(unsigned char c, float value, uint8_t mantissa, parser_words_t *words, parser_cmd_explicit_t *cmd);
FORCEINLINE static uint8_t parser_letter_word(uint8_t c, float value, uint8_t mantissa, parser_words_t *words, parser_cmd_explicit_t *cmd);
static uint8_t parse_grbl_exec_code(uint8_t code);
static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *words, parser_cmd_explicit_t *cmd);
static uint8_t parser_validate_command(parser_state_t *new_state, parser_words_t *words, parser_cmd_explicit_t *cmd);
Expand Down Expand Up @@ -152,7 +152,7 @@ void parser_init(void)
uint8_t parser_read_command(void)
{
uint8_t error = STATUS_OK;
unsigned char c = serial_peek();
uint8_t c = serial_peek();

if (c == '$')
{
Expand Down Expand Up @@ -307,8 +307,8 @@ void parser_update_probe_pos(void)
static uint8_t parser_grbl_command(void)
{
serial_getc(); // eat $
unsigned char c = serial_peek();
unsigned char grbl_cmd_str[GRBL_CMD_MAX_LEN + 1];
uint8_t c = serial_peek();
uint8_t grbl_cmd_str[GRBL_CMD_MAX_LEN + 1];
uint8_t grbl_cmd_len = 0;

// if not IDLE
Expand All @@ -330,7 +330,7 @@ static uint8_t parser_grbl_command(void)

do
{
c = serial_getc();
c = serial_peek();
// toupper
if (c >= 'a' && c <= 'z')
{
Expand All @@ -339,8 +339,14 @@ static uint8_t parser_grbl_command(void)

if (!(c >= 'A' && c <= 'Z'))
{
if (c < '0' || c > '9' || grbl_cmd_len) // replaces old ungetc
{
serial_getc();
}
break;
}

serial_getc();
grbl_cmd_str[grbl_cmd_len++] = c;
} while ((grbl_cmd_len < GRBL_CMD_MAX_LEN));

Expand Down Expand Up @@ -377,7 +383,7 @@ static uint8_t parser_grbl_command(void)
{
float val = 0;
setting_offset_t setting_num = 0;
serial_ungetc();
// serial_ungetc();
error = parser_get_float(&val);
if (!error)
{
Expand Down Expand Up @@ -444,24 +450,27 @@ static uint8_t parser_grbl_command(void)
return STATUS_INVALID_STATEMENT;
}

settings_save_startup_gcode(block_address);
// run startup block
serial_broadcast(true);
serial_stream_eeprom(block_address);
error = parser_fetch_command(&next_state, &words, &cmd);
if (error)
if (error == STATUS_OK)
{
return error;
error = parser_validate_command(&next_state, &words, &cmd);
}
error = parser_validate_command(&next_state, &words, &cmd);
if (error)

serial_broadcast(false);
// reset streams
serial_stream_change(NULL);

if (error != STATUS_OK)
{
return error;
// the Gcode is not valid then erase the startup block
mcu_eeprom_putc(block_address, 0);
}
// everything ok reverts string and saves it
do
{
serial_ungetc();
} while (serial_peek() != '=');
serial_getc();
settings_save_startup_gcode(block_address);
return STATUS_OK;

return error;
case EOL:
return GRBL_SEND_STARTUP_BLOCKS;
}
Expand Down Expand Up @@ -537,7 +546,7 @@ static uint8_t parser_grbl_command(void)
}

#ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS
if (mcu_custom_grbl_cmd((char *)grbl_cmd_str, grbl_cmd_len, c) == STATUS_OK)
if (mcu_custom_grbl_cmd((uint8_t *)grbl_cmd_str, grbl_cmd_len, c) == STATUS_OK)
{
return STATUS_OK;
}
Expand Down Expand Up @@ -659,10 +668,9 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w
uint8_t wordcount = 0;
for (;;)
{
unsigned char word = 0;
uint8_t word = 0;
float value = 0;
// this flushes leading white chars and also takes care of processing comments
parser_get_next_preprocessed(true);

#ifdef ECHO_CMD
if (!wordcount)
{
Expand Down Expand Up @@ -1849,7 +1857,7 @@ uint8_t parser_get_float(float *value)
uint8_t fpcount = 0;
uint8_t result = NUMBER_UNDEF;

unsigned char c = parser_get_next_preprocessed(true);
uint8_t c = parser_get_next_preprocessed(true);

*value = 0;

Expand Down Expand Up @@ -1945,15 +1953,15 @@ uint8_t parser_get_float(float *value)
*/
#define COMMENT_OK 1
#define COMMENT_NOTOK 2
static void parser_get_comment(unsigned char start_char)
static void parser_get_comment(uint8_t start_char)
{
uint8_t comment_end = 0;
#ifdef PROCESS_COMMENTS
uint8_t msg_parser = 0;
#endif
for (;;)
{
unsigned char c = serial_peek();
uint8_t c = serial_peek();
switch (c)
{
// case '(': //error under RS274NGC (commented for Grbl compatibility)
Expand Down Expand Up @@ -2011,11 +2019,12 @@ static void parser_get_comment(unsigned char start_char)
}
}

static uint8_t parser_get_token(unsigned char *word, float *value)
static uint8_t parser_get_token(uint8_t *word, float *value)
{
unsigned char c = serial_getc();
// this flushes leading white chars and also takes care of processing comments
uint8_t c = parser_get_next_preprocessed(false);

// if other char starts tokenization
// if other uint8_t starts tokenization
if (c >= 'a' && c <= 'z')
{
c -= 32; // uppercase
Expand All @@ -2032,7 +2041,7 @@ static uint8_t parser_get_token(unsigned char *word, float *value)
#ifdef ECHO_CMD
serial_putc(c);
#endif
if (c >= 'A' && c <= 'Z') // invalid recognized char
if (c >= 'A' && c <= 'Z') // invalid recognized uint8_t
{
if (!parser_get_float(value))
{
Expand Down Expand Up @@ -2341,7 +2350,7 @@ static uint8_t parser_mcode_word(uint8_t code, uint8_t mantissa, parser_state_t
return STATUS_OK;
}

static uint8_t parser_letter_word(unsigned char c, float value, uint8_t mantissa, parser_words_t *words, parser_cmd_explicit_t *cmd)
static uint8_t parser_letter_word(uint8_t c, float value, uint8_t mantissa, parser_words_t *words, parser_cmd_explicit_t *cmd)
{
uint16_t new_words = cmd->words;
switch (c)
Expand Down Expand Up @@ -2492,7 +2501,7 @@ static uint8_t parser_letter_word(unsigned char c, float value, uint8_t mantissa
#endif
break;
default:
if (c >= 'A' && c <= 'Z') // invalid recognized char
if (c >= 'A' && c <= 'Z') // invalid recognized uint8_t
{
return STATUS_GCODE_UNUSED_WORDS;
}
Expand All @@ -2509,9 +2518,9 @@ static uint8_t parser_letter_word(unsigned char c, float value, uint8_t mantissa
return STATUS_OK;
}

static unsigned char parser_get_next_preprocessed(bool peek)
static uint8_t parser_get_next_preprocessed(bool peek)
{
unsigned char c = serial_peek();
uint8_t c = serial_peek();

while (c == ' ' || c == '(' || c == ';')
{
Expand All @@ -2533,7 +2542,7 @@ static unsigned char parser_get_next_preprocessed(bool peek)

static void parser_discard_command(void)
{
unsigned char c = '@';
uint8_t c = '@';
#ifdef ECHO_CMD
serial_putc(c);
#endif
Expand Down
6 changes: 3 additions & 3 deletions uCNC/src/core/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ extern "C"
// generates a default delegate, event and handler hook
typedef struct gcode_parse_args_
{
unsigned char word;
uint8_t word;
uint8_t code;
uint8_t* error;
float value;
Expand Down Expand Up @@ -328,9 +328,9 @@ extern "C"
typedef struct grbl_cmd_args_
{
uint8_t *error;
unsigned char *cmd;
uint8_t *cmd;
uint8_t len;
char next_char;
uint8_t next_char;
} grbl_cmd_args_t;
DECL_EVENT_HANDLER(grbl_cmd);

Expand Down
Loading
Loading