Переглянути джерело

新增业务模块占位文件夹和运行控制脚本

niujiuru 10 місяців тому
батько
коміт
e85d9b0c5e
12 змінених файлів з 198 додано та 1 видалено
  1. 0 0
      Makefile
  2. 5 1
      README.md
  3. 25 0
      config.ini
  4. 0 0
      go.mod
  5. 0 0
      main.go
  6. 13 0
      scripts/modules/daemon
  7. 55 0
      scripts/modules/funcs/functions.sh
  8. 14 0
      scripts/modules/myapp
  9. 20 0
      scripts/serverdaemon
  10. 16 0
      scripts/set_env
  11. 27 0
      scripts/start
  12. 23 0
      scripts/stop

+ 5 - 1
README.md

@@ -1,3 +1,7 @@
 # rtu_sy_1a
 # rtu_sy_1a
 
 
-便携式色板测报终端; 型号:YF-SY-1A
+项目名称:便携式色板测报终端;型号:YF-SY-1A;RTU数据板程序。
+
+项目依赖:云飞科技RTU数据板通用模块封装“rtu_linux_modules”,请先下载到与本项目的同级目录,下载地址:[rtu_linux_modules](http://218.28.198.186:10202/YFKJ_EmbeddedSoftwareTeam/rtu_linux_modules)
+
+牛九如 2025年12月26日

+ 25 - 0
config.ini

@@ -0,0 +1,25 @@
+[Log]
+; 日志级别: trace、debug、info、warn、error、fatal、panic
+Level = debug
+; 输出目标: console(控制台)、file(文件)、all(控制台+文件)
+Target = file
+; 每个日志文件的最大大下, 以"MB"为单位
+MaxFileSize = 30
+; 保留的最大备份文件数量
+MaxBackupFileCnts = 5
+
+[MQTTSrv]
+; 地址端口
+BrokerAddress = tcp://www.hnyfwlw.com:61883
+; 用户名称
+Username = user
+; 接入密码
+Password = f335bf402c655ee5fd2b5300905124e
+
+[Img2Ftp]
+; 地址端口
+ServerAddress = 8.136.98.49:21
+; 用户名称
+Username = bxsban
+; 接入密码
+Password = yf1234567



+ 13 - 0
scripts/modules/daemon

@@ -0,0 +1,13 @@
+#!/bin/sh
+# start up and monitor servers
+# 2013-09-27 10:28 created by niujiuru
+
+start()
+{
+  sh ${CWD}/serverdaemon &
+}
+
+stop()
+{
+  kill_programs serverdaemon
+}

+ 55 - 0
scripts/modules/funcs/functions.sh

@@ -0,0 +1,55 @@
+#!/bin/sh
+# useful functions
+# 2013-09-26 11:00 created by niujiuru
+
+# export envionment variables
+export_env()
+{
+  PATH="/bin:/sbin:/usr/bin:/usr/sbin"
+
+  CWD=$(dirname $0)
+  [ "${CWD%%[^/]*}" != "/" ] && CWD="${PWD}/${CWD}"
+
+  export PATH CWD
+}
+
+# load module by name
+# pass THIS_MODULE to module
+# $1: module name
+load_module()
+{
+  local module="$1"
+  THIS_MODULE="${module}"
+  . ${CWD}/modules/${module}
+}
+
+# load module & call module's method
+# $1: module name
+# $2: method name
+# $...: method params
+call_module()
+{
+  local module="$1"
+  local method="$2"
+  shift 2
+  load_module "$module" && "$method" $*
+  return $?
+}
+
+# return true if program is running
+# $1: program's name
+is_running()
+{
+  ps | grep -w "$1" | grep -v "grep" &>/dev/null
+}
+
+# kill program(s) by name
+# $1: program name
+kill_programs()
+{
+  local sig=${2:-15}
+  for p in $(ps | grep -w "$1" | grep -v "grep" | awk '{print $1}')
+  do
+    kill -$sig $p
+  done
+}

+ 14 - 0
scripts/modules/myapp

@@ -0,0 +1,14 @@
+#!/bin/sh
+# start/stop an application
+# 2014-07-29 09:45 created by niujiuru
+
+start()
+{
+  chmod a+x ${APPBINS_PATH}/${APPNAME}
+  ${APPBINS_PATH}/${APPNAME} &
+}
+
+stop()
+{
+  kill_programs ${APPNAME} 9
+}

+ 20 - 0
scripts/serverdaemon

@@ -0,0 +1,20 @@
+#!/bin/sh
+# a daemon, start and monitor servers
+# 2013-09-27 09:28 created by niujiuru
+
+. $(dirname $0)/set_env
+. $(dirname $0)/modules/funcs/functions.sh
+export_env
+
+INTERVAL=60
+
+while true
+do
+  if ! is_running "${APPNAME}"
+  then
+    echo "starting ${APPNAME}: ${APPBINS_PATH}/${APPNAME} &"
+    rm -rf ${APPRUNS_PATH}/*.lock
+    ${APPBINS_PATH}/${APPNAME} &
+  fi
+  sleep $INTERVAL
+done

+ 16 - 0
scripts/set_env

@@ -0,0 +1,16 @@
+export APPHOME_PATH="/home/root/rtu_sy_1a"
+export APPBINS_PATH="${APPHOME_PATH}"
+export APPLIBS_PATH="${APPHOME_PATH}/lib"
+export APPRUNS_PATH="${APPHOME_PATH}/status"
+export APPNAME="rtu_sy_1a.out"
+
+#导出运行时库
+export LD_LIBRARY_PATH=${APPLIBS_PATH}
+
+#设置系统主频(需放到/etc/rc.local中执行)
+#echo userspace > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
+#echo 528000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
+
+#设置一秒落盘(需放到/etc/rc.local中执行)
+#echo 100 > /proc/sys/vm/dirty_writeback_centisecs
+#echo 100 > /proc/sys/vm/dirty_expire_centisecs

+ 27 - 0
scripts/start

@@ -0,0 +1,27 @@
+#!/bin/sh
+# script that runs on system startup
+# 2013-09-26 09:30 created by niujiuru
+
+. $(dirname $0)/set_env
+. $(dirname $0)/modules/funcs/functions.sh
+export_env
+
+# 重置海康相机(1200W海康U口相机在RTU板子上冷启动时, 需要先重置相机, 才能正常工作)
+HKCAM_RESET="${APPBINS_PATH}/hkcam_reset.out"
+if [ -e "$HKCAM_RESET" ]; then
+  chmod a+x "$HKCAM_RESET"
+  "$HKCAM_RESET"
+  sleep 5
+fi
+
+# 启动主应用程序模块
+ORDER="
+myapp
+daemon
+"
+
+for m in ${ORDER}
+do
+  echo ":: starting $m"
+  call_module "$m" start
+done

+ 23 - 0
scripts/stop

@@ -0,0 +1,23 @@
+#!/bin/sh
+# script that runs on system stop
+# 2013-09-26 09:50 created by niujiuru
+
+. $(dirname $0)/set_env
+. $(dirname $0)/modules/funcs/functions.sh
+export_env
+
+ORDER="
+daemon
+myapp
+"
+
+for m in ${ORDER}
+do
+  echo ":: stopping $m"
+  call_module "$m" stop
+done
+
+if [ -d "${APPRUNS_PATH}" ]; then
+  echo ":: removing all files from ${APPRUNS_PATH}"
+  rm -f ${APPRUNS_PATH}/* 2>/dev/null
+fi