RE: [PATCH] rtl83xx-poe: add package

2021-03-12 Thread Adrian Schmutzler
Hi,

> -Original Message-
> From: openwrt-devel [mailto:openwrt-devel-boun...@lists.openwrt.org]
> On Behalf Of Bjørn Mork
> Sent: Dienstag, 9. März 2021 22:18
> To: openwrt-devel@lists.openwrt.org
> Cc: John Crispin ; Bjørn Mork 
> Subject: [PATCH] rtl83xx-poe: add package
> 
> From: John Crispin 
> 
> Signed-off-by: John Crispin 
> Signed-off-by: Bjørn Mork 

This lacks a commit message.

Is this needed in core repo?

A few nitpicks below.

> ---
> This is John's simple PoE daemon for the realtek devices, which has been
> cycling around in assorted repos since last year.  It's well tested by now.  
> I've
> been running this with constant polling from cacti for a few months now
> without any issues.
> 
> I believe this should be included in master to make it easier to find and 
> install
> for new users.
> 
> 
> 
> Bjørn
> 
> 
>  package/rtl83xx-poe/Makefile |  29 +++
>  package/rtl83xx-poe/files/bin/poe.lua| 316 +++
>  package/rtl83xx-poe/files/etc/config/poe |  10 +  package/rtl83xx-
> poe/files/etc/init.d/poe |  18 ++
>  4 files changed, 373 insertions(+)
>  create mode 100644 package/rtl83xx-poe/Makefile  create mode 100755
> package/rtl83xx-poe/files/bin/poe.lua
>  create mode 100644 package/rtl83xx-poe/files/etc/config/poe
>  create mode 100755 package/rtl83xx-poe/files/etc/init.d/poe
> 
> diff --git a/package/rtl83xx-poe/Makefile b/package/rtl83xx-poe/Makefile
> new file mode 100644 index ..195b1eb20949
> --- /dev/null
> +++ b/package/rtl83xx-poe/Makefile
> @@ -0,0 +1,29 @@
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=rtl83xx-poe
> +PKG_RELEASE:=2

Should be "1" or $(COMMITCOUNT)

> +
> +PKG_LICENSE:=GPL-2.0+

GPL-2.0-or-later

Best

Adrian


> +
> +include $(INCLUDE_DIR)/package.mk
> +
> +define Package/rtl83xx-poe
> +  SECTION:=utils
> +  CATEGORY:=Utilities
> +  DEPENDS:=+libubox-lua +libubus-lua +libuci-lua +lua-rs232
> +  TITLE:=PoE daemon for realtek switches endef
> +
> +define Package/rtl83xx-poe/description
> + This package contains an utility to allow triggering the PoE state of 
> realtek
> switch ports.
> +endef
> +
> +define Build/Compile
> +
> +endef
> +
> +define Package/rtl83xx-poe/install
> + $(CP) ./files/* $(1)/
> +endef
> +
> +$(eval $(call BuildPackage,rtl83xx-poe))
> diff --git a/package/rtl83xx-poe/files/bin/poe.lua b/package/rtl83xx-
> poe/files/bin/poe.lua
> new file mode 100755
> index ..86dafe13cd01
> --- /dev/null
> +++ b/package/rtl83xx-poe/files/bin/poe.lua
> @@ -0,0 +1,316 @@
> +#!/usr/bin/lua
> +local rs = require "luars232"
> +
> +port_name = "/dev/ttyS1"
> +out = io.stderr
> +nseq = 0
> +
> +budget = 65.0
> +port_power = {0, 0, 0, 0, 0, 0, 0, 0 }
> +
> +if arg[1] ~= nil then
> + budget = tonumber(arg[1])
> +end
> +for i = 1, 8 do
> + port_power[i] = arg[i + 1]
> +end
> +
> +function initSerial(p)
> + local e, p = rs.open(p)
> + if e ~= rs.RS232_ERR_NOERROR then
> + -- handle error
> + out:write(string.format("can't open serial port '%s', error:
> '%s'\n",
> + port_name, rs.error_tostring(e)))
> + return
> + end
> +
> + assert(p:set_baud_rate(rs.RS232_BAUD_19200) ==
> rs.RS232_ERR_NOERROR)
> + assert(p:set_data_bits(rs.RS232_DATA_8) ==
> rs.RS232_ERR_NOERROR)
> + assert(p:set_parity(rs.RS232_PARITY_NONE) ==
> rs.RS232_ERR_NOERROR)
> + assert(p:set_stop_bits(rs.RS232_STOP_1) ==
> rs.RS232_ERR_NOERROR)
> + assert(p:set_flow_control(rs.RS232_FLOW_OFF)  ==
> rs.RS232_ERR_NOERROR)
> +
> + out:write(string.format("OK, port open with values '%s'\n",
> +tostring(p)))
> +
> + return p
> +end
> +
> +function receive(pCon)
> + local reply = {}
> + local retries = 0
> +
> + while table.getn(reply) < 12 and retries < 4 do
> + -- Read up to 12 byte response, timeout 400ms
> + err, data_read, size = pCon:read(12, 400)
> + assert(err == rs.RS232_ERR_NOERROR)
> +--   io.write(string.format("-> [%2d]:", string.len(data_read)))
> + for i = 1, string.len(data_read) do
> + table.insert(reply, string.byte(string.sub(data_read, i,
> i)))
> +--   io.write(string.format(" %02x", reply[i]))
> + end
> +--   io.write("\n")
> + retries = retries + 1
> + end
> + if table.getn(reply) ~= 12 then
> + print ("Unexpected length!")
> +   

Re: [PATCH] rtl83xx-poe: add package

2021-03-11 Thread Stijn Segers

Working brilliantly for weeks here as well.

Tested-by: Stijn Segers 



___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


Re: [PATCH] rtl83xx-poe: add package

2021-03-10 Thread Birger Koblitz

Run tested by me on a DGS1210-10P.
Please merge,
  Birger

On 09/03/2021 22:18, Bjørn Mork wrote:

From: John Crispin 

Signed-off-by: John Crispin 
Signed-off-by: Bjørn Mork 
---
This is John's simple PoE daemon for the realtek devices, which has been
cycling around in assorted repos since last year.  It's well tested by
now.  I've been running this with constant polling from cacti for a
few months now without any issues.

I believe this should be included in master to make it easier to find
and install for new users.



Bjørn


  package/rtl83xx-poe/Makefile |  29 +++
  package/rtl83xx-poe/files/bin/poe.lua| 316 +++
  package/rtl83xx-poe/files/etc/config/poe |  10 +
  package/rtl83xx-poe/files/etc/init.d/poe |  18 ++
  4 files changed, 373 insertions(+)
  create mode 100644 package/rtl83xx-poe/Makefile
  create mode 100755 package/rtl83xx-poe/files/bin/poe.lua
  create mode 100644 package/rtl83xx-poe/files/etc/config/poe
  create mode 100755 package/rtl83xx-poe/files/etc/init.d/poe

diff --git a/package/rtl83xx-poe/Makefile b/package/rtl83xx-poe/Makefile
new file mode 100644
index ..195b1eb20949
--- /dev/null
+++ b/package/rtl83xx-poe/Makefile
@@ -0,0 +1,29 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=rtl83xx-poe
+PKG_RELEASE:=2
+
+PKG_LICENSE:=GPL-2.0+
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/rtl83xx-poe
+  SECTION:=utils
+  CATEGORY:=Utilities
+  DEPENDS:=+libubox-lua +libubus-lua +libuci-lua +lua-rs232
+  TITLE:=PoE daemon for realtek switches
+endef
+
+define Package/rtl83xx-poe/description
+ This package contains an utility to allow triggering the PoE state of realtek 
switch ports.
+endef
+
+define Build/Compile
+
+endef
+
+define Package/rtl83xx-poe/install
+   $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,rtl83xx-poe))
diff --git a/package/rtl83xx-poe/files/bin/poe.lua 
b/package/rtl83xx-poe/files/bin/poe.lua
new file mode 100755
index ..86dafe13cd01
--- /dev/null
+++ b/package/rtl83xx-poe/files/bin/poe.lua
@@ -0,0 +1,316 @@
+#!/usr/bin/lua
+local rs = require "luars232"
+
+port_name = "/dev/ttyS1"
+out = io.stderr
+nseq = 0
+
+budget = 65.0
+port_power = {0, 0, 0, 0, 0, 0, 0, 0 }
+
+if arg[1] ~= nil then
+   budget = tonumber(arg[1])
+end
+for i = 1, 8 do
+   port_power[i] = arg[i + 1]
+end
+
+function initSerial(p)
+   local e, p = rs.open(p)
+   if e ~= rs.RS232_ERR_NOERROR then
+   -- handle error
+   out:write(string.format("can't open serial port '%s', error: 
'%s'\n",
+   port_name, rs.error_tostring(e)))
+   return
+   end
+
+   assert(p:set_baud_rate(rs.RS232_BAUD_19200) == rs.RS232_ERR_NOERROR)
+   assert(p:set_data_bits(rs.RS232_DATA_8) == rs.RS232_ERR_NOERROR)
+   assert(p:set_parity(rs.RS232_PARITY_NONE) == rs.RS232_ERR_NOERROR)
+   assert(p:set_stop_bits(rs.RS232_STOP_1) == rs.RS232_ERR_NOERROR)
+   assert(p:set_flow_control(rs.RS232_FLOW_OFF)  == rs.RS232_ERR_NOERROR)
+
+   out:write(string.format("OK, port open with values '%s'\n", 
tostring(p)))
+
+   return p
+end
+
+function receive(pCon)
+   local reply = {}
+   local retries = 0
+
+   while table.getn(reply) < 12 and retries < 4 do
+   -- Read up to 12 byte response, timeout 400ms
+   err, data_read, size = pCon:read(12, 400)
+   assert(err == rs.RS232_ERR_NOERROR)
+-- io.write(string.format("-> [%2d]:", string.len(data_read)))
+   for i = 1, string.len(data_read) do
+   table.insert(reply, string.byte(string.sub(data_read, 
i, i)))
+-- io.write(string.format(" %02x", reply[i]))
+   end
+-- io.write("\n")
+   retries = retries + 1
+   end
+   if table.getn(reply) ~= 12 then
+   print ("Unexpected length!")
+   return(nil)
+   end
+   local sum = 0
+   for i = 1, 11 do
+   sum = sum + reply[i]
+   end
+   if sum % 256 ~= reply[12] then
+   print ("Checksum error!")
+   return(nil)
+   end
+   return(reply)
+end
+
+function sendCommand(pCon, cmd)
+   nseq = nseq + 1
+   cmd[2] = nseq % 256
+
+   while table.getn(cmd) < 11 do
+   table.insert(cmd, 0xff)
+   end
+   local c_string = ""
+   local sum = 0
+-- io.write("send  ")
+   for i = 1, 11 do
+   sum = sum + cmd[i]
+-- io.write(string.format(" %02x", cmd[i]))
+   c_string = c_string .. string.char(cmd[i])
+   end
+-- io.write(string.format(" %02x\n", sum % 256))
+   c_string = c_string .. string.char(sum % 256)
+   err, len_written = pCon:write(c_string)
+   assert(err == rs.RS232_ERR_NOERROR)
+
+   local reply = receive(pCon)
+   if reply then
+-- io.write("recv  ")
+-- dumpReply(reply)
+   if 

[PATCH] rtl83xx-poe: add package

2021-03-09 Thread Bjørn Mork
From: John Crispin 

Signed-off-by: John Crispin 
Signed-off-by: Bjørn Mork 
---
This is John's simple PoE daemon for the realtek devices, which has been
cycling around in assorted repos since last year.  It's well tested by
now.  I've been running this with constant polling from cacti for a
few months now without any issues.

I believe this should be included in master to make it easier to find
and install for new users.



Bjørn


 package/rtl83xx-poe/Makefile |  29 +++
 package/rtl83xx-poe/files/bin/poe.lua| 316 +++
 package/rtl83xx-poe/files/etc/config/poe |  10 +
 package/rtl83xx-poe/files/etc/init.d/poe |  18 ++
 4 files changed, 373 insertions(+)
 create mode 100644 package/rtl83xx-poe/Makefile
 create mode 100755 package/rtl83xx-poe/files/bin/poe.lua
 create mode 100644 package/rtl83xx-poe/files/etc/config/poe
 create mode 100755 package/rtl83xx-poe/files/etc/init.d/poe

diff --git a/package/rtl83xx-poe/Makefile b/package/rtl83xx-poe/Makefile
new file mode 100644
index ..195b1eb20949
--- /dev/null
+++ b/package/rtl83xx-poe/Makefile
@@ -0,0 +1,29 @@
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=rtl83xx-poe
+PKG_RELEASE:=2
+
+PKG_LICENSE:=GPL-2.0+
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/rtl83xx-poe
+  SECTION:=utils
+  CATEGORY:=Utilities
+  DEPENDS:=+libubox-lua +libubus-lua +libuci-lua +lua-rs232
+  TITLE:=PoE daemon for realtek switches
+endef
+
+define Package/rtl83xx-poe/description
+ This package contains an utility to allow triggering the PoE state of realtek 
switch ports.
+endef
+
+define Build/Compile
+
+endef
+
+define Package/rtl83xx-poe/install
+   $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,rtl83xx-poe))
diff --git a/package/rtl83xx-poe/files/bin/poe.lua 
b/package/rtl83xx-poe/files/bin/poe.lua
new file mode 100755
index ..86dafe13cd01
--- /dev/null
+++ b/package/rtl83xx-poe/files/bin/poe.lua
@@ -0,0 +1,316 @@
+#!/usr/bin/lua
+local rs = require "luars232"
+
+port_name = "/dev/ttyS1"
+out = io.stderr
+nseq = 0
+
+budget = 65.0
+port_power = {0, 0, 0, 0, 0, 0, 0, 0 }
+
+if arg[1] ~= nil then
+   budget = tonumber(arg[1])
+end
+for i = 1, 8 do
+   port_power[i] = arg[i + 1]
+end
+
+function initSerial(p)
+   local e, p = rs.open(p)
+   if e ~= rs.RS232_ERR_NOERROR then
+   -- handle error
+   out:write(string.format("can't open serial port '%s', error: 
'%s'\n",
+   port_name, rs.error_tostring(e)))
+   return
+   end
+
+   assert(p:set_baud_rate(rs.RS232_BAUD_19200) == rs.RS232_ERR_NOERROR)
+   assert(p:set_data_bits(rs.RS232_DATA_8) == rs.RS232_ERR_NOERROR)
+   assert(p:set_parity(rs.RS232_PARITY_NONE) == rs.RS232_ERR_NOERROR)
+   assert(p:set_stop_bits(rs.RS232_STOP_1) == rs.RS232_ERR_NOERROR)
+   assert(p:set_flow_control(rs.RS232_FLOW_OFF)  == rs.RS232_ERR_NOERROR)
+
+   out:write(string.format("OK, port open with values '%s'\n", 
tostring(p)))
+
+   return p
+end
+
+function receive(pCon)
+   local reply = {}
+   local retries = 0
+
+   while table.getn(reply) < 12 and retries < 4 do
+   -- Read up to 12 byte response, timeout 400ms
+   err, data_read, size = pCon:read(12, 400)
+   assert(err == rs.RS232_ERR_NOERROR)
+-- io.write(string.format("-> [%2d]:", string.len(data_read)))
+   for i = 1, string.len(data_read) do
+   table.insert(reply, string.byte(string.sub(data_read, 
i, i)))
+-- io.write(string.format(" %02x", reply[i]))
+   end
+-- io.write("\n")
+   retries = retries + 1
+   end
+   if table.getn(reply) ~= 12 then
+   print ("Unexpected length!")
+   return(nil)
+   end
+   local sum = 0
+   for i = 1, 11 do
+   sum = sum + reply[i]
+   end
+   if sum % 256 ~= reply[12] then
+   print ("Checksum error!")
+   return(nil)
+   end
+   return(reply)
+end
+
+function sendCommand(pCon, cmd)
+   nseq = nseq + 1
+   cmd[2] = nseq % 256
+
+   while table.getn(cmd) < 11 do
+   table.insert(cmd, 0xff)
+   end
+   local c_string = ""
+   local sum = 0
+-- io.write("send  ")
+   for i = 1, 11 do
+   sum = sum + cmd[i]
+-- io.write(string.format(" %02x", cmd[i]))
+   c_string = c_string .. string.char(cmd[i])
+   end
+-- io.write(string.format(" %02x\n", sum % 256))
+   c_string = c_string .. string.char(sum % 256)
+   err, len_written = pCon:write(c_string)
+   assert(err == rs.RS232_ERR_NOERROR)
+
+   local reply = receive(pCon)
+   if reply then
+-- io.write("recv  ")
+-- dumpReply(reply)
+   if (reply[1] == cmd[1] and reply[2] == cmd[2]) then
+   return(reply)
+   else
+