Skip to content

Commit

Permalink
ser2net: extend dynamic config generation (refs openwrt#5302)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Heimpold <[email protected]>
  • Loading branch information
mhei committed Dec 30, 2017
1 parent 71ea9e8 commit 1dd54f5
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 58 deletions.
11 changes: 7 additions & 4 deletions net/ser2net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk

PKG_NAME:=ser2net
PKG_VERSION:=3.5
PKG_RELEASE:=1
PKG_RELEASE:=2

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/ser2net
Expand Down Expand Up @@ -43,13 +43,16 @@ endef

define Package/ser2net/install
$(INSTALL_DIR) $(1)/usr/sbin
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/ser2net $(1)/usr/sbin/
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/ser2net $(1)/usr/sbin/

$(INSTALL_DIR) $(1)/etc
$(INSTALL_CONF) $(PKG_BUILD_DIR)/ser2net.conf $(1)/etc/

$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/etc/config/ser2net $(1)/etc/config/ser2net
$(INSTALL_CONF) ./files/ser2net.config $(1)/etc/config/ser2net

$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/etc/init.d/ser2net $(1)/etc/init.d/ser2net
$(INSTALL_BIN) ./files/ser2net.init $(1)/etc/init.d/ser2net

This comment has been minimized.

Copy link
@karlp

karlp Dec 30, 2017

this is just noise. What's it for in this commit? If you want to make chages, it looks like the existing stuff could just be converted to $(CP) files/ $(1) and be done.

This comment has been minimized.

Copy link
@mhei

mhei Jan 7, 2018

Author Owner

For only 3 config files, I prefer it explicit instead of having the files distributed in subdirectories here.

endef

$(eval $(call BuildPackage,ser2net))
8 changes: 0 additions & 8 deletions net/ser2net/files/etc/config/ser2net

This file was deleted.

46 changes: 0 additions & 46 deletions net/ser2net/files/etc/init.d/ser2net

This file was deleted.

70 changes: 70 additions & 0 deletions net/ser2net/files/ser2net.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# This is a minimal example configuration file for ser2net. For a version with
# detailed comments and all possible configuration directives, please visit:
# https://github.com/cminyard/ser2net/blob/master/ser2net.conf
#
# On OpenWrt/LEDE systems, this configuration serves as a base configuration.
# During boot of the system, the UCI configuration file /etc/config/ser2net is
# parsed and converted to additional configuration lines which are _appended_
# to this file. The ser2net daemon is then started with the combined
# configuration file /tmp/ser2net.conf.
#
# A basic service configuration line has the following format:
# <network port>:<state>:<timeout>:<device>:<options>
# network port
# Name or number of the port to accept connections
# from for this device. A port number may be of the form
# [ipv4,|ipv6,][tcp,|udp,][host,]port, such as
# 127.0.0.1,2000 or ipv4,tcp,localhost,2000. If the host is
# specified, it will only bind to the IP address
# specified. Otherwise it will bind to all the ports on the
# machine. If ipv4 or ipv6 is specified, it will only bind
# to that network type.
#
# state
# Either raw or rawlp or telnet or off. off disables
# the port from accepting connections. It can be
# turned on later from the control port. raw enables
# the port and transfers all data as-is between the
# port and the long. rawlp enables the port and
# transfers all input data to device, device is open
# without any termios setting. It allow to use
# /dev/lpX devices and printers connected to them.
# telnet enables the port and runs the telnet proto-
# col on the port to set up telnet parameters. This
# is most useful for using telnet.
#
# timeout
# The time (in seconds) before the port will be dis-
# connected if there is no activity on it. A zero
# value disables this function.
#
# device
# The name of the device to connect to. This
# must be in the form of /dev/<device>.
#
# options
# Sets operational parameters for the serial port.
# For a serial device (not IPMI SOL):
# Options 300, 1200, 2400, 4800, 9600, 19200, 38400,
# 57600, 115200 set the various baud rates. EVEN,
# ODD, NONE (MARK and SPACE if supported) set the parity.
# Note that MARK and SPACE are not available on all systems
# or hardware, if it is not supported then it will be
# silently set to ODD or EVEN parity.
# 1STOPBIT, 2STOPBITS set
# the number of stop bits. 5DATABITS, 6DATABITS,
# 7DATABITS, 8DATABITS set the number of data bits.
# [-]XONXOFF turns on (- off) XON/XOFF support.
# [-]RTSCTS turns on (- off) hardware flow control,
# [-]LOCAL turns off (- on) monitoring of the modem lines,
# and [-]HANGUP_WHEN_DONE turns on (- off) lowering the
# modem control lines when the connection is done.
# [-]NOBREAK disables automatic setting of the break
# setting of the serial port.
#
# The "[-]remctl" option allow remote control (ala RFC
# 2217) of serial-port configuration.
#
# Example:
# 5000:telnet:0:/dev/ttyAPP0:115200 8DATABITS NONE 1STOPBIT -XONXOFF -LOCAL -RTSCTS remctl
67 changes: 67 additions & 0 deletions net/ser2net/files/ser2net.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
config global
option enabled 1

config controlport
option enabled 0
option host localhost
option port 2000

config default
option speed 115200
option databits 8
option parity 'none'
option stopbits 1
option rtscts false
option local false
option remctl true

#config led rx
# option driver sysfs
# option device 'duckbill:green:rs485'
# option duration 20
# option state 1

#config led tx
# option driver sysfs
# option device 'duckbill:red:rs485'
# option duration 20
# option state 1

config proxy
option enabled 0
option port 5000
option protocol telnet
option timeout 0
option device '/dev/ttyAPP0'
option baudrate 115200
option databits 8
option parity 'none'
option stopbits 1
# option led_tx 'tx'
# option led_rx 'rx'
option rtscts false
option local false
option xonxoff false
list options ''

config proxy
option enabled 0
option port 5001
option protocol telnet
option timeout 0
option device '/dev/ttyUSB0'
option baudrate 115200
option databits 8
option parity 'none'
option stopbits 1

config proxy
option enabled 0
option port 5002
option protocol raw
option timeout 0
option device '/dev/ttyUSB1'
option baudrate 9600
option databits 8
option parity 'none'
option stopbits 1
Loading

6 comments on commit 1dd54f5

@karlp
Copy link

@karlp karlp commented on 1dd54f5 Dec 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this will work :)

@TimelessNL
Copy link

@TimelessNL TimelessNL commented on 1dd54f5 Jan 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was testing you conf/config/init files but are you sure they work?
It seems that (does not work):

config global
option enabled 1

config_get_bool enabled ser2net enabled 0

however this works:

config ser2net global
option enabled 1

config_get_bool enabled global enabled 0

When I try it without 'ser2net' in the config name, the resulting 'enable' boolean is always 0. I'm running LEDE 17.01.2 and just copied your scripts, which should be fine I suppose.

@mhei
Copy link
Owner Author

@mhei mhei commented on 1dd54f5 Jan 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doohh, you are right. somehow this slipped through... I've commited a fix, please re-test.

@TimelessNL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's correct now. ;)

One thing I personally do not understand. Why is 'ser2net' needed at the global section and not at all the other sections? It's working nevertheless, so thats fine. But I would like to understand.

@karlp
Copy link

@karlp karlp commented on 1dd54f5 Jan 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TimelessNL names vs types are a disaster in UCI, but so be it.
it's from

config_load ser2net
config_get_bool enabled ser2net enabled 0

vs

config_foreach blah

config_load ser2nnet loads /etc/config/ser2net,
config_get_bool is making a variable called enabled, from the section (type/name I never remember which is which) ser2net, option "enabled" with a default value of 0.

The _foreach just iterates all the sections of the type, regardless of name

@TimelessNL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmh interesting. Thanks for explaining!

Please sign in to comment.