在网上找了一圈,也没有找到luci-app-ser2net的OpenWrt页面,于是自己动手写了个luci-app-ser2net。至于串口透传模块ser2net_client和ser2net_server可以联系本人。用户只需简单设置,即可实现串口到网络的双向数据透明传输,支持心跳功能,支持5路socket连接。
将luci-app-ser2net目录放到OpenWrt源码的package/utils下:
[xujun@localhost luci-app-ser2net]$ tree
.
├── files
│ └── root
│ ├── etc
│ │ ├── config
│ │ │ └── ser2net
│ │ └── init.d
│ │ └── ser2net_client
│ └── usr
│ └── lib
│ └── lua
│ └── luci
│ ├── controller
│ │ └── ser2net.lua
│ └── model
│ └── cbi
│ └── ser2net.lua
└── Makefile
12 directories, 5 files
[xujun@localhost luci-app-ser2net]$
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-ser2net
PKG_VERSION=1.0
PKG_RELEASE:=1
PKG_MAINTAINER:=xujun<[email protected]>
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/luci-app-ser2net
SECTION:=luci
CATEGORY:=LuCI
SUBMENU:=3. Applications
TITLE:=ser2net for LuCI
PKGARCH:=all
endef
define Package/luci-app-ser2net/description
This package contains LuCI configuration pages for ser2net.
endef
define Build/Prepare
endef
define Build/Configure
endef
define Build/Compile
endef
define Package/luci-app-ser2net/install
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/model/cbi
$(INSTALL_DIR) $(1)/usr/lib/lua/luci/controller
$(INSTALL_CONF) ./files/root/etc/config/ser2net $(1)/etc/config/ser2net
$(INSTALL_BIN) ./files/root/etc/init.d/ser2net_client $(1)/etc/init.d/ser2net_client
$(INSTALL_DATA) ./files/root/usr/lib/lua/luci/model/cbi/ser2net.lua $(1)/usr/lib/lua/luci/model/cbi/ser2net.lua
$(INSTALL_DATA) ./files/root/usr/lib/lua/luci/controller/ser2net.lua $(1)/usr/lib/lua/luci/controller/ser2net.lua
endef
$(eval $(call BuildPackage,luci-app-ser2net))
config ser2net
option enabled '0'
option DeviceId '12345678'
option SimNumber '13900001234'
option interval '60'
option heartbeat 'FE'
option MaxDataLen '1000'
option DataWaitTime '300'
option ReDialTime '60'
option serial '/dev/ttyS0'
option 'baudrate' '57600'
option 'databit' '8'
option 'parity_check' 'n'
option 'stopbit' '1'
option srvmode '0'
option srvport '9999'
option clinum '5'
option protocol1 'tcp'
option ip1 ''
option BasePort1 ''
option protocol2 'tcp'
option ip2 ''
option BasePort2 ''
option protocol3 'tcp'
option protocol4 'tcp'
option protocol5 'tcp'
#!/bin/sh /etc/rc.common
START=100
ser2net()
{
local enabled
config_get_bool enabled $1 enabled
if [ $enabled ]; then
# /etc/init.d/ser2net_server stop
local srvmode
config_get srvmode $1 srvmode
echo $srvmode
if [ "$srvmode"x = "0"x ]; then
echo $srvmode
killall /bin/ser2net_server
pidof ser2net_client | awk '{print $2}' > /tmp/ser2net_client
PID=$(cat /tmp/ser2net_client)
rm /tmp/ser2net_client
if [ ! $PID ]; then
echo "ser2net client has started."
/bin/ser2net_client &
else
echo "ser2net client: is already running"
fi
else
echo $srvmode
killall /bin/ser2net_client
pidof ser2net_server | awk '{print $2}' > /tmp/ser2net_server
PID=$(cat /tmp/ser2net_server)
rm /tmp/ser2net_server
if [ ! $PID ]; then
echo "ser2net server has started."
/bin/ser2net_server &
else
echo "ser2net server: is already running"
fi
fi
fi
}
start()
{
config_load ser2net
config_foreach ser2net ser2net
}
stop()
{
# pidof ser2net_client | sed -e "s/$$//g" > /tmp/ser2net_client_pid
# PID=`cat /tmp/ser2net_client_pid`
# rm -f /tmp/ser2net_client_pid
# kill -9 $PID
echo "ser2net client has stoped."
echo "ser2net server has stoped."
killall /bin/ser2net_client
killall /bin/ser2net_server
}
module("luci.controller.ser2net", package.seeall)
function index()
entry({"admin", "services", "ser2net"}, cbi("ser2net"), _("ser2net"), 102)
end
--[[
LuCI - Lua Configuration Interface
Copyright 2010 Jo-Philipp Wich
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
]]--
require("luci.sys")
m = Map("ser2net", translate("Serial<->Networking"), translate("Serial data and network data exchanged."))
s = m:section(TypedSection, "ser2net", "")
s.addremove = false
s.anonymous = true
s:tab("basic", translate("Basic Configuration"))
enabled = s:taboption("basic", Flag, "enabled", translate("Enable"))
DeviceId = s:taboption("basic", Value, "DeviceId", translate("Device ID"))
DeviceId.rmempty = false
DeviceId.default = "12345678"
DeviceId:depends("enabled", "1")
SimNumber = s:taboption("basic", Value, "SimNumber", translate("Sim Number"))
SimNumber.rmempty = false
SimNumber.default = "13900001234"
SimNumber:depends("enabled", "1")
interval = s:taboption("basic", Value, "interval", translate("Heartbeat Interval (s)"))
interval.rmempty = false
interval.default = "60"
interval:depends("enabled", "1")
heartbeat = s:taboption("basic", Value, "heartbeat", translate("Heartbeat Content"))
heartbeat.rmempty = false
heartbeat.default = "FE"
heartbeat:depends("enabled", "1")
MaxDataLen = s:taboption("basic", Value, "MaxDataLen", translate("MaxDataLen"))
MaxDataLen.rmempty = false
MaxDataLen.default = "1000"
MaxDataLen:depends("enabled", "1")
DataWaitTime = s:taboption("basic", Value, "DataWaitTime", translate("DataWaitTime"))
DataWaitTime.rmempty = false
DataWaitTime.default = "300"
DataWaitTime:depends("enabled", "1")
ReDialTime = s:taboption("basic", Value, "ReDialTime", translate("ReDialTime"))
ReDialTime.rmempty = false
ReDialTime.default = "15"
ReDialTime:depends("enabled", "1")
Parameter1 = s:taboption("basic", Value, "Parameter1", translate("Parameter1"))
Parameter1:depends("enabled", "1")
Parameter2 = s:taboption("basic", Value, "Parameter2", translate("Parameter2"))
Parameter2:depends("enabled", "1")
Parameter3 = s:taboption("basic", Value, "Parameter3", translate("Parameter3"))
Parameter3:depends("enabled", "1")
Parameter4 = s:taboption("basic", Value, "Parameter4", translate("Parameter4"))
Parameter4:depends("enabled", "1")
Parameter5 = s:taboption("basic", Value, "Parameter5", translate("Parameter5"))
Parameter5:depends("enabled", "1")
s:tab("serial", translate("Serial Configuration"))
baudrate = s:taboption("serial", ListValue, "baudrate", translate("Baudrate (bps)"))
baudrate:value("110", "110")
baudrate:value("300", "300")
baudrate:value("600", "600")
baudrate:value("1200", "1200")
baudrate:value("2400", "2400")
baudrate:value("4800", "4800")
baudrate:value("9600", "9600")
baudrate:value("19200", "19200")
baudrate:value("38400", "38400")
baudrate:value("57600", "57600")
baudrate:value("115200", "115200")
baudrate:value("230400", "230400")
baudrate.default = "57600"
databit = s:taboption("serial", ListValue, "databit", translate("Databit"))
databit:value("5", "5")
databit:value("6", "6")
databit:value("7", "7")
databit:value("8", "8")
databit.default = "8"
parity_check = s:taboption("serial", ListValue, "parity_check", translate("Odd-Even Check"))
parity_check:value("n", translate("None Check"))
parity_check:value("o", translate("Odd Check"))
parity_check:value("e", translate("Even Check"))
parity_check.default = "n"
stopbit = s:taboption("serial", ListValue, "stopbit", translate("Stopbit"))
stopbit:value("1", "1")
stopbit:value("2", "2")
stopbit.default = "1"
s:tab("network", translate("Networking Configuration"))
o = s:taboption("network", ListValue, "srvmode", translate("Server Mode"))
o:value("0", "Client")
o:value("1", "Tcp")
o:value("2", "Udp")
o:value("3", "Tcp&Udp")
o = s:taboption("network", Value, "srvport", translate("Server Port"))
o:depends("srvmode", "1")
o:depends("srvmode", "2")
o:depends("srvmode", "3")
o.datatype="port"
protocol1 = s:taboption("network", ListValue, "protocol1", translate("Protocol 1"))
protocol1:value("udp", "Udp")
protocol1:value("tcp", "Tcp")
protocol1:depends("srvmode", "0")
ip1 = s:taboption("network", Value, "ip1", translate("Data Center 1"))
ip1:depends("srvmode", "0")
--[[ip1.datatype="ip4addr"]]--
BasePort1 = s:taboption("network", Value, "BasePort1", translate("Data Center 1 Port"))
BasePort1:depends("srvmode", "0")
BasePort1.datatype="port"
protocol2 = s:taboption("network", ListValue, "protocol2", translate("Protocol 2"))
protocol2:value("udp", "Udp")
protocol2:value("tcp", "Tcp")
protocol2:depends("srvmode", "0")
ip2 = s:taboption("network", Value, "ip2", translate("Data Center 2"))
ip2:depends("srvmode", "0")
--[[ip2.datatype="ip4addr"]]--
BasePort2 = s:taboption("network", Value, "BasePort2", translate("Data Center 2 Port"))
BasePort2:depends("srvmode", "0")
BasePort2.datatype="port"
protocol3 = s:taboption("network", ListValue, "protocol3", translate("Protocol 3"))
protocol3:value("udp", "Udp")
protocol3:value("tcp", "Tcp")
protocol3:depends("srvmode", "0")
ip3 = s:taboption("network", Value, "ip3", translate("Data Center 3"))
ip3:depends("srvmode", "0")
--[[ip3.datatype="ip4addr"]]--
BasePort3 = s:taboption("network", Value, "BasePort3", translate("Data Center 3 Port"))
BasePort3:depends("srvmode", "0")
BasePort3.datatype="port"
protocol4 = s:taboption("network", ListValue, "protocol4", translate("Protocol 4"))
protocol4:value("udp", "Udp")
protocol4:value("tcp", "Tcp")
protocol4:depends("srvmode", "0")
ip4 = s:taboption("network", Value, "ip4", translate("Data Center 4"))
ip4:depends("srvmode", "0")
--[[ip4.datatype="ip4addr"]]--
BasePort4 = s:taboption("network", Value, "BasePort4", translate("Data Center 4 Port"))
BasePort4:depends("srvmode", "0")
BasePort4.datatype="port"
protocol5 = s:taboption("network", ListValue, "protocol5", translate("Protocol 5"))
protocol5:value("udp", "Udp")
protocol5:value("tcp", "Tcp")
protocol5:depends("srvmode", "0")
ip5 = s:taboption("network", Value, "ip5", translate("Data Center 5"))
ip5:depends("srvmode", "0")
--[[ip5.datatype="ip4addr"]]--
BasePort5 = s:taboption("network", Value, "BasePort5", translate("Data Center 5 Port"))
BasePort5:depends("srvmode", "0")
BasePort5.datatype="port"
local apply = luci.http.formvalue("cbi.apply")
if apply then
io.popen("/etc/init.d/ser2net_client restart")
end
return m
最后make menuconfig,可看到luci-app-ser2net。
make package/utils/luci-app-ser2net/compile V=s 即可。