Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
meta-elphel393
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
meta-elphel393
Commits
5c39c2aa
Commit
5c39c2aa
authored
May 18, 2016
by
Mikhail Karpenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Install tempmon to /usr/bin and update its init script
parent
f7dc5d36
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
44 deletions
+85
-44
init_tempmon
recipes-core/init-tempmon/files/init_tempmon
+34
-17
init_tempmon.py
recipes-core/init-tempmon/files/init_tempmon.py
+47
-10
init-tempmon_1.0.bb
recipes-core/init-tempmon/init-tempmon_1.0.bb
+4
-17
No files found.
recipes-core/init-tempmon/files/init_tempmon
View file @
5c39c2aa
#!/bin/sh
#!/bin/sh
DEAMON
=
/usr/bin/init_tempmon.py
PATH
=
/sbin:/bin:/usr/sbin:/usr/bin
PATH
=
/sbin:/bin:/usr/sbin:/usr/bin
DAEMON
=
/usr/sbin/init_tempmon
NAME
=
init_tempmon
NAME
=
init_tempmon
DESC
=
"temperature monitor daemon"
DESC
=
"temperature monitor daemon"
SCRIPT_NAME
=
init_tempmon.py
MNTPOINT
=
/mnt/mmc
# PID file name, must match to the name in init_tempmon.py sript
MMCDEV
=
/dev/mmcblk0p1
PID_FILE
=
/var/run/init_tempmon.pid
SOME_SCRIPT
=
init_tempmon.py
.
/etc/init.d/functions
test
-x
$DEAMON
||
exit
0
case
"
$1
"
in
case
"
$1
"
in
start
)
start
)
echo
-n
"Starting
$DESC
: "
if
[
!
-f
$PID_FILE
]
;
then
if
[
-f
$MNTPOINT
/
$SOME_SCRIPT
]
;
then
echo
-n
"Starting
$DESC
: "
echo
" Launching
$SOME_SCRIPT
"
echo
$SCRIPT_NAME
$MNTPOINT
/
$SOME_SCRIPT
$DEAMON
&
else
else
echo
"
$SOME_SCRIPT
not found. Nothing to launch.
"
echo
"Already running
"
fi
fi
;;
;;
stop
)
stop
)
echo
-n
"Stopping
$DESC
: "
if
[
-f
$PID_FILE
]
;
then
echo
"
$NAME
."
echo
-n
"Stopping
$DESC
: "
echo
"
$NAME
"
pid
=
$(
cat
$PID_FILE
)
/bin/kill
$pid
rm
$PID_FILE
else
echo
"Not running, nothing to stop"
fi
;;
;;
restart
)
restart
)
echo
-n
"Restarting
$DESC
: "
if
[
-f
$PID_FILE
]
;
then
echo
"
$NAME
."
echo
-n
"Restarting
$DESC
: "
echo
"
$NAME
"
pid
=
$(
cat
$PID_FILE
)
/bin/kill
$pid
$DEAMON
&
else
echo
"Not running, nothing to restart"
fi
;;
;;
status
)
status
)
echo
-n
"
$NAME
status:"
echo
-n
"
$NAME
status:
"
if
[
-f
/var/run/
$NAM
E
]
;
then
if
[
-f
$PID_FIL
E
]
;
then
echo
-n
"Running"
echo
"Running"
else
else
echo
-n
"Not running"
echo
"Not running"
fi
fi
;;
;;
*
)
*
)
...
...
recipes-core/init-tempmon/files/init_tempmon.py
View file @
5c39c2aa
...
@@ -26,6 +26,7 @@ import os
...
@@ -26,6 +26,7 @@ import os
import
sys
import
sys
import
time
import
time
import
subprocess
import
subprocess
import
atexit
from
posix
import
EX_OSFILE
,
F_OK
from
posix
import
EX_OSFILE
,
F_OK
DEBUG
=
0
DEBUG
=
0
...
@@ -40,6 +41,8 @@ TEMP_HYSTERESIS = 2.0
...
@@ -40,6 +41,8 @@ TEMP_HYSTERESIS = 2.0
SAMPLING_TIME
=
1
SAMPLING_TIME
=
1
""" Temperature scaling factor. """
""" Temperature scaling factor. """
SCALE_CFT
=
0.001
SCALE_CFT
=
0.001
""" The name of the file in /var/run which will contain PID """
PID_NAME
=
"init_tempmon"
ctrl_path_pref
=
"/sys/devices/soc0/elphel393-pwr@0/"
ctrl_path_pref
=
"/sys/devices/soc0/elphel393-pwr@0/"
ctrl_fn
=
{
"poweroff_fn"
:
"power_off"
,
ctrl_fn
=
{
"poweroff_fn"
:
"power_off"
,
...
@@ -47,11 +50,12 @@ ctrl_fn = {"poweroff_fn": "power_off",
...
@@ -47,11 +50,12 @@ ctrl_fn = {"poweroff_fn": "power_off",
"vp5_dis_fn"
:
"channels_dis"
,
"vp5_dis_fn"
:
"channels_dis"
,
"gpio_fn"
:
"gpio_10389"
}
"gpio_fn"
:
"gpio_10389"
}
hwmon_path_pref
=
"/sys/devices/soc0/amba@0/f8007100.ps7-xadc/iio:device0/"
hwmon_path_pref
=
"/sys/devices/soc0/amba@0/f8007100.ps7-xadc/iio:device0/"
hwmon_fn
=
{
"offset"
:
"in_temp0_offset"
,
hwmon_fn
=
{
"offset"
:
"in_temp0_offset"
,
"raw"
:
"in_temp0_raw"
,
"raw"
:
"in_temp0_raw"
,
"scale"
:
"in_temp0_scale"
}
"scale"
:
"in_temp0_scale"
}
out_path_pref
=
"/var/volatile/tmp/"
out_path_pref
=
"/var/volatile/tmp/"
out_fn
=
{
"core_temp_fn"
:
"core_temp"
}
out_fn
=
{
"core_temp_fn"
:
"core_temp"
,
"temp_params_fn"
:
"core_temp_params"
}
class
temp_monitor
():
class
temp_monitor
():
def
__init__
(
self
,
ctrl_path_pref
,
ctrl_file_names
,
hwmon_path_pref
,
hwmon_fn
,
def
__init__
(
self
,
ctrl_path_pref
,
ctrl_file_names
,
hwmon_path_pref
,
hwmon_fn
,
...
@@ -63,17 +67,36 @@ class temp_monitor():
...
@@ -63,17 +67,36 @@ class temp_monitor():
self
.
hwmon_path_prefix
=
hwmon_path_pref
self
.
hwmon_path_prefix
=
hwmon_path_pref
self
.
hwmon_fnames
=
hwmon_fn
self
.
hwmon_fnames
=
hwmon_fn
self
.
samples_window
=
[]
self
.
samples_window
=
[]
self
.
pid_fname
=
"/var/run/"
+
PID_NAME
+
".pid"
""" Number of samples for temperature averaging """
""" Number of samples for temperature averaging """
self
.
samples_num
=
5
self
.
samples_num
=
5
self
.
fan_cmd
=
{
"fan_cmd_on"
:
"0x101"
,
self
.
fan_cmd
=
{
"fan_cmd_on"
:
"0x101"
,
"fan_cmd_off"
:
"0x100"
}
"fan_cmd_off"
:
"0x100"
}
self
.
params
=
{
"temp_minor"
:
TEMP_FAN_ON
,
"temp_major"
:
TEMP_SHUTDOWN
,
"temp_hyst"
:
TEMP_HYSTERESIS
,
"temp_sampling_time"
:
SAMPLING_TIME
}
""" Create output files """
""" Create output files """
try
:
try
:
self
.
core_temp_out_f
=
open
(
out_path_prefix
+
out_fnames
[
"core_temp_fn"
],
"w"
)
self
.
core_temp_out_f
=
open
(
out_path_prefix
+
out_fnames
[
"core_temp_fn"
],
"w"
)
except
IOError
:
except
IOError
:
print
"Failed to create file: '
%
s
%
s'"
%
(
out_path_prefix
,
out_fnames
[
"core_temp_fn"
])
print
"Failed to create file: '
%
s
%
s'"
%
(
out_path_prefix
,
out_fnames
[
"core_temp_fn"
])
try
:
self
.
core_temp_params_f
=
open
(
out_path_prefix
+
out_fnames
[
"temp_params_fn"
],
"w"
)
except
IOError
:
self
.
core_temp_out_f
.
close
()
print
"Failed to create file: '
%
s
%
s'"
%
(
out_path_prefix
,
out_fnames
[
"temp_params_fn"
])
""" Create pid file """
with
open
(
self
.
pid_fname
,
"w"
)
as
pid_file
:
pid_file
.
write
(
str
(
os
.
getpid
()))
atexit
.
register
(
self
.
delpid
)
def
delpid
(
self
):
if
os
.
access
(
self
.
pid_fname
,
F_OK
):
os
.
remove
(
self
.
pid_fname
)
def
check_files
(
self
):
def
check_files
(
self
):
"""
"""
Check if all files exist in the system.
Check if all files exist in the system.
...
@@ -141,22 +164,36 @@ class temp_monitor():
...
@@ -141,22 +164,36 @@ class temp_monitor():
samples
.
sort
()
samples
.
sort
()
avg
=
samples
[
len
(
samples
)
/
2
]
avg
=
samples
[
len
(
samples
)
/
2
]
if
core_temp
<
(
TEMP_FAN_ON
-
TEMP_HYSTERESIS
)
and
self
.
is_fan_on
:
if
core_temp
<
(
self
.
params
[
"temp_minor"
]
-
self
.
params
[
"temp_hyst"
]
)
and
self
.
is_fan_on
:
self
.
fan_ctrl
(
"off"
)
self
.
fan_ctrl
(
"off"
)
elif
core_temp
>=
TEMP_FAN_ON
and
core_temp
<
TEMP_SHUTDOWN
and
not
self
.
is_fan_on
:
elif
core_temp
>=
self
.
params
[
"temp_minor"
]
and
core_temp
<
self
.
params
[
"temp_major"
]
and
not
self
.
is_fan_on
:
self
.
fan_ctrl
(
"on"
)
self
.
fan_ctrl
(
"on"
)
elif
avg
>=
TEMP_SHUTDOWN
:
elif
avg
>=
self
.
params
[
"temp_major"
]
:
self
.
shutdown
()
self
.
shutdown
()
self
.
core_temp_out_f
.
seek
(
0
)
self
.
core_temp_out_f
.
seek
(
0
)
self
.
core_temp_out_f
.
write
(
str
(
core_temp
))
self
.
core_temp_out_f
.
write
(
str
(
core_temp
))
self
.
core_temp_out_f
.
flush
()
self
.
core_temp_out_f
.
flush
()
print
"Core temperature: '
%
f', median: '
%
f'"
%
(
core_temp
,
avg
)
#
print "Core temperature: '%f', median: '%f'" % (core_temp, avg)
time
.
sleep
(
SAMPLING_TIME
)
time
.
sleep
(
self
.
params
[
"temp_sampling_time"
]
)
except
(
KeyboardInterrupt
,
SystemExit
):
except
(
KeyboardInterrupt
,
SystemExit
):
print
"Got keyboard interrupt. Exiting."
self
.
core_temp_out_f
.
close
()
self
.
core_temp_params_f
.
close
()
os
.
remove
(
self
.
pid_fname
)
print
"'
%
s': got keyboard interrupt. Exiting."
%
os
.
path
.
basename
(
__file__
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
def
read_temp_params
(
self
):
"""
Read parameters from file and update local values.
"""
for
key
,
val
in
self
.
params
.
items
():
self
.
core_temp_params_f
.
seek
(
0
)
file_lines
=
self
.
core_temp_params_f
.
readlines
()
for
line
in
file_lines
:
if
line
.
find
(
key
)
==
0
:
self
.
core_temp_params_f
[
key
]
=
float
(
line
.
split
(
":"
)[
1
]
.
strip
())
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
if
DEBUG
:
if
DEBUG
:
...
...
recipes-core/init-tempmon/init-tempmon_1.0.bb
View file @
5c39c2aa
...
@@ -21,7 +21,7 @@ SRC_URI = "file://init_tempmon \
...
@@ -21,7 +21,7 @@ SRC_URI = "file://init_tempmon \
S = "${WORKDIR}/"
S = "${WORKDIR}/"
INITSCRIPT_NAME = "init_tempmon"
INITSCRIPT_NAME = "init_tempmon"
INITSCRIPT_PARAMS = "defaults 9
6
"
INITSCRIPT_PARAMS = "defaults 9
4
"
RDEPENDS_${PN} += "python-core"
RDEPENDS_${PN} += "python-core"
...
@@ -29,6 +29,7 @@ FILES_${PN} = "\
...
@@ -29,6 +29,7 @@ FILES_${PN} = "\
/etc/* \
/etc/* \
/usr/* \
/usr/* \
"
"
PACKAGES = " init-tempmon"
#This needs to get the script into rc?.d/
#This needs to get the script into rc?.d/
inherit update-rc.d
inherit update-rc.d
...
@@ -36,20 +37,6 @@ inherit update-rc.d
...
@@ -36,20 +37,6 @@ inherit update-rc.d
do_install_append() {
do_install_append() {
install -d ${D}${sysconfdir}/init.d
install -d ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/init_tempmon ${D}${sysconfdir}/init.d
install -m 0755 ${WORKDIR}/init_tempmon ${D}${sysconfdir}/init.d
install -d ${D}${bindir}
for RLOC in ${PRODUCTION_ROOT_LOCATION}; do
install -m 0755 ${S}/init_tempmon.py ${D}${bindir}
if [ ! -d ${DEPLOY_DIR_IMAGE}/${RLOC} ]; then
mkdir -p ${DEPLOY_DIR_IMAGE}/${RLOC}
fi
if [ -f ${S}init_tempmon.py ]; then
if [ -f ${DEPLOY_DIR_IMAGE}/${RLOC}/init_tempmon.py ]; then
rm ${DEPLOY_DIR_IMAGE}/${RLOC}/init_tempmon.py
fi
cp ${S}init_tempmon.py ${DEPLOY_DIR_IMAGE}/${RLOC}/init_tempmon.py
else
echo "NOT 3 FOUND!"
fi
done
}
}
PACKAGES = " init-tempmon"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment