Skip to content

Commit

Permalink
RRF: add support for sending gcode checksums (#2250)
Browse files Browse the repository at this point in the history
* RRF: add support for sending gcode checksums

* Update RRFSendCmd.h

Co-authored-by: BigTreeTech <38851044+bigtreetech@users.noreply.github.com>
  • Loading branch information
pfn and bigtreetech committed Nov 18, 2021
1 parent 7d0332a commit e5f8706
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
57 changes: 57 additions & 0 deletions TFT/src/User/API/RRFSendCmd.c
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++);
}
}
6 changes: 6 additions & 0 deletions TFT/src/User/API/RRFSendCmd.h
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
10 changes: 9 additions & 1 deletion TFT/src/User/API/interfaceCmd.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "interfaceCmd.h"
#include "includes.h"
#include "RRFSendCmd.h"

#define CMD_QUEUE_SIZE 20

Expand Down Expand Up @@ -221,7 +222,14 @@ bool sendCmd(bool purge, bool avoidTerminal)

if (!purge) // if command is not purged, send it to printer
{
Serial_Puts(SERIAL_PORT, cmd_ptr);
if (infoMachineSettings.firmwareType != FW_REPRAPFW && infoMachineSettings.firmwareType != FW_NOT_DETECTED)
{
Serial_Puts(SERIAL_PORT, cmd_ptr);
}
else
{
rrfSendCmd(cmd_ptr);
}
setCurrentAckSrc(cmd_port_index);
}

Expand Down

0 comments on commit e5f8706

Please sign in to comment.