Add extracted tools: CitrineOS, OpenOCPP, ShapeShifter
- CitrineOS core extracted (CSMS OCPP 2.0.1) - OpenOCPP extracted (firmware OCPP 1.6J/2.0.1) - ShapeShifter library installed (pip install -e) - ShapeShifter specification extracted - EVerest extracted TODO updated with progress
This commit is contained in:
37
tools/EVerest-main/lib/everest/io/src/serial/event_pty.cpp
Normal file
37
tools/EVerest-main/lib/everest/io/src/serial/event_pty.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include <cstring>
|
||||
#include <everest/io/serial/event_pty.hpp>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace everest::lib::io::serial {
|
||||
|
||||
void event_pty::set_status_handler(cb_status const& handler) {
|
||||
m_status = handler;
|
||||
}
|
||||
|
||||
void event_pty::set_data_handler(cb_rx const& handler) {
|
||||
m_data = handler;
|
||||
set_rx_handler([this, handler](auto const& pl, auto& obj) {
|
||||
if (pl.size() > 0) {
|
||||
if (pl[0] == 0) {
|
||||
if (m_data) {
|
||||
m_data({pl.begin() + 1, pl.end()}, obj);
|
||||
}
|
||||
} else {
|
||||
if (m_status) {
|
||||
m_status(get_raw_handler()->get_status());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
std::string event_pty::get_slave_path() {
|
||||
return get_raw_handler()->get_slave_path();
|
||||
}
|
||||
|
||||
} // namespace everest::lib::io::serial
|
||||
100
tools/EVerest-main/lib/everest/io/src/serial/pty_handler.cpp
Normal file
100
tools/EVerest-main/lib/everest/io/src/serial/pty_handler.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest
|
||||
|
||||
#include <cstring>
|
||||
#include <errno.h>
|
||||
#include <everest/io/serial/pty_handler.hpp>
|
||||
#include <iostream>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace everest::lib::io::serial {
|
||||
|
||||
bool pty_handler::tx(PayloadT& data) {
|
||||
auto status = ::write(m_dev.master_fd, data.data(), data.size());
|
||||
if (status == -1) {
|
||||
error_id = errno;
|
||||
std::cout << "ERROR: Failed to write to pty master." << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (status < static_cast<ssize_t>(data.size())) {
|
||||
// We have a reference to the current data. Replace it with what is left to be written
|
||||
// and return false. This signals the current block cannot be removed from the buffer.
|
||||
data = {data.begin() + status, data.end()};
|
||||
return false;
|
||||
}
|
||||
error_id = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pty_handler::rx(PayloadT& data) {
|
||||
// This should not be expensive, since capacity is only touched once, since
|
||||
// data is expected to stay the same object during the livetime of this instance
|
||||
data.resize(buffer_size_limit);
|
||||
auto n_bytes = ::read(m_dev.master_fd, data.data(), data.size());
|
||||
if (n_bytes == -1) {
|
||||
error_id = errno;
|
||||
return false;
|
||||
}
|
||||
data.resize(n_bytes);
|
||||
error_id = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pty_handler::open() {
|
||||
auto mypty = serial::openpty();
|
||||
if (not mypty.has_value()) {
|
||||
error_id = errno;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto aware = serial::make_pty_mode_aware(mypty.value());
|
||||
if (not aware) {
|
||||
std::cout << "ERROR: Preparing pty for packet mode and extproc" << std::endl;
|
||||
error_id = errno;
|
||||
return false;
|
||||
}
|
||||
auto binary = serial::set_binary_mode(mypty->slave_fd);
|
||||
if (not binary) {
|
||||
std::cout << "ERROR: Preparing pty for binary mode" << std::endl;
|
||||
error_id = errno;
|
||||
return false;
|
||||
}
|
||||
m_dev = std::move(mypty.value());
|
||||
error_id = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
int pty_handler::get_fd() const {
|
||||
return m_dev.master_fd;
|
||||
}
|
||||
|
||||
pty_status pty_handler::get_status() {
|
||||
pty_status result;
|
||||
struct termios status;
|
||||
auto attr_res = tcgetattr(m_dev.master_fd, &status);
|
||||
if (attr_res == -1) {
|
||||
error_id = errno;
|
||||
std::cout << "Failed to get attributes" << std::endl;
|
||||
return result;
|
||||
}
|
||||
|
||||
result.ixon = status.c_iflag & IXON; // enable xon/xoff flow control on output
|
||||
result.ixoff = status.c_iflag & IXOFF; // enable xon/xoff flow control on input
|
||||
result.cstopb = status.c_cflag & CSTOPB; // two stop bits instead of one
|
||||
result.cbaud = cfgetospeed(&status);
|
||||
|
||||
error_id = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
int pty_handler::get_error() const {
|
||||
return error_id;
|
||||
}
|
||||
|
||||
std::string pty_handler::get_slave_path() const {
|
||||
return m_dev.slave_path;
|
||||
}
|
||||
|
||||
} // namespace everest::lib::io::serial
|
||||
76
tools/EVerest-main/lib/everest/io/src/serial/serial.cpp
Normal file
76
tools/EVerest-main/lib/everest/io/src/serial/serial.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2020 - 2025 Pionix GmbH and Contributors to EVerest
|
||||
#include <cstdlib>
|
||||
#include <everest/io/serial/serial.hpp>
|
||||
#include <fcntl.h>
|
||||
#include <optional>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace everest::lib::io::serial {
|
||||
|
||||
std::optional<pty> openpty() {
|
||||
pty result;
|
||||
|
||||
result.master_fd = event::unique_fd(::posix_openpt(O_RDWR | O_NOCTTY));
|
||||
if (not result.master_fd.is_fd()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
if (::grantpt(result.master_fd) == -1) {
|
||||
return std::nullopt;
|
||||
}
|
||||
if (::unlockpt(result.master_fd) == -1) {
|
||||
return std::nullopt;
|
||||
}
|
||||
auto mb_name = ::ptsname(result.master_fd);
|
||||
if (mb_name == 0) {
|
||||
return std::nullopt;
|
||||
}
|
||||
result.slave_path = mb_name;
|
||||
result.slave_fd = event::unique_fd(::open(mb_name, 0));
|
||||
if (not result.slave_fd.is_fd()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool set_packet_mode(int fd) {
|
||||
int nonzero = 1;
|
||||
return ioctl(fd, TIOCPKT, &nonzero) == 0;
|
||||
}
|
||||
|
||||
bool set_extproc_flag(int fd) {
|
||||
struct termios tio;
|
||||
|
||||
if (tcgetattr(fd, &tio) == -1) {
|
||||
return false;
|
||||
}
|
||||
tio.c_lflag |= EXTPROC;
|
||||
|
||||
if (tcsetattr(fd, TCSANOW, &tio) == -1) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool set_binary_mode(int fd) {
|
||||
struct termios tty;
|
||||
if (tcgetattr(fd, &tty) < 0) {
|
||||
return false;
|
||||
}
|
||||
cfmakeraw(&tty);
|
||||
|
||||
if (tcsetattr(fd, TCSAFLUSH, &tty) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool make_pty_mode_aware(pty const& item) {
|
||||
return set_packet_mode(item.master_fd) && set_extproc_flag(item.slave_fd);
|
||||
}
|
||||
|
||||
} // namespace everest::lib::io::serial
|
||||
Reference in New Issue
Block a user