Skip to content

Commit

Permalink
fixed null char reading from eeprom
Browse files Browse the repository at this point in the history
  • Loading branch information
Paciente8159 committed Oct 10, 2023
1 parent 6fb119b commit 44797bd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion makefiles/virtual/uCNC.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Libs=
PrivateResource=
ResourceIncludes=
MakeIncludes=
Compiler=-DWIN_INTERFACE=2 -DENABLE_EXTRA_SYSTEM_CMDS -DWIN_COM_NAME=COM11 -DBOARD=BOARD_VIRTUAL -DMCU=MCU_VIRTUAL_WIN_@@_
Compiler=-DWIN_INTERFACE=2 -DENABLE_EXTRA_SYSTEM_CMDS -DWIN_COM_NAME=COM11 -DBOARD=BOARD_VIRTUAL -DMCU=MCU_VIRTUAL -DDISABLE_MULTISTREAM_SERIAL_@@_
CppCompiler=_@@_
Linker=-lws2_32_@@_
IsCpp=0
Expand Down
14 changes: 10 additions & 4 deletions uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1030,10 +1030,16 @@ static void cnc_io_dotasks(void)
void cnc_run_startup_blocks(void)
{
serial_broadcast(true);
serial_stream_eeprom(STARTUP_BLOCK0_ADDRESS_OFFSET);
cnc_exec_cmd();
serial_stream_eeprom(STARTUP_BLOCK1_ADDRESS_OFFSET);
cnc_exec_cmd();
if (settings_check_startup_gcode(STARTUP_BLOCK0_ADDRESS_OFFSET))
{
serial_stream_eeprom(STARTUP_BLOCK0_ADDRESS_OFFSET);
cnc_exec_cmd();
}
if (settings_check_startup_gcode(STARTUP_BLOCK1_ADDRESS_OFFSET))
{
serial_stream_eeprom(STARTUP_BLOCK1_ADDRESS_OFFSET);
cnc_exec_cmd();
}
serial_broadcast(false);
serial_stream_change(NULL);
}
6 changes: 3 additions & 3 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,7 @@ static uint8_t parser_fetch_command(parser_state_t *new_state, parser_words_t *w
{
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 @@ -2021,7 +2020,8 @@ static void parser_get_comment(uint8_t start_char)

static uint8_t parser_get_token(uint8_t *word, float *value)
{
uint8_t 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 uint8_t starts tokenization
if (c >= 'a' && c <= 'z')
Expand Down
4 changes: 4 additions & 0 deletions uCNC/src/interface/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ static FORCEINLINE uint8_t _serial_peek(void)
while (!serial_available())
;
peek = stream_getc();
// prevents null char reading from eeprom
if(!peek) {
peek = '\n';
}
serial_peek_buffer = peek;
return peek;
}
Expand Down
16 changes: 11 additions & 5 deletions uCNC/src/interface/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ bool settings_allows_negative(setting_offset_t id)
}
#endif
#ifdef ENABLE_SKEW_COMPENSATION
if (id >=37 && id <= 39)
if (id >= 37 && id <= 39)
{
return true;
}
Expand Down Expand Up @@ -595,6 +595,9 @@ void settings_erase(uint16_t address, uint8_t size)

bool settings_check_startup_gcode(uint16_t address)
{
serial_putc('>');
serial_putc(':');

#ifndef RAM_ONLY_SETTINGS
uint8_t size = (RX_BUFFER_SIZE - 1); // defined in serial.h
uint8_t crc = 0;
Expand All @@ -615,14 +618,16 @@ bool settings_check_startup_gcode(uint16_t address)

if (crc ^ mcu_eeprom_getc(cmd_address))
{
serial_putc('>');
serial_putc(':');
protocol_send_error(STATUS_SETTING_READ_FAIL);
settings_erase(address, 1);
return false;
}
#endif

return true;
#else
protocol_send_ok();
return false;
#endif
}

void settings_save_startup_gcode(uint16_t address)
Expand All @@ -635,7 +640,8 @@ void settings_save_startup_gcode(uint16_t address)
{
c = serial_getc();
crc = crc7(c, crc);
mcu_eeprom_putc(address++, (uint8_t)c);
mcu_eeprom_putc(address, (uint8_t)c);
address++;
size--;
} while (size && c);

Expand Down

0 comments on commit 44797bd

Please sign in to comment.