Skip to content

Commit 76f9245

Browse files
Morse Micromorse-arienjudge
authored andcommitted
smart-manager: build smart-manager from source for 1.16.4
smart-manager has been open sourced from 1.16.4 onwards. Update the package Makefile to compile from source.
1 parent b41ed09 commit 76f9245

6 files changed

Lines changed: 543 additions & 25 deletions

File tree

features/smart-manager/Makefile

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
1-
#
2-
# Copyright (C) 2023 Morse Micro
3-
#
4-
# This is free software, licensed under the Apache License, Version 2.0
5-
#
6-
7-
81
include $(TOPDIR)/rules.mk
92

103
PKG_NAME:=smart_manager
11-
PKG_RELEASE:=1
12-
PKG_VERSION:=rel_1_15_3_2025_Apr_16
13-
PKG_SOURCE:=$(PKG_NAME)_$(PKG_VERSION).tar.xz
14-
PKG_SOURCE_URL:=https://github.com/MorseMicro/smart-manager/releases/download/1.15.3/
15-
PKG_HASH:=39d63e7a1d93042d32c76cf0dd217277cb598683dafd596678a13b5a7e5290dc
16-
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)_$(PKG_VERSION)
4+
PKG_VERSION:=1.16.4
5+
PKG_RELEASE=1
6+
7+
8+
PKG_LICENSE:=BSD-3-Clause
9+
10+
PKG_SOURCE_URL:=https://github.com/MorseMicro/smart-manager.git
11+
PKG_SOURCE_PROTO:=git
12+
PKG_SOURCE_VERSION:=$(PKG_VERSION)
13+
PKG_HASH:=cd19357aa658f421c2bbb564ab2d6eafe78899e6f4e530e048f4ea51e548faf1
14+
15+
PKG_MAINTAINER:=Morse Micro
16+
PKG_BUILD_PARALLEL:=1
17+
PKG_BUILD_DEPENDS:=scons/host
1718

1819
include $(INCLUDE_DIR)/package.mk
20+
include ../../include/scons.mk
1921

2022
define Package/smart_manager
2123
SECTION:=net
22-
CATEGORY:=Network
23-
SUBMENU:=WirelessAPD
24+
CATEGORY:=Morse Micro
25+
SUBMENU:=Features
2426
TITLE:=Morse Micro HaLow DCS Smart Manager
2527
DEPENDS:= +kmod-morse +libnl +libpthread +libconfig +hostapd_s1g
2628
USERID:=network=101:network=101
2729
endef
2830

29-
define Package/smart_manager/description
30-
31-
endef
31+
SCONS_OPTIONS+="MORSE_VERSION=$(PKG_VERSION)"
3232

33-
define Build/Compile
33+
define Build/Configure
34+
(cd $(PKG_BUILD_DIR); \
35+
$(SCONS_VARS) scons $(SCONS_OPTIONS) \
36+
)
3437
endef
3538

3639
define Package/smart_manager/install
37-
$(INSTALL_DIR) $(1)/etc
40+
$(INSTALL_DIR) $(1)/sbin
3841
$(INSTALL_DIR) $(1)/etc/init.d
3942
$(INSTALL_DIR) $(1)/etc/uci-defaults
4043
$(INSTALL_DIR) $(1)/usr/share/smart_manager
41-
$(INSTALL_DIR) $(1)/sbin
42-
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(CONFIG_TARGET_ARCH_PACKAGES)/etc/init.d/smart_manager $(1)/etc/init.d/smart_manager
43-
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(CONFIG_TARGET_ARCH_PACKAGES)/etc/uci-defaults/50-smart_manager $(1)/etc/uci-defaults/50-smart_manager
44-
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(CONFIG_TARGET_ARCH_PACKAGES)/sbin/smart_manager $(1)/sbin/smart_manager
45-
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(CONFIG_TARGET_ARCH_PACKAGES)/usr/share/smart_manager/dcs.mmext $(1)/usr/share/smart_manager/dcs.mmext
44+
$(INSTALL_BIN) $(PKG_BUILD_DIR)/build/smart_manager $(1)/sbin/
45+
$(INSTALL_BIN) ./files/etc/init.d/smart_manager $(1)/etc/init.d/
46+
$(INSTALL_BIN) ./files/etc/uci-defaults/50-smart_manager $(1)/etc/uci-defaults/
47+
$(INSTALL_BIN) $(PKG_BUILD_DIR)/build/modules/dcs/dcs.mmext $(1)/usr/share/smart_manager/
4648
endef
4749

4850
$(eval $(call BuildPackage,smart_manager))
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#!/bin/sh /etc/rc.common
2+
3+
. "${IPKG_INSTROOT}/lib/netifd/netifd-wireless.sh"
4+
5+
STOP=10
6+
7+
USE_PROCD=1
8+
PROG=/sbin/smart_manager
9+
SERVICE=smart_manager
10+
11+
setup_dcs_conf() {
12+
local cfg="$1"
13+
local conf_path="$2"
14+
local ifname="$3"
15+
16+
config_get_bool enable_datalog "$cfg" enable_datalog 0
17+
config_get_bool enable_test "$cfg" enable_test 0
18+
config_get log_level "$cfg" log_level 2
19+
config_get algorithm "$cfg" algorithm ewma
20+
config_get rounds "$cfg" rounds 10
21+
config_get threshold "$cfg" threshold 5
22+
config_get scan_int "$cfg" scan_int 2
23+
config_get round_int "$cfg" round_int 10
24+
config_get ewma_alpha "$cfg" ewma_alpha 30
25+
config_get root_dir "$cfg" root_dir "/var/log"
26+
config_get dtims_for_csa "$cfg" dtims_for_csa 10
27+
28+
[ $enable_datalog -eq 0 ] && enable_datalog=false || enable_datalog=true
29+
datalog=$(cat <<EOF
30+
datalog: {
31+
root_dir = "$root_dir"
32+
dcs: {
33+
enabled = $enable_datalog
34+
}
35+
}
36+
EOF
37+
)
38+
39+
algorithm_sec=
40+
case "$algorithm" in
41+
"sample_and_hold")
42+
algorithm_sec=$(cat <<EOF
43+
algo_type = "sample_and_hold"
44+
sample_and_hold: {
45+
rounds_for_eval = $rounds
46+
threshold_percentage = $threshold
47+
sec_per_scan = $scan_int
48+
sec_per_round = $round_int
49+
}
50+
EOF
51+
)
52+
;;
53+
54+
*)
55+
algorithm_sec=$(cat <<EOF
56+
algo_type = "ewma"
57+
ewma: {
58+
ewma_alpha = $ewma_alpha
59+
rounds_for_csa = $rounds
60+
threshold_percentage = $threshold
61+
sec_per_scan = $scan_int
62+
sec_per_round = $round_int
63+
}
64+
EOF
65+
)
66+
;;
67+
esac
68+
69+
70+
cat > "$conf_path" <<EOF
71+
module_dirs: ["/usr/share/smart_manager/"]
72+
modules: ["dcs"]
73+
interface_name = "$ifname"
74+
logging: {
75+
level = $log_level
76+
}
77+
backends: {
78+
hostapd: {
79+
control_path: "/var/run/hostapd_s1g"
80+
}
81+
}
82+
$datalog
83+
dcs: {
84+
$algorithm_sec
85+
trigger_csa = True
86+
dtims_for_csa = $dtims_for_csa
87+
}
88+
EOF
89+
}
90+
91+
get_first_ifname() {
92+
[ -n "$ifname" ] && return
93+
json_get_vars ifname
94+
}
95+
96+
get_first_ap_ifname() {
97+
# This relies on running after netifd morse.sh has set up the AP.
98+
# Hostapd does not need to have started.
99+
# At boot, this will fail due to the above, but netifd morse.sh will restart
100+
# us after setting up the AP.
101+
json_load "$(wifi status "$radio")"
102+
json_select "$radio"
103+
for_each_interface "ap" get_first_ifname
104+
[ -n "$ifname" ] && return 0;
105+
}
106+
107+
start_dcs() {
108+
local cfg="$1"
109+
# trim radio0_dcs to radio0
110+
local radio="${cfg%_dcs}"
111+
112+
eval "HAS_DCS_CONFIG_$radio=1"
113+
114+
config_get_bool enabled "$cfg" enabled 0
115+
[ $enabled -ne 1 ] && return
116+
117+
if [ "$(uci get "wireless.${radio}.type")" != "morse" ]; then
118+
logger -t $SERVICE -p daemon.crit "wireless.${cfg} not a morse device!"
119+
return 1
120+
fi
121+
122+
radiojs=$(wifi status $radio 2>/dev/null)
123+
if [ $? -ne 0 ]; then
124+
logger -t $SERVICE -p daemon.crit "Selected radio $radio does not exist!"
125+
return 1
126+
fi
127+
128+
json_load "$radiojs"
129+
json_select $radio
130+
json_get_vars disabled
131+
set_default disabled 1
132+
if [ "$disabled" -ne 0 ]; then
133+
logger -t $SERVICE -p daemon.crit "$radio disabled"
134+
return 1
135+
fi
136+
137+
ifname=
138+
if ! get_first_ap_ifname "$radio"; then
139+
logger -t $SERVICE -p daemon.crit "Couldn't get ifname for ap on $radio"
140+
return 1
141+
fi
142+
143+
dcs_conf="/var/run/smart_manager.${radio}.conf"
144+
145+
setup_dcs_conf $cfg $dcs_conf $ifname
146+
147+
procd_open_instance $cfg.$ifname
148+
procd_set_param command $PROG $dcs_conf
149+
procd_set_param file $dcs_conf
150+
procd_set_param stdout 1
151+
procd_set_param stderr 1
152+
procd_set_param respawn
153+
procd_close_instance
154+
}
155+
156+
start_default_dcs() {
157+
local wifi_device="$1"
158+
local dcs_section="${wifi_device}_dcs"
159+
160+
# Abort if there's already a config section (i.e. we did it earlier).
161+
# This val was saved above.
162+
if [ "$(eval echo \$HAS_DCS_CONFIG_${wifi_device})" = 1 ]; then
163+
return
164+
fi
165+
166+
if [ "$(config_get "$wifi_device" type)" != morse ]; then
167+
return
168+
fi
169+
170+
case "$(config_get "$wifi_device" channel)" in
171+
''|0|auto)
172+
config_set "$dcs_section" enabled 1
173+
start_dcs "$dcs_section"
174+
;;
175+
esac
176+
}
177+
178+
start_service() {
179+
config_load smart_manager
180+
config_foreach start_dcs dcs
181+
182+
# Default to loading smart_manager if no config
183+
# and channel is set to auto (i.e. ACS is used).
184+
config_load wireless
185+
config_foreach start_default_dcs wifi-device
186+
}
187+
188+
stop_service() {
189+
rm -f /var/run/smart_manager*
190+
}
191+
192+
service_triggers() {
193+
procd_add_reload_trigger smart_manager
194+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
3+
. /lib/functions.sh
4+
5+
# Migrate all wireless dcs sections to a new smart_manager config
6+
migrate_dcs() {
7+
local config="$1"
8+
9+
# move wireless.radioX_dcs to smart_manager.radioX_dcs
10+
uci show "wireless.$config" | sed -e 's/^wireless/set smart_manager/' | uci batch
11+
uci delete "wireless.$config"
12+
# move wireless.radioX.dcs to smart_manager.radioX_dcs.enabled
13+
uci show "wireless.${config%_dcs}.dcs" | sed -e "s/^wireless.${config%_dcs}.dcs/set smart_manager.$config.enabled/" | uci batch
14+
uci delete "wireless.${config%_dcs}.dcs"
15+
}
16+
17+
touch /etc/config/smart_manager
18+
config_load wireless
19+
config_foreach migrate_dcs dcs

0 commit comments

Comments
 (0)