Skip to content

Commit

Permalink
DonkeyPi initial rename.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelventura committed Jan 6, 2023
1 parent 70aadf2 commit 38a344e
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ erl_crash.dump
*.ez

# Ignore package tarball (built via "mix hex.build").
ash_serial-*.tar
dpi_serial-*.tar

# Temporary files, for example, from tests.
/tmp/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ OUTDIR = $(PRIVDIR)/$(MIX_TARGET)

#-pedantic -Wall allow unused during debugging
#-Werror remove to run on macos with lots of warnings
PORT_TARGET = $(OUTDIR)/ash_serial
PORT_TARGET = $(OUTDIR)/dpi_serial
PORT_SOURCES = $(SRCDIR)/*.c
PORT_HEADERS = $(SRCDIR)/*.h
PORT_CFLAGS = -g0 -O3 -pedantic -Wall -Wextra -D_XOPEN_SOURCE=700
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Ash.Serial
# Dpi.Serial

- https://github.com/samuelventura/sport
- https://github.com/samuelventura/sniff
2 changes: 1 addition & 1 deletion lib/list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# {"ttyUSB2", "FTDI_USB_<->_Serial_Cable_FT0K2HYD_2"},
# {"ttyUSB3", "FTDI_USB_<->_Serial_Cable_FT0K2HYD_3"}

defmodule Ash.Serial.List do
defmodule Dpi.Serial.List do
def find(name) do
Enum.find_value(list(), name, fn {dev, aka} ->
if name == dev or name == aka, do: dev
Expand Down
2 changes: 1 addition & 1 deletion lib/params.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Ash.Serial.Params do
defmodule Dpi.Serial.Params do
@configs [
"8N1",
"8N2",
Expand Down
6 changes: 3 additions & 3 deletions lib/port.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Ash.Serial.Port do
defmodule Dpi.Serial.Port do
@opts [:path, :config, :speed]

def open(opts) do
Expand All @@ -8,9 +8,9 @@ defmodule Ash.Serial.Port do
end

opts = [:binary, :exit_status, :stream, args: args]
priv = :code.priv_dir(:ash_serial)
priv = :code.priv_dir(:dpi_serial)
target = File.read!("#{priv}/target") |> String.trim()
Port.open({:spawn_executable, '#{priv}/#{target}/ash_serial'}, opts)
Port.open({:spawn_executable, '#{priv}/#{target}/dpi_serial'}, opts)
end

def write!(port, iodata) do
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
defmodule Ash.Serial.MixProject do
defmodule Dpi.Serial.MixProject do
use Mix.Project

def project do
[
app: :ash_serial,
app: :dpi_serial,
version: "0.1.0",
elixir: "~> 1.13",
make_clean: ["clean"],
Expand Down
18 changes: 9 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "main.h"

char* ash_arg(const char *str, const char *pre)
char* dpi_arg(const char *str, const char *pre)
{
int len = strlen(pre);
if (strncmp(str, pre, len) != 0) return NULL;
Expand All @@ -9,7 +9,7 @@ char* ash_arg(const char *str, const char *pre)

#define DATA_LEN 256

//ash_serial --path=/dev/ttyUSB0 --config=8N1 --speed=9600
//dpi_serial --path=/dev/ttyUSB0 --config=8N1 --speed=9600
int main(int argc, char *argv[])
{
UNUSED(argc);
Expand All @@ -20,17 +20,17 @@ int main(int argc, char *argv[])
for(int i=1; i<argc; i++)
{
char *p;
p = ash_arg(argv[i], "--path=");
p = dpi_arg(argv[i], "--path=");
if (p != NULL) serial.path = p;
p = ash_arg(argv[i], "--config=");
p = dpi_arg(argv[i], "--config=");
if (p != NULL) serial.config = p;
p = ash_arg(argv[i], "--speed=");
p = dpi_arg(argv[i], "--speed=");
if (p != NULL) serial.speed = atoi(p);
}
serial_open(&serial);
if (serial.error != NULL)
{
ash_crash("%s %s %d: %s", serial.path, serial.config, serial.speed, serial.error);
dpi_crash("%s %s %d: %s", serial.path, serial.config, serial.speed, serial.error);
}
char* data[DATA_LEN];
struct pollfd fds[2];
Expand All @@ -40,20 +40,20 @@ int main(int argc, char *argv[])
fds[1].events = POLLIN | POLLHUP;
while(1) {
int r = poll(fds, 2, -1);
if (r < 0) ash_crash("events poll");
if (r < 0) dpi_crash("events poll");
if (fds[0].revents & POLLHUP) break;
if (fds[1].revents & POLLHUP) break;
if (fds[0].revents & POLLIN) {
int rn = read(0, data, DATA_LEN);
if (rn <= 0) break;
int wn = write(serial.fd, data, rn);
if (wn != rn) ash_crash("fds[0] wn %d != rn %d", wn, rn);
if (wn != rn) dpi_crash("fds[0] wn %d != rn %d", wn, rn);
}
if (fds[1].revents & POLLIN) {
int rn = read(serial.fd, data, DATA_LEN);
if (rn <= 0) break;
int wn = write(1, data, rn);
if (wn != rn) ash_crash("fds[1] wn %d != rn %d", wn, rn);
if (wn != rn) dpi_crash("fds[1] wn %d != rn %d", wn, rn);
}
}
exit(1);
Expand Down
22 changes: 11 additions & 11 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@
#define UNUSED3(x,y,z) UNUSED(x);UNUSED(y);UNUSED(z);
// #define MAX(x, y) ((x)>(y)?(x):(y))

void ash_debug(const char* fmt, ...);
void ash_crash(const char* fmt, ...);
void dpi_debug(const char* fmt, ...);
void dpi_crash(const char* fmt, ...);

// #define __TRACE_ENABLED__

#ifdef __TRACE_ENABLED__

#define ash_trace(...) ash_debug(__VA_ARGS__)
#define ash_trace_every() ash_trace("%s:%s tid:%ul", __FILE__, __func__, pthread_self());
#define ash_trace_once() static bool _##__func__ = false; \
if (!_##__func__) ash_trace_every(); \
#define dpi_trace(...) dpi_debug(__VA_ARGS__)
#define dpi_trace_every() dpi_trace("%s:%s tid:%ul", __FILE__, __func__, pthread_self());
#define dpi_trace_once() static bool _##__func__ = false; \
if (!_##__func__) dpi_trace_every(); \
_##__func__ = true;

#else

#define ash_trace(...)
#define ash_trace_every()
#define ash_trace_once()
#define dpi_trace(...)
#define dpi_trace_every()
#define dpi_trace_once()

#endif

Expand All @@ -59,8 +59,8 @@ typedef struct {
const char *config; // 8N1 | 7E1 | 7O1
} Serial;

void ash_debug(const char* fmt, ...);
void ash_crash(const char* fmt, ...);
void dpi_debug(const char* fmt, ...);
void dpi_crash(const char* fmt, ...);

int serial_baud(int speed);
void serial_open(Serial *serial);
Expand Down
4 changes: 2 additions & 2 deletions src/tools.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "main.h"

void ash_debug(const char* fmt, ...)
void dpi_debug(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Expand All @@ -10,7 +10,7 @@ void ash_debug(const char* fmt, ...)
fflush(stderr);
}

void ash_crash(const char* fmt, ...)
void dpi_crash(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
Expand Down
6 changes: 3 additions & 3 deletions test/config_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Ash.Serial.ConfigTest do
defmodule Dpi.Serial.ConfigTest do
use ExUnit.Case
alias Ash.Serial.Port
alias Ash.Serial.Params
alias Dpi.Serial.Port
alias Dpi.Serial.Params

setup do
pid = Socat.start()
Expand Down
6 changes: 3 additions & 3 deletions test/speed_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Ash.Serial.SpeedTest do
defmodule Dpi.Serial.SpeedTest do
use ExUnit.Case
alias Ash.Serial.Port
alias Ash.Serial.Params
alias Dpi.Serial.Port
alias Dpi.Serial.Params

setup do
pid = Socat.start()
Expand Down
6 changes: 3 additions & 3 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ExUnit.start()

defmodule Tests do
alias Ash.Serial.Port
alias Dpi.Serial.Port

@toms 200

Expand Down Expand Up @@ -32,8 +32,8 @@ defmodule Tests do
end

defmodule Socat do
@socat0 "/tmp/ash.socat0"
@socat1 "/tmp/ash.socat1"
@socat0 "/tmp/dpi.socat0"
@socat1 "/tmp/dpi.socat1"
@args ["-d", "-d", "pty,link=#{@socat0}", "pty,link=#{@socat1}"]
@toms 200

Expand Down

0 comments on commit 38a344e

Please sign in to comment.