-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RRF: add support for sending gcode checksums (#2250)
* RRF: add support for sending gcode checksums * Update RRFSendCmd.h Co-authored-by: BigTreeTech <38851044+bigtreetech@users.noreply.github.com>
- Loading branch information
1 parent
7d0332a
commit e5f8706
Showing
3 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "RRFSendCmd.h" | ||
#include "Serial.h" | ||
#include <stdio.h> | ||
|
||
static uint8_t n_sent = 0; | ||
static uint32_t line_number = 0; | ||
static uint8_t checksum = 0; | ||
|
||
void sendCharAndChecksum(const char c) | ||
{ | ||
checksum ^= c; | ||
Serial_Putchar(SERIAL_PORT, c); | ||
n_sent++; | ||
} | ||
|
||
void sendChar(const char c) | ||
{ | ||
if (c == '\n') | ||
{ | ||
if (n_sent != 0) | ||
{ | ||
Serial_Putchar(SERIAL_PORT, '*'); | ||
char digit0 = checksum % 10 + '0'; | ||
checksum /= 10; | ||
char digit1 = checksum % 10 + '0'; | ||
checksum /= 10; | ||
if (checksum != 0) | ||
{ | ||
Serial_Putchar(SERIAL_PORT, checksum + '0'); | ||
} | ||
Serial_Putchar(SERIAL_PORT, digit1); | ||
Serial_Putchar(SERIAL_PORT, digit0); | ||
} | ||
Serial_Putchar(SERIAL_PORT, c); | ||
n_sent = 0; | ||
} | ||
else | ||
{ | ||
if (n_sent == 0) | ||
{ | ||
char number[11]; | ||
checksum = 0; | ||
sendCharAndChecksum('N'); | ||
snprintf(number, 11, "%lu", line_number++); | ||
rrfSendCmd(number); | ||
sendCharAndChecksum(' '); | ||
} | ||
sendCharAndChecksum(c); | ||
} | ||
} | ||
|
||
void rrfSendCmd(const char* cmd_ptr) { | ||
while (*cmd_ptr != 0) | ||
{ | ||
sendChar(*cmd_ptr++); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef _RRF_SEND_CMD_H_ | ||
#define _RRF_SEND_CMD_H_ | ||
|
||
void rrfSendCmd(const char* cmd_ptr); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters