yarf 0.1
Yet Another RepRap Firmware
|
The g-code component parses incoming g-code commands and calls the corresponding functions in the commands component. More...
#include "gcode.h"
#include "yarf.h"
#include "commands.h"
#include <math.h>
#include <stdbool.h>
#include <string.h>
Go to the source code of this file.
Data Structures | |
struct | gcode_command |
Structure representing a parsed g-code command. More... | |
Defines | |
#define | N_SEEN _BV(0) |
#define | CODE_SEEN _BV(1) |
#define | X_SEEN _BV(2) |
#define | Y_SEEN _BV(3) |
#define | Z_SEEN _BV(4) |
#define | E_SEEN _BV(5) |
#define | F_SEEN _BV(6) |
#define | S_SEEN _BV(7) |
#define | CS_SEEN _BV(8) |
#define | COORD_SEEN (X_SEEN | Y_SEEN | Z_SEEN | E_SEEN | F_SEEN | S_SEEN) |
Functions | |
static int | get_signed_long (char *s, long *l) |
Reads a signed long integer from a given string and returns the number of characters read. | |
static int | get_signed_int (char *s, int *i) |
Reads a signed integer from a given string and returns the number of characters read. | |
static int | get_uint8_t (char *s, uint8_t *u) |
Reads an unsigned 8-bit integer from a given string and returns the number of characters read or -1 if the integer read was too large to fit in an 8-bit unsigned integer field. | |
static int | get_float (char *s, float *f) |
Reads a float from a given string and returns the number of characters read. | |
static unsigned char | count_whitespace (char *s) |
Counts the number of whitespace characters at the start of a given string. | |
static void | clear_command (gcode_command *cmd) |
Clears a given g-code command data structure. | |
static uint8_t | checksum (char *s, size_t length) |
Calculates the checksum of a g-code command with a given length. | |
static int | parse_command (gcode_command *cmd) |
Reads a g-code command from the host stream, parses it and places the result into a given g-code command data structure. | |
static void | send_resend (unsigned long line_number) |
Sends a g-code resend command to the host for a given line number. | |
static void | send_reply (gcode_command *cmd, cmd_response_t *r) |
Sends a given g-code response to the host, as a reply to a given g-code command. | |
static void | command_unknown (cmd_response_t *r) |
Initializes a g-code response to be an 'unknown command' response. | |
static void | dispatch_command (gcode_command *cmd, cmd_response_t *r) |
Dispatches a given g-code command to the command component for execution and stores the response in a variable pointed to by a given pointer. | |
void | gcode_init (FILE *host_stream) |
Initializes the g-code component. | |
int | gcode_process_command () |
Reads and processes an incoming g-code command from the host stream. | |
Variables | |
static FILE * | host |
Stream from which to read the g-codes and on which to output responses. | |
static long | expected_line_number |
The expected line number of the next g-code command to be received. |
The g-code component parses incoming g-code commands and calls the corresponding functions in the commands component.
Definition in file gcode.c.
static uint8_t checksum | ( | char * | s, |
size_t | length | ||
) | [static] |
static void clear_command | ( | gcode_command * | cmd | ) | [static] |
static void command_unknown | ( | cmd_response_t * | r | ) | [static] |
static unsigned char count_whitespace | ( | char * | s | ) | [static] |
static void dispatch_command | ( | gcode_command * | cmd, |
cmd_response_t * | r | ||
) | [inline, static] |
Dispatches a given g-code command to the command component for execution and stores the response in a variable pointed to by a given pointer.
cmd | the g-code command to dispatch to the command component |
r | a pointer to the variable to write the response to |
void gcode_init | ( | FILE * | host_stream | ) |
int gcode_process_command | ( | void | ) |
static int get_float | ( | char * | s, |
float * | f | ||
) | [static] |
Reads a float from a given string and returns the number of characters read.
s | the string from which to read the signed integer |
f | pointer to the variable in which to write the number read |
This function skips any leading whitespace, and includes that whitespace in the number of characters read.
static int get_signed_int | ( | char * | s, |
int * | i | ||
) | [static] |
Reads a signed integer from a given string and returns the number of characters read.
s | the string from which to read the signed integer |
i | pointer to the variable in which to write the number read |
This function skips any leading whitespace, and includes that whitespace in the number of characters read.
static int get_signed_long | ( | char * | s, |
long * | l | ||
) | [static] |
Reads a signed long integer from a given string and returns the number of characters read.
s | the string from which to read the signed long integer |
l | pointer to the variable in which to write the number read |
This function skips any leading whitespace, and includes that whitespace in the number of characters read.
static int get_uint8_t | ( | char * | s, |
uint8_t * | u | ||
) | [static] |
Reads an unsigned 8-bit integer from a given string and returns the number of characters read or -1 if the integer read was too large to fit in an 8-bit unsigned integer field.
s | the string from which to read the unsigned 8-bit integer |
u | pointer to the variable in which to write the number read |
This function skips any leading whitespace, and includes that whitespace in the number of characters read.
static int parse_command | ( | gcode_command * | cmd | ) | [static] |
Reads a g-code command from the host stream, parses it and places the result into a given g-code command data structure.
cmd | pointer to the variable in which to return the parsed g-code command |
static void send_reply | ( | gcode_command * | cmd, |
cmd_response_t * | r | ||
) | [inline, static] |