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

RRF: add support for sending gcode checksums #2250

Merged
merged 2 commits into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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++);
}
}
5 changes: 5 additions & 0 deletions TFT/src/User/API/RRFSendCmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef _RRF_SEND_CMD_H_
#define _RRF_SEND_CMD_H_

void rrfSendCmd(const char* cmd_ptr);
#endif
bigtreetech marked this conversation as resolved.
Show resolved Hide resolved
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