Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION := 1.15
VERSION=$(PKG_VERSION)

ifdef CROSS_COMPILE
CC := $(CROSS_COMPILE)-gcc
Expand All @@ -20,7 +20,7 @@ ROOT_DIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

EXTRA_CFLAGS += -DVERSION='"$(VERSION)"'

mtpoe_ctrl-h := mtpoe_ctrl.h mk_com.h params.h signals.h
mtpoe_ctrl-h := mtpoe_ctrl.h mk_boards.h mk_com.h params.h signals.h
mtpoe_ctrl-objs-c := mk_com.c
mtpoe_ctrl-objs := $(mtpoe_ctrl-objs-c:%.c=objs/%.o)
mtpoe_ctrl-bins-c := mtpoe_ctrl.c
Expand Down
18 changes: 15 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Examples of using:
mtpoe_ctrl --action=set_poe --port=1 --val=2 #auto-on PoE for port ether3
mtpoe_ctrl --action=set_poe --port=2 --val=1 #force-on PoE for port ether4
mtpoe_ctrl --action=set_poe --port=3 --val=0 #turn off PoE for port ether5
mtpoe_ctrl --action=load_poe_from_uci #load PoE port settings from uci->network->mtik_poe
mtpoe_ctrl --action=load_poe_from_uci #load PoE port settings from uci->network->poe

In /etc/config/network the mtik_poe section should be present:
config mtik_poe
In /etc/config/network the poe section should be present:
config poe
option port0 '1'
option port1 '0'
option port2 '1'
Expand Down Expand Up @@ -68,3 +68,15 @@ or if you use DTS:
spi-max-frequency = <2200000>;
};
};

RB500UPr+S+IN:
The board name expected is "mikrotik,rb5009upr".
It is expected the appropriate spi device is defined in DT and the PoE is enabled. This is already ensured with
patches for this board (also refer to https://forum.openwrt.org/t/mikrotik-rb750-r2-series-poe/7032/68).
The get_poe command does not return the ports configuration (0x45), only the status.

Build:
1. Copy openwrt/package/utils/mtpoe_ctrl into <openwrt build tree>/package/utils/
2. In <openwrt build tree> run 'make menuconfig' and select this new package to build
3a. Type 'make' to rebuild the openwrt OR
3b. Type 'make package/utils/mtpoe_ctrl/{clean,compile}' to build this package only
6 changes: 3 additions & 3 deletions README.ru
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
mtpoe_ctrl --action=set_poe --port=1 --val=2 #auto-on PoE для порта ether3
mtpoe_ctrl --action=set_poe --port=2 --val=1 #force-on PoE для порта ether4
mtpoe_ctrl --action=set_poe --port=3 --val=0 #выключить PoE для порта ether5
mtpoe_ctrl --action=load_poe_from_uci #загрузить PoE настройки портов из uci->network->mtik_poe
mtpoe_ctrl --action=load_poe_from_uci #загрузить PoE настройки портов из uci->network->poe

В /etc/config/network должна присутствовать секция mtik_poe:
config mtik_poe
В /etc/config/network должна присутствовать секция poe:
config poe
option port0 '1'
option port1 '0'
option port2 '1'
Expand Down
42 changes: 42 additions & 0 deletions mk_boards.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef _MK_BOARDS
#define _MK_BOARDS

#include <stdint.h>
#include "mk_com.h"

#define BOARDS_NUM (sizeof(poe_boards)/sizeof(poe_boards[0]))
#define POE_BOARD_NAME_LEN 32

struct poe_board {
char *name;
int proto_ver;
char *spidev;
int ports_num;
int port_state_map[POE_CMD_PORTS_MAX];
};

/*************************************************************************************
все изместные нам PoE устройства */
const struct poe_board poe_boards[ ] = {
{ /* RouterBOARD 750P r2, RouterBOARD 750UP r2*/
.name = "rb-750p-pbr2",
.proto_ver = 2,
.spidev = "/dev/spidev0.2",
.ports_num = 4,
.port_state_map = {0xd, 0xc, 0xb, 0xa}
}, { /* RouterBOARD 960PGS */
.name = "mikrotik,routerboard-960pgs",
.proto_ver = 3,
.spidev = "/dev/spidev0.2",
.ports_num = 4,
.port_state_map = {0xd, 0xc, 0xb, 0xa}
}, { /* RouterBOARD RB5009UPr+S+IN and its base */
.name = "mikrotik,rb5009 mikrotik,rb5009upr",
.proto_ver = 4,
.spidev = "/dev/spidev2.0",
.ports_num = 8,
.port_state_map = {0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1}
}
};//----------------------------------------------------------------------------------

#endif
2 changes: 1 addition & 1 deletion mk_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ uint8_t *spidev_query(int fd, uint8_t cmd, uint8_t arg1, uint8_t arg2){
}
/* проверим то, что получили от микроконтроллера */
p = rx + 4; //p указывает на начало ответа(+4 байта)
if(poe_proto == 3)
if((poe_proto == 3) || (poe_proto == 4))
tx_crc = 0xFF;
//проверим что rx[0] == tx_crc
if(*(p++) != tx_crc){
Expand Down
3 changes: 2 additions & 1 deletion mk_com.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#define POE_CMD_STATE 0x45 /* получение статуса всех POE портов(off, force-on, auto-on) */
/* запрос статуса(есть ли потребление, КЗ) POE для указанного порта.
так же возвращает ток потребления в mA */
#define POE_CMD_PORT_STATE_BASE 0x59 /* 0x59 .. 0x5C */
#define POE_CMD_PORT_STATE_BASE 0x50 /* 0x50 .. 0x5F */
#define POE_CMD_PORTS_MAX 16 /* Maximum number of handled ports.*/

uint8_t *spidev_query(int, uint8_t, uint8_t, uint8_t);
uint8_t *spidev_raw_query(int, uint8_t *, size_t);
Expand Down
Loading