Compare commits

...
Sign in to create a new pull request.

12 commits

Author SHA1 Message Date
a3addedfe7 Add space in printout
There is a space missing betweet two words in the "Please provide your username" string to separate "to" and "other". This patch adds a space in the right place.
2017-02-02 11:34:07 +01:00
Igor Socec
b375ee19ce Fix bug where tty is dropped out of device name 2017-01-25 16:36:02 +01:00
Igor Socec
f3babe58df Put logs in a standard location: /var/log 2017-01-25 16:14:52 +01:00
Igor Socec
cded0313c2 Don't install with just make, require make install 2017-01-25 11:41:02 +01:00
Igor Socec
ce8971eb2b Correct paths in moxerverctl and adapt Makefiles 2017-01-25 11:31:44 +01:00
Igor Socec
ee5aaa2690 Update README.md 2017-01-25 01:44:34 +01:00
Igor Socec
83bd22bef9 Change names of config file and control script
Also make top Makefile more tidy.
2017-01-25 01:33:37 +01:00
Igor Socec
a1162d1674 Use a prefix when installing executables 2017-01-24 20:40:57 +01:00
Igor Socec
aa3adfee0c Update README.md 2017-01-24 18:54:24 +01:00
Igor Socec
aae67971ff Improve Makefiles with build and install directories 2017-01-24 18:16:47 +01:00
Igor Socec
efc292af2c Improve source tree 2017-01-11 17:30:13 +01:00
Igor Socec
61d4e2fc64 Start using Travis CI
Add .travis.yml file and build status flag.
2017-01-10 16:42:57 +01:00
20 changed files with 172 additions and 49 deletions

6
.gitignore vendored
View file

@ -1,8 +1,6 @@
# executables # object files/output directories
moxerver
# object files
*.o *.o
*.dir
# logs directory during development # logs directory during development
logs logs

7
.travis.yml Normal file
View file

@ -0,0 +1,7 @@
language: cpp
compiler:
- gcc
- clang
script: make install

View file

@ -1,43 +1,38 @@
# target name # components
TARGET = moxerver SERVER = moxerver
TOOLS = tools
# special include directories # system install root directory
INCDIRS = -I. INSTALL_ROOT = $(abspath ./install.dir)
# special library directories
LIBDIRS = -L.
# used libraries
#LIBS = -lm
LIBS = -lpthread
# compiler and flags # prefix for /bin directory
CC = gcc BIN_PREFIX = /usr
CFLAGS = -Wall $(INCDIRS) $(LIBDIRS) $(LIBS)
# objects are .o files created from all .c files in the directory (same name) # ==============================================================================
OBJECTS = $(patsubst %.c,%.o,$(wildcard *.c))
# headers are all .h files in the directory
HEADERS = $(wildcard *.h)
# all objects are built from their .c files and all headers in the directory # directories used for local component builds
%.o: %.c $(HEADERS) BUILDDIR = build.dir
$(CC) $(CFLAGS) -c $< -o $@ # directory configuration for local component builds
DIR_CONFIG = BUILDDIR=$(BUILDDIR) INSTALLDIR=$(INSTALL_ROOT) BIN_PREFIX=$(BIN_PREFIX)
# target is built from all object files # ==============================================================================
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) $(CFLAGS) -o $@
# supported make options (clean, install...)
.PHONY: default install clean
# support for default, clean and all options # default builds components
.PHONY: default all clean default:
cd $(SERVER) && make $(DIR_CONFIG)
cd $(TOOLS) && make $(DIR_CONFIG)
# all calls all other options # install handles component installation
all: default install: default
mkdir -p $(INSTALL_ROOT)
cd $(SERVER) && make install $(DIR_CONFIG)
cd $(TOOLS) && make install $(DIR_CONFIG)
# default builds target # clean removes build and install results
default: $(TARGET)
# clean removed object files and target
clean: clean:
-rm -f *.o cd $(SERVER) && make clean $(DIR_CONFIG)
-rm -f $(TARGET) cd $(TOOLS) && make clean $(DIR_CONFIG)
-rm -rf $(INSTALL_ROOT)

View file

@ -1,16 +1,40 @@
moxanix [![Build Status](https://travis-ci.org/socec/moxanix.svg?branch=master)](https://travis-ci.org/socec/moxanix)
Moxanix
======= =======
A serial device server, provides console access to multiple serial devices through telnet connection. A serial device server, provides console access to multiple serial devices through telnet connection.
Architecture
============
The serial device server is broken down into multiple micro servers dedicated to a single serial device and TCP port pair.
These micro servers are then managed by a control script. The control script allows the user to start and stop these micro servers or check their status.
Connections between serial devices and TCP ports are configured in a separate file.
This design allows scalability and customization based on the number of available serial connections and TCP port availability.
moxerver moxerver
-------- --------
- server application handling the session between a specific TCP port and a specific serial device - a light server application handling the session between one TCP port and one serial device
- allows bidirectional communication - allows bidirectional communication
- it is expected to run a separate instance for every serial device - it is expected to run a separate instance for every serial device and TCP port pair
moxanix.sh moxerverctl
---------- -----------
- starts, stops or displays status for different moxervers - starts, stops or displays status for different moxervers
- commands can handle one specific or all moxervers at once - commands can handle one specific or all moxervers at once
moxerver.cfg
------------
- defines connections between serial devices and TCP ports
- each line corresponds to one micro server handling the defined connection
Build and install
=================
Run `make` to build the project and `make install` to install it.
This default build will produce artifacts in a directory "install.dir" with executables installed in "usr/bin" (default prefix is "usr").
You can install directly into some other directory with `make INSTALL_ROOT=/some/dir`.
You can change the default install prefix for executables with `make BIN_PREFIX=someprefix`.
These options can also be combined into `make INSTALL_ROOT=/some/dir BIN_PREFIX=someprefix`

65
moxerver/Makefile Normal file
View file

@ -0,0 +1,65 @@
# target names
TARGET_BINARY = moxerver
# ==============================================================================
# directory for build results
BUILDDIR = $(abspath build.dir)
# installation root
INSTALLDIR = $(abspath install.dir)
# prefix for /bin directory
BIN_PREFIX = /usr
# ==============================================================================
# add include directories
INCDIRS = -I.
# add library directories
LIBDIRS = -L.
# list used libraries
#LIBS = -lm
LIBS = -lpthread
# ==============================================================================
# compiler and flags
CC = gcc
CFLAGS = -Wall $(INCDIRS) $(LIBDIRS) $(LIBS)
# ==============================================================================
# build everything in a dedicated directory $(BUILDDIR)
# objects are .o files created from all .c files in the directory (same name)
OBJECTS = $(patsubst %.c, $(BUILDDIR)/%.o, $(wildcard *.c))
# headers are all .h files in the directory
HEADERS = $(wildcard *.h)
# all objects are built from their .c files in the directory
$(BUILDDIR)/%.o: %.c
mkdir -p $(BUILDDIR)
$(CC) $(CFLAGS) -c $< -o $@
# target binary is built from all object files
$(BUILDDIR)/$(TARGET_BINARY): $(OBJECTS)
$(CC) $(OBJECTS) $(CFLAGS) -o $@
# ==============================================================================
# supported make options (clean, install...)
.PHONY: all default install clean
# all calls all other options
all: default install
# default builds target
default: $(BUILDDIR)/$(TARGET_BINARY)
# install target binary
install: default
install -Dm0755 $(BUILDDIR)/$(TARGET_BINARY) $(INSTALLDIR)/$(BIN_PREFIX)/bin/$(TARGET_BINARY)
# clean removes object files and target (ignore errors with "-" before commands)
clean:
-rm -rf $(BUILDDIR)
-rm -rf $(INSTALLDIR)

View file

@ -133,7 +133,7 @@ int client_ask_username(client_t *client)
/* show username request to the client */ /* show username request to the client */
snprintf(msg, BUFFER_LEN, snprintf(msg, BUFFER_LEN,
"\nPlease provide a username to identify yourself to" "\nPlease provide a username to identify yourself to "
"other users (max %d characters):\n", USERNAME_LEN); "other users (max %d characters):\n", USERNAME_LEN);
client_write(client, msg, strlen(msg)); client_write(client, msg, strlen(msg));

32
tools/Makefile Normal file
View file

@ -0,0 +1,32 @@
# target names
TARGET_CONTROL = moxerverctl
TARGET_CONFIG = moxerver.cfg
# ==============================================================================
# directory for build results
BUILDDIR = $(abspath build.dir)
# installation root
INSTALLDIR = $(abspath install.dir)
# prefix for /bin directory
BIN_PREFIX = /usr
# ==============================================================================
# supported make options (clean, install...)
.PHONY: default install clean
# default does nothing
default:
# install targets
install:
# install configuration file
install -Dm0644 $(TARGET_CONFIG) $(INSTALLDIR)/etc/$(TARGET_CONFIG)
# install control script, referring to the configuration file
install -Dm0755 $(TARGET_CONTROL) $(INSTALLDIR)/$(BIN_PREFIX)/bin/$(TARGET_CONTROL)
sed -i -e 's#ROOT=\"\"#ROOT=$(INSTALLDIR)#' $(INSTALLDIR)/$(BIN_PREFIX)/bin/$(TARGET_CONTROL)
# clean removes object files and target (ignore errors with "-" before commands)
clean:
-rm -rf $(INSTALLDIR)

14
moxanix.sh → tools/moxerverctl Executable file → Normal file
View file

@ -4,10 +4,12 @@
# setup # setup
# ===== # =====
ROOT=""
# parameters # parameters
CONFIGURATION_FILE="./moxanix.cfg" CONFIGURATION_FILE="$ROOT/etc/moxerver.cfg"
SERVER_BINARY="./moxerver" SERVER_BINARY="moxerver"
LOG_DIRECTORY="./logs" LOG_DIRECTORY="$ROOT/var/log/moxerver"
# global variables for configuration # global variables for configuration
@ -61,9 +63,9 @@ do_read_config()
# configuration lines # configuration lines
CONF_LINES[$CONF_SIZE]=$(echo -n $line) CONF_LINES[$CONF_SIZE]=$(echo -n $line)
# extract configuration arguments # extract configuration arguments
tcp=$(echo $line | awk '{print $1}' | tr -d "tcp=") tcp=$(echo $line | awk '{print $1}' | sed -e 's/tcp=//')
tty=$(echo $line | awk '{print $2}' | tr -d "tty=") tty=$(echo $line | awk '{print $2}' | sed -e 's/tty=//')
baud=$(echo $line | awk '{print $3}' | tr -d "baud=") baud=$(echo $line | awk '{print $3}' | sed -e 's/baud=//')
# compose configuration argument lines for passing to the servers # compose configuration argument lines for passing to the servers
CONF_ARGS[$CONF_SIZE]="-p $tcp -t $tty -b $baud" CONF_ARGS[$CONF_SIZE]="-p $tcp -t $tty -b $baud"
# increment configuration size (array index) # increment configuration size (array index)