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

Add a CI #8

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI
on:
push:
branches:
- master
pull_request:

jobs:
BuildLinux:
runs-on: ubuntu-20.04 # test slightly older ubuntu.
strategy:
fail-fast: false
matrix:
compiler:
- g++
- clang++

name: Build ${{matrix.compiler}}
steps:
- name: Get the Source
uses: actions/checkout@v3

- name: Configure shell
run: |
echo "CXX=${{ matrix.compiler }}" >> $GITHUB_ENV
echo "CXXFLAGS=-Werror" >> $GITHUB_ENV

- name: Build
run: |
make -k

BuildMac:
name: Build Mac
runs-on: macos-latest
steps:
- name: Get the Source
uses: actions/checkout@v3

- name: Build
run: |
make -k
32 changes: 19 additions & 13 deletions machine-connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include <charconv>
#include <string>

#if defined(__APPLE__) && !defined(USE_TERMIOS)
# define USE_TERMIOS
#endif

#ifdef USE_TERMIOS
# include <termios.h>
#else
Expand Down Expand Up @@ -45,7 +49,9 @@ static bool SetTTYSpeed(tty_termios_t *tty, int speed_number) {
case 57600: speed = B57600; break;
case 115200: speed = B115200; break;
case 230400: speed = B230400; break;
#ifdef B460800
case 460800: speed = B460800; break;
#endif
default:
fprintf(stderr,
"Invalid speed '%d'; valid speeds are "
Expand Down Expand Up @@ -113,10 +119,9 @@ static bool SetTTYParams(int fd, std::string_view parameters) {

if (param[0] == 'b' || param[0] == 'B') {
int s;
if (auto r = std::from_chars(param.begin()+1, param.end(), s);
if (auto r = std::from_chars(param.begin() + 1, param.end(), s);
r.ec == std::errc()) {
if (!SetTTYSpeed(&tty, s))
return false;
if (!SetTTYSpeed(&tty, s)) return false;
}
continue;
}
Expand All @@ -125,8 +130,7 @@ static bool SetTTYParams(int fd, std::string_view parameters) {
bool flag_positive = true;
if (param[0] == '+') {
param = param.substr(1);
}
else if (param[0] == '-') {
} else if (param[0] == '-') {
flag_positive = false;
param = param.substr(1);
}
Expand All @@ -137,10 +141,9 @@ static bool SetTTYParams(int fd, std::string_view parameters) {
} else {
tty.c_cflag &= ~CRTSCTS;
}
}
else {
fprintf(stderr, "Unknown option %.*s\n",
(int)param.size(), param.data());
} else {
fprintf(stderr, "Unknown option %.*s\n", (int)param.size(),
param.data());
return false;
}
}
Expand Down Expand Up @@ -226,14 +229,17 @@ int OpenTCPSocket(const char *host) {
return fd;
}

static int OpenTTY(const char *descriptor) {
const char *comma = strchrnul(descriptor, ',');
const std::string path(descriptor, comma);
static int OpenTTY(std::string_view descriptor) {
auto first_comma = descriptor.find(',');
const std::string path(descriptor.substr(0, first_comma));
const std::string_view tty_params =
(first_comma != std::string_view::npos)
? descriptor.substr(first_comma + 1) : "";
const int fd = open(path.c_str(), O_RDWR | O_NOCTTY | O_SYNC);
if (fd < 0) {
return -1;
}
if (!SetTTYParams(fd, *comma ? comma + 1 : "")) {
if (!SetTTYParams(fd, tty_params)) {
return -1;
}
return fd;
Expand Down
19 changes: 9 additions & 10 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ int main(int argc, char *argv[]) {
bool print_communication = true; // print line+block to $log_gcode
bool print_unusual_messages = true; // messages outside handshake

// No cli options yet.
size_t buffer_size = (1 << 20); // Input buffer in bytes.
FILE *log_gcode = stderr; // Write gcode communication log here.
FILE *log_info = stderr; // info log, can be switched off with -q
// No cli options for the following yet. Make configurable ?
const size_t buffer_size = (1 << 20); // Input buffer in bytes
FILE *const log_gcode = stderr; // Log gcode communication here.
FILE *log_info = stderr; // info log, switched off with -q

const char *EXTRA_MESSAGE_ON = "\033[7m";
const char *EXTRA_MESSAGE_ON = "\033[7m";
const char *EXTRA_MESSAGE_OFF = "\033[0m";
if (!isatty(STDERR_FILENO)) {
EXTRA_MESSAGE_ON = EXTRA_MESSAGE_OFF = "";
Expand Down Expand Up @@ -242,9 +242,8 @@ int main(int argc, char *argv[]) {
// Even without OK flow control, we need to wait as machine might
// just reset on connect.
if (machine) {
machine->DiscardPendingInput(
initial_squash_chatter_ms,
print_communication ? log_gcode : nullptr);
machine->DiscardPendingInput(initial_squash_chatter_ms,
print_communication ? log_gcode : nullptr);
}

if (log_info) {
Expand Down Expand Up @@ -299,8 +298,8 @@ int main(int argc, char *argv[]) {
fprintf(log_gcode,
use_ok_flow_control ? "<< OK\n" : "\n");
} else {
while (!print_msg.empty() && isspace(
*(print_msg.end() - 1))) {
while (!print_msg.empty() &&
isspace(*(print_msg.end() - 1))) {
print_msg.remove_suffix(1);
}
fprintf(log_gcode, "\n%s%.*s%s", EXTRA_MESSAGE_ON,
Expand Down