mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Replace custom python connector with ncat (#42)
* Replace custom made daemon with nmap-ncat * Use stderr to log ncat output * Refresh the branch
This commit is contained in:
9
connector/Dockerfile
Normal file
9
connector/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM alpine:edge
|
||||
|
||||
RUN apk add --no-cache coreutils nmap-ncat
|
||||
|
||||
EXPOSE 2560/tcp
|
||||
|
||||
SHELL ["/bin/ash", "-c"]
|
||||
CMD stty -F /dev/arduino -echo 115200 && \
|
||||
ncat -n -k -l 2560 </dev/arduino >/dev/arduino
|
19
connector/README.md
Normal file
19
connector/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Use a container to implement a serial to net bridge
|
||||
|
||||
This uses `ncat` by [namp](https://nmap.org/ncat/) to bridge a serial port to a network port. The serial port is passed to the Podman command (eg. `/dev/ttyUSB0`) and the network port is `2560`.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> Other variants of `nc` or `ncat` may not work as expected.
|
||||
|
||||
## Build and run the container
|
||||
|
||||
```bash
|
||||
$ podman buil -t dcc/bridge .
|
||||
$ podman run -d --device=/dev/ttyUSB0:/dev/arduino -p 2560:2560 --name dcc-bridge dcc/bridge
|
||||
```
|
||||
|
||||
It can be tested with `telnet`:
|
||||
|
||||
```bash
|
||||
$ telnet localhost 2560
|
||||
```
|
BIN
connector/simulator/CommandStation-EX-uno-13488e1.elf
Executable file
BIN
connector/simulator/CommandStation-EX-uno-13488e1.elf
Executable file
Binary file not shown.
8
connector/simulator/Dockerfile
Normal file
8
connector/simulator/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM dcc/bridge
|
||||
|
||||
RUN apk update && apk add --no-cache qemu-system-avr \
|
||||
&& mkdir /io
|
||||
ADD start.sh /usr/local/bin
|
||||
ADD CommandStation-EX*.elf /io
|
||||
|
||||
ENTRYPOINT ["/usr/local/bin/start.sh"]
|
13
connector/simulator/README.md
Normal file
13
connector/simulator/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Connector and AVR simulator
|
||||
|
||||
> [!WARNING]
|
||||
> The simulator is intended for light development and testing purposes only and far from being a complete replacement for a real hardware.
|
||||
|
||||
`qemu-system-avr` tries to use all the CPU cycles (leaving a CPU core stuck at 100%; limit CPU core usage to 10% via `--cpus 0.1`. It can be adjusted on slower machines.
|
||||
|
||||
```bash
|
||||
$ podman build -t dcc/connector:sim .
|
||||
$ podman run --init --cpus 0.1 -d -p 2560:2560 dcc/connector:sim
|
||||
```
|
||||
|
||||
All traffic will be collected on the container's `stderr` for debugging purposes.
|
11
connector/simulator/start.sh
Executable file
11
connector/simulator/start.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
PTY=0
|
||||
|
||||
# if container is run with -ti pts/0 is already taken
|
||||
if [ -c /dev/pts/0 ]; then
|
||||
PTY=1
|
||||
fi
|
||||
|
||||
qemu-system-avr -machine uno -bios /io/CommandStation-EX*.elf -serial pty -daemonize
|
||||
ncat -n -k -l 2560 -o /dev/stderr </dev/pts/${PTY} >/dev/pts/${PTY}
|
Reference in New Issue
Block a user